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

Quick Search    Search Deep

Source code: com/robrohan/treebeard/LoadFile.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   * LoadFile.java
20   *
21   * Created on July 22, 2002, 9:46 PM
22   */
23  
24  package com.robrohan.treebeard;
25  /** the load file dialog. used mostly with the xml and xslt panes
26   * @author rob
27   */
28  public class LoadFile extends javax.swing.JDialog implements java.io.Serializable {
29      
30      private String fileURI=null;
31      
32      /** Creates new form LoadFile
33       * @param parent to whom does this dialog belong?
34       * @param modal modal?
35       */
36      public LoadFile(java.awt.Frame parent, boolean modal) {
37          super(parent, modal);
38          initComponents();
39      }
40      
41      /** get the combo box object
42       * @return the file URI
43       */    
44      public javax.swing.JComboBox getComboBox(){
45          return this.txtURI;
46      }
47      
48      /** set the combox box object
49       * @param jcb the combo box object to use
50       */    
51      public void setComboBox(javax.swing.JComboBox jcb){
52          this.txtURI = jcb;
53          this.pack();
54      }
55      
56      /** This method is called from within the constructor to
57       * initialize the form.
58       * WARNING: Do NOT modify this code. The content of this method is
59       * always regenerated by the Form Editor.
60       */
61      private void initComponents() {//GEN-BEGIN:initComponents
62          fileChooser = new javax.swing.JFileChooser();
63          panCenter = new javax.swing.JPanel();
64          jPanel1 = new javax.swing.JPanel();
65          jLabel1 = new javax.swing.JLabel();
66          txtURI = new javax.swing.JComboBox();
67          jButton1 = new javax.swing.JButton();
68          jPanel6 = new javax.swing.JPanel();
69          jCheckBox1 = new javax.swing.JCheckBox();
70          jPanel7 = new javax.swing.JPanel();
71          jButton2 = new javax.swing.JButton();
72          jButton3 = new javax.swing.JButton();
73          jPanel2 = new javax.swing.JPanel();
74          jPanel3 = new javax.swing.JPanel();
75          jPanel4 = new javax.swing.JPanel();
76          jPanel5 = new javax.swing.JPanel();
77  
78          addWindowListener(new java.awt.event.WindowAdapter() {
79              public void windowClosing(java.awt.event.WindowEvent evt) {
80                  closeDialog(evt);
81              }
82          });
83  
84          panCenter.setLayout(new java.awt.GridLayout(3, 1));
85  
86          jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
87  
88          jLabel1.setText("URI:");
89          jPanel1.add(jLabel1);
90  
91          txtURI.setEditable(true);
92          txtURI.setMinimumSize(new java.awt.Dimension(128, 25));
93          txtURI.setPreferredSize(new java.awt.Dimension(250, 25));
94          jPanel1.add(txtURI);
95  
96          jButton1.setText("Browse");
97          jButton1.addActionListener(new java.awt.event.ActionListener() {
98              public void actionPerformed(java.awt.event.ActionEvent evt) {
99                  jButton1ActionPerformed(evt);
100             }
101         });
102 
103         jPanel1.add(jButton1);
104 
105         panCenter.add(jPanel1);
106 
107         jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
108 
109         jCheckBox1.setText("Reference Only Do Not Load (Local Files Only)");
110         jCheckBox1.setToolTipText("(For really large files ~4mb)");
111         jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
112             public void actionPerformed(java.awt.event.ActionEvent evt) {
113                 jCheckBox1ActionPerformed(evt);
114             }
115         });
116 
117         jPanel6.add(jCheckBox1);
118 
119         panCenter.add(jPanel6);
120 
121         jPanel7.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
122 
123         jButton2.setText("Okay");
124         jButton2.addActionListener(new java.awt.event.ActionListener() {
125             public void actionPerformed(java.awt.event.ActionEvent evt) {
126                 jButton2ActionPerformed(evt);
127             }
128         });
129 
130         jPanel7.add(jButton2);
131 
132         jButton3.setText("Cancel");
133         jButton3.addActionListener(new java.awt.event.ActionListener() {
134             public void actionPerformed(java.awt.event.ActionEvent evt) {
135                 jButton3ActionPerformed(evt);
136             }
137         });
138 
139         jPanel7.add(jButton3);
140 
141         panCenter.add(jPanel7);
142 
143         getContentPane().add(panCenter, java.awt.BorderLayout.CENTER);
144 
145         getContentPane().add(jPanel2, java.awt.BorderLayout.NORTH);
146 
147         getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
148 
149         getContentPane().add(jPanel4, java.awt.BorderLayout.EAST);
150 
151         getContentPane().add(jPanel5, java.awt.BorderLayout.WEST);
152 
153         pack();
154     }//GEN-END:initComponents
155 
156     private boolean referenceState=false;
157     private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
158         referenceState = this.jCheckBox1.isSelected();
159     }//GEN-LAST:event_jCheckBox1ActionPerformed
160     /** did they click the reference only check box?
161      * @return true=checked
162      */    
163     public boolean isReference(){
164         return referenceState;
165     }
166     
167     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
168         this.fileURI="";
169         //this.txtURI.setText("");
170         this.txtURI.setSelectedIndex(-1);
171         killWindow();
172     }//GEN-LAST:event_jButton3ActionPerformed
173 
174     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
175         //if the item is not blank add the item to the list
176         boolean already_in_list = false;
177         
178         if(!this.txtURI.getSelectedItem().toString().equals("")){
179            
180             for(int x=0; x<txtURI.getItemCount(); x++){
181                 if(((String)txtURI.getItemAt(x)).equals(txtURI.getSelectedItem().toString())){
182                     already_in_list = true;
183                     break;
184                 }
185             }
186             
187             if(!already_in_list) this.txtURI.addItem(this.txtURI.getSelectedItem().toString());
188         }
189         
190         this.fileURI = this.txtURI.getSelectedItem().toString().trim();
191         killWindow();
192     }//GEN-LAST:event_jButton2ActionPerformed
193 
194     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
195         fileChooser.setName("");
196         fileChooser.setDialogTitle("Load Local File");
197         fileChooser.showOpenDialog(this);
198         
199         if(fileChooser.getSelectedFile() != null && !fileChooser.getSelectedFile().equals("")){
200             //this.txtURI.setText(fileChooser.getSelectedFile().toString());
201             this.txtURI.setSelectedItem(fileChooser.getSelectedFile().toString());
202             //this.txtURI.addItem(fileChooser.getSelectedFile().toString());
203             //this.txtURI.setSelectedItem(fileChooser.getSelectedFile().toString());
204         }
205     }//GEN-LAST:event_jButton1ActionPerformed
206     
207     /** set / add the combo box selected text to
208      * @param to file name to add/set the combo box selection to
209      */    
210     public void setFileName(String to){
211         //this.txtURI.setText(to);
212         if(to != null && !to.equals("")){
213             this.txtURI.addItem(to);
214             this.txtURI.setSelectedItem(to);
215         }
216     }
217     
218     private void killWindow(){
219         setVisible(false);
220         dispose();   
221     }
222     
223     /** get the selected file URI
224      * @return the file URI
225      */    
226     public String getFileURI(){
227         return this.fileURI;
228     }
229     
230     /** Closes the dialog */
231     private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
232         killWindow();
233     }//GEN-LAST:event_closeDialog
234     
235     /**
236      * test
237     public static void main(String args[]) {
238         new LoadFile(new javax.swing.JFrame(), true).show();
239     } */
240     
241     
242     // Variables declaration - do not modify//GEN-BEGIN:variables
243     private javax.swing.JPanel jPanel7;
244     private javax.swing.JPanel jPanel6;
245     private javax.swing.JPanel jPanel5;
246     private javax.swing.JPanel jPanel4;
247     private javax.swing.JPanel jPanel3;
248     private javax.swing.JPanel jPanel2;
249     private javax.swing.JButton jButton3;
250     private javax.swing.JPanel jPanel1;
251     private javax.swing.JButton jButton2;
252     private javax.swing.JButton jButton1;
253     private javax.swing.JCheckBox jCheckBox1;
254     private javax.swing.JFileChooser fileChooser;
255     private javax.swing.JComboBox txtURI;
256     private javax.swing.JPanel panCenter;
257     private javax.swing.JLabel jLabel1;
258     // End of variables declaration//GEN-END:variables
259     
260 }