001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks.demo;
032:
033: import java.awt.Container;
034: import java.awt.Dialog;
035: import java.awt.FileDialog;
036: import java.awt.event.ActionEvent;
037: import java.awt.event.ActionListener;
038:
039: import javax.swing.*;
040:
041: import com.jgoodies.forms.builder.ButtonBarBuilder;
042: import com.jgoodies.forms.builder.PanelBuilder;
043: import com.jgoodies.forms.layout.CellConstraints;
044: import com.jgoodies.forms.layout.FormLayout;
045:
046: /**
047: * Contains a bunch of buttons to open a bunch of standard dialogs.
048: *
049: * @author Karsten Lentzsch
050: * @version $Revision: 1.3 $
051: */
052: final class DialogsTab {
053:
054: private Container parent;
055:
056: private JButton informationButton;
057: private JButton warningButton;
058: private JButton questionButton;
059: private JButton errorButton;
060: private JButton chooseFileNativeButton;
061: private JButton chooseFileSwingButton;
062:
063: /**
064: * Creates and configures the UI components.
065: */
066: private void initComponents() {
067: informationButton = new JButton("Information");
068: informationButton.addActionListener(new ActionListener() {
069: public void actionPerformed(ActionEvent e) {
070: JOptionPane
071: .showMessageDialog(
072: getParentFrame(),
073: "We just wanted to let you know that you have pressed\n"
074: + "the Information button to open this sample message dialog.\n\n",
075: "Information",
076: JOptionPane.INFORMATION_MESSAGE);
077: }
078: });
079: warningButton = new JButton("Warning");
080: warningButton.addActionListener(new ActionListener() {
081: public void actionPerformed(ActionEvent e) {
082: JOptionPane
083: .showMessageDialog(
084: getParentFrame(),
085: "We just wanted to let you know that you have pressed\n"
086: + "the Warning button to open this sample message dialog.\n\n",
087: "Warning", JOptionPane.WARNING_MESSAGE);
088: }
089: });
090: questionButton = new JButton("Question");
091: questionButton.addActionListener(new ActionListener() {
092: public void actionPerformed(ActionEvent e) {
093: JOptionPane
094: .showConfirmDialog(
095: getParentFrame(),
096: "We just wanted to let you know that you have pressed\n"
097: + "the Question button to open this sample question dialog.\n\n"
098: + "Are you satisfied with the dialog's appearance?\n\n",
099: "Question", JOptionPane.YES_NO_OPTION);
100: }
101: });
102: errorButton = new JButton("Error");
103: errorButton.addActionListener(new ActionListener() {
104: public void actionPerformed(ActionEvent e) {
105: JOptionPane
106: .showMessageDialog(
107: getParentFrame(),
108: "We just wanted to let you know that you have pressed\n"
109: + "the Error button to open this error message dialog.\n\n"
110: + "Just go ahead and proceed.\n\n",
111: "Error", JOptionPane.ERROR_MESSAGE);
112: }
113: });
114: chooseFileNativeButton = new JButton("Open...");
115: chooseFileNativeButton.addActionListener(new ActionListener() {
116: public void actionPerformed(ActionEvent e) {
117: Dialog dialog = new FileDialog(getParentFrame(),
118: "Open File (Native)");
119: dialog.setResizable(true);
120: dialog.setVisible(true);
121: }
122: });
123: chooseFileSwingButton = new JButton("Open...");
124: chooseFileSwingButton.addActionListener(new ActionListener() {
125: public void actionPerformed(ActionEvent e) {
126: new JFileChooser("Open File (Swing)")
127: .showOpenDialog(getParentFrame());
128: }
129: });
130: }
131:
132: /**
133: * Builds and returns the panel.
134: */
135: JComponent build(Container aParent) {
136: this .parent = aParent;
137: initComponents();
138:
139: FormLayout layout = new FormLayout(
140: "0:grow, left:pref, 0:grow",
141: "0:grow, pref, 4dlu, pref, 14dlu, pref, 4dlu, pref, 14dlu, pref, 4dlu, pref, 0:grow");
142: PanelBuilder builder = new PanelBuilder(layout);
143: builder.setDefaultDialogBorder();
144: builder.getPanel().setOpaque(false);
145:
146: CellConstraints cc = new CellConstraints();
147:
148: builder.addLabel("Press a button to open a message dialog.", cc
149: .xy(2, 2));
150: builder.add(buildButtonBar(), cc.xy(2, 4));
151: builder.addLabel("This opens the native file chooser.", cc.xy(
152: 2, 6));
153: builder.add(chooseFileNativeButton, cc.xy(2, 8));
154: builder.addLabel("This opens the Swing file chooser.", cc.xy(2,
155: 10));
156: builder.add(chooseFileSwingButton, cc.xy(2, 12));
157:
158: return builder.getPanel();
159: }
160:
161: /**
162: * Builds and returns the message dialog button bar.
163: *
164: * @return the message dialog button bar
165: */
166: private JPanel buildButtonBar() {
167: ButtonBarBuilder builder = new ButtonBarBuilder();
168: builder.getPanel().setOpaque(false);
169: builder.addGriddedButtons(new JButton[] { informationButton,
170: warningButton, questionButton, errorButton });
171: return builder.getPanel();
172: }
173:
174: // Helper Code ************************************************************
175:
176: JFrame getParentFrame() {
177: return (JFrame) (SwingUtilities.getWindowAncestor(parent));
178: }
179:
180: }
|