source: ether_statistics/service/implementation/gov/noaa/pmel/sgt/swing/prop/ColorDialog.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 4.5 KB
Line 
1/*
2 * $Id: ColorDialog.java,v 1.2 2003/08/22 23:02:39 dwd Exp $
3 *
4 * This software is provided by NOAA for full, free and open release.  It is
5 * understood by the recipient/user that NOAA assumes no liability for any
6 * errors contained in the code.  Although this software is released without
7 * conditions or restrictions in its use, it is expected that appropriate
8 * credit be given to its author and to the National Oceanic and Atmospheric
9 * Administration should the software be included by the recipient as an
10 * element in other product development.
11 */
12
13package gov.noaa.pmel.sgt.swing.prop;
14
15import java.awt.*;
16import javax.swing.*;
17import java.awt.event.*;
18import javax.swing.border.*;
19
20/**
21 * @author Donald Denbo
22 * @version $Revision: 1.2 $, $Date: 2003/08/22 23:02:39 $
23 * @since 3.0
24 **/
25public class ColorDialog extends JDialog {
26  private JPanel panel1 = new JPanel();
27  private JColorChooser colorChooserPanel = new JColorChooser();
28  private JPanel alphaPanel = new JPanel();
29  private JPanel buttonPanel = new JPanel();
30  private JButton cancelButton = new JButton();
31  private JButton okButton = new JButton();
32  private TitledBorder titledBorder1;
33  private JLabel jLabel1 = new JLabel();
34  private Border border1;
35  private GridBagLayout gridBagLayout1 = new GridBagLayout();
36  private JTextField alphaTF = new JTextField();
37  private GridBagLayout gridBagLayout2 = new GridBagLayout();
38
39  private Color color_ = null;
40
41  public ColorDialog(Dialog dialog,  String title, boolean modal) {
42    super(dialog, title, modal);
43    init(dialog);
44  }
45
46  public ColorDialog(Frame frame, String title, boolean modal) {
47    super(frame, title, modal);
48    init(frame);
49  }
50
51  private void init(Window win) {
52    try {
53      jbInit();
54      pack();
55    }
56    catch(Exception ex) {
57      ex.printStackTrace();
58    }
59    if(win != null) {
60      Rectangle fBounds = win.getBounds();
61      Point fLoc = win.getLocationOnScreen();
62      Rectangle bounds = getBounds();
63      int x = fLoc.x + fBounds.width/2 - bounds.width/2;
64      int y = fLoc.y + fBounds.height/2 - bounds.height/2;
65      setLocation(x, y);
66    }
67  }
68
69  public ColorDialog() {
70    this((Frame)null, "", false);
71  }
72
73  private void jbInit() throws Exception {
74    titledBorder1 = new TitledBorder("");
75    border1 = BorderFactory.createLineBorder(Color.gray,1);
76    panel1.setLayout(gridBagLayout1);
77    buttonPanel.setBorder(BorderFactory.createEtchedBorder());
78    cancelButton.setText("Cancel");
79    cancelButton.addActionListener(new java.awt.event.ActionListener() {
80      public void actionPerformed(ActionEvent e) {
81        cancelButton_actionPerformed(e);
82      }
83    });
84    okButton.setText("OK");
85    okButton.addActionListener(new java.awt.event.ActionListener() {
86      public void actionPerformed(ActionEvent e) {
87        okButton_actionPerformed(e);
88      }
89    });
90    alphaPanel.setBorder(titledBorder1);
91    alphaPanel.setLayout(gridBagLayout2);
92    titledBorder1.setTitle("Alpha Channel");
93    titledBorder1.setBorder(border1);
94    jLabel1.setText("Alpha");
95    alphaTF.setText("0");
96    alphaTF.setColumns(5);
97    getContentPane().add(panel1);
98    panel1.add(colorChooserPanel,    new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
99            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
100    panel1.add(alphaPanel,    new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
101            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
102    alphaPanel.add(jLabel1,   new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
103            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 10, 5, 5), 0, 0));
104    alphaPanel.add(alphaTF,    new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
105            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 15), 0, 0));
106    panel1.add(buttonPanel,     new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0
107            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
108    buttonPanel.add(okButton, null);
109    buttonPanel.add(cancelButton, null);
110  }
111
112  void cancelButton_actionPerformed(ActionEvent e) {
113    setVisible(false);
114  }
115
116  void okButton_actionPerformed(ActionEvent e) {
117    Color temp = colorChooserPanel.getColor();
118    int alpha = Integer.parseInt(alphaTF.getText());
119    color_ = new Color(temp.getRed(), temp.getGreen(), temp.getBlue(), alpha);
120    setVisible(false);
121  }
122
123  public void setColor(Color color) {
124    color_ = color;
125    colorChooserPanel.setColor(color_);
126    alphaTF.setText(Integer.toString(color_.getAlpha()));
127  }
128
129  public Color getColor() {
130    return color_;
131  }
132}
Note: See TracBrowser for help on using the repository browser.