Lines 1-19
Link Here
|
1 |
/* |
1 |
/* |
2 |
|
2 |
|
3 |
Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
Licensed to the Apache Software Foundation (ASF) under one or more |
4 |
contributor license agreements. See the NOTICE file distributed with |
4 |
contributor license agreements. See the NOTICE file distributed with |
5 |
this work for additional information regarding copyright ownership. |
5 |
this work for additional information regarding copyright ownership. |
6 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
7 |
(the "License"); you may not use this file except in compliance with |
7 |
(the "License"); you may not use this file except in compliance with |
8 |
the License. You may obtain a copy of the License at |
8 |
the License. You may obtain a copy of the License at |
9 |
|
9 |
|
10 |
http://www.apache.org/licenses/LICENSE-2.0 |
10 |
http://www.apache.org/licenses/LICENSE-2.0 |
11 |
|
11 |
|
12 |
Unless required by applicable law or agreed to in writing, software |
12 |
Unless required by applicable law or agreed to in writing, software |
13 |
distributed under the License is distributed on an "AS IS" BASIS, |
13 |
distributed under the License is distributed on an "AS IS" BASIS, |
14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 |
See the License for the specific language governing permissions and |
15 |
See the License for the specific language governing permissions and |
16 |
limitations under the License. |
16 |
limitations under the License. |
17 |
|
17 |
|
18 |
*/ |
18 |
*/ |
19 |
package org.apache.batik.apps.svgbrowser; |
19 |
package org.apache.batik.apps.svgbrowser; |
Lines 25-31
Link Here
|
25 |
import java.awt.Event; |
25 |
import java.awt.Event; |
26 |
import java.awt.EventQueue; |
26 |
import java.awt.EventQueue; |
27 |
import java.awt.FileDialog; |
27 |
import java.awt.FileDialog; |
28 |
import java.awt.Font; |
|
|
29 |
import java.awt.Graphics2D; |
28 |
import java.awt.Graphics2D; |
30 |
import java.awt.Rectangle; |
29 |
import java.awt.Rectangle; |
31 |
import java.awt.Toolkit; |
30 |
import java.awt.Toolkit; |
Lines 44-54
Link Here
|
44 |
import java.awt.image.BufferedImage; |
43 |
import java.awt.image.BufferedImage; |
45 |
import java.awt.print.PrinterException; |
44 |
import java.awt.print.PrinterException; |
46 |
import java.io.BufferedOutputStream; |
45 |
import java.io.BufferedOutputStream; |
|
|
46 |
import java.io.BufferedReader; |
47 |
import java.io.File; |
47 |
import java.io.File; |
|
|
48 |
import java.io.FileOutputStream; |
48 |
import java.io.FilenameFilter; |
49 |
import java.io.FilenameFilter; |
49 |
import java.io.FileOutputStream; |
|
|
50 |
import java.io.IOException; |
50 |
import java.io.IOException; |
51 |
import java.io.InputStream; |
51 |
import java.io.InputStream; |
|
|
52 |
import java.io.InputStreamReader; |
52 |
import java.io.OutputStream; |
53 |
import java.io.OutputStream; |
53 |
import java.io.OutputStreamWriter; |
54 |
import java.io.OutputStreamWriter; |
54 |
import java.io.Reader; |
55 |
import java.io.Reader; |
Lines 70-75
Link Here
|
70 |
import javax.swing.Action; |
71 |
import javax.swing.Action; |
71 |
import javax.swing.BorderFactory; |
72 |
import javax.swing.BorderFactory; |
72 |
import javax.swing.ButtonGroup; |
73 |
import javax.swing.ButtonGroup; |
|
|
74 |
import javax.swing.ImageIcon; |
73 |
import javax.swing.JComponent; |
75 |
import javax.swing.JComponent; |
74 |
import javax.swing.JDialog; |
76 |
import javax.swing.JDialog; |
75 |
import javax.swing.JFileChooser; |
77 |
import javax.swing.JFileChooser; |
Lines 79-93
Link Here
|
79 |
import javax.swing.JOptionPane; |
81 |
import javax.swing.JOptionPane; |
80 |
import javax.swing.JPanel; |
82 |
import javax.swing.JPanel; |
81 |
import javax.swing.JRadioButtonMenuItem; |
83 |
import javax.swing.JRadioButtonMenuItem; |
82 |
import javax.swing.JScrollPane; |
|
|
83 |
import javax.swing.JTextArea; |
84 |
import javax.swing.JToolBar; |
84 |
import javax.swing.JToolBar; |
85 |
import javax.swing.JWindow; |
85 |
import javax.swing.JWindow; |
86 |
import javax.swing.KeyStroke; |
86 |
import javax.swing.KeyStroke; |
87 |
import javax.swing.filechooser.FileFilter; |
87 |
import javax.swing.filechooser.FileFilter; |
88 |
import javax.swing.text.Document; |
|
|
89 |
import javax.swing.text.PlainDocument; |
90 |
|
88 |
|
|
|
89 |
import org.apache.batik.apps.svgbrowser.srcview.SourceViewFrame; |
91 |
import org.apache.batik.bridge.DefaultExternalResourceSecurity; |
90 |
import org.apache.batik.bridge.DefaultExternalResourceSecurity; |
92 |
import org.apache.batik.bridge.DefaultScriptSecurity; |
91 |
import org.apache.batik.bridge.DefaultScriptSecurity; |
93 |
import org.apache.batik.bridge.EmbededExternalResourceSecurity; |
92 |
import org.apache.batik.bridge.EmbededExternalResourceSecurity; |
Lines 102-110
Link Here
|
102 |
import org.apache.batik.bridge.UpdateManagerEvent; |
101 |
import org.apache.batik.bridge.UpdateManagerEvent; |
103 |
import org.apache.batik.bridge.UpdateManagerListener; |
102 |
import org.apache.batik.bridge.UpdateManagerListener; |
104 |
import org.apache.batik.dom.StyleSheetProcessingInstruction; |
103 |
import org.apache.batik.dom.StyleSheetProcessingInstruction; |
|
|
104 |
import org.apache.batik.dom.svg.LiveAttributeException; |
105 |
import org.apache.batik.dom.svg.SVGOMDocument; |
105 |
import org.apache.batik.dom.svg.SVGOMDocument; |
|
|
106 |
import org.apache.batik.dom.util.DOMUtilities; |
107 |
import org.apache.batik.dom.util.DocumentDescriptor; |
106 |
import org.apache.batik.dom.util.HashTable; |
108 |
import org.apache.batik.dom.util.HashTable; |
107 |
import org.apache.batik.dom.util.DOMUtilities; |
|
|
108 |
import org.apache.batik.ext.swing.JAffineTransformChooser; |
109 |
import org.apache.batik.ext.swing.JAffineTransformChooser; |
109 |
import org.apache.batik.swing.JSVGCanvas; |
110 |
import org.apache.batik.swing.JSVGCanvas; |
110 |
import org.apache.batik.swing.gvt.GVTTreeRendererEvent; |
111 |
import org.apache.batik.swing.gvt.GVTTreeRendererEvent; |
Lines 129-142
Link Here
|
129 |
import org.apache.batik.transcoder.svg2svg.SVGTranscoder; |
130 |
import org.apache.batik.transcoder.svg2svg.SVGTranscoder; |
130 |
import org.apache.batik.util.ParsedURL; |
131 |
import org.apache.batik.util.ParsedURL; |
131 |
import org.apache.batik.util.Platform; |
132 |
import org.apache.batik.util.Platform; |
|
|
133 |
import org.apache.batik.util.SVGConstants; |
132 |
import org.apache.batik.util.Service; |
134 |
import org.apache.batik.util.Service; |
133 |
import org.apache.batik.util.SVGConstants; |
|
|
134 |
import org.apache.batik.util.XMLConstants; |
135 |
import org.apache.batik.util.XMLConstants; |
135 |
import org.apache.batik.util.gui.DOMViewer; |
136 |
import org.apache.batik.util.gui.DOMViewer; |
136 |
import org.apache.batik.util.gui.JErrorPane; |
137 |
import org.apache.batik.util.gui.ErrorConsole; |
137 |
import org.apache.batik.util.gui.LocationBar; |
138 |
import org.apache.batik.util.gui.LocationBar; |
138 |
import org.apache.batik.util.gui.MemoryMonitor; |
139 |
import org.apache.batik.util.gui.MemoryMonitor; |
|
|
140 |
import org.apache.batik.util.gui.TimelineViewer; |
139 |
import org.apache.batik.util.gui.URIChooser; |
141 |
import org.apache.batik.util.gui.URIChooser; |
|
|
142 |
import org.apache.batik.util.gui.ErrorConsole.ErrorInfo; |
143 |
import org.apache.batik.util.gui.ErrorConsole.AttributeErrorInfo; |
140 |
import org.apache.batik.util.gui.resource.ActionMap; |
144 |
import org.apache.batik.util.gui.resource.ActionMap; |
141 |
import org.apache.batik.util.gui.resource.JComponentModifier; |
145 |
import org.apache.batik.util.gui.resource.JComponentModifier; |
142 |
import org.apache.batik.util.gui.resource.MenuFactory; |
146 |
import org.apache.batik.util.gui.resource.MenuFactory; |
Lines 151-3086
Link Here
|
151 |
|
155 |
|
152 |
/** |
156 |
/** |
153 |
* This class represents a SVG viewer swing frame. |
157 |
* This class represents a SVG viewer swing frame. |
154 |
* |
158 |
* |
155 |
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a> |
159 |
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a> |
156 |
* @version $Id$ |
160 |
* @version $Id$ |
157 |
*/ |
161 |
*/ |
158 |
public class JSVGViewerFrame |
162 |
public class JSVGViewerFrame extends JFrame implements ActionMap, |
159 |
extends JFrame |
163 |
SVGDocumentLoaderListener, GVTTreeBuilderListener, |
160 |
implements ActionMap, |
164 |
SVGLoadEventDispatcherListener, GVTTreeRendererListener, |
161 |
SVGDocumentLoaderListener, |
165 |
LinkActivationListener, UpdateManagerListener { |
162 |
GVTTreeBuilderListener, |
|
|
163 |
SVGLoadEventDispatcherListener, |
164 |
GVTTreeRendererListener, |
165 |
LinkActivationListener, |
166 |
UpdateManagerListener { |
167 |
|
166 |
|
168 |
private static String EOL; |
167 |
private static String EOL; |
169 |
static { |
168 |
static { |
170 |
try { |
169 |
try { |
171 |
EOL = System.getProperty("line.separator", "\n"); |
170 |
EOL = System.getProperty("line.separator", "\n"); |
172 |
} catch (SecurityException e) { |
171 |
} catch (SecurityException e) { |
173 |
EOL = "\n"; |
172 |
EOL = "\n"; |
174 |
} |
173 |
} |
175 |
} |
174 |
} |
176 |
|
175 |
|
177 |
/** |
176 |
/** |
178 |
* Kind of ugly, but we need to know if we are running before |
177 |
* Kind of ugly, but we need to know if we are running before or after |
179 |
* or after 1.4... |
178 |
* 1.4... |
180 |
*/ |
179 |
*/ |
181 |
protected static boolean priorJDK1_4 = true; |
180 |
protected static boolean priorJDK1_4 = true; |
182 |
|
181 |
|
183 |
/** |
182 |
/** |
184 |
* If the following class can be found (it appeared in JDK 1.4), |
183 |
* If the following class can be found (it appeared in JDK 1.4), then we |
185 |
* then we know we are post JDK 1.4. |
184 |
* know we are post JDK 1.4. |
186 |
*/ |
185 |
*/ |
187 |
protected static final String JDK_1_4_PRESENCE_TEST_CLASS |
186 |
protected static final String JDK_1_4_PRESENCE_TEST_CLASS = "java.util.logging.LoggingPermission"; |
188 |
= "java.util.logging.LoggingPermission"; |
|
|
189 |
|
187 |
|
190 |
static { |
188 |
static { |
191 |
try { |
189 |
try { |
192 |
Class.forName(JDK_1_4_PRESENCE_TEST_CLASS); |
190 |
Class.forName(JDK_1_4_PRESENCE_TEST_CLASS); |
193 |
priorJDK1_4 = false; |
191 |
priorJDK1_4 = false; |
194 |
} catch (ClassNotFoundException e) { |
192 |
} catch (ClassNotFoundException e) { |
195 |
} |
193 |
} |
196 |
} |
194 |
} |
197 |
|
195 |
|
198 |
/** |
196 |
/** |
199 |
* The gui resources file name |
197 |
* The gui resources file name |
200 |
*/ |
198 |
*/ |
201 |
public static final String RESOURCES = |
199 |
public static final String RESOURCES = "org.apache.batik.apps.svgbrowser.resources.GUI"; |
202 |
"org.apache.batik.apps.svgbrowser.resources.GUI"; |
|
|
203 |
|
200 |
|
204 |
// The actions names. |
201 |
// The actions names. |
205 |
public static final String ABOUT_ACTION = "AboutAction"; |
202 |
public static final String ABOUT_ACTION = "AboutAction"; |
206 |
public static final String OPEN_ACTION = "OpenAction"; |
|
|
207 |
public static final String OPEN_LOCATION_ACTION = "OpenLocationAction"; |
208 |
public static final String NEW_WINDOW_ACTION = "NewWindowAction"; |
209 |
public static final String RELOAD_ACTION = "ReloadAction"; |
210 |
public static final String SAVE_AS_ACTION = "SaveAsAction"; |
211 |
public static final String BACK_ACTION = "BackAction"; |
212 |
public static final String FORWARD_ACTION = "ForwardAction"; |
213 |
public static final String FULL_SCREEN_ACTION = "FullScreenAction"; |
214 |
public static final String PRINT_ACTION = "PrintAction"; |
215 |
public static final String EXPORT_AS_JPG_ACTION = "ExportAsJPGAction"; |
216 |
public static final String EXPORT_AS_PNG_ACTION = "ExportAsPNGAction"; |
217 |
public static final String EXPORT_AS_TIFF_ACTION = "ExportAsTIFFAction"; |
218 |
public static final String PREFERENCES_ACTION = "PreferencesAction"; |
219 |
public static final String CLOSE_ACTION = "CloseAction"; |
220 |
public static final String VIEW_SOURCE_ACTION = "ViewSourceAction"; |
221 |
public static final String EXIT_ACTION = "ExitAction"; |
222 |
public static final String RESET_TRANSFORM_ACTION = "ResetTransformAction"; |
223 |
public static final String ZOOM_IN_ACTION = "ZoomInAction"; |
224 |
public static final String ZOOM_OUT_ACTION = "ZoomOutAction"; |
225 |
public static final String PREVIOUS_TRANSFORM_ACTION = "PreviousTransformAction"; |
226 |
public static final String NEXT_TRANSFORM_ACTION = "NextTransformAction"; |
227 |
public static final String USE_STYLESHEET_ACTION = "UseStylesheetAction"; |
228 |
public static final String PLAY_ACTION = "PlayAction"; |
229 |
public static final String PAUSE_ACTION = "PauseAction"; |
230 |
public static final String STOP_ACTION = "StopAction"; |
231 |
public static final String MONITOR_ACTION = "MonitorAction"; |
232 |
public static final String DOM_VIEWER_ACTION = "DOMViewerAction"; |
233 |
public static final String SET_TRANSFORM_ACTION = "SetTransformAction"; |
234 |
public static final String FIND_DIALOG_ACTION = "FindDialogAction"; |
235 |
public static final String THUMBNAIL_DIALOG_ACTION = "ThumbnailDialogAction"; |
236 |
public static final String FLUSH_ACTION = "FlushAction"; |
237 |
public static final String TOGGLE_DEBUGGER_ACTION = "ToggleDebuggerAction"; |
238 |
|
203 |
|
239 |
/** |
204 |
public static final String OPEN_ACTION = "OpenAction"; |
240 |
* The cursor indicating that an operation is pending. |
|
|
241 |
*/ |
242 |
public static final Cursor WAIT_CURSOR = |
243 |
new Cursor(Cursor.WAIT_CURSOR); |
244 |
|
205 |
|
245 |
/** |
206 |
public static final String OPEN_LOCATION_ACTION = "OpenLocationAction"; |
246 |
* The default cursor. |
|
|
247 |
*/ |
248 |
public static final Cursor DEFAULT_CURSOR = |
249 |
new Cursor(Cursor.DEFAULT_CURSOR); |
250 |
|
207 |
|
251 |
/** |
208 |
public static final String NEW_WINDOW_ACTION = "NewWindowAction"; |
252 |
* Name for the os-name property |
|
|
253 |
*/ |
254 |
public static final String PROPERTY_OS_NAME |
255 |
= Resources.getString("JSVGViewerFrame.property.os.name"); |
256 |
|
209 |
|
257 |
/** |
210 |
public static final String RELOAD_ACTION = "ReloadAction"; |
258 |
* Name for the os.name default |
|
|
259 |
*/ |
260 |
public static final String PROPERTY_OS_NAME_DEFAULT |
261 |
= Resources.getString("JSVGViewerFrame.property.os.name.default"); |
262 |
|
211 |
|
263 |
/** |
212 |
public static final String SAVE_AS_ACTION = "SaveAsAction"; |
264 |
* Name for the os.name property prefix we are looking |
|
|
265 |
* for in OpenAction to work around JFileChooser bug |
266 |
*/ |
267 |
public static final String PROPERTY_OS_WINDOWS_PREFIX |
268 |
= Resources.getString("JSVGViewerFrame.property.os.windows.prefix"); |
269 |
|
213 |
|
270 |
/** |
214 |
public static final String BACK_ACTION = "BackAction"; |
271 |
* Resource string name for the Open dialog. |
|
|
272 |
*/ |
273 |
protected static final String OPEN_TITLE = "Open.title"; |
274 |
|
215 |
|
275 |
/** |
216 |
public static final String FORWARD_ACTION = "ForwardAction"; |
276 |
* The input handlers |
|
|
277 |
*/ |
278 |
protected static Vector handlers; |
279 |
|
217 |
|
280 |
/** |
218 |
public static final String FULL_SCREEN_ACTION = "FullScreenAction"; |
281 |
* The default input handler |
|
|
282 |
*/ |
283 |
protected static SquiggleInputHandler defaultHandler = new SVGInputHandler(); |
284 |
|
219 |
|
285 |
/** |
220 |
public static final String PRINT_ACTION = "PrintAction"; |
286 |
* The resource bundle |
|
|
287 |
*/ |
288 |
protected static ResourceBundle bundle; |
289 |
|
221 |
|
290 |
/** |
222 |
public static final String EXPORT_AS_JPG_ACTION = "ExportAsJPGAction"; |
291 |
* The resource manager |
|
|
292 |
*/ |
293 |
protected static ResourceManager resources; |
294 |
static { |
295 |
bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault()); |
296 |
resources = new ResourceManager(bundle); |
297 |
} |
298 |
|
223 |
|
299 |
/** |
224 |
public static final String EXPORT_AS_PNG_ACTION = "ExportAsPNGAction"; |
300 |
* The current application. |
|
|
301 |
*/ |
302 |
protected Application application; |
303 |
|
225 |
|
304 |
/** |
226 |
public static final String EXPORT_AS_TIFF_ACTION = "ExportAsTIFFAction"; |
305 |
* The JSVGCanvas. |
|
|
306 |
*/ |
307 |
protected Canvas svgCanvas; |
308 |
|
227 |
|
309 |
/** |
228 |
public static final String PREFERENCES_ACTION = "PreferencesAction"; |
310 |
* An extension of JSVGCanvas that exposes the Rhino interpreter. |
|
|
311 |
*/ |
312 |
protected static class Canvas extends JSVGCanvas { |
313 |
|
229 |
|
314 |
/** |
230 |
public static final String CLOSE_ACTION = "CloseAction"; |
315 |
* Creates a new Canvas. |
|
|
316 |
*/ |
317 |
public Canvas(SVGUserAgent ua, boolean eventsEnabled, |
318 |
boolean selectableText) { |
319 |
super(ua, eventsEnabled, selectableText); |
320 |
} |
321 |
|
231 |
|
322 |
/** |
232 |
public static final String VIEW_SOURCE_ACTION = "ViewSourceAction"; |
323 |
* Returns the Rhino interpreter for this canvas. |
|
|
324 |
*/ |
325 |
public Object getRhinoInterpreter() { |
326 |
if (bridgeContext == null) { |
327 |
return null; |
328 |
} |
329 |
return bridgeContext.getInterpreter("text/ecmascript"); |
330 |
} |
331 |
} |
332 |
|
233 |
|
333 |
/** |
234 |
public static final String EXIT_ACTION = "ExitAction"; |
334 |
* The panel where the svgCanvas is displayed |
|
|
335 |
*/ |
336 |
protected JPanel svgCanvasPanel; |
337 |
|
235 |
|
338 |
/** |
236 |
public static final String RESET_TRANSFORM_ACTION = "ResetTransformAction"; |
339 |
* A window used for full screen display |
|
|
340 |
*/ |
341 |
protected JWindow window; |
342 |
|
237 |
|
343 |
/** |
238 |
public static final String ZOOM_IN_ACTION = "ZoomInAction"; |
344 |
* The memory monitor frame. |
|
|
345 |
*/ |
346 |
protected static JFrame memoryMonitorFrame; |
347 |
|
239 |
|
348 |
/** |
240 |
public static final String ZOOM_OUT_ACTION = "ZoomOutAction"; |
349 |
* The current path. |
|
|
350 |
*/ |
351 |
protected File currentPath = new File(""); |
352 |
|
241 |
|
353 |
/** |
242 |
public static final String PREVIOUS_TRANSFORM_ACTION = "PreviousTransformAction"; |
354 |
* The current export path. |
|
|
355 |
*/ |
356 |
protected File currentSavePath = new File(""); |
357 |
|
243 |
|
358 |
/** |
244 |
public static final String NEXT_TRANSFORM_ACTION = "NextTransformAction"; |
359 |
* The back action |
|
|
360 |
*/ |
361 |
protected BackAction backAction = new BackAction(); |
362 |
|
245 |
|
363 |
/** |
246 |
public static final String USE_STYLESHEET_ACTION = "UseStylesheetAction"; |
364 |
* The forward action |
|
|
365 |
*/ |
366 |
protected ForwardAction forwardAction = new ForwardAction(); |
367 |
|
247 |
|
368 |
/** |
248 |
public static final String PLAY_ACTION = "PlayAction"; |
369 |
* The play action |
|
|
370 |
*/ |
371 |
protected PlayAction playAction = new PlayAction(); |
372 |
|
249 |
|
373 |
/** |
250 |
public static final String PAUSE_ACTION = "PauseAction"; |
374 |
* The pause action |
|
|
375 |
*/ |
376 |
protected PauseAction pauseAction = new PauseAction(); |
377 |
|
251 |
|
378 |
/** |
252 |
public static final String STOP_ACTION = "StopAction"; |
379 |
* The stop action |
|
|
380 |
*/ |
381 |
protected StopAction stopAction = new StopAction(); |
382 |
|
253 |
|
383 |
/** |
254 |
public static final String MONITOR_ACTION = "MonitorAction"; |
384 |
* The previous transform action |
|
|
385 |
*/ |
386 |
protected PreviousTransformAction previousTransformAction = |
387 |
new PreviousTransformAction(); |
388 |
|
255 |
|
389 |
/** |
256 |
public static final String DOM_VIEWER_ACTION = "DOMViewerAction"; |
390 |
* The next transform action |
|
|
391 |
*/ |
392 |
protected NextTransformAction nextTransformAction = |
393 |
new NextTransformAction(); |
394 |
|
257 |
|
395 |
/** |
258 |
public static final String TIMELINE_VIEWER_ACTION = "TimelineViewerAction"; |
396 |
* The use (author) stylesheet action |
|
|
397 |
*/ |
398 |
protected UseStylesheetAction useStylesheetAction = |
399 |
new UseStylesheetAction(); |
400 |
|
259 |
|
401 |
/** |
260 |
public static final String SET_TRANSFORM_ACTION = "SetTransformAction"; |
402 |
* The debug flag. |
|
|
403 |
*/ |
404 |
protected boolean debug; |
405 |
|
261 |
|
406 |
/** |
262 |
public static final String FIND_DIALOG_ACTION = "FindDialogAction"; |
407 |
* The auto adjust flag. |
|
|
408 |
*/ |
409 |
protected boolean autoAdjust = true; |
410 |
|
263 |
|
411 |
/** |
264 |
public static final String THUMBNAIL_DIALOG_ACTION = "ThumbnailDialogAction"; |
412 |
* Whether the update manager was stopped. |
|
|
413 |
*/ |
414 |
protected boolean managerStopped; |
415 |
|
265 |
|
416 |
/** |
266 |
public static final String FLUSH_ACTION = "FlushAction"; |
417 |
* The SVG user agent. |
|
|
418 |
*/ |
419 |
protected SVGUserAgent userAgent = new UserAgent(); |
420 |
|
267 |
|
421 |
/** |
268 |
public static final String TOGGLE_DEBUGGER_ACTION = "ToggleDebuggerAction"; |
422 |
* The current document. |
|
|
423 |
*/ |
424 |
protected SVGDocument svgDocument; |
425 |
|
269 |
|
426 |
/** |
270 |
/** |
427 |
* The URI chooser. |
271 |
* The cursor indicating that an operation is pending. |
428 |
*/ |
272 |
*/ |
429 |
protected URIChooser uriChooser; |
273 |
public static final Cursor WAIT_CURSOR = new Cursor(Cursor.WAIT_CURSOR); |
430 |
|
274 |
|
431 |
/** |
275 |
/** |
432 |
* The DOM viewer. |
276 |
* The default cursor. |
433 |
*/ |
277 |
*/ |
434 |
protected DOMViewer domViewer; |
278 |
public static final Cursor DEFAULT_CURSOR = new Cursor( |
|
|
279 |
Cursor.DEFAULT_CURSOR); |
435 |
|
280 |
|
436 |
/** |
281 |
/** |
437 |
* The Find dialog. |
282 |
* Name for the os-name property |
438 |
*/ |
283 |
*/ |
439 |
protected FindDialog findDialog; |
284 |
public static final String PROPERTY_OS_NAME = Resources |
|
|
285 |
.getString("JSVGViewerFrame.property.os.name"); |
440 |
|
286 |
|
441 |
/** |
287 |
/** |
442 |
* The Find dialog. |
288 |
* Name for the os.name default |
443 |
*/ |
289 |
*/ |
444 |
protected ThumbnailDialog thumbnailDialog; |
290 |
public static final String PROPERTY_OS_NAME_DEFAULT = Resources |
|
|
291 |
.getString("JSVGViewerFrame.property.os.name.default"); |
445 |
|
292 |
|
446 |
/** |
293 |
/** |
447 |
* The transform dialog |
294 |
* Name for the os.name property prefix we are looking for in OpenAction to |
448 |
*/ |
295 |
* work around JFileChooser bug |
449 |
protected JAffineTransformChooser.Dialog transformDialog; |
296 |
*/ |
|
|
297 |
public static final String PROPERTY_OS_WINDOWS_PREFIX = Resources |
298 |
.getString("JSVGViewerFrame.property.os.windows.prefix"); |
450 |
|
299 |
|
451 |
/** |
300 |
/** |
452 |
* The location bar. |
301 |
* Resource string name for the Open dialog. |
453 |
*/ |
302 |
*/ |
454 |
protected LocationBar locationBar; |
303 |
protected static final String OPEN_TITLE = "Open.title"; |
455 |
|
304 |
|
456 |
/** |
305 |
/** |
457 |
* The status bar. |
306 |
* The input handlers |
458 |
*/ |
307 |
*/ |
459 |
protected StatusBar statusBar; |
308 |
protected static Vector handlers; |
460 |
|
309 |
|
461 |
/** |
310 |
/** |
462 |
* The initial frame title. |
311 |
* The default input handler |
463 |
*/ |
312 |
*/ |
464 |
protected String title; |
313 |
protected static SquiggleInputHandler defaultHandler = new SVGInputHandler(); |
465 |
|
314 |
|
466 |
/** |
315 |
/** |
467 |
* The local history. |
316 |
* The resource bundle |
468 |
*/ |
317 |
*/ |
469 |
protected LocalHistory localHistory; |
318 |
protected static ResourceBundle bundle; |
470 |
|
319 |
|
471 |
/** |
320 |
/** |
472 |
* The transform history. |
321 |
* The resource manager |
473 |
*/ |
322 |
*/ |
474 |
protected TransformHistory transformHistory = new TransformHistory(); |
323 |
protected static ResourceManager resources; |
|
|
324 |
static { |
325 |
bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault()); |
326 |
resources = new ResourceManager(bundle); |
327 |
} |
475 |
|
328 |
|
476 |
/** |
329 |
/** |
477 |
* The alternate style-sheet title. |
330 |
* The current application. |
478 |
*/ |
331 |
*/ |
479 |
protected String alternateStyleSheet; |
332 |
protected Application application; |
480 |
|
333 |
|
481 |
/** |
334 |
/** |
482 |
* The debugger object. |
335 |
* The JSVGCanvas. |
483 |
*/ |
336 |
*/ |
484 |
protected Debugger debugger; |
337 |
protected Canvas svgCanvas; |
485 |
|
338 |
|
486 |
/** |
339 |
/** |
487 |
* Creates a new SVG viewer frame. |
340 |
* An extension of JSVGCanvas that exposes the Rhino interpreter. |
488 |
*/ |
341 |
*/ |
489 |
public JSVGViewerFrame(Application app) { |
342 |
protected static class Canvas extends JSVGCanvas { |
490 |
application = app; |
|
|
491 |
|
343 |
|
492 |
addWindowListener(new WindowAdapter() { |
344 |
/** |
493 |
public void windowClosing(WindowEvent e) { |
345 |
* Creates a new Canvas. |
494 |
application.closeJSVGViewerFrame(JSVGViewerFrame.this); |
346 |
*/ |
495 |
} |
347 |
public Canvas(SVGUserAgent ua, boolean eventsEnabled, |
496 |
}); |
348 |
boolean selectableText) { |
|
|
349 |
super(ua, eventsEnabled, selectableText); |
350 |
} |
497 |
|
351 |
|
498 |
// |
352 |
/** |
499 |
// Set the frame's maximum size so that content |
353 |
* Returns the Rhino interpreter for this canvas. |
500 |
// bigger than the screen does not cause the creation |
354 |
*/ |
501 |
// of unnecessary large images. |
355 |
public Object getRhinoInterpreter() { |
502 |
// |
356 |
if (bridgeContext == null) { |
503 |
svgCanvas = new Canvas(userAgent, true, true) { |
357 |
return null; |
504 |
Dimension screenSize; |
358 |
} |
|
|
359 |
return bridgeContext.getInterpreter("text/ecmascript"); |
360 |
} |
361 |
} |
505 |
|
362 |
|
506 |
{ |
363 |
/** |
507 |
screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
364 |
* The panel where the svgCanvas is displayed |
508 |
setMaximumSize(screenSize); |
365 |
*/ |
509 |
} |
366 |
protected JPanel svgCanvasPanel; |
510 |
|
367 |
|
511 |
public Dimension getPreferredSize(){ |
368 |
/** |
512 |
Dimension s = super.getPreferredSize(); |
369 |
* A window used for full screen display |
513 |
if (s.width > screenSize.width) s.width =screenSize.width; |
370 |
*/ |
514 |
if (s.height > screenSize.height) s.height = screenSize.height; |
371 |
protected JWindow window; |
515 |
return s; |
|
|
516 |
} |
517 |
|
372 |
|
|
|
373 |
/** |
374 |
* The memory monitor frame. |
375 |
*/ |
376 |
protected static JFrame memoryMonitorFrame; |
518 |
|
377 |
|
519 |
/** |
378 |
/** |
520 |
* This method is called when the component knows the desired |
379 |
* The current path. |
521 |
* size of the window (based on width/height of outermost SVG |
380 |
*/ |
522 |
* element). We override it to immediately pack this frame. |
381 |
protected File currentPath = new File(""); |
523 |
*/ |
|
|
524 |
public void setMySize(Dimension d) { |
525 |
setPreferredSize(d); |
526 |
invalidate(); |
527 |
if (JSVGViewerFrame.this.autoAdjust) { |
528 |
Platform.unmaximize(JSVGViewerFrame.this); |
529 |
JSVGViewerFrame.this.pack(); |
530 |
} |
531 |
} |
532 |
|
382 |
|
533 |
public void setDisableInteractions(boolean b) { |
383 |
/** |
534 |
super.setDisableInteractions(b); |
384 |
* The current export path. |
|
|
385 |
*/ |
386 |
protected File currentSavePath = new File(""); |
535 |
|
387 |
|
536 |
// Disable/Enable all our different ways to adjust the |
388 |
/** |
537 |
// rendering transform (menus, toolbar, thumbnail, keyboard). |
389 |
* The back action |
|
|
390 |
*/ |
391 |
protected BackAction backAction = new BackAction(); |
538 |
|
392 |
|
539 |
((Action)listeners.get(SET_TRANSFORM_ACTION)) .setEnabled(!b); |
393 |
/** |
|
|
394 |
* The forward action |
395 |
*/ |
396 |
protected ForwardAction forwardAction = new ForwardAction(); |
540 |
|
397 |
|
541 |
if (thumbnailDialog != null) |
398 |
/** |
542 |
thumbnailDialog.setInteractionEnabled(!b); |
399 |
* The play action |
543 |
} |
400 |
*/ |
544 |
}; |
401 |
protected PlayAction playAction = new PlayAction(); |
545 |
|
402 |
|
546 |
javax.swing.ActionMap map = svgCanvas.getActionMap(); |
403 |
/** |
547 |
map.put(FULL_SCREEN_ACTION, new FullScreenAction()); |
404 |
* The pause action |
548 |
javax.swing.InputMap imap = svgCanvas.getInputMap(JComponent.WHEN_FOCUSED); |
405 |
*/ |
549 |
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0); |
406 |
protected PauseAction pauseAction = new PauseAction(); |
550 |
imap.put(key, FULL_SCREEN_ACTION); |
|
|
551 |
|
407 |
|
552 |
svgCanvas.setDoubleBufferedRendering(true); |
408 |
/** |
|
|
409 |
* The stop action |
410 |
*/ |
411 |
protected StopAction stopAction = new StopAction(); |
553 |
|
412 |
|
554 |
listeners.put(ABOUT_ACTION, new AboutAction()); |
413 |
/** |
555 |
listeners.put(OPEN_ACTION, new OpenAction()); |
414 |
* The previous transform action |
556 |
listeners.put(OPEN_LOCATION_ACTION, new OpenLocationAction()); |
415 |
*/ |
557 |
listeners.put(NEW_WINDOW_ACTION, new NewWindowAction()); |
416 |
protected PreviousTransformAction previousTransformAction = new PreviousTransformAction(); |
558 |
listeners.put(RELOAD_ACTION, new ReloadAction()); |
|
|
559 |
listeners.put(SAVE_AS_ACTION, new SaveAsAction()); |
560 |
listeners.put(BACK_ACTION, backAction); |
561 |
listeners.put(FORWARD_ACTION, forwardAction); |
562 |
listeners.put(PRINT_ACTION, new PrintAction()); |
563 |
listeners.put(EXPORT_AS_JPG_ACTION, new ExportAsJPGAction()); |
564 |
listeners.put(EXPORT_AS_PNG_ACTION, new ExportAsPNGAction()); |
565 |
listeners.put(EXPORT_AS_TIFF_ACTION, new ExportAsTIFFAction()); |
566 |
listeners.put(PREFERENCES_ACTION, new PreferencesAction()); |
567 |
listeners.put(CLOSE_ACTION, new CloseAction()); |
568 |
listeners.put(EXIT_ACTION, application.createExitAction(this)); |
569 |
listeners.put(VIEW_SOURCE_ACTION, new ViewSourceAction()); |
570 |
|
417 |
|
571 |
javax.swing.ActionMap cMap = svgCanvas.getActionMap(); |
418 |
/** |
572 |
listeners.put(RESET_TRANSFORM_ACTION, |
419 |
* The next transform action |
573 |
cMap.get(JSVGCanvas.RESET_TRANSFORM_ACTION)); |
420 |
*/ |
574 |
listeners.put(ZOOM_IN_ACTION, |
421 |
protected NextTransformAction nextTransformAction = new NextTransformAction(); |
575 |
cMap.get(JSVGCanvas.ZOOM_IN_ACTION)); |
|
|
576 |
listeners.put(ZOOM_OUT_ACTION, |
577 |
cMap.get(JSVGCanvas.ZOOM_OUT_ACTION)); |
578 |
|
422 |
|
579 |
listeners.put(PREVIOUS_TRANSFORM_ACTION, previousTransformAction); |
423 |
/** |
580 |
key = KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.CTRL_MASK); |
424 |
* The use (author) stylesheet action |
581 |
imap.put(key, previousTransformAction); |
425 |
*/ |
|
|
426 |
protected UseStylesheetAction useStylesheetAction = new UseStylesheetAction(); |
582 |
|
427 |
|
583 |
listeners.put(NEXT_TRANSFORM_ACTION, nextTransformAction); |
428 |
/** |
584 |
key = KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_MASK); |
429 |
* The debug flag. |
585 |
imap.put(key, nextTransformAction); |
430 |
*/ |
|
|
431 |
protected boolean debug; |
586 |
|
432 |
|
587 |
listeners.put(USE_STYLESHEET_ACTION, useStylesheetAction); |
433 |
/** |
588 |
listeners.put(PLAY_ACTION, playAction); |
434 |
* The auto adjust flag. |
589 |
listeners.put(PAUSE_ACTION, pauseAction); |
435 |
*/ |
590 |
listeners.put(STOP_ACTION, stopAction); |
436 |
protected boolean autoAdjust = true; |
591 |
listeners.put(MONITOR_ACTION, new MonitorAction()); |
|
|
592 |
listeners.put(DOM_VIEWER_ACTION, new DOMViewerAction()); |
593 |
listeners.put(SET_TRANSFORM_ACTION, new SetTransformAction()); |
594 |
listeners.put(FIND_DIALOG_ACTION, new FindDialogAction()); |
595 |
listeners.put(THUMBNAIL_DIALOG_ACTION, new ThumbnailDialogAction()); |
596 |
listeners.put(FLUSH_ACTION, new FlushAction()); |
597 |
listeners.put(TOGGLE_DEBUGGER_ACTION, new ToggleDebuggerAction()); |
598 |
|
437 |
|
599 |
JPanel p = null; |
438 |
/** |
600 |
try { |
439 |
* Whether the update manager was stopped. |
601 |
// Create the menu |
440 |
*/ |
602 |
MenuFactory mf = new MenuFactory(bundle, this); |
441 |
protected boolean managerStopped; |
603 |
JMenuBar mb = |
|
|
604 |
mf.createJMenuBar("MenuBar", application.getUISpecialization()); |
605 |
setJMenuBar(mb); |
606 |
|
442 |
|
607 |
localHistory = new LocalHistory(mb, this); |
443 |
/** |
|
|
444 |
* The SVG user agent. |
445 |
*/ |
446 |
protected SVGUserAgent userAgent = new UserAgent(); |
608 |
|
447 |
|
609 |
String[] uri = application.getVisitedURIs(); |
448 |
/** |
610 |
for (int i=0; i<uri.length; i++) { |
449 |
* The current document. |
611 |
if (uri[i] != null && !"".equals(uri[i])) { |
450 |
*/ |
612 |
localHistory.update(uri[i]); |
451 |
protected SVGDocument svgDocument; |
613 |
} |
|
|
614 |
} |
615 |
p = new JPanel(new BorderLayout()); |
616 |
|
452 |
|
617 |
// Create the toolbar |
453 |
/** |
618 |
ToolBarFactory tbf = new ToolBarFactory(bundle, this); |
454 |
* The descriptor associated with the current document. |
619 |
JToolBar tb = tbf.createJToolBar("ToolBar"); |
455 |
*/ |
620 |
tb.setFloatable(false); |
456 |
protected DocumentDescriptor docDescriptor; |
621 |
getContentPane().add(p, BorderLayout.NORTH); |
|
|
622 |
p.add(tb, BorderLayout.NORTH); |
623 |
p.add(new javax.swing.JSeparator(), BorderLayout.CENTER); |
624 |
p.add(locationBar = new LocationBar(), BorderLayout.SOUTH); |
625 |
locationBar.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
626 |
|
457 |
|
627 |
} catch (MissingResourceException e) { |
458 |
/** |
628 |
System.out.println(e.getMessage()); |
459 |
* Document text, stored when the document is loaded |
629 |
System.exit(0); |
460 |
*/ |
630 |
} |
461 |
protected String docText; |
631 |
|
462 |
|
632 |
svgCanvasPanel = new JPanel(new BorderLayout()); |
463 |
/** |
633 |
svgCanvasPanel.setBorder(BorderFactory.createEtchedBorder()); |
464 |
* The URI chooser. |
|
|
465 |
*/ |
466 |
protected URIChooser uriChooser; |
634 |
|
467 |
|
635 |
svgCanvasPanel.add(svgCanvas, BorderLayout.CENTER); |
468 |
/** |
636 |
p = new JPanel(new BorderLayout()); |
469 |
* The DOM viewer. |
637 |
p.add(svgCanvasPanel, BorderLayout.CENTER); |
470 |
*/ |
638 |
p.add(statusBar = new StatusBar(), BorderLayout.SOUTH); |
471 |
protected DOMViewer domViewer; |
639 |
|
472 |
|
640 |
getContentPane().add(p, BorderLayout.CENTER); |
473 |
/** |
|
|
474 |
* The Timeline viewer. |
475 |
*/ |
476 |
protected TimelineViewer timelineViewer; |
641 |
|
477 |
|
642 |
svgCanvas.addSVGDocumentLoaderListener(this); |
478 |
/** |
643 |
svgCanvas.addGVTTreeBuilderListener(this); |
479 |
* The Find dialog. |
644 |
svgCanvas.addSVGLoadEventDispatcherListener(this); |
480 |
*/ |
645 |
svgCanvas.addGVTTreeRendererListener(this); |
481 |
protected FindDialog findDialog; |
646 |
svgCanvas.addLinkActivationListener(this); |
|
|
647 |
svgCanvas.addUpdateManagerListener(this); |
648 |
|
482 |
|
649 |
svgCanvas.addMouseMotionListener(new MouseMotionAdapter() { |
483 |
/** |
650 |
public void mouseMoved(MouseEvent e) { |
484 |
* The Find dialog. |
651 |
if (svgDocument == null) { |
485 |
*/ |
652 |
statusBar.setXPosition(e.getX()); |
486 |
protected ThumbnailDialog thumbnailDialog; |
653 |
statusBar.setYPosition(e.getY()); |
|
|
654 |
} else { |
655 |
try { |
656 |
AffineTransform at; |
657 |
at = svgCanvas.getViewBoxTransform(); |
658 |
if (at != null) { |
659 |
at = at.createInverse(); |
660 |
Point2D p2d = |
661 |
at.transform(new Point2D.Float(e.getX(), e.getY()), |
662 |
null); |
663 |
statusBar.setXPosition((float)p2d.getX()); |
664 |
statusBar.setYPosition((float)p2d.getY()); |
665 |
return; |
666 |
} |
667 |
} catch (NoninvertibleTransformException ex) { |
668 |
} |
669 |
statusBar.setXPosition(e.getX()); |
670 |
statusBar.setYPosition(e.getY()); |
671 |
} |
672 |
} |
673 |
}); |
674 |
svgCanvas.addMouseListener(new MouseAdapter() { |
675 |
public void mouseExited(MouseEvent e) { |
676 |
Dimension dim = svgCanvas.getSize(); |
677 |
if (svgDocument == null) { |
678 |
statusBar.setWidth(dim.width); |
679 |
statusBar.setHeight(dim.height); |
680 |
} else { |
681 |
try { |
682 |
AffineTransform at; |
683 |
at = svgCanvas.getViewBoxTransform(); |
684 |
if (at != null) { |
685 |
at = at.createInverse(); |
686 |
Point2D o = |
687 |
at.transform(new Point2D.Float(0, 0), |
688 |
null); |
689 |
Point2D p2d = |
690 |
at.transform(new Point2D.Float(dim.width, |
691 |
dim.height), |
692 |
null); |
693 |
statusBar.setWidth((float)(p2d.getX() - o.getX())); |
694 |
statusBar.setHeight((float)(p2d.getY() - o.getY())); |
695 |
return; |
696 |
} |
697 |
} catch (NoninvertibleTransformException ex) { |
698 |
} |
699 |
statusBar.setWidth(dim.width); |
700 |
statusBar.setHeight(dim.height); |
701 |
} |
702 |
} |
703 |
}); |
704 |
svgCanvas.addComponentListener(new ComponentAdapter() { |
705 |
public void componentResized(ComponentEvent e) { |
706 |
Dimension dim = svgCanvas.getSize(); |
707 |
if (svgDocument == null) { |
708 |
statusBar.setWidth(dim.width); |
709 |
statusBar.setHeight(dim.height); |
710 |
} else { |
711 |
try { |
712 |
AffineTransform at; |
713 |
at = svgCanvas.getViewBoxTransform(); |
714 |
if (at != null) { |
715 |
at = at.createInverse(); |
716 |
Point2D o = |
717 |
at.transform(new Point2D.Float(0, 0), |
718 |
null); |
719 |
Point2D p2d = |
720 |
at.transform(new Point2D.Float(dim.width, |
721 |
dim.height), |
722 |
null); |
723 |
statusBar.setWidth((float)(p2d.getX() - o.getX())); |
724 |
statusBar.setHeight((float)(p2d.getY() - o.getY())); |
725 |
return; |
726 |
} |
727 |
} catch (NoninvertibleTransformException ex) { |
728 |
} |
729 |
statusBar.setWidth(dim.width); |
730 |
statusBar.setHeight(dim.height); |
731 |
} |
732 |
} |
733 |
}); |
734 |
|
487 |
|
735 |
locationBar.addActionListener(new AbstractAction() { |
488 |
/** |
736 |
public void actionPerformed(ActionEvent e) { |
489 |
* The transform dialog |
737 |
String st = locationBar.getText().trim(); |
490 |
*/ |
738 |
int i = st.indexOf( '#' ); |
491 |
protected JAffineTransformChooser.Dialog transformDialog; |
739 |
String t = ""; |
|
|
740 |
if (i != -1) { |
741 |
t = st.substring(i + 1); |
742 |
st = st.substring(0, i); |
743 |
} |
744 |
|
492 |
|
745 |
if (st.equals("")) |
493 |
/** |
746 |
return; |
494 |
* The location bar. |
|
|
495 |
*/ |
496 |
protected LocationBar locationBar; |
747 |
|
497 |
|
748 |
try{ |
498 |
/** |
749 |
File f = new File(st); |
499 |
* The status bar. |
750 |
if (f.exists()) { |
500 |
*/ |
751 |
if (f.isDirectory()) { |
501 |
protected StatusBar statusBar; |
752 |
return; |
|
|
753 |
} else { |
754 |
try { |
755 |
st = f.getCanonicalPath(); |
756 |
if (st.startsWith("/")) { |
757 |
st = "file:" + st; |
758 |
} else { |
759 |
st = "file:/" + st; |
760 |
} |
761 |
} catch (IOException ex) { |
762 |
} |
763 |
} |
764 |
} |
765 |
}catch(SecurityException se){ |
766 |
// Could not patch the file URI for security |
767 |
// reasons (e.g., when run as an unsigned |
768 |
// JavaWebStart jar): file access is not |
769 |
// allowed. Loading will fail, but there is |
770 |
// nothing more to do at this point. |
771 |
} |
772 |
|
502 |
|
773 |
String fi = svgCanvas.getFragmentIdentifier(); |
503 |
/** |
774 |
if (svgDocument != null) { |
504 |
* The initial frame title. |
775 |
ParsedURL docPURL |
505 |
*/ |
776 |
= new ParsedURL(svgDocument.getURL()); |
506 |
protected String title; |
777 |
ParsedURL purl = new ParsedURL(docPURL, st); |
|
|
778 |
fi = (fi == null) ? "" : fi; |
779 |
if (docPURL.equals(purl) && t.equals(fi)) { |
780 |
return; |
781 |
} |
782 |
} |
783 |
if (t.length() != 0) { |
784 |
st += '#' + t; |
785 |
} |
786 |
locationBar.setText(st); |
787 |
locationBar.addToHistory(st); |
788 |
showSVGDocument(st); |
789 |
} |
790 |
}); |
791 |
} |
792 |
|
507 |
|
793 |
/** |
508 |
/** |
794 |
* Call dispose on canvas as well. |
509 |
* The local history. |
795 |
*/ |
510 |
*/ |
796 |
public void dispose() { |
511 |
protected LocalHistory localHistory; |
797 |
hideDebugger(); |
|
|
798 |
svgCanvas.dispose(); |
799 |
super.dispose(); |
800 |
} |
801 |
|
512 |
|
802 |
/** |
513 |
/** |
803 |
* Whether to show the debug traces. |
514 |
* The transform history. |
804 |
*/ |
515 |
*/ |
805 |
public void setDebug(boolean b) { |
516 |
protected TransformHistory transformHistory = new TransformHistory(); |
806 |
debug = b; |
|
|
807 |
} |
808 |
|
517 |
|
809 |
/** |
518 |
/** |
810 |
* Whether to auto adjust the canvas to the size of the document. |
519 |
* The alternate style-sheet title. |
811 |
*/ |
520 |
*/ |
812 |
public void setAutoAdjust(boolean b) { |
521 |
protected String alternateStyleSheet; |
813 |
autoAdjust = b; |
|
|
814 |
} |
815 |
|
522 |
|
816 |
/** |
523 |
/** |
817 |
* Returns the main JSVGCanvas of this frame. |
524 |
* The debugger object. |
818 |
*/ |
525 |
*/ |
819 |
public JSVGCanvas getJSVGCanvas() { |
526 |
protected Debugger debugger; |
820 |
return svgCanvas; |
|
|
821 |
} |
822 |
|
527 |
|
823 |
/** |
528 |
/** |
824 |
* Needed to work-around JFileChooser bug with abstract Files |
529 |
* Creates a new SVG viewer frame. |
825 |
*/ |
530 |
*/ |
826 |
private static File makeAbsolute(File f){ |
531 |
public JSVGViewerFrame(Application app) { |
827 |
if(!f.isAbsolute()){ |
532 |
application = app; |
828 |
return f.getAbsoluteFile(); |
|
|
829 |
} |
830 |
return f; |
831 |
} |
832 |
|
533 |
|
833 |
/** |
534 |
addWindowListener(new WindowAdapter() { |
834 |
* Shows the Rhino debugger. |
535 |
public void windowClosing(WindowEvent e) { |
835 |
*/ |
536 |
application.closeJSVGViewerFrame(JSVGViewerFrame.this); |
836 |
public void showDebugger() { |
537 |
} |
837 |
if (debugger == null && Debugger.isPresent) { |
538 |
}); |
838 |
debugger = new Debugger(this, locationBar.getText()); |
|
|
839 |
debugger.initialize(); |
840 |
} |
841 |
} |
842 |
|
539 |
|
843 |
/** |
540 |
// |
844 |
* Hides and destroys the Rhino debugger. |
541 |
// Set the frame's maximum size so that content |
845 |
*/ |
542 |
// bigger than the screen does not cause the creation |
846 |
public void hideDebugger() { |
543 |
// of unnecessary large images. |
847 |
if (debugger != null) { |
544 |
// |
848 |
debugger.clearAllBreakpoints(); |
545 |
svgCanvas = new Canvas(userAgent, true, true) { |
849 |
debugger.go(); |
546 |
Dimension screenSize; |
850 |
debugger.dispose(); |
|
|
851 |
debugger = null; |
852 |
} |
853 |
} |
854 |
|
547 |
|
855 |
/** |
548 |
{ |
856 |
* Rhino debugger class. |
549 |
screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
857 |
*/ |
550 |
setMaximumSize(screenSize); |
858 |
protected static class Debugger { |
551 |
} |
859 |
|
552 |
|
860 |
/** |
553 |
public Dimension getPreferredSize() { |
861 |
* Whether the Rhino debugger classes are present. |
554 |
Dimension s = super.getPreferredSize(); |
862 |
*/ |
555 |
if (s.width > screenSize.width) |
863 |
protected static boolean isPresent; |
556 |
s.width = screenSize.width; |
|
|
557 |
if (s.height > screenSize.height) |
558 |
s.height = screenSize.height; |
559 |
return s; |
560 |
} |
864 |
|
561 |
|
865 |
/** |
562 |
/** |
866 |
* The Rhino debugger class. |
563 |
* This method is called when the component knows the desired size |
867 |
*/ |
564 |
* of the window (based on width/height of outermost SVG element). |
868 |
protected static Class debuggerClass; |
565 |
* We override it to immediately pack this frame. |
|
|
566 |
*/ |
567 |
public void setMySize(Dimension d) { |
568 |
setPreferredSize(d); |
569 |
invalidate(); |
570 |
if (JSVGViewerFrame.this.autoAdjust) { |
571 |
Platform.unmaximize(JSVGViewerFrame.this); |
572 |
JSVGViewerFrame.this.pack(); |
573 |
} |
574 |
} |
869 |
|
575 |
|
870 |
/** |
576 |
public void setDisableInteractions(boolean b) { |
871 |
* The Rhino ContextFactory class. |
577 |
super.setDisableInteractions(b); |
872 |
*/ |
|
|
873 |
protected static Class contextFactoryClass; |
874 |
|
578 |
|
875 |
// Indexes into the debuggerMethods array. |
579 |
// Disable/Enable all our different ways to adjust the |
876 |
protected static final int CLEAR_ALL_BREAKPOINTS_METHOD = 0; |
580 |
// rendering transform (menus, toolbar, thumbnail, keyboard). |
877 |
protected static final int GO_METHOD = 1; |
|
|
878 |
protected static final int SET_EXIT_ACTION_METHOD = 2; |
879 |
protected static final int ATTACH_TO_METHOD = 3; |
880 |
protected static final int DETACH_METHOD = 4; |
881 |
protected static final int DISPOSE_METHOD = 5; |
882 |
protected static final int GET_DEBUG_FRAME_METHOD = 6; |
883 |
|
581 |
|
884 |
/** |
582 |
((Action) listeners.get(SET_TRANSFORM_ACTION)).setEnabled(!b); |
885 |
* Rhino debugger class constructor. |
|
|
886 |
*/ |
887 |
protected static Constructor debuggerConstructor; |
888 |
|
583 |
|
889 |
/** |
584 |
if (thumbnailDialog != null) |
890 |
* Rhino debugger class methods. |
585 |
thumbnailDialog.setInteractionEnabled(!b); |
891 |
*/ |
586 |
} |
892 |
protected static Method[] debuggerMethods; |
587 |
}; |
893 |
|
588 |
|
894 |
/** |
589 |
javax.swing.ActionMap map = svgCanvas.getActionMap(); |
895 |
* The RhinoInterpreter class. |
590 |
map.put(FULL_SCREEN_ACTION, new FullScreenAction()); |
896 |
*/ |
591 |
javax.swing.InputMap imap = svgCanvas |
897 |
protected static Class rhinoInterpreterClass; |
592 |
.getInputMap(JComponent.WHEN_FOCUSED); |
|
|
593 |
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0); |
594 |
imap.put(key, FULL_SCREEN_ACTION); |
898 |
|
595 |
|
899 |
/** |
596 |
svgCanvas.setDoubleBufferedRendering(true); |
900 |
* The {@code getContextFactory} method on the {@link |
|
|
901 |
* org.apache.batik.script.rhino.RhinoInterpreter} class. |
902 |
*/ |
903 |
protected static Method getContextFactoryMethod; |
904 |
|
597 |
|
905 |
static { |
598 |
listeners.put(ABOUT_ACTION, new AboutAction()); |
906 |
try { |
599 |
listeners.put(OPEN_ACTION, new OpenAction()); |
907 |
Class dc = |
600 |
listeners.put(OPEN_LOCATION_ACTION, new OpenLocationAction()); |
908 |
Class.forName("org.mozilla.javascript.tools.debugger.Main"); |
601 |
listeners.put(NEW_WINDOW_ACTION, new NewWindowAction()); |
909 |
Class cfc = |
602 |
listeners.put(RELOAD_ACTION, new ReloadAction()); |
910 |
Class.forName("org.mozilla.javascript.ContextFactory"); |
603 |
listeners.put(SAVE_AS_ACTION, new SaveAsAction()); |
911 |
rhinoInterpreterClass = Class.forName |
604 |
listeners.put(BACK_ACTION, backAction); |
912 |
("org.apache.batik.script.rhino.RhinoInterpreter"); |
605 |
listeners.put(FORWARD_ACTION, forwardAction); |
913 |
debuggerConstructor = |
606 |
listeners.put(PRINT_ACTION, new PrintAction()); |
914 |
dc.getConstructor(new Class[] { String.class }); |
607 |
listeners.put(EXPORT_AS_JPG_ACTION, new ExportAsJPGAction()); |
915 |
debuggerMethods = new Method[] { |
608 |
listeners.put(EXPORT_AS_PNG_ACTION, new ExportAsPNGAction()); |
916 |
dc.getMethod("clearAllBreakpoints", (Class[]) null), |
609 |
listeners.put(EXPORT_AS_TIFF_ACTION, new ExportAsTIFFAction()); |
917 |
dc.getMethod("go", (Class[]) null), |
610 |
listeners.put(PREFERENCES_ACTION, new PreferencesAction()); |
918 |
dc.getMethod("setExitAction", new Class[] {Runnable.class}), |
611 |
listeners.put(CLOSE_ACTION, new CloseAction()); |
919 |
dc.getMethod("attachTo", new Class[] { cfc }), |
612 |
listeners.put(EXIT_ACTION, application.createExitAction(this)); |
920 |
dc.getMethod("detach", (Class[]) null), |
613 |
listeners.put(VIEW_SOURCE_ACTION, new ViewSourceAction()); |
921 |
dc.getMethod("dispose", (Class[]) null), |
|
|
922 |
dc.getMethod("getDebugFrame", (Class[]) null) |
923 |
}; |
924 |
getContextFactoryMethod = |
925 |
rhinoInterpreterClass.getMethod("getContextFactory", |
926 |
(Class[]) null); |
927 |
debuggerClass = dc; |
928 |
isPresent = true; |
929 |
} catch (ClassNotFoundException cnfe) { |
930 |
} catch (NoSuchMethodException nsme) { |
931 |
} catch (SecurityException se) { |
932 |
} |
933 |
} |
934 |
|
614 |
|
935 |
/** |
615 |
javax.swing.ActionMap cMap = svgCanvas.getActionMap(); |
936 |
* The Rhino debugger instance. |
616 |
listeners.put(RESET_TRANSFORM_ACTION, cMap |
937 |
*/ |
617 |
.get(JSVGCanvas.RESET_TRANSFORM_ACTION)); |
938 |
protected Object debuggerInstance; |
618 |
listeners.put(ZOOM_IN_ACTION, cMap.get(JSVGCanvas.ZOOM_IN_ACTION)); |
|
|
619 |
listeners.put(ZOOM_OUT_ACTION, cMap.get(JSVGCanvas.ZOOM_OUT_ACTION)); |
939 |
|
620 |
|
940 |
/** |
621 |
listeners.put(PREVIOUS_TRANSFORM_ACTION, previousTransformAction); |
941 |
* The JSVGViewerFrame. |
622 |
key = KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.CTRL_MASK); |
942 |
*/ |
623 |
imap.put(key, previousTransformAction); |
943 |
protected JSVGViewerFrame svgFrame; |
|
|
944 |
|
624 |
|
945 |
/** |
625 |
listeners.put(NEXT_TRANSFORM_ACTION, nextTransformAction); |
946 |
* Creates a new Debugger. |
626 |
key = KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_MASK); |
947 |
*/ |
627 |
imap.put(key, nextTransformAction); |
948 |
public Debugger(JSVGViewerFrame frame, String url) { |
|
|
949 |
svgFrame = frame; |
950 |
try { |
951 |
debuggerInstance = debuggerConstructor.newInstance |
952 |
(new Object[] { "JavaScript Debugger - " + url }); |
953 |
} catch (IllegalAccessException iae) { |
954 |
throw new RuntimeException(iae.getMessage()); |
955 |
} catch (InvocationTargetException ite) { |
956 |
ite.printStackTrace(); |
957 |
throw new RuntimeException(ite.getMessage()); |
958 |
} catch (InstantiationException ie) { |
959 |
throw new RuntimeException(ie.getMessage()); |
960 |
} |
961 |
} |
962 |
|
628 |
|
963 |
/** |
629 |
listeners.put(USE_STYLESHEET_ACTION, useStylesheetAction); |
964 |
* Sets the document URL to use in the window title. |
630 |
listeners.put(PLAY_ACTION, playAction); |
965 |
*/ |
631 |
listeners.put(PAUSE_ACTION, pauseAction); |
966 |
public void setDocumentURL(String url) { |
632 |
listeners.put(STOP_ACTION, stopAction); |
967 |
getDebugFrame().setTitle("JavaScript Debugger - " + url); |
633 |
listeners.put(MONITOR_ACTION, new MonitorAction()); |
968 |
} |
634 |
listeners.put(DOM_VIEWER_ACTION, new DOMViewerAction()); |
|
|
635 |
listeners.put(TIMELINE_VIEWER_ACTION, new TimelineViewerAction()); |
636 |
listeners.put(SET_TRANSFORM_ACTION, new SetTransformAction()); |
637 |
listeners.put(FIND_DIALOG_ACTION, new FindDialogAction()); |
638 |
listeners.put(THUMBNAIL_DIALOG_ACTION, new ThumbnailDialogAction()); |
639 |
listeners.put(FLUSH_ACTION, new FlushAction()); |
640 |
listeners.put(TOGGLE_DEBUGGER_ACTION, new ToggleDebuggerAction()); |
969 |
|
641 |
|
970 |
/** |
642 |
JPanel p = null; |
971 |
* Initializes the debugger by massaging the GUI and attaching it |
643 |
try { |
972 |
* to the Rhino interpreter's {@link |
644 |
// Create the menu |
973 |
* org.mozilla.javascript.ContextFactory}. |
645 |
MenuFactory mf = new MenuFactory(bundle, this); |
974 |
*/ |
646 |
JMenuBar mb = mf.createJMenuBar("MenuBar", application |
975 |
public void initialize() { |
647 |
.getUISpecialization()); |
976 |
// Customize the menubar a bit, disable menu |
648 |
setJMenuBar(mb); |
977 |
// items that can't be used and change 'Exit' to 'Close'. |
|
|
978 |
JFrame debugGui = getDebugFrame(); |
979 |
JMenuBar menuBar = debugGui.getJMenuBar(); |
980 |
JMenu menu = menuBar.getMenu(0); |
981 |
menu.getItem(0).setEnabled(false); // Open... |
982 |
menu.getItem(1).setEnabled(false); // Run... |
983 |
menu.getItem(3).setText |
984 |
(Resources.getString("Close.text")); // Exit -> "Close" |
985 |
menu.getItem(3).setAccelerator |
986 |
(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK)); |
987 |
|
649 |
|
988 |
debugGui.setSize(600, 460); |
650 |
localHistory = new LocalHistory(mb, this); |
989 |
debugGui.pack(); |
|
|
990 |
setExitAction(new Runnable() { |
991 |
public void run() { |
992 |
svgFrame.hideDebugger(); |
993 |
}}); |
994 |
WindowAdapter wa = new WindowAdapter() { |
995 |
public void windowClosing(WindowEvent e) { |
996 |
svgFrame.hideDebugger(); |
997 |
}}; |
998 |
debugGui.addWindowListener(wa); |
999 |
debugGui.setVisible(true); |
1000 |
attach(); |
1001 |
} |
1002 |
|
651 |
|
1003 |
/** |
652 |
String[] uri = application.getVisitedURIs(); |
1004 |
* Attaches the debugger to the canvas' current interpreter. |
653 |
for (int i = 0; i < uri.length; i++) { |
1005 |
*/ |
654 |
if (uri[i] != null && !"".equals(uri[i])) { |
1006 |
public void attach() { |
655 |
localHistory.update(uri[i]); |
1007 |
Object interpreter = svgFrame.svgCanvas.getRhinoInterpreter(); |
656 |
} |
1008 |
if (interpreter != null) { |
657 |
} |
1009 |
attachTo(getContextFactory(interpreter)); |
658 |
p = new JPanel(new BorderLayout()); |
1010 |
} |
|
|
1011 |
} |
1012 |
|
659 |
|
1013 |
/** |
660 |
// Create the toolbar |
1014 |
* Calls {@code getDebugFrame} on {@link #debuggerInstance}. |
661 |
ToolBarFactory tbf = new ToolBarFactory(bundle, this); |
1015 |
*/ |
662 |
JToolBar tb = tbf.createJToolBar("ToolBar"); |
1016 |
protected JFrame getDebugFrame() { |
663 |
tb.setFloatable(false); |
1017 |
try { |
664 |
getContentPane().add(p, BorderLayout.NORTH); |
1018 |
return (JFrame) debuggerMethods[GET_DEBUG_FRAME_METHOD].invoke |
665 |
p.add(tb, BorderLayout.NORTH); |
1019 |
(debuggerInstance, (Object[]) null); |
666 |
p.add(new javax.swing.JSeparator(), BorderLayout.CENTER); |
1020 |
} catch (InvocationTargetException ite) { |
667 |
p.add(locationBar = new LocationBar(), BorderLayout.SOUTH); |
1021 |
throw new RuntimeException(ite.getMessage()); |
668 |
locationBar.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
1022 |
} catch (IllegalAccessException iae) { |
|
|
1023 |
throw new RuntimeException(iae.getMessage()); |
1024 |
} |
1025 |
} |
1026 |
|
669 |
|
1027 |
/** |
670 |
} catch (MissingResourceException e) { |
1028 |
* Calls {@code setExitAction} on {@link #debuggerInstance}. |
671 |
System.out.println(e.getMessage()); |
1029 |
*/ |
672 |
System.exit(0); |
1030 |
protected void setExitAction(Runnable r) { |
673 |
} |
1031 |
try { |
|
|
1032 |
debuggerMethods[SET_EXIT_ACTION_METHOD].invoke |
1033 |
(debuggerInstance, new Object[] { r }); |
1034 |
} catch (InvocationTargetException ite) { |
1035 |
throw new RuntimeException(ite.getMessage()); |
1036 |
} catch (IllegalAccessException iae) { |
1037 |
throw new RuntimeException(iae.getMessage()); |
1038 |
} |
1039 |
} |
1040 |
|
674 |
|
1041 |
/** |
675 |
svgCanvasPanel = new JPanel(new BorderLayout()); |
1042 |
* Calls {@code attachTo} on {@link #debuggerInstance}. |
676 |
svgCanvasPanel.setBorder(BorderFactory.createEtchedBorder()); |
1043 |
*/ |
|
|
1044 |
public void attachTo(Object contextFactory) { |
1045 |
try { |
1046 |
debuggerMethods[ATTACH_TO_METHOD].invoke |
1047 |
(debuggerInstance, new Object[] { contextFactory }); |
1048 |
} catch (InvocationTargetException ite) { |
1049 |
throw new RuntimeException(ite.getMessage()); |
1050 |
} catch (IllegalAccessException iae) { |
1051 |
throw new RuntimeException(iae.getMessage()); |
1052 |
} |
1053 |
} |
1054 |
|
677 |
|
1055 |
/** |
678 |
svgCanvasPanel.add(svgCanvas, BorderLayout.CENTER); |
1056 |
* Calls {@code detach} on {@link #debuggerInstance}. |
679 |
p = new JPanel(new BorderLayout()); |
1057 |
*/ |
680 |
p.add(svgCanvasPanel, BorderLayout.CENTER); |
1058 |
public void detach() { |
681 |
p.add(statusBar = new StatusBar(), BorderLayout.SOUTH); |
1059 |
try { |
|
|
1060 |
debuggerMethods[DETACH_METHOD].invoke(debuggerInstance, |
1061 |
(Object[]) null); |
1062 |
} catch (InvocationTargetException ite) { |
1063 |
throw new RuntimeException(ite.getMessage()); |
1064 |
} catch (IllegalAccessException iae) { |
1065 |
throw new RuntimeException(iae.getMessage()); |
1066 |
} |
1067 |
} |
1068 |
|
682 |
|
1069 |
/** |
683 |
getContentPane().add(p, BorderLayout.CENTER); |
1070 |
* Calls {@code go} on {@link #debuggerInstance}. |
|
|
1071 |
*/ |
1072 |
public void go() { |
1073 |
try { |
1074 |
debuggerMethods[GO_METHOD].invoke(debuggerInstance, |
1075 |
(Object[]) null); |
1076 |
} catch (InvocationTargetException ite) { |
1077 |
throw new RuntimeException(ite.getMessage()); |
1078 |
} catch (IllegalAccessException iae) { |
1079 |
throw new RuntimeException(iae.getMessage()); |
1080 |
} |
1081 |
} |
1082 |
|
684 |
|
1083 |
/** |
685 |
svgCanvas.addSVGDocumentLoaderListener(this); |
1084 |
* Calls {@code clearAllBreakpoints} on {@link #debuggerInstance}. |
686 |
svgCanvas.addGVTTreeBuilderListener(this); |
1085 |
*/ |
687 |
svgCanvas.addSVGLoadEventDispatcherListener(this); |
1086 |
public void clearAllBreakpoints() { |
688 |
svgCanvas.addGVTTreeRendererListener(this); |
1087 |
try { |
689 |
svgCanvas.addLinkActivationListener(this); |
1088 |
debuggerMethods[CLEAR_ALL_BREAKPOINTS_METHOD].invoke |
690 |
svgCanvas.addUpdateManagerListener(this); |
1089 |
(debuggerInstance, (Object[]) null); |
|
|
1090 |
} catch (InvocationTargetException ite) { |
1091 |
throw new RuntimeException(ite.getMessage()); |
1092 |
} catch (IllegalAccessException iae) { |
1093 |
throw new RuntimeException(iae.getMessage()); |
1094 |
} |
1095 |
} |
1096 |
|
691 |
|
1097 |
/** |
692 |
svgCanvas.addMouseMotionListener(new MouseMotionAdapter() { |
1098 |
* Calls {@code dispose} on {@link #debuggerInstance}. |
693 |
public void mouseMoved(MouseEvent e) { |
1099 |
*/ |
694 |
if (svgDocument == null) { |
1100 |
public void dispose() { |
695 |
statusBar.setXPosition(e.getX()); |
1101 |
try { |
696 |
statusBar.setYPosition(e.getY()); |
1102 |
debuggerMethods[DISPOSE_METHOD].invoke(debuggerInstance, |
697 |
} else { |
1103 |
(Object[]) null); |
698 |
try { |
1104 |
} catch (InvocationTargetException ite) { |
699 |
AffineTransform at; |
1105 |
throw new RuntimeException(ite.getMessage()); |
700 |
at = svgCanvas.getViewBoxTransform(); |
1106 |
} catch (IllegalAccessException iae) { |
701 |
if (at != null) { |
1107 |
throw new RuntimeException(iae.getMessage()); |
702 |
at = at.createInverse(); |
1108 |
} |
703 |
Point2D p2d = at.transform(new Point2D.Float(e |
1109 |
} |
704 |
.getX(), e.getY()), null); |
|
|
705 |
statusBar.setXPosition((float) p2d.getX()); |
706 |
statusBar.setYPosition((float) p2d.getY()); |
707 |
return; |
708 |
} |
709 |
} catch (NoninvertibleTransformException ex) { |
710 |
} |
711 |
statusBar.setXPosition(e.getX()); |
712 |
statusBar.setYPosition(e.getY()); |
713 |
} |
714 |
} |
715 |
}); |
716 |
svgCanvas.addMouseListener(new MouseAdapter() { |
717 |
public void mouseExited(MouseEvent e) { |
718 |
Dimension dim = svgCanvas.getSize(); |
719 |
if (svgDocument == null) { |
720 |
statusBar.setWidth(dim.width); |
721 |
statusBar.setHeight(dim.height); |
722 |
} else { |
723 |
try { |
724 |
AffineTransform at; |
725 |
at = svgCanvas.getViewBoxTransform(); |
726 |
if (at != null) { |
727 |
at = at.createInverse(); |
728 |
Point2D o = at.transform(new Point2D.Float(0, 0), |
729 |
null); |
730 |
Point2D p2d = at.transform(new Point2D.Float( |
731 |
dim.width, dim.height), null); |
732 |
statusBar.setWidth((float) (p2d.getX() - o.getX())); |
733 |
statusBar |
734 |
.setHeight((float) (p2d.getY() - o.getY())); |
735 |
return; |
736 |
} |
737 |
} catch (NoninvertibleTransformException ex) { |
738 |
} |
739 |
statusBar.setWidth(dim.width); |
740 |
statusBar.setHeight(dim.height); |
741 |
} |
742 |
} |
743 |
}); |
744 |
svgCanvas.addComponentListener(new ComponentAdapter() { |
745 |
public void componentResized(ComponentEvent e) { |
746 |
Dimension dim = svgCanvas.getSize(); |
747 |
if (svgDocument == null) { |
748 |
statusBar.setWidth(dim.width); |
749 |
statusBar.setHeight(dim.height); |
750 |
} else { |
751 |
try { |
752 |
AffineTransform at; |
753 |
at = svgCanvas.getViewBoxTransform(); |
754 |
if (at != null) { |
755 |
at = at.createInverse(); |
756 |
Point2D o = at.transform(new Point2D.Float(0, 0), |
757 |
null); |
758 |
Point2D p2d = at.transform(new Point2D.Float( |
759 |
dim.width, dim.height), null); |
760 |
statusBar.setWidth((float) (p2d.getX() - o.getX())); |
761 |
statusBar |
762 |
.setHeight((float) (p2d.getY() - o.getY())); |
763 |
return; |
764 |
} |
765 |
} catch (NoninvertibleTransformException ex) { |
766 |
} |
767 |
statusBar.setWidth(dim.width); |
768 |
statusBar.setHeight(dim.height); |
769 |
} |
770 |
} |
771 |
}); |
1110 |
|
772 |
|
1111 |
/** |
773 |
locationBar.addActionListener(new AbstractAction() { |
1112 |
* Calls {@code getContextFactory} on the given instance of |
774 |
public void actionPerformed(ActionEvent e) { |
1113 |
* {@link org.apache.batik.script.rhino.RhinoInterpreter}. |
775 |
String st = locationBar.getText().trim(); |
1114 |
*/ |
776 |
int i = st.indexOf('#'); |
1115 |
protected Object getContextFactory(Object rhinoInterpreter) { |
777 |
String t = ""; |
1116 |
try { |
778 |
if (i != -1) { |
1117 |
return getContextFactoryMethod.invoke(rhinoInterpreter, |
779 |
t = st.substring(i + 1); |
1118 |
(Object[]) null); |
780 |
st = st.substring(0, i); |
1119 |
} catch (InvocationTargetException ite) { |
781 |
} |
1120 |
throw new RuntimeException(ite.getMessage()); |
|
|
1121 |
} catch (IllegalAccessException iae) { |
1122 |
throw new RuntimeException(iae.getMessage()); |
1123 |
} |
1124 |
} |
1125 |
} |
1126 |
|
782 |
|
1127 |
/** |
783 |
if (st.equals("")) |
1128 |
* To show the about dialog |
784 |
return; |
1129 |
*/ |
|
|
1130 |
public class AboutAction extends AbstractAction { |
1131 |
public AboutAction(){ |
1132 |
} |
1133 |
|
785 |
|
1134 |
public void actionPerformed(ActionEvent e){ |
786 |
try { |
1135 |
AboutDialog dlg = new AboutDialog(JSVGViewerFrame.this); |
787 |
File f = new File(st); |
1136 |
// Work around pack() bug on some platforms |
788 |
if (f.exists()) { |
1137 |
dlg.setSize(dlg.getPreferredSize()); |
789 |
if (f.isDirectory()) { |
1138 |
dlg.setLocationRelativeTo(JSVGViewerFrame.this); |
790 |
return; |
1139 |
dlg.setVisible(true); |
791 |
} else { |
1140 |
dlg.toFront(); |
792 |
try { |
1141 |
} |
793 |
st = f.getCanonicalPath(); |
1142 |
} |
794 |
if (st.startsWith("/")) { |
|
|
795 |
st = "file:" + st; |
796 |
} else { |
797 |
st = "file:/" + st; |
798 |
} |
799 |
} catch (IOException ex) { |
800 |
} |
801 |
} |
802 |
} |
803 |
} catch (SecurityException se) { |
804 |
// Could not patch the file URI for security |
805 |
// reasons (e.g., when run as an unsigned |
806 |
// JavaWebStart jar): file access is not |
807 |
// allowed. Loading will fail, but there is |
808 |
// nothing more to do at this point. |
809 |
} |
1143 |
|
810 |
|
1144 |
/** |
811 |
String fi = svgCanvas.getFragmentIdentifier(); |
1145 |
* To open a new file. |
812 |
if (svgDocument != null) { |
1146 |
*/ |
813 |
ParsedURL docPURL = new ParsedURL(svgDocument.getURL()); |
1147 |
public class OpenAction extends AbstractAction { |
814 |
ParsedURL purl = new ParsedURL(docPURL, st); |
|
|
815 |
fi = (fi == null) ? "" : fi; |
816 |
if (docPURL.equals(purl) && t.equals(fi)) { |
817 |
return; |
818 |
} |
819 |
} |
820 |
if (t.length() != 0) { |
821 |
st += '#' + t; |
822 |
} |
823 |
locationBar.setText(st); |
824 |
locationBar.addToHistory(st); |
825 |
showSVGDocument(st); |
826 |
} |
827 |
}); |
828 |
} |
1148 |
|
829 |
|
1149 |
public OpenAction() { |
830 |
/** |
1150 |
} |
831 |
* Call dispose on canvas as well. |
1151 |
public void actionPerformed(ActionEvent e) { |
832 |
*/ |
1152 |
File f = null; |
833 |
public void dispose() { |
1153 |
if (Platform.isOSX) { |
834 |
hideDebugger(); |
1154 |
FileDialog fileDialog = |
835 |
svgCanvas.dispose(); |
1155 |
new FileDialog(JSVGViewerFrame.this, |
836 |
super.dispose(); |
1156 |
Resources.getString(OPEN_TITLE)); |
837 |
} |
1157 |
fileDialog.setFilenameFilter(new FilenameFilter() { |
|
|
1158 |
public boolean accept(File dir, String name) { |
1159 |
Iterator iter = getHandlers().iterator(); |
1160 |
while (iter.hasNext()) { |
1161 |
SquiggleInputHandler handler |
1162 |
= (SquiggleInputHandler)iter.next(); |
1163 |
if (handler.accept(new File(dir, name))) { |
1164 |
return true; |
1165 |
} |
1166 |
} |
1167 |
return false; |
1168 |
} |
1169 |
}); |
1170 |
fileDialog.setVisible(true); |
1171 |
String filename = fileDialog.getFile(); |
1172 |
if (fileDialog != null) { |
1173 |
String dirname = fileDialog.getDirectory(); |
1174 |
f = new File(dirname, filename); |
1175 |
} |
1176 |
} else { |
1177 |
JFileChooser fileChooser = null; |
1178 |
|
838 |
|
1179 |
// Apply work around Windows problem when security is enabled, |
839 |
/** |
1180 |
// and when prior to JDK 1.4. |
840 |
* Whether to show the debug traces. |
1181 |
String os = System.getProperty(PROPERTY_OS_NAME, PROPERTY_OS_NAME_DEFAULT); |
841 |
*/ |
1182 |
SecurityManager sm = System.getSecurityManager(); |
842 |
public void setDebug(boolean b) { |
|
|
843 |
debug = b; |
844 |
} |
1183 |
|
845 |
|
1184 |
if ( priorJDK1_4 && sm != null && os.indexOf(PROPERTY_OS_WINDOWS_PREFIX) != -1 ){ |
846 |
/** |
1185 |
fileChooser = new JFileChooser(makeAbsolute(currentPath), |
847 |
* Whether to auto adjust the canvas to the size of the document. |
1186 |
new WindowsAltFileSystemView()); |
848 |
*/ |
1187 |
} else { |
849 |
public void setAutoAdjust(boolean b) { |
1188 |
fileChooser = new JFileChooser(makeAbsolute(currentPath)); |
850 |
autoAdjust = b; |
1189 |
} |
851 |
} |
1190 |
|
852 |
|
1191 |
fileChooser.setFileHidingEnabled(false); |
853 |
/** |
1192 |
fileChooser.setFileSelectionMode |
854 |
* Returns the main JSVGCanvas of this frame. |
1193 |
(JFileChooser.FILES_ONLY); |
855 |
*/ |
|
|
856 |
public JSVGCanvas getJSVGCanvas() { |
857 |
return svgCanvas; |
858 |
} |
1194 |
|
859 |
|
1195 |
// |
860 |
/** |
1196 |
// Add file filters from the handlers map |
861 |
* Needed to work-around JFileChooser bug with abstract Files |
1197 |
// |
862 |
*/ |
1198 |
Iterator iter = getHandlers().iterator(); |
863 |
private static File makeAbsolute(File f) { |
1199 |
while (iter.hasNext()) { |
864 |
if (!f.isAbsolute()) { |
1200 |
SquiggleInputHandler handler |
865 |
return f.getAbsoluteFile(); |
1201 |
= (SquiggleInputHandler)iter.next(); |
866 |
} |
1202 |
fileChooser.addChoosableFileFilter |
867 |
return f; |
1203 |
(new SquiggleInputHandlerFilter(handler)); |
868 |
} |
1204 |
} |
|
|
1205 |
|
869 |
|
1206 |
int choice = fileChooser.showOpenDialog(JSVGViewerFrame.this); |
870 |
/** |
1207 |
if (choice == JFileChooser.APPROVE_OPTION) { |
871 |
* Shows the Rhino debugger. |
1208 |
f = fileChooser.getSelectedFile(); |
872 |
*/ |
1209 |
currentPath = f; |
873 |
public void showDebugger() { |
1210 |
} |
874 |
if (debugger == null && Debugger.isPresent) { |
1211 |
} |
875 |
debugger = new Debugger(this, locationBar.getText()); |
|
|
876 |
debugger.initialize(); |
877 |
} |
878 |
} |
1212 |
|
879 |
|
1213 |
if (f != null) { |
880 |
/** |
1214 |
try { |
881 |
* Hides and destroys the Rhino debugger. |
1215 |
String furl = f.toURL().toString(); |
882 |
*/ |
1216 |
showSVGDocument(furl); |
883 |
public void hideDebugger() { |
1217 |
} catch (MalformedURLException ex) { |
884 |
if (debugger != null) { |
1218 |
if (userAgent != null) { |
885 |
debugger.clearAllBreakpoints(); |
1219 |
userAgent.displayError(ex); |
886 |
debugger.go(); |
1220 |
} |
887 |
debugger.dispose(); |
1221 |
} |
888 |
debugger = null; |
1222 |
} |
889 |
} |
1223 |
} |
890 |
} |
1224 |
} |
|
|
1225 |
|
891 |
|
1226 |
/** |
892 |
/** |
1227 |
* Shows the given document into the viewer frame |
893 |
* Rhino debugger class. |
1228 |
*/ |
894 |
*/ |
1229 |
public void showSVGDocument(String uri){ |
895 |
protected static class Debugger { |
1230 |
try { |
|
|
1231 |
ParsedURL purl = new ParsedURL(uri); |
1232 |
SquiggleInputHandler |
1233 |
handler = getInputHandler(purl); |
1234 |
|
896 |
|
1235 |
handler.handle(purl, |
897 |
/** |
1236 |
JSVGViewerFrame.this); |
898 |
* Whether the Rhino debugger classes are present. |
1237 |
} catch (Exception e) { |
899 |
*/ |
1238 |
if (userAgent != null) { |
900 |
protected static boolean isPresent; |
1239 |
userAgent.displayError(e); |
|
|
1240 |
} |
1241 |
} |
1242 |
|
901 |
|
1243 |
} |
902 |
/** |
|
|
903 |
* The Rhino debugger class. |
904 |
*/ |
905 |
protected static Class debuggerClass; |
1244 |
|
906 |
|
1245 |
/** |
907 |
/** |
1246 |
* Returns the input handler for the given URI |
908 |
* The Rhino ContextFactory class. |
1247 |
*/ |
909 |
*/ |
1248 |
public SquiggleInputHandler getInputHandler(ParsedURL purl) throws IOException { |
910 |
protected static Class contextFactoryClass; |
1249 |
Iterator iter = getHandlers().iterator(); |
|
|
1250 |
SquiggleInputHandler handler = null; |
1251 |
|
911 |
|
1252 |
while (iter.hasNext()) { |
912 |
// Indexes into the debuggerMethods array. |
1253 |
SquiggleInputHandler curHandler = |
913 |
protected static final int CLEAR_ALL_BREAKPOINTS_METHOD = 0; |
1254 |
(SquiggleInputHandler)iter.next(); |
|
|
1255 |
if (curHandler.accept(purl)) { |
1256 |
handler = curHandler; |
1257 |
break; |
1258 |
} |
1259 |
} |
1260 |
|
914 |
|
1261 |
// No handler found, use the default one. |
915 |
protected static final int GO_METHOD = 1; |
1262 |
if (handler == null) { |
|
|
1263 |
handler = defaultHandler; |
1264 |
} |
1265 |
|
916 |
|
1266 |
return handler; |
917 |
protected static final int SET_EXIT_ACTION_METHOD = 2; |
1267 |
} |
|
|
1268 |
|
918 |
|
|
|
919 |
protected static final int ATTACH_TO_METHOD = 3; |
1269 |
|
920 |
|
1270 |
/** |
921 |
protected static final int DETACH_METHOD = 4; |
1271 |
* Returns the list of input file handler. |
|
|
1272 |
*/ |
1273 |
protected static Vector getHandlers() { |
1274 |
if (handlers != null) { |
1275 |
return handlers; |
1276 |
} |
1277 |
|
922 |
|
1278 |
handlers = new Vector(); |
923 |
protected static final int DISPOSE_METHOD = 5; |
1279 |
registerHandler(new SVGInputHandler()); |
|
|
1280 |
|
924 |
|
1281 |
Iterator iter = Service.providers(SquiggleInputHandler.class); |
925 |
protected static final int GET_DEBUG_FRAME_METHOD = 6; |
1282 |
while (iter.hasNext()) { |
|
|
1283 |
SquiggleInputHandler handler |
1284 |
= (SquiggleInputHandler)iter.next(); |
1285 |
|
926 |
|
1286 |
registerHandler(handler); |
927 |
/** |
1287 |
} |
928 |
* Rhino debugger class constructor. |
|
|
929 |
*/ |
930 |
protected static Constructor debuggerConstructor; |
1288 |
|
931 |
|
1289 |
return handlers; |
932 |
/** |
1290 |
} |
933 |
* Rhino debugger class methods. |
|
|
934 |
*/ |
935 |
protected static Method[] debuggerMethods; |
1291 |
|
936 |
|
1292 |
/** |
937 |
/** |
1293 |
* Registers an input file handler by adding it to the handlers map. |
938 |
* The RhinoInterpreter class. |
1294 |
* @param handler the new input handler to register. |
939 |
*/ |
1295 |
*/ |
940 |
protected static Class rhinoInterpreterClass; |
1296 |
public static synchronized |
|
|
1297 |
void registerHandler(SquiggleInputHandler handler) { |
1298 |
Vector handlers = getHandlers(); |
1299 |
handlers.addElement(handler); |
1300 |
} |
1301 |
|
941 |
|
1302 |
/** |
942 |
/** |
1303 |
* To open a new document. |
943 |
* The {@code getContextFactory} method on the {@link |
1304 |
*/ |
944 |
* org.apache.batik.script.rhino.RhinoInterpreter} class. |
1305 |
public class OpenLocationAction extends AbstractAction { |
945 |
*/ |
1306 |
public OpenLocationAction() {} |
946 |
protected static Method getContextFactoryMethod; |
1307 |
public void actionPerformed(ActionEvent e) { |
|
|
1308 |
if (uriChooser == null) { |
1309 |
uriChooser = new URIChooser(JSVGViewerFrame.this); |
1310 |
uriChooser.setFileFilter(new SVGFileFilter()); |
1311 |
uriChooser.pack(); |
1312 |
Rectangle fr = getBounds(); |
1313 |
Dimension sd = uriChooser.getSize(); |
1314 |
uriChooser.setLocation(fr.x + (fr.width - sd.width) / 2, |
1315 |
fr.y + (fr.height - sd.height) / 2); |
1316 |
} |
1317 |
if (uriChooser.showDialog() == URIChooser.OK_OPTION) { |
1318 |
String s = uriChooser.getText(); |
1319 |
if (s == null) return; |
1320 |
int i = s.indexOf( '#' ); |
1321 |
String t = ""; |
1322 |
if (i != -1) { |
1323 |
t = s.substring(i + 1); |
1324 |
s = s.substring(0, i); |
1325 |
} |
1326 |
if (!s.equals("")) { |
1327 |
File f = new File(s); |
1328 |
if (f.exists()) { |
1329 |
if (f.isDirectory()) { |
1330 |
s = null; |
1331 |
} else { |
1332 |
try { |
1333 |
s = f.getCanonicalPath(); |
1334 |
if (s.startsWith("/")) { |
1335 |
s = "file:" + s; |
1336 |
} else { |
1337 |
s = "file:/" + s; |
1338 |
} |
1339 |
} catch (IOException ex) { |
1340 |
} |
1341 |
} |
1342 |
} |
1343 |
if (s != null) { |
1344 |
if (svgDocument != null) { |
1345 |
ParsedURL docPURL |
1346 |
= new ParsedURL(svgDocument.getURL()); |
1347 |
ParsedURL purl = new ParsedURL(docPURL, s); |
1348 |
String fi = svgCanvas.getFragmentIdentifier(); |
1349 |
if (docPURL.equals(purl) && t.equals(fi)) { |
1350 |
return; |
1351 |
} |
1352 |
} |
1353 |
if (t.length() != 0) { |
1354 |
s += '#' + t; |
1355 |
} |
1356 |
|
947 |
|
1357 |
showSVGDocument(s); |
948 |
static { |
1358 |
} |
949 |
try { |
1359 |
} |
950 |
Class dc = Class |
1360 |
} |
951 |
.forName("org.mozilla.javascript.tools.debugger.Main"); |
1361 |
} |
952 |
Class cfc = Class |
1362 |
} |
953 |
.forName("org.mozilla.javascript.ContextFactory"); |
|
|
954 |
rhinoInterpreterClass = Class |
955 |
.forName("org.apache.batik.script.rhino.RhinoInterpreter"); |
956 |
debuggerConstructor = dc |
957 |
.getConstructor(new Class[] { String.class }); |
958 |
debuggerMethods = new Method[] { |
959 |
dc.getMethod("clearAllBreakpoints", (Class[]) null), |
960 |
dc.getMethod("go", (Class[]) null), |
961 |
dc.getMethod("setExitAction", |
962 |
new Class[] { Runnable.class }), |
963 |
dc.getMethod("attachTo", new Class[] { cfc }), |
964 |
dc.getMethod("detach", (Class[]) null), |
965 |
dc.getMethod("dispose", (Class[]) null), |
966 |
dc.getMethod("getDebugFrame", (Class[]) null) }; |
967 |
getContextFactoryMethod = rhinoInterpreterClass.getMethod( |
968 |
"getContextFactory", (Class[]) null); |
969 |
debuggerClass = dc; |
970 |
isPresent = true; |
971 |
} catch (ClassNotFoundException cnfe) { |
972 |
} catch (NoSuchMethodException nsme) { |
973 |
} catch (SecurityException se) { |
974 |
} |
975 |
} |
1363 |
|
976 |
|
1364 |
/** |
977 |
/** |
1365 |
* To open a new window. |
978 |
* The Rhino debugger instance. |
1366 |
*/ |
979 |
*/ |
1367 |
public class NewWindowAction extends AbstractAction { |
980 |
protected Object debuggerInstance; |
1368 |
public NewWindowAction() {} |
|
|
1369 |
public void actionPerformed(ActionEvent e) { |
1370 |
JSVGViewerFrame vf = application.createAndShowJSVGViewerFrame(); |
1371 |
|
981 |
|
1372 |
// Copy the current settings to the new window. |
982 |
/** |
1373 |
vf.autoAdjust = autoAdjust; |
983 |
* The JSVGViewerFrame. |
1374 |
vf.debug = debug; |
984 |
*/ |
1375 |
vf.svgCanvas.setProgressivePaint(svgCanvas.getProgressivePaint()); |
985 |
protected JSVGViewerFrame svgFrame; |
1376 |
vf.svgCanvas.setDoubleBufferedRendering |
|
|
1377 |
(svgCanvas.getDoubleBufferedRendering()); |
1378 |
} |
1379 |
} |
1380 |
|
986 |
|
1381 |
/** |
987 |
/** |
1382 |
* To show the preferences. |
988 |
* Creates a new Debugger. |
1383 |
*/ |
989 |
*/ |
1384 |
public class PreferencesAction extends AbstractAction { |
990 |
public Debugger(JSVGViewerFrame frame, String url) { |
1385 |
public PreferencesAction() {} |
991 |
svgFrame = frame; |
1386 |
public void actionPerformed(ActionEvent e) { |
992 |
try { |
1387 |
application.showPreferenceDialog(JSVGViewerFrame.this); |
993 |
debuggerInstance = debuggerConstructor |
1388 |
} |
994 |
.newInstance(new Object[] { "JavaScript Debugger - " |
1389 |
} |
995 |
+ url }); |
|
|
996 |
} catch (IllegalAccessException iae) { |
997 |
throw new RuntimeException(iae.getMessage()); |
998 |
} catch (InvocationTargetException ite) { |
999 |
ite.printStackTrace(); |
1000 |
throw new RuntimeException(ite.getMessage()); |
1001 |
} catch (InstantiationException ie) { |
1002 |
throw new RuntimeException(ie.getMessage()); |
1003 |
} |
1004 |
} |
1390 |
|
1005 |
|
1391 |
/** |
1006 |
/** |
1392 |
* To close the last document. |
1007 |
* Sets the document URL to use in the window title. |
1393 |
*/ |
1008 |
*/ |
1394 |
public class CloseAction extends AbstractAction { |
1009 |
public void setDocumentURL(String url) { |
1395 |
public CloseAction() {} |
1010 |
getDebugFrame().setTitle("JavaScript Debugger - " + url); |
1396 |
public void actionPerformed(ActionEvent e) { |
1011 |
} |
1397 |
application.closeJSVGViewerFrame(JSVGViewerFrame.this); |
|
|
1398 |
} |
1399 |
} |
1400 |
|
1012 |
|
1401 |
/** |
1013 |
/** |
1402 |
* To reload the current document. |
1014 |
* Initializes the debugger by massaging the GUI and attaching it to the |
1403 |
*/ |
1015 |
* Rhino interpreter's {@link org.mozilla.javascript.ContextFactory}. |
1404 |
public class ReloadAction extends AbstractAction { |
1016 |
*/ |
1405 |
public ReloadAction() {} |
1017 |
public void initialize() { |
1406 |
public void actionPerformed(ActionEvent e) { |
1018 |
// Customize the menubar a bit, disable menu |
1407 |
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) == 1) { |
1019 |
// items that can't be used and change 'Exit' to 'Close'. |
1408 |
svgCanvas.flushImageCache(); |
1020 |
JFrame debugGui = getDebugFrame(); |
1409 |
} |
1021 |
JMenuBar menuBar = debugGui.getJMenuBar(); |
1410 |
if (svgDocument != null) { |
1022 |
JMenu menu = menuBar.getMenu(0); |
1411 |
localHistory.reload(); |
1023 |
menu.getItem(0).setEnabled(false); // Open... |
1412 |
} |
1024 |
menu.getItem(1).setEnabled(false); // Run... |
1413 |
} |
1025 |
menu.getItem(3).setText(Resources.getString("Close.text")); // Exit |
1414 |
} |
1026 |
// -> |
|
|
1027 |
// "Close" |
1028 |
menu.getItem(3).setAccelerator( |
1029 |
KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK)); |
1415 |
|
1030 |
|
1416 |
/** |
1031 |
debugGui.setSize(600, 460); |
1417 |
* To go back to the previous document |
1032 |
debugGui.pack(); |
1418 |
*/ |
1033 |
setExitAction(new Runnable() { |
1419 |
public class BackAction extends AbstractAction |
1034 |
public void run() { |
1420 |
implements JComponentModifier { |
1035 |
svgFrame.hideDebugger(); |
1421 |
List components = new LinkedList(); |
1036 |
} |
1422 |
public BackAction() {} |
1037 |
}); |
1423 |
public void actionPerformed(ActionEvent e) { |
1038 |
WindowAdapter wa = new WindowAdapter() { |
1424 |
if (localHistory.canGoBack()) { |
1039 |
public void windowClosing(WindowEvent e) { |
1425 |
localHistory.back(); |
1040 |
svgFrame.hideDebugger(); |
1426 |
} |
1041 |
} |
1427 |
} |
1042 |
}; |
|
|
1043 |
debugGui.addWindowListener(wa); |
1044 |
debugGui.setVisible(true); |
1045 |
attach(); |
1046 |
} |
1428 |
|
1047 |
|
1429 |
public void addJComponent(JComponent c) { |
1048 |
/** |
1430 |
components.add(c); |
1049 |
* Attaches the debugger to the canvas' current interpreter. |
1431 |
c.setEnabled(false); |
1050 |
*/ |
1432 |
} |
1051 |
public void attach() { |
|
|
1052 |
Object interpreter = svgFrame.svgCanvas.getRhinoInterpreter(); |
1053 |
if (interpreter != null) { |
1054 |
attachTo(getContextFactory(interpreter)); |
1055 |
} |
1056 |
} |
1433 |
|
1057 |
|
1434 |
protected void update() { |
1058 |
/** |
1435 |
boolean b = localHistory.canGoBack(); |
1059 |
* Calls {@code getDebugFrame} on {@link #debuggerInstance}. |
1436 |
Iterator it = components.iterator(); |
1060 |
*/ |
1437 |
while (it.hasNext()) { |
1061 |
protected JFrame getDebugFrame() { |
1438 |
((JComponent)it.next()).setEnabled(b); |
1062 |
try { |
1439 |
} |
1063 |
return (JFrame) debuggerMethods[GET_DEBUG_FRAME_METHOD].invoke( |
1440 |
} |
1064 |
debuggerInstance, (Object[]) null); |
1441 |
} |
1065 |
} catch (InvocationTargetException ite) { |
|
|
1066 |
throw new RuntimeException(ite.getMessage()); |
1067 |
} catch (IllegalAccessException iae) { |
1068 |
throw new RuntimeException(iae.getMessage()); |
1069 |
} |
1070 |
} |
1442 |
|
1071 |
|
1443 |
/** |
1072 |
/** |
1444 |
* To go forward to the next document |
1073 |
* Calls {@code setExitAction} on {@link #debuggerInstance}. |
1445 |
*/ |
1074 |
*/ |
1446 |
public class ForwardAction extends AbstractAction |
1075 |
protected void setExitAction(Runnable r) { |
1447 |
implements JComponentModifier { |
1076 |
try { |
1448 |
List components = new LinkedList(); |
1077 |
debuggerMethods[SET_EXIT_ACTION_METHOD].invoke( |
1449 |
public ForwardAction() {} |
1078 |
debuggerInstance, new Object[] { r }); |
1450 |
public void actionPerformed(ActionEvent e) { |
1079 |
} catch (InvocationTargetException ite) { |
1451 |
if (localHistory.canGoForward()) { |
1080 |
throw new RuntimeException(ite.getMessage()); |
1452 |
localHistory.forward(); |
1081 |
} catch (IllegalAccessException iae) { |
1453 |
} |
1082 |
throw new RuntimeException(iae.getMessage()); |
1454 |
} |
1083 |
} |
|
|
1084 |
} |
1455 |
|
1085 |
|
1456 |
public void addJComponent(JComponent c) { |
1086 |
/** |
1457 |
components.add(c); |
1087 |
* Calls {@code attachTo} on {@link #debuggerInstance}. |
1458 |
c.setEnabled(false); |
1088 |
*/ |
1459 |
} |
1089 |
public void attachTo(Object contextFactory) { |
|
|
1090 |
try { |
1091 |
debuggerMethods[ATTACH_TO_METHOD].invoke(debuggerInstance, |
1092 |
new Object[] { contextFactory }); |
1093 |
} catch (InvocationTargetException ite) { |
1094 |
throw new RuntimeException(ite.getMessage()); |
1095 |
} catch (IllegalAccessException iae) { |
1096 |
throw new RuntimeException(iae.getMessage()); |
1097 |
} |
1098 |
} |
1460 |
|
1099 |
|
1461 |
protected void update() { |
1100 |
/** |
1462 |
boolean b = localHistory.canGoForward(); |
1101 |
* Calls {@code detach} on {@link #debuggerInstance}. |
1463 |
Iterator it = components.iterator(); |
1102 |
*/ |
1464 |
while (it.hasNext()) { |
1103 |
public void detach() { |
1465 |
((JComponent)it.next()).setEnabled(b); |
1104 |
try { |
1466 |
} |
1105 |
debuggerMethods[DETACH_METHOD].invoke(debuggerInstance, |
1467 |
} |
1106 |
(Object[]) null); |
1468 |
} |
1107 |
} catch (InvocationTargetException ite) { |
|
|
1108 |
throw new RuntimeException(ite.getMessage()); |
1109 |
} catch (IllegalAccessException iae) { |
1110 |
throw new RuntimeException(iae.getMessage()); |
1111 |
} |
1112 |
} |
1469 |
|
1113 |
|
1470 |
/** |
1114 |
/** |
1471 |
* To print the current document. |
1115 |
* Calls {@code go} on {@link #debuggerInstance}. |
1472 |
*/ |
1116 |
*/ |
1473 |
public class PrintAction extends AbstractAction { |
1117 |
public void go() { |
1474 |
public PrintAction() {} |
1118 |
try { |
1475 |
public void actionPerformed(ActionEvent e) { |
1119 |
debuggerMethods[GO_METHOD].invoke(debuggerInstance, |
1476 |
if (svgDocument != null) { |
1120 |
(Object[]) null); |
1477 |
final SVGDocument doc = svgDocument; |
1121 |
} catch (InvocationTargetException ite) { |
1478 |
new Thread() { |
1122 |
throw new RuntimeException(ite.getMessage()); |
1479 |
public void run(){ |
1123 |
} catch (IllegalAccessException iae) { |
1480 |
String uri = doc.getURL(); |
1124 |
throw new RuntimeException(iae.getMessage()); |
1481 |
String fragment = svgCanvas.getFragmentIdentifier(); |
1125 |
} |
1482 |
if (fragment != null) { |
1126 |
} |
1483 |
uri += '#' +fragment; |
|
|
1484 |
} |
1485 |
|
1127 |
|
1486 |
// |
1128 |
/** |
1487 |
// Build a PrintTranscoder to handle printing |
1129 |
* Calls {@code clearAllBreakpoints} on {@link #debuggerInstance}. |
1488 |
// of the svgDocument object |
1130 |
*/ |
1489 |
// |
1131 |
public void clearAllBreakpoints() { |
1490 |
PrintTranscoder pt = new PrintTranscoder(); |
1132 |
try { |
|
|
1133 |
debuggerMethods[CLEAR_ALL_BREAKPOINTS_METHOD].invoke( |
1134 |
debuggerInstance, (Object[]) null); |
1135 |
} catch (InvocationTargetException ite) { |
1136 |
throw new RuntimeException(ite.getMessage()); |
1137 |
} catch (IllegalAccessException iae) { |
1138 |
throw new RuntimeException(iae.getMessage()); |
1139 |
} |
1140 |
} |
1491 |
|
1141 |
|
1492 |
// |
1142 |
/** |
1493 |
// Set transcoding hints |
1143 |
* Calls {@code dispose} on {@link #debuggerInstance}. |
1494 |
// |
1144 |
*/ |
1495 |
if (application.getXMLParserClassName() != null) { |
1145 |
public void dispose() { |
1496 |
pt.addTranscodingHint |
1146 |
try { |
1497 |
(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
1147 |
debuggerMethods[DISPOSE_METHOD].invoke(debuggerInstance, |
1498 |
application.getXMLParserClassName()); |
1148 |
(Object[]) null); |
1499 |
} |
1149 |
} catch (InvocationTargetException ite) { |
|
|
1150 |
throw new RuntimeException(ite.getMessage()); |
1151 |
} catch (IllegalAccessException iae) { |
1152 |
throw new RuntimeException(iae.getMessage()); |
1153 |
} |
1154 |
} |
1500 |
|
1155 |
|
1501 |
pt.addTranscodingHint(PrintTranscoder.KEY_SHOW_PAGE_DIALOG, |
1156 |
/** |
1502 |
Boolean.TRUE); |
1157 |
* Calls {@code getContextFactory} on the given instance of |
|
|
1158 |
* {@link org.apache.batik.script.rhino.RhinoInterpreter}. |
1159 |
*/ |
1160 |
protected Object getContextFactory(Object rhinoInterpreter) { |
1161 |
try { |
1162 |
return getContextFactoryMethod.invoke(rhinoInterpreter, |
1163 |
(Object[]) null); |
1164 |
} catch (InvocationTargetException ite) { |
1165 |
throw new RuntimeException(ite.getMessage()); |
1166 |
} catch (IllegalAccessException iae) { |
1167 |
throw new RuntimeException(iae.getMessage()); |
1168 |
} |
1169 |
} |
1170 |
} |
1503 |
|
1171 |
|
|
|
1172 |
/** |
1173 |
* To show the about dialog |
1174 |
*/ |
1175 |
public class AboutAction extends AbstractAction { |
1176 |
public AboutAction() { |
1177 |
} |
1504 |
|
1178 |
|
1505 |
pt.addTranscodingHint(PrintTranscoder.KEY_SHOW_PRINTER_DIALOG, |
1179 |
public void actionPerformed(ActionEvent e) { |
1506 |
Boolean.TRUE); |
1180 |
AboutDialog dlg = new AboutDialog(JSVGViewerFrame.this); |
|
|
1181 |
// Work around pack() bug on some platforms |
1182 |
dlg.setSize(dlg.getPreferredSize()); |
1183 |
dlg.setLocationRelativeTo(JSVGViewerFrame.this); |
1184 |
dlg.setVisible(true); |
1185 |
dlg.toFront(); |
1186 |
} |
1187 |
} |
1507 |
|
1188 |
|
1508 |
// |
1189 |
/** |
1509 |
// Do transcoding now |
1190 |
* To open a new file. |
1510 |
// |
1191 |
*/ |
1511 |
pt.transcode(new TranscoderInput(uri), null); |
1192 |
public class OpenAction extends AbstractAction { |
1512 |
|
1193 |
|
1513 |
// |
1194 |
public OpenAction() { |
1514 |
// Print |
1195 |
} |
1515 |
// |
|
|
1516 |
try { |
1517 |
pt.print(); |
1518 |
} catch (PrinterException ex) { |
1519 |
userAgent.displayError(ex); |
1520 |
} |
1521 |
} |
1522 |
}.start(); |
1523 |
} |
1524 |
} |
1525 |
} |
1526 |
|
1196 |
|
1527 |
/** |
1197 |
public void actionPerformed(ActionEvent e) { |
1528 |
* To save the current document as SVG. |
1198 |
File f = null; |
1529 |
*/ |
1199 |
if (Platform.isOSX) { |
1530 |
public class SaveAsAction extends AbstractAction { |
1200 |
FileDialog fileDialog = new FileDialog(JSVGViewerFrame.this, |
1531 |
public SaveAsAction() {} |
1201 |
Resources.getString(OPEN_TITLE)); |
|
|
1202 |
fileDialog.setFilenameFilter(new FilenameFilter() { |
1203 |
public boolean accept(File dir, String name) { |
1204 |
Iterator iter = getHandlers().iterator(); |
1205 |
while (iter.hasNext()) { |
1206 |
SquiggleInputHandler handler = (SquiggleInputHandler) iter |
1207 |
.next(); |
1208 |
if (handler.accept(new File(dir, name))) { |
1209 |
return true; |
1210 |
} |
1211 |
} |
1212 |
return false; |
1213 |
} |
1214 |
}); |
1215 |
fileDialog.setVisible(true); |
1216 |
String filename = fileDialog.getFile(); |
1217 |
if (fileDialog != null) { |
1218 |
String dirname = fileDialog.getDirectory(); |
1219 |
f = new File(dirname, filename); |
1220 |
} |
1221 |
} else { |
1222 |
JFileChooser fileChooser = null; |
1532 |
|
1223 |
|
1533 |
public void actionPerformed(ActionEvent e) { |
1224 |
// Apply work around Windows problem when security is enabled, |
1534 |
JFileChooser fileChooser; |
1225 |
// and when prior to JDK 1.4. |
1535 |
fileChooser = new JFileChooser(makeAbsolute(currentSavePath)); |
1226 |
String os = System.getProperty(PROPERTY_OS_NAME, |
1536 |
fileChooser.setDialogTitle(resources.getString("SaveAs.title")); |
1227 |
PROPERTY_OS_NAME_DEFAULT); |
1537 |
fileChooser.setFileHidingEnabled(false); |
1228 |
SecurityManager sm = System.getSecurityManager(); |
1538 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
|
|
1539 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".svg")); |
1540 |
|
1229 |
|
1541 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
1230 |
if (priorJDK1_4 && sm != null |
1542 |
if (choice != JFileChooser.APPROVE_OPTION) |
1231 |
&& os.indexOf(PROPERTY_OS_WINDOWS_PREFIX) != -1) { |
1543 |
return; |
1232 |
fileChooser = new JFileChooser(makeAbsolute(currentPath), |
|
|
1233 |
new WindowsAltFileSystemView()); |
1234 |
} else { |
1235 |
fileChooser = new JFileChooser(makeAbsolute(currentPath)); |
1236 |
} |
1544 |
|
1237 |
|
1545 |
final File f = fileChooser.getSelectedFile(); |
1238 |
fileChooser.setFileHidingEnabled(false); |
|
|
1239 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
1546 |
|
1240 |
|
1547 |
SVGOptionPanel sop; |
1241 |
// |
1548 |
sop = SVGOptionPanel.showDialog(JSVGViewerFrame.this); |
1242 |
// Add file filters from the handlers map |
|
|
1243 |
// |
1244 |
Iterator iter = getHandlers().iterator(); |
1245 |
while (iter.hasNext()) { |
1246 |
SquiggleInputHandler handler = (SquiggleInputHandler) iter |
1247 |
.next(); |
1248 |
fileChooser |
1249 |
.addChoosableFileFilter(new SquiggleInputHandlerFilter( |
1250 |
handler)); |
1251 |
} |
1549 |
|
1252 |
|
1550 |
final boolean useXMLBase = sop.getUseXMLBase(); |
1253 |
int choice = fileChooser.showOpenDialog(JSVGViewerFrame.this); |
1551 |
final boolean prettyPrint = sop.getPrettyPrint(); |
1254 |
if (choice == JFileChooser.APPROVE_OPTION) { |
1552 |
sop = null; |
1255 |
f = fileChooser.getSelectedFile(); |
|
|
1256 |
currentPath = f; |
1257 |
} |
1258 |
} |
1553 |
|
1259 |
|
1554 |
final SVGDocument svgDoc = svgCanvas.getSVGDocument(); |
1260 |
if (f != null) { |
1555 |
if (svgDoc == null) return; |
1261 |
try { |
|
|
1262 |
String furl = f.toURL().toString(); |
1263 |
showSVGDocument(furl); |
1264 |
} catch (MalformedURLException ex) { |
1265 |
if (userAgent != null) { |
1266 |
userAgent.displayError(ex); |
1267 |
} |
1268 |
} |
1269 |
} |
1270 |
} |
1271 |
} |
1556 |
|
1272 |
|
1557 |
statusBar.setMessage(resources.getString("Message.saveAs")); |
1273 |
/** |
1558 |
currentSavePath = f; |
1274 |
* Shows the given document into the viewer frame |
1559 |
OutputStreamWriter w = null; |
1275 |
*/ |
1560 |
try { |
1276 |
public void showSVGDocument(String uri) { |
1561 |
OutputStream tos = null; |
1277 |
try { |
1562 |
tos = new FileOutputStream(f); |
1278 |
ParsedURL purl = new ParsedURL(uri); |
1563 |
tos = new BufferedOutputStream(tos); |
1279 |
SquiggleInputHandler handler = getInputHandler(purl); |
1564 |
w = new OutputStreamWriter(tos, "utf-8"); |
|
|
1565 |
} catch (Exception ex) { |
1566 |
userAgent.displayError(ex); |
1567 |
return; |
1568 |
} |
1569 |
|
1280 |
|
1570 |
final OutputStreamWriter writer = w; |
1281 |
handler.handle(purl, JSVGViewerFrame.this); |
|
|
1282 |
} catch (Exception e) { |
1283 |
if (userAgent != null) { |
1284 |
userAgent.displayError(e); |
1285 |
} |
1286 |
} |
1571 |
|
1287 |
|
1572 |
final Runnable doneRun = new Runnable() { |
1288 |
} |
1573 |
public void run() { |
|
|
1574 |
String doneStr = resources.getString("Message.done"); |
1575 |
statusBar.setMessage(doneStr); |
1576 |
} |
1577 |
}; |
1578 |
Runnable r = new Runnable() { |
1579 |
public void run() { |
1580 |
try { |
1581 |
// Write standard XML header. |
1582 |
writer.write |
1583 |
("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); |
1584 |
writer.write (EOL); |
1585 |
|
1289 |
|
1586 |
Node fc = svgDoc.getFirstChild(); |
1290 |
/** |
1587 |
if (fc.getNodeType() != Node.DOCUMENT_TYPE_NODE) { |
1291 |
* Returns the input handler for the given URI |
1588 |
// Not DT node in Document, so |
1292 |
*/ |
1589 |
// provide Document Type dec. |
1293 |
public SquiggleInputHandler getInputHandler(ParsedURL purl) |
1590 |
writer.write ("<!DOCTYPE svg PUBLIC '"); |
1294 |
throws IOException { |
1591 |
writer.write (SVGConstants.SVG_PUBLIC_ID); |
1295 |
Iterator iter = getHandlers().iterator(); |
1592 |
writer.write ("' '"); |
1296 |
SquiggleInputHandler handler = null; |
1593 |
writer.write (SVGConstants.SVG_SYSTEM_ID); |
|
|
1594 |
writer.write ("'>"); |
1595 |
writer.write (EOL); |
1596 |
writer.write (EOL); |
1597 |
} |
1598 |
Element root = svgDoc.getRootElement(); |
1599 |
boolean doXMLBase = useXMLBase; |
1600 |
if (root.hasAttributeNS |
1601 |
(XMLConstants.XML_NAMESPACE_URI, "base")) |
1602 |
doXMLBase = false; |
1603 |
|
1297 |
|
1604 |
if (doXMLBase) { |
1298 |
while (iter.hasNext()) { |
1605 |
root.setAttributeNS |
1299 |
SquiggleInputHandler curHandler = (SquiggleInputHandler) iter |
1606 |
(XMLConstants.XML_NAMESPACE_URI, |
1300 |
.next(); |
1607 |
"xml:base", |
1301 |
if (curHandler.accept(purl)) { |
1608 |
svgDoc.getURL()); |
1302 |
handler = curHandler; |
1609 |
} |
1303 |
break; |
|
|
1304 |
} |
1305 |
} |
1610 |
|
1306 |
|
1611 |
if (prettyPrint) { |
1307 |
// No handler found, use the default one. |
1612 |
SVGTranscoder trans = new SVGTranscoder(); |
1308 |
if (handler == null) { |
1613 |
trans.transcode(new TranscoderInput(svgDoc), |
1309 |
handler = defaultHandler; |
1614 |
new TranscoderOutput(writer)); |
1310 |
} |
1615 |
} else { |
|
|
1616 |
DOMUtilities.writeDocument(svgDoc, writer); |
1617 |
} |
1618 |
|
1311 |
|
1619 |
writer.close(); |
1312 |
return handler; |
|
|
1313 |
} |
1620 |
|
1314 |
|
1621 |
if (doXMLBase) |
1315 |
/** |
1622 |
root.removeAttributeNS |
1316 |
* Returns the list of input file handler. |
1623 |
(XMLConstants.XML_NAMESPACE_URI, |
1317 |
*/ |
1624 |
"xml:base"); |
1318 |
protected static Vector getHandlers() { |
|
|
1319 |
if (handlers != null) { |
1320 |
return handlers; |
1321 |
} |
1625 |
|
1322 |
|
1626 |
if (EventQueue.isDispatchThread()) { |
1323 |
handlers = new Vector(); |
1627 |
doneRun.run(); |
1324 |
registerHandler(new SVGInputHandler()); |
1628 |
} else { |
|
|
1629 |
EventQueue.invokeLater(doneRun); |
1630 |
} |
1631 |
} catch (Exception ex) { |
1632 |
userAgent.displayError(ex); |
1633 |
} |
1634 |
} |
1635 |
}; |
1636 |
|
1325 |
|
1637 |
UpdateManager um = svgCanvas.getUpdateManager(); |
1326 |
Iterator iter = Service.providers(SquiggleInputHandler.class); |
1638 |
if ((um != null) && (um.isRunning())) { |
1327 |
while (iter.hasNext()) { |
1639 |
um.getUpdateRunnableQueue().invokeLater(r); |
1328 |
SquiggleInputHandler handler = (SquiggleInputHandler) iter.next(); |
1640 |
} else { |
|
|
1641 |
r.run(); |
1642 |
} |
1643 |
} |
1644 |
} |
1645 |
|
1329 |
|
1646 |
/** |
1330 |
registerHandler(handler); |
1647 |
* To save the current document as JPG. |
1331 |
} |
1648 |
*/ |
|
|
1649 |
public class ExportAsJPGAction extends AbstractAction { |
1650 |
public ExportAsJPGAction() {} |
1651 |
public void actionPerformed(ActionEvent e) { |
1652 |
JFileChooser fileChooser = |
1653 |
new JFileChooser(makeAbsolute(currentSavePath)); |
1654 |
fileChooser.setDialogTitle(resources.getString("ExportAsJPG.title")); |
1655 |
fileChooser.setFileHidingEnabled(false); |
1656 |
fileChooser.setFileSelectionMode |
1657 |
(JFileChooser.FILES_ONLY); |
1658 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".jpg")); |
1659 |
|
1332 |
|
1660 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
1333 |
return handlers; |
1661 |
if (choice == JFileChooser.APPROVE_OPTION) { |
1334 |
} |
1662 |
float quality = |
|
|
1663 |
JPEGOptionPanel.showDialog(JSVGViewerFrame.this); |
1664 |
|
1335 |
|
1665 |
final File f = fileChooser.getSelectedFile(); |
1336 |
/** |
1666 |
BufferedImage buffer = svgCanvas.getOffScreen(); |
1337 |
* Registers an input file handler by adding it to the handlers map. |
1667 |
if (buffer != null) { |
1338 |
* |
1668 |
statusBar.setMessage |
1339 |
* @param handler |
1669 |
(resources.getString("Message.exportAsJPG")); |
1340 |
* the new input handler to register. |
|
|
1341 |
*/ |
1342 |
public static synchronized void registerHandler(SquiggleInputHandler handler) { |
1343 |
Vector handlers = getHandlers(); |
1344 |
handlers.addElement(handler); |
1345 |
} |
1670 |
|
1346 |
|
1671 |
// create a BufferedImage of the appropriate type |
1347 |
/** |
1672 |
int w = buffer.getWidth(); |
1348 |
* To open a new document. |
1673 |
int h = buffer.getHeight(); |
1349 |
*/ |
1674 |
final ImageTranscoder trans = new JPEGTranscoder(); |
1350 |
public class OpenLocationAction extends AbstractAction { |
1675 |
if (application.getXMLParserClassName() != null) { |
1351 |
public OpenLocationAction() { |
1676 |
trans.addTranscodingHint |
1352 |
} |
1677 |
(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
|
|
1678 |
application.getXMLParserClassName()); |
1679 |
} |
1680 |
trans.addTranscodingHint |
1681 |
(JPEGTranscoder.KEY_QUALITY, new Float(quality)); |
1682 |
|
1353 |
|
1683 |
final BufferedImage img = trans.createImage(w, h); |
1354 |
public void actionPerformed(ActionEvent e) { |
|
|
1355 |
if (uriChooser == null) { |
1356 |
uriChooser = new URIChooser(JSVGViewerFrame.this); |
1357 |
uriChooser.setFileFilter(new SVGFileFilter()); |
1358 |
uriChooser.pack(); |
1359 |
Rectangle fr = getBounds(); |
1360 |
Dimension sd = uriChooser.getSize(); |
1361 |
uriChooser.setLocation(fr.x + (fr.width - sd.width) / 2, fr.y |
1362 |
+ (fr.height - sd.height) / 2); |
1363 |
} |
1364 |
if (uriChooser.showDialog() == URIChooser.OK_OPTION) { |
1365 |
String s = uriChooser.getText(); |
1366 |
if (s == null) |
1367 |
return; |
1368 |
int i = s.indexOf('#'); |
1369 |
String t = ""; |
1370 |
if (i != -1) { |
1371 |
t = s.substring(i + 1); |
1372 |
s = s.substring(0, i); |
1373 |
} |
1374 |
if (!s.equals("")) { |
1375 |
File f = new File(s); |
1376 |
if (f.exists()) { |
1377 |
if (f.isDirectory()) { |
1378 |
s = null; |
1379 |
} else { |
1380 |
try { |
1381 |
s = f.getCanonicalPath(); |
1382 |
if (s.startsWith("/")) { |
1383 |
s = "file:" + s; |
1384 |
} else { |
1385 |
s = "file:/" + s; |
1386 |
} |
1387 |
} catch (IOException ex) { |
1388 |
} |
1389 |
} |
1390 |
} |
1391 |
if (s != null) { |
1392 |
if (svgDocument != null) { |
1393 |
ParsedURL docPURL = new ParsedURL(svgDocument |
1394 |
.getURL()); |
1395 |
ParsedURL purl = new ParsedURL(docPURL, s); |
1396 |
String fi = svgCanvas.getFragmentIdentifier(); |
1397 |
if (docPURL.equals(purl) && t.equals(fi)) { |
1398 |
return; |
1399 |
} |
1400 |
} |
1401 |
if (t.length() != 0) { |
1402 |
s += '#' + t; |
1403 |
} |
1684 |
|
1404 |
|
1685 |
// paint the buffer to the image |
1405 |
showSVGDocument(s); |
1686 |
Graphics2D g2d = img.createGraphics(); |
1406 |
} |
1687 |
g2d.setColor(Color.white); |
1407 |
} |
1688 |
g2d.fillRect(0, 0, w, h); |
1408 |
} |
1689 |
g2d.drawImage(buffer, null, 0, 0); |
1409 |
} |
1690 |
new Thread() { |
1410 |
} |
1691 |
public void run() { |
|
|
1692 |
try { |
1693 |
currentSavePath = f; |
1694 |
OutputStream ostream = |
1695 |
new BufferedOutputStream(new FileOutputStream(f)); |
1696 |
trans.writeImage(img, new TranscoderOutput(ostream)); |
1697 |
ostream.close(); |
1698 |
} catch (Exception ex) { } |
1699 |
statusBar.setMessage |
1700 |
(resources.getString("Message.done")); |
1701 |
} |
1702 |
}.start(); |
1703 |
} |
1704 |
} |
1705 |
} |
1706 |
} |
1707 |
|
1411 |
|
1708 |
/** |
1412 |
/** |
1709 |
* To save the current document as PNG. |
1413 |
* To open a new window. |
1710 |
*/ |
1414 |
*/ |
1711 |
public class ExportAsPNGAction extends AbstractAction { |
1415 |
public class NewWindowAction extends AbstractAction { |
1712 |
public ExportAsPNGAction() {} |
1416 |
public NewWindowAction() { |
1713 |
public void actionPerformed(ActionEvent e) { |
1417 |
} |
1714 |
JFileChooser fileChooser = |
|
|
1715 |
new JFileChooser(makeAbsolute(currentSavePath)); |
1716 |
fileChooser.setDialogTitle(resources.getString("ExportAsPNG.title")); |
1717 |
fileChooser.setFileHidingEnabled(false); |
1718 |
fileChooser.setFileSelectionMode |
1719 |
(JFileChooser.FILES_ONLY); |
1720 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".png")); |
1721 |
|
1418 |
|
1722 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
1419 |
public void actionPerformed(ActionEvent e) { |
1723 |
if (choice == JFileChooser.APPROVE_OPTION) { |
1420 |
JSVGViewerFrame vf = application.createAndShowJSVGViewerFrame(); |
1724 |
|
1421 |
|
1725 |
// Start: By Jun Inamori (jun@oop-reserch.com) |
1422 |
// Copy the current settings to the new window. |
1726 |
boolean isIndexed = PNGOptionPanel.showDialog(JSVGViewerFrame.this); |
1423 |
vf.autoAdjust = autoAdjust; |
1727 |
// End: By Jun Inamori (jun@oop-reserch.com) |
1424 |
vf.debug = debug; |
|
|
1425 |
vf.svgCanvas.setProgressivePaint(svgCanvas.getProgressivePaint()); |
1426 |
vf.svgCanvas.setDoubleBufferedRendering(svgCanvas |
1427 |
.getDoubleBufferedRendering()); |
1428 |
} |
1429 |
} |
1728 |
|
1430 |
|
1729 |
final File f = fileChooser.getSelectedFile(); |
1431 |
/** |
1730 |
BufferedImage buffer = svgCanvas.getOffScreen(); |
1432 |
* To show the preferences. |
1731 |
if (buffer != null) { |
1433 |
*/ |
1732 |
statusBar.setMessage |
1434 |
public class PreferencesAction extends AbstractAction { |
1733 |
(resources.getString("Message.exportAsPNG")); |
1435 |
public PreferencesAction() { |
|
|
1436 |
} |
1734 |
|
1437 |
|
1735 |
// create a BufferedImage of the appropriate type |
1438 |
public void actionPerformed(ActionEvent e) { |
1736 |
int w = buffer.getWidth(); |
1439 |
application.showPreferenceDialog(JSVGViewerFrame.this); |
1737 |
int h = buffer.getHeight(); |
1440 |
} |
1738 |
final ImageTranscoder trans = new PNGTranscoder(); |
1441 |
} |
1739 |
if (application.getXMLParserClassName() != null) { |
|
|
1740 |
trans.addTranscodingHint |
1741 |
(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
1742 |
application.getXMLParserClassName()); |
1743 |
} |
1744 |
trans.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE, |
1745 |
Boolean.TRUE ); |
1746 |
|
1442 |
|
1747 |
// Start: By Jun Inamori |
1443 |
/** |
1748 |
if(isIndexed){ |
1444 |
* To close the last document. |
1749 |
trans.addTranscodingHint(PNGTranscoder.KEY_INDEXED,new Integer(256)); |
1445 |
*/ |
1750 |
} |
1446 |
public class CloseAction extends AbstractAction { |
1751 |
// End: By Jun Inamori |
1447 |
public CloseAction() { |
|
|
1448 |
} |
1752 |
|
1449 |
|
1753 |
final BufferedImage img = trans.createImage(w, h); |
1450 |
public void actionPerformed(ActionEvent e) { |
|
|
1451 |
application.closeJSVGViewerFrame(JSVGViewerFrame.this); |
1452 |
} |
1453 |
} |
1754 |
|
1454 |
|
1755 |
// paint the buffer to the image |
1455 |
/** |
1756 |
Graphics2D g2d = img.createGraphics(); |
1456 |
* To reload the current document. |
1757 |
g2d.drawImage(buffer, null, 0, 0); |
1457 |
*/ |
1758 |
new Thread() { |
1458 |
public class ReloadAction extends AbstractAction { |
1759 |
public void run() { |
1459 |
public ReloadAction() { |
1760 |
try { |
1460 |
} |
1761 |
currentSavePath = f; |
|
|
1762 |
OutputStream ostream = |
1763 |
new BufferedOutputStream(new FileOutputStream(f)); |
1764 |
trans.writeImage(img, |
1765 |
new TranscoderOutput(ostream)); |
1766 |
ostream.close(); |
1767 |
} catch (Exception ex) {} |
1768 |
statusBar.setMessage |
1769 |
(resources.getString("Message.done")); |
1770 |
} |
1771 |
}.start(); |
1772 |
} |
1773 |
} |
1774 |
} |
1775 |
} |
1776 |
|
1461 |
|
1777 |
/** |
1462 |
public void actionPerformed(ActionEvent e) { |
1778 |
* To save the current document as TIFF. |
1463 |
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) == 1) { |
1779 |
*/ |
1464 |
svgCanvas.flushImageCache(); |
1780 |
public class ExportAsTIFFAction extends AbstractAction { |
1465 |
} |
1781 |
public ExportAsTIFFAction() {} |
1466 |
if (svgDocument != null) { |
1782 |
public void actionPerformed(ActionEvent e) { |
1467 |
localHistory.reload(); |
1783 |
JFileChooser fileChooser = |
1468 |
} |
1784 |
new JFileChooser(makeAbsolute(currentSavePath)); |
1469 |
} |
1785 |
fileChooser.setDialogTitle(resources.getString("ExportAsTIFF.title")); |
1470 |
} |
1786 |
fileChooser.setFileHidingEnabled(false); |
|
|
1787 |
fileChooser.setFileSelectionMode |
1788 |
(JFileChooser.FILES_ONLY); |
1789 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".tiff")); |
1790 |
|
1471 |
|
1791 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
1472 |
/** |
1792 |
if (choice == JFileChooser.APPROVE_OPTION) { |
1473 |
* To go back to the previous document |
1793 |
final File f = fileChooser.getSelectedFile(); |
1474 |
*/ |
1794 |
BufferedImage buffer = svgCanvas.getOffScreen(); |
1475 |
public class BackAction extends AbstractAction implements |
1795 |
if (buffer != null) { |
1476 |
JComponentModifier { |
1796 |
statusBar.setMessage |
1477 |
List components = new LinkedList(); |
1797 |
(resources.getString("Message.exportAsTIFF")); |
|
|
1798 |
|
1478 |
|
1799 |
// create a BufferedImage of the appropriate type |
1479 |
public BackAction() { |
1800 |
int w = buffer.getWidth(); |
1480 |
} |
1801 |
int h = buffer.getHeight(); |
|
|
1802 |
final ImageTranscoder trans = new TIFFTranscoder(); |
1803 |
if (application.getXMLParserClassName() != null) { |
1804 |
trans.addTranscodingHint |
1805 |
(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
1806 |
application.getXMLParserClassName()); |
1807 |
} |
1808 |
final BufferedImage img = trans.createImage(w, h); |
1809 |
|
1481 |
|
1810 |
// paint the buffer to the image |
1482 |
public void actionPerformed(ActionEvent e) { |
1811 |
Graphics2D g2d = img.createGraphics(); |
1483 |
if (localHistory.canGoBack()) { |
1812 |
g2d.drawImage(buffer, null, 0, 0); |
1484 |
localHistory.back(); |
1813 |
new Thread() { |
1485 |
} |
1814 |
public void run() { |
1486 |
} |
1815 |
try { |
|
|
1816 |
currentSavePath = f; |
1817 |
OutputStream ostream = new BufferedOutputStream |
1818 |
(new FileOutputStream(f)); |
1819 |
trans.writeImage |
1820 |
(img, new TranscoderOutput(ostream)); |
1821 |
ostream.close(); |
1822 |
} catch (Exception ex) {} |
1823 |
statusBar.setMessage |
1824 |
(resources.getString("Message.done")); |
1825 |
} |
1826 |
}.start(); |
1827 |
} |
1828 |
} |
1829 |
} |
1830 |
} |
1831 |
|
1487 |
|
1832 |
/** |
1488 |
public void addJComponent(JComponent c) { |
1833 |
* To view the source of the current document. |
1489 |
components.add(c); |
1834 |
*/ |
1490 |
c.setEnabled(false); |
1835 |
public class ViewSourceAction extends AbstractAction { |
1491 |
} |
1836 |
public ViewSourceAction() {} |
|
|
1837 |
public void actionPerformed(ActionEvent e) { |
1838 |
if (svgDocument == null) { |
1839 |
return; |
1840 |
} |
1841 |
|
1492 |
|
1842 |
final ParsedURL u = new ParsedURL(svgDocument.getURL()); |
1493 |
protected void update() { |
|
|
1494 |
boolean b = localHistory.canGoBack(); |
1495 |
Iterator it = components.iterator(); |
1496 |
while (it.hasNext()) { |
1497 |
((JComponent) it.next()).setEnabled(b); |
1498 |
} |
1499 |
} |
1500 |
} |
1843 |
|
1501 |
|
1844 |
final JFrame fr = new JFrame(u.toString()); |
1502 |
/** |
1845 |
fr.setSize(resources.getInteger("ViewSource.width"), |
1503 |
* To go forward to the next document |
1846 |
resources.getInteger("ViewSource.height")); |
1504 |
*/ |
1847 |
final JTextArea ta = new JTextArea(); |
1505 |
public class ForwardAction extends AbstractAction implements |
1848 |
ta.setLineWrap(true); |
1506 |
JComponentModifier { |
1849 |
ta.setFont(new Font("monospaced", Font.PLAIN, 12)); |
1507 |
List components = new LinkedList(); |
1850 |
|
1508 |
|
1851 |
JScrollPane scroll = new JScrollPane(); |
1509 |
public ForwardAction() { |
1852 |
scroll.getViewport().add(ta); |
1510 |
} |
1853 |
scroll.setVerticalScrollBarPolicy |
|
|
1854 |
(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
1855 |
fr.getContentPane().add(scroll, BorderLayout.CENTER); |
1856 |
|
1511 |
|
1857 |
new Thread() { |
1512 |
public void actionPerformed(ActionEvent e) { |
1858 |
public void run() { |
1513 |
if (localHistory.canGoForward()) { |
1859 |
char [] buffer = new char[4096]; |
1514 |
localHistory.forward(); |
|
|
1515 |
} |
1516 |
} |
1860 |
|
1517 |
|
1861 |
try { |
1518 |
public void addJComponent(JComponent c) { |
1862 |
Document doc = new PlainDocument(); |
1519 |
components.add(c); |
|
|
1520 |
c.setEnabled(false); |
1521 |
} |
1863 |
|
1522 |
|
1864 |
ParsedURL purl = new ParsedURL(svgDocument.getURL()); |
1523 |
protected void update() { |
1865 |
InputStream is |
1524 |
boolean b = localHistory.canGoForward(); |
1866 |
= u.openStream(getInputHandler(purl). |
1525 |
Iterator it = components.iterator(); |
1867 |
getHandledMimeTypes()); |
1526 |
while (it.hasNext()) { |
1868 |
// u.openStream(MimeTypeConstants.MIME_TYPES_SVG); |
1527 |
((JComponent) it.next()).setEnabled(b); |
|
|
1528 |
} |
1529 |
} |
1530 |
} |
1869 |
|
1531 |
|
1870 |
Reader in = XMLUtilities.createXMLDocumentReader(is); |
1532 |
/** |
1871 |
int len; |
1533 |
* To print the current document. |
1872 |
while ((len=in.read(buffer, 0, buffer.length)) != -1) { |
1534 |
*/ |
1873 |
doc.insertString(doc.getLength(), |
1535 |
public class PrintAction extends AbstractAction { |
1874 |
new String(buffer, 0, len), null); |
1536 |
public PrintAction() { |
1875 |
} |
1537 |
} |
1876 |
|
1538 |
|
1877 |
ta.setDocument(doc); |
1539 |
public void actionPerformed(ActionEvent e) { |
1878 |
ta.setEditable(false); |
1540 |
if (svgDocument != null) { |
1879 |
ta.setBackground(Color.white); |
1541 |
final SVGDocument doc = svgDocument; |
1880 |
fr.setVisible(true); |
1542 |
new Thread() { |
1881 |
} catch (Exception ex) { |
1543 |
public void run() { |
1882 |
userAgent.displayError(ex); |
1544 |
String uri = doc.getURL(); |
1883 |
} |
1545 |
String fragment = svgCanvas.getFragmentIdentifier(); |
1884 |
} |
1546 |
if (fragment != null) { |
1885 |
}.start(); |
1547 |
uri += '#' + fragment; |
1886 |
} |
1548 |
} |
1887 |
} |
|
|
1888 |
|
1549 |
|
1889 |
/** |
1550 |
// |
1890 |
* To flush image cache (purely for debugging purposes) |
1551 |
// Build a PrintTranscoder to handle printing |
1891 |
*/ |
1552 |
// of the svgDocument object |
1892 |
public class FlushAction extends AbstractAction { |
1553 |
// |
1893 |
public FlushAction() {} |
1554 |
PrintTranscoder pt = new PrintTranscoder(); |
1894 |
public void actionPerformed(ActionEvent e) { |
|
|
1895 |
svgCanvas.flush(); |
1896 |
// Force redraw... |
1897 |
svgCanvas.setRenderingTransform(svgCanvas.getRenderingTransform()); |
1898 |
} |
1899 |
} |
1900 |
|
1555 |
|
1901 |
/** |
1556 |
// |
1902 |
* To toggle visiblity of JavaScript Debugger. |
1557 |
// Set transcoding hints |
1903 |
*/ |
1558 |
// |
1904 |
public class ToggleDebuggerAction extends AbstractAction { |
1559 |
if (application.getXMLParserClassName() != null) { |
1905 |
public ToggleDebuggerAction() { |
1560 |
pt.addTranscodingHint( |
1906 |
super("Toggle Debugger Action"); |
1561 |
JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
1907 |
} |
1562 |
application.getXMLParserClassName()); |
|
|
1563 |
} |
1908 |
|
1564 |
|
1909 |
public void actionPerformed(ActionEvent e) { |
1565 |
pt.addTranscodingHint( |
1910 |
if (debugger == null) { |
1566 |
PrintTranscoder.KEY_SHOW_PAGE_DIALOG, |
1911 |
showDebugger(); |
1567 |
Boolean.TRUE); |
1912 |
} else { |
|
|
1913 |
hideDebugger(); |
1914 |
} |
1915 |
} |
1916 |
} |
1917 |
|
1568 |
|
1918 |
/** |
1569 |
pt.addTranscodingHint( |
1919 |
* To go back to the previous transform |
1570 |
PrintTranscoder.KEY_SHOW_PRINTER_DIALOG, |
1920 |
*/ |
1571 |
Boolean.TRUE); |
1921 |
public class PreviousTransformAction extends AbstractAction |
|
|
1922 |
implements JComponentModifier { |
1923 |
List components = new LinkedList(); |
1924 |
public PreviousTransformAction() {} |
1925 |
public void actionPerformed(ActionEvent e) { |
1926 |
if (transformHistory.canGoBack()) { |
1927 |
transformHistory.back(); |
1928 |
update(); |
1929 |
nextTransformAction.update(); |
1930 |
svgCanvas.setRenderingTransform(transformHistory.currentTransform()); |
1931 |
} |
1932 |
} |
1933 |
|
1572 |
|
1934 |
public void addJComponent(JComponent c) { |
1573 |
// |
1935 |
components.add(c); |
1574 |
// Do transcoding now |
1936 |
c.setEnabled(false); |
1575 |
// |
1937 |
} |
1576 |
pt.transcode(new TranscoderInput(uri), null); |
1938 |
|
1577 |
|
1939 |
protected void update() { |
1578 |
// |
1940 |
boolean b = transformHistory.canGoBack(); |
1579 |
// Print |
1941 |
Iterator it = components.iterator(); |
1580 |
// |
1942 |
while (it.hasNext()) { |
1581 |
try { |
1943 |
((JComponent)it.next()).setEnabled(b); |
1582 |
pt.print(); |
1944 |
} |
1583 |
} catch (PrinterException ex) { |
1945 |
} |
1584 |
userAgent.displayError(ex); |
1946 |
} |
1585 |
} |
|
|
1586 |
} |
1587 |
}.start(); |
1588 |
} |
1589 |
} |
1590 |
} |
1947 |
|
1591 |
|
1948 |
/** |
1592 |
/** |
1949 |
* To go forward to the next transform |
1593 |
* To save the current document as SVG. |
1950 |
*/ |
1594 |
*/ |
1951 |
public class NextTransformAction extends AbstractAction |
1595 |
public class SaveAsAction extends AbstractAction { |
1952 |
implements JComponentModifier { |
1596 |
public SaveAsAction() { |
1953 |
List components = new LinkedList(); |
1597 |
} |
1954 |
public NextTransformAction() {} |
|
|
1955 |
public void actionPerformed(ActionEvent e) { |
1956 |
if (transformHistory.canGoForward()) { |
1957 |
transformHistory.forward(); |
1958 |
update(); |
1959 |
previousTransformAction.update(); |
1960 |
svgCanvas.setRenderingTransform(transformHistory.currentTransform()); |
1961 |
} |
1962 |
} |
1963 |
|
1598 |
|
1964 |
public void addJComponent(JComponent c) { |
1599 |
public void actionPerformed(ActionEvent e) { |
1965 |
components.add(c); |
1600 |
JFileChooser fileChooser; |
1966 |
c.setEnabled(false); |
1601 |
fileChooser = new JFileChooser(makeAbsolute(currentSavePath)); |
1967 |
} |
1602 |
fileChooser.setDialogTitle(resources.getString("SaveAs.title")); |
|
|
1603 |
fileChooser.setFileHidingEnabled(false); |
1604 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
1605 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".svg")); |
1968 |
|
1606 |
|
1969 |
protected void update() { |
1607 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
1970 |
boolean b = transformHistory.canGoForward(); |
1608 |
if (choice != JFileChooser.APPROVE_OPTION) |
1971 |
Iterator it = components.iterator(); |
1609 |
return; |
1972 |
while (it.hasNext()) { |
|
|
1973 |
((JComponent)it.next()).setEnabled(b); |
1974 |
} |
1975 |
} |
1976 |
} |
1977 |
|
1610 |
|
1978 |
/** |
1611 |
final File f = fileChooser.getSelectedFile(); |
1979 |
* To apply the selected author stylesheet |
|
|
1980 |
*/ |
1981 |
public class UseStylesheetAction extends AbstractAction |
1982 |
implements JComponentModifier { |
1983 |
|
1612 |
|
1984 |
List components = new LinkedList(); |
1613 |
SVGOptionPanel sop; |
|
|
1614 |
sop = SVGOptionPanel.showDialog(JSVGViewerFrame.this); |
1985 |
|
1615 |
|
1986 |
public UseStylesheetAction() {} |
1616 |
final boolean useXMLBase = sop.getUseXMLBase(); |
|
|
1617 |
final boolean prettyPrint = sop.getPrettyPrint(); |
1618 |
sop = null; |
1987 |
|
1619 |
|
1988 |
public void actionPerformed(ActionEvent e) { |
1620 |
final SVGDocument svgDoc = svgCanvas.getSVGDocument(); |
1989 |
} |
1621 |
if (svgDoc == null) |
|
|
1622 |
return; |
1990 |
|
1623 |
|
1991 |
public void addJComponent(JComponent c) { |
1624 |
statusBar.setMessage(resources.getString("Message.saveAs")); |
1992 |
components.add(c); |
1625 |
currentSavePath = f; |
1993 |
c.setEnabled(false); |
1626 |
OutputStreamWriter w = null; |
1994 |
} |
1627 |
try { |
|
|
1628 |
OutputStream tos = null; |
1629 |
tos = new FileOutputStream(f); |
1630 |
tos = new BufferedOutputStream(tos); |
1631 |
w = new OutputStreamWriter(tos, "utf-8"); |
1632 |
} catch (Exception ex) { |
1633 |
userAgent.displayError(ex); |
1634 |
return; |
1635 |
} |
1995 |
|
1636 |
|
1996 |
protected void update() { |
1637 |
final OutputStreamWriter writer = w; |
1997 |
alternateStyleSheet = null; |
|
|
1998 |
Iterator it = components.iterator(); |
1999 |
SVGDocument doc = svgCanvas.getSVGDocument(); |
2000 |
while (it.hasNext()) { |
2001 |
JComponent stylesheetMenu = (JComponent)it.next(); |
2002 |
stylesheetMenu.removeAll(); |
2003 |
stylesheetMenu.setEnabled(false); |
2004 |
|
1638 |
|
2005 |
ButtonGroup buttonGroup = new ButtonGroup(); |
1639 |
final Runnable doneRun = new Runnable() { |
|
|
1640 |
public void run() { |
1641 |
String doneStr = resources.getString("Message.done"); |
1642 |
statusBar.setMessage(doneStr); |
1643 |
} |
1644 |
}; |
1645 |
Runnable r = new Runnable() { |
1646 |
public void run() { |
1647 |
try { |
1648 |
// Write standard XML header. |
1649 |
writer |
1650 |
.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); |
1651 |
writer.write(EOL); |
2006 |
|
1652 |
|
2007 |
for (Node n = doc.getFirstChild(); |
1653 |
Node fc = svgDoc.getFirstChild(); |
2008 |
n != null && n.getNodeType() != Node.ELEMENT_NODE; |
1654 |
if (fc.getNodeType() != Node.DOCUMENT_TYPE_NODE) { |
2009 |
n = n.getNextSibling()) { |
1655 |
// Not DT node in Document, so |
2010 |
if (n instanceof StyleSheetProcessingInstruction) { |
1656 |
// provide Document Type dec. |
2011 |
StyleSheetProcessingInstruction sspi; |
1657 |
writer.write("<!DOCTYPE svg PUBLIC '"); |
2012 |
sspi = (StyleSheetProcessingInstruction)n; |
1658 |
writer.write(SVGConstants.SVG_PUBLIC_ID); |
2013 |
HashTable attrs = sspi.getPseudoAttributes(); |
1659 |
writer.write("' '"); |
2014 |
final String title = (String)attrs.get("title"); |
1660 |
writer.write(SVGConstants.SVG_SYSTEM_ID); |
2015 |
String alt = (String)attrs.get("alternate"); |
1661 |
writer.write("'>"); |
2016 |
if (title != null && "yes".equals(alt)) { |
1662 |
writer.write(EOL); |
2017 |
JRadioButtonMenuItem button; |
1663 |
writer.write(EOL); |
2018 |
button = new JRadioButtonMenuItem(title); |
1664 |
} |
|
|
1665 |
Element root = svgDoc.getRootElement(); |
1666 |
boolean doXMLBase = useXMLBase; |
1667 |
if (root.hasAttributeNS(XMLConstants.XML_NAMESPACE_URI, |
1668 |
"base")) |
1669 |
doXMLBase = false; |
2019 |
|
1670 |
|
2020 |
button.addActionListener |
1671 |
if (doXMLBase) { |
2021 |
(new java.awt.event.ActionListener() { |
1672 |
root.setAttributeNS(XMLConstants.XML_NAMESPACE_URI, |
2022 |
public void actionPerformed(ActionEvent e) { |
1673 |
"xml:base", svgDoc.getURL()); |
2023 |
SVGOMDocument doc; |
1674 |
} |
2024 |
doc = (SVGOMDocument)svgCanvas.getSVGDocument(); |
|
|
2025 |
doc.clearViewCSS(); |
2026 |
alternateStyleSheet = title; |
2027 |
svgCanvas.setSVGDocument(doc); |
2028 |
} |
2029 |
}); |
2030 |
|
1675 |
|
2031 |
buttonGroup.add(button); |
1676 |
if (prettyPrint) { |
2032 |
stylesheetMenu.add(button); |
1677 |
SVGTranscoder trans = new SVGTranscoder(); |
2033 |
stylesheetMenu.setEnabled(true); |
1678 |
trans.transcode(new TranscoderInput(svgDoc), |
2034 |
} |
1679 |
new TranscoderOutput(writer)); |
2035 |
} |
1680 |
} else { |
2036 |
} |
1681 |
DOMUtilities.writeDocument(svgDoc, writer); |
2037 |
} |
1682 |
} |
2038 |
} |
|
|
2039 |
} |
2040 |
|
1683 |
|
2041 |
/** |
1684 |
writer.close(); |
2042 |
* To restart after a pause. |
|
|
2043 |
*/ |
2044 |
public class PlayAction extends AbstractAction |
2045 |
implements JComponentModifier { |
2046 |
List components = new LinkedList(); |
2047 |
public PlayAction() {} |
2048 |
public void actionPerformed(ActionEvent e) { |
2049 |
svgCanvas.resumeProcessing(); |
2050 |
} |
2051 |
|
1685 |
|
2052 |
public void addJComponent(JComponent c) { |
1686 |
if (doXMLBase) |
2053 |
components.add(c); |
1687 |
root.removeAttributeNS( |
2054 |
c.setEnabled(false); |
1688 |
XMLConstants.XML_NAMESPACE_URI, "xml:base"); |
2055 |
} |
|
|
2056 |
|
1689 |
|
2057 |
public void update(boolean enabled) { |
1690 |
if (EventQueue.isDispatchThread()) { |
2058 |
Iterator it = components.iterator(); |
1691 |
doneRun.run(); |
2059 |
while (it.hasNext()) { |
1692 |
} else { |
2060 |
((JComponent)it.next()).setEnabled(enabled); |
1693 |
EventQueue.invokeLater(doneRun); |
2061 |
} |
1694 |
} |
2062 |
} |
1695 |
} catch (Exception ex) { |
2063 |
} |
1696 |
userAgent.displayError(ex); |
|
|
1697 |
} |
1698 |
} |
1699 |
}; |
2064 |
|
1700 |
|
2065 |
/** |
1701 |
UpdateManager um = svgCanvas.getUpdateManager(); |
2066 |
* To pause a document. |
1702 |
if ((um != null) && (um.isRunning())) { |
2067 |
*/ |
1703 |
um.getUpdateRunnableQueue().invokeLater(r); |
2068 |
public class PauseAction extends AbstractAction |
1704 |
} else { |
2069 |
implements JComponentModifier { |
1705 |
r.run(); |
2070 |
List components = new LinkedList(); |
1706 |
} |
2071 |
public PauseAction() {} |
1707 |
} |
2072 |
public void actionPerformed(ActionEvent e) { |
1708 |
} |
2073 |
svgCanvas.suspendProcessing(); |
|
|
2074 |
} |
2075 |
|
1709 |
|
2076 |
public void addJComponent(JComponent c) { |
1710 |
/** |
2077 |
components.add(c); |
1711 |
* To save the current document as JPG. |
2078 |
c.setEnabled(false); |
1712 |
*/ |
2079 |
} |
1713 |
public class ExportAsJPGAction extends AbstractAction { |
|
|
1714 |
public ExportAsJPGAction() { |
1715 |
} |
2080 |
|
1716 |
|
2081 |
public void update(boolean enabled) { |
1717 |
public void actionPerformed(ActionEvent e) { |
2082 |
Iterator it = components.iterator(); |
1718 |
JFileChooser fileChooser = new JFileChooser( |
2083 |
while (it.hasNext()) { |
1719 |
makeAbsolute(currentSavePath)); |
2084 |
((JComponent)it.next()).setEnabled(enabled); |
1720 |
fileChooser |
2085 |
} |
1721 |
.setDialogTitle(resources.getString("ExportAsJPG.title")); |
2086 |
} |
1722 |
fileChooser.setFileHidingEnabled(false); |
2087 |
} |
1723 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
|
|
1724 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".jpg")); |
2088 |
|
1725 |
|
2089 |
/** |
1726 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
2090 |
* To stop the current processing. |
1727 |
if (choice == JFileChooser.APPROVE_OPTION) { |
2091 |
*/ |
1728 |
float quality = JPEGOptionPanel |
2092 |
public class StopAction extends AbstractAction |
1729 |
.showDialog(JSVGViewerFrame.this); |
2093 |
implements JComponentModifier { |
|
|
2094 |
List components = new LinkedList(); |
2095 |
public StopAction() {} |
2096 |
public void actionPerformed(ActionEvent e) { |
2097 |
svgCanvas.stopProcessing(); |
2098 |
} |
2099 |
|
1730 |
|
2100 |
public void addJComponent(JComponent c) { |
1731 |
final File f = fileChooser.getSelectedFile(); |
2101 |
components.add(c); |
1732 |
BufferedImage buffer = svgCanvas.getOffScreen(); |
2102 |
c.setEnabled(false); |
1733 |
if (buffer != null) { |
2103 |
} |
1734 |
statusBar.setMessage(resources |
|
|
1735 |
.getString("Message.exportAsJPG")); |
2104 |
|
1736 |
|
2105 |
public void update(boolean enabled) { |
1737 |
// create a BufferedImage of the appropriate type |
2106 |
Iterator it = components.iterator(); |
1738 |
int w = buffer.getWidth(); |
2107 |
while (it.hasNext()) { |
1739 |
int h = buffer.getHeight(); |
2108 |
((JComponent)it.next()).setEnabled(enabled); |
1740 |
final ImageTranscoder trans = new JPEGTranscoder(); |
2109 |
} |
1741 |
if (application.getXMLParserClassName() != null) { |
2110 |
} |
1742 |
trans.addTranscodingHint( |
2111 |
} |
1743 |
JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
|
|
1744 |
application.getXMLParserClassName()); |
1745 |
} |
1746 |
trans.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, |
1747 |
new Float(quality)); |
2112 |
|
1748 |
|
2113 |
/** |
1749 |
final BufferedImage img = trans.createImage(w, h); |
2114 |
* To show the set transform dialog |
|
|
2115 |
*/ |
2116 |
public class SetTransformAction extends AbstractAction { |
2117 |
public SetTransformAction(){} |
2118 |
public void actionPerformed(ActionEvent e){ |
2119 |
if (transformDialog == null){ |
2120 |
transformDialog |
2121 |
= JAffineTransformChooser.createDialog |
2122 |
(JSVGViewerFrame.this, |
2123 |
resources.getString("SetTransform.title")); |
2124 |
} |
2125 |
|
1750 |
|
2126 |
AffineTransform txf = transformDialog.showDialog(); |
1751 |
// paint the buffer to the image |
2127 |
if(txf != null){ |
1752 |
Graphics2D g2d = img.createGraphics(); |
2128 |
AffineTransform at = svgCanvas.getRenderingTransform(); |
1753 |
g2d.setColor(Color.white); |
2129 |
if(at == null){ |
1754 |
g2d.fillRect(0, 0, w, h); |
2130 |
at = new AffineTransform(); |
1755 |
g2d.drawImage(buffer, null, 0, 0); |
2131 |
} |
1756 |
new Thread() { |
|
|
1757 |
public void run() { |
1758 |
try { |
1759 |
currentSavePath = f; |
1760 |
OutputStream ostream = new BufferedOutputStream( |
1761 |
new FileOutputStream(f)); |
1762 |
trans.writeImage(img, new TranscoderOutput( |
1763 |
ostream)); |
1764 |
ostream.close(); |
1765 |
} catch (Exception ex) { |
1766 |
} |
1767 |
statusBar.setMessage(resources |
1768 |
.getString("Message.done")); |
1769 |
} |
1770 |
}.start(); |
1771 |
} |
1772 |
} |
1773 |
} |
1774 |
} |
2132 |
|
1775 |
|
2133 |
txf.concatenate(at); |
1776 |
/** |
2134 |
svgCanvas.setRenderingTransform(txf); |
1777 |
* To save the current document as PNG. |
2135 |
} |
1778 |
*/ |
2136 |
} |
1779 |
public class ExportAsPNGAction extends AbstractAction { |
2137 |
} |
1780 |
public ExportAsPNGAction() { |
|
|
1781 |
} |
2138 |
|
1782 |
|
2139 |
/** |
1783 |
public void actionPerformed(ActionEvent e) { |
2140 |
* To display the memory monitor. |
1784 |
JFileChooser fileChooser = new JFileChooser( |
2141 |
*/ |
1785 |
makeAbsolute(currentSavePath)); |
2142 |
public class MonitorAction extends AbstractAction { |
1786 |
fileChooser |
2143 |
public MonitorAction() {} |
1787 |
.setDialogTitle(resources.getString("ExportAsPNG.title")); |
2144 |
public void actionPerformed(ActionEvent e) { |
1788 |
fileChooser.setFileHidingEnabled(false); |
2145 |
if (memoryMonitorFrame == null) { |
1789 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
2146 |
memoryMonitorFrame = new MemoryMonitor(); |
1790 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".png")); |
2147 |
Rectangle fr = getBounds(); |
|
|
2148 |
Dimension md = memoryMonitorFrame.getSize(); |
2149 |
memoryMonitorFrame.setLocation(fr.x + (fr.width - md.width) / 2, |
2150 |
fr.y + (fr.height - md.height) / 2); |
2151 |
} |
2152 |
memoryMonitorFrame.setVisible(true); |
2153 |
} |
2154 |
} |
2155 |
|
1791 |
|
2156 |
/** |
1792 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
2157 |
* To display the Find dialog |
1793 |
if (choice == JFileChooser.APPROVE_OPTION) { |
2158 |
*/ |
|
|
2159 |
public class FindDialogAction extends AbstractAction { |
2160 |
public FindDialogAction() {} |
2161 |
public void actionPerformed(ActionEvent e) { |
2162 |
if (findDialog == null) { |
2163 |
findDialog = new FindDialog(JSVGViewerFrame.this, svgCanvas); |
2164 |
findDialog.setGraphicsNode(svgCanvas.getGraphicsNode()); |
2165 |
findDialog.pack(); |
2166 |
Rectangle fr = getBounds(); |
2167 |
Dimension td = findDialog.getSize(); |
2168 |
findDialog.setLocation(fr.x + (fr.width - td.width) / 2, |
2169 |
fr.y + (fr.height - td.height) / 2); |
2170 |
} |
2171 |
findDialog.setVisible(true); |
2172 |
} |
2173 |
} |
2174 |
|
1794 |
|
2175 |
/** |
1795 |
// Start: By Jun Inamori (jun@oop-reserch.com) |
2176 |
* To display the Thumbnail dialog |
1796 |
boolean isIndexed = PNGOptionPanel |
2177 |
*/ |
1797 |
.showDialog(JSVGViewerFrame.this); |
2178 |
public class ThumbnailDialogAction extends AbstractAction { |
1798 |
// End: By Jun Inamori (jun@oop-reserch.com) |
2179 |
public ThumbnailDialogAction() {} |
|
|
2180 |
public void actionPerformed(ActionEvent e) { |
2181 |
if (thumbnailDialog == null) { |
2182 |
thumbnailDialog |
2183 |
= new ThumbnailDialog(JSVGViewerFrame.this, svgCanvas); |
2184 |
thumbnailDialog.pack(); |
2185 |
Rectangle fr = getBounds(); |
2186 |
Dimension td = thumbnailDialog.getSize(); |
2187 |
thumbnailDialog.setLocation(fr.x + (fr.width - td.width) / 2, |
2188 |
fr.y + (fr.height - td.height) / 2); |
2189 |
} |
2190 |
thumbnailDialog.setInteractionEnabled |
2191 |
(!svgCanvas.getDisableInteractions()); |
2192 |
thumbnailDialog.setVisible(true); |
2193 |
} |
2194 |
} |
2195 |
|
1799 |
|
2196 |
/** |
1800 |
final File f = fileChooser.getSelectedFile(); |
2197 |
* To display the document full screen |
1801 |
BufferedImage buffer = svgCanvas.getOffScreen(); |
2198 |
*/ |
1802 |
if (buffer != null) { |
2199 |
public class FullScreenAction extends AbstractAction { |
1803 |
statusBar.setMessage(resources |
2200 |
public FullScreenAction() {} |
1804 |
.getString("Message.exportAsPNG")); |
2201 |
|
1805 |
|
2202 |
public void actionPerformed(ActionEvent e) { |
1806 |
// create a BufferedImage of the appropriate type |
2203 |
if (window == null || !window.isVisible()) { |
1807 |
int w = buffer.getWidth(); |
2204 |
if (window == null) { |
1808 |
int h = buffer.getHeight(); |
2205 |
window = new JWindow(JSVGViewerFrame.this); |
1809 |
final ImageTranscoder trans = new PNGTranscoder(); |
2206 |
Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); |
1810 |
if (application.getXMLParserClassName() != null) { |
2207 |
window.setSize(size); |
1811 |
trans.addTranscodingHint( |
2208 |
} |
1812 |
JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
2209 |
// Go to full screen in JWindow) |
1813 |
application.getXMLParserClassName()); |
2210 |
svgCanvas.getParent().remove(svgCanvas); |
1814 |
} |
2211 |
window.getContentPane().add(svgCanvas); |
1815 |
trans.addTranscodingHint( |
2212 |
window.setVisible(true); |
1816 |
PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE, |
2213 |
window.toFront(); |
1817 |
Boolean.TRUE); |
2214 |
svgCanvas.requestFocus(); |
|
|
2215 |
} else { |
2216 |
// Go back to JSVGViewerFrame display |
2217 |
svgCanvas.getParent().remove(svgCanvas); |
2218 |
svgCanvasPanel.add(svgCanvas, BorderLayout.CENTER); |
2219 |
window.setVisible(false); |
2220 |
} |
2221 |
} |
2222 |
} |
2223 |
|
1818 |
|
2224 |
/** |
1819 |
// Start: By Jun Inamori |
2225 |
* To display the DOM viewer of the document |
1820 |
if (isIndexed) { |
2226 |
*/ |
1821 |
trans.addTranscodingHint(PNGTranscoder.KEY_INDEXED, |
2227 |
public class DOMViewerAction extends AbstractAction { |
1822 |
new Integer(256)); |
2228 |
public DOMViewerAction() {} |
1823 |
} |
2229 |
public void actionPerformed(ActionEvent e) { |
1824 |
// End: By Jun Inamori |
2230 |
if (domViewer == null) { |
|
|
2231 |
domViewer = new DOMViewer(); |
2232 |
if (svgDocument != null) { |
2233 |
domViewer.setDocument(svgDocument, |
2234 |
(ViewCSS)svgDocument.getDocumentElement()); |
2235 |
} |
2236 |
Rectangle fr = getBounds(); |
2237 |
Dimension td = domViewer.getSize(); |
2238 |
domViewer.setLocation(fr.x + (fr.width - td.width) / 2, |
2239 |
fr.y + (fr.height - td.height) / 2); |
2240 |
} |
2241 |
domViewer.setVisible(true); |
2242 |
} |
2243 |
} |
2244 |
|
1825 |
|
2245 |
// ActionMap ///////////////////////////////////////////////////// |
1826 |
final BufferedImage img = trans.createImage(w, h); |
2246 |
|
1827 |
|
2247 |
/** |
1828 |
// paint the buffer to the image |
2248 |
* The map that contains the action listeners |
1829 |
Graphics2D g2d = img.createGraphics(); |
2249 |
*/ |
1830 |
g2d.drawImage(buffer, null, 0, 0); |
2250 |
protected Map listeners = new HashMap(); |
1831 |
new Thread() { |
|
|
1832 |
public void run() { |
1833 |
try { |
1834 |
currentSavePath = f; |
1835 |
OutputStream ostream = new BufferedOutputStream( |
1836 |
new FileOutputStream(f)); |
1837 |
trans.writeImage(img, new TranscoderOutput( |
1838 |
ostream)); |
1839 |
ostream.close(); |
1840 |
} catch (Exception ex) { |
1841 |
} |
1842 |
statusBar.setMessage(resources |
1843 |
.getString("Message.done")); |
1844 |
} |
1845 |
}.start(); |
1846 |
} |
1847 |
} |
1848 |
} |
1849 |
} |
2251 |
|
1850 |
|
2252 |
/** |
1851 |
/** |
2253 |
* Returns the action associated with the given string |
1852 |
* To save the current document as TIFF. |
2254 |
* or null on error |
1853 |
*/ |
2255 |
* @param key the key mapped with the action to get |
1854 |
public class ExportAsTIFFAction extends AbstractAction { |
2256 |
* @throws MissingListenerException if the action is not found |
1855 |
public ExportAsTIFFAction() { |
2257 |
*/ |
1856 |
} |
2258 |
public Action getAction(String key) throws MissingListenerException { |
|
|
2259 |
Action result = (Action)listeners.get(key); |
2260 |
//if (result == null) { |
2261 |
//result = canvas.getAction(key); |
2262 |
//} |
2263 |
if (result == null) { |
2264 |
throw new MissingListenerException("Can't find action.", RESOURCES, key); |
2265 |
} |
2266 |
return result; |
2267 |
} |
2268 |
|
1857 |
|
2269 |
// SVGDocumentLoaderListener /////////////////////////////////////////// |
1858 |
public void actionPerformed(ActionEvent e) { |
|
|
1859 |
JFileChooser fileChooser = new JFileChooser( |
1860 |
makeAbsolute(currentSavePath)); |
1861 |
fileChooser.setDialogTitle(resources |
1862 |
.getString("ExportAsTIFF.title")); |
1863 |
fileChooser.setFileHidingEnabled(false); |
1864 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
1865 |
fileChooser.addChoosableFileFilter(new ImageFileFilter(".tiff")); |
2270 |
|
1866 |
|
2271 |
long time; // For debug. |
1867 |
int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); |
|
|
1868 |
if (choice == JFileChooser.APPROVE_OPTION) { |
1869 |
final File f = fileChooser.getSelectedFile(); |
1870 |
BufferedImage buffer = svgCanvas.getOffScreen(); |
1871 |
if (buffer != null) { |
1872 |
statusBar.setMessage(resources |
1873 |
.getString("Message.exportAsTIFF")); |
2272 |
|
1874 |
|
2273 |
/** |
1875 |
// create a BufferedImage of the appropriate type |
2274 |
* Called when the loading of a document was started. |
1876 |
int w = buffer.getWidth(); |
2275 |
*/ |
1877 |
int h = buffer.getHeight(); |
2276 |
public void documentLoadingStarted(SVGDocumentLoaderEvent e) { |
1878 |
final ImageTranscoder trans = new TIFFTranscoder(); |
2277 |
String msg = resources.getString("Message.documentLoad"); |
1879 |
if (application.getXMLParserClassName() != null) { |
2278 |
if (debug) { |
1880 |
trans.addTranscodingHint( |
2279 |
System.out.println(msg); |
1881 |
JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, |
2280 |
time = System.currentTimeMillis(); |
1882 |
application.getXMLParserClassName()); |
2281 |
} |
1883 |
} |
2282 |
statusBar.setMainMessage(msg); |
1884 |
final BufferedImage img = trans.createImage(w, h); |
2283 |
stopAction.update(true); |
|
|
2284 |
svgCanvas.setCursor(WAIT_CURSOR); |
2285 |
} |
2286 |
|
1885 |
|
|
|
1886 |
// paint the buffer to the image |
1887 |
Graphics2D g2d = img.createGraphics(); |
1888 |
g2d.drawImage(buffer, null, 0, 0); |
1889 |
new Thread() { |
1890 |
public void run() { |
1891 |
try { |
1892 |
currentSavePath = f; |
1893 |
OutputStream ostream = new BufferedOutputStream( |
1894 |
new FileOutputStream(f)); |
1895 |
trans.writeImage(img, new TranscoderOutput( |
1896 |
ostream)); |
1897 |
ostream.close(); |
1898 |
} catch (Exception ex) { |
1899 |
} |
1900 |
statusBar.setMessage(resources |
1901 |
.getString("Message.done")); |
1902 |
} |
1903 |
}.start(); |
1904 |
} |
1905 |
} |
1906 |
} |
1907 |
} |
2287 |
|
1908 |
|
2288 |
/** |
1909 |
/** |
2289 |
* Called when the loading of a document was completed. |
1910 |
* To view the source of the current document. |
2290 |
*/ |
1911 |
*/ |
2291 |
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { |
1912 |
public class ViewSourceAction extends AbstractAction { |
2292 |
if (debug) { |
1913 |
|
2293 |
System.out.print(resources.getString("Message.documentLoadTime")); |
1914 |
protected SourceViewFrame sourceViewFrame; |
2294 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
1915 |
|
2295 |
} |
1916 |
protected Thread displayThread; |
|
|
1917 |
|
1918 |
public ViewSourceAction() { |
1919 |
} |
2296 |
|
1920 |
|
2297 |
setSVGDocument(e.getSVGDocument(), |
1921 |
public void actionPerformed(ActionEvent e) { |
2298 |
e.getSVGDocument().getURL(), |
1922 |
if (svgDocument == null) { |
2299 |
e.getSVGDocument().getTitle()); |
1923 |
return; |
2300 |
} |
1924 |
} |
2301 |
|
1925 |
|
2302 |
/** |
1926 |
final ParsedURL u = new ParsedURL(svgDocument.getURL()); |
2303 |
* Forces the viewer frame to show the input SVGDocument |
|
|
2304 |
*/ |
2305 |
public void setSVGDocument(SVGDocument svgDocument, |
2306 |
String svgDocumentURL, |
2307 |
String svgDocumentTitle) { |
2308 |
this.svgDocument = svgDocument; |
2309 |
|
1927 |
|
2310 |
if (domViewer != null) { |
1928 |
sourceViewFrame = new SourceViewFrame(application, userAgent); |
2311 |
if(domViewer.isVisible() && svgDocument != null) { |
1929 |
displayThread = new Thread() { |
2312 |
domViewer.setDocument(svgDocument, |
1930 |
public void run() { |
2313 |
(ViewCSS)svgDocument.getDocumentElement()); |
1931 |
// char[] buffer = new char[4096]; |
2314 |
} else { |
|
|
2315 |
domViewer.dispose(); |
2316 |
domViewer = null; |
2317 |
} |
2318 |
} |
2319 |
stopAction.update(false); |
2320 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2321 |
String s = svgDocumentURL; |
2322 |
locationBar.setText(s); |
2323 |
if (debugger != null) { |
2324 |
debugger.detach(); |
2325 |
debugger.setDocumentURL(s); |
2326 |
} |
2327 |
if (title == null) { |
2328 |
title = getTitle(); |
2329 |
} |
2330 |
|
1932 |
|
2331 |
String dt = svgDocumentTitle; |
1933 |
try { |
2332 |
if (dt.length() != 0) { |
1934 |
StringBuilder sb = new StringBuilder(); |
2333 |
setTitle(title + ": " + dt); |
|
|
2334 |
} else { |
2335 |
int i = s.lastIndexOf("/"); |
2336 |
if (i == -1) |
2337 |
i = s.lastIndexOf("\\"); |
2338 |
if (i == -1) { |
2339 |
setTitle(title + ": " + s); |
2340 |
} else { |
2341 |
setTitle(title + ": " + s.substring(i + 1)); |
2342 |
} |
2343 |
} |
2344 |
|
1935 |
|
2345 |
localHistory.update(s); |
1936 |
ParsedURL purl = new ParsedURL(svgDocument.getURL()); |
2346 |
application.addVisitedURI(s); |
1937 |
InputStream is = u.openStream(getInputHandler(purl) |
2347 |
backAction.update(); |
1938 |
.getHandledMimeTypes()); |
2348 |
forwardAction.update(); |
1939 |
// u.openStream(MimeTypeConstants.MIME_TYPES_SVG); |
2349 |
|
1940 |
|
2350 |
transformHistory = new TransformHistory(); |
1941 |
// Reader in = XMLUtilities.createXMLDocumentReader(is); |
2351 |
previousTransformAction.update(); |
1942 |
// int len; |
2352 |
nextTransformAction.update(); |
1943 |
// while ((len = in.read(buffer, 0, buffer.length)) != -1) { |
|
|
1944 |
// sb.append(new String(buffer, 0, len)); |
1945 |
// } |
2353 |
|
1946 |
|
2354 |
useStylesheetAction.update(); |
1947 |
BufferedReader reader = new BufferedReader( |
2355 |
} |
1948 |
new InputStreamReader(is)); |
|
|
1949 |
String line; |
2356 |
|
1950 |
|
2357 |
/** |
1951 |
while ((line = reader.readLine()) != null) { |
2358 |
* Called when the loading of a document was cancelled. |
1952 |
sb.append(line + "\n"); |
2359 |
*/ |
1953 |
} |
2360 |
public void documentLoadingCancelled(SVGDocumentLoaderEvent e) { |
1954 |
|
2361 |
String msg = resources.getString("Message.documentCancelled"); |
1955 |
sourceViewFrame.setText(sb.toString()); |
2362 |
if (debug) { |
1956 |
sourceViewFrame.setTitle(u.toString()); |
2363 |
System.out.println(msg); |
1957 |
ImageIcon icon = new ImageIcon(getClass().getResource( |
2364 |
} |
1958 |
resources.getString("ViewSource.frameicon"))); |
2365 |
statusBar.setMainMessage(""); |
1959 |
sourceViewFrame.setIconImage(icon.getImage()); |
2366 |
statusBar.setMessage(msg); |
1960 |
sourceViewFrame.setSize(resources.getInteger("ViewSource.width"), |
2367 |
stopAction.update(false); |
1961 |
resources.getInteger("ViewSource.height")); |
2368 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
1962 |
sourceViewFrame.setVisible(true); |
2369 |
} |
1963 |
} catch (Exception ex) { |
|
|
1964 |
userAgent.displayError(ex); |
1965 |
} |
1966 |
} |
1967 |
}; |
1968 |
displayThread.start(); |
1969 |
} |
1970 |
|
1971 |
public SourceViewFrame getSourceViewFrame() { |
1972 |
return sourceViewFrame; |
1973 |
} |
1974 |
|
1975 |
public Thread getDisplayThread() { |
1976 |
return displayThread; |
1977 |
} |
1978 |
} |
2370 |
|
1979 |
|
2371 |
/** |
1980 |
/** |
2372 |
* Called when the loading of a document has failed. |
1981 |
* To flush image cache (purely for debugging purposes) |
2373 |
*/ |
1982 |
*/ |
2374 |
public void documentLoadingFailed(SVGDocumentLoaderEvent e) { |
1983 |
public class FlushAction extends AbstractAction { |
2375 |
String msg = resources.getString("Message.documentFailed"); |
1984 |
public FlushAction() { |
2376 |
if (debug) { |
1985 |
} |
2377 |
System.out.println(msg); |
|
|
2378 |
} |
2379 |
statusBar.setMainMessage(""); |
2380 |
statusBar.setMessage(msg); |
2381 |
stopAction.update(false); |
2382 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2383 |
} |
2384 |
|
1986 |
|
2385 |
// GVTTreeBuilderListener ////////////////////////////////////////////// |
1987 |
public void actionPerformed(ActionEvent e) { |
|
|
1988 |
svgCanvas.flush(); |
1989 |
// Force redraw... |
1990 |
svgCanvas.setRenderingTransform(svgCanvas.getRenderingTransform()); |
1991 |
} |
1992 |
} |
2386 |
|
1993 |
|
2387 |
/** |
1994 |
/** |
2388 |
* Called when a build started. |
1995 |
* To toggle visiblity of JavaScript Debugger. |
2389 |
* The data of the event is initialized to the old document. |
1996 |
*/ |
2390 |
*/ |
1997 |
public class ToggleDebuggerAction extends AbstractAction { |
2391 |
public void gvtBuildStarted(GVTTreeBuilderEvent e) { |
1998 |
public ToggleDebuggerAction() { |
2392 |
String msg = resources.getString("Message.treeBuild"); |
1999 |
super("Toggle Debugger Action"); |
2393 |
if (debug) { |
2000 |
} |
2394 |
System.out.println(msg); |
|
|
2395 |
time = System.currentTimeMillis(); |
2396 |
} |
2397 |
statusBar.setMainMessage(msg); |
2398 |
stopAction.update(true); |
2399 |
svgCanvas.setCursor(WAIT_CURSOR); |
2400 |
} |
2401 |
|
2001 |
|
2402 |
/** |
2002 |
public void actionPerformed(ActionEvent e) { |
2403 |
* Called when a build was completed. |
2003 |
if (debugger == null) { |
2404 |
*/ |
2004 |
showDebugger(); |
2405 |
public void gvtBuildCompleted(GVTTreeBuilderEvent e) { |
2005 |
} else { |
2406 |
if (debug) { |
2006 |
hideDebugger(); |
2407 |
System.out.print(resources.getString("Message.treeBuildTime")); |
2007 |
} |
2408 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2008 |
} |
2409 |
} |
2009 |
} |
2410 |
if (findDialog != null) { |
|
|
2411 |
if(findDialog.isVisible()) { |
2412 |
findDialog.setGraphicsNode(svgCanvas.getGraphicsNode()); |
2413 |
} else { |
2414 |
findDialog.dispose(); |
2415 |
findDialog = null; |
2416 |
} |
2417 |
} |
2418 |
stopAction.update(false); |
2419 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2420 |
svgCanvas.setSelectionOverlayXORMode |
2421 |
(application.isSelectionOverlayXORMode()); |
2422 |
svgCanvas.requestFocus(); // request focus when load completes. |
2423 |
if (debugger != null) { |
2424 |
debugger.attach(); |
2425 |
} |
2426 |
} |
2427 |
|
2010 |
|
2428 |
/** |
2011 |
/** |
2429 |
* Called when a build was cancelled. |
2012 |
* To go back to the previous transform |
2430 |
*/ |
2013 |
*/ |
2431 |
public void gvtBuildCancelled(GVTTreeBuilderEvent e) { |
2014 |
public class PreviousTransformAction extends AbstractAction implements |
2432 |
String msg = resources.getString("Message.treeCancelled"); |
2015 |
JComponentModifier { |
2433 |
if (debug) { |
2016 |
List components = new LinkedList(); |
2434 |
System.out.println(msg); |
|
|
2435 |
} |
2436 |
statusBar.setMainMessage(""); |
2437 |
statusBar.setMessage(msg); |
2438 |
stopAction.update(false); |
2439 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2440 |
svgCanvas.setSelectionOverlayXORMode |
2441 |
(application.isSelectionOverlayXORMode()); |
2442 |
} |
2443 |
|
2017 |
|
2444 |
/** |
2018 |
public PreviousTransformAction() { |
2445 |
* Called when a build failed. |
2019 |
} |
2446 |
*/ |
|
|
2447 |
public void gvtBuildFailed(GVTTreeBuilderEvent e) { |
2448 |
String msg = resources.getString("Message.treeFailed"); |
2449 |
if (debug) { |
2450 |
System.out.println(msg); |
2451 |
} |
2452 |
statusBar.setMainMessage(""); |
2453 |
statusBar.setMessage(msg); |
2454 |
stopAction.update(false); |
2455 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2456 |
svgCanvas.setSelectionOverlayXORMode |
2457 |
(application.isSelectionOverlayXORMode()); |
2458 |
if (autoAdjust) { |
2459 |
pack(); |
2460 |
} |
2461 |
} |
2462 |
|
2020 |
|
2463 |
// SVGLoadEventDispatcherListener ////////////////////////////////////// |
2021 |
public void actionPerformed(ActionEvent e) { |
|
|
2022 |
if (transformHistory.canGoBack()) { |
2023 |
transformHistory.back(); |
2024 |
update(); |
2025 |
nextTransformAction.update(); |
2026 |
svgCanvas.setRenderingTransform(transformHistory |
2027 |
.currentTransform()); |
2028 |
} |
2029 |
} |
2464 |
|
2030 |
|
2465 |
/** |
2031 |
public void addJComponent(JComponent c) { |
2466 |
* Called when a onload event dispatch started. |
2032 |
components.add(c); |
2467 |
*/ |
2033 |
c.setEnabled(false); |
2468 |
public void svgLoadEventDispatchStarted(SVGLoadEventDispatcherEvent e) { |
2034 |
} |
2469 |
String msg = resources.getString("Message.onload"); |
|
|
2470 |
if (debug) { |
2471 |
System.out.println(msg); |
2472 |
time = System.currentTimeMillis(); |
2473 |
} |
2474 |
stopAction.update(true); |
2475 |
statusBar.setMainMessage(msg); |
2476 |
} |
2477 |
|
2035 |
|
2478 |
/** |
2036 |
protected void update() { |
2479 |
* Called when a onload event dispatch was completed. |
2037 |
boolean b = transformHistory.canGoBack(); |
2480 |
*/ |
2038 |
Iterator it = components.iterator(); |
2481 |
public void svgLoadEventDispatchCompleted(SVGLoadEventDispatcherEvent e) { |
2039 |
while (it.hasNext()) { |
2482 |
if (debug) { |
2040 |
((JComponent) it.next()).setEnabled(b); |
2483 |
System.out.print(resources.getString("Message.onloadTime")); |
2041 |
} |
2484 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2042 |
} |
2485 |
} |
2043 |
} |
2486 |
stopAction.update(false); |
|
|
2487 |
statusBar.setMainMessage(""); |
2488 |
statusBar.setMessage(resources.getString("Message.done")); |
2489 |
} |
2490 |
|
2044 |
|
2491 |
/** |
2045 |
/** |
2492 |
* Called when a onload event dispatch was cancelled. |
2046 |
* To go forward to the next transform |
2493 |
*/ |
2047 |
*/ |
2494 |
public void svgLoadEventDispatchCancelled(SVGLoadEventDispatcherEvent e) { |
2048 |
public class NextTransformAction extends AbstractAction implements |
2495 |
String msg = resources.getString("Message.onloadCancelled"); |
2049 |
JComponentModifier { |
2496 |
if (debug) { |
2050 |
List components = new LinkedList(); |
2497 |
System.out.println(msg); |
|
|
2498 |
} |
2499 |
stopAction.update(false); |
2500 |
statusBar.setMainMessage(""); |
2501 |
statusBar.setMessage(msg); |
2502 |
} |
2503 |
|
2051 |
|
2504 |
/** |
2052 |
public NextTransformAction() { |
2505 |
* Called when a onload event dispatch failed. |
2053 |
} |
2506 |
*/ |
|
|
2507 |
public void svgLoadEventDispatchFailed(SVGLoadEventDispatcherEvent e) { |
2508 |
String msg = resources.getString("Message.onloadFailed"); |
2509 |
if (debug) { |
2510 |
System.out.println(msg); |
2511 |
} |
2512 |
stopAction.update(false); |
2513 |
statusBar.setMainMessage(""); |
2514 |
statusBar.setMessage(msg); |
2515 |
} |
2516 |
|
2054 |
|
2517 |
// GVTTreeRendererListener ///////////////////////////////////////////// |
2055 |
public void actionPerformed(ActionEvent e) { |
|
|
2056 |
if (transformHistory.canGoForward()) { |
2057 |
transformHistory.forward(); |
2058 |
update(); |
2059 |
previousTransformAction.update(); |
2060 |
svgCanvas.setRenderingTransform(transformHistory |
2061 |
.currentTransform()); |
2062 |
} |
2063 |
} |
2518 |
|
2064 |
|
2519 |
/** |
2065 |
public void addJComponent(JComponent c) { |
2520 |
* Called when a rendering is in its preparing phase. |
2066 |
components.add(c); |
2521 |
*/ |
2067 |
c.setEnabled(false); |
2522 |
public void gvtRenderingPrepare(GVTTreeRendererEvent e) { |
2068 |
} |
2523 |
if (debug) { |
|
|
2524 |
String msg = resources.getString("Message.treeRenderingPrep"); |
2525 |
System.out.println(msg); |
2526 |
time = System.currentTimeMillis(); |
2527 |
} |
2528 |
stopAction.update(true); |
2529 |
svgCanvas.setCursor(WAIT_CURSOR); |
2530 |
statusBar.setMainMessage(resources.getString("Message.treeRendering")); |
2531 |
} |
2532 |
|
2069 |
|
2533 |
/** |
2070 |
protected void update() { |
2534 |
* Called when a rendering started. |
2071 |
boolean b = transformHistory.canGoForward(); |
2535 |
*/ |
2072 |
Iterator it = components.iterator(); |
2536 |
public void gvtRenderingStarted(GVTTreeRendererEvent e) { |
2073 |
while (it.hasNext()) { |
2537 |
if (debug) { |
2074 |
((JComponent) it.next()).setEnabled(b); |
2538 |
String msg = resources.getString("Message.treeRenderingPrepTime"); |
2075 |
} |
2539 |
System.out.print(msg); |
2076 |
} |
2540 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2077 |
} |
2541 |
time = System.currentTimeMillis(); |
|
|
2542 |
msg = resources.getString("Message.treeRenderingStart"); |
2543 |
System.out.println(msg); |
2544 |
} |
2545 |
// Do nothing |
2546 |
} |
2547 |
|
2078 |
|
2548 |
/** |
2079 |
/** |
2549 |
* Called when a rendering was completed. |
2080 |
* To apply the selected author stylesheet |
2550 |
*/ |
2081 |
*/ |
2551 |
public void gvtRenderingCompleted(GVTTreeRendererEvent e) { |
2082 |
public class UseStylesheetAction extends AbstractAction implements |
2552 |
if (debug) { |
2083 |
JComponentModifier { |
2553 |
String msg = resources.getString("Message.treeRenderingTime"); |
|
|
2554 |
System.out.print(msg); |
2555 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2556 |
} |
2557 |
statusBar.setMainMessage(""); |
2558 |
statusBar.setMessage(resources.getString("Message.done")); |
2559 |
if (!svgCanvas.isDynamic() || managerStopped) { |
2560 |
stopAction.update(false); |
2561 |
} |
2562 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2563 |
|
2084 |
|
2564 |
transformHistory.update(svgCanvas.getRenderingTransform()); |
2085 |
List components = new LinkedList(); |
2565 |
previousTransformAction.update(); |
|
|
2566 |
nextTransformAction.update(); |
2567 |
} |
2568 |
|
2086 |
|
2569 |
/** |
2087 |
public UseStylesheetAction() { |
2570 |
* Called when a rendering was cancelled. |
2088 |
} |
2571 |
*/ |
|
|
2572 |
public void gvtRenderingCancelled(GVTTreeRendererEvent e) { |
2573 |
String msg = resources.getString("Message.treeRenderingCancelled"); |
2574 |
if (debug) { |
2575 |
System.out.println(msg); |
2576 |
} |
2577 |
statusBar.setMainMessage(""); |
2578 |
statusBar.setMessage(msg); |
2579 |
if (!svgCanvas.isDynamic()) { |
2580 |
stopAction.update(false); |
2581 |
} |
2582 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2583 |
} |
2584 |
|
2089 |
|
2585 |
/** |
2090 |
public void actionPerformed(ActionEvent e) { |
2586 |
* Called when a rendering failed. |
2091 |
} |
2587 |
*/ |
|
|
2588 |
public void gvtRenderingFailed(GVTTreeRendererEvent e) { |
2589 |
String msg = resources.getString("Message.treeRenderingFailed"); |
2590 |
if (debug) { |
2591 |
System.out.println(msg); |
2592 |
} |
2593 |
statusBar.setMainMessage(""); |
2594 |
statusBar.setMessage(msg); |
2595 |
if (!svgCanvas.isDynamic()) { |
2596 |
stopAction.update(false); |
2597 |
} |
2598 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2599 |
} |
2600 |
|
2092 |
|
2601 |
// LinkActivationListener ///////////////////////////////////////// |
2093 |
public void addJComponent(JComponent c) { |
|
|
2094 |
components.add(c); |
2095 |
c.setEnabled(false); |
2096 |
} |
2602 |
|
2097 |
|
2603 |
/** |
2098 |
protected void update() { |
2604 |
* Called when a link was activated. |
2099 |
alternateStyleSheet = null; |
2605 |
*/ |
2100 |
Iterator it = components.iterator(); |
2606 |
public void linkActivated(LinkActivationEvent e) { |
2101 |
SVGDocument doc = svgCanvas.getSVGDocument(); |
2607 |
String s = e.getReferencedURI(); |
2102 |
while (it.hasNext()) { |
2608 |
if (svgDocument != null) { |
2103 |
JComponent stylesheetMenu = (JComponent) it.next(); |
2609 |
ParsedURL docURL = new ParsedURL(svgDocument.getURL()); |
2104 |
stylesheetMenu.removeAll(); |
2610 |
ParsedURL url = new ParsedURL(docURL, s); |
2105 |
stylesheetMenu.setEnabled(false); |
2611 |
if (!url.sameFile(docURL)) { |
|
|
2612 |
return; |
2613 |
} |
2614 |
|
2106 |
|
2615 |
if (s.indexOf( '#' ) != -1) { |
2107 |
ButtonGroup buttonGroup = new ButtonGroup(); |
2616 |
localHistory.update(s); |
|
|
2617 |
locationBar.setText(s); |
2618 |
if (debugger != null) { |
2619 |
debugger.detach(); |
2620 |
debugger.setDocumentURL(s); |
2621 |
} |
2622 |
application.addVisitedURI(s); |
2623 |
backAction.update(); |
2624 |
forwardAction.update(); |
2625 |
|
2108 |
|
2626 |
transformHistory = new TransformHistory(); |
2109 |
for (Node n = doc.getFirstChild(); n != null |
2627 |
previousTransformAction.update(); |
2110 |
&& n.getNodeType() != Node.ELEMENT_NODE; n = n |
2628 |
nextTransformAction.update(); |
2111 |
.getNextSibling()) { |
2629 |
} |
2112 |
if (n instanceof StyleSheetProcessingInstruction) { |
2630 |
} |
2113 |
StyleSheetProcessingInstruction sspi; |
2631 |
} |
2114 |
sspi = (StyleSheetProcessingInstruction) n; |
|
|
2115 |
HashTable attrs = sspi.getPseudoAttributes(); |
2116 |
final String title = (String) attrs.get("title"); |
2117 |
String alt = (String) attrs.get("alternate"); |
2118 |
if (title != null && "yes".equals(alt)) { |
2119 |
JRadioButtonMenuItem button; |
2120 |
button = new JRadioButtonMenuItem(title); |
2632 |
|
2121 |
|
2633 |
// UpdateManagerListener //////////////////////////////////////////////// |
2122 |
button |
|
|
2123 |
.addActionListener(new java.awt.event.ActionListener() { |
2124 |
public void actionPerformed( |
2125 |
ActionEvent e) { |
2126 |
SVGOMDocument doc; |
2127 |
doc = (SVGOMDocument) svgCanvas |
2128 |
.getSVGDocument(); |
2129 |
doc.clearViewCSS(); |
2130 |
alternateStyleSheet = title; |
2131 |
svgCanvas.setSVGDocument(doc); |
2132 |
} |
2133 |
}); |
2634 |
|
2134 |
|
2635 |
/** |
2135 |
buttonGroup.add(button); |
2636 |
* Called when the manager was started. |
2136 |
stylesheetMenu.add(button); |
2637 |
*/ |
2137 |
stylesheetMenu.setEnabled(true); |
2638 |
public void managerStarted(UpdateManagerEvent e) { |
2138 |
} |
2639 |
if (debug) { |
2139 |
} |
2640 |
String msg = resources.getString("Message.updateManagerStarted"); |
2140 |
} |
2641 |
System.out.println(msg); |
2141 |
} |
2642 |
} |
2142 |
} |
2643 |
managerStopped = false; |
2143 |
} |
2644 |
playAction.update(false); |
|
|
2645 |
pauseAction.update(true); |
2646 |
stopAction.update(true); |
2647 |
} |
2648 |
|
2144 |
|
2649 |
/** |
2145 |
/** |
2650 |
* Called when the manager was suspended. |
2146 |
* To restart after a pause. |
2651 |
*/ |
2147 |
*/ |
2652 |
public void managerSuspended(UpdateManagerEvent e) { |
2148 |
public class PlayAction extends AbstractAction implements |
2653 |
if (debug) { |
2149 |
JComponentModifier { |
2654 |
String msg = resources.getString("Message.updateManagerSuspended"); |
2150 |
List components = new LinkedList(); |
2655 |
System.out.println(msg); |
|
|
2656 |
} |
2657 |
playAction.update(true); |
2658 |
pauseAction.update(false); |
2659 |
} |
2660 |
|
2151 |
|
2661 |
/** |
2152 |
public PlayAction() { |
2662 |
* Called when the manager was resumed. |
2153 |
} |
2663 |
*/ |
|
|
2664 |
public void managerResumed(UpdateManagerEvent e) { |
2665 |
if (debug) { |
2666 |
String msg = resources.getString("Message.updateManagerResumed"); |
2667 |
System.out.println(msg); |
2668 |
} |
2669 |
playAction.update(false); |
2670 |
pauseAction.update(true); |
2671 |
} |
2672 |
|
2154 |
|
2673 |
/** |
2155 |
public void actionPerformed(ActionEvent e) { |
2674 |
* Called when the manager was stopped. |
2156 |
svgCanvas.resumeProcessing(); |
2675 |
*/ |
2157 |
} |
2676 |
public void managerStopped(UpdateManagerEvent e) { |
|
|
2677 |
if (debug) { |
2678 |
String msg = resources.getString("Message.updateManagerStopped"); |
2679 |
System.out.println(msg); |
2680 |
} |
2681 |
managerStopped = true; |
2682 |
playAction.update(false); |
2683 |
pauseAction.update(false); |
2684 |
stopAction.update(false); |
2685 |
} |
2686 |
|
2158 |
|
2687 |
/** |
2159 |
public void addJComponent(JComponent c) { |
2688 |
* Called when an update started. |
2160 |
components.add(c); |
2689 |
*/ |
2161 |
c.setEnabled(false); |
2690 |
public void updateStarted(final UpdateManagerEvent e) { |
2162 |
} |
2691 |
} |
|
|
2692 |
|
2163 |
|
2693 |
/** |
2164 |
public void update(boolean enabled) { |
2694 |
* Called when an update was completed. |
2165 |
Iterator it = components.iterator(); |
2695 |
*/ |
2166 |
while (it.hasNext()) { |
2696 |
public void updateCompleted(final UpdateManagerEvent e) { |
2167 |
((JComponent) it.next()).setEnabled(enabled); |
2697 |
} |
2168 |
} |
|
|
2169 |
} |
2170 |
} |
2698 |
|
2171 |
|
2699 |
/** |
2172 |
/** |
2700 |
* Called when an update failed. |
2173 |
* To pause a document. |
2701 |
*/ |
2174 |
*/ |
2702 |
public void updateFailed(UpdateManagerEvent e) { |
2175 |
public class PauseAction extends AbstractAction implements |
2703 |
} |
2176 |
JComponentModifier { |
|
|
2177 |
List components = new LinkedList(); |
2704 |
|
2178 |
|
2705 |
/** |
2179 |
public PauseAction() { |
2706 |
* This class implements a SVG user agent. |
2180 |
} |
2707 |
*/ |
|
|
2708 |
protected class UserAgent implements SVGUserAgent { |
2709 |
|
2181 |
|
2710 |
/** |
2182 |
public void actionPerformed(ActionEvent e) { |
2711 |
* Creates a new SVGUserAgent. |
2183 |
svgCanvas.suspendProcessing(); |
2712 |
*/ |
2184 |
} |
2713 |
protected UserAgent() { |
|
|
2714 |
} |
2715 |
|
2185 |
|
2716 |
/** |
2186 |
public void addJComponent(JComponent c) { |
2717 |
* Displays an error message. |
2187 |
components.add(c); |
2718 |
*/ |
2188 |
c.setEnabled(false); |
2719 |
public void displayError(String message) { |
2189 |
} |
2720 |
if (debug) { |
|
|
2721 |
System.err.println(message); |
2722 |
} |
2723 |
JOptionPane pane = |
2724 |
new JOptionPane(message, JOptionPane.ERROR_MESSAGE); |
2725 |
JDialog dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR"); |
2726 |
dialog.setModal(false); |
2727 |
dialog.setVisible(true); |
2728 |
} |
2729 |
|
2190 |
|
2730 |
/** |
2191 |
public void update(boolean enabled) { |
2731 |
* Displays an error resulting from the specified Exception. |
2192 |
Iterator it = components.iterator(); |
2732 |
*/ |
2193 |
while (it.hasNext()) { |
2733 |
public void displayError(Exception ex) { |
2194 |
((JComponent) it.next()).setEnabled(enabled); |
2734 |
if (debug) { |
2195 |
} |
2735 |
ex.printStackTrace(); |
2196 |
} |
2736 |
} |
2197 |
} |
2737 |
JErrorPane pane = |
|
|
2738 |
new JErrorPane(ex, JOptionPane.ERROR_MESSAGE); |
2739 |
JDialog dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR"); |
2740 |
dialog.setModal(false); |
2741 |
dialog.setVisible(true); |
2742 |
} |
2743 |
|
2198 |
|
2744 |
/** |
2199 |
/** |
2745 |
* Displays a message in the User Agent interface. |
2200 |
* To stop the current processing. |
2746 |
* The given message is typically displayed in a status bar. |
2201 |
*/ |
2747 |
*/ |
2202 |
public class StopAction extends AbstractAction implements |
2748 |
public void displayMessage(String message) { |
2203 |
JComponentModifier { |
2749 |
statusBar.setMessage(message); |
2204 |
List components = new LinkedList(); |
2750 |
} |
|
|
2751 |
|
2205 |
|
2752 |
/** |
2206 |
public StopAction() { |
2753 |
* Shows an alert dialog box. |
2207 |
} |
2754 |
*/ |
|
|
2755 |
public void showAlert(String message) { |
2756 |
svgCanvas.showAlert(message); |
2757 |
} |
2758 |
|
2208 |
|
2759 |
/** |
2209 |
public void actionPerformed(ActionEvent e) { |
2760 |
* Shows a prompt dialog box. |
2210 |
svgCanvas.stopProcessing(); |
2761 |
*/ |
2211 |
} |
2762 |
public String showPrompt(String message) { |
|
|
2763 |
return svgCanvas.showPrompt(message); |
2764 |
} |
2765 |
|
2212 |
|
2766 |
/** |
2213 |
public void addJComponent(JComponent c) { |
2767 |
* Shows a prompt dialog box. |
2214 |
components.add(c); |
2768 |
*/ |
2215 |
c.setEnabled(false); |
2769 |
public String showPrompt(String message, String defaultValue) { |
2216 |
} |
2770 |
return svgCanvas.showPrompt(message, defaultValue); |
|
|
2771 |
} |
2772 |
|
2217 |
|
2773 |
/** |
2218 |
public void update(boolean enabled) { |
2774 |
* Shows a confirm dialog box. |
2219 |
Iterator it = components.iterator(); |
2775 |
*/ |
2220 |
while (it.hasNext()) { |
2776 |
public boolean showConfirm(String message) { |
2221 |
((JComponent) it.next()).setEnabled(enabled); |
2777 |
return svgCanvas.showConfirm(message); |
2222 |
} |
2778 |
} |
2223 |
} |
|
|
2224 |
} |
2779 |
|
2225 |
|
2780 |
/** |
2226 |
/** |
2781 |
* Returns the size of a px CSS unit in millimeters. |
2227 |
* To show the set transform dialog |
2782 |
*/ |
2228 |
*/ |
2783 |
public float getPixelUnitToMillimeter() { |
2229 |
public class SetTransformAction extends AbstractAction { |
2784 |
return 0.26458333333333333333333333333333f; // 96dpi |
2230 |
public SetTransformAction() { |
2785 |
} |
2231 |
} |
2786 |
|
2232 |
|
2787 |
/** |
2233 |
public void actionPerformed(ActionEvent e) { |
2788 |
* Returns the size of a px CSS unit in millimeters. |
2234 |
if (transformDialog == null) { |
2789 |
* This will be removed after next release. |
2235 |
transformDialog = JAffineTransformChooser.createDialog( |
2790 |
* @see #getPixelUnitToMillimeter() |
2236 |
JSVGViewerFrame.this, resources |
2791 |
*/ |
2237 |
.getString("SetTransform.title")); |
2792 |
public float getPixelToMM() { |
2238 |
} |
2793 |
return getPixelUnitToMillimeter(); |
|
|
2794 |
|
2239 |
|
2795 |
} |
2240 |
AffineTransform txf = transformDialog.showDialog(); |
|
|
2241 |
if (txf != null) { |
2242 |
AffineTransform at = svgCanvas.getRenderingTransform(); |
2243 |
if (at == null) { |
2244 |
at = new AffineTransform(); |
2245 |
} |
2796 |
|
2246 |
|
2797 |
/** |
2247 |
txf.concatenate(at); |
2798 |
* Returns the default font family. |
2248 |
svgCanvas.setRenderingTransform(txf); |
2799 |
*/ |
2249 |
} |
2800 |
public String getDefaultFontFamily() { |
2250 |
} |
2801 |
return application.getDefaultFontFamily(); |
2251 |
} |
2802 |
} |
|
|
2803 |
|
2252 |
|
2804 |
/** |
2253 |
/** |
2805 |
* Returns the medium font size. |
2254 |
* To display the memory monitor. |
2806 |
*/ |
2255 |
*/ |
2807 |
public float getMediumFontSize() { |
2256 |
public class MonitorAction extends AbstractAction { |
2808 |
// 9pt (72pt == 1in) |
2257 |
public MonitorAction() { |
2809 |
return 9f * 25.4f / (72f * getPixelUnitToMillimeter()); |
2258 |
} |
2810 |
} |
|
|
2811 |
|
2259 |
|
2812 |
/** |
2260 |
public void actionPerformed(ActionEvent e) { |
2813 |
* Returns a lighter font-weight. |
2261 |
if (memoryMonitorFrame == null) { |
2814 |
*/ |
2262 |
memoryMonitorFrame = new MemoryMonitor(); |
2815 |
public float getLighterFontWeight(float f) { |
2263 |
Rectangle fr = getBounds(); |
2816 |
// Round f to nearest 100... |
2264 |
Dimension md = memoryMonitorFrame.getSize(); |
2817 |
int weight = ((int)((f+50)/100))*100; |
2265 |
memoryMonitorFrame.setLocation( |
2818 |
switch (weight) { |
2266 |
fr.x + (fr.width - md.width) / 2, fr.y |
2819 |
case 100: return 100; |
2267 |
+ (fr.height - md.height) / 2); |
2820 |
case 200: return 100; |
2268 |
} |
2821 |
case 300: return 200; |
2269 |
memoryMonitorFrame.setVisible(true); |
2822 |
case 400: return 300; |
2270 |
} |
2823 |
case 500: return 400; |
2271 |
} |
2824 |
case 600: return 400; |
|
|
2825 |
case 700: return 400; |
2826 |
case 800: return 400; |
2827 |
case 900: return 400; |
2828 |
default: |
2829 |
throw new IllegalArgumentException("Bad Font Weight: " + f); |
2830 |
} |
2831 |
} |
2832 |
|
2272 |
|
2833 |
/** |
2273 |
/** |
2834 |
* Returns a bolder font-weight. |
2274 |
* To display the Find dialog |
2835 |
*/ |
2275 |
*/ |
2836 |
public float getBolderFontWeight(float f) { |
2276 |
public class FindDialogAction extends AbstractAction { |
2837 |
// Round f to nearest 100... |
2277 |
public FindDialogAction() { |
2838 |
int weight = ((int)((f+50)/100))*100; |
2278 |
} |
2839 |
switch (weight) { |
|
|
2840 |
case 100: return 600; |
2841 |
case 200: return 600; |
2842 |
case 300: return 600; |
2843 |
case 400: return 600; |
2844 |
case 500: return 600; |
2845 |
case 600: return 700; |
2846 |
case 700: return 800; |
2847 |
case 800: return 900; |
2848 |
case 900: return 900; |
2849 |
default: |
2850 |
throw new IllegalArgumentException("Bad Font Weight: " + f); |
2851 |
} |
2852 |
} |
2853 |
|
2279 |
|
|
|
2280 |
public void actionPerformed(ActionEvent e) { |
2281 |
if (findDialog == null) { |
2282 |
findDialog = new FindDialog(JSVGViewerFrame.this, svgCanvas); |
2283 |
findDialog.setGraphicsNode(svgCanvas.getGraphicsNode()); |
2284 |
findDialog.pack(); |
2285 |
Rectangle fr = getBounds(); |
2286 |
Dimension td = findDialog.getSize(); |
2287 |
findDialog.setLocation(fr.x + (fr.width - td.width) / 2, fr.y |
2288 |
+ (fr.height - td.height) / 2); |
2289 |
} |
2290 |
findDialog.setVisible(true); |
2291 |
} |
2292 |
} |
2854 |
|
2293 |
|
2855 |
/** |
2294 |
/** |
2856 |
* Returns the language settings. |
2295 |
* To display the Thumbnail dialog |
2857 |
*/ |
2296 |
*/ |
2858 |
public String getLanguages() { |
2297 |
public class ThumbnailDialogAction extends AbstractAction { |
2859 |
return application.getLanguages(); |
2298 |
public ThumbnailDialogAction() { |
2860 |
} |
2299 |
} |
2861 |
|
2300 |
|
2862 |
/** |
2301 |
public void actionPerformed(ActionEvent e) { |
2863 |
* Returns the user stylesheet uri. |
2302 |
if (thumbnailDialog == null) { |
2864 |
* @return null if no user style sheet was specified. |
2303 |
thumbnailDialog = new ThumbnailDialog(JSVGViewerFrame.this, |
2865 |
*/ |
2304 |
svgCanvas); |
2866 |
public String getUserStyleSheetURI() { |
2305 |
thumbnailDialog.pack(); |
2867 |
return application.getUserStyleSheetURI(); |
2306 |
Rectangle fr = getBounds(); |
2868 |
} |
2307 |
Dimension td = thumbnailDialog.getSize(); |
|
|
2308 |
thumbnailDialog.setLocation(fr.x + (fr.width - td.width) / 2, |
2309 |
fr.y + (fr.height - td.height) / 2); |
2310 |
} |
2311 |
thumbnailDialog.setInteractionEnabled(!svgCanvas |
2312 |
.getDisableInteractions()); |
2313 |
thumbnailDialog.setVisible(true); |
2314 |
} |
2315 |
} |
2869 |
|
2316 |
|
2870 |
/** |
2317 |
/** |
2871 |
* Returns the class name of the XML parser. |
2318 |
* To display the document full screen |
2872 |
*/ |
2319 |
*/ |
2873 |
public String getXMLParserClassName() { |
2320 |
public class FullScreenAction extends AbstractAction { |
2874 |
return application.getXMLParserClassName(); |
2321 |
public FullScreenAction() { |
2875 |
} |
2322 |
} |
2876 |
|
2323 |
|
2877 |
/** |
2324 |
public void actionPerformed(ActionEvent e) { |
2878 |
* Returns true if the XML parser must be in validation mode, false |
2325 |
if (window == null || !window.isVisible()) { |
2879 |
* otherwise. |
2326 |
if (window == null) { |
2880 |
*/ |
2327 |
window = new JWindow(JSVGViewerFrame.this); |
2881 |
public boolean isXMLParserValidating() { |
2328 |
Dimension size = Toolkit.getDefaultToolkit() |
2882 |
return application.isXMLParserValidating(); |
2329 |
.getScreenSize(); |
2883 |
} |
2330 |
window.setSize(size); |
|
|
2331 |
} |
2332 |
// Go to full screen in JWindow) |
2333 |
svgCanvas.getParent().remove(svgCanvas); |
2334 |
window.getContentPane().add(svgCanvas); |
2335 |
window.setVisible(true); |
2336 |
window.toFront(); |
2337 |
svgCanvas.requestFocus(); |
2338 |
} else { |
2339 |
// Go back to JSVGViewerFrame display |
2340 |
svgCanvas.getParent().remove(svgCanvas); |
2341 |
svgCanvasPanel.add(svgCanvas, BorderLayout.CENTER); |
2342 |
window.setVisible(false); |
2343 |
} |
2344 |
} |
2345 |
} |
2884 |
|
2346 |
|
2885 |
/** |
2347 |
/** |
2886 |
* Returns this user agent's CSS media. |
2348 |
* To display the DOM viewer of the document |
2887 |
*/ |
2349 |
*/ |
2888 |
public String getMedia() { |
2350 |
public class DOMViewerAction extends AbstractAction { |
2889 |
return application.getMedia(); |
2351 |
|
2890 |
} |
2352 |
public DOMViewerAction() { |
|
|
2353 |
} |
2891 |
|
2354 |
|
2892 |
/** |
2355 |
public void actionPerformed(ActionEvent e) { |
2893 |
* Returns this user agent's alternate style-sheet title. |
2356 |
if (domViewer == null) { |
2894 |
*/ |
2357 |
domViewer = new DOMViewer(); |
2895 |
public String getAlternateStyleSheet() { |
2358 |
if (svgDocument != null) { |
2896 |
return alternateStyleSheet; |
2359 |
domViewer.setDocument(svgDocument, (ViewCSS) svgDocument |
2897 |
} |
2360 |
.getDocumentElement()); |
|
|
2361 |
} |
2362 |
Rectangle fr = getBounds(); |
2363 |
Dimension td = domViewer.getSize(); |
2364 |
domViewer.setLocation(fr.x + (fr.width - td.width) / 2, fr.y |
2365 |
+ (fr.height - td.height) / 2); |
2366 |
} |
2367 |
domViewer.setVisible(true); |
2368 |
} |
2369 |
|
2370 |
public DOMViewer getDOMViewer() { |
2371 |
return domViewer; |
2372 |
} |
2373 |
} |
2898 |
|
2374 |
|
2899 |
/** |
2375 |
/** |
2900 |
* Opens a link. |
2376 |
* To display the Timeline viewer of the document |
2901 |
* @param uri The document URI. |
2377 |
*/ |
2902 |
* @param newc Whether the link should be activated in a new component. |
2378 |
public class TimelineViewerAction extends AbstractAction { |
2903 |
*/ |
2379 |
public TimelineViewerAction() { |
2904 |
public void openLink(String uri, boolean newc) { |
2380 |
} |
2905 |
if (newc) { |
|
|
2906 |
application.openLink(uri); |
2907 |
} else { |
2908 |
showSVGDocument(uri); |
2909 |
} |
2910 |
} |
2911 |
|
2381 |
|
2912 |
/** |
2382 |
public void actionPerformed(ActionEvent e) { |
2913 |
* Tells whether the given extension is supported by this |
2383 |
if (timelineViewer == null) { |
2914 |
* user agent. |
2384 |
timelineViewer = new TimelineViewer(svgDocument); |
2915 |
*/ |
2385 |
Rectangle fr = getBounds(); |
2916 |
public boolean supportExtension(String s) { |
2386 |
Dimension td = timelineViewer.getSize(); |
2917 |
return false; |
2387 |
timelineViewer.setLocation(fr.x + (fr.width - td.width) / 2, fr.y |
2918 |
} |
2388 |
+ (fr.height - td.height) / 2); |
|
|
2389 |
} |
2390 |
timelineViewer.setVisible(true); |
2391 |
} |
2392 |
} |
2919 |
|
2393 |
|
2920 |
public void handleElement(Element elt, Object data){ |
2394 |
// ActionMap ///////////////////////////////////////////////////// |
2921 |
} |
|
|
2922 |
|
2395 |
|
2923 |
/** |
2396 |
/** |
2924 |
* Returns the security settings for the given script |
2397 |
* The map that contains the action listeners |
2925 |
* type, script url and document url |
2398 |
*/ |
2926 |
* |
2399 |
protected Map listeners = new HashMap(); |
2927 |
* @param scriptType type of script, as found in the |
|
|
2928 |
* type attribute of the <script> element. |
2929 |
* @param scriptURL url for the script, as defined in |
2930 |
* the script's xlink:href attribute. If that |
2931 |
* attribute was empty, then this parameter should |
2932 |
* be null |
2933 |
* @param docURL url for the document into which the |
2934 |
* script was found. |
2935 |
*/ |
2936 |
public ScriptSecurity getScriptSecurity(String scriptType, |
2937 |
ParsedURL scriptURL, |
2938 |
ParsedURL docURL){ |
2939 |
if (!application.canLoadScriptType(scriptType)) { |
2940 |
return new NoLoadScriptSecurity(scriptType); |
2941 |
} else { |
2942 |
switch(application.getAllowedScriptOrigin()) { |
2943 |
case ResourceOrigin.ANY: |
2944 |
return new RelaxedScriptSecurity(scriptType, |
2945 |
scriptURL, |
2946 |
docURL); |
2947 |
case ResourceOrigin.DOCUMENT: |
2948 |
return new DefaultScriptSecurity(scriptType, |
2949 |
scriptURL, |
2950 |
docURL); |
2951 |
case ResourceOrigin.EMBEDED: |
2952 |
return new EmbededScriptSecurity(scriptType, |
2953 |
scriptURL, |
2954 |
docURL); |
2955 |
default: |
2956 |
return new NoLoadScriptSecurity(scriptType); |
2957 |
} |
2958 |
} |
2959 |
} |
2960 |
|
2400 |
|
2961 |
/** |
2401 |
/** |
2962 |
* This method throws a SecurityException if the script |
2402 |
* Returns the action associated with the given string or null on error |
2963 |
* of given type, found at url and referenced from docURL |
2403 |
* |
2964 |
* should not be loaded. |
2404 |
* @param key |
2965 |
* |
2405 |
* the key mapped with the action to get |
2966 |
* This is a convenience method to call checkLoadScript |
2406 |
* @throws MissingListenerException |
2967 |
* on the ScriptSecurity strategy returned by |
2407 |
* if the action is not found |
2968 |
* getScriptSecurity. |
2408 |
*/ |
2969 |
* |
2409 |
public Action getAction(String key) throws MissingListenerException { |
2970 |
* @param scriptType type of script, as found in the |
2410 |
Action result = (Action) listeners.get(key); |
2971 |
* type attribute of the <script> element. |
2411 |
// if (result == null) { |
2972 |
* @param scriptURL url for the script, as defined in |
2412 |
// result = canvas.getAction(key); |
2973 |
* the script's xlink:href attribute. If that |
2413 |
// } |
2974 |
* attribute was empty, then this parameter should |
2414 |
if (result == null) { |
2975 |
* be null |
2415 |
throw new MissingListenerException("Can't find action.", RESOURCES, |
2976 |
* @param docURL url for the document into which the |
2416 |
key); |
2977 |
* script was found. |
2417 |
} |
2978 |
*/ |
2418 |
return result; |
2979 |
public void checkLoadScript(String scriptType, |
2419 |
} |
2980 |
ParsedURL scriptURL, |
|
|
2981 |
ParsedURL docURL) throws SecurityException { |
2982 |
ScriptSecurity s = getScriptSecurity(scriptType, |
2983 |
scriptURL, |
2984 |
docURL); |
2985 |
|
2420 |
|
2986 |
if (s != null) { |
2421 |
// SVGDocumentLoaderListener /////////////////////////////////////////// |
2987 |
s.checkLoadScript(); |
|
|
2988 |
} |
2989 |
} |
2990 |
|
2422 |
|
2991 |
/** |
2423 |
long time; // For debug. |
2992 |
* Returns the security settings for the given |
|
|
2993 |
* resource url and document url |
2994 |
* |
2995 |
* @param resourceURL url for the resource, as defined in |
2996 |
* the resource's xlink:href attribute. If that |
2997 |
* attribute was empty, then this parameter should |
2998 |
* be null |
2999 |
* @param docURL url for the document into which the |
3000 |
* resource was found. |
3001 |
*/ |
3002 |
public ExternalResourceSecurity |
3003 |
getExternalResourceSecurity(ParsedURL resourceURL, |
3004 |
ParsedURL docURL){ |
3005 |
switch(application.getAllowedExternalResourceOrigin()) { |
3006 |
case ResourceOrigin.ANY: |
3007 |
return new RelaxedExternalResourceSecurity(resourceURL, |
3008 |
docURL); |
3009 |
case ResourceOrigin.DOCUMENT: |
3010 |
return new DefaultExternalResourceSecurity(resourceURL, |
3011 |
docURL); |
3012 |
case ResourceOrigin.EMBEDED: |
3013 |
return new EmbededExternalResourceSecurity(resourceURL); |
3014 |
default: |
3015 |
return new NoLoadExternalResourceSecurity(); |
3016 |
} |
3017 |
} |
3018 |
|
2424 |
|
3019 |
/** |
2425 |
/** |
3020 |
* This method throws a SecurityException if the resource |
2426 |
* Called when the loading of a document was started. |
3021 |
* found at url and referenced from docURL |
2427 |
*/ |
3022 |
* should not be loaded. |
2428 |
public void documentLoadingStarted(SVGDocumentLoaderEvent e) { |
3023 |
* |
2429 |
String msg = resources.getString("Message.documentLoad"); |
3024 |
* This is a convenience method to call checkLoadExternalResource |
2430 |
if (debug) { |
3025 |
* on the ExternalResourceSecurity strategy returned by |
2431 |
System.out.println(msg); |
3026 |
* getExternalResourceSecurity. |
2432 |
time = System.currentTimeMillis(); |
3027 |
* |
2433 |
} |
3028 |
* @param resourceURL url for the script, as defined in |
2434 |
statusBar.setMainMessage(msg); |
3029 |
* the resource's xlink:href attribute. If that |
2435 |
stopAction.update(true); |
3030 |
* attribute was empty, then this parameter should |
2436 |
svgCanvas.setCursor(WAIT_CURSOR); |
3031 |
* be null |
2437 |
} |
3032 |
* @param docURL url for the document into which the |
|
|
3033 |
* resource was found. |
3034 |
*/ |
3035 |
public void |
3036 |
checkLoadExternalResource(ParsedURL resourceURL, |
3037 |
ParsedURL docURL) throws SecurityException { |
3038 |
ExternalResourceSecurity s |
3039 |
= getExternalResourceSecurity(resourceURL, docURL); |
3040 |
|
2438 |
|
3041 |
if (s != null) { |
2439 |
/** |
3042 |
s.checkLoadExternalResource(); |
2440 |
* Called when the loading of a document was completed. |
3043 |
} |
2441 |
*/ |
3044 |
} |
2442 |
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { |
3045 |
} |
2443 |
if (debug) { |
|
|
2444 |
System.out.print(resources.getString("Message.documentLoadTime")); |
2445 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2446 |
} |
3046 |
|
2447 |
|
3047 |
/** |
2448 |
setSVGDocument(e.getSVGDocument(), e.getSVGDocument().getURL(), e |
3048 |
* A FileFilter used when exporting the SVG document as an image. |
2449 |
.getSVGDocument().getTitle(), e.getDocumentDescriptor()); |
3049 |
*/ |
2450 |
} |
3050 |
protected static class ImageFileFilter extends FileFilter { |
|
|
3051 |
|
2451 |
|
3052 |
/** The extension of the image filename. */ |
2452 |
/** |
3053 |
protected String extension; |
2453 |
* Forces the viewer frame to show the input SVGDocument |
|
|
2454 |
*/ |
2455 |
public void setSVGDocument(SVGDocument svgDocument, String svgDocumentURL, |
2456 |
String svgDocumentTitle, DocumentDescriptor docDescriptor) { |
2457 |
this.svgDocument = svgDocument; |
2458 |
this.docDescriptor = docDescriptor; |
3054 |
|
2459 |
|
3055 |
public ImageFileFilter(String extension) { |
2460 |
if (domViewer != null) { |
3056 |
this.extension = extension; |
2461 |
if (domViewer.isVisible() && svgDocument != null) { |
3057 |
} |
2462 |
domViewer.setDocument(svgDocument, (ViewCSS) svgDocument |
|
|
2463 |
.getDocumentElement()); |
2464 |
} else { |
2465 |
domViewer.dispose(); |
2466 |
domViewer = null; |
2467 |
} |
2468 |
} |
2469 |
if (timelineViewer != null) { |
2470 |
if (timelineViewer.isVisible() && svgDocument != null) { |
2471 |
// timelineViewer.setDocument(svgDocument); |
2472 |
} else { |
2473 |
// timelineViewer.dispose(); |
2474 |
timelineViewer = null; |
2475 |
} |
2476 |
} |
2477 |
stopAction.update(false); |
2478 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2479 |
String s = svgDocumentURL; |
2480 |
locationBar.setText(s); |
2481 |
if (debugger != null) { |
2482 |
debugger.detach(); |
2483 |
debugger.setDocumentURL(s); |
2484 |
} |
2485 |
if (title == null) { |
2486 |
title = getTitle(); |
2487 |
} |
3058 |
|
2488 |
|
3059 |
/** |
2489 |
String dt = svgDocumentTitle; |
3060 |
* Returns true if <tt>f</tt> is a file with the correct extension, |
2490 |
if (dt.length() != 0) { |
3061 |
* false otherwise. |
2491 |
setTitle(title + ": " + dt); |
3062 |
*/ |
2492 |
} else { |
3063 |
public boolean accept(File f) { |
2493 |
int i = s.lastIndexOf("/"); |
3064 |
boolean accept = false; |
2494 |
if (i == -1) |
3065 |
String fileName = null; |
2495 |
i = s.lastIndexOf("\\"); |
3066 |
if (f != null) { |
2496 |
if (i == -1) { |
3067 |
if (f.isDirectory()) { |
2497 |
setTitle(title + ": " + s); |
3068 |
accept = true; |
2498 |
} else { |
3069 |
} else { |
2499 |
setTitle(title + ": " + s.substring(i + 1)); |
3070 |
fileName = f.getPath().toLowerCase(); |
2500 |
} |
3071 |
if (fileName.endsWith(extension)) { |
2501 |
} |
3072 |
accept = true; |
|
|
3073 |
} |
3074 |
} |
3075 |
} |
3076 |
return accept; |
3077 |
} |
3078 |
|
2502 |
|
3079 |
/** |
2503 |
localHistory.update(s); |
3080 |
* Returns the file description |
2504 |
application.addVisitedURI(s); |
3081 |
*/ |
2505 |
backAction.update(); |
3082 |
public String getDescription() { |
2506 |
forwardAction.update(); |
3083 |
return extension; |
2507 |
|
3084 |
} |
2508 |
transformHistory = new TransformHistory(); |
3085 |
} |
2509 |
previousTransformAction.update(); |
|
|
2510 |
nextTransformAction.update(); |
2511 |
|
2512 |
useStylesheetAction.update(); |
2513 |
} |
2514 |
|
2515 |
/** |
2516 |
* Called when the loading of a document was cancelled. |
2517 |
*/ |
2518 |
public void documentLoadingCancelled(SVGDocumentLoaderEvent e) { |
2519 |
String msg = resources.getString("Message.documentCancelled"); |
2520 |
if (debug) { |
2521 |
System.out.println(msg); |
2522 |
} |
2523 |
statusBar.setMainMessage(""); |
2524 |
statusBar.setMessage(msg); |
2525 |
stopAction.update(false); |
2526 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2527 |
} |
2528 |
|
2529 |
/** |
2530 |
* Called when the loading of a document has failed. |
2531 |
*/ |
2532 |
public void documentLoadingFailed(SVGDocumentLoaderEvent e) { |
2533 |
String msg = resources.getString("Message.documentFailed"); |
2534 |
if (debug) { |
2535 |
System.out.println(msg); |
2536 |
} |
2537 |
statusBar.setMainMessage(""); |
2538 |
statusBar.setMessage(msg); |
2539 |
stopAction.update(false); |
2540 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2541 |
} |
2542 |
|
2543 |
// GVTTreeBuilderListener ////////////////////////////////////////////// |
2544 |
|
2545 |
/** |
2546 |
* Called when a build started. The data of the event is initialized to the |
2547 |
* old document. |
2548 |
*/ |
2549 |
public void gvtBuildStarted(GVTTreeBuilderEvent e) { |
2550 |
String msg = resources.getString("Message.treeBuild"); |
2551 |
if (debug) { |
2552 |
System.out.println(msg); |
2553 |
time = System.currentTimeMillis(); |
2554 |
} |
2555 |
statusBar.setMainMessage(msg); |
2556 |
stopAction.update(true); |
2557 |
svgCanvas.setCursor(WAIT_CURSOR); |
2558 |
} |
2559 |
|
2560 |
/** |
2561 |
* Called when a build was completed. |
2562 |
*/ |
2563 |
public void gvtBuildCompleted(GVTTreeBuilderEvent e) { |
2564 |
if (debug) { |
2565 |
System.out.print(resources.getString("Message.treeBuildTime")); |
2566 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2567 |
} |
2568 |
if (findDialog != null) { |
2569 |
if (findDialog.isVisible()) { |
2570 |
findDialog.setGraphicsNode(svgCanvas.getGraphicsNode()); |
2571 |
} else { |
2572 |
findDialog.dispose(); |
2573 |
findDialog = null; |
2574 |
} |
2575 |
} |
2576 |
stopAction.update(false); |
2577 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2578 |
svgCanvas.setSelectionOverlayXORMode(application |
2579 |
.isSelectionOverlayXORMode()); |
2580 |
svgCanvas.requestFocus(); // request focus when load completes. |
2581 |
if (debugger != null) { |
2582 |
debugger.attach(); |
2583 |
} |
2584 |
} |
2585 |
|
2586 |
/** |
2587 |
* Called when a build was cancelled. |
2588 |
*/ |
2589 |
public void gvtBuildCancelled(GVTTreeBuilderEvent e) { |
2590 |
String msg = resources.getString("Message.treeCancelled"); |
2591 |
if (debug) { |
2592 |
System.out.println(msg); |
2593 |
} |
2594 |
statusBar.setMainMessage(""); |
2595 |
statusBar.setMessage(msg); |
2596 |
stopAction.update(false); |
2597 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2598 |
svgCanvas.setSelectionOverlayXORMode(application |
2599 |
.isSelectionOverlayXORMode()); |
2600 |
} |
2601 |
|
2602 |
/** |
2603 |
* Called when a build failed. |
2604 |
*/ |
2605 |
public void gvtBuildFailed(GVTTreeBuilderEvent e) { |
2606 |
String msg = resources.getString("Message.treeFailed"); |
2607 |
if (debug) { |
2608 |
System.out.println(msg); |
2609 |
} |
2610 |
statusBar.setMainMessage(""); |
2611 |
statusBar.setMessage(msg); |
2612 |
stopAction.update(false); |
2613 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2614 |
svgCanvas.setSelectionOverlayXORMode(application |
2615 |
.isSelectionOverlayXORMode()); |
2616 |
if (autoAdjust) { |
2617 |
pack(); |
2618 |
} |
2619 |
} |
2620 |
|
2621 |
// SVGLoadEventDispatcherListener ////////////////////////////////////// |
2622 |
|
2623 |
/** |
2624 |
* Called when a onload event dispatch started. |
2625 |
*/ |
2626 |
public void svgLoadEventDispatchStarted(SVGLoadEventDispatcherEvent e) { |
2627 |
String msg = resources.getString("Message.onload"); |
2628 |
if (debug) { |
2629 |
System.out.println(msg); |
2630 |
time = System.currentTimeMillis(); |
2631 |
} |
2632 |
stopAction.update(true); |
2633 |
statusBar.setMainMessage(msg); |
2634 |
} |
2635 |
|
2636 |
/** |
2637 |
* Called when a onload event dispatch was completed. |
2638 |
*/ |
2639 |
public void svgLoadEventDispatchCompleted(SVGLoadEventDispatcherEvent e) { |
2640 |
if (debug) { |
2641 |
System.out.print(resources.getString("Message.onloadTime")); |
2642 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2643 |
} |
2644 |
stopAction.update(false); |
2645 |
statusBar.setMainMessage(""); |
2646 |
statusBar.setMessage(resources.getString("Message.done")); |
2647 |
} |
2648 |
|
2649 |
/** |
2650 |
* Called when a onload event dispatch was cancelled. |
2651 |
*/ |
2652 |
public void svgLoadEventDispatchCancelled(SVGLoadEventDispatcherEvent e) { |
2653 |
String msg = resources.getString("Message.onloadCancelled"); |
2654 |
if (debug) { |
2655 |
System.out.println(msg); |
2656 |
} |
2657 |
stopAction.update(false); |
2658 |
statusBar.setMainMessage(""); |
2659 |
statusBar.setMessage(msg); |
2660 |
} |
2661 |
|
2662 |
/** |
2663 |
* Called when a onload event dispatch failed. |
2664 |
*/ |
2665 |
public void svgLoadEventDispatchFailed(SVGLoadEventDispatcherEvent e) { |
2666 |
String msg = resources.getString("Message.onloadFailed"); |
2667 |
if (debug) { |
2668 |
System.out.println(msg); |
2669 |
} |
2670 |
stopAction.update(false); |
2671 |
statusBar.setMainMessage(""); |
2672 |
statusBar.setMessage(msg); |
2673 |
} |
2674 |
|
2675 |
// GVTTreeRendererListener ///////////////////////////////////////////// |
2676 |
|
2677 |
/** |
2678 |
* Called when a rendering is in its preparing phase. |
2679 |
*/ |
2680 |
public void gvtRenderingPrepare(GVTTreeRendererEvent e) { |
2681 |
if (debug) { |
2682 |
String msg = resources.getString("Message.treeRenderingPrep"); |
2683 |
System.out.println(msg); |
2684 |
time = System.currentTimeMillis(); |
2685 |
} |
2686 |
stopAction.update(true); |
2687 |
svgCanvas.setCursor(WAIT_CURSOR); |
2688 |
statusBar.setMainMessage(resources.getString("Message.treeRendering")); |
2689 |
} |
2690 |
|
2691 |
/** |
2692 |
* Called when a rendering started. |
2693 |
*/ |
2694 |
public void gvtRenderingStarted(GVTTreeRendererEvent e) { |
2695 |
if (debug) { |
2696 |
String msg = resources.getString("Message.treeRenderingPrepTime"); |
2697 |
System.out.print(msg); |
2698 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2699 |
time = System.currentTimeMillis(); |
2700 |
msg = resources.getString("Message.treeRenderingStart"); |
2701 |
System.out.println(msg); |
2702 |
} |
2703 |
// Do nothing |
2704 |
} |
2705 |
|
2706 |
/** |
2707 |
* Called when a rendering was completed. |
2708 |
*/ |
2709 |
public void gvtRenderingCompleted(GVTTreeRendererEvent e) { |
2710 |
if (debug) { |
2711 |
String msg = resources.getString("Message.treeRenderingTime"); |
2712 |
System.out.print(msg); |
2713 |
System.out.println((System.currentTimeMillis() - time) + " ms"); |
2714 |
} |
2715 |
statusBar.setMainMessage(""); |
2716 |
statusBar.setMessage(resources.getString("Message.done")); |
2717 |
if (!svgCanvas.isDynamic() || managerStopped) { |
2718 |
stopAction.update(false); |
2719 |
} |
2720 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2721 |
|
2722 |
transformHistory.update(svgCanvas.getRenderingTransform()); |
2723 |
previousTransformAction.update(); |
2724 |
nextTransformAction.update(); |
2725 |
} |
2726 |
|
2727 |
/** |
2728 |
* Called when a rendering was cancelled. |
2729 |
*/ |
2730 |
public void gvtRenderingCancelled(GVTTreeRendererEvent e) { |
2731 |
String msg = resources.getString("Message.treeRenderingCancelled"); |
2732 |
if (debug) { |
2733 |
System.out.println(msg); |
2734 |
} |
2735 |
statusBar.setMainMessage(""); |
2736 |
statusBar.setMessage(msg); |
2737 |
if (!svgCanvas.isDynamic()) { |
2738 |
stopAction.update(false); |
2739 |
} |
2740 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2741 |
} |
2742 |
|
2743 |
/** |
2744 |
* Called when a rendering failed. |
2745 |
*/ |
2746 |
public void gvtRenderingFailed(GVTTreeRendererEvent e) { |
2747 |
String msg = resources.getString("Message.treeRenderingFailed"); |
2748 |
if (debug) { |
2749 |
System.out.println(msg); |
2750 |
} |
2751 |
statusBar.setMainMessage(""); |
2752 |
statusBar.setMessage(msg); |
2753 |
if (!svgCanvas.isDynamic()) { |
2754 |
stopAction.update(false); |
2755 |
} |
2756 |
svgCanvas.setCursor(DEFAULT_CURSOR); |
2757 |
} |
2758 |
|
2759 |
// LinkActivationListener ///////////////////////////////////////// |
2760 |
|
2761 |
/** |
2762 |
* Called when a link was activated. |
2763 |
*/ |
2764 |
public void linkActivated(LinkActivationEvent e) { |
2765 |
String s = e.getReferencedURI(); |
2766 |
if (svgDocument != null) { |
2767 |
ParsedURL docURL = new ParsedURL(svgDocument.getURL()); |
2768 |
ParsedURL url = new ParsedURL(docURL, s); |
2769 |
if (!url.sameFile(docURL)) { |
2770 |
return; |
2771 |
} |
2772 |
|
2773 |
if (s.indexOf('#') != -1) { |
2774 |
localHistory.update(s); |
2775 |
locationBar.setText(s); |
2776 |
if (debugger != null) { |
2777 |
debugger.detach(); |
2778 |
debugger.setDocumentURL(s); |
2779 |
} |
2780 |
application.addVisitedURI(s); |
2781 |
backAction.update(); |
2782 |
forwardAction.update(); |
2783 |
|
2784 |
transformHistory = new TransformHistory(); |
2785 |
previousTransformAction.update(); |
2786 |
nextTransformAction.update(); |
2787 |
} |
2788 |
} |
2789 |
} |
2790 |
|
2791 |
// UpdateManagerListener //////////////////////////////////////////////// |
2792 |
|
2793 |
/** |
2794 |
* Called when the manager was started. |
2795 |
*/ |
2796 |
public void managerStarted(UpdateManagerEvent e) { |
2797 |
if (debug) { |
2798 |
String msg = resources.getString("Message.updateManagerStarted"); |
2799 |
System.out.println(msg); |
2800 |
} |
2801 |
managerStopped = false; |
2802 |
playAction.update(false); |
2803 |
pauseAction.update(true); |
2804 |
stopAction.update(true); |
2805 |
} |
2806 |
|
2807 |
/** |
2808 |
* Called when the manager was suspended. |
2809 |
*/ |
2810 |
public void managerSuspended(UpdateManagerEvent e) { |
2811 |
if (debug) { |
2812 |
String msg = resources.getString("Message.updateManagerSuspended"); |
2813 |
System.out.println(msg); |
2814 |
} |
2815 |
playAction.update(true); |
2816 |
pauseAction.update(false); |
2817 |
} |
2818 |
|
2819 |
/** |
2820 |
* Called when the manager was resumed. |
2821 |
*/ |
2822 |
public void managerResumed(UpdateManagerEvent e) { |
2823 |
if (debug) { |
2824 |
String msg = resources.getString("Message.updateManagerResumed"); |
2825 |
System.out.println(msg); |
2826 |
} |
2827 |
playAction.update(false); |
2828 |
pauseAction.update(true); |
2829 |
} |
2830 |
|
2831 |
/** |
2832 |
* Called when the manager was stopped. |
2833 |
*/ |
2834 |
public void managerStopped(UpdateManagerEvent e) { |
2835 |
if (debug) { |
2836 |
String msg = resources.getString("Message.updateManagerStopped"); |
2837 |
System.out.println(msg); |
2838 |
} |
2839 |
managerStopped = true; |
2840 |
playAction.update(false); |
2841 |
pauseAction.update(false); |
2842 |
stopAction.update(false); |
2843 |
} |
2844 |
|
2845 |
/** |
2846 |
* Called when an update started. |
2847 |
*/ |
2848 |
public void updateStarted(final UpdateManagerEvent e) { |
2849 |
} |
2850 |
|
2851 |
/** |
2852 |
* Called when an update was completed. |
2853 |
*/ |
2854 |
public void updateCompleted(final UpdateManagerEvent e) { |
2855 |
} |
2856 |
|
2857 |
/** |
2858 |
* Called when an update failed. |
2859 |
*/ |
2860 |
public void updateFailed(UpdateManagerEvent e) { |
2861 |
} |
2862 |
|
2863 |
/** |
2864 |
* This class implements a SVG user agent. |
2865 |
*/ |
2866 |
protected class UserAgent implements SVGUserAgent { |
2867 |
|
2868 |
/** |
2869 |
* Creates a new SVGUserAgent. |
2870 |
*/ |
2871 |
protected UserAgent() { |
2872 |
} |
2873 |
|
2874 |
/** |
2875 |
* Displays an error message. |
2876 |
*/ |
2877 |
public void displayError(String message) { |
2878 |
if (debug) { |
2879 |
System.err.println(message); |
2880 |
} |
2881 |
JOptionPane pane = new JOptionPane(message, |
2882 |
JOptionPane.ERROR_MESSAGE); |
2883 |
JDialog dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR"); |
2884 |
dialog.setModal(false); |
2885 |
dialog.setVisible(true); |
2886 |
} |
2887 |
|
2888 |
/** |
2889 |
* Displays an error resulting from the specified Exception. |
2890 |
*/ |
2891 |
public void displayError(Exception ex) { |
2892 |
if (debug) { |
2893 |
ex.printStackTrace(); |
2894 |
} |
2895 |
// JErrorPane pane = |
2896 |
// new JErrorPane(ex, JOptionPane.ERROR_MESSAGE); |
2897 |
ErrorConsole console = ErrorConsole.getInstance(); |
2898 |
if (ex instanceof LiveAttributeException) { |
2899 |
LiveAttributeException lex = (LiveAttributeException) ex; |
2900 |
ParsedURL purl = new ParsedURL(svgDocument.getURL()); |
2901 |
InputStream is = null; |
2902 |
try { |
2903 |
is = purl.openStream(getInputHandler(purl) |
2904 |
.getHandledMimeTypes()); |
2905 |
} catch (IOException e) { |
2906 |
e.printStackTrace(); |
2907 |
// do nothing, error console will report stream not |
2908 |
// available |
2909 |
} |
2910 |
AttributeErrorInfo info = new AttributeErrorInfo(lex, svgDocument |
2911 |
.getDocumentURI(), ErrorConsole.ERROR, is, lex |
2912 |
.getElement(), docDescriptor, |
2913 |
(ViewSourceAction) listeners.get(VIEW_SOURCE_ACTION), |
2914 |
(DOMViewerAction) listeners.get(DOM_VIEWER_ACTION)); |
2915 |
console.add(info); |
2916 |
} else { |
2917 |
String uri; |
2918 |
if (svgDocument == null) { |
2919 |
uri = currentPath.getAbsolutePath(); |
2920 |
} else { |
2921 |
uri = svgDocument.getDocumentURI(); |
2922 |
} |
2923 |
ErrorInfo info = new ErrorInfo(ex, |
2924 |
uri, ErrorConsole.ERROR); |
2925 |
console.add(info); |
2926 |
} |
2927 |
ErrorConsole.showDialog(JSVGViewerFrame.this); |
2928 |
} |
2929 |
|
2930 |
/** |
2931 |
* Displays a message in the User Agent interface. The given message is |
2932 |
* typically displayed in a status bar. |
2933 |
*/ |
2934 |
public void displayMessage(String message) { |
2935 |
statusBar.setMessage(message); |
2936 |
} |
2937 |
|
2938 |
/** |
2939 |
* Shows an alert dialog box. |
2940 |
*/ |
2941 |
public void showAlert(String message) { |
2942 |
svgCanvas.showAlert(message); |
2943 |
} |
2944 |
|
2945 |
/** |
2946 |
* Shows a prompt dialog box. |
2947 |
*/ |
2948 |
public String showPrompt(String message) { |
2949 |
return svgCanvas.showPrompt(message); |
2950 |
} |
2951 |
|
2952 |
/** |
2953 |
* Shows a prompt dialog box. |
2954 |
*/ |
2955 |
public String showPrompt(String message, String defaultValue) { |
2956 |
return svgCanvas.showPrompt(message, defaultValue); |
2957 |
} |
2958 |
|
2959 |
/** |
2960 |
* Shows a confirm dialog box. |
2961 |
*/ |
2962 |
public boolean showConfirm(String message) { |
2963 |
return svgCanvas.showConfirm(message); |
2964 |
} |
2965 |
|
2966 |
/** |
2967 |
* Returns the size of a px CSS unit in millimeters. |
2968 |
*/ |
2969 |
public float getPixelUnitToMillimeter() { |
2970 |
return 0.26458333333333333333333333333333f; // 96dpi |
2971 |
} |
2972 |
|
2973 |
/** |
2974 |
* Returns the size of a px CSS unit in millimeters. This will be |
2975 |
* removed after next release. |
2976 |
* |
2977 |
* @see #getPixelUnitToMillimeter() |
2978 |
*/ |
2979 |
public float getPixelToMM() { |
2980 |
return getPixelUnitToMillimeter(); |
2981 |
|
2982 |
} |
2983 |
|
2984 |
/** |
2985 |
* Returns the default font family. |
2986 |
*/ |
2987 |
public String getDefaultFontFamily() { |
2988 |
return application.getDefaultFontFamily(); |
2989 |
} |
2990 |
|
2991 |
/** |
2992 |
* Returns the medium font size. |
2993 |
*/ |
2994 |
public float getMediumFontSize() { |
2995 |
// 9pt (72pt == 1in) |
2996 |
return 9f * 25.4f / (72f * getPixelUnitToMillimeter()); |
2997 |
} |
2998 |
|
2999 |
/** |
3000 |
* Returns a lighter font-weight. |
3001 |
*/ |
3002 |
public float getLighterFontWeight(float f) { |
3003 |
// Round f to nearest 100... |
3004 |
int weight = ((int) ((f + 50) / 100)) * 100; |
3005 |
switch (weight) { |
3006 |
case 100: |
3007 |
return 100; |
3008 |
case 200: |
3009 |
return 100; |
3010 |
case 300: |
3011 |
return 200; |
3012 |
case 400: |
3013 |
return 300; |
3014 |
case 500: |
3015 |
return 400; |
3016 |
case 600: |
3017 |
return 400; |
3018 |
case 700: |
3019 |
return 400; |
3020 |
case 800: |
3021 |
return 400; |
3022 |
case 900: |
3023 |
return 400; |
3024 |
default: |
3025 |
throw new IllegalArgumentException("Bad Font Weight: " + f); |
3026 |
} |
3027 |
} |
3028 |
|
3029 |
/** |
3030 |
* Returns a bolder font-weight. |
3031 |
*/ |
3032 |
public float getBolderFontWeight(float f) { |
3033 |
// Round f to nearest 100... |
3034 |
int weight = ((int) ((f + 50) / 100)) * 100; |
3035 |
switch (weight) { |
3036 |
case 100: |
3037 |
return 600; |
3038 |
case 200: |
3039 |
return 600; |
3040 |
case 300: |
3041 |
return 600; |
3042 |
case 400: |
3043 |
return 600; |
3044 |
case 500: |
3045 |
return 600; |
3046 |
case 600: |
3047 |
return 700; |
3048 |
case 700: |
3049 |
return 800; |
3050 |
case 800: |
3051 |
return 900; |
3052 |
case 900: |
3053 |
return 900; |
3054 |
default: |
3055 |
throw new IllegalArgumentException("Bad Font Weight: " + f); |
3056 |
} |
3057 |
} |
3058 |
|
3059 |
/** |
3060 |
* Returns the language settings. |
3061 |
*/ |
3062 |
public String getLanguages() { |
3063 |
return application.getLanguages(); |
3064 |
} |
3065 |
|
3066 |
/** |
3067 |
* Returns the user stylesheet uri. |
3068 |
* |
3069 |
* @return null if no user style sheet was specified. |
3070 |
*/ |
3071 |
public String getUserStyleSheetURI() { |
3072 |
return application.getUserStyleSheetURI(); |
3073 |
} |
3074 |
|
3075 |
/** |
3076 |
* Returns the class name of the XML parser. |
3077 |
*/ |
3078 |
public String getXMLParserClassName() { |
3079 |
return application.getXMLParserClassName(); |
3080 |
} |
3081 |
|
3082 |
/** |
3083 |
* Returns true if the XML parser must be in validation mode, false |
3084 |
* otherwise. |
3085 |
*/ |
3086 |
public boolean isXMLParserValidating() { |
3087 |
return application.isXMLParserValidating(); |
3088 |
} |
3089 |
|
3090 |
/** |
3091 |
* Returns this user agent's CSS media. |
3092 |
*/ |
3093 |
public String getMedia() { |
3094 |
return application.getMedia(); |
3095 |
} |
3096 |
|
3097 |
/** |
3098 |
* Returns this user agent's alternate style-sheet title. |
3099 |
*/ |
3100 |
public String getAlternateStyleSheet() { |
3101 |
return alternateStyleSheet; |
3102 |
} |
3103 |
|
3104 |
/** |
3105 |
* Opens a link. |
3106 |
* |
3107 |
* @param uri |
3108 |
* The document URI. |
3109 |
* @param newc |
3110 |
* Whether the link should be activated in a new component. |
3111 |
*/ |
3112 |
public void openLink(String uri, boolean newc) { |
3113 |
if (newc) { |
3114 |
application.openLink(uri); |
3115 |
} else { |
3116 |
showSVGDocument(uri); |
3117 |
} |
3118 |
} |
3119 |
|
3120 |
/** |
3121 |
* Tells whether the given extension is supported by this user agent. |
3122 |
*/ |
3123 |
public boolean supportExtension(String s) { |
3124 |
return false; |
3125 |
} |
3126 |
|
3127 |
public void handleElement(Element elt, Object data) { |
3128 |
} |
3129 |
|
3130 |
/** |
3131 |
* Returns the security settings for the given script type, script url |
3132 |
* and document url |
3133 |
* |
3134 |
* @param scriptType |
3135 |
* type of script, as found in the type attribute of the |
3136 |
* <script> element. |
3137 |
* @param scriptURL |
3138 |
* url for the script, as defined in the script's xlink:href |
3139 |
* attribute. If that attribute was empty, then this |
3140 |
* parameter should be null |
3141 |
* @param docURL |
3142 |
* url for the document into which the script was found. |
3143 |
*/ |
3144 |
public ScriptSecurity getScriptSecurity(String scriptType, |
3145 |
ParsedURL scriptURL, ParsedURL docURL) { |
3146 |
if (!application.canLoadScriptType(scriptType)) { |
3147 |
return new NoLoadScriptSecurity(scriptType); |
3148 |
} else { |
3149 |
switch (application.getAllowedScriptOrigin()) { |
3150 |
case ResourceOrigin.ANY: |
3151 |
return new RelaxedScriptSecurity(scriptType, scriptURL, |
3152 |
docURL); |
3153 |
case ResourceOrigin.DOCUMENT: |
3154 |
return new DefaultScriptSecurity(scriptType, scriptURL, |
3155 |
docURL); |
3156 |
case ResourceOrigin.EMBEDED: |
3157 |
return new EmbededScriptSecurity(scriptType, scriptURL, |
3158 |
docURL); |
3159 |
default: |
3160 |
return new NoLoadScriptSecurity(scriptType); |
3161 |
} |
3162 |
} |
3163 |
} |
3164 |
|
3165 |
/** |
3166 |
* This method throws a SecurityException if the script of given type, |
3167 |
* found at url and referenced from docURL should not be loaded. |
3168 |
* |
3169 |
* This is a convenience method to call checkLoadScript on the |
3170 |
* ScriptSecurity strategy returned by getScriptSecurity. |
3171 |
* |
3172 |
* @param scriptType |
3173 |
* type of script, as found in the type attribute of the |
3174 |
* <script> element. |
3175 |
* @param scriptURL |
3176 |
* url for the script, as defined in the script's xlink:href |
3177 |
* attribute. If that attribute was empty, then this |
3178 |
* parameter should be null |
3179 |
* @param docURL |
3180 |
* url for the document into which the script was found. |
3181 |
*/ |
3182 |
public void checkLoadScript(String scriptType, ParsedURL scriptURL, |
3183 |
ParsedURL docURL) throws SecurityException { |
3184 |
ScriptSecurity s = getScriptSecurity(scriptType, scriptURL, docURL); |
3185 |
|
3186 |
if (s != null) { |
3187 |
s.checkLoadScript(); |
3188 |
} |
3189 |
} |
3190 |
|
3191 |
/** |
3192 |
* Returns the security settings for the given resource url and document |
3193 |
* url |
3194 |
* |
3195 |
* @param resourceURL |
3196 |
* url for the resource, as defined in the resource's |
3197 |
* xlink:href attribute. If that attribute was empty, then |
3198 |
* this parameter should be null |
3199 |
* @param docURL |
3200 |
* url for the document into which the resource was found. |
3201 |
*/ |
3202 |
public ExternalResourceSecurity getExternalResourceSecurity( |
3203 |
ParsedURL resourceURL, ParsedURL docURL) { |
3204 |
switch (application.getAllowedExternalResourceOrigin()) { |
3205 |
case ResourceOrigin.ANY: |
3206 |
return new RelaxedExternalResourceSecurity(resourceURL, docURL); |
3207 |
case ResourceOrigin.DOCUMENT: |
3208 |
return new DefaultExternalResourceSecurity(resourceURL, docURL); |
3209 |
case ResourceOrigin.EMBEDED: |
3210 |
return new EmbededExternalResourceSecurity(resourceURL); |
3211 |
default: |
3212 |
return new NoLoadExternalResourceSecurity(); |
3213 |
} |
3214 |
} |
3215 |
|
3216 |
/** |
3217 |
* This method throws a SecurityException if the resource found at url |
3218 |
* and referenced from docURL should not be loaded. |
3219 |
* |
3220 |
* This is a convenience method to call checkLoadExternalResource on the |
3221 |
* ExternalResourceSecurity strategy returned by |
3222 |
* getExternalResourceSecurity. |
3223 |
* |
3224 |
* @param resourceURL |
3225 |
* url for the script, as defined in the resource's |
3226 |
* xlink:href attribute. If that attribute was empty, then |
3227 |
* this parameter should be null |
3228 |
* @param docURL |
3229 |
* url for the document into which the resource was found. |
3230 |
*/ |
3231 |
public void checkLoadExternalResource(ParsedURL resourceURL, |
3232 |
ParsedURL docURL) throws SecurityException { |
3233 |
ExternalResourceSecurity s = getExternalResourceSecurity( |
3234 |
resourceURL, docURL); |
3235 |
|
3236 |
if (s != null) { |
3237 |
s.checkLoadExternalResource(); |
3238 |
} |
3239 |
} |
3240 |
} |
3241 |
|
3242 |
/** |
3243 |
* A FileFilter used when exporting the SVG document as an image. |
3244 |
*/ |
3245 |
protected static class ImageFileFilter extends FileFilter { |
3246 |
|
3247 |
/** The extension of the image filename. */ |
3248 |
protected String extension; |
3249 |
|
3250 |
public ImageFileFilter(String extension) { |
3251 |
this.extension = extension; |
3252 |
} |
3253 |
|
3254 |
/** |
3255 |
* Returns true if <tt>f</tt> is a file with the correct extension, |
3256 |
* false otherwise. |
3257 |
*/ |
3258 |
public boolean accept(File f) { |
3259 |
boolean accept = false; |
3260 |
String fileName = null; |
3261 |
if (f != null) { |
3262 |
if (f.isDirectory()) { |
3263 |
accept = true; |
3264 |
} else { |
3265 |
fileName = f.getPath().toLowerCase(); |
3266 |
if (fileName.endsWith(extension)) { |
3267 |
accept = true; |
3268 |
} |
3269 |
} |
3270 |
} |
3271 |
return accept; |
3272 |
} |
3273 |
|
3274 |
/** |
3275 |
* Returns the file description |
3276 |
*/ |
3277 |
public String getDescription() { |
3278 |
return extension; |
3279 |
} |
3280 |
} |
3086 |
} |
3281 |
} |