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: DialogOpenProject.java,v $
19 Created on $Date: 2003/06/30 08:05:41 $
20 */
21 package net.sf.bloof.browser;
22
23 import java.awt.BorderLayout;
24 import java.awt.Frame;
25 import java.awt.event.ActionEvent;
26
27 import javax.swing.DefaultListModel;
28 import javax.swing.JButton;
29 import javax.swing.JDialog;
30 import javax.swing.JList;
31 import javax.swing.JPanel;
32
33 import net.sf.bloof.db.DbAccess;
34
35 /**
36 * Opens an existing Bloof project
37 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
38 */
39
40 public class DialogOpenProject extends JDialog {
41
42 /**
43 * Default constructor
44 * @see java.awt.Dialog#Dialog( Frame, String, boolean )
45 */
46 public DialogOpenProject(Frame aFrame, String aTitle, boolean aModal) {
47 super(aFrame, aTitle, aModal);
48 try {
49 initFrame();
50 pack();
51 } catch (Exception ex) {
52 ex.printStackTrace();
53 }
54 }
55
56 private void cancelButtonActionPerformed(ActionEvent aE) {
57 Main.getGuiControl().processUselessEvent(aE);
58 this.dispose();
59 }
60
61 /**
62 * Method getdbAccess.
63 * @return DbAccess
64 */
65 public DbAccess getdbAccess() {
66 return mDbAccess;
67 }
68
69 /**
70 * Method getdbAccess.
71 * @return Project
72 */
73 public Project getProject() {
74 return mProject;
75 }
76 private void initFrame() throws Exception {
77 /* init root pannel */
78 JPanel rootPanel = new JPanel(new BorderLayout());
79
80 /* init buttons panel */
81 JPanel buttonsPanel = new JPanel();
82 JButton cancelButton = new JButton("Cancel");
83 cancelButton.addActionListener(new java.awt.event.ActionListener() {
84 public void actionPerformed(ActionEvent aE) {
85 cancelButtonActionPerformed(aE);
86 }
87 });
88 JButton okButton = new JButton("OK");
89 okButton.addActionListener(new java.awt.event.ActionListener() {
90 public void actionPerformed(ActionEvent aE) {
91 okButtonActionPerformed(aE);
92 }
93 });
94
95 Project[] p = Main.getProjects();
96 DefaultListModel model = new DefaultListModel();
97 for (int i = 0; i < p.length; i++) {
98 model.addElement(p[i]);
99 }
100 mProjets.setModel(model);
101 mProjets.setSelectedIndex(0);
102 /* construct buttons pane */
103 buttonsPanel.add(okButton, null);
104 buttonsPanel.add(cancelButton, null);
105 /* construct main panel */
106 rootPanel.add(buttonsPanel, BorderLayout.SOUTH);
107 rootPanel.add(mProjets, BorderLayout.CENTER);
108 getContentPane().add(rootPanel);
109
110 }
111
112 private void okButtonActionPerformed(ActionEvent aE) {
113 Main.getGuiControl().processUselessEvent(aE);
114 this.dispose();
115 mProject = (Project) mProjets.getSelectedValue();
116 mDbAccess = mProject.getDbAcces();
117 }
118 private JList mProjets = new JList();
119 private Project mProject;
120 /* database access panel */
121 /* Access objects created from user input */
122 private DbAccess mDbAccess;
123
124 }