/* * Copyright 2003 Sun Microsystems, Inc. ALL RIGHTS RESERVED * Use of this software is authorized pursuant to the terms * of the license found at * http://developer.java.sun.com/berkeley_license.html. */ package divelog; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; import divelog.DiveHandler; public class UIWestPanel extends JPanel implements ActionListener, ItemListener { //Opens class private JLabel diveNumber = new JLabel("Dive #: "); private JLabel diveNumberL = new JLabel(); private JLabel menu2 = new JLabel("Maximum Depth"); private JLabel jelly = new JLabel("", new ImageIcon("images/jellyfish.jpg"), JLabel.CENTER); private JLabel dateL = new JLabel("Date: " ); private JTextField date = new JTextField("00/00/00"); private JLabel psiStartL = new JLabel("PSI Start:"); private JTextField psiStart = new JTextField("0000"); private JLabel psiEndL = new JLabel("PSI End:"); private JTextField psiEnd = new JTextField("000"); private JLabel psiUsedL = new JLabel("PSI Used:"); private JLabel psiUsed = new JLabel(); private JLabel bottomTimeL = new JLabel("Time in Minutes:"); private JTextField bottomTime = new JTextField("00"); private JLabel visL = new JLabel("Visibility:"); private JTextField vis = new JTextField("00"); private JComboBox maxDepths; private JLabel location = new JLabel("Dive Type: "); private JRadioButton rb; private JRadioButton boatButton; private JRadioButton shoreButton; // To hold result for ButtonGroup private JRadioButton b; private JLabel blank = new JLabel(" "); protected JButton view; protected JButton enter; //To track how many dives private int count = 0; //String for JComboBox result private String s; //Variable for text area public JTextArea comments; private JScrollPane scrollpane; private JLabel whiteshark; private Box box; // Constructor public UIWestPanel () { // Open constructor setLayout(new BorderLayout()); setBackground(Color.white); //Features for lefthandside of screen String[] depths = { "1", "10", "20", "30", "40", "50","60", "70", "80", "90", "100", "120", "140", "160 ", "180", "200" }; maxDepths = new JComboBox(depths); maxDepths.setMaximumRowCount(5); maxDepths.setBackground(Color.white); maxDepths.setEditable(true); //Adding listener for functionality maxDepths.addActionListener(this); boatButton = new JRadioButton("Boat"); shoreButton = new JRadioButton("Shore"); shoreButton.setBackground(Color.white); boatButton.setBackground(Color.white); //Adding listeners for functionality shoreButton.addItemListener(this); boatButton.addItemListener(this); ButtonGroup group = new ButtonGroup(); group.add(boatButton); group.add(shoreButton); view = new JButton(); enter = new JButton(); //Create pannel for components JPanel wpanel = new JPanel(new GridLayout(16, 2, 0, 0)); wpanel.setBackground(Color.white); //Add components //Combo Box for depth of dive wpanel.add (menu2); wpanel.add (maxDepths); wpanel.add(dateL); wpanel.add(date); wpanel.add(location); wpanel.add(blank); wpanel.add(shoreButton); wpanel.add(boatButton); wpanel.add(Box.createVerticalStrut(3)); wpanel.add(Box.createVerticalStrut(3)); wpanel.add(psiStartL); wpanel.add(psiStart); wpanel.add(psiEndL); wpanel.add(psiEnd); wpanel.add(psiUsedL); wpanel.add(psiUsed); wpanel.add(bottomTimeL); wpanel.add(bottomTime); wpanel.add(visL); wpanel.add(vis); wpanel.add(diveNumber); wpanel.add(diveNumberL); wpanel.add(enter); wpanel.add(view); //Define textarea, and create panel //for textarea, shark, and button JPanel cpanel = new JPanel(); comments = new JTextArea(15, 10); comments.setLineWrap(true); comments.setWrapStyleWord(true); scrollpane = new JScrollPane(comments); scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); whiteshark = new JLabel("", new ImageIcon("images/gwhite.gif"), JLabel.CENTER); box = Box.createVerticalBox(); box.add(scrollpane); box.add(Box.createVerticalStrut(35)); box.add(whiteshark); cpanel.setBackground(Color.white); cpanel.add(box); //Add panels to border layout of // Dives object. add(jelly, "North"); add(cpanel, "East"); add(wpanel, "West"); } // Closes constructor public void actionPerformed(ActionEvent ae) { s = (String) maxDepths.getSelectedItem(); if ((s.equals("10")) || (s.equals("20"))) JOptionPane.showMessageDialog(null, "You should go snorkling!"); else if ((s == "120") || (s == "140") || (s == "160")) JOptionPane.showMessageDialog(null, "You'd better be an experienced diver!", "Warning", JOptionPane.WARNING_MESSAGE); else if ((s == "180") || (s == "200")) JOptionPane.showMessageDialog(null, "You better have a thorough understanding of mixed gases and deco stops!", null, JOptionPane.WARNING_MESSAGE); } public JButton getView () {return view;} public JButton getEnter () {return enter;} public void itemStateChanged(ItemEvent ie) { rb = (JRadioButton) ie.getItem(); } //collects the user input from fields and stores them in // a Vector. public Vector getUIFields() { Vector fieldValues = new Vector(); fieldValues.add(rb.getText()); fieldValues.add(date.getText()); fieldValues.add(s); fieldValues.add(psiStart.getText()); fieldValues.add(psiEnd.getText()); fieldValues.add(psiUsed.getText()); fieldValues.add(bottomTime.getText()); fieldValues.add(diveNumberL.getText()); fieldValues.add(vis.getText()); fieldValues.add(comments.getText()); return fieldValues; }// closes getUIFields public int getCount() { count++; diveNumberL.setText(String.valueOf(count)); return count; } public void getAirIntake() { //opens getAirIntake //Declares int variables to hold the result of //converting strings to int int beginAir = Integer.parseInt(psiStart.getText()); int endAir = Integer.parseInt(psiEnd.getText()); int airConsumed = beginAir - endAir; psiUsed.setText(String.valueOf(airConsumed)); }// closes getAirIntake public void clearFields() { shoreButton.setSelected(true); date.setText("00/00/00"); psiStart.setText("0000"); psiEnd.setText("000"); psiUsed.setText(""); bottomTime.setText("00"); vis.setText("00"); comments.setText(""); } public void setFields(String string[]) throws IllegalArgumentException { if (string.length <= 0) throw new IllegalArgumentException( "Not enough fields were filled in"); //Checks to see which bottom //was selected. date.setText(string[0]); maxDepths.setSelectedItem(string[1]); //rb.setSelectedItem(string[2]); psiStart.setText(string[3]); psiEnd.setText(string[4]); psiUsed.setText(string[5]); bottomTime.setText(string[6]); diveNumberL.setText(string[7]); vis.setText(string[8]); comments.setText(string[9]); } }//Closes UIWestPanel class