Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jplot/PiperOptions.java


1   /*
2    * JPLOT  -- Java Plotting Interface for any programme or
3    *           as an independent GUI
4    * 
5    * Copyright (C) 1999 Jan van der Lee
6    *
7    * This program is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation; either version 2
10   * of the License, or (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
20   * 02111-1307, USA.
21   *
22   * Send bugs, suggestions or queries to <jplot@cig.ensmp.fr>
23   * The latest releases are found at 
24   * http://www.cig.ensmp.fr/~vanderlee/jplot.html
25   *
26   * Initally developed for use by the Centre d'Informatique Geologique 
27   * Ecole des Mines de Paris, Fontainebleau, France.
28   */
29  
30  package jplot;
31  
32  import java.awt.*;
33  import java.util.*;
34  import javax.swing.*;
35  import java.awt.geom.*;
36  import java.awt.event.*;
37  import javax.swing.border.*;
38  
39  /**
40   * Here we create a panel which allows a user to modify several
41   * parameters specific to piper diagrams.
42   * Calling the <code>show</code> method pops up a frame (dialog) which
43   * includes the panel.
44   */
45  public class PiperOptions extends JPanel {
46  
47    private JDialog dialog;
48  
49    private JCheckBox cb_showTds, cb_hideTds;
50    private JTextField scalingField;
51    private GraphPars gp;
52    private JPlot jplot;
53    
54    /**
55     * Principal constructor. Builds a panel with Piper diagram options.
56     * @param gp instance of the object containing all graphical parameters
57     */
58    public PiperOptions (JPlot jp, GraphPars _gp) {
59      gp = _gp;
60      jplot = jp;
61      dialog = null;
62      //setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
63  
64      GriddedPanel p = new GriddedPanel();
65      p.setBorder(new EmptyBorder(new Insets(5,5,5,5)));
66  
67      Dimension cbField = new Dimension(110,20);
68      //Dimension shortField = new Dimension(80,22);
69  
70      ButtonGroup bg = new ButtonGroup();
71      cb_showTds = new JCheckBox("Show");
72      bg.add(cb_showTds);
73      cb_hideTds = new JCheckBox("Hide");
74      bg.add(cb_hideTds);
75      scalingField = new JTextField();
76      scalingField.setColumns(6);
77      //scalingField.setPreferredSize(shortField);
78      JPanel scalingPanel = new JPanel(new BorderLayout());
79      scalingPanel.add(Utils.makeLabel("scaling"),BorderLayout.WEST);
80      scalingPanel.add(scalingField,BorderLayout.CENTER);
81  
82      // spacing between labels and fields:
83      EmptyBorder border = new EmptyBorder(new Insets(0,0,0,10));
84  
85      // place the widgets in the panel:
86      JLabel label = new JLabel("Total Dissolved Solids:");
87      label.setBorder(border);
88      p.addComponent(label,1,1);
89      p.addComponent(cb_showTds,1,2);
90      p.addComponent(cb_hideTds,1,3);
91      p.addComponent(scalingPanel,2,2);
92      add(p);
93    }
94  
95    /**
96     * Updates the panel with the current graphical parameters.
97     */
98    public void refresh() {
99      cb_showTds.setSelected(gp.drawTds());
100     cb_hideTds.setSelected(!gp.drawTds());
101     scalingField.setText(Float.toString(gp.getTdsFactor()));
102   }
103 
104   public void setValues() {
105     gp.setDrawTds(cb_showTds.isSelected());
106     gp.setTdsFactor(Float.parseFloat(scalingField.getText()));
107   }
108 
109  /**
110    * Return a modal JDialog.
111    * @param parent frame which is the parent of this dialog.
112    * @param x x-position of the upper left corner
113    * @param y y-position of the upper left corner
114    */
115   public void show(Frame parent, int x, int y) {
116     if (dialog == null) {
117       dialog = new JDialog(parent,"Piper diagram options",true);
118       dialog.addWindowListener(new WindowAdapter() {
119   public void windowClosing(WindowEvent e) {
120     dialog.dispose();
121   }
122       });
123 
124       JPanel p = new JPanel(new FlowLayout());
125       p.setBorder(BorderFactory.createEtchedBorder());
126       JButton b = new JButton("Apply");
127       b.addActionListener(new ActionListener() {
128     public void actionPerformed(ActionEvent e) {
129       setValues();
130       gp.setDataChanged(true);
131       jplot.updateGraphIfShowing();
132       dialog.dispose();
133     }
134   });
135       p.add(b);
136       b = new JButton("Dismiss");
137       b.addActionListener(new ActionListener() {
138     public void actionPerformed(ActionEvent e) {
139       dialog.dispose();
140     }
141   });
142       p.add(b);
143       dialog.getContentPane().add(this,BorderLayout.CENTER);
144       dialog.getContentPane().add(p,BorderLayout.SOUTH);
145       dialog.setLocation(x,y);
146       dialog.pack();
147     }
148     refresh();
149     dialog.show();  // blocks until user brings dialog down.
150   }
151 }
152 
153 
154 
155 
156 
157 
158 
159 
160