1 6 7 package org.netbeans.test.editor.app.gui; 8 9 import java.awt.Component ; 10 import java.awt.Dimension ; 11 import java.awt.GridLayout ; 12 import java.awt.event.ActionEvent ; 13 import java.awt.event.ActionListener ; 14 import java.beans.PropertyChangeEvent ; 15 import java.beans.PropertyChangeListener ; 16 import java.util.Enumeration ; 17 import java.util.Hashtable ; 18 import java.util.Vector ; 19 import javax.swing.DefaultListCellRenderer ; 20 import javax.swing.JButton ; 21 import javax.swing.JComponent ; 22 import javax.swing.JList ; 23 import javax.swing.JTextField ; 24 import javax.swing.ListCellRenderer ; 25 import org.netbeans.test.editor.app.Main; 26 import org.netbeans.test.editor.app.core.properties.ArrayProperty; 27 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException; 28 import org.netbeans.test.editor.app.core.properties.Properties; 29 import org.netbeans.test.editor.app.core.Test; 30 import org.netbeans.test.editor.app.core.TestCallAction; 31 import org.netbeans.test.editor.app.core.TestLogAction; 32 import org.netbeans.test.editor.app.core.TestNode; 33 import org.netbeans.test.editor.app.core.TestSetIEAction; 34 import org.netbeans.test.editor.app.core.TestSetKitAction; 35 import org.netbeans.test.editor.app.core.TestStringAction; 36 import org.netbeans.test.editor.app.core.XMLNode; 37 import org.netbeans.test.editor.app.core.properties.StringProperty; 38 import org.netbeans.test.editor.app.gui.QuestionDialog; 39 40 44 public class PropertiesDialog extends javax.swing.JDialog implements PropertyChangeListener { 45 46 XMLNode node; 47 static Hashtable lines=new Hashtable (); 48 49 String oldString; 50 51 52 public PropertiesDialog(java.awt.Frame parent, XMLNode n) { 53 super(parent, false); 54 this.node=n; 55 node.addPropertyChangeListener(this); 56 initComponents(); 57 oldString=node.toString(); 58 setTitle(getTitle()+" ["+node+"]"); 59 generateButtons(); 60 pack(); 61 setSize(PropertiesDialog.PropertyLine.WIDTH*2+64,PropertiesDialog.PropertyLine.HEIGHT*(leftPanel.getComponentCount()+2)); 62 splitPane.setDividerLocation((getWidth()/7)*3); 63 setLocation(parent.getX(),parent.getY()+parent.getHeight()-getHeight()); 64 } 65 66 71 private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane (); 73 splitPane = new javax.swing.JSplitPane (); 74 jPanel1 = new javax.swing.JPanel (); 75 leftPanel = new javax.swing.JPanel (); 76 jPanel2 = new javax.swing.JPanel (); 77 rightPanel = new javax.swing.JPanel (); 78 79 setTitle("Properties"); 80 addWindowListener(new java.awt.event.WindowAdapter () { 81 public void windowClosing(java.awt.event.WindowEvent evt) { 82 closeDialog(evt); 83 } 84 }); 85 86 splitPane.setDividerLocation(0); 87 splitPane.setDividerSize(4); 88 splitPane.setResizeWeight(1.0); 89 splitPane.setPreferredSize(new java.awt.Dimension (100, 100)); 90 jPanel1.setLayout(new java.awt.BorderLayout ()); 91 92 leftPanel.setLayout(new java.awt.GridLayout (1, 1)); 93 94 jPanel1.add(leftPanel, java.awt.BorderLayout.CENTER); 95 96 splitPane.setLeftComponent(jPanel1); 97 98 jPanel2.setLayout(new java.awt.BorderLayout ()); 99 100 rightPanel.setLayout(new java.awt.GridLayout (1, 1)); 101 102 jPanel2.add(rightPanel, java.awt.BorderLayout.CENTER); 103 104 splitPane.setRightComponent(jPanel2); 105 106 jScrollPane1.setViewportView(splitPane); 107 108 getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); 109 110 pack(); 111 } 113 114 private void closeDialog(java.awt.event.WindowEvent evt) { setVisible(false); 116 node.removePropertyChangeListener(this); 117 dispose(); 118 } 120 123 public static void main(String args[]) { 124 new PropertiesDialog(new javax.swing.JFrame (), new TestStringAction("Aaaa","a")).show(); 125 } 126 127 private void generateButtons() { 128 try { 129 Properties ps=node.getProperties(); 130 int rows=1; 131 PropertyLine line; 132 String propertyName; 133 134 propertyName="Type"; 136 String type=node.getClass().getName(); 137 type=type.substring(type.lastIndexOf('.')+1); 138 line=getPropertyLine(propertyName,new StringProperty(type),true); 139 leftPanel.add(line.button); 140 rightPanel.add(line.panel); 141 line.panel.setDialog(this); 142 144 for (Enumeration en=ps.propertyNames();en.hasMoreElements();) { 145 rows++; 146 ((GridLayout )(leftPanel.getLayout())).setRows(rows); 147 ((GridLayout )(rightPanel.getLayout())).setRows(rows); 148 propertyName=(String )(en.nextElement()); 149 line=getPropertyLine(propertyName,ps.getProperty(propertyName)); 150 leftPanel.add(line.button); 151 rightPanel.add(line.panel); 152 line.panel.setDialog(this); 153 } 154 } catch (Exception ex) { 155 ex.printStackTrace(); 156 } 157 } 158 159 public void buttonPressed(java.awt.event.ActionEvent evt) { Component [] cs=rightPanel.getComponents(); 161 for (int i=0;i < cs.length;i++) { 162 if (!evt.getSource().equals(cs[i])) { 163 ((PropertyPanel)(cs[i])).setState(true); 164 } 165 } 166 } 167 168 public PropertyLine getPropertyLine(String propertyName,Object value) { 169 PropertyLine ret; 170 ret=new PropertiesDialog.PropertyLine(propertyName,value); 171 lines.put(propertyName,ret); 172 return ret; 173 } 174 175 public PropertyLine getPropertyLine(String propertyName,Object value,boolean readOnly) { 176 PropertyLine ret; 177 ret=new PropertiesDialog.PropertyLine(propertyName,value,readOnly); 178 lines.put(propertyName,ret); 179 return ret; 180 } 181 182 public void propertyChanged(String property,Object value) { 183 try { 184 node.setProperty(property, value); 185 } catch (BadPropertyNameException ex) { 186 QuestionDialog dlg=new QuestionDialog(Main.frame,ex.getMessage()); 187 dlg.show(); 188 } 189 } 190 191 196 public void propertyChange(PropertyChangeEvent evt) { 197 if (oldString.compareTo(node.toString()) != 0) { 198 oldString=node.toString(); 199 setTitle("Properties ["+oldString+"]"); 200 } 201 Properties ps=node.getProperties(); 202 Component [] csl=leftPanel.getComponents(); 203 Component [] csr=rightPanel.getComponents(); 204 for (int i=1;i < csl.length;i++) { String s=((JButton )csl[i]).getText(); 206 Object o=ps.getProperty(s); 207 ((PropertyPanel)(csr[i])).setProperty(o); 208 } 209 } 210 211 static class PropertyLine { 212 213 public static int HEIGHT=24; 214 public static int WIDTH=132; 215 216 public JButton button; 217 public PropertyPanel panel; 218 219 public PropertyLine(String name,Object data) { 220 if (data instanceof ArrayProperty) { 221 panel=new ArrayPropertyPanel((ArrayProperty)data,name); 222 } else { 223 panel=new PropertyPanel(data,name); 224 } 225 panel.setSize(WIDTH,HEIGHT); 226 button=new JButton (name); 227 button.setSize(WIDTH,HEIGHT); 228 button.addActionListener(new ActionListener () { 229 public void actionPerformed(ActionEvent ev) { 230 panel.changeState(ev); 231 } 232 }); 233 } 234 235 public PropertyLine(String name,Object data,boolean readOnly) { 236 button=new JButton (name); 237 button.setSize(WIDTH,HEIGHT); 238 button.addActionListener(new ActionListener () { 239 public void actionPerformed(ActionEvent ev) { 240 panel.changeState(ev); 241 } 242 }); 243 panel=new PropertyPanel(data,name,readOnly); 244 panel.setSize(WIDTH,HEIGHT); 245 } 246 247 } 248 249 private javax.swing.JScrollPane jScrollPane1; 251 private javax.swing.JPanel jPanel2; 252 private javax.swing.JPanel leftPanel; 253 private javax.swing.JPanel jPanel1; 254 private javax.swing.JSplitPane splitPane; 255 private javax.swing.JPanel rightPanel; 256 258 } 259 | Popular Tags |