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: * MeterIntervalDialog.java
028: *
029: * Created on 17 agosto 2005, 11.19
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import it.businesslogic.ireport.SubDataset;
036: import it.businesslogic.ireport.chart.DataRange;
037: import it.businesslogic.ireport.chart.MeterInterval;
038: import it.businesslogic.ireport.util.Misc;
039: import javax.swing.SpinnerNumberModel;
040: import it.businesslogic.ireport.util.I18n;
041:
042: /**
043: *
044: * @author Administrator
045: */
046: public class MeterIntervalDialog extends javax.swing.JDialog {
047:
048: private MeterInterval meterInterval = null;
049:
050: private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
051:
052: /** Creates new form CategorySeriesDialog */
053: public MeterIntervalDialog(java.awt.Dialog parent, boolean modal) {
054: super (parent, modal);
055: initComponents();
056: applyI18n();
057:
058: this .setSize(500, 500);
059: it.businesslogic.ireport.util.Misc.centerFrame(this );
060:
061: javax.swing.KeyStroke escape = javax.swing.KeyStroke
062: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
063: false);
064: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
065: public void actionPerformed(java.awt.event.ActionEvent e) {
066: jButtonCancelActionPerformed(e);
067: }
068: };
069:
070: getRootPane().getInputMap(
071: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
072: escape, "ESCAPE");
073: getRootPane().getActionMap().put("ESCAPE", escapeAction);
074:
075: jSpinnerAlpha.setModel(new SpinnerNumberModel(1.0d, 0.0d, 1.0d,
076: 0.01d));
077:
078: //to make the default button ...
079: this .getRootPane().setDefaultButton(this .jButtonOK);
080: }
081:
082: /**
083: * this method is used to pass the correct subdataset to the expression editor
084: */
085: public void setSubDataset(SubDataset sds) {
086: jRTextExpressionHigh.setSubDataset(sds);
087: jRTextExpressionLow.setSubDataset(sds);
088: }
089:
090: /** This method is called from within the constructor to
091: * initialize the form.
092: * WARNING: Do NOT modify this code. The content of this method is
093: * always regenerated by the Form Editor.
094: */
095: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
096: private void initComponents() {
097: java.awt.GridBagConstraints gridBagConstraints;
098:
099: jPanel1 = new javax.swing.JPanel();
100: jLabelLabel = new javax.swing.JLabel();
101: jTextFieldLabel = new javax.swing.JTextField();
102: jLabelColor = new javax.swing.JLabel();
103: colorSelectorPanel = new it.businesslogic.ireport.gui.sheet.ColorSelectorPanel();
104: jButtonDefaultColor = new javax.swing.JButton();
105: jLabelAlpha = new javax.swing.JLabel();
106: jSpinnerAlpha = new javax.swing.JSpinner();
107: jLabelRangeLow = new javax.swing.JLabel();
108: jRTextExpressionLow = new it.businesslogic.ireport.gui.JRTextExpressionArea();
109: jLabelRangeHigh = new javax.swing.JLabel();
110: jRTextExpressionHigh = new it.businesslogic.ireport.gui.JRTextExpressionArea();
111: jSeparator1 = new javax.swing.JSeparator();
112: jPanel6 = new javax.swing.JPanel();
113: jPanel7 = new javax.swing.JPanel();
114: jButtonOK = new javax.swing.JButton();
115: jButtonCancel = new javax.swing.JButton();
116:
117: getContentPane().setLayout(new java.awt.GridBagLayout());
118:
119: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
120: setTitle("Time series");
121: jPanel1.setLayout(new java.awt.GridBagLayout());
122:
123: jPanel1.setPreferredSize(new java.awt.Dimension(400, 250));
124: jLabelLabel.setText("Label");
125: gridBagConstraints = new java.awt.GridBagConstraints();
126: gridBagConstraints.gridx = 0;
127: gridBagConstraints.gridy = 0;
128: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
129: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 4);
130: jPanel1.add(jLabelLabel, gridBagConstraints);
131:
132: gridBagConstraints = new java.awt.GridBagConstraints();
133: gridBagConstraints.gridx = 1;
134: gridBagConstraints.gridwidth = 2;
135: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136: gridBagConstraints.weightx = 1.0;
137: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
138: jPanel1.add(jTextFieldLabel, gridBagConstraints);
139:
140: jLabelColor.setText("Color");
141: gridBagConstraints = new java.awt.GridBagConstraints();
142: gridBagConstraints.gridx = 0;
143: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 4);
145: jPanel1.add(jLabelColor, gridBagConstraints);
146:
147: colorSelectorPanel.setBorder(new javax.swing.border.LineBorder(
148: new java.awt.Color(102, 102, 102), 1, true));
149: colorSelectorPanel
150: .setMinimumSize(new java.awt.Dimension(50, 10));
151: colorSelectorPanel.setPreferredSize(new java.awt.Dimension(130,
152: 22));
153: colorSelectorPanel
154: .addActionListener(new java.awt.event.ActionListener() {
155: public void actionPerformed(
156: java.awt.event.ActionEvent evt) {
157: colorSelectorPanelActionPerformed(evt);
158: }
159: });
160:
161: gridBagConstraints = new java.awt.GridBagConstraints();
162: gridBagConstraints.gridx = 1;
163: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
164: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
165: jPanel1.add(colorSelectorPanel, gridBagConstraints);
166:
167: jButtonDefaultColor.setText("Use default color");
168: jButtonDefaultColor
169: .addActionListener(new java.awt.event.ActionListener() {
170: public void actionPerformed(
171: java.awt.event.ActionEvent evt) {
172: jButtonDefaultColorActionPerformed(evt);
173: }
174: });
175:
176: gridBagConstraints = new java.awt.GridBagConstraints();
177: gridBagConstraints.gridx = 2;
178: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
179: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
180: jPanel1.add(jButtonDefaultColor, gridBagConstraints);
181:
182: jLabelAlpha.setText("Alpha");
183: gridBagConstraints = new java.awt.GridBagConstraints();
184: gridBagConstraints.gridx = 0;
185: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
186: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 4);
187: jPanel1.add(jLabelAlpha, gridBagConstraints);
188:
189: jSpinnerAlpha.setMinimumSize(new java.awt.Dimension(100, 18));
190: jSpinnerAlpha.setPreferredSize(new java.awt.Dimension(130, 18));
191: gridBagConstraints = new java.awt.GridBagConstraints();
192: gridBagConstraints.gridx = 1;
193: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
194: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
195: jPanel1.add(jSpinnerAlpha, gridBagConstraints);
196:
197: jLabelRangeLow.setText("Data range low expression");
198: gridBagConstraints = new java.awt.GridBagConstraints();
199: gridBagConstraints.gridx = 0;
200: gridBagConstraints.gridwidth = 3;
201: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
202: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
203: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
204: jPanel1.add(jLabelRangeLow, gridBagConstraints);
205:
206: jRTextExpressionLow.setBorder(javax.swing.BorderFactory
207: .createEtchedBorder());
208: jRTextExpressionLow.setElectricScroll(0);
209: jRTextExpressionLow.setMinimumSize(new java.awt.Dimension(10,
210: 10));
211: jRTextExpressionLow.setPreferredSize(new java.awt.Dimension(10,
212: 10));
213: gridBagConstraints = new java.awt.GridBagConstraints();
214: gridBagConstraints.gridx = 0;
215: gridBagConstraints.gridwidth = 3;
216: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
217: gridBagConstraints.weightx = 1.0;
218: gridBagConstraints.weighty = 1.0;
219: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
220: jPanel1.add(jRTextExpressionLow, gridBagConstraints);
221:
222: jLabelRangeHigh.setText("Data range high expression");
223: gridBagConstraints = new java.awt.GridBagConstraints();
224: gridBagConstraints.gridx = 0;
225: gridBagConstraints.gridwidth = 3;
226: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
227: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
228: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
229: jPanel1.add(jLabelRangeHigh, gridBagConstraints);
230:
231: jRTextExpressionHigh.setBorder(javax.swing.BorderFactory
232: .createEtchedBorder());
233: jRTextExpressionHigh.setElectricScroll(0);
234: jRTextExpressionHigh.setMinimumSize(new java.awt.Dimension(10,
235: 10));
236: jRTextExpressionHigh.setPreferredSize(new java.awt.Dimension(
237: 10, 10));
238: gridBagConstraints = new java.awt.GridBagConstraints();
239: gridBagConstraints.gridx = 0;
240: gridBagConstraints.gridwidth = 3;
241: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
242: gridBagConstraints.weightx = 1.0;
243: gridBagConstraints.weighty = 1.0;
244: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
245: jPanel1.add(jRTextExpressionHigh, gridBagConstraints);
246:
247: gridBagConstraints = new java.awt.GridBagConstraints();
248: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
249: gridBagConstraints.weightx = 1.0;
250: gridBagConstraints.weighty = 1.0;
251: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
252: getContentPane().add(jPanel1, gridBagConstraints);
253:
254: gridBagConstraints = new java.awt.GridBagConstraints();
255: gridBagConstraints.gridx = 0;
256: gridBagConstraints.gridwidth = 2;
257: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
258: gridBagConstraints.weightx = 1.0;
259: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
260: getContentPane().add(jSeparator1, gridBagConstraints);
261:
262: jPanel6.setLayout(new java.awt.GridBagLayout());
263:
264: gridBagConstraints = new java.awt.GridBagConstraints();
265: gridBagConstraints.gridheight = 2;
266: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
267: gridBagConstraints.weightx = 1.0;
268: gridBagConstraints.weighty = 1.0;
269: jPanel6.add(jPanel7, gridBagConstraints);
270:
271: jButtonOK.setMnemonic('o');
272: jButtonOK.setText("OK");
273: jButtonOK
274: .addActionListener(new java.awt.event.ActionListener() {
275: public void actionPerformed(
276: java.awt.event.ActionEvent evt) {
277: jButtonOKActionPerformed(evt);
278: }
279: });
280:
281: gridBagConstraints = new java.awt.GridBagConstraints();
282: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
283: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
284: jPanel6.add(jButtonOK, gridBagConstraints);
285:
286: jButtonCancel.setMnemonic('c');
287: jButtonCancel.setText("Cancel");
288: jButtonCancel
289: .addActionListener(new java.awt.event.ActionListener() {
290: public void actionPerformed(
291: java.awt.event.ActionEvent evt) {
292: jButtonCancelActionPerformed(evt);
293: }
294: });
295:
296: gridBagConstraints = new java.awt.GridBagConstraints();
297: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
298: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
299: jPanel6.add(jButtonCancel, gridBagConstraints);
300:
301: gridBagConstraints = new java.awt.GridBagConstraints();
302: gridBagConstraints.gridx = 0;
303: gridBagConstraints.gridy = 18;
304: gridBagConstraints.gridwidth = 2;
305: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
306: gridBagConstraints.weightx = 1.0;
307: getContentPane().add(jPanel6, gridBagConstraints);
308:
309: pack();
310: }// </editor-fold>//GEN-END:initComponents
311:
312: private void jButtonDefaultColorActionPerformed(
313: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDefaultColorActionPerformed
314:
315: colorSelectorPanel.setValue(null);
316:
317: }//GEN-LAST:event_jButtonDefaultColorActionPerformed
318:
319: private void colorSelectorPanelActionPerformed(
320: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_colorSelectorPanelActionPerformed
321:
322: }//GEN-LAST:event_colorSelectorPanelActionPerformed
323:
324: private void jButtonCancelActionPerformed(
325: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
326: this .setVisible(false);
327: this .dispose();
328: }//GEN-LAST:event_jButtonCancelActionPerformed
329:
330: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
331:
332: MeterInterval tmpmi = getMeterInterval();
333: if (tmpmi == null) {
334: tmpmi = new MeterInterval();
335: }
336:
337: tmpmi.setLabel(jTextFieldLabel.getText());
338: tmpmi.setColor((java.awt.Color) ColorSelectorPanel
339: .parseColorString("" + colorSelectorPanel.getValue()));
340:
341: tmpmi.setAlpha(((SpinnerNumberModel) jSpinnerAlpha.getModel())
342: .getNumber().doubleValue());
343: tmpmi.getDataRange().setLowExpression(
344: jRTextExpressionLow.getText());
345: tmpmi.getDataRange().setHighExpression(
346: jRTextExpressionHigh.getText());
347:
348: setMeterInterval(tmpmi);
349:
350: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
351: this .setVisible(false);
352: this .dispose();
353: }//GEN-LAST:event_jButtonOKActionPerformed
354:
355: public int getDialogResult() {
356: return dialogResult;
357: }
358:
359: public void setDialogResult(int dialogResult) {
360: this .dialogResult = dialogResult;
361: }
362:
363: // Variables declaration - do not modify//GEN-BEGIN:variables
364: private it.businesslogic.ireport.gui.sheet.ColorSelectorPanel colorSelectorPanel;
365: private javax.swing.JButton jButtonCancel;
366: private javax.swing.JButton jButtonDefaultColor;
367: private javax.swing.JButton jButtonOK;
368: private javax.swing.JLabel jLabelAlpha;
369: private javax.swing.JLabel jLabelColor;
370: private javax.swing.JLabel jLabelLabel;
371: private javax.swing.JLabel jLabelRangeHigh;
372: private javax.swing.JLabel jLabelRangeLow;
373: private javax.swing.JPanel jPanel1;
374: private javax.swing.JPanel jPanel6;
375: private javax.swing.JPanel jPanel7;
376: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionHigh;
377: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionLow;
378: private javax.swing.JSeparator jSeparator1;
379: private javax.swing.JSpinner jSpinnerAlpha;
380: private javax.swing.JTextField jTextFieldLabel;
381:
382: // End of variables declaration//GEN-END:variables
383:
384: public void applyI18n() {
385: // Start autogenerated code ----------------------
386: jButtonDefaultColor.setText(I18n.getString(
387: "meterIntervalDialog.buttonDefaultColor",
388: "Use default color"));
389: // End autogenerated code ----------------------
390: jButtonOK.setText(it.businesslogic.ireport.util.I18n.getString(
391: "ok", "Ok"));
392: jButtonCancel.setText(it.businesslogic.ireport.util.I18n
393: .getString("cancel", "Cancel"));
394:
395: jLabelLabel.setText(it.businesslogic.ireport.util.I18n
396: .getString("meterinterval.label", "Label"));
397: jLabelColor.setText(it.businesslogic.ireport.util.I18n
398: .getString("meterinterval.color", "Color"));
399: jLabelAlpha.setText(it.businesslogic.ireport.util.I18n
400: .getString("meterinterval.alpha", "Alpha"));
401: jLabelRangeHigh.setText(it.businesslogic.ireport.util.I18n
402: .getString("meterinterval.highexp",
403: "Data range high expression"));
404: jLabelRangeLow.setText(it.businesslogic.ireport.util.I18n
405: .getString("meterinterval.lowexp",
406: "Data range low expression"));
407:
408: setTitle(I18n.getString("meterIntervalDialog.title",
409: "Meter interval"));
410: jButtonCancel.setMnemonic(I18n.getString(
411: "meterIntervalDialog.buttonCancelMnemonic", "c")
412: .charAt(0));
413: jButtonOK.setMnemonic(I18n.getString(
414: "meterIntervalDialog.buttonOKMnemonic", "o").charAt(0));
415:
416: this .getRootPane().updateUI();
417: }
418:
419: public MeterInterval getMeterInterval() {
420: return meterInterval;
421: }
422:
423: /*
424: * The MeterInterval is stored and modified only when ok is pressed.
425: * No further modifications are required to the original object like
426: * all around iReport.
427: *
428: */
429: public void setMeterInterval(MeterInterval meterInterval) {
430: this .meterInterval = meterInterval;
431:
432: if (meterInterval != null) {
433: jTextFieldLabel.setText(meterInterval.getLabel());
434: ((SpinnerNumberModel) jSpinnerAlpha.getModel())
435: .setValue(new Double(meterInterval.getAlpha()));
436: if (meterInterval.getColor() != null) {
437: colorSelectorPanel.setValue(meterInterval.getColor());
438: }
439: jRTextExpressionLow.setText(meterInterval.getDataRange()
440: .getLowExpression());
441: jRTextExpressionHigh.setText(meterInterval.getDataRange()
442: .getHighExpression());
443: }
444: }
445:
446: public static final int COMPONENT_NONE = 0;
447: public static final int COMPONENT_LOW_EXPRESSION = 1;
448: public static final int COMPONENT_HIGH_EXPRESSION = 2;
449:
450: /**
451: * This method set the focus on a specific component.
452: *
453: * expressionInfo[0] can be something like:
454: * COMPONENT_CATEGORY_EXPRESSION, COMPONENT_SERIES_EXPRESSION, COMPONENT_VALUE_EXPRESSION...
455: *
456: * If it is COMPONENT_HYPERLINK, other parameters are expected...
457: * otherInfo is used here only for COMPONENT_HYPERLINK
458: * otherInfo[0] = expression ID
459: * otherInfo[1] = parameter #
460: * otherInfo[2] = parameter expression ID
461: */
462: public void setFocusedExpression(Object[] expressionInfo) {
463: if (expressionInfo == null)
464: return;
465: int expID = ((Integer) expressionInfo[0]).intValue();
466:
467: switch (expID) {
468: case COMPONENT_LOW_EXPRESSION:
469: Misc.selectTextAndFocusArea(jRTextExpressionLow);
470: break;
471: case COMPONENT_HIGH_EXPRESSION:
472: Misc.selectTextAndFocusArea(jRTextExpressionHigh);
473: break;
474: }
475: }
476: }
|