Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ProjectInformationPanel.java

Go to the documentation of this file.
00001 /*
00002  * ProjectInformationPanel.java
00003  *
00004  * Copyright (C) 2005 Project SQUID, http://www.cs.helsinki.fi/group/squid/
00005  *
00006  * This file is part of Ikayaki.
00007  *
00008  * Ikayaki is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Ikayaki is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Ikayaki; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021  */
00022 
00023 package ikayaki.gui;
00024 
00025 import com.intellij.uiDesigner.core.GridConstraints;
00026 import com.intellij.uiDesigner.core.GridLayoutManager;
00027 import com.intellij.uiDesigner.core.Spacer;
00028 import ikayaki.Project;
00029 
00030 import javax.swing.*;
00031 import javax.swing.event.DocumentEvent;
00032 import javax.swing.event.DocumentListener;
00033 import javax.swing.text.NumberFormatter;
00034 import java.awt.*;
00035 import java.awt.event.ActionEvent;
00036 import java.awt.event.ActionListener;
00037 import java.beans.PropertyChangeEvent;
00038 import java.beans.PropertyChangeListener;
00039 import java.text.DateFormat;
00040 import java.text.DecimalFormat;
00041 import java.text.ParseException;
00042 import java.util.Date;
00043 import java.util.LinkedList;
00044 import java.util.Queue;
00045 
00051 public class ProjectInformationPanel extends ProjectComponent {
00052 
00053     /* Radio Button Groups */
00054     private ButtonGroup measurementType;
00055     private JRadioButton measurementTypeAuto;
00056     private JRadioButton measurementTypeManual;
00057 
00058     private ButtonGroup sampleType;
00059     private JRadioButton sampleTypeHand;
00060     private JRadioButton sampleTypeCore;
00061 
00062     private ButtonGroup normalization;
00063     private JRadioButton normalizationVolume;
00064     private JRadioButton normalizationMass;
00065 
00066     /* Plain Text Fields */
00067     private JTextField operatorField;
00068     private JTextField dateField;
00069     private JTextField rockTypeField;
00070     private JTextField areaField;
00071     private JTextField siteField;
00072     private JTextArea commentArea;
00073 
00074     /* Number-only Text Fields */
00075     private JFormattedTextField latitudeField;
00076     private JFormattedTextField longitudeField;
00077     private JFormattedTextField strikeField;
00078     private JFormattedTextField dipField;
00079     private JFormattedTextField massField;
00080     private JFormattedTextField volumeField;
00081     private JFormattedTextField susceptibilityField;
00082 
00083     private JPanel contentPane;
00084 
00085     private boolean propertiesModified = false;
00086     private boolean parametersModified = false;
00087 
00091     public ProjectInformationPanel() {
00092         setLayout(new BorderLayout());
00093         add(contentPane, "Center");
00094         contentPane.setBorder(BorderFactory.createEmptyBorder(0, 4, 8, 4));
00095 
00096         /* Radio Button Groups */
00097         measurementType = new ButtonGroup();
00098         measurementType.add(measurementTypeAuto);
00099         measurementType.add(measurementTypeManual);
00100 
00101         sampleType = new ButtonGroup();
00102         sampleType.add(sampleTypeHand);
00103         sampleType.add(sampleTypeCore);
00104 
00105         normalization = new ButtonGroup();
00106         normalization.add(normalizationVolume);
00107         normalization.add(normalizationMass);
00108 
00109         /* Formatted Text Fields */
00110         MyFormatterFactory factory = new MyFormatterFactory();
00111         latitudeField.setFormatterFactory(factory);
00112         longitudeField.setFormatterFactory(factory);
00113         strikeField.setFormatterFactory(factory);
00114         dipField.setFormatterFactory(factory);
00115         massField.setFormatterFactory(factory);
00116         volumeField.setFormatterFactory(factory);
00117         susceptibilityField.setFormatterFactory(factory);
00118 
00119         /* Listeners for properties */
00120         DocumentListener propertiesDocumentListener = new DocumentListener() {
00121             public void insertUpdate(DocumentEvent e) {
00122                 initSaveProperties();
00123             }
00124 
00125             public void removeUpdate(DocumentEvent e) {
00126                 initSaveProperties();
00127             }
00128 
00129             public void changedUpdate(DocumentEvent e) {
00130                 initSaveProperties();
00131             }
00132         };
00133         ActionListener propertiesActionListener = new ActionListener() {
00134             public void actionPerformed(ActionEvent e) {
00135                 initSaveProperties();
00136             }
00137         };
00138         PropertyChangeListener propertiesPropertyChangeListener = new PropertyChangeListener() {
00139             public void propertyChange(PropertyChangeEvent evt) {
00140                 initSaveProperties();
00141             }
00142         };
00143 
00144         measurementTypeAuto.addActionListener(propertiesActionListener);
00145         measurementTypeManual.addActionListener(propertiesActionListener);
00146 
00147         operatorField.getDocument().addDocumentListener(propertiesDocumentListener);
00148         dateField.getDocument().addDocumentListener(propertiesDocumentListener);
00149         rockTypeField.getDocument().addDocumentListener(propertiesDocumentListener);
00150         areaField.getDocument().addDocumentListener(propertiesDocumentListener);
00151         siteField.getDocument().addDocumentListener(propertiesDocumentListener);
00152         commentArea.getDocument().addDocumentListener(propertiesDocumentListener);
00153 
00154         latitudeField.addPropertyChangeListener("value", propertiesPropertyChangeListener);
00155         longitudeField.addPropertyChangeListener("value", propertiesPropertyChangeListener);
00156 
00157         /* Listeners for parameters */
00158         ActionListener parametersActionListener = new ActionListener() {
00159             public void actionPerformed(ActionEvent e) {
00160                 initSaveParameters();
00161             }
00162         };
00163         PropertyChangeListener parametersPropertyChangeListener = new PropertyChangeListener() {
00164             public void propertyChange(PropertyChangeEvent evt) {
00165                 initSaveParameters();
00166             }
00167         };
00168 
00169         sampleTypeHand.addActionListener(parametersActionListener);
00170         sampleTypeCore.addActionListener(parametersActionListener);
00171         normalizationVolume.addActionListener(parametersActionListener);
00172         normalizationMass.addActionListener(parametersActionListener);
00173 
00174         strikeField.addPropertyChangeListener("value", parametersPropertyChangeListener);
00175         dipField.addPropertyChangeListener("value", parametersPropertyChangeListener);
00176         massField.addPropertyChangeListener("value", parametersPropertyChangeListener);
00177         volumeField.addPropertyChangeListener("value", parametersPropertyChangeListener);
00178         susceptibilityField.addPropertyChangeListener("value", parametersPropertyChangeListener);
00179 
00180         /* Autosaving at regular intervals */
00181         Timer autosave = new Timer(500, new ActionListener() {
00182             public void actionPerformed(ActionEvent e) {
00183                 saveProperties();
00184                 saveParameters();
00185             }
00186         });
00187         autosave.start();
00188         
00189         // initialize with no project
00190         setProject(null);
00191     }
00192 
00198     @Override public void setEnabled(boolean enabled) {
00199         super.setEnabled(enabled);
00200         Queue<Component> components = new LinkedList<Component>();
00201         for (Component c : getComponents()) {
00202             components.add(c);
00203         }
00204         Component component = null;
00205         while ((component = components.poll()) != null) {
00206             component.setEnabled(enabled);
00207             if (component instanceof Container) {
00208                 for (Component c : ((Container) component).getComponents()) {
00209                     components.add(c);
00210                 }
00211             }
00212         }
00213     }
00214 
00218     public void setProject(Project project) {
00219 
00220         // save the old project's values
00221         saveProperties();
00222         saveParameters();
00223 
00224         super.setProject(project);
00225         setEnabled(project != null);
00226 
00227         if (project != null) {
00228             // get values from the new project
00229 
00230             /* Radio Button Groups */
00231             measurementTypeAuto.setSelected(project.getProperty(Project.MEASUREMENT_TYPE_PROPERTY,
00232                     Project.MEASUREMENT_TYPE_AUTO_VALUE).equals(Project.MEASUREMENT_TYPE_AUTO_VALUE));
00233             measurementTypeManual.setSelected(project.getProperty(Project.MEASUREMENT_TYPE_PROPERTY,
00234                     Project.MEASUREMENT_TYPE_AUTO_VALUE).equals(Project.MEASUREMENT_TYPE_MANUAL_VALUE));
00235             sampleTypeHand.setSelected(project.getSampleType() == Project.SampleType.HAND);
00236             sampleTypeCore.setSelected(project.getSampleType() == Project.SampleType.CORE);
00237             normalizationVolume.setSelected(project.getNormalization() == Project.Normalization.VOLUME);
00238             normalizationMass.setSelected(project.getNormalization() == Project.Normalization.MASS);
00239 
00240             /* Plain Text Fields */
00241             operatorField.setText(project.getProperty(Project.OPERATOR_PROPERTY, ""));
00242             dateField.setText(
00243                     project.getProperty(Project.DATE_PROPERTY, DateFormat.getDateInstance().format(new Date())));
00244             rockTypeField.setText(project.getProperty(Project.ROCK_TYPE_PROPERTY, ""));
00245             areaField.setText(project.getProperty(Project.AREA_PROPERTY, ""));
00246             siteField.setText(project.getProperty(Project.SITE_PROPERTY, ""));
00247             commentArea.setText(project.getProperty(Project.COMMENT_PROPERTY, ""));
00248             commentArea.setCaretPosition(0);    // scroll the viewport to the top
00249 
00250             /* Number Fields */
00251             latitudeField.setText(project.getProperty(Project.LATITUDE_PROPERTY, ""));
00252             longitudeField.setText(project.getProperty(Project.LONGITUDE_PROPERTY, ""));
00253             strikeField.setValue(new Double(project.getStrike()));
00254             dipField.setValue(new Double(project.getDip()));
00255             massField.setValue(new Double(project.getMass()));
00256             volumeField.setValue(new Double(project.getVolume()));
00257             susceptibilityField.setValue(new Double(project.getSusceptibility()));
00258         } else {
00259             // no project active, clear the form fields
00260 
00261             /* Radio Button Groups */
00262             measurementTypeAuto.setSelected(true);
00263             measurementTypeManual.setSelected(false);
00264             sampleTypeHand.setSelected(true);
00265             sampleTypeCore.setSelected(false);
00266             normalizationVolume.setSelected(true);
00267             normalizationMass.setSelected(false);
00268 
00269             /* Plain Text Fields */
00270             operatorField.setText("");
00271             dateField.setText("");
00272             rockTypeField.setText("");
00273             areaField.setText("");
00274             siteField.setText("");
00275             commentArea.setText("");
00276 
00277             /* Number Fields */
00278             latitudeField.setValue(null);
00279             longitudeField.setValue(null);
00280             strikeField.setValue(null);
00281             dipField.setValue(null);
00282             massField.setValue(null);
00283             volumeField.setValue(null);
00284             susceptibilityField.setValue(null);
00285         }
00286 
00287         // prevent the saving of unchanged values
00288         propertiesModified = false;
00289         parametersModified = false;
00290     }
00291 
00295     private void initSaveProperties() {
00296         propertiesModified = true;
00297     }
00298 
00302     private void initSaveParameters() {
00303         parametersModified = true;
00304     }
00305 
00312     private void saveProperties() {
00313         if (!propertiesModified) {
00314             return;
00315         }
00316 
00317         /* Radio Button Groups */
00318         if (measurementTypeAuto.isSelected()) {
00319             getProject().setProperty(Project.MEASUREMENT_TYPE_PROPERTY, Project.MEASUREMENT_TYPE_AUTO_VALUE);
00320         }
00321         if (measurementTypeManual.isSelected()) {
00322             getProject().setProperty(Project.MEASUREMENT_TYPE_PROPERTY, Project.MEASUREMENT_TYPE_MANUAL_VALUE);
00323         }
00324 
00325         /* Plain Text Fields */
00326         getProject().setProperty(Project.OPERATOR_PROPERTY, operatorField.getText());
00327         getProject().setProperty(Project.DATE_PROPERTY, dateField.getText());
00328         getProject().setProperty(Project.ROCK_TYPE_PROPERTY, rockTypeField.getText());
00329         getProject().setProperty(Project.AREA_PROPERTY, areaField.getText());
00330         getProject().setProperty(Project.SITE_PROPERTY, siteField.getText());
00331         getProject().setProperty(Project.COMMENT_PROPERTY, commentArea.getText());
00332 
00333         /* Number Fields */
00334         getProject().setProperty(Project.LATITUDE_PROPERTY, latitudeField.getText());
00335         getProject().setProperty(Project.LONGITUDE_PROPERTY, longitudeField.getText());
00336 
00337         propertiesModified = false;
00338     }
00339 
00346     private void saveParameters() {
00347         if (!parametersModified) {
00348             return;
00349         }
00350 
00351         /* Radio Button Groups */
00352         if (sampleTypeHand.isSelected()) {
00353             getProject().setSampleType(Project.SampleType.HAND);
00354         }
00355         if (sampleTypeCore.isSelected()) {
00356             getProject().setSampleType(Project.SampleType.CORE);
00357         }
00358         if (normalizationVolume.isSelected()) {
00359             getProject().setNormalization(Project.Normalization.VOLUME);
00360         }
00361         if (normalizationMass.isSelected()) {
00362             getProject().setNormalization(Project.Normalization.MASS);
00363         }
00364 
00365         /* Number-only Text Fields */
00366         Number value;
00367         value = (Number) strikeField.getValue();
00368         getProject().setStrike(value.doubleValue());
00369         value = (Number) dipField.getValue();
00370         getProject().setDip(value.doubleValue());
00371         value = (Number) massField.getValue();
00372         getProject().setMass(value.doubleValue());
00373         value = (Number) volumeField.getValue();
00374         getProject().setVolume(value.doubleValue());
00375         value = (Number) susceptibilityField.getValue();
00376         getProject().setSusceptibility(value.doubleValue());
00377 
00378         parametersModified = false;
00379     }
00380 
00381     {
00382 // GUI initializer generated by IntelliJ IDEA GUI Designer
00383 // !!! IMPORTANT !!!
00384 // DO NOT EDIT OR ADD ANY CODE HERE!
00385         $$$setupUI$$$();
00386     }
00387 
00392     private void $$$setupUI$$$() {
00393         contentPane = new JPanel();
00394         contentPane.setLayout(new GridLayoutManager(15, 5, new Insets(0, 0, 0, 0), 4, 4));
00395         siteField = new JTextField();
00396         contentPane.add(siteField,
00397                 new GridConstraints(4, 1, 1, 4, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00398                         GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00399                         new Dimension(70, -1), null));
00400         areaField = new JTextField();
00401         contentPane.add(areaField,
00402                 new GridConstraints(3, 1, 1, 4, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00403                         GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00404                         new Dimension(70, -1), null));
00405         final JPanel panel1 = new JPanel();
00406         panel1.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), 4, 4));
00407         contentPane.add(panel1,
00408                 new GridConstraints(1, 1, 1, 4, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00409                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null));
00410         measurementTypeAuto = new JRadioButton();
00411         measurementTypeAuto.setText("Auto");
00412         panel1.add(measurementTypeAuto,
00413                 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00414                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00415                         GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00416         measurementTypeManual = new JRadioButton();
00417         measurementTypeManual.setText("Manual");
00418         panel1.add(measurementTypeManual,
00419                 new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00420                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00421                         GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00422         final Spacer spacer1 = new Spacer();
00423         panel1.add(spacer1,
00424                 new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00425                         GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null));
00426         final Spacer spacer2 = new Spacer();
00427         contentPane.add(spacer2,
00428                 new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
00429                         GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 15), null));
00430         final JPanel panel2 = new JPanel();
00431         panel2.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), 4, 4));
00432         contentPane.add(panel2,
00433                 new GridConstraints(12, 1, 1, 4, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00434                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null));
00435         final Spacer spacer3 = new Spacer();
00436         panel2.add(spacer3,
00437                 new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00438                         GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null));
00439         normalizationMass = new JRadioButton();
00440         normalizationMass.setText("Mass");
00441         panel2.add(normalizationMass,
00442                 new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00443                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00444                         GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00445         normalizationVolume = new JRadioButton();
00446         normalizationVolume.setText("Volume");
00447         panel2.add(normalizationVolume,
00448                 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00449                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00450                         GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00451         latitudeField = new JFormattedTextField();
00452         contentPane.add(latitudeField,
00453                 new GridConstraints(8, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00454                         GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00455                         new Dimension(40, -1), null));
00456         longitudeField = new JFormattedTextField();
00457         contentPane.add(longitudeField,
00458                 new GridConstraints(8, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00459                         GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00460                         new Dimension(40, -1), null));
00461         strikeField = new JFormattedTextField();
00462         contentPane.add(strikeField,
00463                 new GridConstraints(9, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00464                         GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00465                         new Dimension(40, -1), null));
00466         final JLabel label1 = new JLabel();
00467         label1.setText("Dip");
00468         contentPane.add(label1,
00469                 new GridConstraints(9, 3, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00470                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00471         dipField = new JFormattedTextField();
00472         contentPane.add(dipField,
00473                 new GridConstraints(9, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00474                         GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00475                         new Dimension(40, -1), null));
00476         volumeField = new JFormattedTextField();
00477         contentPane.add(volumeField,
00478                 new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00479                         GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00480                         new Dimension(40, -1), null));
00481         massField = new JFormattedTextField();
00482         contentPane.add(massField,
00483                 new GridConstraints(10, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00484                         GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00485                         new Dimension(40, -1), null));
00486         susceptibilityField = new JFormattedTextField();
00487         contentPane.add(susceptibilityField,
00488                 new GridConstraints(11, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00489                         GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00490                         new Dimension(40, -1), null));
00491         final Spacer spacer4 = new Spacer();
00492         contentPane.add(spacer4,
00493                 new GridConstraints(13, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
00494                         GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 15), null));
00495         final JLabel label2 = new JLabel();
00496         label2.setText("Volume (cm³)");
00497         contentPane.add(label2,
00498                 new GridConstraints(10, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00499                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00500         final JLabel label3 = new JLabel();
00501         label3.setText("Susceptibility");
00502         contentPane.add(label3,
00503                 new GridConstraints(11, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00504                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00505         final JLabel label4 = new JLabel();
00506         label4.setText("Normalize by");
00507         contentPane.add(label4,
00508                 new GridConstraints(12, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00509                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00510         final JLabel label5 = new JLabel();
00511         label5.setText("Comments");
00512         contentPane.add(label5,
00513                 new GridConstraints(14, 0, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_NONE,
00514                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00515         final JLabel label6 = new JLabel();
00516         label6.setText("Longitude");
00517         contentPane.add(label6,
00518                 new GridConstraints(8, 3, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00519                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00520         final JLabel label7 = new JLabel();
00521         label7.setText("Operator / Date");
00522         contentPane.add(label7,
00523                 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00524                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00525         final JLabel label8 = new JLabel();
00526         label8.setText("Measurement type");
00527         contentPane.add(label8,
00528                 new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00529                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00530         final JLabel label9 = new JLabel();
00531         label9.setText("Site");
00532         contentPane.add(label9,
00533                 new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00534                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00535         final JLabel label10 = new JLabel();
00536         label10.setText("Area");
00537         contentPane.add(label10,
00538                 new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00539                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00540         final JLabel label11 = new JLabel();
00541         label11.setText("Latitude");
00542         contentPane.add(label11,
00543                 new GridConstraints(8, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00544                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00545         final JLabel label12 = new JLabel();
00546         label12.setText("Strike");
00547         contentPane.add(label12,
00548                 new GridConstraints(9, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00549                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00550         final JLabel label13 = new JLabel();
00551         label13.setText("Mass (grams)");
00552         contentPane.add(label13,
00553                 new GridConstraints(10, 3, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00554                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00555         final JPanel panel3 = new JPanel();
00556         panel3.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), 4, 0));
00557         contentPane.add(panel3,
00558                 new GridConstraints(0, 1, 1, 4, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00559                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null));
00560         operatorField = new JTextField();
00561         panel3.add(operatorField,
00562                 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00563                         GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00564                         new Dimension(70, -1), null));
00565         dateField = new JTextField();
00566         panel3.add(dateField,
00567                 new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00568                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(80, -1),
00569                         null));
00570         final JLabel label14 = new JLabel();
00571         label14.setText("/");
00572         panel3.add(label14,
00573                 new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE,
00574                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00575         final JScrollPane scrollPane1 = new JScrollPane();
00576         scrollPane1.setEnabled(true);
00577         scrollPane1.setHorizontalScrollBarPolicy(31);
00578         contentPane.add(scrollPane1,
00579                 new GridConstraints(14, 1, 1, 4, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00580                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW,
00581                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW,
00582                         new Dimension(-1, 50), null, null));
00583         commentArea = new JTextArea();
00584         commentArea.setLineWrap(true);
00585         commentArea.setRows(3);
00586         scrollPane1.setViewportView(commentArea);
00587         rockTypeField = new JTextField();
00588         contentPane.add(rockTypeField,
00589                 new GridConstraints(6, 1, 1, 4, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
00590                         GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
00591                         new Dimension(70, -1), null));
00592         final JLabel label15 = new JLabel();
00593         label15.setText("Rock type");
00594         contentPane.add(label15,
00595                 new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00596                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00597         final JLabel label16 = new JLabel();
00598         label16.setText("Sample type");
00599         contentPane.add(label16,
00600                 new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
00601                         GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00602         final JPanel panel4 = new JPanel();
00603         panel4.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), 4, 4));
00604         contentPane.add(panel4,
00605                 new GridConstraints(5, 1, 1, 4, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
00606                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null));
00607         final Spacer spacer5 = new Spacer();
00608         panel4.add(spacer5,
00609                 new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00610                         GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null));
00611         sampleTypeCore = new JRadioButton();
00612         sampleTypeCore.setText("Core");
00613         panel4.add(sampleTypeCore,
00614                 new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00615                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00616                         GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00617         sampleTypeHand = new JRadioButton();
00618         sampleTypeHand.setText("Hand");
00619         panel4.add(sampleTypeHand,
00620                 new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
00621                         GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
00622                         GridConstraints.SIZEPOLICY_FIXED, null, null, null));
00623         final Spacer spacer6 = new Spacer();
00624         contentPane.add(spacer6,
00625                 new GridConstraints(10, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
00626                         GridConstraints.SIZEPOLICY_FIXED, 1, null, new Dimension(4, -1), null));
00627         final Spacer spacer7 = new Spacer();
00628         contentPane.add(spacer7,
00629                 new GridConstraints(7, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
00630                         GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 15), null));
00631     }
00632 
00638     private class MyFormatterFactory extends JFormattedTextField.AbstractFormatterFactory {
00647         public JFormattedTextField.AbstractFormatter getFormatter(final JFormattedTextField tf) {
00648             NumberFormatter formatter;
00649             DecimalFormat format;
00650 
00651             if (tf == latitudeField || tf == longitudeField) {
00652                 // allow null values
00653                 format = new NullableDecimalFormat();
00654             } else if (tf == massField || tf == volumeField || tf == susceptibilityField) {
00655                 // show only positive numbers
00656                 format = new PositiveDecimalFormat();
00657             } else {
00658                 // show all numbers
00659                 format = new DecimalFormat();
00660             }
00661             format.setGroupingUsed(true);
00662             format.setMaximumFractionDigits(6);
00663             formatter = new NumberFormatter(format);
00664 
00665             // set value ranges
00666             if (tf == strikeField) {
00667                 formatter.setMinimum(new Double(0));
00668                 formatter.setMaximum(new Double(360));
00669             } else if (tf == dipField) {
00670                 formatter.setMinimum(new Double(0));
00671                 formatter.setMaximum(new Double(180));
00672             }
00673 
00674             // commit changes when pressing enter
00675             tf.addActionListener(new ActionListener() {
00676                 public void actionPerformed(ActionEvent e) {
00677                     try {
00678                         tf.commitEdit();
00679                     } catch (ParseException e1) {
00680                         e1.printStackTrace();
00681                     }
00682                 }
00683             });
00684             return formatter;
00685         }
00686     }
00687 }

Generated on Fri May 6 16:00:32 2005 for Squid by  doxygen 1.4.1