1 package org.enhydra.kelp.ant.xmlc; 2 3 import org.enhydra.kelp.common.AbstractTool; 7 import org.enhydra.kelp.common.event.SelectionPanelEvent; 8 import org.enhydra.kelp.common.event.SelectionPanelListener; 9 import org.enhydra.kelp.common.event.WriteListener; 10 import org.enhydra.kelp.common.node.OtterProject; 11 import org.enhydra.kelp.common.node.OtterFileNode; 12 import org.enhydra.kelp.common.swing.AddinInnerPanel; 13 import org.enhydra.kelp.common.properties.XMLCProjectPropertyPanel; 14 15 import org.enhydra.kelp.ant.node.AntProject; 17 import org.enhydra.kelp.ant.swing.HTMLViewer; 18 19 20 import org.enhydra.tool.common.PathHandle; 22 import org.enhydra.tool.common.InnerPanel; 23 import org.enhydra.tool.common.SwingUtil; 24 import org.enhydra.tool.common.ButtonPanel; 25 import org.enhydra.tool.common.event.FirstFocusEvent; 26 import org.enhydra.tool.common.event.FirstFocusListener; 27 28 import java.io.File ; 30 import java.io.IOException ; 31 import java.awt.Component ; 32 import java.awt.Dialog ; 33 import java.awt.Frame ; 34 import java.awt.event.ActionListener ; 35 import java.lang.ref.WeakReference ; 36 import java.net.URL ; 37 import java.util.ResourceBundle ; 38 39 import javax.swing.JDialog ; 40 import javax.swing.JEditorPane ; 41 42 import org.enhydra.kelp.common.node.OtterDocumentNode; 43 import org.enhydra.kelp.ant.node.AntDocumentNode; 44 53 54 public class AntXMLCTool extends AbstractTool 55 implements SelectionPanelListener, FirstFocusListener { 56 57 static ResourceBundle addinRes = 58 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 59 private AntXMLCInnerPanel innerPanel = null; 60 private AntXMLCButtonPanel buttonPanel = null; 61 private WeakReference compileRef = null; 62 private static AntProject project = null; 63 64 public AntXMLCTool() { 65 super(); 66 innerPanel = new AntXMLCInnerPanel(); 67 buttonPanel = new AntXMLCButtonPanel(); 68 innerPanel.addFirstFocusListener(this); 69 innerPanel.getSelectionPanel().addSelectionPanelListener(this); 70 } 71 public static void main(String [] args) { 72 SwingUtil.setLookAndFeelToSystem(); 73 AntXMLCTool tool = null; 74 75 if(args.length > 0){ 76 File root = new File (args[0]); 78 if(!root.exists()){ 79 System.err.println("ERROR: directory'"+args[0]+"' don't exist!"); 80 return; 81 } 82 try { 83 project = new AntProject(args[0]); 84 } 85 catch (Exception ex) { 86 ex.printStackTrace(); 87 return; 88 } 89 90 }else{ 91 return; 92 } 94 tool = new AntXMLCTool(); 95 tool.setProject(project); tool.showDialog(new Frame ()); 97 } 99 102 public void build() { 103 ((AntXMLCInnerPanel)getInnerPanel()).selectOutputTab(); 104 ((AntXMLCInnerPanel)getInnerPanel()).save(); 105 ((AntXMLCInnerPanel)getInnerPanel()).clearOutput(); 106 buildImpl(); 107 } 108 109 private void buildImpl() { 110 AntXMLCBuilder builder = new AntXMLCBuilder(((AntXMLCInnerPanel)getInnerPanel()).getWriteListeners()); 111 builder.setProject(getProject()); 112 builder.build(); 113 } 114 115 public static final String getDefaultTitle() { 116 return "XML Compiler"; 117 } 118 119 public String getTitle() { 121 return AntXMLCTool.getDefaultTitle(); 122 } 123 124 public InnerPanel getInnerPanel() { 126 return innerPanel; 127 } 128 129 public ButtonPanel getButtonPanel() { 131 return buttonPanel; 132 } 133 134 public ActionListener createButtonListener() { 135 return (new AntXMLCButtonListener(this)); 136 } 137 138 public void setProject(OtterProject project) { 140 super.setProject(project); 141 setNodes(project.getAllDocuments()); 142 } 143 144 public void clearAll() { 146 super.clearAll(); 147 innerPanel.removeFirstFocusListener(this); 148 if (compileRef != null) { 149 compileRef.clear(); 150 } 151 innerPanel = null; 152 buttonPanel = null; 153 compileRef = null; 154 } 155 156 public void onFirstFocus(FirstFocusEvent event) { 158 refreshCompile(); 159 } 160 public void onSelection(SelectionPanelEvent event) { 162 boolean enable = event.getSelected().size() > 0; 163 OtterFileNode[] fileNodes = new OtterFileNode[0]; 165 fileNodes = innerPanel.getNodes(); 166 OtterDocumentNode[] docNodes = new OtterDocumentNode[fileNodes.length]; 167 for(int i=0; i<fileNodes.length;i++){ 168 docNodes[i] = (OtterDocumentNode) fileNodes[i]; 169 } 170 project.setAllDocuments(docNodes); 171 refreshCompile(enable); 173 } 174 175 public void showHelp(Dialog parent){ 176 URL helpURL = this.getClass().getClassLoader().getResource("using_ant_kelp.html"); 177 HTMLViewer.createAndShow(parent, "Kelp Help", helpURL); 178 179 } 180 185 188 protected OtterFileNode[] getNodes() { 189 return innerPanel.getNodes(); 190 } 191 192 195 protected void setNodes(OtterFileNode[] n) { 196 innerPanel.setNodes(n); 197 } 199 200 protected String [] getSelectText() { 201 String [] s = { 202 "Documents Available", "Documents Selected" 203 }; 204 return s; 205 } 206 207 protected String getBuildText() { 209 return addinRes.getString("buttonMake_Text"); 210 } 211 212 protected String getProgressTitle() { 214 return addinRes.getString("XMLC_Progress"); 215 } 216 217 protected AddinInnerPanel getPropertyPanel() { 219 return innerPanel; 220 } 221 222 private Component getCompile() { 223 Component comp = null; 224 225 if (compileRef == null) { 226 comp = ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(), 227 AntXMLCButtonPanel.COMMAND_COMPILE); 228 if (comp != null) { 229 compileRef = new WeakReference (comp); 230 } 231 } else { 232 comp = (Component ) compileRef.get(); 233 } 234 return comp; 235 } 236 private void refreshCompile() { 238 239 boolean enable = false; 240 OtterFileNode[] nodes = new OtterFileNode[0]; 241 nodes = innerPanel.getNodes(); 242 if(nodes != null){ 243 244 for (int i = 0; i < nodes.length; i++) { 245 if (nodes[i].isSelected()) { 246 enable = true; 247 break; 248 } 249 } 250 } 251 refreshCompile(enable); 252 } 253 254 private void refreshCompile(boolean enable) { 255 Component compileButton = getCompile(); 256 257 if (compileButton != null) { 258 compileButton.setEnabled(enable); 259 } 260 } 261 262 } | Popular Tags |