Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/robrohan/fangorn/TreeViewer.java


1   /*
2    * Treebeard: an xml xslt transfomer
3    * Copyright (C) 2002 Rob Rohan
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the
6    * Free Software Foundation; either version 2 of the License, or (at your
7    * option) any later version.
8    * 
9    * This program is distributed in the hope that it will be useful, but 
10   * WITHOUT ANY WARRANTY; without even the implied warranty of 
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
12   * General Public License for more details.
13   * 
14   * You should have received a copy of the GNU General Public License along 
15   * with this program; if not, write to the Free Software Foundation, Inc.,
16   * 675 Mass Ave, Cambridge, MA 02139, USA.
17   *
18   * Email: me@robrohan.com
19   * TreeViewer.java
20   *
21   * Created on September 2, 2002, 4:31 PM
22   */
23  
24  package com.robrohan.fangorn;
25  
26  /**
27   * This is currently (1/10/2003) used to display templates, but it should be
28   * generic enough to do other tree displays as well. It is dependent on 
29   * com.robrohan.treebeard.TreeView
30   * @author  rob
31   */
32  public class TreeViewer extends javax.swing.JInternalFrame {
33      private com.robrohan.treebeard.TreeView tv;
34      private javax.swing.ImageIcon load_icon;
35      
36      /** Creates new form TreeViewer
37       * @param title the title of the ent (titlebar)
38       * @param resizable should it be resizable?
39       * @param closeable should it be closeable?
40       * @param maximizable should it be maximizable?
41       * @param iconifiable should it be iconifiable?
42       */
43      public TreeViewer(String title, boolean resizable, boolean closeable, boolean maximizable, boolean iconifiable) {
44          super(title,resizable, closeable, maximizable, iconifiable);
45          initComponents();
46          
47          load_icon = new javax.swing.ImageIcon(
48              getClass().getResource("/com/robrohan/treebeard/images/diskget_sm.gif")
49          );
50          
51          tv = new com.robrohan.treebeard.TreeView();
52          
53          this.jToolBar1.add(new loadFileAction());
54          askForFile();
55      }
56     
57      /** is this an ent?
58       * @return should be false
59       */    
60      public boolean isEnt(){
61          return false;
62          
63      }
64      
65      class loadFileAction extends javax.swing.AbstractAction{
66          public loadFileAction(){
67              super("Open File",load_icon);
68          }
69          public void actionPerformed(java.awt.event.ActionEvent e) {
70              askForFile();
71          }
72      }
73      
74      /**
75       * show the open dialog
76       */
77      private void askForFile(){
78          TreeChooser.showOpenDialog(this);
79          java.io.File file = TreeChooser.getSelectedFile();
80          if(file != null){
81              loadFile(file);
82          }
83      }
84      
85      /**
86       * load a file
87       */
88      private void loadFile(java.io.File file){      
89          try{
90              tv.rootNodeString = file.getName();
91              
92              tv.setType(com.robrohan.treebeard.TreeView.TEMPLATE);
93              
94              panCenter.removeAll();
95              
96              this.panCenter.add(
97                 new javax.swing.JScrollPane(tv.treeData(file))
98              );
99              pack();
100            
101         }catch(Exception e){
102             System.err.println("TreeViewer: " + e);
103             e.printStackTrace(System.err);
104         }
105         
106         this.repaint();
107     }
108     
109     
110     /** This method is called from within the constructor to
111      * initialize the form.
112      * WARNING: Do NOT modify this code. The content of this method is
113      * always regenerated by the Form Editor.
114      */
115     private void initComponents() {//GEN-BEGIN:initComponents
116         TreeChooser = new javax.swing.JFileChooser();
117         jPanel2 = new javax.swing.JPanel();
118         jPanel3 = new javax.swing.JPanel();
119         jPanel4 = new javax.swing.JPanel();
120         panCenter = new javax.swing.JPanel();
121         panTop = new javax.swing.JPanel();
122         jToolBar1 = new javax.swing.JToolBar();
123 
124         getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
125 
126         getContentPane().add(jPanel3, java.awt.BorderLayout.EAST);
127 
128         getContentPane().add(jPanel4, java.awt.BorderLayout.WEST);
129 
130         panCenter.setLayout(new java.awt.BorderLayout());
131 
132         getContentPane().add(panCenter, java.awt.BorderLayout.CENTER);
133 
134         panTop.setLayout(new java.awt.BorderLayout());
135 
136         panTop.add(jToolBar1, java.awt.BorderLayout.CENTER);
137 
138         getContentPane().add(panTop, java.awt.BorderLayout.NORTH);
139 
140         pack();
141     }//GEN-END:initComponents
142     
143     
144     // Variables declaration - do not modify//GEN-BEGIN:variables
145     private javax.swing.JPanel jPanel4;
146     private javax.swing.JPanel jPanel3;
147     private javax.swing.JPanel panTop;
148     private javax.swing.JPanel jPanel2;
149     private javax.swing.JFileChooser TreeChooser;
150     private javax.swing.JToolBar jToolBar1;
151     private javax.swing.JPanel panCenter;
152     // End of variables declaration//GEN-END:variables
153     
154 }