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.properties.editors;
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.model.ElementPadding;
022: import org.pentaho.reportdesigner.lib.client.components.CenterPanelDialog;
023: import org.pentaho.reportdesigner.lib.client.components.TextComponentHelper;
024: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
025: import org.pentaho.reportdesigner.lib.client.util.UndoHelper;
026: import org.pentaho.reportdesigner.lib.client.util.WindowUtils;
027:
028: import javax.swing.*;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.util.logging.Level;
032: import java.util.logging.Logger;
033:
034: /**
035: * User: Martin
036: * Date: 01.11.2005
037: * Time: 10:23:10
038: */
039: public class PaddingChooser {
040: @NonNls
041: @NotNull
042: private static final Logger LOG = Logger
043: .getLogger(PaddingChooser.class.getName());
044:
045: private PaddingChooser() {
046: }
047:
048: @Nullable
049: public static ElementPadding showValueChooser(@NotNull
050: JComponent parent, @NotNull
051: String title, @Nullable
052: ElementPadding initialValue) {
053: final CenterPanelDialog centerPanelDialog = CenterPanelDialog
054: .createDialog(parent, title,
055: CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
056:
057: @NonNls
058: FormLayout formLayout = new FormLayout(
059: "0dlu, right:max(60dlu;default), 4dlu, fill:default:grow, 0dlu",
060: "0dlu, " + "pref, " + "4dlu, " + "pref, " + "4dlu, "
061: + "pref, " + "4dlu, " + "pref, " + "4dlu, "
062: + "0dlu:grow");
063:
064: JPanel centerPanel = new JPanel(formLayout);
065: CellConstraints cc = new CellConstraints();
066:
067: JTextField textField1 = new JTextField(
068: initialValue != null ? String.valueOf(initialValue
069: .getTop()) : "");
070: UndoHelper.installUndoSupport(textField1);
071: TextComponentHelper.installDefaultPopupMenu(textField1);
072:
073: JTextField textField2 = new JTextField(
074: initialValue != null ? String.valueOf(initialValue
075: .getBottom()) : "");
076: UndoHelper.installUndoSupport(textField2);
077: TextComponentHelper.installDefaultPopupMenu(textField2);
078:
079: JTextField textField3 = new JTextField(
080: initialValue != null ? String.valueOf(initialValue
081: .getLeft()) : "");
082: UndoHelper.installUndoSupport(textField3);
083: TextComponentHelper.installDefaultPopupMenu(textField3);
084:
085: JTextField textField4 = new JTextField(
086: initialValue != null ? String.valueOf(initialValue
087: .getRight()) : "");
088: UndoHelper.installUndoSupport(textField4);
089: TextComponentHelper.installDefaultPopupMenu(textField4);
090:
091: centerPanel.add(new JLabel(TranslationManager.getInstance()
092: .getTranslation("R", "Padding.top")), cc.xy(2, 2));
093: centerPanel.add(textField1, cc.xy(4, 2));
094: centerPanel.add(new JLabel(TranslationManager.getInstance()
095: .getTranslation("R", "Padding.bottom")), cc.xy(2, 4));
096: centerPanel.add(textField2, cc.xy(4, 4));
097: centerPanel.add(new JLabel(TranslationManager.getInstance()
098: .getTranslation("R", "Padding.left")), cc.xy(2, 6));
099: centerPanel.add(textField3, cc.xy(4, 6));
100: centerPanel.add(new JLabel(TranslationManager.getInstance()
101: .getTranslation("R", "Padding.right")), cc.xy(2, 8));
102: centerPanel.add(textField4, cc.xy(4, 8));
103:
104: final boolean[] action = new boolean[] { false };
105:
106: JButton okButton = new JButton(TranslationManager.getInstance()
107: .getTranslation("R", "Button.ok"));
108: okButton.addActionListener(new ActionListener() {
109: public void actionPerformed(@NotNull
110: ActionEvent e) {
111: action[0] = true;
112: centerPanelDialog.dispose();
113: }
114: });
115:
116: JButton cancelButton = new JButton(TranslationManager
117: .getInstance().getTranslation("R", "Button.cancel"));
118: cancelButton.addActionListener(new ActionListener() {
119: public void actionPerformed(@NotNull
120: ActionEvent e) {
121: action[0] = false;
122: centerPanelDialog.dispose();
123: }
124: });
125:
126: centerPanelDialog.setButtons(okButton, cancelButton, okButton,
127: cancelButton);
128:
129: centerPanelDialog.setCenterPanel(centerPanel);
130: centerPanelDialog.pack();
131: WindowUtils.setLocationRelativeTo(centerPanelDialog, parent);
132: centerPanelDialog.setVisible(true);
133:
134: if (action[0]) {
135: double d1;
136: double d2;
137: double d3;
138: double d4;
139: try {
140: d1 = Double.parseDouble(textField1.getText());
141: d2 = Double.parseDouble(textField2.getText());
142: d3 = Double.parseDouble(textField3.getText());
143: d4 = Double.parseDouble(textField4.getText());
144: } catch (NumberFormatException e) {
145: if (LOG.isLoggable(Level.FINE))
146: LOG.log(Level.FINE,
147: "PaddingChooser.showValueChooser ", e);
148: return initialValue;
149: }
150:
151: return new ElementPadding(d1, d2, d3, d4);
152: }
153: return initialValue;
154: }
155: }
|