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.lib.client.components.CenterPanelDialog;
022: import org.pentaho.reportdesigner.lib.client.components.TextComponentHelper;
023: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
024: import org.pentaho.reportdesigner.lib.client.util.UndoHelper;
025: import org.pentaho.reportdesigner.lib.client.util.WindowUtils;
026:
027: import javax.swing.*;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030:
031: /**
032: * User: Martin
033: * Date: 11.01.2006
034: * Time: 11:02:54
035: */
036: public class StringChooser {
037: private StringChooser() {
038: }
039:
040: @Nullable
041: public static String showStringArrayChooser(@NotNull
042: JComponent parent, @NotNull
043: String title, @Nullable
044: String value) {
045: final CenterPanelDialog centerPanelDialog = CenterPanelDialog
046: .createDialog(parent, title,
047: CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
048:
049: @NonNls
050: final FormLayout formLayout = new FormLayout(
051: "4dlu, fill:default:grow, 4dlu",
052: "4dlu, fill:default:grow, 4dlu");
053: final JPanel centerPanel = new JPanel(formLayout);
054:
055: final CellConstraints cc = new CellConstraints();
056:
057: JTextArea textArea = new JTextArea(value);
058: UndoHelper.installUndoSupport(textArea);
059: TextComponentHelper.installDefaultPopupMenu(textArea);
060:
061: centerPanel.add(new JScrollPane(textArea), cc.xy(2, 2));
062:
063: final boolean[] action = new boolean[] { false };
064:
065: JButton okButton = new JButton(TranslationManager.getInstance()
066: .getTranslation("R", "Button.ok"));
067: okButton.addActionListener(new ActionListener() {
068: public void actionPerformed(@NotNull
069: ActionEvent e) {
070: action[0] = true;
071: centerPanelDialog.dispose();
072: }
073: });
074:
075: JButton cancelButton = new JButton(TranslationManager
076: .getInstance().getTranslation("R", "Button.cancel"));
077: cancelButton.addActionListener(new ActionListener() {
078: public void actionPerformed(@NotNull
079: ActionEvent e) {
080: action[0] = false;
081: centerPanelDialog.dispose();
082: }
083: });
084:
085: centerPanelDialog.setButtons(okButton, cancelButton, okButton,
086: cancelButton);
087:
088: centerPanelDialog.setCenterPanel(centerPanel);
089: centerPanelDialog.pack();
090: centerPanelDialog.setSize(300, 300);
091: WindowUtils.setLocationRelativeTo(centerPanelDialog, parent);
092: centerPanelDialog.setVisible(true);
093:
094: if (action[0]) {
095: return textArea.getText();
096: }
097: return value;
098: }
099:
100: }
|