KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > sheet > MeterIntervalsSheetPropertyComponent


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * MeterIntervalsSheetPropertyComponent.java
28  *
29  * Created on 15 agosto 2005, 13.32
30  *
31  */

32
33 package it.businesslogic.ireport.gui.sheet;
34
35 import it.businesslogic.ireport.chart.MeterInterval;
36 import it.businesslogic.ireport.chart.SeriesColor;
37 import it.businesslogic.ireport.gui.FieldPatternDialog;
38 import it.businesslogic.ireport.gui.MainFrame;
39 import java.awt.Color JavaDoc;
40 import java.awt.Dialog JavaDoc;
41 import java.awt.Frame JavaDoc;
42 import java.awt.Window JavaDoc;
43 import java.awt.event.ActionEvent JavaDoc;
44 import java.util.List JavaDoc;
45 import javax.swing.BoxLayout JavaDoc;
46 import javax.swing.JOptionPane JavaDoc;
47 import javax.swing.SwingUtilities JavaDoc;
48 import it.businesslogic.ireport.util.I18n;
49
50 /**
51  *
52  * @author Administrator
53  */

54 public class MeterIntervalsSheetPropertyComponent extends javax.swing.JPanel JavaDoc {
55     
56     private java.util.List JavaDoc listOfMeterIntervals = new java.util.ArrayList JavaDoc();
57     
58     private boolean init = false;
59      
60     /** Creates new form ExpressionSheetPanel */
61     public MeterIntervalsSheetPropertyComponent() {
62         initComponents();
63         
64         //javax.swing.BoxLayout bl = new javax.swing.BoxLayout(jPanelColors,javax.swing.BoxLayout.X_AXIS);
65
//jPanelColors.setLayout(bl);
66
applyI18n();
67         setListOfMeterIntervals(listOfMeterIntervals);
68     }
69     
70     
71     /** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the Form Editor.
75      */

76     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
77
private void initComponents() {
78         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
79
80         jPanelColors = new javax.swing.JPanel JavaDoc();
81         jPanelSample = new javax.swing.JPanel JavaDoc();
82         jPanelSpacer = new javax.swing.JPanel JavaDoc();
83         jButton1 = new javax.swing.JButton JavaDoc();
84
85         setLayout(new java.awt.GridBagLayout JavaDoc());
86
87         setBackground(new java.awt.Color JavaDoc(255, 255, 255));
88         jPanelColors.setLayout(new javax.swing.BoxLayout JavaDoc(jPanelColors, javax.swing.BoxLayout.X_AXIS));
89
90         jPanelColors.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
91         jPanelSample.setBorder(new javax.swing.border.LineBorder JavaDoc(new java.awt.Color JavaDoc(0, 0, 0), 1, true));
92         jPanelSample.setMaximumSize(new java.awt.Dimension JavaDoc(12, 12));
93         jPanelColors.add(jPanelSample);
94
95         jPanelSpacer.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
96         jPanelColors.add(jPanelSpacer);
97
98         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
99         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
100         gridBagConstraints.weightx = 1.0;
101         gridBagConstraints.weighty = 1.0;
102         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 4, 2, 4);
103         add(jPanelColors, gridBagConstraints);
104
105         jButton1.setText("...");
106         jButton1.setMaximumSize(new java.awt.Dimension JavaDoc(19, 10));
107         jButton1.setMinimumSize(new java.awt.Dimension JavaDoc(19, 10));
108         jButton1.setPreferredSize(new java.awt.Dimension JavaDoc(19, 10));
109         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
110             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
111                 jButton1ActionPerformed(evt);
112             }
113         });
114
115         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
116         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
117         gridBagConstraints.weighty = 1.0;
118         add(jButton1, gridBagConstraints);
119
120     }// </editor-fold>//GEN-END:initComponents
121

122     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
123

124         MeterIntervalsDialog dialog = null;
125         Window JavaDoc topLevel = SwingUtilities.getWindowAncestor(this);
126  
127         if (topLevel == null)
128         {
129             dialog = new MeterIntervalsDialog((Frame)null,true);
130         }
131         else if (topLevel instanceof Frame) {
132             dialog = new MeterIntervalsDialog((Frame)topLevel, true);
133         }
134         else if (topLevel instanceof Dialog) {
135             dialog = new MeterIntervalsDialog((Dialog)topLevel, true);
136         }
137         
138         dialog.setMeterIntervals(listOfMeterIntervals );
139         dialog.setVisible(true);
140         
141         if (dialog.getDialogResult() == JOptionPane.OK_OPTION)
142         {
143             this.setListOfMeterIntervals( dialog.getMeterIntervals());
144             fireActionListenerActionPerformed( new ActionEvent JavaDoc(this,0,"") );
145         }
146         
147     }//GEN-LAST:event_jButton1ActionPerformed
148

149     
150     // Variables declaration - do not modify//GEN-BEGIN:variables
151
private javax.swing.JButton JavaDoc jButton1;
152     private javax.swing.JPanel JavaDoc jPanelColors;
153     private javax.swing.JPanel JavaDoc jPanelSample;
154     private javax.swing.JPanel JavaDoc jPanelSpacer;
155     // End of variables declaration//GEN-END:variables
156

157     /**
158      * Utility field used by event firing mechanism.
159      */

160     private javax.swing.event.EventListenerList JavaDoc listenerList = null;
161
162     /**
163      * Registers ActionListener to receive events.
164      * @param listener The listener to register.
165      */

166     public synchronized void addActionListener(java.awt.event.ActionListener JavaDoc listener) {
167
168         if (listenerList == null ) {
169             listenerList = new javax.swing.event.EventListenerList JavaDoc();
170         }
171         listenerList.add (java.awt.event.ActionListener JavaDoc.class, listener);
172     }
173
174     /**
175      * Removes ActionListener from the list of listeners.
176      * @param listener The listener to remove.
177      */

178     public synchronized void removeActionListener(java.awt.event.ActionListener JavaDoc listener) {
179
180         listenerList.remove (java.awt.event.ActionListener JavaDoc.class, listener);
181     }
182
183     /**
184      * Notifies all registered listeners about the event.
185      *
186      * @param event The event to be fired
187      */

188     private void fireActionListenerActionPerformed(java.awt.event.ActionEvent JavaDoc event) {
189
190         if (listenerList == null) return;
191         Object JavaDoc[] listeners = listenerList.getListenerList ();
192         for (int i = listeners.length - 2; i >= 0; i -= 2) {
193             if (listeners[i]==java.awt.event.ActionListener JavaDoc.class) {
194                 ((java.awt.event.ActionListener JavaDoc)listeners[i+1]).actionPerformed (event);
195             }
196         }
197     }
198
199     public boolean isInit() {
200         return init;
201     }
202
203     public void setInit(boolean init) {
204         this.init = init;
205     }
206
207     public java.util.List JavaDoc getListOfMeterIntervals() {
208         return listOfMeterIntervals;
209     }
210
211     public void setListOfMeterIntervals(java.util.List JavaDoc listOfMeterIntervals) {
212         
213         if (listOfMeterIntervals == null || !(listOfMeterIntervals instanceof List JavaDoc)) return;
214         
215         this.listOfMeterIntervals = listOfMeterIntervals;
216         
217         // Remove all panels...
218
jPanelColors.removeAll();
219         // Add all panels from the list..
220
//jPanelColors.setLayout(new javax.swing.BoxLayout(jPanelColors, javax.swing.BoxLayout.X_AXIS));
221

222         //java.awt.GridBagConstraints gridBagConstraints = null;
223
for (int i=0; i<listOfMeterIntervals.size(); ++i)
224         {
225             MeterInterval mi = (MeterInterval)listOfMeterIntervals.get(i);
226             javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc();
227             panel.setMinimumSize(new java.awt.Dimension JavaDoc(4,12));
228             panel.setPreferredSize(new java.awt.Dimension JavaDoc(12,12));
229             panel.setMaximumSize(new java.awt.Dimension JavaDoc(12,12));
230             
231             Color c = mi.getColor()==null ? Color.gray : Color.black;
232             
233             panel.setBorder(new javax.swing.border.LineBorder JavaDoc(c, 1, true));
234             panel.setBackground( mi.getColor() );
235             
236             //gridBagConstraints = new java.awt.GridBagConstraints();
237
//gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 1);
238
jPanelColors.add(panel); //, gridBagConstraints);
239
jPanelColors.add(javax.swing.Box.createRigidArea(new java.awt.Dimension JavaDoc(1,0)));
240         }
241         
242         
243         //gridBagConstraints = new java.awt.GridBagConstraints();
244
//gridBagConstraints.weightx = 1.0;
245
//jPanelColors.add(jPanelSpacer, gridBagConstraints);
246
jPanelColors.updateUI();
247         // Add the spacer..
248
}
249     
250     public void applyI18n(){
251                 // Start autogenerated code ----------------------
252
jButton1.setText(I18n.getString("meterIntervalsSheetPropertyComponent.button1","..."));
253                 // End autogenerated code ----------------------
254
}
255 }
256
Popular Tags