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

Quick Search    Search Deep

Source code: com/sunwheeltech/sirius/support/FilePropertyEditor.java


1   package com.sunwheeltech.sirius.support;
2   /* GPL
3   ulunum java libraries for complex simulation modelling, 
4   3d graphics, peer-to-peer networking and other purposes
5   
6   version 0.1 released December 2001
7   see the file contents.html for a quick description of whats in
8   each package, and what you can expect to do with it
9   
10  Copyright (C) December 2001 Dave Crane  dave@cranepeople.co.uk
11  
12  
13  Find the GNU public license at:
14  
15    http://www.gnu.org/copyleft/gpl.html
16   
17  This program is free software; you can redistribute it and/or
18  modify it under the terms of the GNU General Public License
19  as published by the Free Software Foundation; either version 2
20  of the License, or (at your option) any later version. 
21  
22  This program is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  GNU General Public License for more details. 
26  
27  You should have received a copy of the GNU General Public License
28  along with this program; if not, write to the Free Software
29  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
30  */
31  
32  
33  import ulu.view.*;
34  import ulu.view.io.*;
35  import ulu.view.ui.*;
36  import ulu.view.sys.fs.*;
37  import ulu.view.sys.refl.*;
38  import ulu.view.ui.sirius.*;
39  
40  import ulu.ut.*;
41  import dog.gui.*;
42  import java.awt.*;
43  import java.awt.image.*;
44  import java.awt.event.*;
45  import java.beans.*;
46  import java.io.*;
47  import java.net.*;
48  import java.util.*;
49  
50  /**
51   * <p>Property editor for File objects with a popup dialog for browsing filesystem
52   * or text input, to allow files not present on the debvelopment system
53   *
54   * @author Dave Crane  Sunwheel Technologies Ltd  April 2003
55   */
56  public class FilePropertyEditor
57  extends GenericDialogPropertyEditor{
58  
59    /** file property being edited */
60    File file=null;
61    /** get the value of the property being edited */
62    public Object getValue(){ 
63      return file; 
64    }
65    /** set the value of the property being edited */
66    public void setValue(Object obj){
67      if (obj instanceof File){
68        try{ file=new File(((File)obj).toString()); }
69        catch (Exception ex){}
70      }else if (obj instanceof Referrer){
71        try{
72          Referrer ref=((Referrer)obj);
73          file=(File)(ref.getReference());
74        }catch (Exception ex){}
75      }
76    }
77    
78    /** customise the dialog for browsing files etc.
79    */
80    public void makeGUI(){
81      super.makeGUI();
82      View v=new ViewImpl();
83      Shaper sh=new FileShaper();
84      sh.modify(v);
85      setRoot(v);
86      dialog.addPredefinedFilter(FileFilters.FOLDERS_ONLY);
87    }
88    
89    
90    /** retrieve valid text representation of current value of the field. By default, returns the toString() 
91    of the current view's referred object, or "null" if empty
92    @return display string indicating current value of the field
93    */
94    public String getAsText(){
95      String ret="null";
96      try{
97        ret=file.toString();
98      }catch (Exception ex){}
99      return ret;
100   }
101   
102   /**
103   set the value of the property from the text input - try to create a url from the text. (It only checks for
104   well-formedness of the URL, doesn't try to connect to it)
105   @param str the string to set the data from
106   @return parsed object
107   */
108   public Object parseTextInput(String str){
109     Object ret=null;
110     try{
111       File f=new File(str);
112       ret=f;
113     }catch (Exception ex){
114     }
115     return ret;
116   }
117 
118   /** implementation of a method that parses
119   the Item returned by the dialog
120   @param obj object to be validated
121   @return parsed object (may be null)
122   */
123   public Object parseDialogResult(Object obj){ 
124     Object ret=null;
125     if (obj instanceof Referrer){
126       ret=((Referrer)obj).getReference();
127     }
128     return ret;
129   }
130 
131   /** match dialog value to text input, as the text has just been altered. See
132   if the url is file or zip or jar-class protocol, and try to  set the dialog
133   to point to that item's parent folder
134   */
135   protected void syncDialogToText(){
136   }
137     
138    
139   /** get the code that will initialise the value 
140   @return java code snippet
141   */
142   public String getJavaInitializationString(){
143     return (file==null) ? "null" : "new java.io.File("+file.toString()+")";
144   }
145   
146 }