KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2001-2003 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.CardLayout JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.FlowLayout JavaDoc;
25 import java.awt.Frame JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.awt.event.KeyAdapter JavaDoc;
30 import java.awt.event.KeyEvent JavaDoc;
31 import java.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.Map JavaDoc;
34
35 import javax.swing.AbstractButton JavaDoc;
36 import javax.swing.BorderFactory JavaDoc;
37 import javax.swing.ButtonGroup JavaDoc;
38 import javax.swing.ImageIcon JavaDoc;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JCheckBox JavaDoc;
41 import javax.swing.JDialog JavaDoc;
42 import javax.swing.JLabel JavaDoc;
43 import javax.swing.JList JavaDoc;
44 import javax.swing.JPanel JavaDoc;
45 import javax.swing.JRadioButton JavaDoc;
46 import javax.swing.JScrollPane JavaDoc;
47 import javax.swing.JTabbedPane JavaDoc;
48 import javax.swing.JTextField JavaDoc;
49 import javax.swing.ListCellRenderer JavaDoc;
50 import javax.swing.UIManager JavaDoc;
51 import javax.swing.border.Border JavaDoc;
52 import javax.swing.event.ListSelectionEvent JavaDoc;
53 import javax.swing.event.ListSelectionListener JavaDoc;
54
55 import org.apache.batik.ext.swing.GridBagConstants;
56 import org.apache.batik.ext.swing.JGridBagPanel;
57 import org.apache.batik.util.PreferenceManager;
58 import org.apache.batik.util.gui.CSSMediaPanel;
59 import org.apache.batik.util.gui.LanguageDialog;
60 import org.apache.batik.util.gui.UserStyleDialog;
61
62 /**
63  * Dialog that displays user preferences.
64  *
65  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
66  * @version $Id: PreferenceDialog.java,v 1.21 2004/08/18 07:12:27 vhardy Exp $
67  */

68 public class PreferenceDialog extends JDialog JavaDoc
69     implements GridBagConstants {
70
71     /**
72      * The return value if 'OK' is chosen.
73      */

74     public final static int OK_OPTION = 0;
75
76     /**
77      * The return value if 'Cancel' is chosen.
78      */

79     public final static int CANCEL_OPTION = 1;
80
81     //////////////////////////////////////////////////////////////
82
// GUI Resources Keys
83
//////////////////////////////////////////////////////////////
84

85     public static final String JavaDoc ICON_USER_LANGUAGE
86         = "PreferenceDialog.icon.userLanguagePref";
87
88     public static final String JavaDoc ICON_USER_STYLESHEET
89         = "PreferenceDialog.icon.userStylesheetPref";
90
91     public static final String JavaDoc ICON_BEHAVIOR
92         = "PreferenceDialog.icon.behaviorsPref";
93
94     public static final String JavaDoc ICON_NETWORK
95         = "PreferenceDialog.icon.networkPref";
96
97     public static final String JavaDoc LABEL_USER_OPTIONS
98         = "PreferenceDialog.label.user.options";
99
100     public static final String JavaDoc LABEL_BEHAVIOR
101         = "PreferenceDialog.label.behavior";
102
103     public static final String JavaDoc LABEL_NETWORK
104         = "PreferenceDialog.label.network";
105
106     public static final String JavaDoc LABEL_USER_LANGUAGE
107         = "PreferenceDialog.label.user.language";
108
109     public static final String JavaDoc LABEL_USER_STYLESHEET
110         = "PreferenceDialog.label.user.stylesheet";
111
112     public static final String JavaDoc LABEL_USER_FONT
113         = "PreferenceDialog.label.user.font";
114
115     public static final String JavaDoc LABEL_APPLICATIONS
116         = "PreferenceDialog.label.applications";
117
118     public static final String JavaDoc LABEL_SHOW_RENDERING
119         = "PreferenceDialog.label.show.rendering";
120
121     public static final String JavaDoc LABEL_AUTO_ADJUST_WINDOW
122         = "PreferenceDialog.label.auto.adjust.window";
123
124     public static final String JavaDoc LABEL_ENABLE_DOUBLE_BUFFERING
125         = "PreferenceDialog.label.enable.double.buffering";
126
127     public static final String JavaDoc LABEL_SHOW_DEBUG_TRACE
128         = "PreferenceDialog.label.show.debug.trace";
129
130     public static final String JavaDoc LABEL_SELECTION_XOR_MODE
131         = "PreferenceDialog.label.selection.xor.mode";
132
133     public static final String JavaDoc LABEL_IS_XML_PARSER_VALIDATING
134         = "PreferenceDialog.label.is.xml.parser.validating";
135
136     public static final String JavaDoc LABEL_ENFORCE_SECURE_SCRIPTING
137         = "PreferenceDialog.label.enforce.secure.scripting";
138
139     public static final String JavaDoc LABEL_SECURE_SCRIPTING_TOGGLE
140         = "PreferenceDialog.label.secure.scripting.toggle";
141
142     public static final String JavaDoc LABEL_GRANT_SCRIPT_FILE_ACCESS
143         = "PreferenceDialog.label.grant.script.file.access";
144
145     public static final String JavaDoc LABEL_GRANT_SCRIPT_NETWORK_ACCESS
146         = "PreferenceDialog.label.grant.script.network.access";
147
148     public static final String JavaDoc LABEL_LOAD_JAVA
149         = "PreferenceDialog.label.load.java";
150
151     public static final String JavaDoc LABEL_LOAD_ECMASCRIPT
152         = "PreferenceDialog.label.load.ecmascript";
153
154     public static final String JavaDoc LABEL_HOST
155         = "PreferenceDialog.label.host";
156
157     public static final String JavaDoc LABEL_PORT
158         = "PreferenceDialog.label.port";
159
160     public static final String JavaDoc LABEL_OK
161         = "PreferenceDialog.label.ok";
162
163     public static final String JavaDoc LABEL_LOAD_SCRIPTS
164         = "PreferenceDialog.label.load.scripts";
165
166     public static final String JavaDoc LABEL_ORIGIN_ANY
167         = "PreferenceDialog.label.origin.any";
168
169     public static final String JavaDoc LABEL_ORIGIN_DOCUMENT
170         = "PreferenceDialog.label.origin.document";
171
172     public static final String JavaDoc LABEL_ORIGIN_EMBED
173         = "PreferenceDialog.label.origin.embed";
174
175     public static final String JavaDoc LABEL_ORIGIN_NONE
176         = "PreferenceDialog.label.origin.none";
177
178     public static final String JavaDoc LABEL_SCRIPT_ORIGIN
179         = "PreferenceDialog.label.script.origin";
180
181     public static final String JavaDoc LABEL_RESOURCE_ORIGIN
182         = "PreferenceDialog.label.resource.origin";
183
184     public static final String JavaDoc LABEL_CANCEL
185         = "PreferenceDialog.label.cancel";
186
187     public static final String JavaDoc TITLE_BROWSER_OPTIONS
188         = "PreferenceDialog.title.browser.options";
189
190     public static final String JavaDoc TITLE_BEHAVIOR
191         = "PreferenceDialog.title.behavior";
192
193     public static final String JavaDoc TITLE_SECURITY
194         = "PreferenceDialog.title.security";
195
196     public static final String JavaDoc TITLE_NETWORK
197         = "PreferenceDialog.title.network";
198
199     public static final String JavaDoc TITLE_DIALOG
200         = "PreferenceDialog.title.dialog";
201
202     public static final String JavaDoc CONFIG_HOST_TEXT_FIELD_LENGTH
203         = "PreferenceDialog.config.host.text.field.length";
204
205     public static final String JavaDoc CONFIG_PORT_TEXT_FIELD_LENGTH
206         = "PreferenceDialog.config.port.text.field.length";
207
208     public static final String JavaDoc CONFIG_OK_MNEMONIC
209         = "PreferenceDialog.config.ok.mnemonic";
210
211     public static final String JavaDoc CONFIG_CANCEL_MNEMONIC
212         = "PreferenceDialog.config.cancel.mnemonic";
213
214     //////////////////////////////////////////////////////////////
215
// Following are the preference keys used in the
216
// PreferenceManager model.
217
//////////////////////////////////////////////////////////////
218

219     public static final String JavaDoc PREFERENCE_KEY_LANGUAGES
220         = "preference.key.languages";
221
222     public static final String JavaDoc PREFERENCE_KEY_IS_XML_PARSER_VALIDATING
223         = "preference.key.is.xml.parser.validating";
224
225     public static final String JavaDoc PREFERENCE_KEY_USER_STYLESHEET
226         = "preference.key.user.stylesheet";
227
228     public static final String JavaDoc PREFERENCE_KEY_SHOW_RENDERING
229         = "preference.key.show.rendering";
230
231     public static final String JavaDoc PREFERENCE_KEY_AUTO_ADJUST_WINDOW
232         = "preference.key.auto.adjust.window";
233
234     public static final String JavaDoc PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING
235         = "preference.key.enable.double.buffering";
236
237     public static final String JavaDoc PREFERENCE_KEY_SHOW_DEBUG_TRACE
238         = "preference.key.show.debug.trace";
239
240     public static final String JavaDoc PREFERENCE_KEY_SELECTION_XOR_MODE
241         = "preference.key.selection.xor.mode";
242
243     public static final String JavaDoc PREFERENCE_KEY_PROXY_HOST
244         = "preference.key.proxy.host";
245
246     public static final String JavaDoc PREFERENCE_KEY_CSS_MEDIA
247         = "preference.key.cssmedia";
248
249     public static final String JavaDoc PREFERENCE_KEY_DEFAULT_FONT_FAMILY
250         = "preference.key.default.font.family";
251
252     public static final String JavaDoc PREFERENCE_KEY_PROXY_PORT
253         = "preference.key.proxy.port";
254
255     public static final String JavaDoc PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING
256         = "preference.key.enforce.secure.scripting";
257
258     public static final String JavaDoc PREFERENCE_KEY_GRANT_SCRIPT_FILE_ACCESS
259         = "preference.key.grant.script.file.access";
260
261     public static final String JavaDoc PREFERENCE_KEY_GRANT_SCRIPT_NETWORK_ACCESS
262         = "preferenced.key.grant.script.network.access";
263
264     public static final String JavaDoc PREFERENCE_KEY_LOAD_ECMASCRIPT
265         = "preference.key.load.ecmascript";
266
267     public static final String JavaDoc PREFERENCE_KEY_LOAD_JAVA
268         = "preference.key.load.java.script";
269
270     public static final String JavaDoc PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN
271         = "preference.key.allowed.script.origin";
272
273     public static final String JavaDoc PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN
274         = "preference.key.allowed.external.resource.origin";
275
276     /**
277      * <tt>PreferenceManager</tt> used to store and retrieve
278      * preferences
279      */

280     protected PreferenceManager model;
281
282     /**
283      * Allows selection of the desired configuration panel
284      */

285     protected ConfigurationPanelSelector configPanelSelector;
286
287     /**
288      * Allows selection of the user languages
289      */

290     protected LanguageDialog.Panel languagePanel;
291
292     /**
293      * Allows selection of a user stylesheet
294      */

295     protected UserStyleDialog.Panel userStylesheetPanel;
296
297     protected JCheckBox JavaDoc showRendering;
298
299     protected JCheckBox JavaDoc autoAdjustWindow;
300
301     protected JCheckBox JavaDoc showDebugTrace;
302
303     protected JCheckBox JavaDoc enableDoubleBuffering;
304
305     protected JCheckBox JavaDoc selectionXorMode;
306
307     protected JCheckBox JavaDoc isXMLParserValidating;
308
309     protected JCheckBox JavaDoc enforceSecureScripting;
310
311     protected JCheckBox JavaDoc grantScriptFileAccess;
312
313     protected JCheckBox JavaDoc grantScriptNetworkAccess;
314
315     protected JCheckBox JavaDoc loadJava;
316
317     protected JCheckBox JavaDoc loadEcmascript;
318
319     protected ButtonGroup JavaDoc scriptOriginGroup;
320
321     protected ButtonGroup JavaDoc resourceOriginGroup;
322
323     protected JTextField JavaDoc host, port;
324
325     protected CSSMediaPanel cssMediaPanel;
326
327     /**
328      * Code indicating whether the dialog was OKayed
329      * or cancelled
330      */

331     protected int returnCode;
332
333     /**
334      * Default constructor
335      */

336     public PreferenceDialog(PreferenceManager model){
337         super((Frame JavaDoc)null, true);
338
339         if(model == null){
340             throw new IllegalArgumentException JavaDoc();
341         }
342
343         this.model = model;
344         buildGUI();
345         initializeGUI();
346         pack();
347     }
348
349     /**
350      * Returns the preference manager used by this dialog.
351      */

352     public PreferenceManager getPreferenceManager() {
353         return model;
354     }
355
356     /**
357      * Initializes the GUI components with the values
358      * from the model.
359      */

360     protected void initializeGUI(){
361         //
362
// Initialize language. The set of languages is
363
// defined by a String.
364
//
365
String JavaDoc languages = model.getString(PREFERENCE_KEY_LANGUAGES);
366         languagePanel.setLanguages(languages);
367
368         //
369
// Initializes the User Stylesheet
370
//
371
String JavaDoc userStylesheetPath = model.getString(PREFERENCE_KEY_USER_STYLESHEET);
372         userStylesheetPanel.setPath(userStylesheetPath);
373
374         //
375
// Initializes the browser options
376
//
377
showRendering.setSelected(model.getBoolean(PREFERENCE_KEY_SHOW_RENDERING));
378         autoAdjustWindow.setSelected(model.getBoolean(PREFERENCE_KEY_AUTO_ADJUST_WINDOW));
379         enableDoubleBuffering.setSelected(model.getBoolean(PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING));
380         showDebugTrace.setSelected(model.getBoolean(PREFERENCE_KEY_SHOW_DEBUG_TRACE));
381         selectionXorMode.setSelected(model.getBoolean(PREFERENCE_KEY_SELECTION_XOR_MODE));
382
383         isXMLParserValidating.setSelected(model.getBoolean(PREFERENCE_KEY_IS_XML_PARSER_VALIDATING));
384         enforceSecureScripting.setSelected(model.getBoolean(PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING));
385         grantScriptFileAccess.setSelected(model.getBoolean(PREFERENCE_KEY_GRANT_SCRIPT_FILE_ACCESS));
386         grantScriptNetworkAccess.setSelected(model.getBoolean(PREFERENCE_KEY_GRANT_SCRIPT_NETWORK_ACCESS));
387         loadJava.setSelected(model.getBoolean(PREFERENCE_KEY_LOAD_JAVA));
388         loadEcmascript.setSelected(model.getBoolean(PREFERENCE_KEY_LOAD_ECMASCRIPT));
389
390         String JavaDoc allowedScriptOrigin = "" + model.getInteger(PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN);
391         if (allowedScriptOrigin == null || "".equals(allowedScriptOrigin)) {
392             allowedScriptOrigin = "" + ResourceOrigin.NONE;
393         }
394
395         Enumeration JavaDoc e = scriptOriginGroup.getElements();
396         while (e.hasMoreElements()) {
397             AbstractButton JavaDoc ab = (AbstractButton JavaDoc)e.nextElement();
398             String JavaDoc ac = ab.getActionCommand();
399             if (allowedScriptOrigin.equals(ac)) {
400                 ab.setSelected(true);
401             }
402         }
403
404         String JavaDoc allowedResourceOrigin = "" + model.getInteger(PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN);
405         if (allowedResourceOrigin == null || "".equals(allowedResourceOrigin)) {
406             allowedResourceOrigin = "" + ResourceOrigin.NONE;
407         }
408
409         e = resourceOriginGroup.getElements();
410         while (e.hasMoreElements()) {
411             AbstractButton JavaDoc ab = (AbstractButton JavaDoc)e.nextElement();
412             String JavaDoc ac = ab.getActionCommand();
413             if (allowedResourceOrigin.equals(ac)) {
414                 ab.setSelected(true);
415             }
416         }
417
418         showRendering.setEnabled
419             (!model.getBoolean(PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING));
420         grantScriptFileAccess.setEnabled
421             (model.getBoolean(PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING));
422         grantScriptNetworkAccess.setEnabled
423             (model.getBoolean(PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING));
424
425         //
426
// Initialize the proxy options
427
//
428
host.setText(model.getString(PREFERENCE_KEY_PROXY_HOST));
429         port.setText(model.getString(PREFERENCE_KEY_PROXY_PORT));
430
431         //
432
// Initialize the CSS media
433
//
434
cssMediaPanel.setMedia(model.getString(PREFERENCE_KEY_CSS_MEDIA));
435         //
436
// Sets the dialog's title
437
//
438
setTitle(Resources.getString(TITLE_DIALOG));
439     }
440
441     /**
442      * Stores current setting in PreferenceManager model
443      */

444     protected void savePreferences(){
445         model.setString(PREFERENCE_KEY_LANGUAGES,
446                         languagePanel.getLanguages());
447         model.setString(PREFERENCE_KEY_USER_STYLESHEET,
448                         userStylesheetPanel.getPath());
449         model.setBoolean(PREFERENCE_KEY_SHOW_RENDERING,
450                          showRendering.isSelected());
451         model.setBoolean(PREFERENCE_KEY_AUTO_ADJUST_WINDOW,
452                          autoAdjustWindow.isSelected());
453         model.setBoolean(PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING,
454                          enableDoubleBuffering.isSelected());
455         model.setBoolean(PREFERENCE_KEY_SHOW_DEBUG_TRACE,
456                          showDebugTrace.isSelected());
457         model.setBoolean(PREFERENCE_KEY_SELECTION_XOR_MODE,
458                          selectionXorMode.isSelected());
459         model.setBoolean(PREFERENCE_KEY_IS_XML_PARSER_VALIDATING,
460                          isXMLParserValidating.isSelected());
461         model.setBoolean(PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING,
462                          enforceSecureScripting.isSelected());
463         model.setBoolean(PREFERENCE_KEY_GRANT_SCRIPT_FILE_ACCESS,
464                          grantScriptFileAccess.isSelected());
465         model.setBoolean(PREFERENCE_KEY_GRANT_SCRIPT_NETWORK_ACCESS,
466                          grantScriptNetworkAccess.isSelected());
467         model.setBoolean(PREFERENCE_KEY_LOAD_JAVA,
468                          loadJava.isSelected());
469         model.setBoolean(PREFERENCE_KEY_LOAD_ECMASCRIPT,
470                          loadEcmascript.isSelected());
471         model.setInteger(PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN,
472                          (new Integer JavaDoc(scriptOriginGroup.getSelection().getActionCommand())).intValue());
473         model.setInteger(PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN,
474                          (new Integer JavaDoc(resourceOriginGroup.getSelection().getActionCommand())).intValue());
475         model.setString(PREFERENCE_KEY_PROXY_HOST,
476                         host.getText());
477         model.setString(PREFERENCE_KEY_PROXY_PORT,
478                         port.getText());
479         model.setString(PREFERENCE_KEY_CSS_MEDIA,
480                         cssMediaPanel.getMediaAsString());
481     }
482
483     /**
484      * Builds the UI for this dialog
485      */

486     protected void buildGUI(){
487         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc());
488
489         Component JavaDoc config = buildConfigPanel();
490         Component JavaDoc list = buildConfigPanelList();
491
492         panel.add(list, BorderLayout.WEST);
493         panel.add(config, BorderLayout.CENTER);
494         panel.add(buildButtonsPanel(), BorderLayout.SOUTH);
495         panel.setBorder(BorderFactory.createEmptyBorder(2, 2, 0, 0));
496
497         getContentPane().add(panel);
498     }
499
500     /**
501      * Creates the OK/Cancel buttons panel
502      */

503     protected JPanel JavaDoc buildButtonsPanel() {
504         JPanel JavaDoc p = new JPanel JavaDoc(new FlowLayout JavaDoc(FlowLayout.RIGHT));
505         JButton JavaDoc okButton = new JButton JavaDoc(Resources.getString(LABEL_OK));
506         okButton.setMnemonic(Resources.getCharacter(CONFIG_OK_MNEMONIC));
507         JButton JavaDoc cancelButton = new JButton JavaDoc(Resources.getString(LABEL_CANCEL));
508         cancelButton.setMnemonic(Resources.getCharacter(CONFIG_CANCEL_MNEMONIC));
509         p.add(okButton);
510         p.add(cancelButton);
511
512         okButton.addActionListener(new ActionListener JavaDoc(){
513                 public void actionPerformed(ActionEvent JavaDoc e){
514                     setVisible(false);
515                     returnCode = OK_OPTION;
516                     savePreferences();
517                     dispose();
518                 }
519             });
520
521         cancelButton.addActionListener(new ActionListener JavaDoc(){
522                 public void actionPerformed(ActionEvent JavaDoc e){
523                     setVisible(false);
524                     returnCode = CANCEL_OPTION;
525                     dispose();
526                 }
527             });
528
529         addKeyListener(new KeyAdapter JavaDoc(){
530                 public void keyPressed(KeyEvent JavaDoc e){
531                     if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
532                         setVisible(false);
533                         returnCode = CANCEL_OPTION;
534                         dispose();
535                     }
536                 }
537             });
538
539         return p;
540     }
541
542     protected Component JavaDoc buildConfigPanelList(){
543         String JavaDoc[] configList
544             = { Resources.getString(LABEL_NETWORK),
545                 Resources.getString(LABEL_USER_LANGUAGE),
546                 Resources.getString(LABEL_BEHAVIOR),
547                 Resources.getString(LABEL_USER_STYLESHEET),
548                 };
549
550         final JList JavaDoc list = new JList JavaDoc(configList);
551         list.addListSelectionListener(new ListSelectionListener JavaDoc(){
552                 public void valueChanged(ListSelectionEvent JavaDoc evt){
553                     if(!evt.getValueIsAdjusting()){
554                         configPanelSelector.select(list.getSelectedValue().toString());
555                     }
556                 }
557             });
558         list.setVisibleRowCount(4);
559
560         // Set Cell Renderer
561
ClassLoader JavaDoc cl = this.getClass().getClassLoader();
562         Map JavaDoc map= new Hashtable JavaDoc();
563         map.put(Resources.getString(LABEL_USER_LANGUAGE), new ImageIcon JavaDoc(cl.getResource(Resources.getString(ICON_USER_LANGUAGE))));
564         map.put(Resources.getString(LABEL_USER_STYLESHEET), new ImageIcon JavaDoc(cl.getResource(Resources.getString(ICON_USER_STYLESHEET))));
565         map.put(Resources.getString(LABEL_BEHAVIOR), new ImageIcon JavaDoc(cl.getResource(Resources.getString(ICON_BEHAVIOR))));
566         map.put(Resources.getString(LABEL_NETWORK), new ImageIcon JavaDoc(cl.getResource(Resources.getString(ICON_NETWORK))));
567
568         list.setCellRenderer(new IconCellRenderer(map));
569
570         list.setSelectedIndex(0);
571
572         return new JScrollPane JavaDoc(list);
573     }
574
575     protected Component JavaDoc buildConfigPanel(){
576         JPanel JavaDoc configPanel = new JPanel JavaDoc();
577         CardLayout JavaDoc cardLayout = new CardLayout JavaDoc();
578         configPanel.setLayout(cardLayout);
579         configPanel.add(buildUserLanguage(),
580                         Resources.getString(LABEL_USER_LANGUAGE));
581
582         configPanel.add(buildUserStyleSheet(),
583                         Resources.getString(LABEL_USER_STYLESHEET));
584
585         configPanel.add(buildBehavior(),
586                         Resources.getString(LABEL_BEHAVIOR));
587
588         configPanel.add(buildNetwork(),
589                         Resources.getString(LABEL_NETWORK));
590
591         configPanel.add(buildApplications(),
592                         Resources.getString(LABEL_APPLICATIONS));
593
594         configPanelSelector = new ConfigurationPanelSelector(configPanel,
595                                                              cardLayout);
596
597         return configPanel;
598     }
599
600     protected Component JavaDoc buildUserOptions(){
601         JTabbedPane JavaDoc p = new JTabbedPane JavaDoc();
602         p.add(buildUserLanguage(),
603               Resources.getString(LABEL_USER_LANGUAGE));
604         p.add(buildUserStyleSheet(),
605               Resources.getString(LABEL_USER_STYLESHEET));
606         p.add(buildUserFont(),
607               Resources.getString(LABEL_USER_FONT));
608         return p;
609     }
610
611     protected Component JavaDoc buildUserLanguage(){
612         languagePanel = new LanguageDialog.Panel();
613         return languagePanel;
614     }
615
616     protected Component JavaDoc buildUserStyleSheet(){
617         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc());
618         panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
619
620         userStylesheetPanel = new UserStyleDialog.Panel();
621         panel.add(userStylesheetPanel, BorderLayout.NORTH);
622
623         cssMediaPanel = new CSSMediaPanel();
624         panel.add(cssMediaPanel, BorderLayout.SOUTH);
625
626         return panel;
627     }
628
629     protected Component JavaDoc buildUserFont(){
630         return new JButton JavaDoc("User Font");
631     }
632
633     protected Component JavaDoc buildBehavior(){
634         JGridBagPanel p = new JGridBagPanel();
635         showRendering
636             = new JCheckBox JavaDoc(Resources.getString(LABEL_SHOW_RENDERING));
637         autoAdjustWindow
638             = new JCheckBox JavaDoc(Resources.getString(LABEL_AUTO_ADJUST_WINDOW));
639         enableDoubleBuffering
640             = new JCheckBox JavaDoc(Resources.getString(LABEL_ENABLE_DOUBLE_BUFFERING));
641         enableDoubleBuffering.addActionListener(new ActionListener JavaDoc() {
642             public void actionPerformed(ActionEvent JavaDoc evt) {
643                 showRendering.setEnabled(!enableDoubleBuffering.isSelected());
644             }
645         });
646         showDebugTrace
647             = new JCheckBox JavaDoc(Resources.getString(LABEL_SHOW_DEBUG_TRACE));
648
649         selectionXorMode
650             = new JCheckBox JavaDoc(Resources.getString(LABEL_SELECTION_XOR_MODE));
651
652         isXMLParserValidating
653             = new JCheckBox JavaDoc(Resources.getString(LABEL_IS_XML_PARSER_VALIDATING));
654
655         enforceSecureScripting
656             = new JCheckBox JavaDoc(Resources.getString(LABEL_SECURE_SCRIPTING_TOGGLE));
657
658         grantScriptFileAccess
659             = new JCheckBox JavaDoc(Resources.getString(LABEL_GRANT_SCRIPT_FILE_ACCESS));
660         
661         grantScriptNetworkAccess
662             = new JCheckBox JavaDoc(Resources.getString(LABEL_GRANT_SCRIPT_NETWORK_ACCESS));
663
664         JGridBagPanel scriptSecurityPanel = new JGridBagPanel();
665         scriptSecurityPanel.add(enforceSecureScripting, 0, 0, 1, 1, WEST, HORIZONTAL, 1, 0);
666         scriptSecurityPanel.add(grantScriptFileAccess, 1, 0, 1, 1, WEST, HORIZONTAL, 1, 0);
667         scriptSecurityPanel.add(grantScriptNetworkAccess, 1, 1, 1, 1, WEST, HORIZONTAL, 1, 0);
668         
669         enforceSecureScripting.addActionListener(new ActionListener JavaDoc() {
670                 public void actionPerformed(ActionEvent JavaDoc e) {
671                     grantScriptFileAccess.setEnabled(enforceSecureScripting.isSelected());
672                     grantScriptNetworkAccess.setEnabled(enforceSecureScripting.isSelected());
673                 }
674             });
675
676         loadJava
677             = new JCheckBox JavaDoc(Resources.getString(LABEL_LOAD_JAVA));
678
679         loadEcmascript
680             = new JCheckBox JavaDoc(Resources.getString(LABEL_LOAD_ECMASCRIPT));
681
682         JGridBagPanel loadScriptPanel = new JGridBagPanel();
683         loadScriptPanel.add(loadJava, 0, 0, 1, 1, WEST, NONE, 1, 0);
684         loadScriptPanel.add(loadEcmascript, 1, 0, 1, 1, WEST, NONE, 1, 0);
685
686         JPanel JavaDoc scriptOriginPanel = new JPanel JavaDoc();
687
688         scriptOriginGroup = new ButtonGroup JavaDoc();
689         JRadioButton JavaDoc rb = null;
690
691         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_ANY));
692         rb.setActionCommand("" + ResourceOrigin.ANY);
693         scriptOriginGroup.add(rb);
694         scriptOriginPanel.add(rb);
695
696         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_DOCUMENT));
697         rb.setActionCommand("" + ResourceOrigin.DOCUMENT);
698         scriptOriginGroup.add(rb);
699         scriptOriginPanel.add(rb);
700
701         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_EMBED));
702         rb.setActionCommand("" + ResourceOrigin.EMBEDED);
703         scriptOriginGroup.add(rb);
704         scriptOriginPanel.add(rb);
705
706         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_NONE));
707         rb.setActionCommand("" + ResourceOrigin.NONE);
708         scriptOriginGroup.add(rb);
709         scriptOriginPanel.add(rb);
710
711         JPanel JavaDoc resourceOriginPanel = new JPanel JavaDoc();
712         resourceOriginGroup = new ButtonGroup JavaDoc();
713
714         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_ANY));
715         rb.setActionCommand("" + ResourceOrigin.ANY);
716         resourceOriginGroup.add(rb);
717         resourceOriginPanel.add(rb);
718
719         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_DOCUMENT));
720         rb.setActionCommand("" + ResourceOrigin.DOCUMENT);
721         resourceOriginGroup.add(rb);
722         resourceOriginPanel.add(rb);
723
724         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_EMBED));
725         rb.setActionCommand("" + ResourceOrigin.EMBEDED);
726         resourceOriginGroup.add(rb);
727         resourceOriginPanel.add(rb);
728
729         rb = new JRadioButton JavaDoc(Resources.getString(LABEL_ORIGIN_NONE));
730         rb.setActionCommand("" + ResourceOrigin.NONE);
731         resourceOriginGroup.add(rb);
732         resourceOriginPanel.add(rb);
733
734         JTabbedPane JavaDoc browserOptions = new JTabbedPane JavaDoc();
735         // browserOptions.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
736

737         p.add(showRendering, 0, 0, 2, 1, WEST, HORIZONTAL, 1, 0);
738         p.add(autoAdjustWindow, 0, 1, 2, 1, WEST, HORIZONTAL, 1, 0);
739         p.add(enableDoubleBuffering, 0, 2, 2, 1, WEST, HORIZONTAL, 1, 0);
740         p.add(showDebugTrace, 0, 3, 2, 1, WEST, HORIZONTAL, 1, 0);
741         p.add(selectionXorMode, 0, 4, 2, 1, WEST, HORIZONTAL, 1, 0);
742         p.add(isXMLParserValidating, 0, 5, 2, 1, WEST, HORIZONTAL, 1, 0);
743         p.add(new JLabel JavaDoc(), 0, 11, 2, 1, WEST, BOTH, 1, 1);
744
745         browserOptions.addTab(Resources.getString(TITLE_BEHAVIOR), p);
746         p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
747
748         p = new JGridBagPanel();
749         p.add(new JLabel JavaDoc(Resources.getString(LABEL_ENFORCE_SECURE_SCRIPTING)), 0, 6, 1, 1, NORTHWEST, NONE, 0, 0);
750         p.add(scriptSecurityPanel, 1, 6, 1, 1, WEST, NONE, 0, 0);
751         p.add(new JLabel JavaDoc(Resources.getString(LABEL_LOAD_SCRIPTS)), 0, 8, 1, 1, WEST, NONE, 0, 0);
752         p.add(loadScriptPanel, 1, 8, 1, 1, WEST, NONE, 1, 0);
753         p.add(new JLabel JavaDoc(Resources.getString(LABEL_SCRIPT_ORIGIN)), 0, 9, 1, 1, WEST, NONE, 0, 0);
754         p.add(scriptOriginPanel, 1, 9, 1, 1, WEST, NONE, 1, 0);
755         p.add(new JLabel JavaDoc(Resources.getString(LABEL_RESOURCE_ORIGIN)), 0, 10, 1, 1, WEST, NONE, 0, 0);
756         p.add(resourceOriginPanel, 1, 10, 1, 1, WEST, NONE, 1, 0);
757         p.add(new JLabel JavaDoc(), 0, 11, 2, 1, WEST, BOTH, 1, 1);
758
759         browserOptions.addTab(Resources.getString(TITLE_SECURITY), p);
760         p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
761
762         JGridBagPanel borderedPanel = new JGridBagPanel();
763         borderedPanel.add(browserOptions, 0, 0, 1, 1, WEST, BOTH, 1, 1);
764         borderedPanel.setBorder(BorderFactory.createCompoundBorder
765                                 (BorderFactory.createTitledBorder
766                                  (BorderFactory.createEtchedBorder(),
767                                   Resources.getString(TITLE_BROWSER_OPTIONS)),
768                                  BorderFactory.createEmptyBorder(10, 10, 10, 10)));
769         
770         return borderedPanel;
771     }
772
773     protected Component JavaDoc buildNetwork(){
774         JGridBagPanel p = new JGridBagPanel();
775         host = new JTextField JavaDoc(Resources.getInteger(CONFIG_HOST_TEXT_FIELD_LENGTH));
776         JLabel JavaDoc hostLabel = new JLabel JavaDoc(Resources.getString(LABEL_HOST));
777         port = new JTextField JavaDoc(Resources.getInteger(CONFIG_PORT_TEXT_FIELD_LENGTH));
778         JLabel JavaDoc portLabel = new JLabel JavaDoc(Resources.getString(LABEL_PORT));
779         p.add(hostLabel, 0, 0, 1, 1, WEST, HORIZONTAL, 0, 0);
780         p.add(host, 0, 1, 1, 1, CENTER, HORIZONTAL, 1, 0);
781         p.add(portLabel, 1, 0, 1, 1, WEST, HORIZONTAL, 0, 0);
782         p.add(port, 1, 1, 1, 1, CENTER, HORIZONTAL, 0, 0);
783         p.add(new JLabel JavaDoc(""), 2, 1, 1, 1, CENTER, HORIZONTAL, 0, 0);
784
785         p.setBorder(BorderFactory.createCompoundBorder
786                     (BorderFactory.createTitledBorder
787                      (BorderFactory.createEtchedBorder(),
788                      Resources.getString(TITLE_NETWORK)),
789                      BorderFactory.createEmptyBorder(10, 10, 10, 10)));
790
791         return p;
792     }
793
794     protected Component JavaDoc buildApplications(){
795         return new JButton JavaDoc("Applications");
796     }
797
798     /**
799      * Shows the dialog
800      * @return OK_OPTION or CANCEL_OPTION
801      */

802     public int showDialog(){
803         pack();
804         show();
805         return returnCode;
806     }
807
808     public static void main(String JavaDoc[] args){
809         Map JavaDoc defaults = new Hashtable JavaDoc();
810         defaults.put(PREFERENCE_KEY_LANGUAGES, "fr");
811         defaults.put(PREFERENCE_KEY_SHOW_RENDERING, Boolean.TRUE);
812         defaults.put(PREFERENCE_KEY_SELECTION_XOR_MODE, Boolean.FALSE);
813         defaults.put(PREFERENCE_KEY_IS_XML_PARSER_VALIDATING, Boolean.FALSE);
814         defaults.put(PREFERENCE_KEY_AUTO_ADJUST_WINDOW, Boolean.TRUE);
815         defaults.put(PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING, Boolean.TRUE);
816         defaults.put(PREFERENCE_KEY_SHOW_DEBUG_TRACE, Boolean.TRUE);
817         defaults.put(PREFERENCE_KEY_PROXY_HOST, "webcache.eng.sun.com");
818         defaults.put(PREFERENCE_KEY_PROXY_PORT, "8080");
819
820         XMLPreferenceManager manager
821             = new XMLPreferenceManager(args[0], defaults);
822         PreferenceDialog dlg = new PreferenceDialog(manager);
823         int c = dlg.showDialog();
824         if(c == OK_OPTION){
825             try{
826                 manager.save();
827                 System.out.println("Done Saving options");
828                 System.exit(0);
829             }catch(Exception JavaDoc e){
830                 System.err.println("Could not save options");
831                 e.printStackTrace();
832             }
833         }
834     }
835 }
836
837
838 class ConfigurationPanelSelector {
839     private CardLayout JavaDoc layout;
840     private Container JavaDoc container;
841
842     public ConfigurationPanelSelector(Container JavaDoc container,
843                                       CardLayout JavaDoc layout){
844         this.layout = layout;
845         this.container = container;
846     }
847
848     public void select(String JavaDoc panelName){
849         layout.show(container, panelName);
850     }
851 }
852
853 class IconCellRendererOld extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
854     Map JavaDoc iconMap;
855
856     public IconCellRendererOld(Map JavaDoc iconMap){
857         this.iconMap = iconMap;
858
859         setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
860     }
861     public Component JavaDoc getListCellRendererComponent
862         (
863          JList JavaDoc list,
864          Object JavaDoc value, // value to display
865
int index, // cell index
866
boolean isSelected, // is the cell selected
867
boolean cellHasFocus) // the list and the cell have the focus
868
{
869         String JavaDoc s = value.toString();
870         setText(s);
871         ImageIcon JavaDoc icon = (ImageIcon JavaDoc)iconMap.get(s);
872         if(icon != null){
873             setIcon(icon);
874             setHorizontalAlignment(CENTER);
875             setHorizontalTextPosition(CENTER);
876             setVerticalTextPosition(BOTTOM);
877         }
878         // if (isSelected) {
879
setBackground(java.awt.Color.red); // list.getSelectionBackground());
880
setForeground(list.getSelectionForeground());
881             /*}
882         else {
883             setBackground(list.getBackground());
884             setForeground(list.getForeground());
885             }*/

886             // setEnabled(list.isEnabled());
887
// setFont(list.getFont());
888
return this;
889     }
890 }
891
892 class IconCellRenderer extends JLabel JavaDoc
893     implements ListCellRenderer JavaDoc
894 {
895     protected Map JavaDoc map;
896     protected static Border JavaDoc noFocusBorder;
897
898     /**
899      * Constructs a default renderer object for an item
900      * in a list.
901      */

902     public IconCellRenderer(Map JavaDoc map) {
903         super();
904     this.map = map;
905         noFocusBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1);
906         setOpaque(true);
907         setBorder(noFocusBorder);
908     }
909
910
911     public Component JavaDoc getListCellRendererComponent(
912         JList JavaDoc list,
913         Object JavaDoc value,
914         int index,
915         boolean isSelected,
916         boolean cellHasFocus)
917     {
918
919         setComponentOrientation(list.getComponentOrientation());
920
921         if (isSelected) {
922             setBackground(list.getSelectionBackground());
923             setForeground(list.getSelectionForeground());
924         }
925         else {
926             setBackground(list.getBackground());
927             setForeground(list.getForeground());
928         }
929
930         setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
931
932         /*if (value instanceof Icon) {
933             setIcon((Icon)value);
934             setText("");
935         }
936         else {
937             setIcon(null);
938             setText((value == null) ? "" : value.toString());
939         }*/

940
941     setText(value.toString());
942         ImageIcon JavaDoc icon = (ImageIcon JavaDoc)map.get(value.toString());
943         if(icon != null){
944             setIcon(icon);
945             setHorizontalAlignment(CENTER);
946             setHorizontalTextPosition(CENTER);
947             setVerticalTextPosition(BOTTOM);
948         }
949         setEnabled(list.isEnabled());
950         setFont(list.getFont());
951
952         return this;
953     }
954
955
956    /**
957     * Overridden for performance reasons.
958     * See the <a HREF="#override">Implementation Note</a>
959     * for more information.
960     */

961     public void validate() {}
962
963    /**
964     * Overridden for performance reasons.
965     * See the <a HREF="#override">Implementation Note</a>
966     * for more information.
967     */

968     public void revalidate() {}
969    /**
970     * Overridden for performance reasons.
971     * See the <a HREF="#override">Implementation Note</a>
972     * for more information.
973     */

974     public void repaint(long tm, int x, int y, int width, int height) {}
975
976    /**
977     * Overridden for performance reasons.
978     * See the <a HREF="#override">Implementation Note</a>
979     * for more information.
980     */

981     public void repaint(Rectangle JavaDoc r) {}
982
983    /**
984     * Overridden for performance reasons.
985     * See the <a HREF="#override">Implementation Note</a>
986     * for more information.
987     */

988     protected void firePropertyChange(String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
989         // Strings get interned...
990
if (propertyName=="text")
991             super.firePropertyChange(propertyName, oldValue, newValue);
992     }
993
994    /**
995     * Overridden for performance reasons.
996     * See the <a HREF="#override">Implementation Note</a>
997     * for more information.
998     */

999     public void firePropertyChange(String JavaDoc propertyName, byte oldValue, byte newValue) {}
1000
1001   /**
1002    * Overridden for performance reasons.
1003    * See the <a HREF="#override">Implementation Note</a>
1004    * for more information.
1005    */

1006    public void firePropertyChange(String JavaDoc propertyName, char oldValue, char newValue) {}
1007
1008   /**
1009    * Overridden for performance reasons.
1010    * See the <a HREF="#override">Implementation Note</a>
1011    * for more information.
1012    */

1013    public void firePropertyChange(String JavaDoc propertyName, short oldValue, short newValue) {}
1014
1015   /**
1016    * Overridden for performance reasons.
1017    * See the <a HREF="#override">Implementation Note</a>
1018    * for more information.
1019    */

1020    public void firePropertyChange(String JavaDoc propertyName, int oldValue, int newValue) {}
1021
1022   /**
1023    * Overridden for performance reasons.
1024    * See the <a HREF="#override">Implementation Note</a>
1025    * for more information.
1026    */

1027    public void firePropertyChange(String JavaDoc propertyName, long oldValue, long newValue) {}
1028
1029   /**
1030    * Overridden for performance reasons.
1031    * See the <a HREF="#override">Implementation Note</a>
1032    * for more information.
1033    */

1034    public void firePropertyChange(String JavaDoc propertyName, float oldValue, float newValue) {}
1035
1036   /**
1037    * Overridden for performance reasons.
1038    * See the <a HREF="#override">Implementation Note</a>
1039    * for more information.
1040    */

1041    public void firePropertyChange(String JavaDoc propertyName, double oldValue, double newValue) {}
1042
1043   /**
1044    * Overridden for performance reasons.
1045    * See the <a HREF="#override">Implementation Note</a>
1046    * for more information.
1047    */

1048    public void firePropertyChange(String JavaDoc propertyName, boolean oldValue, boolean newValue) {}
1049}
1050
Popular Tags