KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > builder > gui > PreferencesProjectPanel


1 /*
2  * $RCSfile: PreferencesProjectPanel.java,v $
3  * @modification $Date: 2001/09/28 19:35:30 $
4  * @version $Id: PreferencesProjectPanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
5  *
6  */

7
8 package com.memoire.vainstall.builder.gui;
9
10 import com.memoire.vainstall.VAGlobals;
11 import com.memoire.vainstall.builder.*;
12
13 import java.awt.*;
14 import java.awt.event.*;
15 import java.io.File JavaDoc;
16
17 import javax.swing.*;
18 import javax.swing.border.*;
19
20 /**
21  * This panel enables the user to change the root directory
22  * where VAInstall install projects a saved.
23  *
24  * @see javax.swing.JPanel
25  *
26  * @author Henrik Falk
27  * @version $Id: PreferencesProjectPanel.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
28  */

29 public class PreferencesProjectPanel extends JPanel implements ActionListener {
30
31     /**
32      * The VAInstall builder data model
33      */

34     private VAIBuilderModel model = null;
35
36     /**
37      * a lowered border for the panel
38      */

39     private final static Border loweredBorder = new SoftBevelBorder(BevelBorder.LOWERED);
40
41     JTextField directoryField;
42
43     JButton directoryButton;
44
45     /**
46      * Default constructor
47      */

48     public PreferencesProjectPanel() {
49
50         setBorder(loweredBorder);
51
52         GridBagLayout layout = new GridBagLayout();
53         setLayout(layout);
54
55         GridBagConstraints constraint=new GridBagConstraints();
56
57         JLabel directoryLabel = new JLabel();
58         directoryLabel.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","PreferencesProjectPanel_Root"));
59         directoryLabel.setFont(new java.awt.Font JavaDoc("TimesRoman", java.awt.Font.PLAIN, 14));
60         constraint.fill = GridBagConstraints.BOTH;
61         constraint.insets = new Insets(4,8,0,4);
62         constraint.anchor = GridBagConstraints.WEST;
63         constraint.gridx = 0;
64         constraint.gridy = 0;
65         constraint.gridwidth = 1;
66         constraint.gridheight = 1;
67         constraint.weightx = 0;
68         constraint.weighty = 0;
69         layout.setConstraints(directoryLabel,constraint);
70         add(directoryLabel);
71         
72         directoryField = new JTextField();
73         directoryField.setEditable(false);
74 // directoryField.setEnabled(false);
75
directoryField.setFont(new java.awt.Font JavaDoc("TimesRoman", java.awt.Font.PLAIN, 14));
76         constraint.fill = GridBagConstraints.BOTH;
77         constraint.insets = new Insets(4,8,4,4);
78         constraint.anchor = GridBagConstraints.CENTER;
79         constraint.gridx = 0;
80         constraint.gridy = 1;
81         constraint.gridwidth = 1;
82         constraint.gridheight = 1;
83         constraint.weightx = 1;
84         constraint.weighty = 0;
85         layout.setConstraints(directoryField,constraint);
86         add(directoryField);
87
88         directoryButton = new JButton();
89         directoryButton.setText(VAGlobals.getResource("com.memoire.vainstall.builder.Language","PreferencesProjectPanel_Change"));
90         directoryButton.setSize(directoryButton.getSize().width,directoryField.getSize().height);
91         directoryButton.addActionListener(this);
92 // directoryButton.setFont(new java.awt.Font("TimesRoman", java.awt.Font.PLAIN, 14));
93
constraint.fill = GridBagConstraints.BOTH;
94         constraint.insets = new Insets(4,4,4,8);
95         constraint.anchor = GridBagConstraints.CENTER;
96         constraint.gridx = 1;
97         constraint.gridy = 1;
98         constraint.gridwidth = 1;
99         constraint.gridheight = 1;
100         constraint.weightx = 0;
101         constraint.weighty = 0;
102         layout.setConstraints(directoryButton,constraint);
103         add(directoryButton);
104
105         JPanel fillPanel = new JPanel();
106         constraint.fill = GridBagConstraints.BOTH;
107         constraint.insets = new Insets(4,4,4,4);
108         constraint.anchor = GridBagConstraints.WEST;
109         constraint.gridx = 0;
110         constraint.gridy = 2;
111         constraint.gridwidth = 1;
112         constraint.gridheight = 1;
113         constraint.weightx = 0;
114         constraint.weighty = 1;
115         layout.setConstraints(fillPanel,constraint);
116         add(fillPanel);
117
118     }
119
120     /**
121      * Implement the actionPerformed method
122      * @param evt the action event
123      */

124     public void actionPerformed(ActionEvent evt) {
125
126         // extract the control that sends the event
127
Object JavaDoc source = evt.getSource();
128
129         if (source == directoryButton) {
130
131             // show filechooser dialog
132
JFileChooser jfc = new JFileChooser();
133             jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
134
135             String JavaDoc rootDirectory = (String JavaDoc)model.getPropertyList().get("vainstall.projectroot");
136             if (rootDirectory == null) {
137                 rootDirectory = System.getProperty("user.dir");
138             }
139             jfc.setCurrentDirectory(new File JavaDoc(rootDirectory));
140
141             int result = jfc.showDialog(null,VAGlobals.getResource("com.memoire.vainstall.builder.Language","PreferencesProjectPanel_Select"));
142             if (result == JFileChooser.APPROVE_OPTION) {
143                 directoryField.setText(jfc.getSelectedFile().getAbsolutePath());
144
145                 // save project root
146
model.getPropertyList().put("vainstall.projectroot",jfc.getSelectedFile().getAbsolutePath());
147             }
148         }
149     }
150
151     /**
152      * save
153      */

154     public void save() {
155     }
156
157     public void initialize(VAIBuilderModel model) {
158         this.model = model;
159
160         String JavaDoc rootDirectory = (String JavaDoc)model.getPropertyList().get("vainstall.projectroot");
161
162         if (rootDirectory == null) {
163             rootDirectory = System.getProperty("user.dir");
164         }
165         directoryField.setText(rootDirectory);
166     }
167
168     public void stop() {
169     }
170
171 }
172
Popular Tags