1 package org.enhydra.kelp.ant.xmlc; 2 import org.enhydra.kelp.common.node.OtterProject; 4 import org.enhydra.kelp.common.Constants; 5 6 import org.enhydra.kelp.ant.node.AntProject; 7 import org.enhydra.kelp.ant.xmlc.AntXMLCParamViewer; 8 9 import org.enhydra.tool.common.DialogPanel; 11 import org.enhydra.tool.common.ExtensionFilter; 12 import org.enhydra.tool.common.PathHandle; 13 14 import org.enhydra.tool.swing.layout.*; 15 16 import java.awt.*; 18 import java.awt.event.*; 19 import javax.swing.*; 20 import javax.swing.border.*; 21 import java.util.ResourceBundle ; 22 import java.io.File ; 23 32 33 public class AntXMLCOptionsPanel extends JPanel { 34 35 static ResourceBundle res = ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 36 37 XYLayout xYLayout1 = new XYLayout(); 38 JPanel jPanel1 = new JPanel(); 39 JPanel jPanel2 = new JPanel(); 40 XYLayout xYLayout2 = new XYLayout(); 41 XYLayout xYLayout3 = new XYLayout(); 42 TitledBorder titledBorder1; 43 TitledBorder titledBorder2; 44 JLabel jLabel1 = new JLabel(); 45 JTextField jTextPackage = new JTextField(); 46 JButton jButtonDefault = new JButton(); 47 JLabel jLabel2 = new JLabel(); 48 JTextField jTextOptionFile = new JTextField(); 49 JButton jButtonEdit = new JButton(); 50 JButton jButtonBrowse = new JButton(); 51 52 AntProject project = null; 54 JPanel jPanel3 = new JPanel(); 55 JCheckBox jCheckBoxInvoke = new JCheckBox(); 56 XYLayout xYLayout4 = new XYLayout(); 57 JCheckBox jCheckBoxVerbose = new JCheckBox(); 58 59 public AntXMLCOptionsPanel() { 60 try { 61 jbInit(); 62 pmInit(); 63 } 64 catch(Exception ex) { 65 ex.printStackTrace(); 66 } 67 } 68 void jbInit() throws Exception { 69 titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Mappings"); 70 titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"XMLC Options"); 71 this.setLayout(xYLayout1); 72 jPanel1.setLayout(xYLayout2); 73 jPanel2.setLayout(xYLayout3); 74 jPanel1.setBorder(titledBorder1); 75 jPanel2.setBorder(titledBorder2); 76 jLabel1.setText(res.getString("Package")); 77 jButtonDefault.setText(res.getString("Default")); 78 jButtonDefault.addActionListener(new java.awt.event.ActionListener () { 79 public void actionPerformed(ActionEvent e) { 80 jButtonDefault_actionPerformed(e); 81 } 82 }); 83 jLabel2.setText(res.getString("Option_file")); 84 jButtonEdit.setText(res.getString("Edit")); 85 jButtonEdit.addActionListener(new java.awt.event.ActionListener () { 86 public void actionPerformed(ActionEvent e) { 87 jButtonEdit_actionPerformed(e); 88 } 89 }); 90 jButtonBrowse.setText(res.getString("Browse")); 91 jButtonBrowse.addActionListener(new java.awt.event.ActionListener () { 92 public void actionPerformed(ActionEvent e) { 93 jButtonBrowse_actionPerformed(e); 94 } 95 }); 96 xYLayout1.setWidth(520); 97 xYLayout1.setHeight(302); 98 jTextOptionFile.setBackground(SystemColor.inactiveCaptionText); 99 jTextOptionFile.setEditable(false); 100 jPanel3.setLayout(xYLayout4); 101 jCheckBoxInvoke.setText(res.getString("XMLC_Invoke_make")); 102 jCheckBoxInvoke.addActionListener(new java.awt.event.ActionListener () { 103 public void actionPerformed(ActionEvent e) { 104 jCheckBoxInvoke_actionPerformed(e); 105 } 106 }); 107 jCheckBoxVerbose.setText(res.getString("Verbose_output")); 108 jCheckBoxVerbose.addActionListener(new java.awt.event.ActionListener () { 109 public void actionPerformed(ActionEvent e) { 110 jCheckBoxVerbose_actionPerformed(e); 111 } 112 }); 113 jTextPackage.addFocusListener(new java.awt.event.FocusAdapter () { 114 public void focusLost(FocusEvent e) { 115 jTextPackage_focusLost(e); 116 } 117 }); 118 119 jPanel1.add(jTextPackage, new XYConstraints(63, 13, 357, 23)); 120 jPanel1.add(jLabel1, new XYConstraints(4, 13, 59, 20)); 121 jPanel1.add(jButtonDefault, new XYConstraints(424, 11, -1, -1)); 122 this.add(jPanel3, new XYConstraints(6, 16, 509, 106)); 123 jPanel2.add(jLabel2, new XYConstraints(3, 15, -1, -1)); 124 jPanel2.add(jTextOptionFile, new XYConstraints(63, 13, 278, 25)); 125 jPanel2.add(jButtonBrowse, new XYConstraints(410, 13, 88, -1)); 126 jPanel2.add(jButtonEdit, new XYConstraints(343, 13, -1, -1)); 127 this.add(jPanel1, new XYConstraints(6, 127, 509, 76)); 128 jPanel3.add(jCheckBoxVerbose, new XYConstraints(6, 52, 151, 21)); 129 jPanel3.add(jCheckBoxInvoke, new XYConstraints(6, 14, -1, -1)); 130 this.add(jPanel2, new XYConstraints(6, 208, 509, 86)); 131 } 132 private void pmInit() { 133 } 139 140 public void setProject(OtterProject otterProject){ 141 if(otterProject instanceof AntProject) { 142 project = (AntProject) otterProject; 143 initOptions(); 144 } 145 else 146 System.err.println("DEBUG project must be AntProject"); } 148 149 private void initOptions() { 150 String invoke = project.getProperty(AntProject.XMLC_INVOKE); 151 if(invoke != null) 152 jCheckBoxInvoke.setSelected(invoke.equalsIgnoreCase("true")); 153 String verbose = project.getProperty(AntProject.XMLC_VERBOSE); 154 if(verbose != null) 155 jCheckBoxVerbose.setSelected(verbose.equalsIgnoreCase("true")); 156 jTextPackage.setText(project.getProperty(AntProject.XMLC_PACKAGE_NAME)); 157 jTextOptionFile.setText(project.getProperty(AntProject.XMLC_OPTIONS_FILE)); 158 } 159 160 public OtterProject getProject(){ 161 return (OtterProject) project; 162 } 163 164 private void editParameters() { 165 String [] params = new String [0]; 166 AntXMLCParamViewer viewer = null; 167 168 viewer = new AntXMLCParamViewer(); 169 params = project.getXMLCOptionsFileParams(); 170 viewer.setParameters(params); 171 viewer.setOwner((Dialog) getTopLevelAncestor()); 172 if (viewer.showDialog() == DialogPanel.OK_OPTION) { 173 params = viewer.getParameters(); 174 project.setXMLCOptionsFileParams(params); 175 } 176 } 177 private void browseForFile() { 178 JFileChooser chooser; 179 ExtensionFilter filter; 180 File file; 181 String fileDir = new String (); 182 String fileName = new String (); 183 String filePath = new String (); 184 185 filter = new ExtensionFilter(); 186 filter.addExtension(Constants.TYPE_XMLC); 187 filter.setDescriptionTitle(res.getString("filter_DescriptionTitle")); 188 chooser = new JFileChooser(); 189 if (jTextOptionFile.getText().trim().length() > 0) { 190 chooser.setCurrentDirectory( 191 new File (project.getProperty(AntProject.RESOURCES_DIR))); 192 } else { 193 210 PathHandle ph = PathHandle.createPathHandle(getProject().getWorkingPath()); 211 chooser.setCurrentDirectory(ph.getFile()); 212 } 213 chooser.setFileFilter(filter); 214 chooser.setDialogTitle(res.getString("chooser_DialogTitle")); 215 chooser.setApproveButtonText(res.getString("OK")); 216 int v = chooser.showOpenDialog(this); 217 218 this.requestFocus(); 219 jButtonBrowse.requestFocus(); 220 if (v == JFileChooser.APPROVE_OPTION) { 221 if (chooser.getSelectedFile() == null 222 || (!chooser.getSelectedFile().isFile())) { 223 jTextOptionFile.setText(new String ()); 224 } else { 225 fileDir = chooser.getCurrentDirectory().toString(); 226 fileDir = stripSlash(fileDir); 227 fileName = chooser.getSelectedFile().getName(); 228 filePath = fileDir + File.separator + fileName; 229 jTextOptionFile.setText(filePath); 230 project.setProperty(AntProject.XMLC_OPTIONS_FILE, filePath); 231 } 232 } 233 chooser.removeAll(); 234 chooser = null; 235 } 236 237 private String stripSlash(String dir) { 238 String stripped = new String (dir); 239 240 if (dir != null) { 241 if (dir.length() > 0) { 242 if (dir.endsWith(File.separator)) { 243 stripped = dir.substring(0, dir.length() - 1); 244 } 245 } 246 } 247 return stripped; 248 } 249 265 void jCheckBoxInvoke_actionPerformed(ActionEvent e) { 266 String invoke = "false"; 267 if(jCheckBoxInvoke.isSelected()) 268 invoke = "true"; 269 project.setProperty(AntProject.XMLC_INVOKE, invoke); 270 } 271 272 void jCheckBoxVerbose_actionPerformed(ActionEvent e) { 273 String verbose = "false"; 274 if(jCheckBoxVerbose.isSelected()) 275 verbose = "true"; 276 project.setProperty(AntProject.XMLC_VERBOSE, verbose); 277 } 278 279 void jButtonDefault_actionPerformed(ActionEvent e) { 280 jTextPackage.setText(project.getProperty(AntProject.XMLC_DEFAULT_PACKAGE)); 282 project.setProperty(AntProject.XMLC_PACKAGE_NAME, jTextPackage.getText()); 283 } 284 285 void jButtonEdit_actionPerformed(ActionEvent e) { 286 editParameters(); 287 } 288 289 void jButtonBrowse_actionPerformed(ActionEvent e) { 290 browseForFile(); 291 } 292 293 void jTextPackage_focusLost(FocusEvent e) { 294 project.setProperty(AntProject.XMLC_PACKAGE_NAME, jTextPackage.getText()); 295 } 296 } | Popular Tags |