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: * BaseWizardPanel.java
028: *
029: * Created on March 22, 2006, 8:34 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.wizard;
034:
035: import javax.swing.JLabel;
036: import it.businesslogic.ireport.util.I18n;
037:
038: /**
039: *
040: * @author gtoffoli
041: */
042: public class BaseWizardPanel extends javax.swing.JPanel {
043:
044: private int currentStep = -1;
045: private GenericWizard genericWizard = null;
046:
047: private int dialogResult = javax.swing.JOptionPane.CLOSED_OPTION;
048:
049: /** Creates new form BaseWizardPanel */
050: public BaseWizardPanel() {
051: initComponents();
052: applyI18n();
053: }
054:
055: public int getDialogResult() {
056: return dialogResult;
057: }
058:
059: public void setDialogResult(int dialogResult) {
060: this .dialogResult = dialogResult;
061: }
062:
063: public GenericWizard getGenericWizard() {
064: return genericWizard;
065: }
066:
067: public void setGenericWizard(GenericWizard genericWizard) {
068: this .genericWizard = genericWizard;
069:
070: genericWizard.initWizard();
071: setCurrentStep(-1);
072: dialogResult = javax.swing.JOptionPane.CLOSED_OPTION;
073:
074: String[] stepsNames = genericWizard.getStepsNames();
075: jPanelLabels.removeAll();
076:
077: for (int i = 0; i < stepsNames.length; ++i) {
078: JLabel jLabelStep = new JLabel();
079: jLabelStep.setFont(new java.awt.Font(jLabelStep.getFont()
080: .getName(), 0, jLabelStep.getFont().getSize()));
081: jLabelStep.setText(stepsNames[i]);
082: java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
083: gridBagConstraints.gridx = 0;
084: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
085: gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
086: jPanelLabels.add(jLabelStep, gridBagConstraints);
087: }
088: goNext();
089: }
090:
091: public void goNext() {
092: if (getGenericWizard().nextStep(getCurrentStep() + 1)) {
093: setCurrentStep(getCurrentStep() + 1); // 0 = first step..
094: setCurrentStepLabel(getGenericWizard().getStepDescription(
095: getCurrentStep()));
096: jPanelStepContainer.removeAll();
097: jPanelStepContainer.add(getGenericWizard().getStepPanel(
098: getCurrentStep()), java.awt.BorderLayout.CENTER);
099: jPanelStepContainer.updateUI();
100: updateButtons();
101: }
102: }
103:
104: public void goStep(int x) {
105: setCurrentStep(x); // 0 = first step..
106: setCurrentStepLabel(getGenericWizard().getStepDescription(
107: getCurrentStep()));
108: jPanelStepContainer.removeAll();
109: jPanelStepContainer.add(getGenericWizard().getStepPanel(
110: getCurrentStep()), java.awt.BorderLayout.CENTER);
111: jPanelStepContainer.updateUI();
112: updateButtons();
113: }
114:
115: public void goPrevious() {
116: if (getCurrentStep() > 0) {
117: if (getGenericWizard().previousStep(getCurrentStep() - 1)) {
118: setCurrentStep(getCurrentStep() - 1);
119: setCurrentStepLabel(getGenericWizard()
120: .getStepDescription(getCurrentStep()));
121: jPanelStepContainer.removeAll();
122: jPanelStepContainer.add(getGenericWizard()
123: .getStepPanel(getCurrentStep()),
124: java.awt.BorderLayout.CENTER);
125: jPanelStepContainer.updateUI();
126:
127: updateButtons();
128: }
129: }
130: }
131:
132: public void updateButtons() {
133:
134: getJButtonFinish().setEnabled(
135: getGenericWizard().canFinish(getCurrentStep()));
136: getJButtonPrev().setEnabled(
137: getGenericWizard().canPrevious(getCurrentStep()));
138: getJButtonNext().setEnabled(
139: getGenericWizard().canNext(getCurrentStep()));
140: }
141:
142: private void setCurrentStepLabel(String label) {
143: jLabelStepDescription.setText(label);
144:
145: for (int i = 0; i < jPanelLabels.getComponentCount(); ++i) {
146: if (jPanelLabels.getComponent(i) instanceof JLabel) {
147: JLabel jLabel = (JLabel) jPanelLabels.getComponent(i);
148: jLabel.setFont(new java.awt.Font(jLabel.getFont()
149: .getName(), (i == getCurrentStep()) ? 1 : 0,
150: jLabel.getFont().getSize()));
151: jLabel.updateUI();
152: }
153: }
154: }
155:
156: public int getCurrentStep() {
157: return currentStep;
158: }
159:
160: public void setCurrentStep(int currentStep) {
161: this .currentStep = currentStep;
162: }
163:
164: public javax.swing.JButton getJButtonCancel() {
165: return jButtonCancel;
166: }
167:
168: public void setJButtonCancel(javax.swing.JButton jButtonCancel) {
169: this .jButtonCancel = jButtonCancel;
170: }
171:
172: public javax.swing.JButton getJButtonFinish() {
173: return jButtonFinish;
174: }
175:
176: public void setJButtonFinish(javax.swing.JButton jButtonFinish) {
177: this .jButtonFinish = jButtonFinish;
178: }
179:
180: public javax.swing.JButton getJButtonNext() {
181: return jButtonNext;
182: }
183:
184: public void setJButtonNext(javax.swing.JButton jButtonNext) {
185: this .jButtonNext = jButtonNext;
186: }
187:
188: public javax.swing.JButton getJButtonPrev() {
189: return jButtonPrev;
190: }
191:
192: public void setJButtonPrev(javax.swing.JButton jButtonPrev) {
193: this .jButtonPrev = jButtonPrev;
194: }
195:
196: /** This method is called from within the constructor to
197: * initialize the form.
198: * WARNING: Do NOT modify this code. The content of this method is
199: * always regenerated by the Form Editor.
200: */
201: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
202: private void initComponents() {
203: java.awt.GridBagConstraints gridBagConstraints;
204:
205: jPanelSteps = new javax.swing.JPanel();
206: jLabel1 = new javax.swing.JLabel();
207: jSeparator2 = new javax.swing.JSeparator();
208: jPanelLabels = new javax.swing.JPanel();
209: jLabelStep1 = new javax.swing.JLabel();
210: jLabel7 = new javax.swing.JLabel();
211: jPanelContent = new javax.swing.JPanel();
212: jPanel2 = new javax.swing.JPanel();
213: jLabelStepDescription = new javax.swing.JLabel();
214: jSeparator4 = new javax.swing.JSeparator();
215: jPanelStepContainer = new javax.swing.JPanel();
216: jSeparator3 = new javax.swing.JSeparator();
217: jPanelContentButtons = new javax.swing.JPanel();
218: jButtonPrev = new javax.swing.JButton();
219: jButtonNext = new javax.swing.JButton();
220: jButtonFinish = new javax.swing.JButton();
221: jButtonCancel = new javax.swing.JButton();
222:
223: setLayout(new java.awt.GridBagLayout());
224:
225: jPanelSteps.setLayout(new java.awt.GridBagLayout());
226:
227: jPanelSteps.setBackground(new java.awt.Color(207, 217, 231));
228: jPanelSteps.setPreferredSize(new java.awt.Dimension(150, 280));
229: jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
230: jLabel1.setText("Steps");
231: gridBagConstraints = new java.awt.GridBagConstraints();
232: gridBagConstraints.gridx = 0;
233: gridBagConstraints.gridy = 1;
234: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
235: gridBagConstraints.insets = new java.awt.Insets(8, 8, 0, 0);
236: jPanelSteps.add(jLabel1, gridBagConstraints);
237:
238: jSeparator2.setBackground(new java.awt.Color(204, 204, 255));
239: jSeparator2.setForeground(new java.awt.Color(0, 0, 0));
240: jSeparator2.setMaximumSize(new java.awt.Dimension(32767, 2));
241: jSeparator2.setMinimumSize(new java.awt.Dimension(2, 2));
242: jSeparator2.setPreferredSize(new java.awt.Dimension(1, 2));
243: gridBagConstraints = new java.awt.GridBagConstraints();
244: gridBagConstraints.gridx = 0;
245: gridBagConstraints.gridy = 2;
246: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
248: jPanelSteps.add(jSeparator2, gridBagConstraints);
249:
250: jPanelLabels.setLayout(new java.awt.GridBagLayout());
251:
252: jPanelLabels.setOpaque(false);
253: jLabelStep1.setFont(new java.awt.Font("Tahoma", 1, 11));
254: jLabelStep1.setText("1. SubDataset selection");
255: gridBagConstraints = new java.awt.GridBagConstraints();
256: gridBagConstraints.gridx = 0;
257: gridBagConstraints.gridy = 5;
258: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
259: gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
260: jPanelLabels.add(jLabelStep1, gridBagConstraints);
261:
262: gridBagConstraints = new java.awt.GridBagConstraints();
263: gridBagConstraints.gridx = 0;
264: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
265: jPanelSteps.add(jPanelLabels, gridBagConstraints);
266:
267: jLabel7.setBackground(new java.awt.Color(207, 217, 231));
268: jLabel7.setIcon(new javax.swing.ImageIcon(getClass()
269: .getResource(
270: "/it/businesslogic/ireport/icons/wizard.jpg")));
271: jLabel7.setVerticalAlignment(javax.swing.SwingConstants.TOP);
272: jLabel7.setOpaque(true);
273: jLabel7.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
274: gridBagConstraints = new java.awt.GridBagConstraints();
275: gridBagConstraints.gridx = 0;
276: gridBagConstraints.gridy = 0;
277: gridBagConstraints.gridheight = 20;
278: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
279: gridBagConstraints.weightx = 1.0;
280: gridBagConstraints.weighty = 1.0;
281: jPanelSteps.add(jLabel7, gridBagConstraints);
282:
283: gridBagConstraints = new java.awt.GridBagConstraints();
284: gridBagConstraints.gridx = 0;
285: gridBagConstraints.gridy = 0;
286: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
287: gridBagConstraints.weighty = 1.0;
288: add(jPanelSteps, gridBagConstraints);
289:
290: jPanelContent.setLayout(new java.awt.GridBagLayout());
291:
292: jPanelContent.setMinimumSize(new java.awt.Dimension(40, 40));
293: jPanelContent.setPreferredSize(new java.awt.Dimension(380, 40));
294: jPanel2.setLayout(new java.awt.GridBagLayout());
295:
296: jPanel2.setMinimumSize(new java.awt.Dimension(380, 40));
297: jPanel2.setPreferredSize(new java.awt.Dimension(380, 40));
298: jLabelStepDescription
299: .setFont(new java.awt.Font("Tahoma", 1, 11));
300: jLabelStepDescription.setText("Step description");
301: gridBagConstraints = new java.awt.GridBagConstraints();
302: gridBagConstraints.gridx = 0;
303: gridBagConstraints.gridy = 1;
304: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
305: gridBagConstraints.weightx = 1.0;
306: gridBagConstraints.insets = new java.awt.Insets(2, 8, 0, 0);
307: jPanel2.add(jLabelStepDescription, gridBagConstraints);
308:
309: jSeparator4.setBackground(new java.awt.Color(204, 204, 255));
310: jSeparator4.setForeground(new java.awt.Color(0, 0, 0));
311: jSeparator4.setMaximumSize(new java.awt.Dimension(32767, 2));
312: jSeparator4.setMinimumSize(new java.awt.Dimension(2, 2));
313: jSeparator4.setPreferredSize(new java.awt.Dimension(1, 2));
314: gridBagConstraints = new java.awt.GridBagConstraints();
315: gridBagConstraints.gridx = 0;
316: gridBagConstraints.gridy = 3;
317: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
318: gridBagConstraints.weightx = 1.0;
319: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
320: jPanel2.add(jSeparator4, gridBagConstraints);
321:
322: gridBagConstraints = new java.awt.GridBagConstraints();
323: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
324: gridBagConstraints.weightx = 1.0;
325: jPanelContent.add(jPanel2, gridBagConstraints);
326:
327: jPanelStepContainer.setLayout(new java.awt.BorderLayout());
328:
329: gridBagConstraints = new java.awt.GridBagConstraints();
330: gridBagConstraints.gridx = 0;
331: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
332: gridBagConstraints.weightx = 1.0;
333: gridBagConstraints.weighty = 1.0;
334: gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
335: jPanelContent.add(jPanelStepContainer, gridBagConstraints);
336:
337: gridBagConstraints = new java.awt.GridBagConstraints();
338: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
339: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
340: gridBagConstraints.weightx = 1.0;
341: gridBagConstraints.weighty = 1.0;
342: add(jPanelContent, gridBagConstraints);
343:
344: jSeparator3.setBackground(new java.awt.Color(204, 204, 255));
345: jSeparator3.setForeground(new java.awt.Color(0, 0, 0));
346: jSeparator3.setMaximumSize(new java.awt.Dimension(32767, 2));
347: jSeparator3.setMinimumSize(new java.awt.Dimension(2, 2));
348: jSeparator3.setPreferredSize(new java.awt.Dimension(1, 2));
349: gridBagConstraints = new java.awt.GridBagConstraints();
350: gridBagConstraints.gridx = 0;
351: gridBagConstraints.gridy = 2;
352: gridBagConstraints.gridwidth = 2;
353: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
354: add(jSeparator3, gridBagConstraints);
355:
356: jPanelContentButtons.setLayout(new java.awt.GridBagLayout());
357:
358: jButtonPrev.setText("< Prev");
359: jButtonPrev.setEnabled(false);
360: jButtonPrev
361: .addActionListener(new java.awt.event.ActionListener() {
362: public void actionPerformed(
363: java.awt.event.ActionEvent evt) {
364: jButtonPrevActionPerformed(evt);
365: }
366: });
367:
368: gridBagConstraints = new java.awt.GridBagConstraints();
369: gridBagConstraints.insets = new java.awt.Insets(8, 2, 8, 2);
370: jPanelContentButtons.add(jButtonPrev, gridBagConstraints);
371:
372: jButtonNext.setText("Next >");
373: jButtonNext.setEnabled(false);
374: jButtonNext
375: .addActionListener(new java.awt.event.ActionListener() {
376: public void actionPerformed(
377: java.awt.event.ActionEvent evt) {
378: jButtonNextActionPerformed(evt);
379: }
380: });
381:
382: gridBagConstraints = new java.awt.GridBagConstraints();
383: gridBagConstraints.insets = new java.awt.Insets(8, 2, 8, 2);
384: jPanelContentButtons.add(jButtonNext, gridBagConstraints);
385:
386: jButtonFinish.setText("Finish");
387: jButtonFinish
388: .addActionListener(new java.awt.event.ActionListener() {
389: public void actionPerformed(
390: java.awt.event.ActionEvent evt) {
391: jButtonFinishActionPerformed(evt);
392: }
393: });
394:
395: gridBagConstraints = new java.awt.GridBagConstraints();
396: gridBagConstraints.insets = new java.awt.Insets(8, 2, 8, 2);
397: jPanelContentButtons.add(jButtonFinish, gridBagConstraints);
398:
399: jButtonCancel.setText("Cancel");
400: jButtonCancel
401: .addActionListener(new java.awt.event.ActionListener() {
402: public void actionPerformed(
403: java.awt.event.ActionEvent evt) {
404: jButtonCancelActionPerformed(evt);
405: }
406: });
407:
408: gridBagConstraints = new java.awt.GridBagConstraints();
409: gridBagConstraints.insets = new java.awt.Insets(8, 2, 8, 4);
410: jPanelContentButtons.add(jButtonCancel, gridBagConstraints);
411:
412: gridBagConstraints = new java.awt.GridBagConstraints();
413: gridBagConstraints.gridx = 0;
414: gridBagConstraints.gridwidth = 2;
415: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
416: gridBagConstraints.weightx = 1.0;
417: add(jPanelContentButtons, gridBagConstraints);
418:
419: }// </editor-fold>//GEN-END:initComponents
420:
421: private void jButtonCancelActionPerformed(
422: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
423: setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
424: getGenericWizard().finish(-1);
425: }//GEN-LAST:event_jButtonCancelActionPerformed
426:
427: private void jButtonFinishActionPerformed(
428: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFinishActionPerformed
429: setDialogResult(javax.swing.JOptionPane.OK_OPTION);
430: getGenericWizard().finish(getCurrentStep());
431: }//GEN-LAST:event_jButtonFinishActionPerformed
432:
433: private void jButtonNextActionPerformed(
434: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNextActionPerformed
435: this .goNext();
436: }//GEN-LAST:event_jButtonNextActionPerformed
437:
438: private void jButtonPrevActionPerformed(
439: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPrevActionPerformed
440: this .goPrevious();
441: }//GEN-LAST:event_jButtonPrevActionPerformed
442:
443: // Variables declaration - do not modify//GEN-BEGIN:variables
444: private javax.swing.JButton jButtonCancel;
445: private javax.swing.JButton jButtonFinish;
446: private javax.swing.JButton jButtonNext;
447: private javax.swing.JButton jButtonPrev;
448: private javax.swing.JLabel jLabel1;
449: private javax.swing.JLabel jLabel7;
450: private javax.swing.JLabel jLabelStep1;
451: private javax.swing.JLabel jLabelStepDescription;
452: private javax.swing.JPanel jPanel2;
453: private javax.swing.JPanel jPanelContent;
454: private javax.swing.JPanel jPanelContentButtons;
455: private javax.swing.JPanel jPanelLabels;
456: private javax.swing.JPanel jPanelStepContainer;
457: private javax.swing.JPanel jPanelSteps;
458: private javax.swing.JSeparator jSeparator2;
459: private javax.swing.JSeparator jSeparator3;
460: private javax.swing.JSeparator jSeparator4;
461:
462: // End of variables declaration//GEN-END:variables
463:
464: public void applyI18n() {
465: // Start autogenerated code ----------------------
466: jButtonCancel.setText(I18n.getString(
467: "baseWizardPanel.buttonCancel", "Cancel"));
468: jButtonFinish.setText(I18n.getString(
469: "baseWizardPanel.buttonFinish", "Finish"));
470: jButtonNext.setText(I18n.getString(
471: "baseWizardPanel.buttonNext", "Next >"));
472: jButtonPrev.setText(I18n.getString(
473: "baseWizardPanel.buttonPrev", "< Prev"));
474: jLabel1.setText(I18n.getString("baseWizardPanel.label1",
475: "Steps"));
476: jLabelStep1.setText(I18n
477: .getString("baseWizardPanel.labelStep1",
478: "1. SubDataset selection"));
479: jLabelStepDescription.setText(I18n.getString(
480: "baseWizardPanel.labelStepDescription",
481: "Step description"));
482: // End autogenerated code ----------------------
483: }
484: }
|