001: /* ====================================================================
002: * Copyright (c) 1998 - 2003 David F. Glasser. All rights
003: * reserved.
004: *
005: * This file is part of the QueryForm Database Tool.
006: *
007: * The QueryForm Database Tool is free software; you can redistribute it
008: * and/or modify it under the terms of the GNU General Public License as
009: * published by the Free Software Foundation; either version 2 of the
010: * License, or (at your option) any later version.
011: *
012: * The QueryForm Database Tool is distributed in the hope that it will
013: * be useful, but WITHOUT ANY WARRANTY; without even the implied
014: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
015: * See the GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with the QueryForm Database Tool; if not, write to:
019: *
020: * The Free Software Foundation, Inc.,
021: * 59 Temple Place, Suite 330
022: * Boston, MA 02111-1307 USA
023: *
024: * or visit http://www.gnu.org.
025: *
026: * ====================================================================
027: *
028: * This product includes software developed by the
029: * Apache Software Foundation (http://www.apache.org/).
030: *
031: * ====================================================================
032: *
033: * $Source: /cvsroot/qform/qform/src/org/glasser/qform/ThirdPartyLafDialog.java,v $
034: * $Revision: 1.2 $
035: * $Author: dglasser $
036: * $Date: 2003/07/14 10:13:58 $
037: *
038: * --------------------------------------------------------------------
039: */
040: package org.glasser.qform;
041:
042: import java.awt.*;
043: import java.awt.event.*;
044: import javax.swing.*;
045: import javax.swing.text.JTextComponent;
046: import javax.swing.border.EmptyBorder;
047:
048: import org.glasser.swing.*;
049:
050: /**
051: * This dialog is used to get the name of a Look And Feel class from the user.
052: */
053: public class ThirdPartyLafDialog extends JDialog implements
054: ActionListener {
055:
056: public static boolean debug = System
057: .getProperty("ThirdPartyLafDialog.debug") != null;
058:
059: private JTextField txtInput = new JTextField();
060:
061: private JLabel lblHeader = new JLabel();
062:
063: private JButton btnPrev = new JButton();
064:
065: private JButton btnNext = new JButton();
066:
067: private JButton btnOK = new JButton("OK");
068:
069: private JButton btnCancel = new JButton("Cancel");
070:
071: private Object[][] buttonConfig = {
072: { btnOK, "O", "SUBMIT",
073: "Enter the class name for a third-party look-and-feel." },
074: { btnCancel, "C", "CANCEL", "Cancel the operation." }
075:
076: };
077:
078: String prompt = "Enter the fully-qualified class name of the Look and Feel class you "
079: + "are going to install. This will be something similar to \"com.sun.java.swing.plaf.gtk.GTKLookAndFeel,\""
080: + " and the class it represents should currently be in QueryForm's classpath."
081: + "\n\nIf it is not in QueryForm's classpath, "
082: + "you can add it by placing its jar file in QueryForm's \"drivers\" directory and restarting QueryForm."
083: + "\n\nIf you do not know the class name for the Look and Feel, consult the Look and Feel's documentation.";
084:
085: JTextArea promptDisplay = null;
086:
087: public ThirdPartyLafDialog(Frame parent) {
088: super (parent);
089:
090: setTitle("Install Look And Feel");
091:
092: JPanel panel = new JPanel();
093:
094: panel.setBorder(new EmptyBorder(10, 10, 10, 10));
095:
096: panel.setLayout(new BorderLayout());
097:
098: promptDisplay = new JTextArea() {
099: public void updateUI() {
100: super .updateUI();
101: Color background = UIManager
102: .getColor("Panel.background");
103: if (background != null) {
104: if (debug)
105: System.out
106: .println("promptDisplay: using Panel.background.");
107: setBackground(background);
108: } else {
109: Container parent = getParent();
110: if (parent != null) {
111: System.out.println("Parent class is "
112: + parent.getClass());
113: background = parent.getBackground();
114: if (background != null) {
115: if (debug)
116: System.out
117: .println("promptDisplay: using parent.getBackground(): "
118: + background);
119: setBackground(background);
120: }
121: }
122: }
123:
124: Color foreground = UIManager
125: .getColor("Label.foreground");
126: if (foreground == null)
127: foreground = Color.black;
128: setDisabledTextColor(foreground);
129: setForeground(foreground);
130:
131: setFont(UIManager.getFont("Label.font"));
132: }
133: };
134:
135: promptDisplay.setEditable(false);
136: promptDisplay.setEnabled(false);
137: promptDisplay.setText(prompt);
138: promptDisplay.setBorder(new EmptyBorder(10, 10, 10, 10));
139: promptDisplay.setLineWrap(true);
140: promptDisplay.setWrapStyleWord(true);
141: promptDisplay.setColumns(35);
142: promptDisplay.setRows(12);
143: promptDisplay.setOpaque(false);
144:
145: JPanel topPanel = new JPanel();
146: topPanel.setLayout(new BorderLayout());
147: topPanel.add(promptDisplay, BorderLayout.CENTER);
148: topPanel.add(txtInput, BorderLayout.SOUTH);
149:
150: panel.add(topPanel, BorderLayout.CENTER);
151:
152: JPanel buttonPanel = new JPanel();
153:
154: GUIHelper.buildButtonPanel(buttonPanel, buttonConfig, this );
155:
156: txtInput
157: .setBorder(new ThinBevelBorder(ThinBevelBorder.LOWERED));
158: txtInput.enableInputMethods(false);
159: txtInput.setColumns(35);
160:
161: panel.add(buttonPanel, BorderLayout.SOUTH);
162:
163: // make it so the ESCAPE key closes the dialog.
164: KeyStroke esc = KeyStroke.getKeyStroke("ESCAPE");
165: ButtonClicker closer = new ButtonClicker(btnCancel);
166: panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(esc,
167: "_ESCAPE_");
168: panel
169: .getInputMap(
170: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
171: .put(esc, "_ESCAPE_");
172: panel.getActionMap().put("_ESCAPE_", closer);
173: setContentPane(panel);
174: promptDisplay.updateUI();
175: pack();
176:
177: setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
178:
179: }
180:
181: public void setVisible(boolean b) {
182: if (b)
183: throw new RuntimeException(
184: "ThirdPartyLafDialog must be opened with the openDialog() method.");
185: }
186:
187: /**
188: * This opens the dialog in a modal state, with the last item
189: * in the historyList displayed for editing. When this method returns,
190: * the results of the user editing can be retrieved with getWhereClause().
191: */
192: public void openDialog() {
193: txtInput.setText(null);
194: setModal(true);
195: txtInput.requestFocus();
196: super .setVisible(true);
197: txtInput.requestFocus();
198: }
199:
200: String input = null;
201:
202: /**
203: * When a user closes the dialog, this returns the results of the editing.
204: * The returned String will always be non-null if the user clicks Submit; it will be an
205: * empty String ("") if the user clicks Submit without entering anything. It will be
206: * null if the user closes the dialog or clicks Cancel.
207: */
208: public String getInput() {
209: return input;
210: }
211:
212: public void actionPerformed(ActionEvent e) {
213:
214: String command = e.getActionCommand();
215: if (command.equals("SUBMIT")) {
216: input = txtInput.getText();
217: if (input == null || (input = input.trim()).length() == 0) {
218: input = null;
219: GUIHelper
220: .errMsg(
221: this ,
222: "Please enter a Look And Feel class name, or click Cancel.",
223: null);
224: return;
225: }
226: super .setVisible(false);
227: } else if (command.equals("CANCEL")) {
228: input = null;
229: super .setVisible(false);
230: }
231: }
232:
233: }
|