KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > templateeditor > TemplateEditor


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.genimen.djeneric.tools.templateeditor;
32
33 import java.awt.AWTEvent JavaDoc;
34 import java.awt.BorderLayout JavaDoc;
35 import java.awt.Color JavaDoc;
36 import java.awt.Component JavaDoc;
37 import java.awt.Dimension JavaDoc;
38 import java.awt.Image JavaDoc;
39 import java.awt.SystemColor JavaDoc;
40 import java.awt.Toolkit JavaDoc;
41 import java.awt.event.ActionEvent JavaDoc;
42 import java.awt.event.InputEvent JavaDoc;
43 import java.awt.event.KeyEvent JavaDoc;
44 import java.awt.event.KeyListener JavaDoc;
45 import java.awt.event.WindowEvent JavaDoc;
46 import java.io.File JavaDoc;
47 import java.io.FileNotFoundException JavaDoc;
48 import java.net.URL JavaDoc;
49
50 import javax.swing.ImageIcon JavaDoc;
51 import javax.swing.JFileChooser JavaDoc;
52 import javax.swing.JLabel JavaDoc;
53 import javax.swing.JMenu JavaDoc;
54 import javax.swing.JMenuBar JavaDoc;
55 import javax.swing.JMenuItem JavaDoc;
56 import javax.swing.JPanel JavaDoc;
57 import javax.swing.JScrollPane JavaDoc;
58 import javax.swing.JSplitPane JavaDoc;
59 import javax.swing.JTabbedPane JavaDoc;
60 import javax.swing.JTextArea JavaDoc;
61 import javax.swing.JTree JavaDoc;
62
63 import com.genimen.djeneric.repository.DjModelView;
64 import com.genimen.djeneric.repository.DjPersistenceManager;
65 import com.genimen.djeneric.repository.DjPersistenceManagerFactory;
66 import com.genimen.djeneric.repository.DjSession;
67 import com.genimen.djeneric.repository.DjUserContextAssociation;
68 import com.genimen.djeneric.repository.exceptions.DjenericException;
69 import com.genimen.djeneric.structure.ExtentUsage;
70 import com.genimen.djeneric.tools.common.AboutDialog;
71 import com.genimen.djeneric.tools.common.DjenericTool;
72 import com.genimen.djeneric.tools.common.ModelViewDialog;
73 import com.genimen.djeneric.tools.generator.util.TemplateSet;
74 import com.genimen.djeneric.tools.generator.util.TemplateSetManager;
75 import com.genimen.djeneric.tools.specifier.tree.DjenericFolder;
76 import com.genimen.djeneric.tools.templateeditor.dialogs.OptionsDialog;
77 import com.genimen.djeneric.tools.templateeditor.ui.TemplatePanel;
78 import com.genimen.djeneric.util.DjEnvironment;
79 import com.genimen.djeneric.util.DjFileFilter;
80 import com.genimen.djeneric.util.DjLogPrintStream;
81 import com.genimen.djeneric.util.DjLogger;
82 import com.genimen.djeneric.util.DjStatusDisplayer;
83 import com.genimen.djeneric.util.DjVersion;
84
85 public class TemplateEditor extends DjenericTool implements KeyListener JavaDoc, DjStatusDisplayer
86 {
87   private static final long serialVersionUID = 1L;
88   protected final String JavaDoc PROPERTIES_FILE_NAME = DjEnvironment.getAbsoluteFileName("templateeditor.properties");
89   protected final static String JavaDoc LOG_FILE_NAME = DjEnvironment.getAbsoluteFileName("templateeditor.log");
90
91   public final static String JavaDoc OK_MSG = "Ok";
92   public final static String JavaDoc KEY_TEMPLATEPATH = "path.template";
93   public final static String JavaDoc KEY_INCLUDEPATH = "path.include";
94
95   JSplitPane JavaDoc _splitpane = new JSplitPane JavaDoc();
96   JMenuBar JavaDoc _menu = new JMenuBar JavaDoc();
97   JMenu JavaDoc _mnuFile = new JMenu JavaDoc();
98   JMenuItem JavaDoc _mnuExit = new JMenuItem JavaDoc();
99   JMenu JavaDoc _mnuHelp = new JMenu JavaDoc();
100   JMenuItem JavaDoc _mnuAbout = new JMenuItem JavaDoc();
101   DjPersistenceManager _mgr;
102   DjSession _session;
103   DjenericFolder _root = new DjenericFolder();
104
105   JLabel JavaDoc _lblStatus = new JLabel JavaDoc();
106   Color JavaDoc _normalColor = new Color JavaDoc(102, 102, 153);
107
108   JPanel JavaDoc _desktopPanel = new JPanel JavaDoc();
109   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
110   JTabbedPane JavaDoc _tabs = new JTabbedPane JavaDoc();
111   JMenuItem JavaDoc _mnuNewSet = new JMenuItem JavaDoc();
112   JMenuItem JavaDoc _mnuOpenSet = new JMenuItem JavaDoc();
113   JMenuItem JavaDoc _mnuSetProperties = new JMenuItem JavaDoc();
114   JMenuItem JavaDoc _mnuOptions = new JMenuItem JavaDoc();
115   JMenu JavaDoc _mnuTools = new JMenu JavaDoc();
116   TemplateSetManager _templateSetManager = new TemplateSetManager();
117   ExtentUsage[] _navigatorStructure = null;
118
119   JMenu JavaDoc _mnuTabs = new JMenu JavaDoc();
120   JMenuItem JavaDoc _mnuNextTab = new JMenuItem JavaDoc();
121   JMenuItem JavaDoc _mnuPrevTab = new JMenuItem JavaDoc();
122   JMenuItem JavaDoc _mnuCloseTab = new JMenuItem JavaDoc();
123   JMenuItem JavaDoc _mnuCloseAll = new JMenuItem JavaDoc();
124   JSplitPane JavaDoc _structureSplitter = new JSplitPane JavaDoc();
125   JTabbedPane JavaDoc _templateSetTabs = new JTabbedPane JavaDoc();
126   JScrollPane JavaDoc _scrStructure = new JScrollPane JavaDoc();
127   JTree JavaDoc _structureTree = new JTree JavaDoc();
128
129   /**
130    * Construct the frame
131    *
132    * @param repositories
133    * Description of the Parameter
134    */

135   public TemplateEditor(String JavaDoc repositories)
136   {
137     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
138     setIconImage(getImage("templateeditor.gif"));
139
140     try
141     {
142       setStatusLabel(_lblStatus);
143       invalidate();
144       loadProps(PROPERTIES_FILE_NAME);
145       setupWindow();
146
147       setupPersistenceManager(repositories);
148       setupSession();
149       setupContext();
150
151       jbInit();
152       getContentPane().setBackground(SystemColor.desktop);
153
154       rescanTemplateSets();
155       updateTitle();
156       validate();
157       _splitpane.setVisible(false);
158     }
159     catch (Exception JavaDoc e)
160     {
161       handleException(e);
162       System.exit(-1);
163     }
164   }
165
166   public TemplateSetManager getTemplateSetManager()
167   {
168     return _templateSetManager;
169   }
170
171   protected void setupPersistenceManager(String JavaDoc repositories) throws DjenericException, FileNotFoundException JavaDoc
172   {
173     DjPersistenceManagerFactory fact = new DjPersistenceManagerFactory(this, repositories);
174     _mgr = fact.createInstance();
175   }
176
177   protected void setupSession() throws DjenericException
178   {
179     _session = _mgr.createSession();
180     _session.setValidateObjectsAfterLoading(false);
181   }
182
183   protected void setupContext() throws DjenericException
184   {
185     DjUserContextAssociation[] ctxt = _mgr.getCurrentUser().getContextAssociations();
186     if (ctxt.length == 1) _mgr.getContextManager().setCurrentContext(ctxt[0].getContext());
187
188     else
189     // a length of 0 will throw an exception; that's what we want here
190
_mgr.determineContext();
191   }
192
193   public ExtentUsage[] getNavigatorStructure() throws DjenericException
194   {
195     if (_navigatorStructure != null) return _navigatorStructure;
196
197     ModelViewDialog vd = new ModelViewDialog(getContentPane(), _mgr.getCurrentUser());
198     DjModelView selectedView = vd.getView();
199
200     _navigatorStructure = selectedView.getExtentUsages();
201     return _navigatorStructure;
202   }
203
204   protected void setupWindow()
205   {
206     int divloc = Integer.parseInt(getProperty("window.dividerloc", "225"));
207     _splitpane.setDividerLocation(divloc);
208
209     divloc = Integer.parseInt(getProperty("window.structuredividerloc", "225"));
210     _structureSplitter.setDividerLocation(divloc);
211
212     int width = Integer.parseInt(getProperty("window.width", "400"));
213     int height = Integer.parseInt(getProperty("window.height", "400"));
214     setSize(new Dimension JavaDoc(width, height));
215     addKeyListener(this);
216   }
217
218   protected void updateTitle()
219   {
220     try
221     {
222       setTitle("Djeneric TemplateEditor v" + DjVersion.getVersion() + " - " + getManager().getConnectionTitle());
223     }
224     catch (Exception JavaDoc x)
225     {
226       DjLogger.log(x);
227     }
228   }
229
230   /**
231    * Component initialization
232    *
233    * @exception Exception
234    * Description of the Exception
235    */

236   protected void jbInit() throws Exception JavaDoc
237   {
238     _structureTree.putClientProperty("JTree.lineStyle", "Angled");
239     _mnuFile.setMnemonic('F');
240     _mnuFile.setText("File");
241     _mnuExit.setText("Exit");
242     _mnuExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, java.awt.event.KeyEvent.ALT_MASK, false));
243     _mnuExit.addActionListener(new java.awt.event.ActionListener JavaDoc()
244     {
245       public void actionPerformed(ActionEvent JavaDoc e)
246       {
247         _mnuExit_actionPerformed(e);
248       }
249     });
250     _mnuHelp.setMnemonic('H');
251     _mnuHelp.setText("Help");
252     _mnuAbout.setText("About");
253     _mnuAbout.addActionListener(new java.awt.event.ActionListener JavaDoc()
254     {
255       public void actionPerformed(ActionEvent JavaDoc e)
256       {
257         _mnuAbout_actionPerformed(e);
258       }
259     });
260     this.setJMenuBar(_menu);
261     this.setVisible(true);
262     _lblStatus.setText("OK");
263     _lblStatus.setOpaque(true);
264     _desktopPanel.setLayout(borderLayout2);
265     _desktopPanel.setBackground(SystemColor.desktop);
266     _mnuNewSet.setMnemonic('P');
267     _mnuNewSet.setText("New Template Set...");
268     _mnuNewSet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK, false));
269     _mnuOpenSet.setMnemonic('O');
270     _mnuOpenSet.setText("Open Template Set...");
271     _mnuOpenSet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(79, java.awt.event.KeyEvent.CTRL_MASK, false));
272     _mnuOpenSet.addActionListener(new java.awt.event.ActionListener JavaDoc()
273     {
274       public void actionPerformed(ActionEvent JavaDoc e)
275       {
276         _mnuOpenSet_actionPerformed(e);
277       }
278     });
279     _mnuSetProperties.setText("Template Set Properties...");
280     _mnuOptions.setText("Options...");
281     _mnuOptions.addActionListener(new java.awt.event.ActionListener JavaDoc()
282     {
283       public void actionPerformed(ActionEvent JavaDoc e)
284       {
285         _mnuOptions_actionPerformed(e);
286       }
287     });
288     _mnuTools.setMnemonic('T');
289     _mnuTools.setText("Tools");
290     _mnuTabs.setMnemonic('A');
291     _mnuTabs.setText("Tabs");
292     _mnuNextTab.setText("Next");
293     _mnuNextTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(117, java.awt.event.KeyEvent.CTRL_MASK, false));
294     _mnuNextTab.addActionListener(new java.awt.event.ActionListener JavaDoc()
295     {
296       public void actionPerformed(ActionEvent JavaDoc e)
297       {
298         _mnuNextTab_actionPerformed(e);
299       }
300     });
301     _mnuPrevTab.setText("Previous");
302     _mnuPrevTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(117, java.awt.event.KeyEvent.CTRL_MASK, false));
303     _mnuPrevTab.addActionListener(new java.awt.event.ActionListener JavaDoc()
304     {
305       public void actionPerformed(ActionEvent JavaDoc e)
306       {
307         _mnuPrevTab_actionPerformed(e);
308       }
309     });
310     _mnuCloseTab.setText("Close");
311     _mnuCloseTab.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, java.awt.event.KeyEvent.CTRL_MASK, false));
312     _mnuCloseTab.addActionListener(new java.awt.event.ActionListener JavaDoc()
313     {
314       public void actionPerformed(ActionEvent JavaDoc e)
315       {
316         _mnuCloseTab_actionPerformed(e);
317       }
318     });
319     _mnuCloseAll.setText("Close All");
320     _mnuCloseAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(115, java.awt.event.KeyEvent.CTRL_MASK
321                                                                         | java.awt.event.KeyEvent.SHIFT_MASK, false));
322     _mnuCloseAll.addActionListener(new java.awt.event.ActionListener JavaDoc()
323     {
324       public void actionPerformed(ActionEvent JavaDoc e)
325       {
326         _mnuCloseAll_actionPerformed(e);
327       }
328     });
329     _splitpane.setOneTouchExpandable(true);
330     _structureSplitter.setOrientation(JSplitPane.VERTICAL_SPLIT);
331     _templateSetTabs.setOpaque(true);
332     this.getContentPane().add(_splitpane, BorderLayout.CENTER);
333     _splitpane.add(_desktopPanel, JSplitPane.RIGHT);
334     _desktopPanel.add(_tabs, BorderLayout.CENTER);
335     this.getContentPane().add(_lblStatus, BorderLayout.SOUTH);
336     _menu.add(_mnuFile);
337     _menu.add(_mnuTools);
338     _menu.add(_mnuTabs);
339     _menu.add(_mnuHelp);
340     _mnuFile.add(_mnuNewSet);
341     _mnuFile.add(_mnuOpenSet);
342     _mnuFile.addSeparator();
343     _mnuFile.add(_mnuSetProperties);
344     _mnuFile.addSeparator();
345     _mnuFile.add(_mnuExit);
346     _mnuHelp.add(_mnuAbout);
347     _mnuTools.add(_mnuOptions);
348     _mnuTabs.add(_mnuNextTab);
349     _mnuTabs.add(_mnuPrevTab);
350     _mnuTabs.add(_mnuCloseTab);
351     _mnuTabs.add(_mnuCloseAll);
352
353     setTabsVisible(false);
354     _structureSplitter.add(_scrStructure, JSplitPane.BOTTOM);
355     _scrStructure.getViewport().add(_structureTree, null);
356     _structureSplitter.add(_templateSetTabs, JSplitPane.TOP);
357     _splitpane.add(_structureSplitter, JSplitPane.LEFT);
358
359   }
360
361   /**
362    * Overridden so we can exit when window is closed
363    *
364    * @param e
365    * Description of the Parameter
366    */

367   protected void processWindowEvent(WindowEvent JavaDoc e)
368   {
369     if (e.getID() == WindowEvent.WINDOW_CLOSING)
370     {
371       try
372       {
373         if (canExit()) exitProgram();
374       }
375       catch (Exception JavaDoc iox)
376       {
377         setStatusMessage(iox);
378       }
379     }
380     else super.processWindowEvent(e);
381
382   }
383
384   protected boolean canExit() throws Exception JavaDoc
385   {
386     return true;
387   }
388
389   protected void updateProperties()
390   {
391     setProperty("window.width", "" + getWidth());
392     setProperty("window.height", "" + getHeight());
393     setProperty("window.dividerloc", "" + _splitpane.getDividerLocation());
394     setProperty("window.structuredividerloc", "" + _structureSplitter.getDividerLocation());
395   }
396
397   public static ImageIcon JavaDoc getImageIcon(String JavaDoc fileName)
398   {
399     URL JavaDoc url = TemplateEditor.class.getResource("images/" + fileName);
400     if (url != null) return new ImageIcon JavaDoc(url);
401     else return new ImageIcon JavaDoc("");
402     // Default to empty image
403
}
404
405   public static Image JavaDoc getImage(String JavaDoc fileName)
406   {
407     URL JavaDoc url = TemplateEditor.class.getResource("images/" + fileName);
408     if (url != null) return Toolkit.getDefaultToolkit().getImage(url);
409
410     else return Toolkit.getDefaultToolkit().getImage("");
411   }
412
413   public DjPersistenceManager getManager()
414   {
415     return _mgr;
416   }
417
418   public DjSession getSession()
419   {
420     return _session;
421   }
422
423   void _mnuExit_actionPerformed(ActionEvent JavaDoc e)
424   {
425     try
426     {
427       if (canExit()) exitProgram();
428     }
429     catch (Exception JavaDoc x)
430     {
431       setStatusMessage(x);
432     }
433   }
434
435   public void closeTab(Component JavaDoc comp)
436   {
437     _tabs.remove(comp);
438     if (_tabs.getComponentCount() == 0) setTabsVisible(false);
439   }
440
441   public void keyTyped(KeyEvent JavaDoc e)
442   {
443   }
444
445   public void keyPressed(KeyEvent JavaDoc e)
446   {
447     if (_tabs.getComponentCount() == 0) return;
448
449     if ((e.getKeyCode() == KeyEvent.VK_F6) && ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0)
450         && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))
451     {
452       prevTab();
453     }
454     else if ((e.getKeyCode() == KeyEvent.VK_F6) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))
455     {
456       nextTab();
457     }
458     else if ((e.getKeyCode() == KeyEvent.VK_F4) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))
459     {
460       closeTab(_tabs.getSelectedComponent());
461     }
462   }
463
464   protected void prevTab()
465   {
466     int idx = _tabs.getSelectedIndex();
467     if (idx == -1) return;
468     if (idx > 0)
469     {
470       idx--;
471     }
472     else
473     {
474       idx = _tabs.getComponentCount() - 1;
475     }
476     _tabs.setSelectedIndex(idx);
477   }
478
479   protected void nextTab()
480   {
481     int idx = _tabs.getSelectedIndex();
482     if (idx == -1) return;
483     if (idx < _tabs.getComponentCount() - 1)
484     {
485       idx++;
486     }
487     else
488     {
489       idx = 0;
490     }
491     _tabs.setSelectedIndex(idx);
492   }
493
494   public void keyReleased(KeyEvent JavaDoc e)
495   {
496   }
497
498   public void setTabsVisible(boolean visible)
499   {
500     _tabs.setVisible(visible);
501     if (visible)
502     {
503       _desktopPanel.setBackground(new Color JavaDoc(212, 208, 200));
504     }
505     else
506     {
507       _desktopPanel.setBackground(SystemColor.desktop);
508     }
509
510   }
511
512   void _mnuAbout_actionPerformed(ActionEvent JavaDoc e)
513   {
514     new AboutDialog(this);
515   }
516
517   public void addTab(Component JavaDoc comp, String JavaDoc title, boolean setSelected)
518   {
519     _tabs.add(comp, title);
520     if (setSelected) _tabs.setSelectedComponent(comp);
521     setTabsVisible(true);
522   }
523
524   void _mnuOptions_actionPerformed(ActionEvent JavaDoc e)
525   {
526     OptionsDialog od = new OptionsDialog(this, getProperties());
527     if (!od.wasCancelled()) rescanTemplateSets();
528   }
529
530   void _mnuSaveProject_actionPerformed(ActionEvent JavaDoc e)
531   {
532     try
533     {
534
535     }
536     catch (Exception JavaDoc x)
537     {
538       setStatusMessage(x);
539     }
540   }
541
542   void _mnuSaveAs_actionPerformed(ActionEvent JavaDoc e)
543   {
544     try
545     {
546
547     }
548     catch (Exception JavaDoc x)
549     {
550       setStatusMessage(x);
551     }
552
553   }
554
555   protected void rescanTemplateSets()
556   {
557     _templateSetManager.rescanTemplateSets(getProperty(KEY_TEMPLATEPATH, "."));
558   }
559
560   public JTextArea JavaDoc createTextTab(String JavaDoc title, boolean setSelected)
561   {
562     JScrollPane JavaDoc scr = new JScrollPane JavaDoc();
563     JTextArea JavaDoc ta = new JTextArea JavaDoc();
564     ta.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 11));
565     ta.setEditable(false);
566
567     scr.getViewport().add(ta);
568     addTab(scr, title, setSelected);
569     return ta;
570   }
571
572   void _mnuNextTab_actionPerformed(ActionEvent JavaDoc e)
573   {
574     nextTab();
575   }
576
577   void _mnuCloseTab_actionPerformed(ActionEvent JavaDoc e)
578   {
579     closeTab(_tabs.getSelectedComponent());
580   }
581
582   void _mnuPrevTab_actionPerformed(ActionEvent JavaDoc e)
583   {
584     prevTab();
585   }
586
587   void _mnuCloseAll_actionPerformed(ActionEvent JavaDoc e)
588   {
589     while (_tabs.getSelectedComponent() != null)
590       closeTab(_tabs.getSelectedComponent());
591   }
592
593   void _mnuOpenSet_actionPerformed(ActionEvent JavaDoc e)
594   {
595     openTemplateSet();
596   }
597
598   protected void initFileChooser(JFileChooser JavaDoc fc)
599   {
600     fc.setCurrentDirectory(new File JavaDoc(getProperty("filelocation", System.getProperties().getProperty("user.dir"))));
601   }
602
603   protected void recordFileChooserSettings(JFileChooser JavaDoc fc)
604   {
605     setProperty("filelocation", fc.getCurrentDirectory().getAbsolutePath());
606   }
607
608   public void openTemplateSet()
609   {
610     try
611     {
612       JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
613       fc.setDialogTitle("Open Template Set");
614       DjFileFilter filter = new DjFileFilter(new String JavaDoc[]{TemplatePanel.TEMPLATESET_EXTENSION}, "Template Set");
615       fc.setFileFilter(filter);
616       initFileChooser(fc);
617
618       fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
619
620       if (fc.showDialog(this, "Open Template Set") == JFileChooser.APPROVE_OPTION)
621       {
622         recordFileChooserSettings(fc);
623         TemplateSet ts = new TemplateSet(fc.getSelectedFile().getAbsolutePath());
624         TemplatePanel tp = new TemplatePanel(this, ts);
625
626         _templateSetTabs.add(tp, ts.getName());
627         _templateSetTabs.setSelectedComponent(tp);
628         setTemplatesetVisible(true);
629       }
630     }
631     catch (Exception JavaDoc x)
632     {
633       setStatusMessage(x);
634     }
635   }
636
637   protected void setTemplatesetVisible(boolean b)
638   {
639     _splitpane.setVisible(b);
640     invalidate();
641     validate();
642   }
643
644   public static void main(String JavaDoc[] args)
645   {
646     try
647     {
648       DjenericTool.setLookAndFeel();
649
650       if (args.length < 1)
651       {
652         System.out.println("Usage: java " + TemplateEditor.class.getName() + " <repositories.xml>");
653         return;
654       }
655       String JavaDoc banner = TemplateEditor.class.getName() + " version " + DjVersion.getVersion();
656       DjLogPrintStream.logAll(banner, LOG_FILE_NAME);
657
658       System.out.println("Reading " + args[0]);
659       new TemplateEditor(args[0]).startApp();
660     }
661     catch (Exception JavaDoc e)
662     {
663       DjLogger.log(e);
664     }
665   }
666
667 }
Popular Tags