Source code: com/sunwheeltech/sirius/support/ResourceURLPropertyEditor.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 resource URLs with a popup dialog for browsing filesystem
52 * or text input (e.g. to allow http, ftp urls)
53 *
54 * @author Dave Crane Sunwheel Technologies Ltd April 2003
55 */
56 public class ResourceURLPropertyEditor
57 extends GenericDialogPropertyEditor{
58
59 /** URL of the resource property being edited */
60 URL url=null;
61 /** get the value of the property being edited */
62 public Object getValue(){
63 return url;
64 }
65 /** set the value of the property being edited */
66 public void setValue(Object obj){
67 if (obj instanceof URL){
68 try{ url=new URL(((URL)obj).toString()); }
69 catch (Exception ex){}
70 }else if (obj instanceof ContentSource){
71 url=((ContentSource)obj).getContent();
72 }
73 }
74
75 /** customise the dialog for browsing files etc.
76 */
77 public void makeGUI(){
78 super.makeGUI();
79 View v=new ViewImpl();
80 Shaper sh=new FileShaper();
81 sh.modify(v);
82 setRoot(v);
83 dialog.addPredefinedFilter(FileFilters.JAR_ONLY);
84 dialog.addPredefinedFilter(FileFilters.ZIP_ONLY);
85 //dialog.addPredefinedFilter(FileFilters.JAR_AND_ZIP_ONLY); problems!!
86 //dialog.addPredefinedFilter(FileFilters.FILES_ONLY); problems!!
87 dialog.addPredefinedFilter(FileFilters.FOLDERS_ONLY);
88 //dialog.addPredefinedFilter(FileFilters.ALL_FILES); not needed
89 }
90
91
92 /** retrieve valid text representation of current value of the field. By default, returns the toString()
93 of the current view's referred object, or "null" if empty
94 @return display string indicating current value of the field
95 */
96 public String getAsText(){
97 String ret="null";
98 try{
99 ret=url.toString();
100 }catch (Exception ex){}
101 return ret;
102 }
103
104 /**
105 set the value of the property from the text input - try to create a url from the text. (It only checks for
106 well-formedness of the URL, doesn't try to connect to it)
107 @param str the string to set the data from
108 @return parsed object
109 */
110 public Object parseTextInput(String str){
111 Object ret=null;
112 try{
113 URL u=new URL(str);
114 ret=u;
115 }catch (MalformedURLException ex){
116 }
117 return ret;
118 }
119
120 /** no-op implementation of a method that parses
121 the Item returned by the dialog
122 @param obj object to be validated
123 @return parsed object (may be null)
124 */
125 public Object parseDialogResult(Object obj){
126 Object ret=null;
127 if (obj instanceof ContentSource){
128 ret=((ContentSource)obj).getContent();
129 }
130 return ret;
131 }
132
133 /** match dialog value to text input, as the text has just been altered. See
134 if the url is file or zip or jar-class protocol, and try to set the dialog
135 to point to that item's parent folder
136 */
137 protected void syncDialogToText(){
138 }
139
140
141 /** get the code that will initialise the value
142 @return java code snippet
143 */
144 public String getJavaInitializationString(){
145 return (url==null) ? "null" : "new java.net.URL("+url.toString()+")";
146 }
147
148 }