1 23 package org.enhydra.kelp.common.xmlc; 24 25 import org.enhydra.tool.common.InnerPanel; 27 import org.enhydra.tool.common.SwingUtil; 28 import org.enhydra.tool.common.ButtonPanel; 29 import org.enhydra.tool.common.event.FirstFocusEvent; 30 import org.enhydra.tool.common.event.FirstFocusListener; 31 32 import org.enhydra.kelp.common.AbstractTool; 34 import org.enhydra.kelp.common.event.SelectionPanelEvent; 35 import org.enhydra.kelp.common.event.SelectionPanelListener; 36 import org.enhydra.kelp.common.event.WriteListener; 37 import org.enhydra.kelp.common.node.OtterProject; 38 import org.enhydra.kelp.common.node.OtterFileNode; 39 import org.enhydra.kelp.common.swing.AddinInnerPanel; 40 import org.enhydra.kelp.common.properties.XMLCProjectPropertyPanel; 41 42 import java.awt.Component ; 44 import java.awt.Frame ; 45 import java.awt.event.ActionListener ; 46 import java.lang.ref.WeakReference ; 47 import java.util.ResourceBundle ; 48 49 public class CoreXMLCTool extends AbstractTool 51 implements SelectionPanelListener, FirstFocusListener { 52 static ResourceBundle addinRes = 53 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 55 private XMLCNodeBuilder nodeBuilder = null; 57 private XMLCProjectPropertyPanel propertyPanel = null; 58 private XMLCInnerPanel innerPanel = null; 59 private XMLCButtonPanel buttonPanel = null; 60 private WeakReference compileRef = null; 61 62 public static void main(String [] args) { 63 SwingUtil.setLookAndFeelToSystem(); 64 CoreXMLCTool tool = null; 65 66 tool = new CoreXMLCTool(); 67 tool.showDialog(new Frame ()); 68 System.exit(0); 69 } 70 71 public static final String getDefaultTitle() { 72 return "XML Compiler"; 73 } 74 75 public CoreXMLCTool() { 76 super(); 77 innerPanel = new XMLCInnerPanel(); 78 buttonPanel = new XMLCButtonPanel(); 79 innerPanel.getSelectionPanel().addSelectionPanelListener(this); 80 innerPanel.setPropertyPanel(getPropertyPanel()); 81 innerPanel.setSelectText(getSelectText()); 82 innerPanel.addFirstFocusListener(this); 83 } 84 85 public void onSelection(SelectionPanelEvent event) { 87 boolean enable = event.getSelected().size() > 0; 88 89 refreshCompile(enable); 90 } 91 92 public String getTitle() { 94 return CoreXMLCTool.getDefaultTitle(); 95 } 96 97 public InnerPanel getInnerPanel() { 99 return innerPanel; 100 } 101 102 public ButtonPanel getButtonPanel() { 104 return buttonPanel; 105 } 106 107 public ActionListener createButtonListener() { 108 return (new XMLCButtonListener(this)); 109 } 110 111 public void setProject(OtterProject project) { 113 super.setProject(project); 114 setNodes(project.getAllXMLCNodes()); 115 } 116 117 public void clearAll() { 119 super.clearAll(); 120 innerPanel.removeFirstFocusListener(this); 121 if (compileRef != null) { 122 compileRef.clear(); 123 } 124 innerPanel = null; 125 buttonPanel = null; 126 compileRef = null; 127 } 128 129 public void build() { 130 innerPanel.selectOutputTab(); 131 innerPanel.save(); 132 innerPanel.clearOutput(); 133 openProgress(); 134 buildImpl(); 135 } 136 137 public void onFirstFocus(FirstFocusEvent event) { 139 refreshCompile(); 140 } 141 142 147 150 protected OtterFileNode[] getNodes() { 151 return innerPanel.getNodes(); 152 } 153 154 157 protected void setNodes(OtterFileNode[] n) { 158 innerPanel.setNodes(n); 159 refreshCompile(); 160 } 161 162 protected String [] getSelectText() { 163 String [] s = { 164 "Documents Available", "Documents Selected" 165 }; 166 167 return s; 168 } 169 170 protected String getBuildText() { 172 return addinRes.getString("buttonMake_Text"); 173 } 174 175 protected String getProgressTitle() { 177 return addinRes.getString("XMLC_Progress"); 178 } 179 180 protected AddinInnerPanel getPropertyPanel() { 182 if (propertyPanel == null) { 183 propertyPanel = new XMLCProjectPropertyPanel(); 184 } 185 return propertyPanel; 186 } 187 188 private void buildImpl() { 189 if (nodeBuilder != null) { 190 nodeBuilder.setFresh(false); 191 } 192 nodeBuilder = new XMLCNodeBuilder(innerPanel.getWriteListeners()); 193 nodeBuilder.setProject(getProject()); 194 nodeBuilder.setNodes(getProject().getAllXMLCNodes()); 195 nodeBuilder.addProgressListener(getProgressMeter()); 196 getProgressMeter().addCancelListener(nodeBuilder); 197 nodeBuilder.build(); 198 } 199 200 private Component getCompile() { 201 Component comp = null; 202 203 if (compileRef == null) { 204 comp = 205 ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(), 206 XMLCButtonPanel.COMMAND_COMPILE); 207 if (comp != null) { 208 compileRef = new WeakReference (comp); 209 } 210 } else { 211 comp = (Component ) compileRef.get(); 212 } 213 return comp; 214 } 215 216 private void refreshCompile() { 217 boolean enable = false; 218 OtterFileNode[] nodes = new OtterFileNode[0]; 219 220 nodes = innerPanel.getNodes(); 221 for (int i = 0; i < nodes.length; i++) { 222 if (nodes[i].isSelected()) { 223 enable = true; 224 break; 225 } 226 } 227 refreshCompile(enable); 228 } 229 230 private void refreshCompile(boolean enable) { 231 Component compileButton = getCompile(); 232 233 if (compileButton != null) { 234 compileButton.setEnabled(enable); 235 } 236 } 237 238 } 239 | Popular Tags |