KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > svgbrowser > JSVGViewerFrame


1 /*
2
3    Copyright 2001-2004 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.apps.svgbrowser;
19
20 import java.awt.BorderLayout JavaDoc;
21 import java.awt.Color JavaDoc;
22 import java.awt.Cursor JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.Event JavaDoc;
25 import java.awt.EventQueue JavaDoc;
26 import java.awt.Font JavaDoc;
27 import java.awt.Graphics2D JavaDoc;
28 import java.awt.Rectangle JavaDoc;
29 import java.awt.Toolkit JavaDoc;
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.awt.event.ComponentAdapter JavaDoc;
32 import java.awt.event.ComponentEvent JavaDoc;
33 import java.awt.event.KeyEvent JavaDoc;
34 import java.awt.event.MouseAdapter JavaDoc;
35 import java.awt.event.MouseEvent JavaDoc;
36 import java.awt.event.MouseMotionAdapter JavaDoc;
37 import java.awt.event.WindowAdapter JavaDoc;
38 import java.awt.event.WindowEvent JavaDoc;
39 import java.awt.geom.AffineTransform JavaDoc;
40 import java.awt.geom.NoninvertibleTransformException JavaDoc;
41 import java.awt.geom.Point2D JavaDoc;
42 import java.awt.image.BufferedImage JavaDoc;
43 import java.awt.print.PrinterException JavaDoc;
44 import java.io.BufferedOutputStream JavaDoc;
45 import java.io.File JavaDoc;
46 import java.io.FileOutputStream JavaDoc;
47 import java.io.IOException JavaDoc;
48 import java.io.InputStream JavaDoc;
49 import java.io.OutputStream JavaDoc;
50 import java.io.OutputStreamWriter JavaDoc;
51 import java.io.Reader JavaDoc;
52 import java.io.Writer JavaDoc;
53 import java.lang.reflect.Constructor JavaDoc;
54 import java.lang.reflect.Method JavaDoc;
55 import java.net.MalformedURLException JavaDoc;
56 import java.util.HashMap JavaDoc;
57 import java.util.Iterator JavaDoc;
58 import java.util.LinkedList JavaDoc;
59 import java.util.List JavaDoc;
60 import java.util.Locale JavaDoc;
61 import java.util.Map JavaDoc;
62 import java.util.MissingResourceException JavaDoc;
63 import java.util.ResourceBundle JavaDoc;
64 import java.util.Vector JavaDoc;
65
66 import javax.swing.AbstractAction JavaDoc;
67 import javax.swing.Action JavaDoc;
68 import javax.swing.BorderFactory JavaDoc;
69 import javax.swing.ButtonGroup JavaDoc;
70 import javax.swing.JCheckBox JavaDoc;
71 import javax.swing.JComponent JavaDoc;
72 import javax.swing.JDialog JavaDoc;
73 import javax.swing.JFileChooser JavaDoc;
74 import javax.swing.JFrame JavaDoc;
75 import javax.swing.JMenu JavaDoc;
76 import javax.swing.JMenuBar JavaDoc;
77 import javax.swing.JOptionPane JavaDoc;
78 import javax.swing.JPanel JavaDoc;
79 import javax.swing.JRadioButtonMenuItem JavaDoc;
80 import javax.swing.JScrollPane JavaDoc;
81 import javax.swing.JTextArea JavaDoc;
82 import javax.swing.JToolBar JavaDoc;
83 import javax.swing.JWindow JavaDoc;
84 import javax.swing.KeyStroke JavaDoc;
85 import javax.swing.filechooser.FileFilter JavaDoc;
86 import javax.swing.text.Document JavaDoc;
87 import javax.swing.text.PlainDocument JavaDoc;
88
89 import org.apache.batik.bridge.DefaultExternalResourceSecurity;
90 import org.apache.batik.bridge.DefaultScriptSecurity;
91 import org.apache.batik.bridge.EmbededExternalResourceSecurity;
92 import org.apache.batik.bridge.EmbededScriptSecurity;
93 import org.apache.batik.bridge.ExternalResourceSecurity;
94 import org.apache.batik.bridge.NoLoadExternalResourceSecurity;
95 import org.apache.batik.bridge.NoLoadScriptSecurity;
96 import org.apache.batik.bridge.RelaxedExternalResourceSecurity;
97 import org.apache.batik.bridge.RelaxedScriptSecurity;
98 import org.apache.batik.bridge.ScriptSecurity;
99 import org.apache.batik.bridge.UpdateManager;
100 import org.apache.batik.bridge.UpdateManagerEvent;
101 import org.apache.batik.bridge.UpdateManagerListener;
102 import org.apache.batik.dom.StyleSheetProcessingInstruction;
103 import org.apache.batik.dom.svg.SVGOMDocument;
104 import org.apache.batik.dom.util.HashTable;
105 import org.apache.batik.dom.util.DOMUtilities;
106 import org.apache.batik.ext.swing.JAffineTransformChooser;
107 import org.apache.batik.swing.JSVGCanvas;
108 import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
109 import org.apache.batik.swing.gvt.GVTTreeRendererListener;
110 import org.apache.batik.swing.svg.GVTTreeBuilderEvent;
111 import org.apache.batik.swing.svg.GVTTreeBuilderListener;
112 import org.apache.batik.swing.svg.LinkActivationEvent;
113 import org.apache.batik.swing.svg.LinkActivationListener;
114 import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
115 import org.apache.batik.swing.svg.SVGDocumentLoaderListener;
116 import org.apache.batik.swing.svg.SVGFileFilter;
117 import org.apache.batik.swing.svg.SVGLoadEventDispatcherEvent;
118 import org.apache.batik.swing.svg.SVGLoadEventDispatcherListener;
119 import org.apache.batik.swing.svg.SVGUserAgent;
120 import org.apache.batik.transcoder.TranscoderInput;
121 import org.apache.batik.transcoder.TranscoderOutput;
122 import org.apache.batik.transcoder.image.ImageTranscoder;
123 import org.apache.batik.transcoder.image.JPEGTranscoder;
124 import org.apache.batik.transcoder.image.PNGTranscoder;
125 import org.apache.batik.transcoder.image.TIFFTranscoder;
126 import org.apache.batik.transcoder.print.PrintTranscoder;
127 import org.apache.batik.transcoder.svg2svg.SVGTranscoder;
128 import org.apache.batik.util.ParsedURL;
129 import org.apache.batik.util.Service;
130 import org.apache.batik.util.SVGConstants;
131 import org.apache.batik.util.XMLConstants;
132 import org.apache.batik.util.gui.DOMViewer;
133 import org.apache.batik.util.gui.JErrorPane;
134 import org.apache.batik.util.gui.LocationBar;
135 import org.apache.batik.util.gui.MemoryMonitor;
136 import org.apache.batik.util.gui.URIChooser;
137 import org.apache.batik.util.gui.resource.ActionMap;
138 import org.apache.batik.util.gui.resource.JComponentModifier;
139 import org.apache.batik.util.gui.resource.MenuFactory;
140 import org.apache.batik.util.gui.resource.MissingListenerException;
141 import org.apache.batik.util.gui.resource.ResourceManager;
142 import org.apache.batik.util.gui.resource.ToolBarFactory;
143 import org.apache.batik.xml.XMLUtilities;
144 import org.mozilla.javascript.Context;
145 import org.mozilla.javascript.ContextListener;
146 import org.w3c.dom.Element JavaDoc;
147 import org.w3c.dom.Node JavaDoc;
148 import org.w3c.dom.css.ViewCSS;
149 import org.w3c.dom.svg.SVGDocument;
150
151 /**
152  * This class represents a SVG viewer swing frame.
153  *
154  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
155  * @version $Id: JSVGViewerFrame.java,v 1.109 2005/03/29 10:48:01 deweese Exp $
156  */

157 public class JSVGViewerFrame
158     extends JFrame JavaDoc
159     implements ActionMap,
160                SVGDocumentLoaderListener,
161                GVTTreeBuilderListener,
162                SVGLoadEventDispatcherListener,
163                GVTTreeRendererListener,
164                LinkActivationListener,
165                UpdateManagerListener {
166
167     static private String JavaDoc EOL;
168     static {
169         String JavaDoc temp;
170         try { temp = System.getProperty ("line.separator", "\n"); }
171         catch (SecurityException JavaDoc e) { temp = "\n"; }
172         EOL = temp;
173     }
174
175     /**
176      * Kind of ugly, but we need to know if we are running before
177      * or after 1.4...
178      */

179     protected static boolean priorJDK1_4 = true;
180
181     /**
182      * If the following class can be found (it appeared in JDK 1.4),
183      * then we know we are post JDK 1.4.
184      */

185     protected static final String JavaDoc JDK_1_4_PRESENCE_TEST_CLASS
186         = "java.util.logging.LoggingPermission";
187
188     static {
189         Class JavaDoc cl = null;
190         try {
191             cl = Class.forName(JDK_1_4_PRESENCE_TEST_CLASS);
192         } catch (ClassNotFoundException JavaDoc e){
193         }
194
195         if (cl != null) {
196             priorJDK1_4 = false;
197         }
198     }
199
200     static JFrame JavaDoc debuggerFrame = null;
201     static Class JavaDoc debuggerClass = null;
202     static Method JavaDoc clearAllBreakpoints = null;
203     static Method JavaDoc scriptGo = null;
204     static Method JavaDoc setExitAction = null;
205     static {
206         try {
207             debuggerClass = JSVGViewerFrame.class.getClassLoader().loadClass
208                 ("org.mozilla.javascript.tools.debugger.Main");
209             clearAllBreakpoints = debuggerClass.getMethod
210                 ("clearAllBreakpoints", null);
211             scriptGo = debuggerClass.getMethod
212                 ("go", null);
213             setExitAction = debuggerClass.getMethod
214                 ("setExitAction", new Class JavaDoc[] {Runnable JavaDoc.class});
215         } catch (ThreadDeath JavaDoc td) {
216             debuggerClass = null;
217             clearAllBreakpoints = null;
218             scriptGo = null;
219             setExitAction = null;
220             throw td;
221         } catch (Throwable JavaDoc t) {
222             debuggerClass = null;
223             clearAllBreakpoints = null;
224             scriptGo = null;
225             setExitAction = null;
226         }
227     }
228
229     public static void showDebugger() {
230         if (debuggerClass == null) return;
231         if (debuggerFrame == null) {
232             try {
233                 Constructor JavaDoc c = debuggerClass.getConstructor
234                     (new Class JavaDoc [] { String JavaDoc.class });
235                 debuggerFrame = (JFrame JavaDoc)c.newInstance
236                     (new Object JavaDoc[] { "Rhino JavaScript Debugger" });
237                 // Customize the menubar a bit, disable menu
238
// items that can't be used and change 'Exit' to 'Close'.
239
JMenuBar JavaDoc menuBar = debuggerFrame.getJMenuBar();
240                 JMenu JavaDoc menu = menuBar.getMenu(0);
241                 menu.getItem(0).setEnabled(false); // Open...
242
menu.getItem(1).setEnabled(false); // Run...
243
menu.getItem(3).setText
244                     (Resources.getString("Close.text")); // Exit -> "Close"
245
menu.getItem(3).setAccelerator
246                     (KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
247
248                 debuggerFrame.setSize(600, 460);
249                 debuggerFrame.pack();
250                 WindowAdapter JavaDoc wa = new WindowAdapter JavaDoc() {
251                         public void windowClosing(WindowEvent JavaDoc e) {
252                             hideDebugger();
253                         }};
254                 setExitAction.invoke(debuggerFrame,
255                                      new Object JavaDoc [] { new Runnable JavaDoc() {
256                                              public void run() {
257                                                  hideDebugger();
258                                              }}});
259                 debuggerFrame.addWindowListener(wa);
260             } catch (Exception JavaDoc ex) {
261                 ex.printStackTrace();
262                 return;
263             }
264         }
265         if (debuggerFrame != null) {
266             debuggerFrame.setVisible(true);
267             Context.addContextListener((ContextListener)debuggerFrame);
268         }
269     }
270
271     public static void hideDebugger() {
272         if (debuggerFrame == null)
273             return;
274         Context.removeContextListener((ContextListener)debuggerFrame);
275         debuggerFrame.setVisible(false);
276         try {
277             clearAllBreakpoints.invoke(debuggerFrame, null);
278             scriptGo.invoke(debuggerFrame, null);
279         } catch (Exception JavaDoc ex) {
280             ex.printStackTrace();
281         }
282     }
283
284     /**
285      * The gui resources file name
286      */

287     public final static String JavaDoc RESOURCES =
288         "org.apache.batik.apps.svgbrowser.resources.GUI";
289
290     // The actions names.
291
public final static String JavaDoc ABOUT_ACTION = "AboutAction";
292     public final static String JavaDoc OPEN_ACTION = "OpenAction";
293     public final static String JavaDoc OPEN_LOCATION_ACTION = "OpenLocationAction";
294     public final static String JavaDoc NEW_WINDOW_ACTION = "NewWindowAction";
295     public final static String JavaDoc RELOAD_ACTION = "ReloadAction";
296     public final static String JavaDoc SAVE_AS_ACTION = "SaveAsAction";
297     public final static String JavaDoc BACK_ACTION = "BackAction";
298     public final static String JavaDoc FORWARD_ACTION = "ForwardAction";
299     public final static String JavaDoc FULL_SCREEN_ACTION = "FullScreenAction";
300     public final static String JavaDoc PRINT_ACTION = "PrintAction";
301     public final static String JavaDoc EXPORT_AS_JPG_ACTION = "ExportAsJPGAction";
302     public final static String JavaDoc EXPORT_AS_PNG_ACTION = "ExportAsPNGAction";
303     public final static String JavaDoc EXPORT_AS_TIFF_ACTION = "ExportAsTIFFAction";
304     public final static String JavaDoc PREFERENCES_ACTION = "PreferencesAction";
305     public final static String JavaDoc CLOSE_ACTION = "CloseAction";
306     public final static String JavaDoc VIEW_SOURCE_ACTION = "ViewSourceAction";
307     public final static String JavaDoc EXIT_ACTION = "ExitAction";
308     public final static String JavaDoc RESET_TRANSFORM_ACTION = "ResetTransformAction";
309     public final static String JavaDoc ZOOM_IN_ACTION = "ZoomInAction";
310     public final static String JavaDoc ZOOM_OUT_ACTION = "ZoomOutAction";
311     public final static String JavaDoc PREVIOUS_TRANSFORM_ACTION = "PreviousTransformAction";
312     public final static String JavaDoc NEXT_TRANSFORM_ACTION = "NextTransformAction";
313     public final static String JavaDoc USE_STYLESHEET_ACTION = "UseStylesheetAction";
314     public final static String JavaDoc PLAY_ACTION = "PlayAction";
315     public final static String JavaDoc PAUSE_ACTION = "PauseAction";
316     public final static String JavaDoc STOP_ACTION = "StopAction";
317     public final static String JavaDoc MONITOR_ACTION = "MonitorAction";
318     public final static String JavaDoc DOM_VIEWER_ACTION = "DOMViewerAction";
319     public final static String JavaDoc SET_TRANSFORM_ACTION = "SetTransformAction";
320     public final static String JavaDoc FIND_DIALOG_ACTION = "FindDialogAction";
321     public final static String JavaDoc THUMBNAIL_DIALOG_ACTION = "ThumbnailDialogAction";
322     public final static String JavaDoc FLUSH_ACTION = "FlushAction";
323     public final static String JavaDoc TOGGLE_DEBUGGER_ACTION = "ToggleDebuggerAction";
324
325     /**
326      * The cursor indicating that an operation is pending.
327      */

328     public final static Cursor JavaDoc WAIT_CURSOR =
329         new Cursor JavaDoc(Cursor.WAIT_CURSOR);
330
331     /**
332      * The default cursor.
333      */

334     public final static Cursor JavaDoc DEFAULT_CURSOR =
335         new Cursor JavaDoc(Cursor.DEFAULT_CURSOR);
336
337     /**
338      * Name for the os-name property
339      */

340     public final static String JavaDoc PROPERTY_OS_NAME
341         = Resources.getString("JSVGViewerFrame.property.os.name");
342
343     /**
344      * Name for the os.name default
345      */

346     public final static String JavaDoc PROPERTY_OS_NAME_DEFAULT
347         = Resources.getString("JSVGViewerFrame.property.os.name.default");
348
349     /**
350      * Name for the os.name property prefix we are looking
351      * for in OpenAction to work around JFileChooser bug
352      */

353     public final static String JavaDoc PROPERTY_OS_WINDOWS_PREFIX
354         = Resources.getString("JSVGViewerFrame.property.os.windows.prefix");
355
356     /**
357      * The input handlers
358      */

359     protected static Vector JavaDoc handlers;
360
361     /**
362      * The default input handler
363      */

364     protected static SquiggleInputHandler defaultHandler = new SVGInputHandler();
365
366     /**
367      * The resource bundle
368      */

369     protected static ResourceBundle JavaDoc bundle;
370
371     /**
372      * The resource manager
373      */

374     protected static ResourceManager resources;
375     static {
376         bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault());
377         resources = new ResourceManager(bundle);
378     }
379
380     /**
381      * The current application.
382      */

383     protected Application application;
384
385     /**
386      * The JSVGCanvas.
387      */

388     protected JSVGCanvas svgCanvas;
389
390     /**
391      * The panel where the svgCanvas is displayed
392      */

393     protected JPanel JavaDoc svgCanvasPanel;
394
395     /**
396      * A window used for full screen display
397      */

398     protected JWindow JavaDoc window;
399
400     /**
401      * The memory monitor frame.
402      */

403     protected static JFrame JavaDoc memoryMonitorFrame;
404
405     /**
406      * The current path.
407      */

408     protected File JavaDoc currentPath = new File JavaDoc("");
409
410     /**
411      * The current export path.
412      */

413     protected File JavaDoc currentSavePath = new File JavaDoc("");
414
415     /**
416      * The back action
417      */

418     protected BackAction backAction = new BackAction();
419
420     /**
421      * The forward action
422      */

423     protected ForwardAction forwardAction = new ForwardAction();
424
425     /**
426      * The play action
427      */

428     protected PlayAction playAction = new PlayAction();
429
430     /**
431      * The pause action
432      */

433     protected PauseAction pauseAction = new PauseAction();
434
435     /**
436      * The stop action
437      */

438     protected StopAction stopAction = new StopAction();
439
440     /**
441      * The previous transform action
442      */

443     protected PreviousTransformAction previousTransformAction =
444         new PreviousTransformAction();
445
446     /**
447      * The next transform action
448      */

449     protected NextTransformAction nextTransformAction =
450         new NextTransformAction();
451
452     /**
453      * The use (author) stylesheet action
454      */

455     protected UseStylesheetAction useStylesheetAction =
456         new UseStylesheetAction();
457
458     /**
459      * The debug flag.
460      */

461     protected boolean debug;
462
463     /**
464      * The auto adjust flag.
465      */

466     protected boolean autoAdjust = true;
467
468     /**
469      * Whether the update manager was stopped.
470      */

471     protected boolean managerStopped;
472
473     /**
474      * The SVG user agent.
475      */

476     protected SVGUserAgent userAgent = new UserAgent();
477
478     /**
479      * The current document.
480      */

481     protected SVGDocument svgDocument;
482
483     /**
484      * The URI chooser.
485      */

486     protected URIChooser uriChooser;
487
488     /**
489      * The DOM viewer.
490      */

491     protected DOMViewer domViewer;
492
493     /**
494      * The Find dialog.
495      */

496     protected FindDialog findDialog;
497
498     /**
499      * The Find dialog.
500      */

501     protected ThumbnailDialog thumbnailDialog;
502
503     /**
504      * The transform dialog
505      */

506     protected JAffineTransformChooser.Dialog transformDialog;
507
508     /**
509      * The location bar.
510      */

511     protected LocationBar locationBar;
512
513     /**
514      * The status bar.
515      */

516     protected StatusBar statusBar;
517
518     /**
519      * The initial frame title.
520      */

521     protected String JavaDoc title;
522
523     /**
524      * The local history.
525      */

526     protected LocalHistory localHistory;
527
528     /**
529      * The transform history.
530      */

531     protected TransformHistory transformHistory = new TransformHistory();
532
533     /**
534      * The alternate style-sheet title.
535      */

536     protected String JavaDoc alternateStyleSheet;
537
538     /**
539      * Creates a new SVG viewer frame.
540      */

541     public JSVGViewerFrame(Application app) {
542         application = app;
543
544         addWindowListener(new WindowAdapter JavaDoc() {
545             public void windowClosing(WindowEvent JavaDoc e) {
546                 application.closeJSVGViewerFrame(JSVGViewerFrame.this);
547             }
548         });
549
550         //
551
// Set the frame's maximum size so that content
552
// bigger than the screen does not cause the creation
553
// of unnecessary large images.
554
//
555
svgCanvas = new JSVGCanvas(userAgent, true, true){
556                 Dimension JavaDoc screenSize;
557                 
558                 {
559                     screenSize = Toolkit.getDefaultToolkit().getScreenSize();
560                     setMaximumSize(screenSize);
561                 }
562                 
563                 public Dimension JavaDoc getPreferredSize(){
564                     Dimension JavaDoc s = super.getPreferredSize();
565                     if (s.width > screenSize.width) s.width =screenSize.width;
566                     if (s.height > screenSize.height) s.height = screenSize.height;
567                     return s;
568                 }
569
570                 
571                 /**
572                  * This method is called when the component knows the desired
573                  * size of the window (based on width/height of outermost SVG
574                  * element). We override it to immediately pack this frame.
575                  */

576                 public void setMySize(Dimension JavaDoc d) {
577                     setPreferredSize(d);
578                     invalidate();
579                     if (JSVGViewerFrame.this.autoAdjust) {
580                         JSVGViewerFrame.this.pack();
581                     }
582                 }
583
584                 public void setDisableInteractions(boolean b) {
585                     super.setDisableInteractions(b);
586
587                     // Disable/Enable all our different ways to adjust the
588
// rendering transform (menus, toolbar, thumbnail, keyboard).
589

590                     ((Action JavaDoc)listeners.get(SET_TRANSFORM_ACTION)) .setEnabled(!b);
591
592                     if (thumbnailDialog != null)
593                         thumbnailDialog.setInteractionEnabled(!b);
594                 }
595             };
596         
597         javax.swing.ActionMap JavaDoc map = svgCanvas.getActionMap();
598         map.put(FULL_SCREEN_ACTION, new FullScreenAction());
599         javax.swing.InputMap JavaDoc imap = svgCanvas.getInputMap(JComponent.WHEN_FOCUSED);
600         KeyStroke JavaDoc key = KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0);
601         imap.put(key, FULL_SCREEN_ACTION);
602
603         svgCanvas.setDoubleBufferedRendering(true);
604
605         listeners.put(ABOUT_ACTION, new AboutAction());
606         listeners.put(OPEN_ACTION, new OpenAction());
607         listeners.put(OPEN_LOCATION_ACTION, new OpenLocationAction());
608         listeners.put(NEW_WINDOW_ACTION, new NewWindowAction());
609         listeners.put(RELOAD_ACTION, new ReloadAction());
610         listeners.put(SAVE_AS_ACTION, new SaveAsAction());
611         listeners.put(BACK_ACTION, backAction);
612         listeners.put(FORWARD_ACTION, forwardAction);
613         listeners.put(PRINT_ACTION, new PrintAction());
614         listeners.put(EXPORT_AS_JPG_ACTION, new ExportAsJPGAction());
615         listeners.put(EXPORT_AS_PNG_ACTION, new ExportAsPNGAction());
616         listeners.put(EXPORT_AS_TIFF_ACTION, new ExportAsTIFFAction());
617         listeners.put(PREFERENCES_ACTION, new PreferencesAction());
618         listeners.put(CLOSE_ACTION, new CloseAction());
619         listeners.put(EXIT_ACTION, application.createExitAction(this));
620         listeners.put(VIEW_SOURCE_ACTION, new ViewSourceAction());
621
622         javax.swing.ActionMap JavaDoc cMap = svgCanvas.getActionMap();
623         listeners.put(RESET_TRANSFORM_ACTION,
624                       cMap.get(JSVGCanvas.RESET_TRANSFORM_ACTION));
625         listeners.put(ZOOM_IN_ACTION,
626                       cMap.get(JSVGCanvas.ZOOM_IN_ACTION));
627         listeners.put(ZOOM_OUT_ACTION,
628                       cMap.get(JSVGCanvas.ZOOM_OUT_ACTION));
629
630         listeners.put(PREVIOUS_TRANSFORM_ACTION, previousTransformAction);
631         key = KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.CTRL_MASK);
632         imap.put(key, previousTransformAction);
633
634         listeners.put(NEXT_TRANSFORM_ACTION, nextTransformAction);
635         key = KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_MASK);
636         imap.put(key, nextTransformAction);
637
638         listeners.put(USE_STYLESHEET_ACTION, useStylesheetAction);
639         listeners.put(PLAY_ACTION, playAction);
640         listeners.put(PAUSE_ACTION, pauseAction);
641         listeners.put(STOP_ACTION, stopAction);
642         listeners.put(MONITOR_ACTION, new MonitorAction());
643         listeners.put(DOM_VIEWER_ACTION, new DOMViewerAction());
644         listeners.put(SET_TRANSFORM_ACTION, new SetTransformAction());
645         listeners.put(FIND_DIALOG_ACTION, new FindDialogAction());
646         listeners.put(THUMBNAIL_DIALOG_ACTION, new ThumbnailDialogAction());
647         listeners.put(FLUSH_ACTION, new FlushAction());
648         listeners.put(TOGGLE_DEBUGGER_ACTION, new ToggleDebuggerAction());
649
650         JPanel JavaDoc p = null;
651         try {
652             // Create the menu
653
MenuFactory mf = new MenuFactory(bundle, this);
654             JMenuBar JavaDoc mb = mf.createJMenuBar("MenuBar");
655             setJMenuBar(mb);
656
657             localHistory = new LocalHistory(mb, this);
658
659             String JavaDoc uri[] = application.getVisitedURIs();
660             for (int i=0; i<uri.length; i++) {
661                 if (uri[i] != null && !"".equals(uri[i])) {
662                     localHistory.update(uri[i]);
663                 }
664             }
665             p = new JPanel JavaDoc(new BorderLayout JavaDoc());
666
667             // Create the toolbar
668
ToolBarFactory tbf = new ToolBarFactory(bundle, this);
669             JToolBar JavaDoc tb = tbf.createJToolBar("ToolBar");
670             tb.setFloatable(false);
671             getContentPane().add(p, BorderLayout.NORTH);
672             p.add(tb, BorderLayout.NORTH);
673             p.add(new javax.swing.JSeparator JavaDoc(), BorderLayout.CENTER);
674             p.add(locationBar = new LocationBar(), BorderLayout.SOUTH);
675
676         } catch (MissingResourceException JavaDoc e) {
677             System.out.println(e.getMessage());
678             System.exit(0);
679         }
680
681         svgCanvasPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
682         svgCanvasPanel.setBorder(BorderFactory.createEtchedBorder());
683
684         svgCanvasPanel.add(svgCanvas, BorderLayout.CENTER);
685         p = new JPanel JavaDoc(new BorderLayout JavaDoc());
686         p.add(svgCanvasPanel, BorderLayout.CENTER);
687         p.add(statusBar = new StatusBar(), BorderLayout.SOUTH);
688
689         getContentPane().add(p, BorderLayout.CENTER);
690
691         svgCanvas.addSVGDocumentLoaderListener(this);
692         svgCanvas.addGVTTreeBuilderListener(this);
693         svgCanvas.addSVGLoadEventDispatcherListener(this);
694         svgCanvas.addGVTTreeRendererListener(this);
695         svgCanvas.addLinkActivationListener(this);
696         svgCanvas.addUpdateManagerListener(this);
697
698         svgCanvas.addMouseMotionListener(new MouseMotionAdapter JavaDoc() {
699                 public void mouseMoved(MouseEvent JavaDoc e) {
700                     if (svgDocument == null) {
701                         statusBar.setXPosition(e.getX());
702                         statusBar.setYPosition(e.getY());
703                     } else {
704                         try {
705                             AffineTransform JavaDoc at;
706                             at = svgCanvas.getViewBoxTransform();
707                             if (at != null) {
708                                 at = at.createInverse();
709                                 Point2D JavaDoc p2d =
710                                     at.transform(new Point2D.Float JavaDoc(e.getX(), e.getY()),
711                                                  null);
712                                 statusBar.setXPosition((float)p2d.getX());
713                                 statusBar.setYPosition((float)p2d.getY());
714                                 return;
715                             }
716                         } catch (NoninvertibleTransformException JavaDoc ex) {
717                         }
718                         statusBar.setXPosition(e.getX());
719                         statusBar.setYPosition(e.getY());
720                     }
721                 }
722             });
723         svgCanvas.addMouseListener(new MouseAdapter JavaDoc() {
724                 public void mouseExited(MouseEvent JavaDoc e) {
725                     Dimension JavaDoc dim = svgCanvas.getSize();
726                     if (svgDocument == null) {
727                         statusBar.setWidth(dim.width);
728                         statusBar.setHeight(dim.height);
729                     } else {
730                         try {
731                             AffineTransform JavaDoc at;
732                             at = svgCanvas.getViewBoxTransform();
733                             if (at != null) {
734                                 at = at.createInverse();
735                                 Point2D JavaDoc o =
736                                     at.transform(new Point2D.Float JavaDoc(0, 0),
737                                                  null);
738                                 Point2D JavaDoc p2d =
739                                     at.transform(new Point2D.Float JavaDoc(dim.width,
740                                                                    dim.height),
741                                                  null);
742                                 statusBar.setWidth((float)(p2d.getX() - o.getX()));
743                                 statusBar.setHeight((float)(p2d.getY() - o.getY()));
744                                 return;
745                             }
746                         } catch (NoninvertibleTransformException JavaDoc ex) {
747                         }
748                         statusBar.setWidth(dim.width);
749                         statusBar.setHeight(dim.height);
750                     }
751                 }
752             });
753         svgCanvas.addComponentListener(new ComponentAdapter JavaDoc() {
754                 public void componentResized(ComponentEvent JavaDoc e) {
755                     Dimension JavaDoc dim = svgCanvas.getSize();
756                     if (svgDocument == null) {
757                         statusBar.setWidth(dim.width);
758                         statusBar.setHeight(dim.height);
759                     } else {
760                         try {
761                             AffineTransform JavaDoc at;
762                             at = svgCanvas.getViewBoxTransform();
763                             if (at != null) {
764                                 at = at.createInverse();
765                                 Point2D JavaDoc o =
766                                     at.transform(new Point2D.Float JavaDoc(0, 0),
767                                                  null);
768                                 Point2D JavaDoc p2d =
769                                     at.transform(new Point2D.Float JavaDoc(dim.width,
770                                                                    dim.height),
771                                                  null);
772                                 statusBar.setWidth((float)(p2d.getX() - o.getX()));
773                                 statusBar.setHeight((float)(p2d.getY() - o.getY()));
774                                 return;
775                             }
776                         } catch (NoninvertibleTransformException JavaDoc ex) {
777                         }
778                         statusBar.setWidth(dim.width);
779                         statusBar.setHeight(dim.height);
780                     }
781                 }
782             });
783
784         locationBar.addActionListener(new AbstractAction JavaDoc() {
785             public void actionPerformed(ActionEvent JavaDoc e) {
786                 String JavaDoc st = locationBar.getText().trim();
787                 int i = st.indexOf("#");
788                 String JavaDoc t = "";
789                 if (i != -1) {
790                     t = st.substring(i + 1);
791                     st = st.substring(0, i);
792                 }
793                 if (!st.equals("")) {
794                     try{
795                         File JavaDoc f = new File JavaDoc(st);
796                         if (f.exists()) {
797                             if (f.isDirectory()) {
798                                 st = null;
799                             } else {
800                                 try {
801                                     st = f.getCanonicalPath();
802                                     if (st.startsWith("/")) {
803                                         st = "file:" + st;
804                                     } else {
805                                         st = "file:/" + st;
806                                     }
807                                 } catch (IOException JavaDoc ex) {
808                                 }
809                             }
810                         }
811                     }catch(SecurityException JavaDoc se){
812                         // Could not patch the file URI for security
813
// reasons (e.g., when run as an unsigned
814
// JavaWebStart jar): file access is not
815
// allowed. Loading will fail, but there is
816
// nothing more to do at this point.
817
}
818
819                     if (st != null) {
820                         if (svgDocument != null) {
821                             ParsedURL docPURL
822                                 = new ParsedURL(svgDocument.getURL());
823                             ParsedURL purl = new ParsedURL(docPURL, st);
824                             String JavaDoc fi = svgCanvas.getFragmentIdentifier();
825                             fi = (fi == null) ? "" : fi;
826                             if (docPURL.equals(purl) && t.equals(fi)) {
827                                 return;
828                             }
829                         }
830                         if (t.length() != 0) {
831                             st += "#" + t;
832                         }
833                         locationBar.setText(st);
834                         locationBar.addToHistory(st);
835                         showSVGDocument(st);
836                     }
837                 }
838             }
839         });
840
841     }
842
843     /**
844      * Call dispose on canvas as well.
845      */

846     public void dispose() {
847         svgCanvas.dispose();
848         super.dispose();
849     }
850
851     /**
852      * Whether to show the debug traces.
853      */

854     public void setDebug(boolean b) {
855         debug = b;
856     }
857
858     /**
859      * Whether to auto adjust the canvas to the size of the document.
860      */

861     public void setAutoAdjust(boolean b) {
862         autoAdjust = b;
863     }
864
865     /**
866      * Returns the main JSVGCanvas of this frame.
867      */

868     public JSVGCanvas getJSVGCanvas() {
869         return svgCanvas;
870     }
871
872     /**
873      * Needed to work-around JFileChooser bug with abstract Files
874      */

875     private static File JavaDoc makeAbsolute(File JavaDoc f){
876         if(!f.isAbsolute()){
877             return f.getAbsoluteFile();
878         }
879         return f;
880     }
881
882     /**
883      * To show the about dialog
884      */

885     public class AboutAction extends AbstractAction JavaDoc {
886         public AboutAction(){
887         }
888
889         public void actionPerformed(ActionEvent JavaDoc e){
890             AboutDialog dlg = new AboutDialog(JSVGViewerFrame.this);
891             // Work around pack() bug on some platforms
892
dlg.setSize(dlg.getPreferredSize());
893             dlg.setLocationRelativeTo(JSVGViewerFrame.this);
894             dlg.setVisible(true);
895             dlg.toFront();
896         }
897     }
898
899     /**
900      * To open a new file.
901      */

902     public class OpenAction extends AbstractAction JavaDoc {
903
904         public OpenAction() {
905         }
906         public void actionPerformed(ActionEvent JavaDoc e) {
907             JFileChooser JavaDoc fileChooser = null;
908
909             // Apply work around Windows problem when security is enabled,
910
// and when prior to JDK 1.4.
911
String JavaDoc os = System.getProperty(PROPERTY_OS_NAME, PROPERTY_OS_NAME_DEFAULT);
912             SecurityManager JavaDoc sm = System.getSecurityManager();
913             
914             if ( priorJDK1_4 && sm != null && os.indexOf(PROPERTY_OS_WINDOWS_PREFIX) != -1 ){
915                 fileChooser = new JFileChooser JavaDoc(makeAbsolute(currentPath),
916                                                new WindowsAltFileSystemView());
917             } else {
918                 fileChooser = new JFileChooser JavaDoc(makeAbsolute(currentPath));
919             }
920
921             fileChooser.setFileHidingEnabled(false);
922             fileChooser.setFileSelectionMode
923                 (JFileChooser.FILES_ONLY);
924
925             //
926
// Add file filters from the handlers map
927
//
928
Iterator JavaDoc iter = getHandlers().iterator();
929             while (iter.hasNext()) {
930                 SquiggleInputHandler handler
931                     = (SquiggleInputHandler)iter.next();
932                 fileChooser.addChoosableFileFilter
933                     (new SquiggleInputHandlerFilter(handler));
934             }
935             
936             int choice = fileChooser.showOpenDialog(JSVGViewerFrame.this);
937             if (choice == JFileChooser.APPROVE_OPTION) {
938                 File JavaDoc f = fileChooser.getSelectedFile();
939                 
940                 currentPath = f;
941                 try {
942                     String JavaDoc furl = f.toURL().toString();
943                     showSVGDocument(furl);
944                 } catch (MalformedURLException JavaDoc ex) {
945                     if (userAgent != null) {
946                         userAgent.displayError(ex);
947                     }
948                 }
949             }
950         }
951     }
952
953     /**
954      * Shows the given document into the viewer frame
955      */

956     public void showSVGDocument(String JavaDoc uri){
957         try {
958             ParsedURL purl = new ParsedURL(uri);
959             SquiggleInputHandler
960                 handler = getInputHandler(purl);
961             
962             handler.handle(purl,
963                            JSVGViewerFrame.this);
964         } catch (Exception JavaDoc e) {
965             if (userAgent != null) {
966                 userAgent.displayError(e);
967             }
968         }
969
970     }
971
972     /**
973      * Returns the input handler for the given URI
974      */

975     public SquiggleInputHandler getInputHandler(ParsedURL purl) throws IOException JavaDoc {
976         Iterator JavaDoc iter = getHandlers().iterator();
977         SquiggleInputHandler handler = null;
978
979         while (iter.hasNext()) {
980             SquiggleInputHandler curHandler =
981                 (SquiggleInputHandler)iter.next();
982             if (curHandler.accept(purl)) {
983                 handler = curHandler;
984                 break;
985             }
986         }
987
988         // No handler found, use the default one.
989
if (handler == null) {
990             handler = defaultHandler;
991         }
992
993         return handler;
994     }
995
996
997     /**
998      * Returns the list of input file handler.
999      */

1000    protected static Vector JavaDoc getHandlers() {
1001        if (handlers != null) {
1002            return handlers;
1003        }
1004
1005        handlers = new Vector JavaDoc();
1006        registerHandler(new SVGInputHandler());
1007        
1008        Iterator JavaDoc iter = Service.providers(SquiggleInputHandler.class);
1009        while (iter.hasNext()) {
1010            SquiggleInputHandler handler
1011                = (SquiggleInputHandler)iter.next();
1012
1013            registerHandler(handler);
1014        }
1015
1016        return handlers;
1017    }
1018
1019    /**
1020     * Registers an input file handler by adding it to the handlers map.
1021     * @param handler the new input handler to register.
1022     */

1023    public static synchronized
1024        void registerHandler(SquiggleInputHandler handler) {
1025        Vector JavaDoc handlers = getHandlers();
1026        handlers.addElement(handler);
1027    }
1028
1029    /**
1030     * To open a new document.
1031     */

1032    public class OpenLocationAction extends AbstractAction JavaDoc {
1033        public OpenLocationAction() {}
1034        public void actionPerformed(ActionEvent JavaDoc e) {
1035            if (uriChooser == null) {
1036                uriChooser = new URIChooser(JSVGViewerFrame.this);
1037                uriChooser.setFileFilter(new SVGFileFilter());
1038                uriChooser.pack();
1039                Rectangle JavaDoc fr = getBounds();
1040                Dimension JavaDoc sd = uriChooser.getSize();
1041                uriChooser.setLocation(fr.x + (fr.width - sd.width) / 2,
1042                                       fr.y + (fr.height - sd.height) / 2);
1043            }
1044            if (uriChooser.showDialog() == URIChooser.OK_OPTION) {
1045                String JavaDoc s = uriChooser.getText();
1046                int i = s.indexOf("#");
1047                String JavaDoc t = "";
1048                if (i != -1) {
1049                    t = s.substring(i + 1);
1050                    s = s.substring(0, i);
1051                }
1052                if (!s.equals("")) {
1053                    File JavaDoc f = new File JavaDoc(s);
1054                    if (f.exists()) {
1055                        if (f.isDirectory()) {
1056                            s = null;
1057                        } else {
1058                            try {
1059                                s = f.getCanonicalPath();
1060                                if (s.startsWith("/")) {
1061                                    s = "file:" + s;
1062                                } else {
1063                                    s = "file:/" + s;
1064                                }
1065                            } catch (IOException JavaDoc ex) {
1066                            }
1067                        }
1068                    }
1069                    if (s != null) {
1070                        if (svgDocument != null) {
1071                            ParsedURL docPURL
1072                                = new ParsedURL(svgDocument.getURL());
1073                            ParsedURL purl = new ParsedURL(docPURL, s);
1074                            String JavaDoc fi = svgCanvas.getFragmentIdentifier();
1075                            if (docPURL.equals(purl) && t.equals(fi)) {
1076                                return;
1077                            }
1078                        }
1079                        if (t.length() != 0) {
1080                            s += "#" + t;
1081                        }
1082
1083                        showSVGDocument(s);
1084                    }
1085                }
1086            }
1087        }
1088    }
1089
1090    /**
1091     * To open a new window.
1092     */

1093    public class NewWindowAction extends AbstractAction JavaDoc {
1094        public NewWindowAction() {}
1095        public void actionPerformed(ActionEvent JavaDoc e) {
1096            JSVGViewerFrame vf = application.createAndShowJSVGViewerFrame();
1097
1098            // Copy the current settings to the new window.
1099
vf.autoAdjust = autoAdjust;
1100            vf.debug = debug;
1101            vf.svgCanvas.setProgressivePaint(svgCanvas.getProgressivePaint());
1102            vf.svgCanvas.setDoubleBufferedRendering
1103                (svgCanvas.getDoubleBufferedRendering());
1104        }
1105    }
1106
1107    /**
1108     * To show the preferences.
1109     */

1110    public class PreferencesAction extends AbstractAction JavaDoc {
1111        public PreferencesAction() {}
1112        public void actionPerformed(ActionEvent JavaDoc e) {
1113            application.showPreferenceDialog(JSVGViewerFrame.this);
1114        }
1115    }
1116
1117    /**
1118     * To close the last document.
1119     */

1120    public class CloseAction extends AbstractAction JavaDoc {
1121        public CloseAction() {}
1122        public void actionPerformed(ActionEvent JavaDoc e) {
1123            application.closeJSVGViewerFrame(JSVGViewerFrame.this);
1124        }
1125    }
1126
1127    /**
1128     * To reload the current document.
1129     */

1130    public class ReloadAction extends AbstractAction JavaDoc {
1131        public ReloadAction() {}
1132        public void actionPerformed(ActionEvent JavaDoc e) {
1133            if ((e.getModifiers() & ActionEvent.SHIFT_MASK) == 1) {
1134                svgCanvas.flushImageCache();
1135            }
1136            if (svgDocument != null) {
1137                localHistory.reload();
1138            }
1139        }
1140    }
1141
1142    /**
1143     * To go back to the previous document
1144     */

1145    public class BackAction extends AbstractAction JavaDoc
1146                            implements JComponentModifier {
1147        List JavaDoc components = new LinkedList JavaDoc();
1148        public BackAction() {}
1149        public void actionPerformed(ActionEvent JavaDoc e) {
1150            if (localHistory.canGoBack()) {
1151                localHistory.back();
1152            }
1153        }
1154
1155        public void addJComponent(JComponent JavaDoc c) {
1156            components.add(c);
1157            c.setEnabled(false);
1158        }
1159
1160        protected void update() {
1161            boolean b = localHistory.canGoBack();
1162            Iterator JavaDoc it = components.iterator();
1163            while (it.hasNext()) {
1164                ((JComponent JavaDoc)it.next()).setEnabled(b);
1165            }
1166        }
1167    }
1168
1169    /**
1170     * To go forward to the next document
1171     */

1172    public class ForwardAction extends AbstractAction JavaDoc
1173                               implements JComponentModifier {
1174        List JavaDoc components = new LinkedList JavaDoc();
1175        public ForwardAction() {}
1176        public void actionPerformed(ActionEvent JavaDoc e) {
1177            if (localHistory.canGoForward()) {
1178                localHistory.forward();
1179            }
1180        }
1181
1182        public void addJComponent(JComponent JavaDoc c) {
1183            components.add(c);
1184            c.setEnabled(false);
1185        }
1186
1187        protected void update() {
1188            boolean b = localHistory.canGoForward();
1189            Iterator JavaDoc it = components.iterator();
1190            while (it.hasNext()) {
1191                ((JComponent JavaDoc)it.next()).setEnabled(b);
1192            }
1193        }
1194    }
1195
1196    /**
1197     * To print the current document.
1198     */

1199    public class PrintAction extends AbstractAction JavaDoc {
1200        public PrintAction() {}
1201        public void actionPerformed(ActionEvent JavaDoc e) {
1202            if (svgDocument != null) {
1203                final SVGDocument doc = svgDocument;
1204                new Thread JavaDoc() {
1205                    public void run(){
1206                        String JavaDoc uri = doc.getURL();
1207                        String JavaDoc fragment = svgCanvas.getFragmentIdentifier();
1208                        if (fragment != null) {
1209                            uri += "#"+fragment;
1210                        }
1211
1212                        //
1213
// Build a PrintTranscoder to handle printing
1214
// of the svgDocument object
1215
//
1216
PrintTranscoder pt = new PrintTranscoder();
1217
1218                        //
1219
// Set transcoding hints
1220
//
1221
pt.addTranscodingHint(PrintTranscoder.KEY_XML_PARSER_CLASSNAME,
1222                                              application.getXMLParserClassName());
1223
1224                        pt.addTranscodingHint(PrintTranscoder.KEY_SHOW_PAGE_DIALOG,
1225                                              Boolean.TRUE);
1226
1227
1228                        pt.addTranscodingHint(PrintTranscoder.KEY_SHOW_PRINTER_DIALOG,
1229                                              Boolean.TRUE);
1230
1231                        //
1232
// Do transcoding now
1233
//
1234
pt.transcode(new TranscoderInput(uri), null);
1235
1236                        //
1237
// Print
1238
//
1239
try {
1240                            pt.print();
1241                        } catch (PrinterException JavaDoc ex) {
1242                            userAgent.displayError(ex);
1243                        }
1244                    }
1245                }.start();
1246            }
1247        }
1248    }
1249
1250    /**
1251     * To save the current document as SVG.
1252     */

1253    public class SaveAsAction extends AbstractAction JavaDoc {
1254        public SaveAsAction() {}
1255
1256        public void actionPerformed(ActionEvent JavaDoc e) {
1257            JFileChooser JavaDoc fileChooser;
1258            fileChooser = new JFileChooser JavaDoc(makeAbsolute(currentSavePath));
1259            fileChooser.setDialogTitle(resources.getString("SaveAs.title"));
1260            fileChooser.setFileHidingEnabled(false);
1261            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
1262            fileChooser.addChoosableFileFilter(new ImageFileFilter(".svg"));
1263
1264            int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
1265            if (choice != JFileChooser.APPROVE_OPTION)
1266                return;
1267
1268            final File JavaDoc f = fileChooser.getSelectedFile();
1269
1270            SVGOptionPanel sop;
1271            sop = SVGOptionPanel.showDialog(JSVGViewerFrame.this);
1272            
1273            final boolean useXMLBase = sop.getUseXMLBase();
1274            final boolean prettyPrint = sop.getPrettyPrint();
1275            sop = null;
1276
1277            final SVGDocument svgDoc = svgCanvas.getSVGDocument();
1278            if (svgDoc == null) return;
1279            
1280            statusBar.setMessage(resources.getString("Message.saveAs"));
1281            currentSavePath = f;
1282            OutputStreamWriter JavaDoc w = null;
1283            try {
1284                OutputStream JavaDoc tos = null;
1285                tos = new FileOutputStream JavaDoc(f);
1286                tos = new BufferedOutputStream JavaDoc(tos);
1287                w = new OutputStreamWriter JavaDoc(tos, "utf-8");
1288            } catch (Exception JavaDoc ex) {
1289                userAgent.displayError(ex);
1290                return;
1291            }
1292
1293            final OutputStreamWriter JavaDoc writer = w;
1294            
1295            final Runnable JavaDoc doneRun = new Runnable JavaDoc() {
1296                    public void run() {
1297                        String JavaDoc doneStr = resources.getString("Message.done");
1298                        statusBar.setMessage(doneStr);
1299                    }
1300                };
1301            Runnable JavaDoc r = new Runnable JavaDoc() {
1302                    public void run() {
1303                        try {
1304                            // Write standard XML header.
1305
writer.write
1306                                ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
1307                                writer.write (EOL);
1308
1309                            Node JavaDoc fc = svgDoc.getFirstChild();
1310                            if (fc.getNodeType() != Node.DOCUMENT_TYPE_NODE) {
1311                                // Not DT node in Document, so
1312
// provide Document Type dec.
1313
writer.write ("<!DOCTYPE svg PUBLIC '");
1314                                writer.write (SVGConstants.SVG_PUBLIC_ID);
1315                                writer.write ("' '");
1316                                writer.write (SVGConstants.SVG_SYSTEM_ID);
1317                                writer.write ("'>");
1318                                writer.write (EOL);
1319                                writer.write (EOL);
1320                            }
1321                            Element JavaDoc root = svgDoc.getRootElement();
1322                            boolean doXMLBase = useXMLBase;
1323                            if (root.hasAttributeNS
1324                                (XMLConstants.XML_NAMESPACE_URI, "base"))
1325                                doXMLBase = false;
1326
1327                            if (doXMLBase) {
1328                                root.setAttributeNS
1329                                    (XMLConstants.XML_NAMESPACE_URI,
1330                                     "xml:base",
1331                                     svgDoc.getURL());
1332                            }
1333
1334                            if (prettyPrint) {
1335                                SVGTranscoder trans = new SVGTranscoder();
1336                                trans.transcode(new TranscoderInput(svgDoc),
1337                                                new TranscoderOutput(writer));
1338                            } else {
1339                                DOMUtilities.writeDocument(svgDoc, writer);
1340                            }
1341
1342                            writer.close();
1343
1344                            if (doXMLBase)
1345                                root.removeAttributeNS
1346                                    (XMLConstants.XML_NAMESPACE_URI,
1347                                     "xml:base");
1348
1349                            if (EventQueue.isDispatchThread()) {
1350                                doneRun.run();
1351                            } else {
1352                                EventQueue.invokeLater(doneRun);
1353                            }
1354                        } catch (Exception JavaDoc ex) {
1355                            userAgent.displayError(ex);
1356                        }
1357                    }
1358                };
1359
1360            UpdateManager um = svgCanvas.getUpdateManager();
1361            if ((um != null) && (um.isRunning())) {
1362                um.getUpdateRunnableQueue().invokeLater(r);
1363            } else {
1364                r.run();
1365            }
1366        }
1367    }
1368
1369    /**
1370     * To save the current document as JPG.
1371     */

1372    public class ExportAsJPGAction extends AbstractAction JavaDoc {
1373        public ExportAsJPGAction() {}
1374        public void actionPerformed(ActionEvent JavaDoc e) {
1375            JFileChooser JavaDoc fileChooser =
1376                new JFileChooser JavaDoc(makeAbsolute(currentSavePath));
1377            fileChooser.setDialogTitle(resources.getString("ExportAsJPG.title"));
1378            fileChooser.setFileHidingEnabled(false);
1379            fileChooser.setFileSelectionMode
1380                (JFileChooser.FILES_ONLY);
1381            fileChooser.addChoosableFileFilter(new ImageFileFilter(".jpg"));
1382
1383            int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
1384            if (choice == JFileChooser.APPROVE_OPTION) {
1385                float quality =
1386                    JPEGOptionPanel.showDialog(JSVGViewerFrame.this);
1387
1388                final File JavaDoc f = fileChooser.getSelectedFile();
1389                BufferedImage JavaDoc buffer = svgCanvas.getOffScreen();
1390                if (buffer != null) {
1391                    statusBar.setMessage
1392                        (resources.getString("Message.exportAsJPG"));
1393
1394                    // create a BufferedImage of the appropriate type
1395
int w = buffer.getWidth();
1396                    int h = buffer.getHeight();
1397                    final ImageTranscoder trans = new JPEGTranscoder();
1398                    trans.addTranscodingHint
1399                        (JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
1400                         application.getXMLParserClassName());
1401                    trans.addTranscodingHint
1402                        (JPEGTranscoder.KEY_QUALITY, new Float JavaDoc(quality));
1403
1404                    final BufferedImage JavaDoc img = trans.createImage(w, h);
1405
1406                    // paint the buffer to the image
1407
Graphics2D JavaDoc g2d = img.createGraphics();
1408                    g2d.setColor(Color.white);
1409                    g2d.fillRect(0, 0, w, h);
1410                    g2d.drawImage(buffer, null, 0, 0);
1411                    new Thread JavaDoc() {
1412                        public void run() {
1413                            try {
1414                                currentSavePath = f;
1415                                OutputStream JavaDoc ostream =
1416                                    new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(f));
1417                                trans.writeImage(img, new TranscoderOutput(ostream));
1418                                ostream.flush();
1419                                ostream.close();
1420                            } catch (Exception JavaDoc ex) { }
1421                            statusBar.setMessage
1422                                (resources.getString("Message.done"));
1423                        }
1424                    }.start();
1425                }
1426            }
1427        }
1428    }
1429
1430    /**
1431     * To save the current document as PNG.
1432     */

1433    public class ExportAsPNGAction extends AbstractAction JavaDoc {
1434        public ExportAsPNGAction() {}
1435        public void actionPerformed(ActionEvent JavaDoc e) {
1436            JFileChooser JavaDoc fileChooser =
1437                new JFileChooser JavaDoc(makeAbsolute(currentSavePath));
1438            fileChooser.setDialogTitle(resources.getString("ExportAsPNG.title"));
1439            fileChooser.setFileHidingEnabled(false);
1440            fileChooser.setFileSelectionMode
1441                (JFileChooser.FILES_ONLY);
1442            fileChooser.addChoosableFileFilter(new ImageFileFilter(".png"));
1443
1444            int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
1445            if (choice == JFileChooser.APPROVE_OPTION) {
1446
1447        // Start: By Jun Inamori (jun@oop-reserch.com)
1448
boolean isIndexed =
1449                    PNGOptionPanel.showDialog(JSVGViewerFrame.this);
1450        // End: By Jun Inamori (jun@oop-reserch.com)
1451

1452                final File JavaDoc f = fileChooser.getSelectedFile();
1453                BufferedImage JavaDoc buffer = svgCanvas.getOffScreen();
1454                if (buffer != null) {
1455                    statusBar.setMessage
1456                        (resources.getString("Message.exportAsPNG"));
1457
1458                    // create a BufferedImage of the appropriate type
1459
int w = buffer.getWidth();
1460                    int h = buffer.getHeight();
1461                    final ImageTranscoder trans = new PNGTranscoder();
1462                    trans.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_CLASSNAME,
1463                                             application.getXMLParserClassName());
1464                    trans.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE,
1465                                             new Boolean JavaDoc(true));
1466
1467            // Start: By Jun Inamori
1468
if(isIndexed){
1469            trans.addTranscodingHint
1470                            (PNGTranscoder.KEY_INDEXED,new Integer JavaDoc(256));
1471            }
1472            // End: By Jun Inamori
1473

1474                    final BufferedImage JavaDoc img = trans.createImage(w, h);
1475
1476                    // paint the buffer to the image
1477
Graphics2D JavaDoc g2d = img.createGraphics();
1478                    g2d.drawImage(buffer, null, 0, 0);
1479                    new Thread JavaDoc() {
1480                        public void run() {
1481                            try {
1482                                currentSavePath = f;
1483                                OutputStream JavaDoc ostream =
1484                                    new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(f));
1485                                trans.writeImage(img,
1486                                                 new TranscoderOutput(ostream));
1487                                ostream.flush();
1488                            } catch (Exception JavaDoc ex) {}
1489                            statusBar.setMessage
1490                                (resources.getString("Message.done"));
1491                        }
1492                    }.start();
1493                }
1494            }
1495        }
1496    }
1497
1498    /**
1499     * To save the current document as TIFF.
1500     */

1501    public class ExportAsTIFFAction extends AbstractAction JavaDoc {
1502        public ExportAsTIFFAction() {}
1503        public void actionPerformed(ActionEvent JavaDoc e) {
1504            JFileChooser JavaDoc fileChooser =
1505                new JFileChooser JavaDoc(makeAbsolute(currentSavePath));
1506            fileChooser.setDialogTitle(resources.getString("ExportAsTIFF.title"));
1507            fileChooser.setFileHidingEnabled(false);
1508            fileChooser.setFileSelectionMode
1509                (JFileChooser.FILES_ONLY);
1510            fileChooser.addChoosableFileFilter(new ImageFileFilter(".tiff"));
1511
1512            int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
1513            if (choice == JFileChooser.APPROVE_OPTION) {
1514                final File JavaDoc f = fileChooser.getSelectedFile();
1515                BufferedImage JavaDoc buffer = svgCanvas.getOffScreen();
1516                if (buffer != null) {
1517                    statusBar.setMessage
1518                        (resources.getString("Message.exportAsTIFF"));
1519
1520                    // create a BufferedImage of the appropriate type
1521
int w = buffer.getWidth();
1522                    int h = buffer.getHeight();
1523                    final ImageTranscoder trans = new TIFFTranscoder();
1524                    trans.addTranscodingHint
1525                        (TIFFTranscoder.KEY_XML_PARSER_CLASSNAME,
1526                         application.getXMLParserClassName());
1527                    final BufferedImage JavaDoc img = trans.createImage(w, h);
1528
1529                    // paint the buffer to the image
1530
Graphics2D JavaDoc g2d = img.createGraphics();
1531                    g2d.drawImage(buffer, null, 0, 0);
1532                    new Thread JavaDoc() {
1533                        public void run() {
1534                            try {
1535                                currentSavePath = f;
1536                                OutputStream JavaDoc ostream = new BufferedOutputStream JavaDoc
1537                                    (new FileOutputStream JavaDoc(f));
1538                                trans.writeImage
1539                                    (img, new TranscoderOutput(ostream));
1540                                ostream.flush();
1541                            } catch (Exception JavaDoc ex) {}
1542                            statusBar.setMessage
1543                                (resources.getString("Message.done"));
1544                        }
1545                    }.start();
1546                }
1547            }
1548        }
1549    }
1550
1551    /**
1552     * To view the source of the current document.
1553     */

1554    public class ViewSourceAction extends AbstractAction JavaDoc {
1555        public ViewSourceAction() {}
1556        public void actionPerformed(ActionEvent JavaDoc e) {
1557            if (svgDocument == null) {
1558                return;
1559            }
1560
1561            final ParsedURL u = new ParsedURL(svgDocument.getURL());
1562            
1563            final JFrame JavaDoc fr = new JFrame JavaDoc(u.toString());
1564            fr.setSize(resources.getInteger("ViewSource.width"),
1565                       resources.getInteger("ViewSource.height"));
1566            final JTextArea JavaDoc ta = new JTextArea JavaDoc();
1567            ta.setLineWrap(true);
1568            ta.setFont(new Font JavaDoc("monospaced", Font.PLAIN, 12));
1569
1570            JScrollPane JavaDoc scroll = new JScrollPane JavaDoc();
1571            scroll.getViewport().add(ta);
1572            scroll.setVerticalScrollBarPolicy
1573                (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
1574            fr.getContentPane().add(scroll, BorderLayout.CENTER);
1575
1576            new Thread JavaDoc() {
1577                public void run() {
1578                    char [] buffer = new char[4096];
1579
1580                    try {
1581                        Document JavaDoc doc = new PlainDocument JavaDoc();
1582
1583                        ParsedURL purl = new ParsedURL(svgDocument.getURL());
1584                        InputStream JavaDoc is
1585                            = u.openStream(getInputHandler(purl).
1586                                           getHandledMimeTypes());
1587                        // u.openStream(MimeTypeConstants.MIME_TYPES_SVG);
1588

1589                        Reader JavaDoc in = XMLUtilities.createXMLDocumentReader(is);
1590                        int len;
1591                        while ((len=in.read(buffer, 0, buffer.length)) != -1) {
1592                            doc.insertString(doc.getLength(),
1593                                             new String JavaDoc(buffer, 0, len), null);
1594                        }
1595
1596                        ta.setDocument(doc);
1597                        ta.setEditable(false);
1598                        ta.setBackground(Color.white);
1599                        fr.setVisible(true);
1600                    } catch (Exception JavaDoc ex) {
1601                        userAgent.displayError(ex);
1602                    }
1603                }
1604            }.start();
1605        }
1606    }
1607
1608    /**
1609     * To flush image cache (purely for debugging purposes)
1610     */

1611    public class FlushAction extends AbstractAction JavaDoc {
1612        public FlushAction() {}
1613        public void actionPerformed(ActionEvent JavaDoc e) {
1614            svgCanvas.flush();
1615            // Force redraw...
1616
svgCanvas.setRenderingTransform(svgCanvas.getRenderingTransform());
1617        }
1618    }
1619
1620    /**
1621     * To toggle visiblity of JavaScript Debugger.
1622     */

1623    public class ToggleDebuggerAction extends AbstractAction JavaDoc {
1624        public ToggleDebuggerAction() {
1625            super("Toggle Debugger Action");
1626            if (debuggerClass == null)
1627                setEnabled(false);
1628        }
1629
1630        public void actionPerformed(ActionEvent JavaDoc e) {
1631            if (debuggerClass == null) {
1632                setEnabled(false);
1633                return;
1634            }
1635            if ((debuggerFrame == null) || !debuggerFrame.isShowing())
1636                showDebugger();
1637            else
1638                hideDebugger();
1639        }
1640    }
1641
1642    /**
1643     * To go back to the previous transform
1644     */

1645    public class PreviousTransformAction extends AbstractAction JavaDoc
1646                                         implements JComponentModifier {
1647        List JavaDoc components = new LinkedList JavaDoc();
1648        public PreviousTransformAction() {}
1649        public void actionPerformed(ActionEvent JavaDoc e) {
1650            if (transformHistory.canGoBack()) {
1651                transformHistory.back();
1652                update();
1653                nextTransformAction.update();
1654                svgCanvas.setRenderingTransform(transformHistory.currentTransform());
1655            }
1656        }
1657
1658        public void addJComponent(JComponent JavaDoc c) {
1659            components.add(c);
1660            c.setEnabled(false);
1661        }
1662
1663        protected void update() {
1664            boolean b = transformHistory.canGoBack();
1665            Iterator JavaDoc it = components.iterator();
1666            while (it.hasNext()) {
1667                ((JComponent JavaDoc)it.next()).setEnabled(b);
1668            }
1669        }
1670    }
1671
1672    /**
1673     * To go forward to the next transform
1674     */

1675    public class NextTransformAction extends AbstractAction JavaDoc
1676                                         implements JComponentModifier {
1677        List JavaDoc components = new LinkedList JavaDoc();
1678        public NextTransformAction() {}
1679        public void actionPerformed(ActionEvent JavaDoc e) {
1680            if (transformHistory.canGoForward()) {
1681                transformHistory.forward();
1682                update();
1683                previousTransformAction.update();
1684                svgCanvas.setRenderingTransform(transformHistory.currentTransform());
1685            }
1686        }
1687
1688        public void addJComponent(JComponent JavaDoc c) {
1689            components.add(c);
1690            c.setEnabled(false);
1691        }
1692
1693        protected void update() {
1694            boolean b = transformHistory.canGoForward();
1695            Iterator JavaDoc it = components.iterator();
1696            while (it.hasNext()) {
1697                ((JComponent JavaDoc)it.next()).setEnabled(b);
1698            }
1699        }
1700    }
1701
1702    /**
1703     * To apply the selected author stylesheet
1704     */

1705    public class UseStylesheetAction extends AbstractAction JavaDoc
1706                                     implements JComponentModifier {
1707
1708        List JavaDoc components = new LinkedList JavaDoc();
1709
1710        public UseStylesheetAction() {}
1711
1712        public void actionPerformed(ActionEvent JavaDoc e) {
1713        }
1714
1715        public void addJComponent(JComponent JavaDoc c) {
1716            components.add(c);
1717            c.setEnabled(false);
1718        }
1719
1720        protected void update() {
1721            alternateStyleSheet = null;
1722            Iterator JavaDoc it = components.iterator();
1723            SVGDocument doc = svgCanvas.getSVGDocument();
1724            while (it.hasNext()) {
1725                JComponent JavaDoc stylesheetMenu = (JComponent JavaDoc)it.next();
1726                stylesheetMenu.removeAll();
1727                stylesheetMenu.setEnabled(false);
1728
1729                ButtonGroup JavaDoc buttonGroup = new ButtonGroup JavaDoc();
1730
1731                for (Node JavaDoc n = doc.getFirstChild();
1732                     n != null && n.getNodeType() != Node.ELEMENT_NODE;
1733                     n = n.getNextSibling()) {
1734                    if (n instanceof StyleSheetProcessingInstruction) {
1735                        StyleSheetProcessingInstruction sspi;
1736                        sspi = (StyleSheetProcessingInstruction)n;
1737                        HashTable attrs = sspi.getPseudoAttributes();
1738                        final String JavaDoc title = (String JavaDoc)attrs.get("title");
1739                        String JavaDoc alt = (String JavaDoc)attrs.get("alternate");
1740                        if (title != null && "yes".equals(alt)) {
1741                            JRadioButtonMenuItem JavaDoc button;
1742                            button = new JRadioButtonMenuItem JavaDoc(title);
1743
1744                            button.addActionListener
1745                                (new java.awt.event.ActionListener JavaDoc() {
1746                                    public void actionPerformed(ActionEvent JavaDoc e) {
1747                                        SVGOMDocument doc;
1748                                        doc = (SVGOMDocument)svgCanvas.getSVGDocument();
1749                                        doc.clearViewCSS();
1750                                        alternateStyleSheet = title;
1751                                        svgCanvas.setSVGDocument(doc);
1752                                    }
1753                                });
1754
1755                            buttonGroup.add(button);
1756                            stylesheetMenu.add(button);
1757                            stylesheetMenu.setEnabled(true);
1758                        }
1759                    }
1760                }
1761            }
1762        }
1763    }
1764
1765    /**
1766     * To restart after a pause.
1767     */

1768    public class PlayAction extends AbstractAction JavaDoc
1769                            implements JComponentModifier {
1770        java.util.List JavaDoc components = new LinkedList JavaDoc();
1771        public PlayAction() {}
1772        public void actionPerformed(ActionEvent JavaDoc e) {
1773            svgCanvas.resumeProcessing();
1774        }
1775
1776        public void addJComponent(JComponent JavaDoc c) {
1777            components.add(c);
1778            c.setEnabled(false);
1779        }
1780
1781        public void update(boolean enabled) {
1782            Iterator JavaDoc it = components.iterator();
1783            while (it.hasNext()) {
1784                ((JComponent JavaDoc)it.next()).setEnabled(enabled);
1785            }
1786        }
1787    }
1788
1789    /**
1790     * To pause a document.
1791     */

1792    public class PauseAction extends AbstractAction JavaDoc
1793                            implements JComponentModifier {
1794        java.util.List JavaDoc components = new LinkedList JavaDoc();
1795        public PauseAction() {}
1796        public void actionPerformed(ActionEvent JavaDoc e) {
1797            svgCanvas.suspendProcessing();
1798        }
1799
1800        public void addJComponent(JComponent JavaDoc c) {
1801            components.add(c);
1802            c.setEnabled(false);
1803        }
1804
1805        public void update(boolean enabled) {
1806            Iterator JavaDoc it = components.iterator();
1807            while (it.hasNext()) {
1808                ((JComponent JavaDoc)it.next()).setEnabled(enabled);
1809            }
1810        }
1811    }
1812
1813    /**
1814     * To stop the current processing.
1815     */

1816    public class StopAction extends AbstractAction JavaDoc
1817                            implements JComponentModifier {
1818        java.util.List JavaDoc components = new LinkedList JavaDoc();
1819        public StopAction() {}
1820        public void actionPerformed(ActionEvent JavaDoc e) {
1821            svgCanvas.stopProcessing();
1822        }
1823
1824        public void addJComponent(JComponent JavaDoc c) {
1825            components.add(c);
1826            c.setEnabled(false);
1827        }
1828
1829        public void update(boolean enabled) {
1830            Iterator JavaDoc it = components.iterator();
1831            while (it.hasNext()) {
1832                ((JComponent JavaDoc)it.next()).setEnabled(enabled);
1833            }
1834        }
1835    }
1836
1837    /**
1838     * To show the set transform dialog
1839     */

1840    public class SetTransformAction extends AbstractAction JavaDoc {
1841        public SetTransformAction(){}
1842        public void actionPerformed(ActionEvent JavaDoc e){
1843            if (transformDialog == null){
1844                transformDialog
1845                    = JAffineTransformChooser.createDialog
1846                    (JSVGViewerFrame.this,
1847                     resources.getString("SetTransform.title"));
1848            }
1849
1850            AffineTransform JavaDoc txf = transformDialog.showDialog();
1851            if(txf != null){
1852                AffineTransform JavaDoc at = svgCanvas.getRenderingTransform();
1853                if(at == null){
1854                    at = new AffineTransform JavaDoc();
1855                }
1856
1857                txf.concatenate(at);
1858                svgCanvas.setRenderingTransform(txf);
1859            }
1860        }
1861    }
1862
1863    /**
1864     * To display the memory monitor.
1865     */

1866    public class MonitorAction extends AbstractAction JavaDoc {
1867        public MonitorAction() {}
1868        public void actionPerformed(ActionEvent JavaDoc e) {
1869            if (memoryMonitorFrame == null) {
1870                memoryMonitorFrame = new MemoryMonitor();
1871                Rectangle JavaDoc fr = getBounds();
1872                Dimension JavaDoc md = memoryMonitorFrame.getSize();
1873                memoryMonitorFrame.setLocation(fr.x + (fr.width - md.width) / 2,
1874                                               fr.y + (fr.height - md.height) / 2);
1875            }
1876            memoryMonitorFrame.setVisible(true);
1877        }
1878    }
1879
1880    /**
1881     * To display the Find dialog
1882     */

1883    public class FindDialogAction extends AbstractAction JavaDoc {
1884        public FindDialogAction() {}
1885        public void actionPerformed(ActionEvent JavaDoc e) {
1886            if (findDialog == null) {
1887                findDialog = new FindDialog(JSVGViewerFrame.this, svgCanvas);
1888                findDialog.setGraphicsNode(svgCanvas.getGraphicsNode());
1889                findDialog.pack();
1890                Rectangle JavaDoc fr = getBounds();
1891                Dimension JavaDoc td = findDialog.getSize();
1892                findDialog.setLocation(fr.x + (fr.width - td.width) / 2,
1893                                       fr.y + (fr.height - td.height) / 2);
1894            }
1895            findDialog.setVisible(true);
1896        }
1897    }
1898
1899    /**
1900     * To display the Thumbnail dialog
1901     */

1902    public class ThumbnailDialogAction extends AbstractAction JavaDoc {
1903        public ThumbnailDialogAction() {}
1904        public void actionPerformed(ActionEvent JavaDoc e) {
1905            if (thumbnailDialog == null) {
1906                thumbnailDialog
1907                    = new ThumbnailDialog(JSVGViewerFrame.this, svgCanvas);
1908                thumbnailDialog.pack();
1909                Rectangle JavaDoc fr = getBounds();
1910                Dimension JavaDoc td = thumbnailDialog.getSize();
1911                thumbnailDialog.setLocation(fr.x + (fr.width - td.width) / 2,
1912                                            fr.y + (fr.height - td.height) / 2);
1913            }
1914            thumbnailDialog.setInteractionEnabled
1915                (!svgCanvas.getDisableInteractions());
1916            thumbnailDialog.setVisible(true);
1917        }
1918    }
1919
1920    /**
1921     * To display the document full screen
1922     */

1923    public class FullScreenAction extends AbstractAction JavaDoc {
1924        public FullScreenAction() {}
1925
1926        public void actionPerformed(ActionEvent JavaDoc e) {
1927            if (window == null || !window.isVisible()) {
1928                if (window == null) {
1929                    window = new JWindow JavaDoc(JSVGViewerFrame.this);
1930                    Dimension JavaDoc size = Toolkit.getDefaultToolkit().getScreenSize();
1931                    window.setSize(size);
1932                }
1933                // Go to full screen in JWindow)
1934
svgCanvas.getParent().remove(svgCanvas);
1935                window.getContentPane().add(svgCanvas);
1936                window.setVisible(true);
1937                window.toFront();
1938                svgCanvas.requestFocus();
1939            } else {
1940                // Go back to JSVGViewerFrame display
1941
svgCanvas.getParent().remove(svgCanvas);
1942                svgCanvasPanel.add(svgCanvas, BorderLayout.CENTER);
1943                window.setVisible(false);
1944            }
1945        }
1946    }
1947    
1948    /**
1949     * To display the DOM viewer of the document
1950     */

1951    public class DOMViewerAction extends AbstractAction JavaDoc {
1952        public DOMViewerAction() {}
1953        public void actionPerformed(ActionEvent JavaDoc e) {
1954            if (domViewer == null) {
1955                domViewer = new DOMViewer();
1956                if (svgDocument != null) {
1957                    domViewer.setDocument(svgDocument,
1958                                          (ViewCSS)svgDocument.getDocumentElement());
1959                }
1960                Rectangle JavaDoc fr = getBounds();
1961                Dimension JavaDoc td = domViewer.getSize();
1962                domViewer.setLocation(fr.x + (fr.width - td.width) / 2,
1963                                      fr.y + (fr.height - td.height) / 2);
1964            }
1965            domViewer.setVisible(true);
1966        }
1967    }
1968
1969    // ActionMap /////////////////////////////////////////////////////
1970

1971    /**
1972     * The map that contains the action listeners
1973     */

1974    protected Map JavaDoc listeners = new HashMap JavaDoc();
1975
1976    /**
1977     * Returns the action associated with the given string
1978     * or null on error
1979     * @param key the key mapped with the action to get
1980     * @throws MissingListenerException if the action is not found
1981     */

1982    public Action JavaDoc getAction(String JavaDoc key) throws MissingListenerException {
1983        Action JavaDoc result = (Action JavaDoc)listeners.get(key);
1984        //if (result == null) {
1985
//result = canvas.getAction(key);
1986
//}
1987
if (result == null) {
1988            throw new MissingListenerException("Can't find action.", RESOURCES, key);
1989        }
1990        return result;
1991    }
1992
1993    // SVGDocumentLoaderListener ///////////////////////////////////////////
1994

1995    long time; // For debug.
1996

1997    /**
1998     * Called when the loading of a document was started.
1999     */

2000    public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
2001        String JavaDoc msg = resources.getString("Message.documentLoad");
2002        if (debug) {
2003            System.out.println(msg);
2004            time = System.currentTimeMillis();
2005        }
2006        statusBar.setMainMessage(msg);
2007        stopAction.update(true);
2008        svgCanvas.setCursor(WAIT_CURSOR);
2009    }
2010
2011
2012    /**
2013     * Called when the loading of a document was completed.
2014     */

2015    public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
2016        if (debug) {
2017            System.out.print(resources.getString("Message.documentLoadTime"));
2018            System.out.println((System.currentTimeMillis() - time) + " ms");
2019        }
2020
2021        setSVGDocument(e.getSVGDocument(),
2022                       e.getSVGDocument().getURL(),
2023                       e.getSVGDocument().getTitle());
2024    }
2025
2026    /**
2027     * Forces the viewer frame to show the input SVGDocument
2028     */

2029    public void setSVGDocument(SVGDocument svgDocument,
2030                               String JavaDoc svgDocumentURL,
2031                               String JavaDoc svgDocumentTitle) {
2032        this.svgDocument = svgDocument;
2033
2034        if (domViewer != null) {
2035            if(domViewer.isVisible() && svgDocument != null) {
2036                domViewer.setDocument(svgDocument,
2037                                      (ViewCSS)svgDocument.getDocumentElement());
2038            } else {
2039                domViewer.dispose();
2040                domViewer = null;
2041            }
2042        }
2043        stopAction.update(false);
2044        svgCanvas.setCursor(DEFAULT_CURSOR);
2045        String JavaDoc s = svgDocumentURL;
2046        String JavaDoc t = svgCanvas.getFragmentIdentifier();
2047        if (t != null) {
2048            s += "#" + t;
2049        }
2050
2051        locationBar.setText(s);
2052        if (title == null) {
2053            title = getTitle();
2054        }
2055
2056        String JavaDoc dt = svgDocumentTitle;
2057        if (dt.length() != 0) {
2058            setTitle(title + ": " + dt);
2059        } else {
2060            int i = s.lastIndexOf("/");
2061            if (i == -1)
2062                i = s.lastIndexOf("\\");
2063            if (i == -1) {
2064                setTitle(title + ": " + s);
2065            } else {
2066                setTitle(title + ": " + s.substring(i + 1));
2067            }
2068        }
2069
2070        localHistory.update(s);
2071        application.addVisitedURI(s);
2072        backAction.update();
2073        forwardAction.update();
2074
2075        transformHistory = new TransformHistory();
2076        previousTransformAction.update();
2077        nextTransformAction.update();
2078
2079        useStylesheetAction.update();
2080    }
2081
2082    /**
2083     * Called when the loading of a document was cancelled.
2084     */

2085    public void documentLoadingCancelled(SVGDocumentLoaderEvent e) {
2086        String JavaDoc msg = resources.getString("Message.documentCancelled");
2087        if (debug) {
2088            System.out.println(msg);
2089        }
2090        statusBar.setMainMessage("");
2091        statusBar.setMessage(msg);
2092        stopAction.update(false);
2093        svgCanvas.setCursor(DEFAULT_CURSOR);
2094    }
2095
2096    /**
2097     * Called when the loading of a document has failed.
2098     */

2099    public void documentLoadingFailed(SVGDocumentLoaderEvent e) {
2100        String JavaDoc msg = resources.getString("Message.documentFailed");
2101        if (debug) {
2102            System.out.println(msg);
2103        }
2104        statusBar.setMainMessage("");
2105        statusBar.setMessage(msg);
2106        stopAction.update(false);
2107        svgCanvas.setCursor(DEFAULT_CURSOR);
2108    }
2109
2110    // GVTTreeBuilderListener //////////////////////////////////////////////
2111

2112    /**
2113     * Called when a build started.
2114     * The data of the event is initialized to the old document.
2115     */

2116    public void gvtBuildStarted(GVTTreeBuilderEvent e) {
2117        String JavaDoc msg = resources.getString("Message.treeBuild");
2118        if (debug) {
2119            System.out.println(msg);
2120            time = System.currentTimeMillis();
2121        }
2122        statusBar.setMainMessage(msg);
2123        stopAction.update(true);
2124        svgCanvas.setCursor(WAIT_CURSOR);
2125    }
2126
2127    /**
2128     * Called when a build was completed.
2129     */

2130    public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
2131        if (debug) {
2132            System.out.print(resources.getString("Message.treeBuildTime"));
2133            System.out.println((System.currentTimeMillis() - time) + " ms");
2134        }
2135        if (findDialog != null) {
2136            if(findDialog.isVisible()) {
2137                findDialog.setGraphicsNode(svgCanvas.getGraphicsNode());
2138            } else {
2139                findDialog.dispose();
2140                findDialog = null;
2141            }
2142        }
2143        stopAction.update(false);
2144        svgCanvas.setCursor(DEFAULT_CURSOR);
2145        svgCanvas.setSelectionOverlayXORMode
2146            (application.isSelectionOverlayXORMode());
2147        svgCanvas.requestFocus(); // request focus when load completes.
2148
}
2149
2150    /**
2151     * Called when a build was cancelled.
2152     */

2153    public void gvtBuildCancelled(GVTTreeBuilderEvent e) {
2154        String JavaDoc msg = resources.getString("Message.treeCancelled");
2155        if (debug) {
2156            System.out.println(msg);
2157        }
2158        statusBar.setMainMessage("");
2159        statusBar.setMessage(msg);
2160        stopAction.update(false);
2161        svgCanvas.setCursor(DEFAULT_CURSOR);
2162        svgCanvas.setSelectionOverlayXORMode
2163            (application.isSelectionOverlayXORMode());
2164    }
2165
2166    /**
2167     * Called when a build failed.
2168     */

2169    public void gvtBuildFailed(GVTTreeBuilderEvent e) {
2170        String JavaDoc msg = resources.getString("Message.treeFailed");
2171        if (debug) {
2172            System.out.println(msg);
2173        }
2174        statusBar.setMainMessage("");
2175        statusBar.setMessage(msg);
2176        stopAction.update(false);
2177        svgCanvas.setCursor(DEFAULT_CURSOR);
2178        svgCanvas.setSelectionOverlayXORMode
2179            (application.isSelectionOverlayXORMode());
2180        if (autoAdjust) {
2181            pack();
2182        }
2183    }
2184
2185    // SVGLoadEventDispatcherListener //////////////////////////////////////
2186

2187    /**
2188     * Called when a onload event dispatch started.
2189     */

2190    public void svgLoadEventDispatchStarted(SVGLoadEventDispatcherEvent e) {
2191        String JavaDoc msg = resources.getString("Message.onload");
2192        if (debug) {
2193            System.out.println(msg);
2194            time = System.currentTimeMillis();
2195        }
2196        stopAction.update(true);
2197        statusBar.setMainMessage(msg);
2198    }
2199
2200    /**
2201     * Called when a onload event dispatch was completed.
2202     */

2203    public void svgLoadEventDispatchCompleted(SVGLoadEventDispatcherEvent e) {
2204        if (debug) {
2205            System.out.print(resources.getString("Message.onloadTime"));
2206            System.out.println((System.currentTimeMillis() - time) + " ms");
2207        }
2208        stopAction.update(false);
2209        statusBar.setMainMessage("");
2210        statusBar.setMessage(resources.getString("Message.done"));
2211    }
2212
2213    /**
2214     * Called when a onload event dispatch was cancelled.
2215     */

2216    public void svgLoadEventDispatchCancelled(SVGLoadEventDispatcherEvent e) {
2217        String JavaDoc msg = resources.getString("Message.onloadCancelled");
2218        if (debug) {
2219            System.out.println(msg);
2220        }
2221        stopAction.update(false);
2222        statusBar.setMainMessage("");
2223        statusBar.setMessage(msg);
2224    }
2225
2226    /**
2227     * Called when a onload event dispatch failed.
2228     */

2229    public void svgLoadEventDispatchFailed(SVGLoadEventDispatcherEvent e) {
2230        String JavaDoc msg = resources.getString("Message.onloadFailed");
2231        if (debug) {
2232            System.out.println(msg);
2233        }
2234        stopAction.update(false);
2235        statusBar.setMainMessage("");
2236        statusBar.setMessage(msg);
2237    }
2238
2239    // GVTTreeRendererListener /////////////////////////////////////////////
2240

2241    /**
2242     * Called when a rendering is in its preparing phase.
2243     */

2244    public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
2245        if (debug) {
2246            String JavaDoc msg = resources.getString("Message.treeRenderingPrep");
2247            System.out.println(msg);
2248            time = System.currentTimeMillis();
2249        }
2250        stopAction.update(true);
2251        svgCanvas.setCursor(WAIT_CURSOR);
2252        statusBar.setMainMessage(resources.getString("Message.treeRendering"));
2253    }
2254
2255    /**
2256     * Called when a rendering started.
2257     */

2258    public void gvtRenderingStarted(GVTTreeRendererEvent e) {
2259        if (debug) {
2260            String JavaDoc msg = resources.getString("Message.treeRenderingPrepTime");
2261            System.out.print(msg);
2262            System.out.println((System.currentTimeMillis() - time) + " ms");
2263            time = System.currentTimeMillis();
2264            msg = resources.getString("Message.treeRenderingStart");
2265            System.out.println(msg);
2266        }
2267        // Do nothing
2268
}
2269
2270    /**
2271     * Called when a rendering was completed.
2272     */

2273    public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
2274        if (debug) {
2275            String JavaDoc msg = resources.getString("Message.treeRenderingTime");
2276            System.out.print(msg);
2277            System.out.println((System.currentTimeMillis() - time) + " ms");
2278        }
2279        statusBar.setMainMessage("");
2280        statusBar.setMessage(resources.getString("Message.done"));
2281        if (!svgCanvas.isDynamic() || managerStopped) {
2282            stopAction.update(false);
2283        }
2284        svgCanvas.setCursor(DEFAULT_CURSOR);
2285
2286        transformHistory.update(svgCanvas.getRenderingTransform());
2287        previousTransformAction.update();
2288        nextTransformAction.update();
2289    }
2290
2291    /**
2292     * Called when a rendering was cancelled.
2293     */

2294    public void gvtRenderingCancelled(GVTTreeRendererEvent e) {
2295        String JavaDoc msg = resources.getString("Message.treeRenderingCancelled");
2296        if (debug) {
2297            System.out.println(msg);
2298        }
2299        statusBar.setMainMessage("");
2300        statusBar.setMessage(msg);
2301        if (!svgCanvas.isDynamic()) {
2302            stopAction.update(false);
2303        }
2304        svgCanvas.setCursor(DEFAULT_CURSOR);
2305    }
2306
2307    /**
2308     * Called when a rendering failed.
2309     */

2310    public void gvtRenderingFailed(GVTTreeRendererEvent e) {
2311        String JavaDoc msg = resources.getString("Message.treeRenderingFailed");
2312        if (debug) {
2313            System.out.println(msg);
2314        }
2315        statusBar.setMainMessage("");
2316        statusBar.setMessage(msg);
2317        if (!svgCanvas.isDynamic()) {
2318            stopAction.update(false);
2319        }
2320        svgCanvas.setCursor(DEFAULT_CURSOR);
2321    }
2322
2323    // LinkActivationListener /////////////////////////////////////////
2324

2325    /**
2326     * Called when a link was activated.
2327     */

2328    public void linkActivated(LinkActivationEvent e) {
2329        String JavaDoc s = e.getReferencedURI();
2330        if (svgDocument != null) {
2331            ParsedURL docURL = new ParsedURL(svgDocument.getURL());
2332            ParsedURL url = new ParsedURL(docURL, s);
2333            if (!url.sameFile(docURL)) {
2334                return;
2335            }
2336
2337            if (s.indexOf("#") != -1) {
2338                localHistory.update(s);
2339                application.addVisitedURI(s);
2340                backAction.update();
2341                forwardAction.update();
2342
2343                transformHistory = new TransformHistory();
2344                previousTransformAction.update();
2345                nextTransformAction.update();
2346            }
2347        }
2348    }
2349
2350    // UpdateManagerListener ////////////////////////////////////////////////
2351

2352    /**
2353     * Called when the manager was started.
2354     */

2355    public void managerStarted(UpdateManagerEvent e) {
2356        if (debug) {
2357            String JavaDoc msg = resources.getString("Message.updateManagerStarted");
2358            System.out.println(msg);
2359        }
2360        managerStopped = false;
2361        playAction.update(false);
2362        pauseAction.update(true);
2363        stopAction.update(true);
2364    }
2365
2366    /**
2367     * Called when the manager was suspended.
2368     */

2369    public void managerSuspended(UpdateManagerEvent e) {
2370        if (debug) {
2371            String JavaDoc msg = resources.getString("Message.updateManagerSuspended");
2372            System.out.println(msg);
2373        }
2374        playAction.update(true);
2375        pauseAction.update(false);
2376    }
2377
2378    /**
2379     * Called when the manager was resumed.
2380     */

2381    public void managerResumed(UpdateManagerEvent e) {
2382        if (debug) {
2383            String JavaDoc msg = resources.getString("Message.updateManagerResumed");
2384            System.out.println(msg);
2385        }
2386        playAction.update(false);
2387        pauseAction.update(true);
2388    }
2389
2390    /**
2391     * Called when the manager was stopped.
2392     */

2393    public void managerStopped(UpdateManagerEvent e) {
2394        if (debug) {
2395            String JavaDoc msg = resources.getString("Message.updateManagerStopped");
2396            System.out.println(msg);
2397        }
2398        managerStopped = true;
2399        playAction.update(false);
2400        pauseAction.update(false);
2401        stopAction.update(false);
2402    }
2403
2404    /**
2405     * Called when an update started.
2406     */

2407    public void updateStarted(final UpdateManagerEvent e) {
2408    }
2409
2410    /**
2411     * Called when an update was completed.
2412     */

2413    public void updateCompleted(final UpdateManagerEvent e) {
2414    }
2415
2416    /**
2417     * Called when an update failed.
2418     */

2419    public void updateFailed(UpdateManagerEvent e) {
2420    }
2421
2422    /**
2423     * This class implements a SVG user agent.
2424     */

2425    protected class UserAgent implements SVGUserAgent {
2426
2427        /**
2428         * Creates a new SVGUserAgent.
2429         */

2430        protected UserAgent() {
2431        }
2432
2433        /**
2434         * Displays an error message.
2435         */

2436        public void displayError(String JavaDoc message) {
2437            if (debug) {
2438                System.err.println(message);
2439            }
2440            JOptionPane JavaDoc pane =
2441                new JOptionPane JavaDoc(message, JOptionPane.ERROR_MESSAGE);
2442            JDialog JavaDoc dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR");
2443            dialog.setModal(false);
2444            dialog.setVisible(true);
2445        }
2446
2447        /**
2448         * Displays an error resulting from the specified Exception.
2449         */

2450        public void displayError(Exception JavaDoc ex) {
2451            if (debug) {
2452                ex.printStackTrace();
2453            }
2454            JErrorPane pane =
2455                new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
2456            JDialog JavaDoc dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR");
2457            dialog.setModal(false);
2458            dialog.setVisible(true);
2459        }
2460
2461        /**
2462         * Displays a message in the User Agent interface.
2463         * The given message is typically displayed in a status bar.
2464         */

2465        public void displayMessage(String JavaDoc message) {
2466            statusBar.setMessage(message);
2467        }
2468
2469        /**
2470         * Shows an alert dialog box.
2471         */

2472        public void showAlert(String JavaDoc message) {
2473            svgCanvas.showAlert(message);
2474        }
2475
2476        /**
2477         * Shows a prompt dialog box.
2478         */

2479        public String JavaDoc showPrompt(String JavaDoc message) {
2480            return svgCanvas.showPrompt(message);
2481        }
2482
2483        /**
2484         * Shows a prompt dialog box.
2485         */

2486        public String JavaDoc showPrompt(String JavaDoc message, String JavaDoc defaultValue) {
2487            return svgCanvas.showPrompt(message, defaultValue);
2488        }
2489
2490        /**
2491         * Shows a confirm dialog box.
2492         */

2493        public boolean showConfirm(String JavaDoc message) {
2494            return svgCanvas.showConfirm(message);
2495        }
2496
2497        /**
2498         * Returns the size of a px CSS unit in millimeters.
2499         */

2500        public float getPixelUnitToMillimeter() {
2501            return 0.26458333333333333333333333333333f; // 96dpi
2502
}
2503        
2504        /**
2505         * Returns the size of a px CSS unit in millimeters.
2506         * This will be removed after next release.
2507         * @see #getPixelUnitToMillimeter()
2508         */

2509        public float getPixelToMM() {
2510            return getPixelUnitToMillimeter();
2511            
2512        }
2513
2514        /**
2515         * Returns the default font family.
2516         */

2517        public String JavaDoc getDefaultFontFamily() {
2518            return application.getDefaultFontFamily();
2519        }
2520
2521        /**
2522         * Returns the medium font size.
2523         */

2524        public float getMediumFontSize() {
2525            // 9pt (72pt == 1in)
2526
return 9f * 25.4f / (72f * getPixelUnitToMillimeter());
2527        }
2528
2529        /**
2530         * Returns a lighter font-weight.
2531         */

2532        public float getLighterFontWeight(float f) {
2533            // Round f to nearest 100...
2534
int weight = ((int)((f+50)/100))*100;
2535            switch (weight) {
2536            case 100: return 100;
2537            case 200: return 100;
2538            case 300: return 200;
2539            case 400: return 300;
2540            case 500: return 400;
2541            case 600: return 400;
2542            case 700: return 400;
2543            case 800: return 400;
2544            case 900: return 400;
2545            default:
2546                throw new IllegalArgumentException JavaDoc("Bad Font Weight: " + f);
2547            }
2548        }
2549
2550        /**
2551         * Returns a bolder font-weight.
2552         */

2553        public float getBolderFontWeight(float f) {
2554            // Round f to nearest 100...
2555
int weight = ((int)((f+50)/100))*100;
2556            switch (weight) {
2557            case 100: return 600;
2558            case 200: return 600;
2559            case 300: return 600;
2560            case 400: return 600;
2561            case 500: return 600;
2562            case 600: return 700;
2563            case 700: return 800;
2564            case 800: return 900;
2565            case 900: return 900;
2566            default:
2567                throw new IllegalArgumentException JavaDoc("Bad Font Weight: " + f);
2568            }
2569        }
2570
2571
2572        /**
2573         * Returns the language settings.
2574         */

2575        public String JavaDoc getLanguages() {
2576            return application.getLanguages();
2577        }
2578
2579        /**
2580         * Returns the user stylesheet uri.
2581         * @return null if no user style sheet was specified.
2582         */

2583        public String JavaDoc getUserStyleSheetURI() {
2584            return application.getUserStyleSheetURI();
2585        }
2586
2587        /**
2588         * Returns the class name of the XML parser.
2589         */

2590        public String JavaDoc getXMLParserClassName() {
2591            return application.getXMLParserClassName();
2592        }
2593
2594        /**
2595         * Returns true if the XML parser must be in validation mode, false
2596         * otherwise.
2597         */

2598        public boolean isXMLParserValidating() {
2599            return application.isXMLParserValidating();
2600        }
2601
2602        /**
2603         * Returns this user agent's CSS media.
2604         */

2605        public String JavaDoc getMedia() {
2606            return application.getMedia();
2607        }
2608
2609        /**
2610         * Returns this user agent's alternate style-sheet title.
2611         */

2612        public String JavaDoc getAlternateStyleSheet() {
2613            return alternateStyleSheet;
2614        }
2615
2616        /**
2617         * Opens a link.
2618         * @param uri The document URI.
2619         * @param newc Whether the link should be activated in a new component.
2620         */

2621        public void openLink(String JavaDoc uri, boolean newc) {
2622            if (newc) {
2623                application.openLink(uri);
2624            } else {
2625                showSVGDocument(uri);
2626            }
2627        }
2628
2629        /**
2630         * Tells whether the given extension is supported by this
2631         * user agent.
2632         */

2633        public boolean supportExtension(String JavaDoc s) {
2634            return false;
2635        }
2636
2637        public void handleElement(Element JavaDoc elt, Object JavaDoc data){
2638        }
2639
2640        /**
2641         * Returns the security settings for the given script
2642         * type, script url and document url
2643         *
2644         * @param scriptType type of script, as found in the
2645         * type attribute of the &lt;script&gt; element.
2646         * @param scriptURL url for the script, as defined in
2647         * the script's xlink:href attribute. If that
2648         * attribute was empty, then this parameter should
2649         * be null
2650         * @param docURL url for the document into which the
2651         * script was found.
2652         */

2653        public ScriptSecurity getScriptSecurity(String JavaDoc scriptType,
2654                                                ParsedURL scriptURL,
2655                                                ParsedURL docURL){
2656            if (!application.canLoadScriptType(scriptType)) {
2657                return new NoLoadScriptSecurity(scriptType);
2658            } else {
2659                switch(application.getAllowedScriptOrigin()) {
2660                case ResourceOrigin.ANY:
2661                    return new RelaxedScriptSecurity(scriptType,
2662                                                     scriptURL,
2663                                                     docURL);
2664                case ResourceOrigin.DOCUMENT:
2665                    return new DefaultScriptSecurity(scriptType,
2666                                                     scriptURL,
2667                                                     docURL);
2668                case ResourceOrigin.EMBEDED:
2669                    return new EmbededScriptSecurity(scriptType,
2670                                                     scriptURL,
2671                                                     docURL);
2672                default:
2673                    return new NoLoadScriptSecurity(scriptType);
2674                }
2675            }
2676        }
2677
2678        /**
2679         * This method throws a SecurityException if the script
2680         * of given type, found at url and referenced from docURL
2681         * should not be loaded.
2682         *
2683         * This is a convenience method to call checkLoadScript
2684         * on the ScriptSecurity strategy returned by
2685         * getScriptSecurity.
2686         *
2687         * @param scriptType type of script, as found in the
2688         * type attribute of the &lt;script&gt; element.
2689         * @param scriptURL url for the script, as defined in
2690         * the script's xlink:href attribute. If that
2691         * attribute was empty, then this parameter should
2692         * be null
2693         * @param docURL url for the document into which the
2694         * script was found.
2695         */

2696        public void checkLoadScript(String JavaDoc scriptType,
2697                                    ParsedURL scriptURL,
2698                                    ParsedURL docURL) throws SecurityException JavaDoc {
2699            ScriptSecurity s = getScriptSecurity(scriptType,
2700                                                     scriptURL,
2701                                                     docURL);
2702
2703            if (s != null) {
2704                s.checkLoadScript();
2705            }
2706        }
2707
2708        /**
2709         * Returns the security settings for the given
2710         * resource url and document url
2711         *
2712         * @param resourceURL url for the resource, as defined in
2713         * the resource's xlink:href attribute. If that
2714         * attribute was empty, then this parameter should
2715         * be null
2716         * @param docURL url for the document into which the
2717         * resource was found.
2718         */

2719        public ExternalResourceSecurity
2720            getExternalResourceSecurity(ParsedURL resourceURL,
2721                                        ParsedURL docURL){
2722            switch(application.getAllowedExternalResourceOrigin()) {
2723            case ResourceOrigin.ANY:
2724                return new RelaxedExternalResourceSecurity(resourceURL,
2725                                                           docURL);
2726            case ResourceOrigin.DOCUMENT:
2727                return new DefaultExternalResourceSecurity(resourceURL,
2728                                                           docURL);
2729            case ResourceOrigin.EMBEDED:
2730                return new EmbededExternalResourceSecurity(resourceURL);
2731            default:
2732                return new NoLoadExternalResourceSecurity();
2733            }
2734        }
2735
2736        /**
2737         * This method throws a SecurityException if the resource
2738         * found at url and referenced from docURL
2739         * should not be loaded.
2740         *
2741         * This is a convenience method to call checkLoadExternalResource
2742         * on the ExternalResourceSecurity strategy returned by
2743         * getExternalResourceSecurity.
2744         *
2745         * @param resourceURL url for the script, as defined in
2746         * the resource's xlink:href attribute. If that
2747         * attribute was empty, then this parameter should
2748         * be null
2749         * @param docURL url for the document into which the
2750         * resource was found.
2751         */

2752        public void
2753            checkLoadExternalResource(ParsedURL resourceURL,
2754                                      ParsedURL docURL) throws SecurityException JavaDoc {
2755            ExternalResourceSecurity s
2756                = getExternalResourceSecurity(resourceURL, docURL);
2757            
2758            if (s != null) {
2759                s.checkLoadExternalResource();
2760            }
2761        }
2762    }
2763
2764    /**
2765     * A FileFilter used when exporting the SVG document as an image.
2766     */

2767    protected static class ImageFileFilter extends FileFilter JavaDoc {
2768
2769        /** The extension of the image filename. */
2770        protected String JavaDoc extension;
2771
2772        public ImageFileFilter(String JavaDoc extension) {
2773            this.extension = extension;
2774        }
2775
2776        /**
2777         * Returns true if <tt>f</tt> is a file with the correct extension,
2778         * false otherwise.
2779         */

2780        public boolean accept(File JavaDoc f) {
2781            boolean accept = false;
2782            String JavaDoc fileName = null;
2783            if (f != null) {
2784                if (f.isDirectory()) {
2785                    accept = true;
2786                } else {
2787                    fileName = f.getPath().toLowerCase();
2788                    if (fileName.endsWith(extension)) {
2789                        accept = true;
2790                    }
2791                }
2792            }
2793            return accept;
2794        }
2795
2796        /**
2797         * Returns the file description
2798         */

2799        public String JavaDoc getDescription() {
2800            return extension;
2801        }
2802    }
2803
2804}
2805
Popular Tags