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: * ChartSelectionJDialog.java
028: *
029: * Created on 8 luglio 2005, 23.26
030: *
031: */
032:
033: package it.businesslogic.ireport.chart.gui;
034:
035: import it.businesslogic.ireport.gui.*;
036: import it.businesslogic.ireport.*;
037: import javax.swing.tree.*;
038: import javax.swing.table.*;
039: import javax.swing.*;
040: import it.businesslogic.ireport.chart.*;
041: import java.util.*;
042: import it.businesslogic.ireport.gui.sheet.*;
043: import it.businesslogic.ireport.gui.listview.*;
044: import it.businesslogic.ireport.util.I18n;
045:
046: /**
047: *
048: * @author Administrator
049: */
050: public class ChartSelectionJDialog extends javax.swing.JDialog {
051:
052: private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
053: private it.businesslogic.ireport.gui.listview.JListView jListView = null;
054: private JList jList1 = null;
055:
056: private Chart chart = null;
057:
058: private boolean multiAxisMode = false;
059:
060: /** Creates new form ChartSelectionJDialog */
061: public ChartSelectionJDialog(java.awt.Dialog parent, boolean modal) {
062: super (parent, modal);
063: initAll();
064: }
065:
066: /** Creates new form ChartSelectionJDialog */
067: public ChartSelectionJDialog(java.awt.Frame parent, boolean modal) {
068: super (parent, modal);
069: initAll();
070: }
071:
072: public void updateCharts() {
073:
074: javax.swing.DefaultListModel dlm = (javax.swing.DefaultListModel) jList1
075: .getModel();
076:
077: dlm.removeAllElements();
078:
079: if (!isMultiAxisMode())
080: dlm.addElement(new ChartDescriptor(
081: "/it/businesslogic/ireport/icons/charts/pie.png",
082: "Pie", "it.businesslogic.ireport.chart.PieChart"));
083: if (!isMultiAxisMode())
084: dlm.addElement(new ChartDescriptor(
085: "/it/businesslogic/ireport/icons/charts/pie3d.png",
086: "Pie 3D",
087: "it.businesslogic.ireport.chart.Pie3DChart"));
088: dlm.addElement(new ChartDescriptor(
089: "/it/businesslogic/ireport/icons/charts/bar.png",
090: "Bar", "it.businesslogic.ireport.chart.BarChart"));
091: dlm.addElement(new ChartDescriptor(
092: "/it/businesslogic/ireport/icons/charts/bar3d.png",
093: "Bar 3D", "it.businesslogic.ireport.chart.Bar3DChart"));
094: dlm.addElement(new ChartDescriptor(
095: "/it/businesslogic/ireport/icons/charts/xybar.png",
096: "YX Bar", "it.businesslogic.ireport.chart.XYBarChart"));
097: dlm
098: .addElement(new ChartDescriptor(
099: "/it/businesslogic/ireport/icons/charts/stackedbar.png",
100: "Stacked Bar",
101: "it.businesslogic.ireport.chart.StackedBarChart"));
102: dlm
103: .addElement(new ChartDescriptor(
104: "/it/businesslogic/ireport/icons/charts/stackedbar3d.png",
105: "Stacked Bar 3D",
106: "it.businesslogic.ireport.chart.StackedBar3DChart"));
107: dlm.addElement(new ChartDescriptor(
108: "/it/businesslogic/ireport/icons/charts/line.png",
109: "Line", "it.businesslogic.ireport.chart.LineChart"));
110: dlm
111: .addElement(new ChartDescriptor(
112: "/it/businesslogic/ireport/icons/charts/xyline.png",
113: "XY Line",
114: "it.businesslogic.ireport.chart.XYLineChart"));
115: dlm.addElement(new ChartDescriptor(
116: "/it/businesslogic/ireport/icons/charts/area.png",
117: "Area", "it.businesslogic.ireport.chart.AreaChart"));
118: dlm
119: .addElement(new ChartDescriptor(
120: "/it/businesslogic/ireport/icons/charts/xyarea.png",
121: "YX Area",
122: "it.businesslogic.ireport.chart.XYAreaChart"));
123: dlm
124: .addElement(new ChartDescriptor(
125: "/it/businesslogic/ireport/icons/charts/stackedarea.png",
126: "Stacked Area",
127: "it.businesslogic.ireport.chart.StackedAreaChart"));
128: dlm.addElement(new ChartDescriptor(
129: "/it/businesslogic/ireport/icons/charts/scatter.png",
130: "Scatter",
131: "it.businesslogic.ireport.chart.ScatterChart"));
132: dlm
133: .addElement(new ChartDescriptor(
134: "/it/businesslogic/ireport/icons/charts/bubble.png",
135: "Bubble",
136: "it.businesslogic.ireport.chart.BubbleChart"));
137: dlm
138: .addElement(new ChartDescriptor(
139: "/it/businesslogic/ireport/icons/charts/timeseries.png",
140: "Time Series",
141: "it.businesslogic.ireport.chart.TimeSeriesChart"));
142: dlm.addElement(new ChartDescriptor(
143: "/it/businesslogic/ireport/icons/charts/highlow.png",
144: "High Low",
145: "it.businesslogic.ireport.chart.HighLowChart"));
146: dlm
147: .addElement(new ChartDescriptor(
148: "/it/businesslogic/ireport/icons/charts/candlestick.png",
149: "Candlestick",
150: "it.businesslogic.ireport.chart.CandlestickChart"));
151: if (!isMultiAxisMode())
152: dlm.addElement(new ChartDescriptor(
153: "/it/businesslogic/ireport/icons/charts/meter.png",
154: "Meter",
155: "it.businesslogic.ireport.chart.MeterChart"));
156: if (!isMultiAxisMode())
157: dlm
158: .addElement(new ChartDescriptor(
159: "/it/businesslogic/ireport/icons/charts/thermometer.png",
160: "Thermometer",
161: "it.businesslogic.ireport.chart.ThermometerChart"));
162: if (!isMultiAxisMode())
163: dlm
164: .addElement(new ChartDescriptor(
165: "/it/businesslogic/ireport/icons/charts/multiaxis.png",
166: "Multi Axis",
167: "it.businesslogic.ireport.chart.MultiAxisChart"));
168:
169: jList1.updateUI();
170:
171: }
172:
173: public void initAll() {
174: initComponents();
175: applyI18n();
176:
177: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
178: jListView = new JListView();
179: jList1 = (JList) jListView.getList();
180:
181: jPanelChartType.add(jListView, java.awt.BorderLayout.CENTER);
182:
183: javax.swing.DefaultListModel dlm = new javax.swing.DefaultListModel();
184: jList1.setModel(dlm);
185: jList1.setCellRenderer(new ChartCellRenderer());
186:
187: updateCharts();
188:
189: jList1.setLayoutOrientation(JList.HORIZONTAL_WRAP);
190: this .setSize(400, 400);
191: it.businesslogic.ireport.util.Misc.centerFrame(this );
192:
193: jList1
194: .setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
195: jList1
196: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
197: public void valueChanged(
198: javax.swing.event.ListSelectionEvent e) {
199: selectedChart();
200: }
201:
202: });
203:
204: javax.swing.KeyStroke escape = javax.swing.KeyStroke
205: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
206: false);
207: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
208: public void actionPerformed(java.awt.event.ActionEvent e) {
209: jButtonCancelActionPerformed(e);
210: }
211: };
212:
213: getRootPane().getInputMap(
214: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
215: escape, "ESCAPE");
216: getRootPane().getActionMap().put("ESCAPE", escapeAction);
217:
218: //to make the default button ...
219: this .getRootPane().setDefaultButton(this .jButtonOk);
220: }
221:
222: /** This method is called from within the constructor to
223: * initialize the form.
224: * WARNING: Do NOT modify this code. The content of this method is
225: * always regenerated by the Form Editor.
226: */
227: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
228: private void initComponents() {
229: java.awt.GridBagConstraints gridBagConstraints;
230:
231: jPanelChartType = new javax.swing.JPanel();
232: jPanel5 = new javax.swing.JPanel();
233: jLabelChartNameVal = new javax.swing.JLabel();
234: jPanel6 = new javax.swing.JPanel();
235: jPanel1 = new javax.swing.JPanel();
236: jPanel2 = new javax.swing.JPanel();
237: jButtonOk = new javax.swing.JButton();
238: jButtonCancel = new javax.swing.JButton();
239:
240: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
241: jPanelChartType.setLayout(new java.awt.BorderLayout());
242:
243: jPanel5.setLayout(new java.awt.GridBagLayout());
244:
245: jPanel5.setBorder(new javax.swing.border.TitledBorder(
246: new javax.swing.border.EtchedBorder(), "Chart info"));
247: jPanel5.setMinimumSize(new java.awt.Dimension(10, 50));
248: jPanel5.setPreferredSize(new java.awt.Dimension(10, 50));
249: gridBagConstraints = new java.awt.GridBagConstraints();
250: gridBagConstraints.gridx = 1;
251: gridBagConstraints.gridy = 0;
252: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
253: gridBagConstraints.ipadx = 1;
254: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
255: gridBagConstraints.weightx = 1.0;
256: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
257: jPanel5.add(jLabelChartNameVal, gridBagConstraints);
258:
259: gridBagConstraints = new java.awt.GridBagConstraints();
260: gridBagConstraints.gridx = 0;
261: gridBagConstraints.weighty = 1.0;
262: jPanel5.add(jPanel6, gridBagConstraints);
263:
264: jPanelChartType.add(jPanel5, java.awt.BorderLayout.SOUTH);
265:
266: getContentPane().add(jPanelChartType,
267: java.awt.BorderLayout.CENTER);
268:
269: jPanel1.setLayout(new java.awt.GridBagLayout());
270:
271: jPanel1.setMinimumSize(new java.awt.Dimension(10, 30));
272: jPanel1.setPreferredSize(new java.awt.Dimension(10, 30));
273: gridBagConstraints = new java.awt.GridBagConstraints();
274: gridBagConstraints.weightx = 1.0;
275: jPanel1.add(jPanel2, gridBagConstraints);
276:
277: jButtonOk.setText("OK");
278: jButtonOk.setEnabled(false);
279: jButtonOk.setMaximumSize(new java.awt.Dimension(200, 25));
280: jButtonOk.setPreferredSize(new java.awt.Dimension(100, 25));
281: jButtonOk
282: .addActionListener(new java.awt.event.ActionListener() {
283: public void actionPerformed(
284: java.awt.event.ActionEvent evt) {
285: jButtonOkActionPerformed(evt);
286: }
287: });
288:
289: gridBagConstraints = new java.awt.GridBagConstraints();
290: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
291: gridBagConstraints.weightx = 0.1;
292: gridBagConstraints.insets = new java.awt.Insets(4, 2, 4, 4);
293: jPanel1.add(jButtonOk, gridBagConstraints);
294:
295: jButtonCancel.setText("Cancel");
296: jButtonCancel
297: .addActionListener(new java.awt.event.ActionListener() {
298: public void actionPerformed(
299: java.awt.event.ActionEvent evt) {
300: jButtonCancelActionPerformed(evt);
301: }
302: });
303:
304: gridBagConstraints = new java.awt.GridBagConstraints();
305: gridBagConstraints.insets = new java.awt.Insets(4, 2, 4, 2);
306: jPanel1.add(jButtonCancel, gridBagConstraints);
307:
308: getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
309:
310: pack();
311: }
312:
313: // </editor-fold>//GEN-END:initComponents
314:
315: private void jButtonCancelActionPerformed(
316: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
317:
318: setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
319: this .setVisible(false);
320: this .dispose();
321:
322: }//GEN-LAST:event_jButtonCancelActionPerformed
323:
324: private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
325:
326: setDialogResult(javax.swing.JOptionPane.OK_OPTION);
327:
328: ChartDescriptor cd = (ChartDescriptor) jList1
329: .getSelectedValue();
330: try {
331: this .setChart((Chart) (getClass().forName(cd
332: .getImplementationClass())).newInstance());
333: } catch (Exception ex) {
334:
335: }
336: this .setVisible(true);
337: this .dispose();
338:
339: }//GEN-LAST:event_jButtonOkActionPerformed
340:
341: public int getDialogResult() {
342: return dialogResult;
343: }
344:
345: public void setDialogResult(int dialogResult) {
346: this .dialogResult = dialogResult;
347: }
348:
349: // Variables declaration - do not modify//GEN-BEGIN:variables
350: private javax.swing.JButton jButtonCancel;
351: private javax.swing.JButton jButtonOk;
352: private javax.swing.JLabel jLabelChartNameVal;
353: private javax.swing.JPanel jPanel1;
354: private javax.swing.JPanel jPanel2;
355: private javax.swing.JPanel jPanel5;
356: private javax.swing.JPanel jPanel6;
357: private javax.swing.JPanel jPanelChartType;
358:
359: // End of variables declaration//GEN-END:variables
360:
361: void selectedChart() {
362: if (jList1.getSelectedIndex() >= 0) {
363: ChartDescriptor cd = (ChartDescriptor) jList1
364: .getSelectedValue();
365: this .jLabelChartNameVal.setText(cd.getName());
366:
367: this .jButtonOk.setEnabled(true);
368: } else {
369: this .jButtonOk.setEnabled(false);
370: }
371: }
372:
373: public Chart getChart() {
374: return chart;
375: }
376:
377: public void setChart(Chart chart) {
378: this .chart = chart;
379: }
380:
381: public boolean isMultiAxisMode() {
382: return multiAxisMode;
383: }
384:
385: public void setMultiAxisMode(boolean multiAxisMode) {
386: this .multiAxisMode = multiAxisMode;
387:
388: updateCharts();
389: }
390:
391: public void applyI18n() {
392: // Start autogenerated code ----------------------
393: jButtonCancel.setText(I18n.getString(
394: "chartSelectionJDialog.buttonCancel", "Cancel"));
395: jButtonOk.setText(I18n.getString(
396: "chartSelectionJDialog.buttonOk", "OK"));
397: // End autogenerated code ----------------------
398: ((javax.swing.border.TitledBorder) jPanel5.getBorder())
399: .setTitle(I18n.getString(
400: "chartSelectionJDialog.panelBorder.ChartInfo",
401: "Chart info"));
402:
403: jButtonCancel.setMnemonic(I18n.getString(
404: "chartSelectionJDialog.buttonCancelMnemonic", "c")
405: .charAt(0));
406: jButtonOk.setMnemonic(I18n.getString(
407: "chartSelectionJDialog.buttonOkMnemonic", "o")
408: .charAt(0));
409:
410: }
411: }
|