001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.ide.common;
053:
054: import java.awt.BorderLayout;
055: import java.awt.Dimension;
056: import java.awt.event.ActionEvent;
057: import java.awt.event.ActionListener;
058: import javax.swing.JButton;
059: import javax.swing.JDialog;
060: import javax.swing.JFrame;
061: import javax.swing.JPanel;
062: import javax.swing.JScrollPane;
063: import javax.swing.border.EmptyBorder;
064: import org.acm.seguin.awt.CenterDialog;
065: import org.acm.seguin.summary.PackageSummary;
066:
067: /**
068: * The package selector dialog box
069: *
070: *@author Chris Seguin
071: *@created October 18, 2001
072: */
073: public class PackageSelectorDialog extends JDialog implements
074: ActionListener {
075: private ButtonPanel buttons;
076: private PackageSelectorArea selection;
077: private PackageSummary summary;
078:
079: /**
080: * Constructor for the PackageSelectorDialog object
081: *
082: *@param parent the parent dialog rame
083: */
084: public PackageSelectorDialog(JFrame parent) {
085: super (parent, "Select package to view", true);
086:
087: getContentPane().setLayout(new BorderLayout());
088: super .setSize(350, 325);
089:
090: selection = new PackageSelectorArea();
091: selection.loadPackages();
092: JScrollPane pane = selection.getScrollPane();
093: pane.setBorder(new EmptyBorder(10, 10, 10, 10));
094: getContentPane().add(pane, BorderLayout.CENTER);
095:
096: buttons = new ButtonPanel(this );
097: buttons.setLocation(220, 0);
098: getContentPane().add(buttons, BorderLayout.EAST);
099:
100: CenterDialog.center(this , parent);
101: }
102:
103: /**
104: * Gets the summary that has been selected
105: *
106: *@return the selected package summary
107: */
108: public PackageSummary getSummary() {
109: return summary;
110: }
111:
112: /**
113: * Selects the package when the user presses OK
114: *
115: *@param evt the action event
116: */
117: public void actionPerformed(ActionEvent evt) {
118: if (evt.getActionCommand().equals("OK")) {
119: summary = selection.getSelection();
120: dispose();
121: }
122: if (evt.getActionCommand().equals("Cancel")) {
123: summary = null;
124: dispose();
125: }
126: }
127:
128: /**
129: * The main program for the PackageSelectorDialog class
130: *
131: *@param args The command line arguments
132: */
133: public static void main(String[] args) {
134: (new PackageSelectorDialog(null)).setVisible(true);
135: }
136:
137: /**
138: * Quick and dirty panel to hold the buttons so that they are not resized
139: * as the window is adjusted.
140: *
141: *@author Chris Seguin
142: *@created October 18, 2001
143: */
144: private class ButtonPanel extends JPanel {
145: private ActionListener listener;
146: private Dimension preferredSize;
147:
148: /**
149: * Constructor for the ButtonPanel object
150: *
151: *@param listener Description of Parameter
152: */
153: public ButtonPanel(ActionListener listener) {
154: this .listener = listener;
155: init();
156:
157: preferredSize = new Dimension();
158: preferredSize.width = 110;
159: preferredSize.height = 80;
160:
161: this .setSize(preferredSize);
162: }
163:
164: /**
165: * Gets the MaximumSize attribute of the ButtonPanel object
166: *
167: *@return The MaximumSize value
168: */
169: public Dimension getMaximumSize() {
170: return preferredSize;
171: }
172:
173: /**
174: * Gets the MinimumSize attribute of the ButtonPanel object
175: *
176: *@return The MinimumSize value
177: */
178: public Dimension getMinimumSize() {
179: return preferredSize;
180: }
181:
182: /**
183: * Gets the PreferredSize attribute of the ButtonPanel object
184: *
185: *@return The PreferredSize value
186: */
187: public Dimension getPreferredSize() {
188: return preferredSize;
189: }
190:
191: /**
192: * Initialize the components of this panel
193: */
194: private void init() {
195: this .setLayout(null);
196:
197: JButton okButton = new JButton("OK");
198: okButton.setBounds(0, 10, 100, 25);
199: this .add(okButton);
200: okButton.addActionListener(listener);
201:
202: JButton cancelButton = new JButton("Cancel");
203: cancelButton.setBounds(0, 45, 100, 25);
204: this .add(cancelButton);
205: cancelButton.addActionListener(listener);
206: }
207: }
208: }
209: // EOF
|