KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > ChartCustomizer


1 package com.calipso.reportgenerator.userinterface;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.ActionListener JavaDoc;
6 import java.awt.event.ActionEvent JavaDoc;
7 import java.awt.event.KeyListener JavaDoc;
8 import java.awt.event.KeyEvent JavaDoc;
9
10 /**
11  * Presenta un GUI que permite customizar un chart
12  */

13
14 public class ChartCustomizer extends JDialog implements ActionListener JavaDoc, KeyListener JavaDoc{
15
16   private JPanel colorPanel;
17   private JPanel checkBoxPanel;
18   private JPanel btsPanel;
19   private JButton btAccept;
20   private JButton btCancel;
21   private JCheckBox checkBoxLegend;
22   private JCheckBox checkBoxToolTips;
23   private JCheckBox checkBoxMultipleAxis;
24   private JButton btColor;
25   private Color color;
26   private boolean legend;
27   private boolean tooltips;
28   private boolean multipleAxis;
29   private Point locationPoint;
30
31
32   /**
33    * Crea una instancia de ChartCustomizer
34    * @param owner
35    * @param modal
36    * @throws HeadlessException
37    */

38   public ChartCustomizer(Frame owner, boolean modal) throws HeadlessException {
39     super(owner, modal);
40     setColor(Color.white);
41     initialize();
42     setLegend(checkBoxLegend.isSelected());
43     setTooltips(checkBoxToolTips.isSelected());
44     setMultipleAxis(checkBoxMultipleAxis.isSelected());
45
46     setLocation(getDefaultLocation());
47   }
48
49   /**
50    * Obtiene la localizacion del GUI para ubicarlo
51    * correctamente en la pantalla.
52    * @return
53    */

54   private Point getDefaultLocation() {
55     Point ownerLocation = getOwner().getLocation();
56     Dimension ownerSize = getOwner().getSize();
57     Dimension size = getSize();
58
59     int x = ownerLocation.x + ownerSize.width / 2 - size.width / 2;
60     int y = ownerLocation.y + ownerSize.height / 2 - size.height / 2;
61     return new Point(x, y);
62   }
63
64   /**
65    * Inicializa el GUI. Crea todos los componentes necesarios.
66    */

67   private void initialize(){
68     colorPanel = new JPanel(new BorderLayout());
69     btColor = new JButton("Color...");
70     btColor.addActionListener(this);
71     btColor.addKeyListener(this);
72     colorPanel.add(btColor);
73
74     checkBoxPanel = new JPanel(new GridLayout(3, 2));
75     checkBoxLegend = new JCheckBox();
76     checkBoxToolTips = new JCheckBox();
77     checkBoxMultipleAxis = new JCheckBox();
78
79     checkBoxPanel.add(new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("235")));
80     checkBoxPanel.add(checkBoxLegend);
81     checkBoxPanel.add(new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("236")));
82     checkBoxPanel.add(checkBoxToolTips);
83     checkBoxPanel.add(new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("391")));
84     checkBoxPanel.add(checkBoxMultipleAxis);
85
86     checkBoxLegend.setSelected(true);
87     checkBoxToolTips.setSelected(true);
88     checkBoxMultipleAxis.setSelected(false);
89
90     btAccept = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("112"));
91     btAccept.addActionListener(this);
92     btAccept.addKeyListener(this);
93     btCancel = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("113"));
94     btCancel.addActionListener(this);
95     btCancel.addKeyListener(this);
96     btsPanel = new JPanel(new FlowLayout());
97     btsPanel.add(btAccept);
98     btsPanel.add(btCancel);
99
100     this.getContentPane().add(colorPanel, BorderLayout.NORTH);
101     this.getContentPane().add(checkBoxPanel, BorderLayout.CENTER);
102     this.getContentPane().add(btsPanel, BorderLayout.SOUTH);
103
104     this.pack();
105   }
106
107   /**
108    * Intercepta los eventos del mouse y setea las propiedades
109    * seleccionadas en el GUI.
110    * @param ae
111    */

112   public void actionPerformed(ActionEvent JavaDoc ae) {
113     if(ae.getSource() == btAccept){
114       setLegend(checkBoxLegend.isSelected());
115       setTooltips(checkBoxToolTips.isSelected());
116       setMultipleAxis(checkBoxMultipleAxis.isSelected());
117       this.dispose();
118     }else if(ae.getSource() == btColor){
119       setColor(JColorChooser.showDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("237"), Color.white));
120     }else if(ae.getSource() == btCancel){
121       this.dispose();
122     }
123   }
124
125   /**
126    * Obtiene el color del background del chart
127    * @return
128    */

129   public Color getColor() {
130     return color;
131   }
132
133   /**
134    * Asigna el color del background del chart
135    * @param color
136    */

137   public void setColor(Color color) {
138     this.color = color;
139   }
140
141   /**
142    * Devuelve un booleano que indica si se ha
143    * seleccionado la leyenda.
144    * @return
145    */

146   public boolean isLegend() {
147     return legend;
148   }
149
150   /**
151    * Asigna un boolean de acuerdo a si se ha
152    * seleccionado la leyenda.
153    * @param legend
154    */

155   public void setLegend(boolean legend) {
156     this.legend = legend;
157   }
158
159   /**
160    * Devuelve un booleano que indica si se ha
161    * seleccionado toolTips.
162    * @return
163    */

164   public boolean isTooltips() {
165     return tooltips;
166   }
167   /**
168    * Asigna un boolean de acuerdo a si se ha
169    * seleccionado toolTips.
170    * @param tooltips
171    */

172   public void setTooltips(boolean tooltips) {
173     this.tooltips = tooltips;
174   }
175
176   public void setMultipleAxis(boolean checkBoxMultipleAxis) {
177     this.multipleAxis = checkBoxMultipleAxis;
178   }
179
180   /**
181    * Intercepta eventos del teclado.
182    * @param e
183    */

184   public void keyTyped(KeyEvent JavaDoc e) {
185   }
186
187   /**
188    * Intercepta los eventos del teclado y setea
189    * propiedades de acuerdo a lo seleccionado.
190    * @param e
191    */

192   public void keyPressed(KeyEvent JavaDoc e) {
193     if(e.getSource() == btAccept){
194       setLegend(checkBoxLegend.isSelected());
195       setTooltips(checkBoxToolTips.isSelected());
196       setMultipleAxis(checkBoxMultipleAxis.isSelected());
197       this.dispose();
198     }else if(e.getSource() == btCancel){
199       this.dispose();
200     }else if(e.getSource() == btColor){
201       setColor(JColorChooser.showDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("237"), Color.white));
202     }
203   }
204
205   /**
206    * Intercepta eventos del teclado.
207    * @param e
208    */

209   public void keyReleased(KeyEvent JavaDoc e) {
210   }
211
212   public boolean isMultipleAxis() {
213     return multipleAxis;
214   }
215 }
216
Popular Tags