001: /*
002: * $RCSfile: PreferencesFrame.java,v $
003: * @modification $Date: 2001/09/28 19:35:30 $
004: * @version $Id: PreferencesFrame.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
005: *
006: */
007:
008: package com.memoire.vainstall.builder.gui;
009:
010: import com.memoire.vainstall.VAGlobals;
011: import com.memoire.vainstall.builder.util.*;
012:
013: import javax.swing.*;
014: import javax.swing.event.*;
015: import javax.swing.tree.*;
016:
017: import java.awt.*;
018: import java.awt.event.*;
019: import java.util.*;
020:
021: /**
022: * This is the preferences dialog where the user can
023: * change various settings for the builder application
024: *
025: * @see java.awt.ActionListener
026: * @see java.awt.WindowListener
027: * @see javax.swing.JFrame
028: * @see javax.swing.event.TreeSelectionListener
029: *
030: * @author Henrik Falk
031: * @version $Id: PreferencesFrame.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
032: */
033: public class PreferencesFrame extends JFrame implements
034: TreeSelectionListener, ActionListener, WindowListener {
035:
036: JRootPane rootpane;
037:
038: JTree tree = new JTree();
039:
040: DefaultTreeModel treeModel = null;
041:
042: AbstractVAIBuilderNode rootNode;
043:
044: JButton okButton;
045:
046: JPanel propertyNodePanel = null;
047: JPanel currentPanel = null;
048: JLabel propertyNodeLabel = null;
049: JLabel propertyNodeImageLabel = null;
050:
051: public PreferencesFrame() {
052:
053: super ("");
054:
055: JPanel allPanel = new JPanel(new GridBagLayout());
056: GridBagLayout alayout = (GridBagLayout) allPanel.getLayout();
057:
058: // ******************************************************
059: JPanel wpanel = new JPanel(new GridBagLayout());
060: GridBagLayout wlayout = (GridBagLayout) wpanel.getLayout();
061:
062: JScrollPane pane = new JScrollPane(tree);
063: pane.setMinimumSize(new Dimension(160, pane.getHeight()));
064: pane.setPreferredSize(new Dimension(160, pane.getHeight()));
065: GridBagConstraints wContraint = new GridBagConstraints();
066: wContraint.fill = GridBagConstraints.BOTH;
067: wContraint.insets = new Insets(4, 4, 4, 4);
068: wContraint.anchor = GridBagConstraints.WEST;
069: wContraint.gridx = 0;
070: wContraint.gridy = 0;
071: wContraint.gridwidth = 1;
072: wContraint.gridheight = 1;
073: wContraint.weightx = 0;
074: wContraint.weighty = 1;
075: wlayout.setConstraints(pane, wContraint);
076: wpanel.add(pane);
077:
078: // ******************************************************
079: JPanel cpanel = new JPanel(new GridBagLayout());
080: GridBagLayout clayout = (GridBagLayout) cpanel.getLayout();
081: GridBagConstraints cContraint = new GridBagConstraints();
082:
083: propertyNodePanel = new JPanel();
084: propertyNodePanel.setLayout(new BorderLayout());
085: cContraint.fill = GridBagConstraints.BOTH;
086: cContraint.insets = new Insets(4, 4, 4, 4);
087: cContraint.anchor = GridBagConstraints.CENTER;
088: cContraint.gridx = 0;
089: cContraint.gridy = 0;
090: cContraint.gridwidth = 1;
091: cContraint.gridheight = 1;
092: cContraint.weightx = 1;
093: cContraint.weighty = 1;
094: clayout.setConstraints(propertyNodePanel, cContraint);
095: cpanel.add(propertyNodePanel);
096:
097: // *****************************************************
098: JPanel labelPanel = new JPanel(new GridBagLayout());
099: labelPanel.setBackground(Color.gray);
100:
101: propertyNodeLabel = new JLabel(" ");
102: propertyNodeLabel.setFont(new java.awt.Font("TimesRoman",
103: java.awt.Font.BOLD, 16));
104: propertyNodeLabel.setForeground(Color.black);
105: GridBagLayout labellayout = (GridBagLayout) labelPanel
106: .getLayout();
107: GridBagConstraints labelContraint = new GridBagConstraints();
108: labelContraint.fill = GridBagConstraints.BOTH;
109: labelContraint.insets = new Insets(4, 4, 4, 4);
110: labelContraint.anchor = GridBagConstraints.WEST;
111: labelContraint.gridx = 0;
112: labelContraint.gridy = 0;
113: labelContraint.gridwidth = 1;
114: labelContraint.gridheight = 1;
115: labelContraint.weightx = 1;
116: labelContraint.weighty = 1;
117: labellayout.setConstraints(propertyNodeLabel, labelContraint);
118: labelPanel.add(propertyNodeLabel);
119:
120: propertyNodeImageLabel = new JLabel();
121: propertyNodeImageLabel
122: .setIcon(new javax.swing.ImageIcon(
123: getClass()
124: .getResource(
125: "/com/memoire/vainstall/builder/images/nodedetailstitle.jpg")));
126: GridBagConstraints labelImageContraint = new GridBagConstraints();
127: labelImageContraint.fill = GridBagConstraints.NONE;
128: labelImageContraint.insets = new Insets(0, 0, 0, 0);
129: labelImageContraint.anchor = GridBagConstraints.EAST;
130: labelImageContraint.gridx = 1;
131: labelImageContraint.gridy = 0;
132: labelImageContraint.gridwidth = 1;
133: labelImageContraint.gridheight = 1;
134: labellayout.setConstraints(propertyNodeImageLabel,
135: labelImageContraint);
136: labelPanel.add(propertyNodeImageLabel);
137:
138: propertyNodePanel.add("North", labelPanel);
139:
140: // ******************************************************
141: JPanel spanel = new JPanel(new GridBagLayout());
142: GridBagLayout slayout = (GridBagLayout) spanel.getLayout();
143: GridBagConstraints sContraint = new GridBagConstraints();
144:
145: JPanel sFill = new JPanel();
146: sFill.setLayout(new FlowLayout());
147: sContraint.fill = GridBagConstraints.BOTH;
148: sContraint.insets = new Insets(4, 4, 4, 4);
149: sContraint.anchor = GridBagConstraints.CENTER;
150: sContraint.gridx = 0;
151: sContraint.gridy = 0;
152: sContraint.gridwidth = 1;
153: sContraint.gridheight = 1;
154: sContraint.weightx = 1;
155: slayout.setConstraints(sFill, sContraint);
156: spanel.add(sFill);
157:
158: okButton = new JButton(VAGlobals.getResource(
159: "com.memoire.vainstall.builder.Language", "Common_OK"));
160: okButton.addActionListener(this );
161: sContraint.weightx = 0;
162: sContraint.gridx = 1;
163: slayout.setConstraints(okButton, sContraint);
164: spanel.add(okButton);
165:
166: // ******************************************************
167:
168: GridBagConstraints awContraint = new GridBagConstraints();
169: awContraint.fill = GridBagConstraints.BOTH;
170: awContraint.insets = new Insets(0, 0, 0, 0);
171: awContraint.anchor = GridBagConstraints.NORTHWEST;
172: awContraint.gridx = 0;
173: awContraint.gridy = 0;
174: awContraint.gridwidth = 1;
175: awContraint.gridheight = 1;
176: awContraint.weightx = 0;
177: awContraint.weighty = 1;
178: alayout.setConstraints(wpanel, awContraint);
179: allPanel.add(wpanel);
180:
181: GridBagConstraints acContraint = new GridBagConstraints();
182: acContraint.fill = GridBagConstraints.BOTH;
183: acContraint.insets = new Insets(0, 0, 0, 0);
184: acContraint.anchor = GridBagConstraints.CENTER;
185: acContraint.gridx = 1;
186: acContraint.gridy = 0;
187: acContraint.gridwidth = 2;
188: acContraint.gridheight = 1;
189: acContraint.weightx = 1;
190: acContraint.weighty = 1;
191: alayout.setConstraints(cpanel, acContraint);
192: allPanel.add(cpanel);
193:
194: GridBagConstraints asContraint = new GridBagConstraints();
195: asContraint.fill = GridBagConstraints.BOTH;
196: asContraint.insets = new Insets(0, 0, 0, 0);
197: asContraint.anchor = GridBagConstraints.CENTER;
198: asContraint.gridx = 0;
199: asContraint.gridy = 1;
200: asContraint.gridwidth = 3;
201: asContraint.gridheight = 1;
202: asContraint.weightx = 1;
203: asContraint.weighty = 0;
204: alayout.setConstraints(spanel, asContraint);
205: allPanel.add(spanel);
206:
207: // ******************************************************
208:
209: this .getContentPane().add("Center", allPanel);
210: this .getRootPane().registerKeyboardAction(this , "VK_ESCAPE",
211: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
212: JComponent.WHEN_IN_FOCUSED_WINDOW);
213: // JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
214:
215: setSize(600, 480);
216:
217: ToolTipManager.sharedInstance().registerComponent(tree);
218: tree.setCellRenderer(new NodeTreeCellRenderer());
219:
220: tree.getSelectionModel().setSelectionMode(
221: TreeSelectionModel.SINGLE_TREE_SELECTION);
222: tree.addTreeSelectionListener(this );
223: tree.putClientProperty("JTree.lineStyle", "Angled");
224:
225: // null model
226: tree.setModel(null);
227: // tree.setShowsRootHandles(true);
228:
229: this .addWindowListener(this );
230:
231: setResizable(false);
232: center();
233:
234: }
235:
236: public void setNode(AbstractVAIBuilderNode root) {
237:
238: rootNode = root;
239: treeModel=new DefaultTreeModel(root);
240: tree.setModel(treeModel);
241:
242: tree.setSelectionRow(0);
243:
244: Enumeration enum = rootNode.preorderEnumeration();
245: while(enum.hasMoreElements() == true) {
246: AbstractVAIBuilderNode node = (AbstractVAIBuilderNode)enum.nextElement();
247: node.start();
248: }
249: }
250:
251: public void actionPerformed(ActionEvent evt) {
252:
253: // extract the control that sends the event
254: Object source = evt.getSource();
255: String actionCommand = evt.getActionCommand();
256:
257: if (actionCommand != null && actionCommand.equals("VK_ESCAPE") == true) {
258: setVisible(false);
259: }
260:
261: if (source == okButton) {
262: if(rootNode != null) {
263: Enumeration enum = rootNode.preorderEnumeration();
264: while(enum.hasMoreElements() == true) {
265: AbstractVAIBuilderNode node = (AbstractVAIBuilderNode)enum.nextElement();
266: node.stop();
267: }
268: }
269: setVisible(false);
270: }
271:}
272:
273: public void valueChanged(TreeSelectionEvent evt) {
274:
275: TreePath path = evt.getNewLeadSelectionPath();
276: if (path == null) {
277: return;
278: }
279: Object obj = path.getLastPathComponent();
280:
281: if (obj instanceof DefaultMutableTreeNode) {
282: Object userObject = ((DefaultMutableTreeNode) obj)
283: .getUserObject();
284: if (userObject instanceof VAINodeInterface) {
285: setTreePanel(((AbstractVAIBuilderNode) userObject)
286: .getUI());
287: setTreePanelTitle(((AbstractVAIBuilderNode) userObject)
288: .getTitle());
289: }
290: }
291:
292: }
293:
294: private void setTreePanelTitle(String title) {
295: propertyNodeLabel.setText(title);
296: }
297:
298: private void setTreePanel(JPanel panel) {
299:
300: if (currentPanel == null) {
301: propertyNodePanel.add("Center", panel);
302: currentPanel = panel;
303: } else {
304: propertyNodePanel.remove(currentPanel);
305: propertyNodePanel.add("Center", panel);
306: currentPanel = panel;
307: }
308: validate();
309: repaint();
310: }
311:
312: public void center() {
313:
314: java.awt.Dimension dimScreen = java.awt.Toolkit
315: .getDefaultToolkit().getScreenSize();
316: this .setLocation((dimScreen.width - this .getSize().width) / 2,
317: (dimScreen.height - this .getSize().height) / 2);
318:
319: }
320:
321: /**
322: * Method to handle events for the WindowListener interface.
323: * @param e java.awt.event.WindowEvent
324: */
325: public void windowActivated(java.awt.event.WindowEvent e) {
326: }
327:
328: /**
329: * Method to handle events for the WindowListener interface.
330: * @param e java.awt.event.WindowEvent
331: */
332: public void windowClosed(java.awt.event.WindowEvent e) {
333: }
334:
335: /**
336: * Method to handle events for the WindowListener interface.
337: * @param e java.awt.event.WindowEvent
338: */
339: public void windowClosing(java.awt.event.WindowEvent e) {
340: }
341:
342: /**
343: * Method to handle events for the WindowListener interface.
344: * @param e java.awt.event.WindowEvent
345: */
346: public void windowDeactivated(java.awt.event.WindowEvent e) {
347: }
348:
349: /**
350: * Method to handle events for the WindowListener interface.
351: * @param e java.awt.event.WindowEvent
352: */
353: public void windowDeiconified(java.awt.event.WindowEvent e) {
354: }
355:
356: /**
357: * Method to handle events for the WindowListener interface.
358: * @param e java.awt.event.WindowEvent
359: */
360: public void windowIconified(java.awt.event.WindowEvent e) {
361: }
362:
363: /**
364: * Method to handle events for the WindowListener interface.
365: * @param e java.awt.event.WindowEvent
366: */
367: public void windowOpened(java.awt.event.WindowEvent e) {
368: okButton.requestFocus();
369: }
370:
371: }
|