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: * XYZSeriesDialog.java
028: *
029: * Created on 17 agosto 2005, 11.19
030: *
031: */
032:
033: package it.businesslogic.ireport.chart;
034:
035: import it.businesslogic.ireport.SubDataset;
036: import it.businesslogic.ireport.util.I18n;
037: import it.businesslogic.ireport.util.Misc;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class XYZSeriesDialog extends javax.swing.JDialog {
044:
045: private String seriesExpression = "";
046: private String xValueExpression = "";
047: private String yValueExpression = "";
048: private String zValueExpression = "";
049:
050: private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
051:
052: /** Creates new form CategorySeriesDialog */
053: public XYZSeriesDialog(java.awt.Frame 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: //to make the default button ...
076: this .getRootPane().setDefaultButton(this .jButtonOK);
077: }
078:
079: /**
080: * this method is used to pass the correct subdataset to the expression editor
081: */
082: public void setSubDataset(SubDataset sds) {
083: jRTextExpressionSeries.setSubDataset(sds);
084: jRTextExpressionXValue.setSubDataset(sds);
085: jRTextExpressionYValue.setSubDataset(sds);
086: jRTextExpressionZValue.setSubDataset(sds);
087: sectionItemHyperlinkPanel1.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: jTabbedPane1 = new javax.swing.JTabbedPane();
100: jPanel1 = new javax.swing.JPanel();
101: jLabelSeriesExpression = new javax.swing.JLabel();
102: jLabelXValueExpression = new javax.swing.JLabel();
103: jLabelYValueExpression = new javax.swing.JLabel();
104: jLabelZValueExpression = new javax.swing.JLabel();
105: jRTextExpressionSeries = new it.businesslogic.ireport.gui.JRTextExpressionArea();
106: jRTextExpressionXValue = new it.businesslogic.ireport.gui.JRTextExpressionArea();
107: jRTextExpressionYValue = new it.businesslogic.ireport.gui.JRTextExpressionArea();
108: jRTextExpressionZValue = new it.businesslogic.ireport.gui.JRTextExpressionArea();
109: sectionItemHyperlinkPanel1 = new it.businesslogic.ireport.chart.gui.SectionItemHyperlinkPanel();
110: jPanel6 = new javax.swing.JPanel();
111: jPanel7 = new javax.swing.JPanel();
112: jButtonOK = new javax.swing.JButton();
113: jButtonCancel = new javax.swing.JButton();
114:
115: getContentPane().setLayout(new java.awt.GridBagLayout());
116:
117: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
118: setTitle("XYZ series");
119: addWindowListener(new java.awt.event.WindowAdapter() {
120: public void windowOpened(java.awt.event.WindowEvent evt) {
121: formWindowOpened(evt);
122: }
123: });
124:
125: jPanel1.setLayout(new java.awt.GridBagLayout());
126:
127: jLabelSeriesExpression.setText("Series expression (required)");
128: gridBagConstraints = new java.awt.GridBagConstraints();
129: gridBagConstraints.gridx = 0;
130: gridBagConstraints.gridy = 0;
131: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
132: gridBagConstraints.weightx = 1.0;
133: jPanel1.add(jLabelSeriesExpression, gridBagConstraints);
134:
135: jLabelXValueExpression.setText("X value expression (required)");
136: gridBagConstraints = new java.awt.GridBagConstraints();
137: gridBagConstraints.gridx = 0;
138: gridBagConstraints.gridy = 2;
139: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140: gridBagConstraints.weightx = 1.0;
141: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
142: jPanel1.add(jLabelXValueExpression, gridBagConstraints);
143:
144: jLabelYValueExpression.setText("Y value expression (required)");
145: gridBagConstraints = new java.awt.GridBagConstraints();
146: gridBagConstraints.gridx = 0;
147: gridBagConstraints.gridy = 10;
148: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149: gridBagConstraints.weightx = 1.0;
150: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
151: jPanel1.add(jLabelYValueExpression, gridBagConstraints);
152:
153: jLabelZValueExpression.setText("Z value expression");
154: gridBagConstraints = new java.awt.GridBagConstraints();
155: gridBagConstraints.gridx = 0;
156: gridBagConstraints.gridy = 14;
157: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158: gridBagConstraints.weightx = 1.0;
159: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
160: jPanel1.add(jLabelZValueExpression, gridBagConstraints);
161:
162: jRTextExpressionSeries.setBorder(javax.swing.BorderFactory
163: .createEtchedBorder());
164: jRTextExpressionSeries.setElectricScroll(0);
165: jRTextExpressionSeries.setMinimumSize(new java.awt.Dimension(
166: 10, 10));
167: jRTextExpressionSeries.setPreferredSize(new java.awt.Dimension(
168: 10, 10));
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.gridx = 0;
171: gridBagConstraints.gridy = 1;
172: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
173: gridBagConstraints.weightx = 1.0;
174: gridBagConstraints.weighty = 1.0;
175: jPanel1.add(jRTextExpressionSeries, gridBagConstraints);
176:
177: jRTextExpressionXValue.setBorder(javax.swing.BorderFactory
178: .createEtchedBorder());
179: jRTextExpressionXValue.setElectricScroll(0);
180: jRTextExpressionXValue.setMinimumSize(new java.awt.Dimension(
181: 10, 10));
182: jRTextExpressionXValue.setPreferredSize(new java.awt.Dimension(
183: 10, 10));
184: gridBagConstraints = new java.awt.GridBagConstraints();
185: gridBagConstraints.gridx = 0;
186: gridBagConstraints.gridy = 3;
187: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
188: gridBagConstraints.weightx = 1.0;
189: gridBagConstraints.weighty = 1.0;
190: jPanel1.add(jRTextExpressionXValue, gridBagConstraints);
191:
192: jRTextExpressionYValue.setBorder(javax.swing.BorderFactory
193: .createEtchedBorder());
194: jRTextExpressionYValue.setElectricScroll(0);
195: jRTextExpressionYValue.setMinimumSize(new java.awt.Dimension(
196: 10, 10));
197: jRTextExpressionYValue.setPreferredSize(new java.awt.Dimension(
198: 10, 10));
199: gridBagConstraints = new java.awt.GridBagConstraints();
200: gridBagConstraints.gridx = 0;
201: gridBagConstraints.gridy = 11;
202: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
203: gridBagConstraints.weightx = 1.0;
204: gridBagConstraints.weighty = 1.0;
205: jPanel1.add(jRTextExpressionYValue, gridBagConstraints);
206:
207: jRTextExpressionZValue.setBorder(javax.swing.BorderFactory
208: .createEtchedBorder());
209: jRTextExpressionZValue.setElectricScroll(0);
210: jRTextExpressionZValue.setMinimumSize(new java.awt.Dimension(
211: 10, 10));
212: jRTextExpressionZValue.setPreferredSize(new java.awt.Dimension(
213: 10, 10));
214: gridBagConstraints = new java.awt.GridBagConstraints();
215: gridBagConstraints.gridx = 0;
216: gridBagConstraints.gridy = 15;
217: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
218: gridBagConstraints.weightx = 1.0;
219: gridBagConstraints.weighty = 1.0;
220: jPanel1.add(jRTextExpressionZValue, gridBagConstraints);
221:
222: jTabbedPane1.addTab("Data", jPanel1);
223:
224: jTabbedPane1.addTab("Item hyperlink",
225: sectionItemHyperlinkPanel1);
226:
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
229: gridBagConstraints.weightx = 1.0;
230: gridBagConstraints.weighty = 1.0;
231: getContentPane().add(jTabbedPane1, gridBagConstraints);
232:
233: jPanel6.setLayout(new java.awt.GridBagLayout());
234:
235: gridBagConstraints = new java.awt.GridBagConstraints();
236: gridBagConstraints.gridheight = 2;
237: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
238: gridBagConstraints.weightx = 1.0;
239: gridBagConstraints.weighty = 1.0;
240: jPanel6.add(jPanel7, gridBagConstraints);
241:
242: jButtonOK.setMnemonic('o');
243: jButtonOK.setText("OK");
244: jButtonOK
245: .addActionListener(new java.awt.event.ActionListener() {
246: public void actionPerformed(
247: java.awt.event.ActionEvent evt) {
248: jButtonOKActionPerformed(evt);
249: }
250: });
251:
252: gridBagConstraints = new java.awt.GridBagConstraints();
253: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
254: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
255: jPanel6.add(jButtonOK, gridBagConstraints);
256:
257: jButtonCancel.setMnemonic('c');
258: jButtonCancel.setText("Cancel");
259: jButtonCancel
260: .addActionListener(new java.awt.event.ActionListener() {
261: public void actionPerformed(
262: java.awt.event.ActionEvent evt) {
263: jButtonCancelActionPerformed(evt);
264: }
265: });
266:
267: gridBagConstraints = new java.awt.GridBagConstraints();
268: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
269: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
270: jPanel6.add(jButtonCancel, gridBagConstraints);
271:
272: gridBagConstraints = new java.awt.GridBagConstraints();
273: gridBagConstraints.gridx = 0;
274: gridBagConstraints.gridy = 18;
275: gridBagConstraints.gridwidth = 2;
276: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
277: gridBagConstraints.weightx = 1.0;
278: getContentPane().add(jPanel6, gridBagConstraints);
279:
280: pack();
281: }// </editor-fold>//GEN-END:initComponents
282:
283: private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
284: sectionItemHyperlinkPanel1.openExtraWindows();
285: }//GEN-LAST:event_formWindowOpened
286:
287: private void jButtonCancelActionPerformed(
288: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
289: this .setVisible(false);
290: this .dispose();
291: }//GEN-LAST:event_jButtonCancelActionPerformed
292:
293: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
294:
295: seriesExpression = jRTextExpressionSeries.getText();
296: setXValueExpression(jRTextExpressionXValue.getText());
297: setYValueExpression(jRTextExpressionYValue.getText());
298: setZValueExpression(jRTextExpressionZValue.getText());
299:
300: java.text.MessageFormat formatter = new java.text.MessageFormat(
301: it.businesslogic.ireport.util.I18n.getString(
302: "gui.notvalidexp", "{0} cannot be blank!"));
303:
304: if (seriesExpression.trim().length() == 0) {
305:
306: javax.swing.JOptionPane
307: .showMessageDialog(
308: this ,
309: formatter
310: .format(new Object[] { it.businesslogic.ireport.util.I18n
311: .getString(
312: "charts.seriesExpression",
313: "Series expression") }),
314: I18n.getString(
315: "message.title.invalidExpression",
316: "Invalid expression"),
317: javax.swing.JOptionPane.ERROR_MESSAGE);
318: return;
319: }
320:
321: if (xValueExpression.trim().length() == 0) {
322: javax.swing.JOptionPane
323: .showMessageDialog(
324: this ,
325: formatter
326: .format(new Object[] { it.businesslogic.ireport.util.I18n
327: .getString(
328: "charts.yValueExpression",
329: "X Value expression") }),
330: I18n.getString(
331: "message.title.invalidExpression",
332: "Invalid expression"),
333: javax.swing.JOptionPane.ERROR_MESSAGE);
334: return;
335: }
336:
337: if (yValueExpression.trim().length() == 0) {
338: javax.swing.JOptionPane
339: .showMessageDialog(
340: this ,
341: formatter
342: .format(new Object[] { it.businesslogic.ireport.util.I18n
343: .getString(
344: "charts.yValueExpression",
345: "Y Value expression") }),
346: I18n.getString(
347: "message.title.invalidExpression",
348: "Invalid expression"),
349: javax.swing.JOptionPane.ERROR_MESSAGE);
350: return;
351: }
352:
353: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
354: this .setVisible(false);
355: this .dispose();
356: }//GEN-LAST:event_jButtonOKActionPerformed
357:
358: /**
359: * @param args the command line arguments
360: */
361: public static void main(String args[]) {
362: java.awt.EventQueue.invokeLater(new Runnable() {
363: public void run() {
364: new CategorySeriesDialog(new javax.swing.JFrame(), true)
365: .setVisible(true);
366: }
367: });
368: }
369:
370: public String getSeriesExpression() {
371: return seriesExpression;
372: }
373:
374: public void setSeriesExpression(String seriesExpression) {
375: this .seriesExpression = seriesExpression;
376: jRTextExpressionSeries.setText(seriesExpression);
377: }
378:
379: public void setSectionItemHyperlink(
380: SectionItemHyperlink sectionItemHyperlink) {
381: sectionItemHyperlinkPanel1
382: .setSectionItemHyperlink(sectionItemHyperlink.cloneMe());
383: }
384:
385: public SectionItemHyperlink getSectionItemHyperlink() {
386: return sectionItemHyperlinkPanel1.getSectionItemHyperlink();
387: }
388:
389: public int getDialogResult() {
390: return dialogResult;
391: }
392:
393: public void setDialogResult(int dialogResult) {
394: this .dialogResult = dialogResult;
395: }
396:
397: // Variables declaration - do not modify//GEN-BEGIN:variables
398: private javax.swing.JButton jButtonCancel;
399: private javax.swing.JButton jButtonOK;
400: private javax.swing.JLabel jLabelSeriesExpression;
401: private javax.swing.JLabel jLabelXValueExpression;
402: private javax.swing.JLabel jLabelYValueExpression;
403: private javax.swing.JLabel jLabelZValueExpression;
404: private javax.swing.JPanel jPanel1;
405: private javax.swing.JPanel jPanel6;
406: private javax.swing.JPanel jPanel7;
407: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionSeries;
408: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionXValue;
409: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionYValue;
410: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionZValue;
411: private javax.swing.JTabbedPane jTabbedPane1;
412: private it.businesslogic.ireport.chart.gui.SectionItemHyperlinkPanel sectionItemHyperlinkPanel1;
413:
414: // End of variables declaration//GEN-END:variables
415:
416: public void applyI18n() {
417: // Start autogenerated code ----------------------
418: // End autogenerated code ----------------------
419: jButtonOK.setText(it.businesslogic.ireport.util.I18n.getString(
420: "ok", "Ok"));
421: jButtonCancel.setText(it.businesslogic.ireport.util.I18n
422: .getString("cancel", "Cancel"));
423:
424: jLabelSeriesExpression
425: .setText(it.businesslogic.ireport.util.I18n.getString(
426: "charts.seriesExpression", "Series expression"));
427: jLabelXValueExpression
428: .setText(it.businesslogic.ireport.util.I18n
429: .getString("charts.xValueExpression",
430: "X Value expression"));
431: jLabelYValueExpression
432: .setText(it.businesslogic.ireport.util.I18n
433: .getString("charts.yValueExpression",
434: "Y Value expression"));
435: jLabelZValueExpression
436: .setText(it.businesslogic.ireport.util.I18n
437: .getString("charts.zValueExpression",
438: "Z Value expression"));
439:
440: jTabbedPane1.setTitleAt(0, I18n.getString(
441: "chartSeries.tab.Data", "Data"));
442: jTabbedPane1.setTitleAt(1, I18n.getString(
443: "chartSeries.tab.ItemHyperlink", "Item hyperlink"));
444:
445: this .setTitle(I18n.getString("xYZSeriesDialog.title",
446: "XYZ series"));
447: jButtonCancel.setMnemonic(I18n.getString(
448: "xYZSeriesDialog.buttonCancelMnemonic", "c").charAt(0));
449: jButtonOK.setMnemonic(I18n.getString(
450: "xYZSeriesDialog.buttonOKMnemonic", "o").charAt(0));
451:
452: this .getRootPane().updateUI();
453: }
454:
455: public String getXValueExpression() {
456: return xValueExpression;
457: }
458:
459: public void setXValueExpression(String xValueExpression) {
460: this .xValueExpression = xValueExpression;
461: jRTextExpressionXValue.setText(xValueExpression);
462: }
463:
464: public String getYValueExpression() {
465: return yValueExpression;
466: }
467:
468: public void setYValueExpression(String yValueExpression) {
469: this .yValueExpression = yValueExpression;
470: jRTextExpressionYValue.setText(yValueExpression);
471: }
472:
473: public String getZValueExpression() {
474: return zValueExpression;
475: }
476:
477: public void setZValueExpression(String zValueExpression) {
478: this .zValueExpression = zValueExpression;
479: jRTextExpressionZValue.setText(zValueExpression);
480: }
481:
482: public static final int COMPONENT_NONE = 0;
483: public static final int COMPONENT_SERIES_EXPRESSION = 1;
484: public static final int COMPONENT_X_EXPRESSION = 2;
485: public static final int COMPONENT_Y_EXPRESSION = 3;
486: public static final int COMPONENT_Z_EXPRESSION = 4;
487: public static final int COMPONENT_HYPERLINK = 100;
488:
489: /**
490: * This method set the focus on a specific component.
491: *
492: * expressionInfo[0] can be something like:
493: * COMPONENT_SERIES_EXPRESSION, ...
494: *
495: * If it is COMPONENT_HYPERLINK, other parameters are expected...
496: * otherInfo is used here only for COMPONENT_HYPERLINK
497: * otherInfo[0] = expression ID
498: * otherInfo[1] = parameter #
499: * otherInfo[2] = parameter expression ID
500: */
501: public void setFocusedExpression(Object[] expressionInfo) {
502: if (expressionInfo == null)
503: return;
504: int expID = ((Integer) expressionInfo[0]).intValue();
505:
506: switch (expID) {
507: case COMPONENT_SERIES_EXPRESSION:
508: Misc.selectTextAndFocusArea(jRTextExpressionSeries);
509: break;
510: case COMPONENT_X_EXPRESSION:
511: Misc.selectTextAndFocusArea(jRTextExpressionXValue);
512: break;
513: case COMPONENT_Y_EXPRESSION:
514: Misc.selectTextAndFocusArea(jRTextExpressionYValue);
515: break;
516: case COMPONENT_Z_EXPRESSION:
517: Misc.selectTextAndFocusArea(jRTextExpressionZValue);
518: break;
519: case COMPONENT_HYPERLINK:
520: jTabbedPane1
521: .setSelectedComponent(sectionItemHyperlinkPanel1);
522: Object newInfo[] = new Object[expressionInfo.length - 1];
523: for (int i = 1; i < expressionInfo.length; ++i)
524: newInfo[i - 1] = expressionInfo[i];
525: sectionItemHyperlinkPanel1.setFocusedExpression(newInfo);
526: break;
527: }
528: }
529: }
|