1 23 package org.enhydra.kelp.common.properties; 24 25 import org.enhydra.tool.common.DataValidationException; 27 28 import org.enhydra.kelp.common.node.OtterNode; 30 import org.enhydra.kelp.common.node.OtterXMLCNode; 31 import org.enhydra.kelp.common.swing.AddinInnerPanel; 32 import org.enhydra.kelp.common.xmlc.MapDialog; 33 import org.enhydra.kelp.common.xmlc.XMLCOptionTab; 34 35 import java.awt.*; 37 import java.awt.event.*; 38 import java.beans.*; 39 import java.io.File ; 40 import javax.swing.*; 41 import javax.swing.border.*; 42 import javax.swing.event.*; 43 import java.util.ResourceBundle ; 44 45 public class XMLCNodePropertyPanel extends AddinInnerPanel { 47 static ResourceBundle res = 48 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); private GridBagLayout layoutMain; 50 private JCheckBox checkCompile; 51 private JTextField textClassName; 52 private JPanel panelClassName; 53 private GridBagLayout layoutClassName; 54 private JRadioButton radioDefault; 55 private JRadioButton radioCustom; 56 private JRadioButton radioMap; 57 private JButton buttonMap; 58 private XMLCOptionTab optionTab; 59 private TitledBorder borderClassName; 60 private ButtonGroup radioGroup; 61 private JCheckBox checkStatic; 62 private LocalButtonListener buttonListener; 63 private LocalCheckListener checkListener; 64 private LocalRadioListener radioListener; 65 66 71 public XMLCNodePropertyPanel() { 72 super(); 73 try { 74 jbInit(); 75 pmInit(); 76 } catch (Exception e) { 77 e.printStackTrace(); 78 } 79 } 80 81 public void read(OtterNode node) { 83 super.read(node); 84 OtterXMLCNode xmlcNode = null; 85 boolean b = false; 86 String s = new String (); 87 88 xmlcNode = getXMLCNode(); 89 optionTab.setNode(xmlcNode); 90 optionTab.init(); 91 optionTab.readProperties(); 92 b = xmlcNode.isSelected(); 93 checkCompile.setSelected(b); 94 if (b) { 95 checkStatic.setSelected(false); 96 } else { 97 b = xmlcNode.isStatic(); 98 checkStatic.setSelected(b); 99 } 100 switch (xmlcNode.getClassNameType()) { 101 case OtterXMLCNode.CLASS_NAME_CUSTOM: 102 radioCustom.setSelected(true); 103 break; 104 case OtterXMLCNode.CLASS_NAME_MAPPED: 105 radioMap.setSelected(true); 106 break; 107 default: 108 radioDefault.setSelected(true); 109 break; 110 } 111 s = xmlcNode.getMetaDataHandler().getClassName(); 112 textClassName.setText(s); 113 enableCompileOptions(checkCompile.isSelected() 114 && (!checkStatic.isSelected())); 115 refreshClassName(); 116 } 117 118 public void write(OtterNode node) throws DataValidationException { 120 super.write(node); 121 OtterXMLCNode xmlcNode = null; 122 123 xmlcNode = getXMLCNode(); 124 optionTab.writeProperties(); 125 boolean b = checkCompile.isSelected(); 126 127 xmlcNode.setSelected(b); 128 if (b) { 129 xmlcNode.setStatic(false); 130 } else { 131 b = checkStatic.isSelected(); 132 xmlcNode.setStatic(b); 133 } 134 String customClassName = textClassName.getText(); 135 136 xmlcNode.setCustomClassName(customClassName); 137 if (radioCustom.isSelected()) { 138 xmlcNode.setClassNameType(OtterXMLCNode.CLASS_NAME_CUSTOM); 139 } else if (radioDefault.isSelected()) { 140 xmlcNode.setClassNameType(OtterXMLCNode.CLASS_NAME_DEFAULT); 141 } else { 142 xmlcNode.setClassNameType(OtterXMLCNode.CLASS_NAME_MAPPED); 143 } 144 } 145 146 public Component[] getFirstFocusComponents() { 148 Component[] comps = new Component[9]; 149 150 comps[0] = checkCompile; 151 comps[1] = textClassName; 152 comps[2] = panelClassName; 153 comps[3] = radioDefault; 154 comps[4] = radioCustom; 155 comps[5] = radioMap; 156 comps[6] = buttonMap; 157 comps[7] = optionTab; 158 comps[8] = checkStatic; 159 return comps; 160 } 161 162 166 172 private void pmInit() throws Exception { 173 radioGroup = 174 (ButtonGroup) Beans.instantiate(getClass().getClassLoader(), 175 ButtonGroup.class.getName()); 176 radioGroup.add(radioDefault); 177 radioGroup.add(radioCustom); 178 radioGroup.add(radioMap); 179 refreshClassName(); 180 radioListener = new LocalRadioListener(); 181 radioDefault.addActionListener(radioListener); 182 radioCustom.addActionListener(radioListener); 183 radioMap.addActionListener(radioListener); 184 185 buttonListener = new LocalButtonListener(); 187 buttonMap.addActionListener(buttonListener); 188 189 checkListener = new LocalCheckListener(); 191 checkCompile.addActionListener(checkListener); 192 checkStatic.addActionListener(checkListener); 193 } 194 195 201 private void jbInit() throws Exception { 202 checkCompile = 203 (JCheckBox) Beans.instantiate(getClass().getClassLoader(), 204 JCheckBox.class.getName()); 205 textClassName = 206 (JTextField) Beans.instantiate(getClass().getClassLoader(), 207 JTextField.class.getName()); 208 layoutMain = 209 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 210 GridBagLayout.class.getName()); 211 panelClassName = 212 (JPanel) Beans.instantiate(getClass().getClassLoader(), 213 JPanel.class.getName()); 214 layoutClassName = 215 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 216 GridBagLayout.class.getName()); 217 radioDefault = 218 (JRadioButton) Beans.instantiate(getClass().getClassLoader(), 219 JRadioButton.class.getName()); 220 radioCustom = 221 (JRadioButton) Beans.instantiate(getClass().getClassLoader(), 222 JRadioButton.class.getName()); 223 radioMap = 224 (JRadioButton) Beans.instantiate(getClass().getClassLoader(), 225 JRadioButton.class.getName()); 226 buttonMap = (JButton) Beans.instantiate(getClass().getClassLoader(), 227 JButton.class.getName()); 228 optionTab = 229 (XMLCOptionTab) Beans.instantiate(getClass().getClassLoader(), 230 XMLCOptionTab.class.getName()); 231 checkStatic = 232 (JCheckBox) Beans.instantiate(getClass().getClassLoader(), 233 JCheckBox.class.getName()); 234 checkCompile.setText(res.getString("checkCompile_Text")); 235 optionTab.setLayout(optionTab.getLayout()); 236 panelClassName.setLayout(layoutClassName); 237 borderClassName = 238 BorderFactory.createTitledBorder(res.getString("Generated_class_name")); 239 panelClassName.setBorder(borderClassName); 240 radioDefault.setSelected(true); 241 radioDefault.setText(res.getString("Default")); 242 radioCustom.setText(res.getString("Custom")); 243 radioMap.setText(res.getString("radioMap_Text")); 244 buttonMap.setText(res.getString("buttonMap_Text")); 245 checkStatic.setText(res.getString("checkStatic_Text")); 246 panelClassName.add(textClassName, 247 new GridBagConstraints(0, 1, 4, 248 GridBagConstraints.REMAINDER, 249 1.0, 1.0, 250 GridBagConstraints.WEST, 251 GridBagConstraints.HORIZONTAL, 252 new Insets(5, 5, 5, 5), 0, 253 0)); 254 panelClassName.add(radioCustom, 255 new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 256 GridBagConstraints.CENTER, 257 GridBagConstraints.NONE, 258 new Insets(0, 0, 0, 0), 0, 259 0)); 260 panelClassName.add(radioMap, 261 new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 262 GridBagConstraints.CENTER, 263 GridBagConstraints.NONE, 264 new Insets(0, 0, 0, 0), 0, 265 0)); 266 panelClassName.add(radioDefault, 267 new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 268 GridBagConstraints.CENTER, 269 GridBagConstraints.NONE, 270 new Insets(0, 0, 0, 0), 0, 271 0)); 272 panelClassName.add(buttonMap, 273 new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, 274 GridBagConstraints.CENTER, 275 GridBagConstraints.NONE, 276 new Insets(0, 0, 0, 0), 0, 277 0)); 278 this.setLayout(layoutMain); 279 this.add(checkCompile, 280 new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, 281 GridBagConstraints.WEST, 282 GridBagConstraints.HORIZONTAL, 283 new Insets(2, 5, 5, 5), 0, 0)); 284 this.add(panelClassName, 285 new GridBagConstraints(0, 3, 1, 1, 0.1, 0.1, 286 GridBagConstraints.CENTER, 287 GridBagConstraints.HORIZONTAL, 288 new Insets(3, 15, 3, 5), 0, 0)); 289 this.add(optionTab, 290 new GridBagConstraints(0, 4, 1, 1, 0.1, 0.1, 291 GridBagConstraints.CENTER, 292 GridBagConstraints.HORIZONTAL, 293 new Insets(3, 15, 5, 5), 0, 0)); 294 this.add(checkStatic, 295 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 296 GridBagConstraints.WEST, 297 GridBagConstraints.HORIZONTAL, 298 new Insets(5, 5, 2, 5), 0, 0)); 299 } 300 301 private void enableCompileOptions(boolean enable) { 302 radioDefault.setEnabled(enable); 303 radioCustom.setEnabled(enable); 304 radioMap.setEnabled(enable); 305 textClassName.setEnabled(enable && radioCustom.isSelected()); 306 if (textClassName.isEnabled()) { 307 textClassName.setBackground(SystemColor.info); 308 } else { 309 textClassName.setBackground(SystemColor.control); 310 } 311 buttonMap.setEnabled(enable); 312 optionTab.setEnabled(enable); 313 } 314 315 private void refreshClassName() { 316 textClassName.setEnabled(radioCustom.isSelected()); 317 if (textClassName.isEnabled()) { 318 textClassName.setBackground(SystemColor.info); 319 } else { 320 textClassName.setBackground(SystemColor.control); 321 } 322 if (getXMLCNode() != null) { 323 String className = new String (); 324 325 save(); 326 className = getXMLCNode().getMetaDataHandler().getClassName(); 327 textClassName.setText(className); 328 } 329 buttonMap.setEnabled(radioMap.isSelected()); 330 } 331 332 private OtterXMLCNode getXMLCNode() { 333 OtterXMLCNode xmlcNode = null; 334 OtterNode node = getNode(); 335 336 if (node instanceof OtterXMLCNode) { 337 xmlcNode = (OtterXMLCNode) node; 338 } 339 return xmlcNode; 340 } 341 342 private void editMap() { 343 MapDialog dialog = null; 344 String t = res.getString("Edit_Project_Map"); 345 346 dialog = new MapDialog(((JDialog) this.getTopLevelAncestor()), t, 347 true); 348 dialog.setProject(getProject()); 349 dialog.show(); 350 } 351 352 private class LocalButtonListener implements ActionListener { 353 public void actionPerformed(ActionEvent e) { 354 Object source = e.getSource(); 355 356 if (source == buttonMap) { 357 editMap(); 358 refreshClassName(); 359 } 360 } 361 362 } 363 364 private class LocalRadioListener implements ActionListener { 366 public void actionPerformed(ActionEvent e) { 367 JRadioButton source = (JRadioButton) e.getSource(); 368 369 if (source.isSelected()) { 370 refreshClassName(); 371 } 372 } 373 374 } 375 376 private class LocalCheckListener implements ActionListener { 378 public void actionPerformed(ActionEvent e) { 379 Object source = null; 380 381 source = e.getSource(); 382 if (source == checkCompile && checkCompile.isSelected()) { 383 checkStatic.setSelected(false); 384 } else if (source == checkStatic && checkStatic.isSelected()) { 385 checkCompile.setSelected(false); 386 } 387 enableCompileOptions(checkCompile.isSelected() 388 && (!checkStatic.isSelected())); 389 } 390 391 } 392 } 393 | Popular Tags |