1 package org.enhydra.kelp.ant.xmlc; 2 3 11 12 import org.enhydra.tool.ToolBoxInfo; 14 import org.enhydra.tool.common.DataValidationException; 15 import org.enhydra.tool.common.SwingUtil; 16 17 import org.enhydra.kelp.KelpInfo; 19 import org.enhydra.kelp.common.Constants; 20 import org.enhydra.kelp.common.event.WriteEvent; 21 import org.enhydra.kelp.common.event.WriteListener; 22 import org.enhydra.kelp.common.node.OtterProject; 23 import org.enhydra.kelp.common.node.OtterFileNode; 24 import org.enhydra.kelp.common.node.OtterNode; 25 import org.enhydra.kelp.common.swing.AddinInnerPanel; 26 import org.enhydra.kelp.common.swing.FileNodeSelectionPanel; 27 import org.enhydra.kelp.ant.swing.AntOutputPanel; 29 30 31 import java.util.ArrayList ; 33 import java.util.Arrays ; 34 import java.util.ResourceBundle ; 35 import java.awt.*; 36 import java.beans.*; 37 import javax.swing.*; 38 39 public class AntXMLCInnerPanel extends AddinInnerPanel { 41 42 static ResourceBundle res = 44 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); private boolean standalone = false; 46 47 private FileNodeSelectionPanel selectionPanel = null; 48 private GridBagLayout layoutMain = null; 49 private AntOutputPanel outputPanel = null; 50 private JTabbedPane tab = null; 51 private WriteListener[] writeListeners = new WriteListener[0]; 52 private String progressTitle = new String (); 53 AntXMLCOptionsPanel optionsPanel = null; 54 55 public static AntXMLCInnerPanel XMLCfindAncestor(Component comp) { 56 Component found = null; 57 AntXMLCInnerPanel ancestor = null; 58 59 found = AddinInnerPanel.findAncestor(comp); 60 if (found == null) {} 61 else if (found instanceof AntXMLCInnerPanel) { 62 ancestor = (AntXMLCInnerPanel) found; 63 } 64 return ancestor; 65 } 66 67 public AntXMLCInnerPanel() { 68 try { 69 jbInit(); 70 pmInit(); 71 } catch (Exception ex) { 72 ex.printStackTrace(); 73 } 74 } 75 76 public void clearAll() { 78 super.clearAll(); 79 layoutMain = null; 80 writeListeners = new WriteListener[0]; 81 } 82 public FileNodeSelectionPanel getSelectionPanel() { 84 return selectionPanel; 85 } 86 protected void setSelectText(String [] s) { 87 getSelectionPanel().setSelectText(s); 88 } 89 protected String [] getSelectText() { 90 return getSelectionPanel().getSelectText(); 91 } 92 95 protected OtterFileNode[] getNodes() { 96 return selectionPanel.getNodes(); 97 } 98 101 protected void setNodes(OtterFileNode[] n) { 102 selectionPanel.setNodes(n); 103 } 104 105 106 public AntXMLCOptionsPanel getOptionsPanel() { 107 return optionsPanel; 108 } 109 110 public void selectOutputTab() { 111 selectTab(outputPanel); 112 } 113 114 public void selectOptionTab() { 115 selectTab(optionsPanel); 116 } 117 118 122 public synchronized WriteListener[] getWriteListeners() { 123 return writeListeners; 124 } 125 126 public synchronized void addWriteListener(WriteListener l) { 127 ArrayList list = null; 128 list = new ArrayList (Arrays.asList(writeListeners)); 129 if (!list.contains(l)) { 130 list.add(l); 131 list.trimToSize(); 132 writeListeners = new WriteListener[list.size()]; 133 writeListeners = (WriteListener[]) list.toArray(writeListeners); 134 } 135 list.clear(); 136 } 137 138 public synchronized void removeWriteListener(WriteListener l) { 139 ArrayList list = null; 140 list = new ArrayList (Arrays.asList(writeListeners)); 141 if (list.contains(l)) { 142 list.remove(l); 143 list.trimToSize(); 144 writeListeners = new WriteListener[list.size()]; 145 writeListeners = (WriteListener[]) list.toArray(writeListeners); 146 } 147 list.clear(); 148 } 149 150 151 public void read(OtterNode node) { 153 super.read(node); 154 outputPanel.setProject(getProject()); 155 optionsPanel.setProject(getProject()); 156 } 157 158 public void write(OtterNode node) throws DataValidationException { 160 super.write(node); 161 if (getProject() == null) { 162 System.err.println("AntXMLCInnerPanel.write(OtterProject p) : no project set"); 163 } else { 164 outputPanel.setProject(getProject()); 165 } 166 } 167 168 protected Component[] getFirstFocusComponents() { 170 Component[] comps = new Component[1]; 171 172 comps[0] = tab; 173 return comps; 174 } 175 176 public void save() { 181 super.save(); 182 } 184 public void clearOutput() { 187 outputPanel.clearOutput(); 189 } 190 191 195 private void selectTab(final JPanel goPanel) { 196 SelectTab runSwing = null; 197 198 runSwing = new SelectTab(tab, goPanel); 199 try { 200 if (SwingUtilities.isEventDispatchThread()) { 201 runSwing.run(); 202 } else { 203 SwingUtilities.invokeAndWait(runSwing); 204 } 205 } catch (Exception e) { 206 e.printStackTrace(); 207 } 208 try { 209 Thread.sleep(500); 210 } catch (InterruptedException e) { 211 212 } 214 } 215 216 220 private void pmInit() { 221 tab.add(res.getString("Selections"), selectionPanel); 222 tab.add(res.getString("Options"), optionsPanel); 223 tab.add(res.getString("Output"), outputPanel); 224 addWriteListener(outputPanel); 225 } 226 227 231 private void jbInit() throws Exception { 232 layoutMain = 233 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 234 GridBagLayout.class.getName()); 235 236 optionsPanel = (AntXMLCOptionsPanel) Beans.instantiate(getClass().getClassLoader(), 237 AntXMLCOptionsPanel.class.getName()); 238 239 selectionPanel = 240 (FileNodeSelectionPanel) Beans.instantiate(getClass().getClassLoader(), 241 FileNodeSelectionPanel.class.getName()); 242 243 outputPanel = 244 (AntOutputPanel) Beans.instantiate(getClass().getClassLoader(), 245 AntOutputPanel.class.getName()); 246 tab = (JTabbedPane) Beans.instantiate(getClass().getClassLoader(), 247 JTabbedPane.class.getName()); 248 249 this.setLayout(layoutMain); 250 this.add(tab, 251 new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 252 GridBagConstraints.CENTER, 253 GridBagConstraints.BOTH, 254 new Insets(5, 5, 5, 5), 5, 5)); 255 } 256 257 private class SelectTab implements Runnable { 258 private JTabbedPane tp = null; 259 private JPanel go = null; 260 261 protected SelectTab(JTabbedPane t, JPanel g) { 262 tp = t; 263 go = g; 264 } 265 266 synchronized public void run() { 267 tp.setSelectedComponent(go); 268 try { 269 SwingUtilities.windowForComponent(tp).repaint(); 270 } catch (NullPointerException e) { 271 272 } 274 } 275 276 } 277 278 } 279 | Popular Tags |