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: * XYSeriesDialog.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 XYSeriesDialog extends javax.swing.JDialog {
044:
045: private String seriesExpression = "";
046: private String xValueExpression = "";
047: private String yValueExpression = "";
048: private String labelExpression = "";
049:
050: private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
051:
052: /** Creates new form CategorySeriesDialog */
053: public XYSeriesDialog(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: jRTextExpressionLabel.setSubDataset(sds);
084: jRTextExpressionSeries.setSubDataset(sds);
085: jRTextExpressionXValue.setSubDataset(sds);
086: jRTextExpressionYValue.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: jLabelLabelExpression = 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: jRTextExpressionLabel = 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("XY 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: jLabelLabelExpression.setText("Label 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(jLabelLabelExpression, 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: jRTextExpressionLabel.setBorder(javax.swing.BorderFactory
208: .createEtchedBorder());
209: jRTextExpressionLabel.setElectricScroll(0);
210: jRTextExpressionLabel.setMinimumSize(new java.awt.Dimension(10,
211: 10));
212: jRTextExpressionLabel.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(jRTextExpressionLabel, gridBagConstraints);
221:
222: jTabbedPane1.addTab("Data", jPanel1);
223:
224: jTabbedPane1.addTab("Item hyperlink",
225: sectionItemHyperlinkPanel1);
226:
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.gridwidth = 2;
229: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
230: gridBagConstraints.weightx = 1.0;
231: gridBagConstraints.weighty = 1.0;
232: getContentPane().add(jTabbedPane1, gridBagConstraints);
233:
234: jPanel6.setLayout(new java.awt.GridBagLayout());
235:
236: gridBagConstraints = new java.awt.GridBagConstraints();
237: gridBagConstraints.gridheight = 2;
238: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
239: gridBagConstraints.weightx = 1.0;
240: gridBagConstraints.weighty = 1.0;
241: jPanel6.add(jPanel7, gridBagConstraints);
242:
243: jButtonOK.setMnemonic('o');
244: jButtonOK.setText("OK");
245: jButtonOK
246: .addActionListener(new java.awt.event.ActionListener() {
247: public void actionPerformed(
248: java.awt.event.ActionEvent evt) {
249: jButtonOKActionPerformed(evt);
250: }
251: });
252:
253: gridBagConstraints = new java.awt.GridBagConstraints();
254: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
255: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
256: jPanel6.add(jButtonOK, gridBagConstraints);
257:
258: jButtonCancel.setMnemonic('c');
259: jButtonCancel.setText("Cancel");
260: jButtonCancel
261: .addActionListener(new java.awt.event.ActionListener() {
262: public void actionPerformed(
263: java.awt.event.ActionEvent evt) {
264: jButtonCancelActionPerformed(evt);
265: }
266: });
267:
268: gridBagConstraints = new java.awt.GridBagConstraints();
269: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
271: jPanel6.add(jButtonCancel, gridBagConstraints);
272:
273: gridBagConstraints = new java.awt.GridBagConstraints();
274: gridBagConstraints.gridx = 0;
275: gridBagConstraints.gridy = 18;
276: gridBagConstraints.gridwidth = 2;
277: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
278: gridBagConstraints.weightx = 1.0;
279: getContentPane().add(jPanel6, gridBagConstraints);
280:
281: pack();
282: }// </editor-fold>//GEN-END:initComponents
283:
284: private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
285: sectionItemHyperlinkPanel1.openExtraWindows();
286: }//GEN-LAST:event_formWindowOpened
287:
288: private void jButtonCancelActionPerformed(
289: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
290: this .setVisible(false);
291: this .dispose();
292: }//GEN-LAST:event_jButtonCancelActionPerformed
293:
294: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
295:
296: seriesExpression = jRTextExpressionSeries.getText();
297: setXValueExpression(jRTextExpressionXValue.getText());
298: setYValueExpression(jRTextExpressionYValue.getText());
299: labelExpression = jRTextExpressionLabel.getText();
300:
301: java.text.MessageFormat formatter = new java.text.MessageFormat(
302: it.businesslogic.ireport.util.I18n.getString(
303: "gui.notvalidexp", "{0} cannot be blank!"));
304:
305: if (seriesExpression.trim().length() == 0) {
306:
307: javax.swing.JOptionPane
308: .showMessageDialog(
309: this ,
310: formatter
311: .format(new Object[] { it.businesslogic.ireport.util.I18n
312: .getString(
313: "charts.seriesExpression",
314: "Series expression") }),
315: I18n.getString(
316: "message.title.invalidExpression",
317: "Invalid expression"),
318: javax.swing.JOptionPane.ERROR_MESSAGE);
319: return;
320: }
321:
322: if (xValueExpression.trim().length() == 0) {
323: javax.swing.JOptionPane
324: .showMessageDialog(
325: this ,
326: formatter
327: .format(new Object[] { it.businesslogic.ireport.util.I18n
328: .getString(
329: "charts.yValueExpression",
330: "X Value expression") }),
331: I18n.getString(
332: "message.title.invalidExpression",
333: "Invalid expression"),
334: javax.swing.JOptionPane.ERROR_MESSAGE);
335: return;
336: }
337:
338: if (yValueExpression.trim().length() == 0) {
339: javax.swing.JOptionPane
340: .showMessageDialog(
341: this ,
342: formatter
343: .format(new Object[] { it.businesslogic.ireport.util.I18n
344: .getString(
345: "charts.yValueExpression",
346: "Y Value expression") }),
347: I18n.getString(
348: "message.title.invalidExpression",
349: "Invalid expression"),
350: javax.swing.JOptionPane.ERROR_MESSAGE);
351: return;
352: }
353:
354: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
355: this .setVisible(false);
356: this .dispose();
357: }//GEN-LAST:event_jButtonOKActionPerformed
358:
359: /**
360: * @param args the command line arguments
361: */
362: public static void main(String args[]) {
363: java.awt.EventQueue.invokeLater(new Runnable() {
364: public void run() {
365: new CategorySeriesDialog(new javax.swing.JFrame(), true)
366: .setVisible(true);
367: }
368: });
369: }
370:
371: public String getSeriesExpression() {
372: return seriesExpression;
373: }
374:
375: public void setSeriesExpression(String seriesExpression) {
376: this .seriesExpression = seriesExpression;
377: jRTextExpressionSeries.setText(seriesExpression);
378: }
379:
380: public String getLabelExpression() {
381: return labelExpression;
382: }
383:
384: public void setLabelExpression(String labelExpression) {
385: this .labelExpression = labelExpression;
386: jRTextExpressionLabel.setText(labelExpression);
387: }
388:
389: public void setSectionItemHyperlink(
390: SectionItemHyperlink sectionItemHyperlink) {
391: sectionItemHyperlinkPanel1
392: .setSectionItemHyperlink(sectionItemHyperlink.cloneMe());
393: }
394:
395: public SectionItemHyperlink getSectionItemHyperlink() {
396: return sectionItemHyperlinkPanel1.getSectionItemHyperlink();
397: }
398:
399: public int getDialogResult() {
400: return dialogResult;
401: }
402:
403: public void setDialogResult(int dialogResult) {
404: this .dialogResult = dialogResult;
405: }
406:
407: // Variables declaration - do not modify//GEN-BEGIN:variables
408: private javax.swing.JButton jButtonCancel;
409: private javax.swing.JButton jButtonOK;
410: private javax.swing.JLabel jLabelLabelExpression;
411: private javax.swing.JLabel jLabelSeriesExpression;
412: private javax.swing.JLabel jLabelXValueExpression;
413: private javax.swing.JLabel jLabelYValueExpression;
414: private javax.swing.JPanel jPanel1;
415: private javax.swing.JPanel jPanel6;
416: private javax.swing.JPanel jPanel7;
417: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionLabel;
418: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionSeries;
419: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionXValue;
420: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionYValue;
421: private javax.swing.JTabbedPane jTabbedPane1;
422: private it.businesslogic.ireport.chart.gui.SectionItemHyperlinkPanel sectionItemHyperlinkPanel1;
423:
424: // End of variables declaration//GEN-END:variables
425:
426: public void applyI18n() {
427: // Start autogenerated code ----------------------
428: // End autogenerated code ----------------------
429: jButtonOK.setText(it.businesslogic.ireport.util.I18n.getString(
430: "ok", "Ok"));
431: jButtonCancel.setText(it.businesslogic.ireport.util.I18n
432: .getString("cancel", "Cancel"));
433:
434: jLabelSeriesExpression
435: .setText(it.businesslogic.ireport.util.I18n.getString(
436: "charts.seriesExpression", "Series expression"));
437: jLabelXValueExpression
438: .setText(it.businesslogic.ireport.util.I18n
439: .getString("charts.xValueExpression",
440: "X Value expression"));
441: jLabelYValueExpression
442: .setText(it.businesslogic.ireport.util.I18n
443: .getString("charts.yValueExpression",
444: "Y Value expression"));
445:
446: jLabelLabelExpression
447: .setText(it.businesslogic.ireport.util.I18n.getString(
448: "charts.labelExpression", "Label expression"));
449:
450: jTabbedPane1.setTitleAt(0, I18n.getString(
451: "chartSeries.tab.Data", "Data"));
452: jTabbedPane1.setTitleAt(1, I18n.getString(
453: "chartSeries.tab.ItemHyperlink", "Item hyperlink"));
454:
455: this .setTitle(I18n.getString("xYSeriesDialog.title",
456: "XY series"));
457: jButtonCancel.setMnemonic(I18n.getString(
458: "xYSeriesDialog.buttonCancelMnemonic", "c").charAt(0));
459: jButtonOK.setMnemonic(I18n.getString(
460: "xYSeriesDialog.buttonOKMnemonic", "o").charAt(0));
461:
462: this .getRootPane().updateUI();
463: }
464:
465: public String getXValueExpression() {
466: return xValueExpression;
467: }
468:
469: public void setXValueExpression(String xValueExpression) {
470: this .xValueExpression = xValueExpression;
471: jRTextExpressionXValue.setText(xValueExpression);
472: }
473:
474: public String getYValueExpression() {
475: return yValueExpression;
476: }
477:
478: public void setYValueExpression(String yValueExpression) {
479: this .yValueExpression = yValueExpression;
480: jRTextExpressionYValue.setText(yValueExpression);
481: }
482:
483: public static final int COMPONENT_NONE = 0;
484: public static final int COMPONENT_SERIES_EXPRESSION = 1;
485: public static final int COMPONENT_X_EXPRESSION = 2;
486: public static final int COMPONENT_Y_EXPRESSION = 3;
487: public static final int COMPONENT_LABEL_EXPRESSION = 4;
488: public static final int COMPONENT_HYPERLINK = 100;
489:
490: /**
491: * This method set the focus on a specific component.
492: *
493: * expressionInfo[0] can be something like:
494: * COMPONENT_SERIES_EXPRESSION, ...
495: *
496: * If it is COMPONENT_HYPERLINK, other parameters are expected...
497: * otherInfo is used here only for COMPONENT_HYPERLINK
498: * otherInfo[0] = expression ID
499: * otherInfo[1] = parameter #
500: * otherInfo[2] = parameter expression ID
501: */
502: public void setFocusedExpression(Object[] expressionInfo) {
503: if (expressionInfo == null)
504: return;
505: int expID = ((Integer) expressionInfo[0]).intValue();
506:
507: switch (expID) {
508: case COMPONENT_SERIES_EXPRESSION:
509: Misc.selectTextAndFocusArea(jRTextExpressionSeries);
510: break;
511: case COMPONENT_X_EXPRESSION:
512: Misc.selectTextAndFocusArea(jRTextExpressionXValue);
513: break;
514: case COMPONENT_Y_EXPRESSION:
515: Misc.selectTextAndFocusArea(jRTextExpressionYValue);
516: break;
517: case COMPONENT_LABEL_EXPRESSION:
518: Misc.selectTextAndFocusArea(jRTextExpressionLabel);
519: break;
520: case COMPONENT_HYPERLINK:
521: jTabbedPane1
522: .setSelectedComponent(sectionItemHyperlinkPanel1);
523: Object newInfo[] = new Object[expressionInfo.length - 1];
524: for (int i = 1; i < expressionInfo.length; ++i)
525: newInfo[i - 1] = expressionInfo[i];
526: sectionItemHyperlinkPanel1.setFocusedExpression(newInfo);
527: break;
528: }
529: }
530: }
|