1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: BrowserDialog.java,v $
19 Created on $Date: 2003/09/06 08:40:52 $
20 */
21 package net.sf.bloof.browser.dialogs;
22
23 import java.awt.BorderLayout;
24 import java.awt.Dimension;
25 import java.awt.Frame;
26 import java.awt.event.ActionEvent;
27 import java.util.HashMap;
28 import java.util.HashSet;
29 import java.util.Iterator;
30
31 import javax.swing.JButton;
32 import javax.swing.JComponent;
33 import javax.swing.JDialog;
34 import javax.swing.JLabel;
35 import javax.swing.JPanel;
36
37 import net.sf.bloof.browser.GuiConstants;
38 import net.sf.bloof.browser.GuiController;
39 import net.sf.bloof.browser.GuiFactory;
40 import net.sf.bloof.browser.events.BrowserAction;
41 import net.sf.bloof.browser.events.BrowserActionListener;
42 import net.sf.bloof.browser.events.BrowserEvent;
43 import net.sf.bloof.browser.events.BrowserEventListener;
44 import net.sf.bloof.browser.intl.Messages;
45 import net.sf.bloof.browser.intl.Text;
46
47 /**
48 * Superclass for dialogs in the bloof browser
49 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
50 * @version $Id: BrowserDialog.java,v 1.3 2003/09/06 08:40:52 pekacki Exp $
51 */
52 public abstract class BrowserDialog extends JDialog implements BrowserEventListener{
53 public BrowserDialog(HashMap aParams) {
54 super(
55 (Frame) aParams.get(PARAM_PARENT_FRAME),
56 (String) aParams.get(PARAM_TITLE),
57 true);
58 mTitle = (String) aParams.get(PARAM_TITLE);
59 mControl = (GuiController) aParams.get(GuiConstants.PARAM_GUI_CONTROLLER);
60 mControl.addBrowserEventListener(this);
61 addBrowserActionListener(mControl);
62 initView();
63 Dimension size = aParams.containsKey(PARAM_SIZE) ? (Dimension) aParams.get(PARAM_SIZE) : GuiConstants.DIALOG_SIZE;
64 setSize(size);
65 GuiFactory.centerOnScreen(this);
66 }
67 /**
68 * Handles the submit operation in the dialog
69 *
70 */
71 public void addBrowserActionListener(BrowserActionListener aListener) {
72 mBrowserActionListeners.add(aListener);
73 }
74
75 public void browserEventOccured(BrowserEvent bE) {
76 }
77
78 /**
79 * Handles the cancel operation in the dialog
80 *
81 */
82 protected void cancelDialog() {
83 this.dispose();
84 }
85 protected void informBrowserActionListeners(BrowserAction aBrowserAction) {
86 for (Iterator iter = mBrowserActionListeners.iterator(); iter.hasNext();) {
87 BrowserActionListener element = (BrowserActionListener) iter.next();
88 element.browserActionOccured(aBrowserAction);
89 }
90 }
91 /**
92 *
93 */
94 private JComponent initButtonsPanel() {
95 JPanel p = new JPanel();
96 JButton cancelButton = new JButton();
97 cancelButton.setText(Messages.getString(Text.CANCEL));
98 cancelButton.addActionListener(new java.awt.event.ActionListener() {
99 public void actionPerformed(ActionEvent aE) {
100 cancelDialog();
101 }
102 });
103 JButton okButton = new JButton();
104 okButton .setText(Messages.getString(Text.OK));
105 okButton .addActionListener(new java.awt.event.ActionListener() {
106 public void actionPerformed(ActionEvent aE) {
107 submitDialog();
108 }
109 });
110 p.add(okButton);
111 p.add(cancelButton);
112 return p;
113
114 }
115
116 private JComponent initTitlePanel() {
117 JPanel p = new JPanel();
118 JLabel l = GuiFactory.createLabel(mTitle, GuiConstants.FONT_TITLE);
119 p.add(l);
120 return p;
121 }
122
123 private void initView() {
124 JPanel rootComponent = new JPanel(new BorderLayout());
125 rootComponent.setBorder(GuiFactory.getBigBorder());
126 JComponent buttonPanel = initButtonsPanel();
127 JComponent tiltePanel = initTitlePanel();
128 rootComponent.add(tiltePanel, BorderLayout.NORTH);
129 rootComponent.add(buttonPanel, BorderLayout.SOUTH);
130 rootComponent.add(mContentPanel, BorderLayout.CENTER);
131 getContentPane().add(rootComponent);
132 }
133
134 protected abstract void submitDialog();
135 public final static String PARAM_PRESET_FILTER = "preset filter",
136 PARAM_PARENT_FRAME = "parent frame",
137 PARAM_SIZE = "size",
138 PARAM_TITLE = "title";
139 private HashSet mBrowserActionListeners = new HashSet();
140 /* big components */
141 protected JPanel mContentPanel = new JPanel();
142 protected GuiController mControl;
143 private String mTitle;
144 }