Revision 1548
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/test/java/README.txt | ||
---|---|---|
1 |
#set( $symbol_pound = '#' ) |
|
2 |
#set( $symbol_dollar = '$' ) |
|
3 |
#set( $symbol_escape = '\' ) |
|
4 |
For each class you are going to test, create one Test class with the same |
|
5 |
name as the class to test, ending with Test. |
|
6 |
|
|
7 |
For example, the unit tests of the "ExampleLibrary" class are performed |
|
8 |
by the "ExampleLibraryTest" class. |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/test/resources/README.txt | ||
---|---|---|
1 |
#set( $symbol_pound = '#' ) |
|
2 |
#set( $symbol_dollar = '$' ) |
|
3 |
#set( $symbol_escape = '\' ) |
|
4 |
Put into this folder the resources needed by your test classes. |
|
5 |
|
|
6 |
This folder is added to the Tests classpath, so you can load any resources |
|
7 |
through the ClassLoader. |
|
8 |
|
|
9 |
By default, in this folder you can find an example of log4j configuration, |
|
10 |
prepared to log messages through the console, so logging works when you |
|
11 |
run your tests classes. |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
DefaultExampleManager class. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.scripting.impl.DefaultExampleManager"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
|
|
26 |
<!-- |
|
27 |
By default, show only logging messages of INFO level or higher, |
|
28 |
through the previously configured CONSOLE appender. |
|
29 |
--> |
|
30 |
<root> |
|
31 |
<priority value="INFO" /> |
|
32 |
<appender-ref ref="CONSOLE" /> |
|
33 |
</root> |
|
34 |
</log4j:configuration> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/utils/AWTUtils.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package utils; |
|
5 |
|
|
6 |
|
|
7 |
import java.awt.AWTKeyStroke; |
|
8 |
import java.awt.Color; |
|
9 |
import java.awt.Component; |
|
10 |
import java.awt.Dimension; |
|
11 |
import java.awt.Font; |
|
12 |
import java.awt.Frame; |
|
13 |
import java.awt.Graphics2D; |
|
14 |
import java.awt.Image; |
|
15 |
import java.awt.MediaTracker; |
|
16 |
import java.awt.event.InputEvent; |
|
17 |
import java.awt.event.KeyEvent; |
|
18 |
import java.awt.font.FontRenderContext; |
|
19 |
import java.awt.font.TextLayout; |
|
20 |
import java.awt.geom.Rectangle2D; |
|
21 |
import java.lang.reflect.Field; |
|
22 |
import java.lang.reflect.Modifier; |
|
23 |
import java.net.URL; |
|
24 |
import java.util.HashMap; |
|
25 |
import java.util.StringTokenizer; |
|
26 |
import java.util.logging.Level; |
|
27 |
import java.util.logging.Logger; |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* Misc helper methods for AWT that don't require Thinlet. |
|
32 |
* |
|
33 |
* @author Dirk Moebius |
|
34 |
*/ |
|
35 |
public class AWTUtils |
|
36 |
{ |
|
37 |
|
|
38 |
//{{{ logging |
|
39 |
private static final Logger log = Logger.getLogger("thinletcommons"); |
|
40 |
private static final boolean debug() { return log.isLoggable(Level.FINE); } |
|
41 |
//}}} |
|
42 |
|
|
43 |
|
|
44 |
private static HashMap keyDescriptions = new HashMap(); |
|
45 |
|
|
46 |
|
|
47 |
static |
|
48 |
{ |
|
49 |
// initialize HashMap keyDescriptions |
|
50 |
Field[] fields = KeyEvent.class.getDeclaredFields(); |
|
51 |
for(int i = 0; i < fields.length; ++i) |
|
52 |
{ |
|
53 |
Field field = fields[i]; |
|
54 |
int modifiers = field.getModifiers(); |
|
55 |
if(((modifiers & (Modifier.STATIC | Modifier.PUBLIC)) != 0) |
|
56 |
&& field.getName().startsWith("VK_")) |
|
57 |
{ |
|
58 |
try |
|
59 |
{ |
|
60 |
int keyCode = field.getInt(null); |
|
61 |
String keyDescription = field.getName().substring(3); |
|
62 |
keyDescriptions.put(new Integer(keyCode), keyDescription); |
|
63 |
} |
|
64 |
catch(IllegalAccessException e) |
|
65 |
{ |
|
66 |
log.log(Level.SEVERE, "can't get value of field " + field, e); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
public static String getColorString(Color c) |
|
74 |
{ |
|
75 |
int red = c.getRed(); |
|
76 |
int green = c.getGreen(); |
|
77 |
int blue = c.getBlue(); |
|
78 |
StringBuffer s = new StringBuffer("#"); |
|
79 |
if(red < 10) s.append("0"); |
|
80 |
s.append(Integer.toHexString(red)); |
|
81 |
if(green < 10) s.append("0"); |
|
82 |
s.append(Integer.toHexString(green)); |
|
83 |
if(blue < 10) s.append("0"); |
|
84 |
s.append(Integer.toHexString(blue)); |
|
85 |
return s.toString(); |
|
86 |
} |
|
87 |
|
|
88 |
|
|
89 |
/** |
|
90 |
* Returns a thinlet font description for the given font. |
|
91 |
* |
|
92 |
* @param font the font |
|
93 |
* @return a thinlet font description such as "Serif 10 bold italic" |
|
94 |
*/ |
|
95 |
public static String getFontString(Font font) |
|
96 |
{ |
|
97 |
StringBuffer s = new StringBuffer(); |
|
98 |
s.append(font.getFamily()); |
|
99 |
s.append(" "); |
|
100 |
s.append(font.getSize()); |
|
101 |
if(font.isItalic()) |
|
102 |
s.append(" italic"); |
|
103 |
if(font.isBold()) |
|
104 |
s.append(" bold"); |
|
105 |
return s.toString(); |
|
106 |
} |
|
107 |
|
|
108 |
|
|
109 |
/** |
|
110 |
* Returns a thinlet font description for the given font, containing only |
|
111 |
* the font properties that <i>differ</i> from the given default font. |
|
112 |
* |
|
113 |
* @param font the font |
|
114 |
* @param defaultFont the default font |
|
115 |
* @return a thinlet font description such as "serif 10 bold italic" |
|
116 |
*/ |
|
117 |
public static String getFontString(Font font, Font defaultFont) |
|
118 |
{ |
|
119 |
StringBuffer s = new StringBuffer(); |
|
120 |
if(!font.getFamily().equals(defaultFont.getFamily())) |
|
121 |
s.append(font.getFamily()); |
|
122 |
if(font.getSize() != defaultFont.getSize()) |
|
123 |
{ |
|
124 |
if(s.length() > 0) s.append(' '); |
|
125 |
s.append(font.getSize()); |
|
126 |
} |
|
127 |
if(font.isItalic() != defaultFont.isItalic()) |
|
128 |
{ |
|
129 |
if(s.length() > 0) s.append(' '); |
|
130 |
s.append("italic"); |
|
131 |
} |
|
132 |
if(font.isBold() != defaultFont.isBold()) |
|
133 |
{ |
|
134 |
if(s.length() > 0) s.append(' '); |
|
135 |
s.append("bold"); |
|
136 |
} |
|
137 |
return s.toString(); |
|
138 |
} |
|
139 |
|
|
140 |
|
|
141 |
/** |
|
142 |
* Get the frame that the specified component resides in, or null if |
|
143 |
* the component has no ancestor of type <code>Frame</code>. |
|
144 |
*/ |
|
145 |
public static Frame getFrame(Component comp) |
|
146 |
{ |
|
147 |
while(comp != null && !(Frame.class.isInstance(comp))) |
|
148 |
comp = comp.getParent(); |
|
149 |
return (Frame)comp; |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
/** |
|
154 |
* Returns the dimension of the specified text string, if it would be |
|
155 |
* rendered with the font and the rendering context of the specified |
|
156 |
* component. |
|
157 |
*/ |
|
158 |
public static Dimension getBounds(String text, Component component) |
|
159 |
{ |
|
160 |
Graphics2D graphics = (Graphics2D)component.getGraphics(); |
|
161 |
StringTokenizer st = new StringTokenizer(text, "\n", true); |
|
162 |
Dimension dim = new Dimension(0, 0); |
|
163 |
while(st.hasMoreTokens()) |
|
164 |
{ |
|
165 |
String token = st.nextToken(); |
|
166 |
if(token.equals("\n")) |
|
167 |
token = "W"; |
|
168 |
TextLayout textLayout = new TextLayout(token, component.getFont(), |
|
169 |
(graphics != null) ? graphics.getFontRenderContext() |
|
170 |
: new FontRenderContext(null, true, false)); |
|
171 |
Rectangle2D rect = textLayout.getBounds(); |
|
172 |
dim.height += (int)rect.getHeight(); |
|
173 |
dim.width = Math.max(dim.width, (int)rect.getWidth()); |
|
174 |
} |
|
175 |
return dim; |
|
176 |
} |
|
177 |
|
|
178 |
|
|
179 |
/** |
|
180 |
* Load an icon. Use a MediaTracker synchronizing on the specified |
|
181 |
* component to wait for the icon to load. |
|
182 |
* |
|
183 |
* @param component the component that the MediaTracker uses to control |
|
184 |
* the loading of the icon. |
|
185 |
* @param path the path relative to the package path of the class of |
|
186 |
* the component, e.g. "icons/icon.gif". |
|
187 |
*/ |
|
188 |
public static Image getIcon(Component component, String path) |
|
189 |
{ |
|
190 |
URL url = component.getClass().getResource(path); |
|
191 |
return getIcon(component, url); |
|
192 |
} |
|
193 |
|
|
194 |
|
|
195 |
/** |
|
196 |
* Load an icon. Use a MediaTracker synchronizing on the specified |
|
197 |
* component to wait for the icon to load. |
|
198 |
* |
|
199 |
* @param component the component that the MediaTracker uses to control |
|
200 |
* the loading of the icon. |
|
201 |
* @param url the URL of the icon. |
|
202 |
*/ |
|
203 |
public static Image getIcon(Component component, URL url) |
|
204 |
{ |
|
205 |
if(debug()) log.fine("loading icon url=" + url + "..."); |
|
206 |
|
|
207 |
Image icon = component.getToolkit().getImage(url); |
|
208 |
|
|
209 |
MediaTracker mediatracker = new MediaTracker(component); |
|
210 |
mediatracker.addImage(icon, 1); |
|
211 |
try |
|
212 |
{ |
|
213 |
mediatracker.waitForID(1); |
|
214 |
} |
|
215 |
catch(InterruptedException e) |
|
216 |
{ |
|
217 |
log.warning("loading of icon " + url + " has been interrupted!"); |
|
218 |
} |
|
219 |
|
|
220 |
return icon; |
|
221 |
} |
|
222 |
|
|
223 |
|
|
224 |
/** |
|
225 |
* Given an AWTKeyStroke, returns a keystroke description that can be |
|
226 |
* parsed by <code>AWTKeyStroke.getAWTKeyStroke(String s)</code>. |
|
227 |
* <p> |
|
228 |
* Examples: "ctrl O", "alt shift F4", "altGraph Q" |
|
229 |
*/ |
|
230 |
public static String getAWTKeyStrokeDescription(AWTKeyStroke k) |
|
231 |
{ |
|
232 |
StringBuffer buf = new StringBuffer(); |
|
233 |
|
|
234 |
int mod = k.getModifiers(); |
|
235 |
if((mod & InputEvent.ALT_DOWN_MASK) != 0 || (mod & InputEvent.ALT_MASK) != 0) |
|
236 |
buf.append("alt "); |
|
237 |
if((mod & InputEvent.ALT_GRAPH_DOWN_MASK) != 0 || (mod & InputEvent.ALT_GRAPH_MASK) != 0) |
|
238 |
buf.append("altGraph "); |
|
239 |
if((mod & InputEvent.META_DOWN_MASK) != 0 || (mod & InputEvent.META_MASK) != 0) |
|
240 |
buf.append("meta "); |
|
241 |
if((mod & InputEvent.CTRL_DOWN_MASK) != 0 || (mod & InputEvent.CTRL_MASK) != 0) |
|
242 |
buf.append("ctrl "); |
|
243 |
if((mod & InputEvent.SHIFT_DOWN_MASK) != 0 || (mod & InputEvent.SHIFT_MASK) != 0) |
|
244 |
buf.append("shift "); |
|
245 |
|
|
246 |
buf.append(getKeyText(k.getKeyCode())); |
|
247 |
|
|
248 |
return buf.toString(); |
|
249 |
} |
|
250 |
|
|
251 |
|
|
252 |
/** |
|
253 |
* Return the key description for a key code, according to the key names |
|
254 |
* in <code>java.awt.event.KeyEvent</code>, omitting the prefix "VK_". |
|
255 |
* For example the strings returned may be "A" - "Z", "F1" - "F24" "RIGHT", |
|
256 |
* "BACK_SPACE", "DEAD_TILDE" and so on. |
|
257 |
*/ |
|
258 |
public static String getKeyText(int keyCode) |
|
259 |
{ |
|
260 |
String desc = (String) keyDescriptions.get(new Integer(keyCode)); |
|
261 |
if(desc == null) |
|
262 |
{ |
|
263 |
log.warning("KeyEvent field for keyCode " + keyCode + " not found!" |
|
264 |
+ " Returning default description."); |
|
265 |
return KeyEvent.getKeyText(keyCode); |
|
266 |
} |
|
267 |
else |
|
268 |
return desc; |
|
269 |
} |
|
270 |
|
|
271 |
} |
|
272 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/utils/ReaderInputStream.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package utils; |
|
5 |
|
|
6 |
|
|
7 |
import java.io.IOException; |
|
8 |
import java.io.InputStream; |
|
9 |
import java.io.Reader; |
|
10 |
|
|
11 |
|
|
12 |
/** |
|
13 |
* This class is the opposite of <code>java.io.InputStreamReader</code>: it |
|
14 |
* provides a bridge from (new) character streams (<i>Reader</i>) to (old) |
|
15 |
* byte streams (<i>InputStream</i>). It reads characters and converts them |
|
16 |
* into bytes. |
|
17 |
* |
|
18 |
* @author Dirk Moebius |
|
19 |
*/ |
|
20 |
public class ReaderInputStream extends InputStream |
|
21 |
{ |
|
22 |
|
|
23 |
protected Reader reader; |
|
24 |
|
|
25 |
|
|
26 |
public ReaderInputStream(Reader reader) |
|
27 |
{ |
|
28 |
this.reader = reader; |
|
29 |
} |
|
30 |
|
|
31 |
|
|
32 |
public int available() throws IOException |
|
33 |
{ |
|
34 |
return reader.ready() ? 1 : 0; |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
public void close() throws IOException |
|
39 |
{ |
|
40 |
reader.close(); |
|
41 |
} |
|
42 |
|
|
43 |
|
|
44 |
public void mark(int readAheadLimit) |
|
45 |
{ |
|
46 |
try { reader.mark(readAheadLimit); } catch(IOException ignore) {} |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
public boolean markSupported() |
|
51 |
{ |
|
52 |
return reader.markSupported(); |
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
public int read() throws IOException |
|
57 |
{ |
|
58 |
return reader.read(); |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
public void reset() throws IOException |
|
63 |
{ |
|
64 |
reader.reset(); |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
public long skip(long n) throws IOException |
|
69 |
{ |
|
70 |
return reader.skip(n); |
|
71 |
} |
|
72 |
|
|
73 |
} |
|
74 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/utils/package.html | ||
---|---|---|
1 |
<body> |
|
2 |
<p> |
|
3 |
This package contains some common utilities not dependent on Thinlet. |
|
4 |
</p> |
|
5 |
</body> |
|
6 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/MessageDialog.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package thinletcommons; |
|
5 |
|
|
6 |
|
|
7 |
import java.awt.BorderLayout; |
|
8 |
import java.awt.Dialog; |
|
9 |
import java.awt.Dimension; |
|
10 |
import java.awt.EventQueue; |
|
11 |
import java.awt.Frame; |
|
12 |
import java.awt.Image; |
|
13 |
import java.util.logging.Level; |
|
14 |
import java.util.logging.Logger; |
|
15 |
|
|
16 |
import thinlet.Thinlet; |
|
17 |
|
|
18 |
import utils.AWTUtils; |
|
19 |
|
|
20 |
|
|
21 |
/** |
|
22 |
* A Thinlet message dialog with configurable OK/CANCEL/YES/NO-Buttons. |
|
23 |
* |
|
24 |
* <p> |
|
25 |
* The dialog is modal and blocks the calling frame/dialog. It is therefore |
|
26 |
* displayed in a separate window. |
|
27 |
* |
|
28 |
* <p> |
|
29 |
* <b>TODO:</b> |
|
30 |
* <ul> |
|
31 |
* <li>make message type configurable (ERROR/WARN/INFO)</li> |
|
32 |
* </ul> |
|
33 |
* |
|
34 |
* @author Dirk Moebius |
|
35 |
*/ |
|
36 |
public class MessageDialog |
|
37 |
{ |
|
38 |
//{{{ logging |
|
39 |
private static final Logger log = Logger.getLogger("thinletcommons"); |
|
40 |
private static final boolean debug() { return log.isLoggable(Level.FINE); } |
|
41 |
//}}} |
|
42 |
|
|
43 |
|
|
44 |
public static final int MODE_OK = 0; |
|
45 |
public static final int MODE_OK_CANCEL = 1; |
|
46 |
public static final int MODE_YES_NO = 2; |
|
47 |
public static final int MODE_YES_NO_CANCEL = 3; |
|
48 |
|
|
49 |
public static final int ACTION_OK = 0; |
|
50 |
public static final int ACTION_CANCEL = 1; |
|
51 |
public static final int ACTION_YES = 2; |
|
52 |
public static final int ACTION_NO = 3; |
|
53 |
|
|
54 |
|
|
55 |
private Thinlet thinlet; |
|
56 |
private ThinletDialog dialog; |
|
57 |
private String msg; |
|
58 |
private Image icon; |
|
59 |
private int mode; |
|
60 |
private int returnValue; |
|
61 |
|
|
62 |
|
|
63 |
/** |
|
64 |
* Show a simple message dialog with an "Ok" button. |
|
65 |
*/ |
|
66 |
public MessageDialog(Dialog owner, String title, String msg) |
|
67 |
{ |
|
68 |
this.dialog = new ThinletDialog(owner, title); |
|
69 |
init(msg, null, MODE_OK); |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
/** |
|
74 |
* Show a simple message dialog with an "Ok" button and a custom icon. |
|
75 |
*/ |
|
76 |
public MessageDialog(Dialog owner, String title, Image icon, String msg) |
|
77 |
{ |
|
78 |
this.dialog = new ThinletDialog(owner, title); |
|
79 |
init(msg, icon, MODE_OK); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
/** |
|
84 |
* Show a simple message dialog with an "Ok" button. |
|
85 |
*/ |
|
86 |
public MessageDialog(Frame owner, String title, String msg) |
|
87 |
{ |
|
88 |
this.dialog = new ThinletDialog(owner, title); |
|
89 |
init(msg, null, MODE_OK); |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
/** |
|
94 |
* Show a simple message dialog with an "Ok" button and a custom icon. |
|
95 |
*/ |
|
96 |
public MessageDialog(Frame owner, String title, Image icon, String msg) |
|
97 |
{ |
|
98 |
this.dialog = new ThinletDialog(owner, title); |
|
99 |
init(msg, icon, MODE_OK); |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
public MessageDialog(Dialog owner, String title, String msg, int mode) |
|
104 |
{ |
|
105 |
this.dialog = new ThinletDialog(owner, title); |
|
106 |
init(msg, null, mode); |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
public MessageDialog(Dialog owner, String title, Image icon, String msg, int mode) |
|
111 |
{ |
|
112 |
this.dialog = new ThinletDialog(owner, title); |
|
113 |
init(msg, icon, mode); |
|
114 |
} |
|
115 |
|
|
116 |
|
|
117 |
public MessageDialog(Frame owner, String title, String msg, int mode) |
|
118 |
{ |
|
119 |
this.dialog = new ThinletDialog(owner, title); |
|
120 |
init(msg, null, mode); |
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
public MessageDialog(Frame owner, String title, Image icon, String msg, int mode) |
|
125 |
{ |
|
126 |
this.dialog = new ThinletDialog(owner, title); |
|
127 |
init(msg, icon, mode); |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
private void init(String msg, Image icon, int mode) |
|
132 |
{ |
|
133 |
this.thinlet = new AntiAliasedThinlet(); |
|
134 |
this.msg = msg; |
|
135 |
this.mode = mode; |
|
136 |
this.icon = icon; |
|
137 |
|
|
138 |
try |
|
139 |
{ |
|
140 |
Object panel = thinlet.parse("/thinletcommons/messagedialog.xml", this); |
|
141 |
thinlet.add(panel); |
|
142 |
} |
|
143 |
catch(Exception e) |
|
144 |
{ |
|
145 |
log.log(Level.SEVERE, "Error parsing messagedialog.xml", e); |
|
146 |
} |
|
147 |
|
|
148 |
this.dialog.setContent(thinlet); |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
/** |
|
153 |
* Show the modal message dialog. |
|
154 |
* This halts the application until the user dismisses the dialog. |
|
155 |
* |
|
156 |
* @return the action selected by user; one of {@link #ACTION_OK}, |
|
157 |
* {@link #ACTION_CANCEL}, {@link #ACTION_YES} or {@link #ACTION_NO}. |
|
158 |
*/ |
|
159 |
public int show() |
|
160 |
{ |
|
161 |
try |
|
162 |
{ |
|
163 |
Dimension dim = AWTUtils.getBounds(msg, dialog); |
|
164 |
if(debug()) log.fine("msg width=" + dim.getWidth() + " height=" + dim.getHeight()); |
|
165 |
Object message = thinlet.find("message"); |
|
166 |
thinlet.setInteger(message, "width", (int)dim.getWidth() + 30); |
|
167 |
thinlet.setInteger(message, "height", (int)dim.getHeight() + 30); |
|
168 |
} |
|
169 |
catch(Exception e) |
|
170 |
{ |
|
171 |
log.log(Level.SEVERE, "Exception getting bounds", e); |
|
172 |
} |
|
173 |
|
|
174 |
returnValue = ACTION_CANCEL; |
|
175 |
|
|
176 |
dialog.pack(); |
|
177 |
dialog.setLocationRelativeTo(dialog.getOwner()); |
|
178 |
dialog.setVisible(true); |
|
179 |
|
|
180 |
return returnValue; |
|
181 |
} |
|
182 |
|
|
183 |
|
|
184 |
//{{{ callback methods for messagedialog.xml |
|
185 |
/** Thinlet callback. */ |
|
186 |
public void init(Object iconLabel, Object textarea, Object button1, Object button2, Object button3) |
|
187 |
{ |
|
188 |
thinlet.setString(textarea, "text", this.msg); |
|
189 |
|
|
190 |
if(this.icon != null) |
|
191 |
thinlet.setIcon(iconLabel, "icon", this.icon); |
|
192 |
|
|
193 |
final Object defaultButton; |
|
194 |
|
|
195 |
switch(this.mode) |
|
196 |
{ |
|
197 |
case MODE_OK: |
|
198 |
hideButton(button1); |
|
199 |
hideButton(button2); |
|
200 |
showButton(button3, "cancel", "Ok", 0, "ok.gif", ACTION_OK); |
|
201 |
defaultButton = button3; |
|
202 |
break; |
|
203 |
case MODE_OK_CANCEL: |
|
204 |
hideButton(button1); |
|
205 |
showButton(button2, "default", "Ok", 0, "ok.gif", ACTION_OK); |
|
206 |
showButton(button3, "cancel", "Cancel", 0, "cancel.gif", ACTION_CANCEL); |
|
207 |
defaultButton = button3; |
|
208 |
break; |
|
209 |
case MODE_YES_NO: |
|
210 |
hideButton(button1); |
|
211 |
showButton(button2, "normal", "Yes", 0, "ok.gif", ACTION_YES); |
|
212 |
showButton(button3, "normal", "No", 0, "cancel.gif", ACTION_NO); |
|
213 |
defaultButton = button3; |
|
214 |
break; |
|
215 |
case MODE_YES_NO_CANCEL: |
|
216 |
showButton(button1, "normal", "Yes", 0, "ok.gif", ACTION_YES); |
|
217 |
showButton(button2, "normal", "No", 0, "cancel.gif", ACTION_NO); |
|
218 |
showButton(button3, "cancel", "Cancel", 0, null, ACTION_CANCEL); |
|
219 |
defaultButton = button3; |
|
220 |
break; |
|
221 |
default: |
|
222 |
throw new IllegalArgumentException("illegal message dialog mode: " + this.mode); |
|
223 |
} |
|
224 |
|
|
225 |
EventQueue.invokeLater(new Runnable() |
|
226 |
{ |
|
227 |
public void run() |
|
228 |
{ |
|
229 |
thinlet.requestFocus(defaultButton); |
|
230 |
} |
|
231 |
}); |
|
232 |
} |
|
233 |
|
|
234 |
|
|
235 |
/** Thinlet callback. */ |
|
236 |
public void buttonPressed(Object button) |
|
237 |
{ |
|
238 |
returnValue = Integer.parseInt((String)thinlet.getProperty(button, "action")); |
|
239 |
dialog.setVisible(false); |
|
240 |
} |
|
241 |
//}}} |
|
242 |
|
|
243 |
|
|
244 |
private void hideButton(Object button) |
|
245 |
{ |
|
246 |
thinlet.setBoolean(button, "visible", false); |
|
247 |
thinlet.setChoice(button, "type", "normal"); |
|
248 |
} |
|
249 |
|
|
250 |
|
|
251 |
private void showButton(Object button, String type, String text, int mnemonic, String icon, int action) |
|
252 |
{ |
|
253 |
thinlet.setChoice(button, "type", type); |
|
254 |
thinlet.setString(button, "text", text); |
|
255 |
thinlet.setInteger(button, "mnemonic", mnemonic); |
|
256 |
if(icon != null) |
|
257 |
thinlet.setIcon(button, "icon", AWTUtils.getIcon(dialog, "/thinletcommons/icons/" + icon)); |
|
258 |
thinlet.putProperty(button, "action", Integer.toString(action)); |
|
259 |
} |
|
260 |
|
|
261 |
} |
|
262 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/AntiAliasedThinlet.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package thinletcommons; |
|
5 |
|
|
6 |
|
|
7 |
import java.awt.Graphics; |
|
8 |
import java.awt.Graphics2D; |
|
9 |
import java.awt.RenderingHints; |
|
10 |
|
|
11 |
|
|
12 |
/** |
|
13 |
* A <code>Thinlet</code> component that is painted with anti-aliased fonts |
|
14 |
* and lines. |
|
15 |
* |
|
16 |
* @author Dirk Moebius |
|
17 |
*/ |
|
18 |
public class AntiAliasedThinlet extends LoggingThinlet |
|
19 |
{ |
|
20 |
|
|
21 |
public AntiAliasedThinlet() |
|
22 |
{ |
|
23 |
super(); |
|
24 |
} |
|
25 |
|
|
26 |
|
|
27 |
public void paint(Graphics g) |
|
28 |
{ |
|
29 |
((Graphics2D) g).setRenderingHint( |
|
30 |
RenderingHints.KEY_ANTIALIASING, |
|
31 |
RenderingHints.VALUE_ANTIALIAS_ON); |
|
32 |
((Graphics2D) g).setRenderingHint( |
|
33 |
RenderingHints.KEY_TEXT_ANTIALIASING, |
|
34 |
RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
|
35 |
super.paint(g); |
|
36 |
} |
|
37 |
|
|
38 |
} |
|
39 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/fontchooser.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<!-- jEdit settings: :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: --> |
|
3 |
|
|
4 |
<panel bottom="12" columns="3" gap="10" left="12" right="12" top="12" weightx="1" weighty="1" init="init(fontlist)"> |
|
5 |
<label colspan="3" for="fontlist" text="Font:" mnemonic="0" valign="bottom"/> |
|
6 |
<list action="fontChanged(this, fontsize, cb_bold, cb_italic, preview, b_ok)" line="false" name="fontlist" rowspan="3" weightx="4" weighty="4"/> |
|
7 |
<label for="fontsize" text="Size:" mnemonic="0" /> |
|
8 |
<spinbox action="fontChanged(fontlist, this, cb_bold, cb_italic, preview, b_ok)" maximum="200" minimum="0" name="fontsize" perform="fontChanged(fontlist, this, cb_bold, cb_italic, preview, b_ok)" text="12" weightx="0"/> |
|
9 |
<panel/> |
|
10 |
<checkbox action="fontChanged(fontlist, fontsize, this, cb_italic, preview, b_ok)" mnemonic="0" name="cb_bold" text="Bold"/> |
|
11 |
<panel/> |
|
12 |
<checkbox action="fontChanged(fontlist, fontsize, cb_bold, this, preview, b_ok)" mnemonic="0" name="cb_italic" text="Italic" valign="top"/> |
|
13 |
<panel border="true" bottom="5" colspan="3" left="3" right="3" text="Preview" top="5" weightx="1" weighty="1"> |
|
14 |
<textarea border="false" editable="false" end="35" height="30" name="preview" start="35" text="The quick brown fox jumps over the lazy dog." weightx="1" weighty="1" width="100" wrap="true"/> |
|
15 |
</panel> |
|
16 |
<panel colspan="3" gap="10" halign="right" weightx="1"> |
|
17 |
<button action="ok(fontlist, fontsize, cb_bold, cb_italic)" icon="/thinletcommons/icons/ok.gif" enabled="false" mnemonic="0" name="b_ok" text="Ok" type="default"/> |
|
18 |
<button action="close()" icon="/thinletcommons/icons/cancel.gif" mnemonic="0" name="b_cancel" text="Cancel" type="cancel"/> |
|
19 |
</panel> |
|
20 |
</panel> |
|
21 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/package.html | ||
---|---|---|
1 |
<body> |
|
2 |
<p> |
|
3 |
This package contains some common gui widgets such as a directory chooser, |
|
4 |
a font chooser, a generic message dialog box etc. |
|
5 |
</p> |
|
6 |
|
|
7 |
<p> |
|
8 |
All widgets are Thinlet widgets. |
|
9 |
</p> |
|
10 |
|
|
11 |
<p> |
|
12 |
Note that the <code>thinletcommons</code> package does not depend on the |
|
13 |
<code>thing</code> package, so these widgets could be used in other |
|
14 |
applications. |
|
15 |
</p> |
|
16 |
</body> |
|
17 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/LoggingThinlet.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package thinletcommons; |
|
5 |
|
|
6 |
|
|
7 |
import java.util.logging.Level; |
|
8 |
import java.util.logging.Logger; |
|
9 |
|
|
10 |
import thinlet.Thinlet; |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* A <code>Thinlet</code> component that logs exceptions to the JDK logging |
|
15 |
* facility. |
|
16 |
* |
|
17 |
* @author Dirk Moebius |
|
18 |
*/ |
|
19 |
public class LoggingThinlet extends Thinlet |
|
20 |
{ |
|
21 |
|
|
22 |
//{{{ logging |
|
23 |
private static final Logger log = Logger.getLogger("thinletcommons"); |
|
24 |
private static final boolean debug() { return log.isLoggable(Level.FINE); } |
|
25 |
//}}} |
|
26 |
|
|
27 |
|
|
28 |
public LoggingThinlet() |
|
29 |
{ |
|
30 |
super(); |
|
31 |
} |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* Log exceptions to a logger named "thinletcommons" with log level SEVERE. |
|
36 |
* |
|
37 |
* @param throwable the thrown exception by the bussiness logic |
|
38 |
*/ |
|
39 |
protected void handleException(Throwable throwable) |
|
40 |
{ |
|
41 |
log.log(Level.SEVERE, "Exception in business logic", throwable); |
|
42 |
//throw new RuntimeException("Exception in business logic", throwable); |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
} |
|
47 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/colorchooser.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<!-- jEdit settings: :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: --> |
|
3 |
|
|
4 |
<panel columns="3" top="10" left="10" right="10" bottom="10" gap="4" init="init(sl_red, sl_green, sl_blue, sb_red, sb_green, sb_blue, tf_hue, tf_saturation, tf_brightness, pb_hue, pb_saturation, pb_brightness, rgb_label)"> |
|
5 |
<label text="Red, green, and blue values" colspan="3" /> |
|
6 |
|
|
7 |
<label text="Red:" alignment="right" for="sb_red" mnemonic="0" /> |
|
8 |
<slider name="sl_red" minimum="0" maximum="255" valign="center" action="sliderChanged(this.value, sb_red)" /> |
|
9 |
<spinbox name="sb_red" minimum="0" maximum="255" text="0" columns="3" action="spinboxChanged(this.text, sl_red)" /> |
|
10 |
|
|
11 |
<label text="Green:" alignment="right" for="sb_green" mnemonic="0" /> |
|
12 |
<slider name="sl_green" minimum="0" maximum="255" valign="center" action="sliderChanged(this.value, sb_green)" /> |
|
13 |
<spinbox name="sb_green" minimum="0" maximum="255" text="0" columns="3" action="spinboxChanged(this.text, sl_green)" /> |
|
14 |
|
|
15 |
<label text="Blue:" alignment="right" for="sb_blue" mnemonic="0" /> |
|
16 |
<slider name="sl_blue" minimum="0" maximum="255" valign="center" action="sliderChanged(this.value, sb_blue)" /> |
|
17 |
<spinbox name="sb_blue" minimum="0" maximum="255" text="0" columns="3" action="spinboxChanged(this.text, sl_blue)" /> |
|
18 |
|
|
19 |
<separator colspan="3" /> |
|
20 |
|
|
21 |
<label text="Hue, saturation, and brightness values" colspan="3" /> |
|
22 |
|
|
23 |
<label text="Hue:" alignment="right" /> |
|
24 |
<textfield name="tf_hue" text="0.0" editable="false" /> |
|
25 |
<progressbar name="pb_hue" valign="center" /> |
|
26 |
|
|
27 |
<label text="Saturation:" alignment="right" /> |
|
28 |
<textfield name="tf_saturation" text="0.0" editable="false" /> |
|
29 |
<progressbar name="pb_saturation" valign="center" /> |
|
30 |
|
|
31 |
<label text="Brightness:" alignment="right" /> |
|
32 |
<textfield name="tf_brightness" text="0.0" editable="false" /> |
|
33 |
<progressbar name="pb_brightness" valign="center" /> |
|
34 |
|
|
35 |
<separator colspan="3"/> |
|
36 |
|
|
37 |
<label colspan="3" name="rgb_label" valign="fill" weighty="1" background="#000000" text="ThinG!" font="40 bold italic" alignment="center"/> |
|
38 |
|
|
39 |
<panel colspan="3" gap="10" halign="right" top="12" weightx="1"> |
|
40 |
<button action="ok()" icon="/thinletcommons/icons/ok.gif" mnemonic="0" name="b_ok" text="Ok" type="default"/> |
|
41 |
<button action="close()" icon="/thinletcommons/icons/cancel.gif" mnemonic="0" name="b_cancel" text="Cancel" type="cancel"/> |
|
42 |
</panel> |
|
43 |
|
|
44 |
</panel> |
|
45 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/dirchooser.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<!-- jEdit settings: :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: --> |
|
3 |
|
|
4 |
<panel |
|
5 |
columns="1" |
|
6 |
gap="6" |
|
7 |
top="6" |
|
8 |
left="6" |
|
9 |
right="6" |
|
10 |
bottom="6" |
|
11 |
width="300" |
|
12 |
height="400" |
|
13 |
init="init(tree)" |
|
14 |
> |
|
15 |
<tree |
|
16 |
name="tree" |
|
17 |
angle="true" |
|
18 |
line="false" |
|
19 |
weightx="1" |
|
20 |
weighty="1" |
|
21 |
perform="ok(this)" |
|
22 |
expand="nodeExpanded(this, item)" |
|
23 |
/> |
|
24 |
<panel gap="6" top="12" weightx="1"> |
|
25 |
<panel weightx="1"/> |
|
26 |
<button name="ok" text="Ok" icon="/thinletcommons/icons/ok.gif" mnemonic="0" type="default" action="ok(tree)"/> |
|
27 |
<button name="cancel" text="Cancel" icon="/thinletcommons/icons/cancel.gif" mnemonic="0" type="cancel" action="close()"/> |
|
28 |
</panel> |
|
29 |
</panel> |
|
30 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/filechooser.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<!-- jEdit settings: :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: --> |
|
3 |
|
|
4 |
<panel bottom="12" columns="1" gap="12" left="12" right="12" top="12" weightx="1" weighty="1"> |
|
5 |
<panel gap="6" weightx="1"> |
|
6 |
<label for="cbPath" mnemonic="0" text="Look In:"/> |
|
7 |
<combobox action="cbPathChanged()" editable="false" name="cbPath" weightx="1"/> |
|
8 |
<button action="goUp()" icon="/thinletcommons/icons/up.gif" name="bUp" tooltip="Go to parent directory"/> |
|
9 |
<button action="goHome()" icon="/thinletcommons/icons/home.gif" name="bHome" tooltip="Go to home directory"/> |
|
10 |
<togglebutton action="toggleShowHiddenFiles(this.selected)" icon="/thinletcommons/icons/hidden_files.gif" name="bShowHidden" tooltip="Toggle display of hidden files."/> |
|
11 |
</panel> |
|
12 |
|
|
13 |
<table action="tableRowSelected()" height="300" line="false" name="tbFilelist" perform="tableRowDoubleClicked()" weightx="1" weighty="1" width="420"> |
|
14 |
<header action="tableHeaderChanged(colName, colType, colSize, colMod)"> |
|
15 |
<column name="colName" sort="ascent" text="Name" width="170"/> |
|
16 |
<column name="colType" text="Type" width="140"/> |
|
17 |
<column name="colSize" text="Size" width="80"/> |
|
18 |
<column name="colMod" text="Last Modified" width="120"/> |
|
19 |
</header> |
|
20 |
</table> |
|
21 |
|
|
22 |
<panel columns="4" gap="6"> |
|
23 |
<label for="tFilename" mnemonic="0" text="File name:"/> |
|
24 |
<textfield name="tFilename" perform="ok()" weightx="1"/> |
|
25 |
|
|
26 |
<!-- some free space between filename field and ok/cancel buttons --> |
|
27 |
<panel left="12" rowspan="2"/> |
|
28 |
|
|
29 |
<button action="ok()" icon="/thinletcommons/icons/ok.gif" mnemonic="0" name="bOk" text="Ok" type="default"/> |
|
30 |
<label for="cbFilter" halign="right" mnemonic="1" text="Filter:"/> |
|
31 |
<combobox action="cbFilterChanged(this.selected)" editable="false" name="cbFilter" weightx="1"/> |
|
32 |
<button action="close()" icon="/thinletcommons/icons/cancel.gif" mnemonic="0" name="bCancel" text="Cancel" type="cancel"/> |
|
33 |
</panel> |
|
34 |
</panel> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/ExtensionFileFilter.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package thinletcommons; |
|
5 |
|
|
6 |
|
|
7 |
import java.io.File; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* A file filter for {@link FileChooser} that accepts files based on file |
|
12 |
* name endings (<i>extensions</i>). |
|
13 |
* |
|
14 |
* <p> |
|
15 |
* Note that the file filter is case sensitive. That is a file filter instance |
|
16 |
* created with <code>new ExtensionFileFilter("xml", "XML files")</code> |
|
17 |
* accepts <code>file.xml</code> but not <code>FILE.XML</code>. |
|
18 |
* |
|
19 |
* @author Dirk Moebius |
|
20 |
*/ |
|
21 |
public class ExtensionFileFilter implements FileFilter |
|
22 |
{ |
|
23 |
|
|
24 |
private String extension; |
|
25 |
private String description; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* Create a new ExceptionFileFilter. |
|
30 |
* |
|
31 |
* @param extension the extention, for example "xml", "jpg", etc. |
|
32 |
* @param description the description. |
|
33 |
*/ |
|
34 |
public ExtensionFileFilter(String extension, String description) |
|
35 |
{ |
|
36 |
this.extension = "." + extension; |
|
37 |
this.description = description; |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
/** |
|
42 |
* Whether the given file is accepted by this filter. |
|
43 |
*/ |
|
44 |
public boolean accept(File file) |
|
45 |
{ |
|
46 |
return file.getName().endsWith(extension); |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
/** |
|
51 |
* A human readable description of this file filter. |
|
52 |
*/ |
|
53 |
public String getDescription() |
|
54 |
{ |
|
55 |
return description; |
|
56 |
} |
|
57 |
|
|
58 |
} |
|
59 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/messagedialog.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<!-- jEdit settings: :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: --> |
|
3 |
|
|
4 |
<panel |
|
5 |
columns="2" |
|
6 |
gap="12" top="12" left="12" right="12" bottom="12" |
|
7 |
init="init(iconLabel, message, button1, button2, button3)" |
|
8 |
> |
|
9 |
<label |
|
10 |
name="iconLabel" |
|
11 |
icon="/thinletcommons/icons/inform.gif" |
|
12 |
valign="top" |
|
13 |
rowspan="2" |
|
14 |
/> |
|
15 |
<textarea |
|
16 |
name="message" |
|
17 |
editable="false" |
|
18 |
border="false" |
|
19 |
wrap="true" |
|
20 |
weightx="1" |
|
21 |
weighty="1" |
|
22 |
/> |
|
23 |
<panel gap="12" halign="right"> |
|
24 |
<button name="button1" text="..." action="buttonPressed(this)"/> |
|
25 |
<button name="button2" text="..." action="buttonPressed(this)"/> |
|
26 |
<button name="button3" text="..." action="buttonPressed(this)"/> |
|
27 |
</panel> |
|
28 |
</panel> |
|
29 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/FileFilter.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package thinletcommons; |
|
5 |
|
|
6 |
|
|
7 |
import java.io.File; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* A file filter for {@link FileChooser}. |
|
12 |
* |
|
13 |
* @author Dirk Moebius |
|
14 |
*/ |
|
15 |
public interface FileFilter |
|
16 |
{ |
|
17 |
/** |
|
18 |
* Whether the given file is accepted by this filter. |
|
19 |
*/ |
|
20 |
public boolean accept(File file); |
|
21 |
|
|
22 |
/** |
|
23 |
* A human readable description of this file filter. |
|
24 |
*/ |
|
25 |
public String getDescription(); |
|
26 |
} |
|
27 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/ThinletDialog.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package thinletcommons; |
|
5 |
|
|
6 |
|
|
7 |
import java.awt.BorderLayout; |
|
8 |
import java.awt.Component; |
|
9 |
import java.awt.Dialog; |
|
10 |
import java.awt.Dimension; |
|
11 |
import java.awt.Frame; |
|
12 |
import java.awt.Graphics; |
|
13 |
import java.awt.Image; |
|
14 |
import java.awt.event.WindowAdapter; |
|
15 |
import java.awt.event.WindowEvent; |
|
16 |
import java.util.logging.Level; |
|
17 |
import java.util.logging.Logger; |
|
18 |
|
|
19 |
import thinlet.Thinlet; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* <code>ThinletDialog</code> is a <i>modal</i> double buffered dialog |
|
24 |
* containing a <i>thinlet</i> component. |
|
25 |
* |
|
26 |
* @author Dirk Moebius |
|
27 |
*/ |
|
28 |
public class ThinletDialog extends Dialog |
|
29 |
{ |
|
30 |
//{{{ logging |
|
31 |
private static final Logger log = Logger.getLogger("thinletcommons"); |
|
32 |
private static final boolean debug() { return log.isLoggable(Level.FINE); } |
|
33 |
//}}} |
|
34 |
|
|
35 |
|
|
36 |
private transient Thinlet content; |
|
37 |
private transient Image doublebuffer; |
|
38 |
|
|
39 |
|
|
40 |
public ThinletDialog(Frame owner) |
|
41 |
{ |
|
42 |
super(owner, true); |
|
43 |
addWindowListener(new WindowHandler()); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
public ThinletDialog(Frame owner, String title) |
|
48 |
{ |
|
49 |
super(owner, title, true); |
|
50 |
addWindowListener(new WindowHandler()); |
|
51 |
} |
|
52 |
|
|
53 |
|
|
54 |
public ThinletDialog(Dialog owner) |
|
55 |
{ |
|
56 |
super(owner); |
|
57 |
setModal(true); |
|
58 |
addWindowListener(new WindowHandler()); |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
public ThinletDialog(Dialog owner, String title) |
|
63 |
{ |
|
64 |
super(owner, title, true); |
|
65 |
addWindowListener(new WindowHandler()); |
|
66 |
} |
|
67 |
|
|
68 |
|
|
69 |
public void setContent(Thinlet content) |
|
70 |
{ |
|
71 |
this.content = content; |
|
72 |
removeAll(); |
|
73 |
setLayout(new BorderLayout()); |
|
74 |
_addImpl(content, BorderLayout.CENTER); |
|
75 |
pack(); |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
public Thinlet getContent() |
|
80 |
{ |
|
81 |
return content; |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
/** |
|
86 |
* Call the paint method to redraw this component without painting a |
|
87 |
* background rectangle. |
|
88 |
*/ |
|
89 |
public void update(Graphics g) |
|
90 |
{ |
|
91 |
paint(g); |
|
92 |
} |
|
93 |
|
|
94 |
|
|
95 |
/** |
|
96 |
* Create a double buffer if needed, the <i>thinlet</i> component paints |
|
97 |
* the content. |
|
98 |
*/ |
|
99 |
public void paint(Graphics g) |
|
100 |
{ |
|
101 |
if(doublebuffer == null) |
|
102 |
{ |
|
103 |
Dimension d = getSize(); |
|
104 |
doublebuffer = createImage(d.width, d.height); |
|
105 |
} |
|
106 |
Graphics dg = doublebuffer.getGraphics(); |
|
107 |
dg.setClip(g.getClipBounds()); |
|
108 |
super.paint(dg); |
|
109 |
dg.dispose(); |
|
110 |
g.drawImage(doublebuffer, 0, 0, this); |
|
111 |
} |
|
112 |
|
|
113 |
|
|
114 |
/** |
|
115 |
* Clear the double buffer image (because the frame has been resized), the |
|
116 |
* overriden method lays out its components (centers the <i>thinlet</i> |
|
117 |
* component). |
|
118 |
*/ |
|
119 |
public void doLayout() |
|
120 |
{ |
|
121 |
if(doublebuffer != null) |
|
122 |
{ |
|
123 |
doublebuffer.flush(); |
|
124 |
doublebuffer = null; |
|
125 |
} |
|
126 |
super.doLayout(); |
|
127 |
} |
|
128 |
|
|
129 |
|
|
130 |
/** |
|
131 |
* Redirects all calls to <code>add(...)</code> to |
|
132 |
* {@link #setContent(Thinlet)}. |
|
133 |
*/ |
|
134 |
protected void addImpl(Component comp, Object constraints, int index) |
|
135 |
{ |
|
136 |
setContent((Thinlet)comp); |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
private void _addImpl(Component comp, String constraints) |
|
141 |
{ |
|
142 |
super.addImpl(comp, constraints, -1); |
|
143 |
} |
|
144 |
|
|
145 |
|
|
146 |
private class WindowHandler extends WindowAdapter |
|
147 |
{ |
|
148 |
public void windowClosing(WindowEvent e) |
|
149 |
{ |
|
150 |
// dialog stays visible if the thinlet returns 'false' in destroy(), |
|
151 |
// otherwise it is closed and control is returned to calling frame. |
|
152 |
setVisible(content != null && !content.destroy()); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
} |
|
157 |
|
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/thing.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<!-- jEdit settings: :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: --> |
|
3 |
|
|
4 |
<panel columns="1" gap="4"> |
|
5 |
|
|
6 |
<menubar weightx="1"> |
|
7 |
<menu text="File" mnemonic="0"> |
|
8 |
<menuitem text="New" mnemonic="0" icon="icons/empty_menu.gif" accelerator="ctrl N" action="menu_file_new()"/> |
|
9 |
<menuitem text="Open..." mnemonic="0" icon="icons/empty_menu.gif" accelerator="ctrl O" action="menu_file_open()"/> |
|
10 |
<separator/> |
|
11 |
<menuitem text="Reload" mnemonic="0" icon="icons/empty_menu.gif" accelerator="ctrl R" action="menu_file_reload()"/> |
|
12 |
<separator/> |
|
13 |
<menuitem text="Save" mnemonic="0" icon="icons/empty_menu.gif" accelerator="ctrl S" action="menu_file_save()"/> |
|
14 |
<menuitem text="Save As..." mnemonic="5" icon="icons/empty_menu.gif" action="menu_file_save_as()"/> |
|
15 |
<separator/> |
|
16 |
<menuitem text="Exit" mnemonic="0" icon="icons/empty_menu.gif" accelerator="alt F4" action="menu_file_exit()"/> |
|
17 |
</menu> |
|
18 |
<menu text="Edit" mnemonic="0"> |
|
19 |
<menuitem text="Cut" name="menu_edit_cut" mnemonic="0" accelerator="ctrl X" icon="icons/edit_cut.gif" action="menu_edit_cut()"/> |
|
20 |
<menuitem text="Copy" name="menu_edit_copy" mnemonic="1" accelerator="ctrl C" icon="icons/edit_copy.gif" action="menu_edit_copy()"/> |
|
21 |
<menuitem text="Paste" name="menu_edit_paste" mnemonic="0" accelerator="ctrl V" icon="icons/edit_paste.gif" action="menu_edit_paste()"/> |
|
22 |
<menuitem text="Paste from system clipboard" name="menu_edit_paste_systemcb" mnemonic="1" accelerator="ctrl shift V" icon="icons/empty_menu.gif" action="menu_edit_paste_systemcb()"/> |
|
23 |
<menuitem text="Delete" name="menu_edit_delete" mnemonic="0" icon="icons/edit_delete.gif" action="menu_edit_delete()"/> |
|
24 |
<separator/> |
|
25 |
<menuitem text="Settings..." mnemonic="0" icon="icons/empty_menu.gif" action="menu_edit_settings()"/> |
|
26 |
</menu> |
|
27 |
<menu text="Tools" mnemonic="0"> |
|
28 |
<menuitem text="Generate Handler Stub Source..." name="menu_tools_generate" mnemonic="0" accelerator="ctrl G" icon="icons/empty_menu.gif" action="menu_tools_generate()"/> |
|
29 |
</menu> |
|
30 |
<menu text="Help" mnemonic="0"> |
|
31 |
<menuitem text="About Thing..." mnemonic="0" icon="icons/thing_small.gif" action="menu_help_about()"/> |
|
32 |
</menu> |
|
33 |
</menubar> |
|
34 |
|
|
35 |
<panel name="toolbar" weightx="1" gap="-1"> |
|
36 |
|
|
37 |
<!-- top level components --> |
|
38 |
<button name="tb_add_panel" property="classname=panel" icon="icons/panel.gif" tooltip="Create new panel" action="addComponent(this)"/> |
|
39 |
<button name="tb_add_dialog" property="classname=dialog" icon="icons/dialog.gif" tooltip="Create new dialog" action="addComponent(this)"/> |
|
40 |
<button name="tb_add_desktop" property="classname=desktop" icon="icons/desktop.gif" tooltip="Create new desktop" action="addComponent(this)"/> |
|
41 |
<button name="tb_add_splitpane" property="classname=splitpane" icon="icons/splitpane.gif" tooltip="Create new splitpane" action="addComponent(this)"/> |
|
42 |
<button name="tb_add_tabbedpane" property="classname=tabbedpane" icon="icons/tabbedpane.gif" tooltip="Create new tabbedpane" action="addComponent(this)"/> |
|
43 |
|
|
44 |
<!-- menu components --> |
|
45 |
<button name="tb_add_menubar" property="classname=menubar" icon="icons/menubar.gif" tooltip="Create new menubar" action="addComponent(this)"/> |
|
46 |
<button name="tb_add_menu" property="classname=menu" icon="icons/menu.gif" tooltip="Create new menu" action="addComponent(this)"/> |
|
47 |
<button name="tb_add_menuitem" property="classname=menuitem" icon="icons/menuitem.gif" tooltip="Create new menuitem" action="addComponent(this)"/> |
|
48 |
<button name="tb_add_checkboxmenuitem" property="classname=checkboxmenuitem" icon="icons/checkboxmenuitem.gif" tooltip="Create new checkboxmenuitem" action="addComponent(this)"/> |
|
49 |
|
|
50 |
<!-- components --> |
|
51 |
<button name="tb_add_label" property="classname=label" icon="icons/label.gif" tooltip="Create new label" action="addComponent(this)"/> |
|
52 |
<button name="tb_add_button" property="classname=button" icon="icons/button.gif" tooltip="Create new button" action="addComponent(this)"/> |
|
53 |
<button name="tb_add_togglebutton" property="classname=togglebutton" icon="icons/togglebutton.gif" tooltip="Create new togglebutton" action="addComponent(this)"/> |
|
54 |
<button name="tb_add_checkbox" property="classname=checkbox" icon="icons/checkbox.gif" tooltip="Create new checkbox" action="addComponent(this)"/> |
|
55 |
<button name="tb_add_textfield" property="classname=textfield" icon="icons/textfield.gif" tooltip="Create new textfield" action="addComponent(this)"/> |
|
56 |
<button name="tb_add_combobox" property="classname=combobox" icon="icons/combobox.gif" tooltip="Create new combobox" action="addComponent(this)"/> |
|
57 |
<button name="tb_add_passwordfield" property="classname=passwordfield" icon="icons/passwordfield.gif" tooltip="Create new passwordfield" action="addComponent(this)"/> |
|
58 |
<button name="tb_add_spinbox" property="classname=spinbox" icon="icons/spinbox.gif" tooltip="Create new spinbox" action="addComponent(this)"/> |
|
59 |
<button name="tb_add_progressbar" property="classname=progressbar" icon="icons/progressbar.gif" tooltip="Create new progressbar" action="addComponent(this)"/> |
|
60 |
<button name="tb_add_slider" property="classname=slider" icon="icons/slider.gif" tooltip="Create new slider" action="addComponent(this)"/> |
|
61 |
<button name="tb_add_separator" property="classname=separator" icon="icons/separator.gif" tooltip="Create new separator" action="addComponent(this)"/> |
|
62 |
<button name="tb_add_list" property="classname=list" icon="icons/list.gif" tooltip="Create new list" action="addComponent(this)"/> |
|
63 |
<button name="tb_add_table" property="classname=table" icon="icons/table.gif" tooltip="Create new table" action="addComponent(this)"/> |
|
64 |
<button name="tb_add_textarea" property="classname=textarea" icon="icons/textarea.gif" tooltip="Create new textarea" action="addComponent(this)"/> |
|
65 |
<button name="tb_add_tree" property="classname=tree" icon="icons/tree.gif" tooltip="Create new tree" action="addComponent(this)"/> |
|
66 |
|
|
67 |
<!-- list items --> |
|
68 |
<button name="tb_add_choice" property="classname=choice" icon="icons/choice.gif" tooltip="Create new choice" action="addComponent(this)"/> |
|
69 |
<button name="tb_add_item" property="classname=item" icon="icons/item.gif" tooltip="Create new item" action="addComponent(this)"/> |
|
70 |
<button name="tb_add_node" property="classname=node" icon="icons/node.gif" tooltip="Create new node" action="addComponent(this)"/> |
|
71 |
<button name="tb_add_tab" property="classname=tab" icon="icons/tab.gif" tooltip="Create new tab" action="addComponent(this)"/> |
|
72 |
|
|
73 |
<!-- table components --> |
|
74 |
<button name="tb_add_row" property="classname=row" icon="icons/row.gif" tooltip="Create new row" action="addComponent(this)"/> |
|
75 |
<button name="tb_add_cell" property="classname=cell" icon="icons/cell.gif" tooltip="Create new cell" action="addComponent(this)"/> |
|
76 |
<button name="tb_add_header" property="classname=header" icon="icons/header.gif" tooltip="Create new header" action="addComponent(this)"/> |
|
77 |
<button name="tb_add_column" property="classname=column" icon="icons/column.gif" tooltip="Create new column" action="addComponent(this)"/> |
|
78 |
|
|
79 |
<!-- other --> |
|
80 |
<button name="tb_add_popupmenu" property="classname=popupmenu" icon="icons/popupmenu.gif" tooltip="Create new popupmenu" action="addComponent(this)"/> |
|
81 |
|
|
82 |
<!-- later --> |
|
83 |
<!-- |
|
84 |
<button name="tb_add_bean" property="classname=bean" icon="icons/bean.gif" tooltip="Create new bean" action="addComponent(this)" enabled="false"/> |
|
85 |
--> |
|
86 |
|
|
87 |
<!-- placeholder in case there are no buttons add all --> |
|
88 |
<separator height="30" width="1"/> |
|
89 |
</panel> |
|
90 |
|
|
91 |
<!-- main workarea --> |
|
92 |
<panel left="4" right="4" weightx="1" weighty="1"> |
|
93 |
<splitpane orientation="horizontal" divider="200" weightx="1" weighty="1"> |
|
94 |
|
|
95 |
<!-- left splitpane: component tree and properties table --> |
|
96 |
<splitpane orientation="vertical"> |
|
97 |
<panel columns="1" weightx="1" weighty="1"> |
|
98 |
<tree name="tree" angle="true" line="false" selection="single" weightx="1" weighty="1" action="treeSelectionChanged()"/> |
|
99 |
<panel top="3" bottom="3" gap="2" scrollable="true"> |
|
100 |
<button name="tb_edit_copy" icon="icons/edit_copy.gif" tooltip="Copy selected component to internal ThinG clipboard and system clipboard" action="menu_edit_copy()"/> |
|
101 |
<button name="tb_edit_cut" icon="icons/edit_cut.gif" tooltip="Cut selected component to internal ThinG clipboard and system clipboard" action="menu_edit_cut()"/> |
|
102 |
<button name="tb_edit_paste" icon="icons/edit_paste.gif" tooltip="Paste component from internal ThinG clipboard below selected component" action="menu_edit_paste()"/> |
|
103 |
<button name="tb_edit_delete" icon="icons/edit_delete.gif" tooltip="Remove selected component" action="menu_edit_delete()"/> |
|
104 |
<separator/> |
|
105 |
<button name="tb_edit_moveup" icon="icons/edit_moveup.gif" tooltip="Move selected component up" action="moveComponentUp()"/> |
|
106 |
<button name="tb_edit_movedown" icon="icons/edit_movedown.gif" tooltip="Move selected component down" action="moveComponentDown()"/> |
|
107 |
</panel> |
|
108 |
</panel> |
|
109 |
<panel columns="1" gap="5"> |
|
110 |
<table name="props" selection="single" weightx="1" weighty="1" action="tableSelectionChanged()"> |
|
111 |
<header> |
|
112 |
<column name="props_key" text="Property" width="80" sort="ascent"/> |
|
113 |
<column name="props_value" text="Value"/> |
|
114 |
</header> |
|
115 |
</table> |
|
116 |
<panel name="propedit" columns="3" gap="5" weightx="1" border="true" top="5" left="5" bottom="5" right="5"> |
|
117 |
<label name="propedit_name" text=""/> |
|
118 |
<panel name="propedit_panel" gap="5" weightx="1"/> |
|
119 |
<button name="propedit_reset" text="Reset" tooltip="Reset to default value" font="10" valign="center" enabled="false" action="propEditReset()"/> |
|
120 |
</panel> |
|
121 |
</panel> |
|
122 |
</splitpane> |
|
123 |
|
|
124 |
<!-- right splitpane: preview panel --> |
|
125 |
<tabbedpane name="tabs" placement="top" selected="1" action="tabSelected(this.selected)"> |
|
126 |
<!-- Attention: because of an obscure bug in Thinlet.getNextFocusable(), --> |
|
127 |
<!-- the tab "XML" must be the first one! If it is not the first panel, Thinlet --> |
|
128 |
<!-- runs into an endless loop when the user navigates from the "Preview" tab --> |
|
129 |
<!-- to the "XML" tab, trying to set the next focusable component. --> |
|
130 |
<tab text="XML" mnemonic="0"> |
|
131 |
<panel weightx="1" weighty="1"> |
|
132 |
<textarea name="serialize" editable="false" weightx="1" weighty="1"/> |
|
133 |
</panel> |
|
134 |
</tab> |
|
135 |
<tab text="Preview" mnemonic="0"> |
|
136 |
<panel name="preview" border="true" scrollable="true" weightx="1" weighty="1"/> |
|
137 |
</tab> |
|
138 |
</tabbedpane> |
|
139 |
|
|
140 |
</splitpane> |
|
141 |
</panel> |
|
142 |
|
|
143 |
<!-- status bar at bottom --> |
|
144 |
<textfield name="statusbar" editable="false" text="ThinG" weightx="1"/> |
|
145 |
|
|
146 |
</panel> |
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.153/org.gvsig.scripting.thing/src/main/java/thinletcommons/FontChooser.java | ||
---|---|---|
1 |
// jEdit settings: |
|
2 |
// :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: |
|
3 |
|
|
4 |
package thinletcommons; |
|
5 |
|
|
6 |
|
|
7 |
import java.awt.Dialog; |
|
8 |
import java.awt.Dimension; |
|
9 |
import java.awt.Font; |
|
10 |
import java.awt.Frame; |
|
11 |
import java.awt.GraphicsEnvironment; |
|
12 |
import java.util.Arrays; |
|
13 |
import java.util.logging.Level; |
|
14 |
import java.util.logging.Logger; |
|
15 |
|
|
16 |
import thinlet.Thinlet; |
|
17 |
|
|
18 |
|
|
19 |
/** |
|
20 |
* A Thinlet font chooser dialog. |
|
21 |
* |
|
22 |
* <p> |
|
23 |
* The dialog is modal and blocks the calling frame/dialog. It is therefore |
|
24 |
* displayed in a separate window. |
|
25 |
* |
|
26 |
* @author Dirk Moebius |
|
27 |
*/ |
|
28 |
public class FontChooser |
|
29 |
{ |
|
30 |
//{{{ logging |
|
31 |
private static final Logger log = Logger.getLogger("thinletcommons"); |
|
32 |
private static final boolean debug() { return log.isLoggable(Level.FINE); } |
|
33 |
//}}} |
|
34 |
|
|
35 |
|
|
36 |
private ThinletDialog dialog; |
|
37 |
private Thinlet thinlet; |
|
38 |
private Font selectedFont; |
|
39 |
|
|
40 |
|
|
41 |
public FontChooser(Frame owner, String title) |
|
42 |
{ |
|
43 |
this.dialog = new ThinletDialog(owner, title); |
|
44 |
init(); |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
public FontChooser(Dialog owner, String title) |
|
49 |
{ |
|
50 |
this.dialog = new ThinletDialog(owner, title); |
|
51 |
init(); |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
private void init() |
|
56 |
{ |
|
57 |
thinlet = new AntiAliasedThinlet(); |
|
58 |
|
|
59 |
try |
|
60 |
{ |
|
61 |
Object panel = thinlet.parse("/thinletcommons/fontchooser.xml", this); |
|
62 |
thinlet.add(panel); |
|
63 |
} |
|
64 |
catch(Exception e) |
|
65 |
{ |
|
66 |
log.log(Level.SEVERE, "Error parsing fontchooser.xml", e); |
|
67 |
} |
|
68 |
|
|
69 |
dialog.setContent(thinlet); |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
/** |
|
74 |
* Show the modal dialog. |
|
75 |
* This halts the application until the user dismisses the dialog. |
|
76 |
*/ |
|
77 |
public void show() |
|
78 |
{ |
|
79 |
dialog.setSize(new Dimension(320, 360)); |
|
80 |
dialog.setLocationRelativeTo(dialog.getOwner()); |
Also available in: Unified diff