001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * MeterIntervalsSheetPropertyComponent.java
028: *
029: * Created on 15 agosto 2005, 13.32
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import it.businesslogic.ireport.chart.MeterInterval;
036: import it.businesslogic.ireport.chart.SeriesColor;
037: import it.businesslogic.ireport.gui.FieldPatternDialog;
038: import it.businesslogic.ireport.gui.MainFrame;
039: import java.awt.Color;
040: import java.awt.Dialog;
041: import java.awt.Frame;
042: import java.awt.Window;
043: import java.awt.event.ActionEvent;
044: import java.util.List;
045: import javax.swing.BoxLayout;
046: import javax.swing.JOptionPane;
047: import javax.swing.SwingUtilities;
048: import it.businesslogic.ireport.util.I18n;
049:
050: /**
051: *
052: * @author Administrator
053: */
054: public class MeterIntervalsSheetPropertyComponent extends
055: javax.swing.JPanel {
056:
057: private java.util.List listOfMeterIntervals = new java.util.ArrayList();
058:
059: private boolean init = false;
060:
061: /** Creates new form ExpressionSheetPanel */
062: public MeterIntervalsSheetPropertyComponent() {
063: initComponents();
064:
065: //javax.swing.BoxLayout bl = new javax.swing.BoxLayout(jPanelColors,javax.swing.BoxLayout.X_AXIS);
066: //jPanelColors.setLayout(bl);
067: applyI18n();
068: setListOfMeterIntervals(listOfMeterIntervals);
069: }
070:
071: /** This method is called from within the constructor to
072: * initialize the form.
073: * WARNING: Do NOT modify this code. The content of this method is
074: * always regenerated by the Form Editor.
075: */
076: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
077: private void initComponents() {
078: java.awt.GridBagConstraints gridBagConstraints;
079:
080: jPanelColors = new javax.swing.JPanel();
081: jPanelSample = new javax.swing.JPanel();
082: jPanelSpacer = new javax.swing.JPanel();
083: jButton1 = new javax.swing.JButton();
084:
085: setLayout(new java.awt.GridBagLayout());
086:
087: setBackground(new java.awt.Color(255, 255, 255));
088: jPanelColors.setLayout(new javax.swing.BoxLayout(jPanelColors,
089: javax.swing.BoxLayout.X_AXIS));
090:
091: jPanelColors.setBackground(new java.awt.Color(255, 255, 255));
092: jPanelSample.setBorder(new javax.swing.border.LineBorder(
093: new java.awt.Color(0, 0, 0), 1, true));
094: jPanelSample.setMaximumSize(new java.awt.Dimension(12, 12));
095: jPanelColors.add(jPanelSample);
096:
097: jPanelSpacer.setBackground(new java.awt.Color(255, 255, 255));
098: jPanelColors.add(jPanelSpacer);
099:
100: gridBagConstraints = new java.awt.GridBagConstraints();
101: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
102: gridBagConstraints.weightx = 1.0;
103: gridBagConstraints.weighty = 1.0;
104: gridBagConstraints.insets = new java.awt.Insets(2, 4, 2, 4);
105: add(jPanelColors, gridBagConstraints);
106:
107: jButton1.setText("...");
108: jButton1.setMaximumSize(new java.awt.Dimension(19, 10));
109: jButton1.setMinimumSize(new java.awt.Dimension(19, 10));
110: jButton1.setPreferredSize(new java.awt.Dimension(19, 10));
111: jButton1.addActionListener(new java.awt.event.ActionListener() {
112: public void actionPerformed(java.awt.event.ActionEvent evt) {
113: jButton1ActionPerformed(evt);
114: }
115: });
116:
117: gridBagConstraints = new java.awt.GridBagConstraints();
118: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
119: gridBagConstraints.weighty = 1.0;
120: add(jButton1, gridBagConstraints);
121:
122: }// </editor-fold>//GEN-END:initComponents
123:
124: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
125:
126: MeterIntervalsDialog dialog = null;
127: Window topLevel = SwingUtilities.getWindowAncestor(this );
128:
129: if (topLevel == null) {
130: dialog = new MeterIntervalsDialog((Frame) null, true);
131: } else if (topLevel instanceof Frame) {
132: dialog = new MeterIntervalsDialog((Frame) topLevel, true);
133: } else if (topLevel instanceof Dialog) {
134: dialog = new MeterIntervalsDialog((Dialog) topLevel, true);
135: }
136:
137: dialog.setMeterIntervals(listOfMeterIntervals);
138: if (meterIntervalsHilightExpression != null) {
139: dialog
140: .setFocusedExpression(meterIntervalsHilightExpression);
141: }
142: dialog.setVisible(true);
143:
144: if (dialog.getDialogResult() == JOptionPane.OK_OPTION) {
145: this .setListOfMeterIntervals(dialog.getMeterIntervals());
146: fireActionListenerActionPerformed(new ActionEvent(this , 0,
147: ""));
148: }
149:
150: }//GEN-LAST:event_jButton1ActionPerformed
151:
152: // Variables declaration - do not modify//GEN-BEGIN:variables
153: private javax.swing.JButton jButton1;
154: private javax.swing.JPanel jPanelColors;
155: private javax.swing.JPanel jPanelSample;
156: private javax.swing.JPanel jPanelSpacer;
157: // End of variables declaration//GEN-END:variables
158:
159: /**
160: * Utility field used by event firing mechanism.
161: */
162: private javax.swing.event.EventListenerList listenerList = null;
163:
164: /**
165: * Registers ActionListener to receive events.
166: * @param listener The listener to register.
167: */
168: public synchronized void addActionListener(
169: java.awt.event.ActionListener listener) {
170:
171: if (listenerList == null) {
172: listenerList = new javax.swing.event.EventListenerList();
173: }
174: listenerList.add(java.awt.event.ActionListener.class, listener);
175: }
176:
177: /**
178: * Removes ActionListener from the list of listeners.
179: * @param listener The listener to remove.
180: */
181: public synchronized void removeActionListener(
182: java.awt.event.ActionListener listener) {
183:
184: listenerList.remove(java.awt.event.ActionListener.class,
185: listener);
186: }
187:
188: /**
189: * Notifies all registered listeners about the event.
190: *
191: * @param event The event to be fired
192: */
193: private void fireActionListenerActionPerformed(
194: java.awt.event.ActionEvent event) {
195:
196: if (listenerList == null)
197: return;
198: Object[] listeners = listenerList.getListenerList();
199: for (int i = listeners.length - 2; i >= 0; i -= 2) {
200: if (listeners[i] == java.awt.event.ActionListener.class) {
201: ((java.awt.event.ActionListener) listeners[i + 1])
202: .actionPerformed(event);
203: }
204: }
205: }
206:
207: public boolean isInit() {
208: return init;
209: }
210:
211: public void setInit(boolean init) {
212: this .init = init;
213: }
214:
215: public java.util.List getListOfMeterIntervals() {
216: return listOfMeterIntervals;
217: }
218:
219: public void setListOfMeterIntervals(
220: java.util.List listOfMeterIntervals) {
221:
222: if (listOfMeterIntervals == null
223: || !(listOfMeterIntervals instanceof List))
224: return;
225:
226: this .listOfMeterIntervals = listOfMeterIntervals;
227:
228: // Remove all panels...
229: jPanelColors.removeAll();
230: // Add all panels from the list..
231: //jPanelColors.setLayout(new javax.swing.BoxLayout(jPanelColors, javax.swing.BoxLayout.X_AXIS));
232:
233: //java.awt.GridBagConstraints gridBagConstraints = null;
234: for (int i = 0; i < listOfMeterIntervals.size(); ++i) {
235: MeterInterval mi = (MeterInterval) listOfMeterIntervals
236: .get(i);
237: javax.swing.JPanel panel = new javax.swing.JPanel();
238: panel.setMinimumSize(new java.awt.Dimension(4, 12));
239: panel.setPreferredSize(new java.awt.Dimension(12, 12));
240: panel.setMaximumSize(new java.awt.Dimension(12, 12));
241:
242: Color c = mi.getColor() == null ? Color.gray : Color.black;
243:
244: panel.setBorder(new javax.swing.border.LineBorder(c, 1,
245: true));
246: panel.setBackground(mi.getColor());
247:
248: //gridBagConstraints = new java.awt.GridBagConstraints();
249: //gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 1);
250: jPanelColors.add(panel); //, gridBagConstraints);
251: jPanelColors.add(javax.swing.Box
252: .createRigidArea(new java.awt.Dimension(1, 0)));
253: }
254:
255: //gridBagConstraints = new java.awt.GridBagConstraints();
256: //gridBagConstraints.weightx = 1.0;
257: //jPanelColors.add(jPanelSpacer, gridBagConstraints);
258: jPanelColors.updateUI();
259: // Add the spacer..
260: }
261:
262: public void applyI18n() {
263: // Start autogenerated code ----------------------
264: jButton1.setText(I18n.getString(
265: "meterIntervalsSheetPropertyComponent.button1", "..."));
266: // End autogenerated code ----------------------
267: }
268:
269: private Object[] meterIntervalsHilightExpression = null;
270:
271: /**
272: * This method set the focus on a specific component.
273: *
274: * expressionInfo[0] can be something like:
275: * COMPONENT_DATASET_SPECIFIC_EXPRESSION, ...
276: *
277: * If it is COMPONENT_DATASET_SPECIFIC_EXPRESSION, other parameters are expected in the array...
278: */
279: public void setFocusedExpression(Object[] expressionInfo) {
280: meterIntervalsHilightExpression = expressionInfo;
281: jButton1ActionPerformed(null);
282: }
283: }
|