001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.wizard.reportgeneratewizard;
015:
016: import com.jgoodies.forms.layout.CellConstraints;
017: import com.jgoodies.forms.layout.FormLayout;
018: import org.jetbrains.annotations.NonNls;
019: import org.jetbrains.annotations.NotNull;
020: import org.jetbrains.annotations.Nullable;
021: import org.pentaho.reportdesigner.crm.report.IconLoader;
022: import org.pentaho.reportdesigner.crm.report.model.PageDefinition;
023: import org.pentaho.reportdesigner.crm.report.model.PageFormatPreset;
024: import org.pentaho.reportdesigner.crm.report.model.PageOrientation;
025: import org.pentaho.reportdesigner.crm.report.properties.editors.PageDefinitionChooser;
026: import org.pentaho.reportdesigner.crm.report.templateplugin.LayoutPlugin;
027: import org.pentaho.reportdesigner.crm.report.templateplugin.LayoutPluginRegistry;
028: import org.pentaho.reportdesigner.crm.report.wizard.AbstractWizardPage;
029: import org.pentaho.reportdesigner.crm.report.wizard.WizardData;
030: import org.pentaho.reportdesigner.lib.client.components.ComponentFactory;
031: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
032: import org.pentaho.reportdesigner.lib.client.util.UncaughtExcpetionsModel;
033:
034: import javax.swing.*;
035: import java.awt.*;
036: import java.awt.event.ActionEvent;
037: import java.awt.event.ActionListener;
038: import java.util.LinkedHashSet;
039:
040: /**
041: * User: Martin
042: * Date: 20.01.2006
043: * Time: 09:48:17
044: */
045: public class WizardPagePageSetup extends AbstractWizardPage {
046: @Nullable
047: private JPanel centerPanel;
048: @NotNull
049: private PageDefinition pageDefinition;
050: @NotNull
051: private LayoutPlugin layoutPlugin;
052:
053: public WizardPagePageSetup() {
054: }
055:
056: @NotNull
057: public JComponent getCenterPanel() {
058: JPanel centerPanel = this .centerPanel;
059: if (centerPanel == null) {
060: layoutPlugin = LayoutPluginRegistry.getInstance()
061: .getLayoutPlugins().iterator().next();//at least one has to be available
062:
063: pageDefinition = new PageDefinition(PageFormatPreset.A4,
064: PageOrientation.PORTRAIT, 20, 20, 20, 20);
065:
066: @NonNls
067: FormLayout formLayout = new FormLayout(
068: "4dlu, default, 4dlu, max(80dlu;default), 4dlu, default, 4dlu:grow",
069: "4dlu, " + "pref, " + "4dlu, " + "pref, "
070: + "4dlu, " + "pref, " + "4dlu:grow");
071: centerPanel = new JPanel(formLayout);
072: CellConstraints cc = new CellConstraints();
073:
074: final JTextField pageDefinitionTextField = new JTextField(
075: pageDefinition.getNiceName());
076: pageDefinitionTextField.setEditable(false);
077:
078: JLabel pageSetupLabel = ComponentFactory.createLabel("R",
079: "WizardPagePageSetup.PaperLabel",
080: pageDefinitionTextField);
081:
082: centerPanel.add(pageSetupLabel, cc.xy(2, 2));
083: centerPanel.add(pageDefinitionTextField, cc.xy(4, 2));
084:
085: JButton pageSetupButton = ComponentFactory.createButton(
086: "R", "WizardPagePageSetup.PageSetupButton");
087: pageSetupButton.setMargin(new Insets(1, 1, 1, 1));
088: centerPanel.add(pageSetupButton, cc.xy(6, 2));
089:
090: pageSetupButton.addActionListener(new ActionListener() {
091: public void actionPerformed(@NotNull
092: ActionEvent e) {
093: pageDefinition = PageDefinitionChooser
094: .showPageDefinitionChooser(
095: getWizardDialog().getReportDialog(),
096: getWizardDialog().getRootPane(),
097: TranslationManager
098: .getInstance()
099: .getTranslation("R",
100: "PropertyEditor.PageDefinition.Title"),
101: WizardPagePageSetup.this .pageDefinition);
102: pageDefinitionTextField.setText(pageDefinition
103: .getNiceName());
104: }
105: });
106:
107: JLabel templateLabel = new JLabel(TranslationManager
108: .getInstance().getTranslation("R",
109: "WizardPagePageSetup.TemplateLabel"));
110: centerPanel.add(templateLabel, cc.xy(2, 4));
111:
112: LinkedHashSet<LayoutPlugin> layoutPlugins = LayoutPluginRegistry
113: .getInstance().getLayoutPlugins();
114: final JComboBox templateComboBox = new JComboBox(
115: layoutPlugins
116: .toArray(new LayoutPlugin[layoutPlugins
117: .size()]));
118:
119: templateComboBox.setSelectedItem(layoutPlugin);
120: centerPanel.add(templateComboBox, cc.xy(4, 4));
121:
122: final JLabel templateSampleImageLabel = new JLabel(
123: layoutPlugin.getSampleImage());
124: templateSampleImageLabel.setBackground(Color.WHITE);
125: templateSampleImageLabel.setOpaque(true);
126: templateSampleImageLabel.setBorder(BorderFactory
127: .createLineBorder(Color.GRAY));
128: centerPanel.add(templateSampleImageLabel, cc.xy(4, 6));
129:
130: templateComboBox.addActionListener(new ActionListener() {
131: public void actionPerformed(@NotNull
132: ActionEvent e) {
133: layoutPlugin = (LayoutPlugin) templateComboBox
134: .getSelectedItem();
135: templateSampleImageLabel.setIcon(layoutPlugin
136: .getSampleImage());
137: }
138: });
139:
140: templateComboBox.setRenderer(new DefaultListCellRenderer() {
141: @NotNull
142: public Component getListCellRendererComponent(@NotNull
143: JList list, @Nullable
144: Object value, int index, boolean isSelected,
145: boolean cellHasFocus) {
146: JLabel label = (JLabel) super
147: .getListCellRendererComponent(list, value,
148: index, isSelected, cellHasFocus);
149: try {
150: if (value instanceof LayoutPlugin) {
151: LayoutPlugin plugin = (LayoutPlugin) value;
152: label.setText(plugin.getLocalizedName());
153: }
154: } catch (Throwable e) {
155: UncaughtExcpetionsModel.getInstance()
156: .addException(e);
157: }
158: return label;
159: }
160: });
161: this .centerPanel = centerPanel;
162: }
163: return centerPanel;
164: }
165:
166: public boolean canNext() {
167: return true;
168: }
169:
170: public boolean canPrevious() {
171: return true;
172: }
173:
174: public boolean canCancel() {
175: return true;
176: }
177:
178: public boolean canFinish() {
179: return true;
180: }
181:
182: @NotNull
183: public WizardData[] getWizardDatas() {
184: return new WizardData[] {
185: new WizardData(WizardData.PAGE_DEFINITION,
186: pageDefinition),
187: new WizardData(WizardData.LAYOUT_PLUGIN, layoutPlugin) };
188: }
189:
190: @NotNull
191: public String getTitle() {
192: return TranslationManager.getInstance().getTranslation("R",
193: "WizardPagePageSetup.Title");
194: }
195:
196: @NotNull
197: public ImageIcon getIcon() {
198: return IconLoader.getInstance().getWizardPagePageSetupIcon();
199: }
200:
201: @NotNull
202: public String getDescription() {
203: return TranslationManager.getInstance().getTranslation("R",
204: "WizardPagePageSetup.Description");
205: }
206:
207: public void dispose() {
208: }
209:
210: }
|