1 23 package org.enhydra.kelp.common.xmlc; 24 25 import org.enhydra.tool.ToolBoxInfo; 27 import org.enhydra.tool.common.DataValidationException; 28 import org.enhydra.tool.common.SwingUtil; 29 30 import org.enhydra.kelp.KelpInfo; 32 import org.enhydra.kelp.common.Constants; 33 import org.enhydra.kelp.common.event.WriteEvent; 34 import org.enhydra.kelp.common.event.WriteListener; 35 import org.enhydra.kelp.common.node.OtterProject; 36 import org.enhydra.kelp.common.node.OtterFileNode; 37 import org.enhydra.kelp.common.node.OtterNode; 38 import org.enhydra.kelp.common.swing.AddinInnerPanel; 39 import org.enhydra.kelp.common.swing.FileNodeSelectionPanel; 40 41 import java.util.ArrayList ; 43 import java.util.Arrays ; 44 import java.util.ResourceBundle ; 45 import java.awt.*; 46 import java.beans.*; 47 import javax.swing.*; 48 49 public class XMLCInnerPanel extends AddinInnerPanel { 51 52 static ResourceBundle res = 54 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 56 private FileNodeSelectionPanel selectionPanel = null; 58 private boolean standalone = false; 59 private JPanel panelOptionFiller0 = null; 60 private JPanel panelOptionFiller1 = null; 61 private JPanel panelOptionFiller2 = null; 62 private GridBagLayout layoutMain = null; 63 private JPanel propertyPanelHolder = null; 64 private AddinInnerPanel propertyPanel = null; 65 private XMLCOutputPanel outputPanel = null; 66 private JTabbedPane tab = null; 67 private WriteListener[] writeListeners = new WriteListener[0]; 68 private String progressTitle = new String (); 69 70 public static XMLCInnerPanel XMLCfindAncestor(Component comp) { 71 Component found = null; 72 XMLCInnerPanel ancestor = null; 73 74 found = AddinInnerPanel.findAncestor(comp); 75 if (found == null) {} 76 else if (found instanceof XMLCInnerPanel) { 77 ancestor = (XMLCInnerPanel) found; 78 } 79 return ancestor; 80 } 81 82 public XMLCInnerPanel() { 83 try { 84 jbInit(); 85 pmInit(); 86 } catch (Exception ex) { 87 ex.printStackTrace(); 88 } 89 } 90 91 public void clearAll() { 93 super.clearAll(); 94 layoutMain = null; 95 writeListeners = new WriteListener[0]; 96 } 97 98 public FileNodeSelectionPanel getSelectionPanel() { 99 return selectionPanel; 100 } 101 102 public AddinInnerPanel getPropertyPanel() { 103 return propertyPanel; 104 } 105 106 public void selectOutputTab() { 107 selectTab(outputPanel); 108 } 109 110 public void selectOptionTab() { 111 selectTab(panelOptionFiller0); 112 } 113 114 protected void setPropertyPanel(AddinInnerPanel p) { 118 if (propertyPanel == null) { 119 propertyPanelHolder.removeAll(); 120 } else { 121 propertyPanelHolder.remove(propertyPanel); 122 } 123 propertyPanel = p; 124 propertyPanelHolder.add(propertyPanel, BorderLayout.CENTER); 125 } 126 127 protected void setSelectText(String [] s) { 128 getSelectionPanel().setSelectText(s); 129 } 130 131 protected String [] getSelectText() { 132 return getSelectionPanel().getSelectText(); 133 } 134 135 protected synchronized WriteListener[] getWriteListeners() { 136 return writeListeners; 137 } 138 139 protected synchronized void addWriteListener(WriteListener l) { 140 ArrayList list = null; 141 142 list = new ArrayList (Arrays.asList(writeListeners)); 143 if (!list.contains(l)) { 144 list.add(l); 145 list.trimToSize(); 146 writeListeners = new WriteListener[list.size()]; 147 writeListeners = (WriteListener[]) list.toArray(writeListeners); 148 } 149 list.clear(); 150 } 151 152 protected synchronized void removeWriteListener(WriteListener l) { 153 ArrayList list = null; 154 155 list = new ArrayList (Arrays.asList(writeListeners)); 156 if (list.contains(l)) { 157 list.remove(l); 158 list.trimToSize(); 159 writeListeners = new WriteListener[list.size()]; 160 writeListeners = (WriteListener[]) list.toArray(writeListeners); 161 } 162 list.clear(); 163 } 164 165 168 protected OtterFileNode[] getNodes() { 169 return selectionPanel.getNodes(); 170 } 171 172 175 protected void setNodes(OtterFileNode[] n) { 176 selectionPanel.setNodes(n); 177 } 178 179 public void read(OtterNode node) { 181 super.read(node); 182 propertyPanel.read(node); 183 outputPanel.setProject(getProject()); 184 } 185 186 public void write(OtterNode node) throws DataValidationException { 188 super.write(node); 189 if (getProject() == null) { 190 System.err.println("XMLCInnerPanel.write(OtterProject p) : no project set"); 191 } else { 192 propertyPanel.write(node); 193 outputPanel.setProject(getProject()); 194 } 195 } 196 197 protected Component[] getFirstFocusComponents() { 199 Component[] comps = new Component[1]; 200 201 comps[0] = tab; 202 return comps; 203 } 204 205 public void save() { 210 super.save(); 211 propertyPanel.save(); 212 } 213 214 protected void clearOutput() { 215 outputPanel.clearOutput(); 216 } 217 218 private void selectTab(final JPanel goPanel) { 222 SelectTab runSwing = null; 223 224 runSwing = new SelectTab(tab, goPanel); 225 try { 226 if (SwingUtilities.isEventDispatchThread()) { 227 runSwing.run(); 228 } else { 229 SwingUtilities.invokeAndWait(runSwing); 230 } 231 } catch (Exception e) { 232 e.printStackTrace(); 233 } 234 try { 235 Thread.sleep(500); 236 } catch (InterruptedException e) { 237 238 } 240 } 241 242 246 private void pmInit() { 247 tab.add(res.getString("Selections"), selectionPanel); 248 tab.add(res.getString("Options"), panelOptionFiller0); 249 tab.add(res.getString("Output"), outputPanel); 250 addWriteListener(outputPanel); 251 } 252 253 257 private void jbInit() throws Exception { 258 layoutMain = 259 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 260 GridBagLayout.class.getName()); 261 panelOptionFiller0 = 262 (JPanel) Beans.instantiate(getClass().getClassLoader(), 263 JPanel.class.getName()); 264 panelOptionFiller1 = 265 (JPanel) Beans.instantiate(getClass().getClassLoader(), 266 JPanel.class.getName()); 267 panelOptionFiller2 = 268 (JPanel) Beans.instantiate(getClass().getClassLoader(), 269 JPanel.class.getName()); 270 selectionPanel = 271 (FileNodeSelectionPanel) Beans.instantiate(getClass().getClassLoader(), 272 FileNodeSelectionPanel.class.getName()); 273 propertyPanelHolder = 274 (JPanel) Beans.instantiate(getClass().getClassLoader(), 275 JPanel.class.getName()); 276 outputPanel = 277 (XMLCOutputPanel) Beans.instantiate(getClass().getClassLoader(), 278 XMLCOutputPanel.class.getName()); 279 tab = (JTabbedPane) Beans.instantiate(getClass().getClassLoader(), 280 JTabbedPane.class.getName()); 281 panelOptionFiller0.setLayout(new GridBagLayout()); 282 panelOptionFiller0.add(panelOptionFiller1, 283 new GridBagConstraints(0, 0, 1, 1, 0.15, 0.15, 284 GridBagConstraints.CENTER, 285 GridBagConstraints.BOTH, 286 new Insets(0, 0, 0, 0), 0, 0)); 287 panelOptionFiller0.add(propertyPanelHolder, 288 new GridBagConstraints(1, 0, 1, 4, 0.7, 0.7, 289 GridBagConstraints.CENTER, 290 GridBagConstraints.NONE, 291 new Insets(0, 0, 0, 0), 0, 0)); 292 panelOptionFiller0.add(panelOptionFiller2, 293 new GridBagConstraints(2, 0, 1, 1, 0.15, 0.15, 294 GridBagConstraints.CENTER, 295 GridBagConstraints.BOTH, 296 new Insets(0, 0, 0, 0), 0, 0)); 297 this.setLayout(layoutMain); 298 this.add(tab, 299 new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 300 GridBagConstraints.CENTER, 301 GridBagConstraints.BOTH, 302 new Insets(5, 5, 5, 5), 5, 5)); 303 } 304 305 private class SelectTab implements Runnable { 307 private JTabbedPane tp = null; 308 private JPanel go = null; 309 310 protected SelectTab(JTabbedPane t, JPanel g) { 311 tp = t; 312 go = g; 313 } 314 315 synchronized public void run() { 316 tp.setSelectedComponent(go); 317 try { 318 SwingUtilities.windowForComponent(tp).repaint(); 319 } catch (NullPointerException e) { 320 321 } 323 } 324 325 } 326 } 327 | Popular Tags |