001: /*
002: * $RCSfile: VAIProductInternalFrame.java,v $
003: * @modification $Date: 2001/09/28 19:35:30 $
004: * @version $Id: VAIProductInternalFrame.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 java.awt.*;
014: import java.util.Enumeration;
015:
016: import javax.swing.*;
017: import javax.swing.border.*;
018: import javax.swing.event.*;
019: import javax.swing.tree.*;
020:
021: /**
022: * This is view/editor for a product
023: *
024: * @see javax.swing.JInternalFrame
025: *
026: * @author Henrik Falk
027: * @version $Id: VAIProductInternalFrame.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
028: */
029: public class VAIProductInternalFrame extends JInternalFrame implements
030: TreeSelectionListener {
031:
032: private final static Border loweredBorder = new SoftBevelBorder(
033: BevelBorder.LOWERED);
034: private final static Border raisedBorder = new SoftBevelBorder(
035: BevelBorder.RAISED);
036:
037: JPanel allPanel;
038:
039: JTree tree = new JTree();
040: DefaultTreeModel treeModel = null;
041: AbstractVAIProductNode rootNode;
042:
043: JScrollPane detailsPane = new JScrollPane();
044:
045: JLabel informationLabel = new JLabel();
046:
047: JPanel propertyNodePanel;
048: JLabel propertyNodeLabel;
049: JPanel currentPanel;
050:
051: /**
052: * Default constructor
053: */
054: public VAIProductInternalFrame() {
055: super ("");
056:
057: setResizable(true);
058: setClosable(true);
059: setMaximizable(true);
060: setIconifiable(true);
061:
062: setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
063:
064: // create the all panel
065: allPanel = new JPanel(new BorderLayout());
066:
067: /*
068: JLabel logoLabel = null;
069: try {
070: logoLabel = new JLabel(new javax.swing.ImageIcon(getClass().getResource("/com/memoire/vainstall/resources/banner.gif")));
071: logoLabel.setMinimumSize(new Dimension(20, 20));
072: } catch(Exception exc) {
073: exc.printStackTrace();
074: logoLabel = new JLabel(VAGlobals.NAME);
075: }
076: */
077: // create panel in which node views are inserted
078: propertyNodePanel = new JPanel();
079: propertyNodePanel.setLayout(new BorderLayout());
080: detailsPane.getViewport().add(propertyNodePanel);
081:
082: // create node title panel
083: JPanel labelPanel = new JPanel(new GridBagLayout());
084: labelPanel.setBackground(Color.gray);
085:
086: propertyNodeLabel = new JLabel(" ");
087: propertyNodeLabel.setFont(new java.awt.Font("TimesRoman",
088: java.awt.Font.BOLD, 16));
089: propertyNodeLabel.setForeground(Color.black);
090: GridBagLayout labellayout = (GridBagLayout) labelPanel
091: .getLayout();
092: GridBagConstraints labelContraint = new GridBagConstraints();
093: labelContraint.fill = GridBagConstraints.BOTH;
094: labelContraint.insets = new Insets(4, 4, 4, 4);
095: labelContraint.anchor = GridBagConstraints.WEST;
096: labelContraint.gridx = 0;
097: labelContraint.gridy = 0;
098: labelContraint.gridwidth = 1;
099: labelContraint.gridheight = 1;
100: labelContraint.weightx = 1;
101: labelContraint.weighty = 1;
102: labellayout.setConstraints(propertyNodeLabel, labelContraint);
103: labelPanel.add(propertyNodeLabel);
104:
105: JLabel propertyNodeImageLabel = new JLabel();
106: propertyNodeImageLabel
107: .setIcon(new javax.swing.ImageIcon(
108: getClass()
109: .getResource(
110: "/com/memoire/vainstall/builder/images/nodedetailstitle.jpg")));
111: GridBagConstraints labelImageContraint = new GridBagConstraints();
112: labelImageContraint.fill = GridBagConstraints.NONE;
113: labelImageContraint.insets = new Insets(0, 0, 0, 0);
114: labelImageContraint.anchor = GridBagConstraints.EAST;
115: labelImageContraint.gridx = 1;
116: labelImageContraint.gridy = 0;
117: labelImageContraint.gridwidth = 1;
118: labelImageContraint.gridheight = 1;
119: labellayout.setConstraints(propertyNodeImageLabel,
120: labelImageContraint);
121: labelPanel.add(propertyNodeImageLabel);
122:
123: propertyNodePanel.add("North", labelPanel);
124:
125: // ******************************************************
126:
127: JScrollPane treePane = new JScrollPane();
128: ToolTipManager.sharedInstance().registerComponent(tree);
129: tree.getSelectionModel().setSelectionMode(
130: TreeSelectionModel.SINGLE_TREE_SELECTION);
131: tree.addTreeSelectionListener(this );
132: tree.putClientProperty("JTree.lineStyle", "Angled");
133: tree.setModel(null);
134: tree.setCellRenderer(new NodeTreeCellRenderer());
135: treePane.getViewport().add(tree);
136:
137: JSplitPane splitPane = new JSplitPane(
138: JSplitPane.HORIZONTAL_SPLIT, treePane, detailsPane);
139: splitPane.setContinuousLayout(true);
140: splitPane.setOneTouchExpandable(true);
141:
142: splitPane.setDividerLocation(180);
143:
144: allPanel.add(splitPane, BorderLayout.CENTER);
145:
146: // insert the all panel into the application frame window
147: this .getContentPane().add("Center", allPanel);
148:
149: }
150:
151: public JTree getTree() {
152: return tree;
153: }
154:
155: private void setTreePanelTitle(String title) {
156: propertyNodeLabel.setText(title);
157: }
158:
159: private void setTreePanel(JPanel panel) {
160:
161: if (currentPanel == null) {
162: propertyNodePanel.add("Center", panel);
163: currentPanel = panel;
164: } else {
165: propertyNodePanel.remove(currentPanel);
166: propertyNodePanel.add("Center", panel);
167: currentPanel = panel;
168: }
169: validate();
170: repaint();
171: }
172:
173: /**
174: * Sets the node as root in the TreeModel
175: */
176: public void setNode(AbstractVAIProductNode root) {
177:
178: rootNode = root;
179: treeModel=new DefaultTreeModel(root);
180: tree.setModel(treeModel);
181:
182: tree.setSelectionRow(0);
183:
184: Enumeration enum = rootNode.preorderEnumeration();
185: while(enum.hasMoreElements() == true) {
186: AbstractVAIProductNode node = (AbstractVAIProductNode)enum.nextElement();
187: node.start();
188: }
189: }
190:
191: /**
192: * Implements the TreeSelectionListener interface
193: * @param evt javax.swing.event.TreeSelectionEvent
194: */
195: public void valueChanged(TreeSelectionEvent evt) {
196:
197: TreePath path = evt.getNewLeadSelectionPath();
198: if (path == null) {
199: return;
200: }
201: Object obj = path.getLastPathComponent();
202:
203: if (obj instanceof DefaultMutableTreeNode) {
204: Object userObject = ((DefaultMutableTreeNode) obj)
205: .getUserObject();
206:
207: if (userObject instanceof VAINodeInterface) {
208: setTreePanel(((AbstractVAIProductNode) userObject)
209: .getUI());
210: setTreePanelTitle(((AbstractVAIProductNode) userObject)
211: .getTitle());
212: }
213: }
214: }
215:
216: }
|