1 18 package org.apache.batik.apps.svgbrowser; 19 20 import java.awt.BorderLayout ; 21 import java.awt.CardLayout ; 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.FlowLayout ; 25 import java.awt.Frame ; 26 import java.awt.Rectangle ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.awt.event.KeyAdapter ; 30 import java.awt.event.KeyEvent ; 31 import java.util.Enumeration ; 32 import java.util.Hashtable ; 33 import java.util.Map ; 34 35 import javax.swing.AbstractButton ; 36 import javax.swing.BorderFactory ; 37 import javax.swing.ButtonGroup ; 38 import javax.swing.ImageIcon ; 39 import javax.swing.JButton ; 40 import javax.swing.JCheckBox ; 41 import javax.swing.JDialog ; 42 import javax.swing.JLabel ; 43 import javax.swing.JList ; 44 import javax.swing.JPanel ; 45 import javax.swing.JRadioButton ; 46 import javax.swing.JScrollPane ; 47 import javax.swing.JTabbedPane ; 48 import javax.swing.JTextField ; 49 import javax.swing.ListCellRenderer ; 50 import javax.swing.UIManager ; 51 import javax.swing.border.Border ; 52 import javax.swing.event.ListSelectionEvent ; 53 import javax.swing.event.ListSelectionListener ; 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 68 public class PreferenceDialog extends JDialog 69 implements GridBagConstants { 70 71 74 public final static int OK_OPTION = 0; 75 76 79 public final static int CANCEL_OPTION = 1; 80 81 85 public static final String ICON_USER_LANGUAGE 86 = "PreferenceDialog.icon.userLanguagePref"; 87 88 public static final String ICON_USER_STYLESHEET 89 = "PreferenceDialog.icon.userStylesheetPref"; 90 91 public static final String ICON_BEHAVIOR 92 = "PreferenceDialog.icon.behaviorsPref"; 93 94 public static final String ICON_NETWORK 95 = "PreferenceDialog.icon.networkPref"; 96 97 public static final String LABEL_USER_OPTIONS 98 = "PreferenceDialog.label.user.options"; 99 100 public static final String LABEL_BEHAVIOR 101 = "PreferenceDialog.label.behavior"; 102 103 public static final String LABEL_NETWORK 104 = "PreferenceDialog.label.network"; 105 106 public static final String LABEL_USER_LANGUAGE 107 = "PreferenceDialog.label.user.language"; 108 109 public static final String LABEL_USER_STYLESHEET 110 = "PreferenceDialog.label.user.stylesheet"; 111 112 public static final String LABEL_USER_FONT 113 = "PreferenceDialog.label.user.font"; 114 115 public static final String LABEL_APPLICATIONS 116 = "PreferenceDialog.label.applications"; 117 118 public static final String LABEL_SHOW_RENDERING 119 = "PreferenceDialog.label.show.rendering"; 120 121 public static final String LABEL_AUTO_ADJUST_WINDOW 122 = "PreferenceDialog.label.auto.adjust.window"; 123 124 public static final String LABEL_ENABLE_DOUBLE_BUFFERING 125 = "PreferenceDialog.label.enable.double.buffering"; 126 127 public static final String LABEL_SHOW_DEBUG_TRACE 128 = "PreferenceDialog.label.show.debug.trace"; 129 130 public static final String LABEL_SELECTION_XOR_MODE 131 = "PreferenceDialog.label.selection.xor.mode"; 132 133 public static final String LABEL_IS_XML_PARSER_VALIDATING 134 = "PreferenceDialog.label.is.xml.parser.validating"; 135 136 public static final String LABEL_ENFORCE_SECURE_SCRIPTING 137 = "PreferenceDialog.label.enforce.secure.scripting"; 138 139 public static final String LABEL_SECURE_SCRIPTING_TOGGLE 140 = "PreferenceDialog.label.secure.scripting.toggle"; 141 142 public static final String LABEL_GRANT_SCRIPT_FILE_ACCESS 143 = "PreferenceDialog.label.grant.script.file.access"; 144 145 public static final String LABEL_GRANT_SCRIPT_NETWORK_ACCESS 146 = "PreferenceDialog.label.grant.script.network.access"; 147 148 public static final String LABEL_LOAD_JAVA 149 = "PreferenceDialog.label.load.java"; 150 151 public static final String LABEL_LOAD_ECMASCRIPT 152 = "PreferenceDialog.label.load.ecmascript"; 153 154 public static final String LABEL_HOST 155 = "PreferenceDialog.label.host"; 156 157 public static final String LABEL_PORT 158 = "PreferenceDialog.label.port"; 159 160 public static final String LABEL_OK 161 = "PreferenceDialog.label.ok"; 162 163 public static final String LABEL_LOAD_SCRIPTS 164 = "PreferenceDialog.label.load.scripts"; 165 166 public static final String LABEL_ORIGIN_ANY 167 = "PreferenceDialog.label.origin.any"; 168 169 public static final String LABEL_ORIGIN_DOCUMENT 170 = "PreferenceDialog.label.origin.document"; 171 172 public static final String LABEL_ORIGIN_EMBED 173 = "PreferenceDialog.label.origin.embed"; 174 175 public static final String LABEL_ORIGIN_NONE 176 = "PreferenceDialog.label.origin.none"; 177 178 public static final String LABEL_SCRIPT_ORIGIN 179 = "PreferenceDialog.label.script.origin"; 180 181 public static final String LABEL_RESOURCE_ORIGIN 182 = "PreferenceDialog.label.resource.origin"; 183 184 public static final String LABEL_CANCEL 185 = "PreferenceDialog.label.cancel"; 186 187 public static final String TITLE_BROWSER_OPTIONS 188 = "PreferenceDialog.title.browser.options"; 189 190 public static final String TITLE_BEHAVIOR 191 = "PreferenceDialog.title.behavior"; 192 193 public static final String TITLE_SECURITY 194 = "PreferenceDialog.title.security"; 195 196 public static final String TITLE_NETWORK 197 = "PreferenceDialog.title.network"; 198 199 public static final String TITLE_DIALOG 200 = "PreferenceDialog.title.dialog"; 201 202 public static final String CONFIG_HOST_TEXT_FIELD_LENGTH 203 = "PreferenceDialog.config.host.text.field.length"; 204 205 public static final String CONFIG_PORT_TEXT_FIELD_LENGTH 206 = "PreferenceDialog.config.port.text.field.length"; 207 208 public static final String CONFIG_OK_MNEMONIC 209 = "PreferenceDialog.config.ok.mnemonic"; 210 211 public static final String CONFIG_CANCEL_MNEMONIC 212 = "PreferenceDialog.config.cancel.mnemonic"; 213 214 219 public static final String PREFERENCE_KEY_LANGUAGES 220 = "preference.key.languages"; 221 222 public static final String PREFERENCE_KEY_IS_XML_PARSER_VALIDATING 223 = "preference.key.is.xml.parser.validating"; 224 225 public static final String PREFERENCE_KEY_USER_STYLESHEET 226 = "preference.key.user.stylesheet"; 227 228 public static final String PREFERENCE_KEY_SHOW_RENDERING 229 = "preference.key.show.rendering"; 230 231 public static final String PREFERENCE_KEY_AUTO_ADJUST_WINDOW 232 = "preference.key.auto.adjust.window"; 233 234 public static final String PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING 235 = "preference.key.enable.double.buffering"; 236 237 public static final String PREFERENCE_KEY_SHOW_DEBUG_TRACE 238 = "preference.key.show.debug.trace"; 239 240 public static final String PREFERENCE_KEY_SELECTION_XOR_MODE 241 = "preference.key.selection.xor.mode"; 242 243 public static final String PREFERENCE_KEY_PROXY_HOST 244 = "preference.key.proxy.host"; 245 246 public static final String PREFERENCE_KEY_CSS_MEDIA 247 = "preference.key.cssmedia"; 248 249 public static final String PREFERENCE_KEY_DEFAULT_FONT_FAMILY 250 = "preference.key.default.font.family"; 251 252 public static final String PREFERENCE_KEY_PROXY_PORT 253 = "preference.key.proxy.port"; 254 255 public static final String PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING 256 = "preference.key.enforce.secure.scripting"; 257 258 public static final String PREFERENCE_KEY_GRANT_SCRIPT_FILE_ACCESS 259 = "preference.key.grant.script.file.access"; 260 261 public static final String PREFERENCE_KEY_GRANT_SCRIPT_NETWORK_ACCESS 262 = "preferenced.key.grant.script.network.access"; 263 264 public static final String PREFERENCE_KEY_LOAD_ECMASCRIPT 265 = "preference.key.load.ecmascript"; 266 267 public static final String PREFERENCE_KEY_LOAD_JAVA 268 = "preference.key.load.java.script"; 269 270 public static final String PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN 271 = "preference.key.allowed.script.origin"; 272 273 public static final String PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN 274 = "preference.key.allowed.external.resource.origin"; 275 276 280 protected PreferenceManager model; 281 282 285 protected ConfigurationPanelSelector configPanelSelector; 286 287 290 protected LanguageDialog.Panel languagePanel; 291 292 295 protected UserStyleDialog.Panel userStylesheetPanel; 296 297 protected JCheckBox showRendering; 298 299 protected JCheckBox autoAdjustWindow; 300 301 protected JCheckBox showDebugTrace; 302 303 protected JCheckBox enableDoubleBuffering; 304 305 protected JCheckBox selectionXorMode; 306 307 protected JCheckBox isXMLParserValidating; 308 309 protected JCheckBox enforceSecureScripting; 310 311 protected JCheckBox grantScriptFileAccess; 312 313 protected JCheckBox grantScriptNetworkAccess; 314 315 protected JCheckBox loadJava; 316 317 protected JCheckBox loadEcmascript; 318 319 protected ButtonGroup scriptOriginGroup; 320 321 protected ButtonGroup resourceOriginGroup; 322 323 protected JTextField host, port; 324 325 protected CSSMediaPanel cssMediaPanel; 326 327 331 protected int returnCode; 332 333 336 public PreferenceDialog(PreferenceManager model){ 337 super((Frame )null, true); 338 339 if(model == null){ 340 throw new IllegalArgumentException (); 341 } 342 343 this.model = model; 344 buildGUI(); 345 initializeGUI(); 346 pack(); 347 } 348 349 352 public PreferenceManager getPreferenceManager() { 353 return model; 354 } 355 356 360 protected void initializeGUI(){ 361 String languages = model.getString(PREFERENCE_KEY_LANGUAGES); 366 languagePanel.setLanguages(languages); 367 368 String userStylesheetPath = model.getString(PREFERENCE_KEY_USER_STYLESHEET); 372 userStylesheetPanel.setPath(userStylesheetPath); 373 374 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 allowedScriptOrigin = "" + model.getInteger(PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN); 391 if (allowedScriptOrigin == null || "".equals(allowedScriptOrigin)) { 392 allowedScriptOrigin = "" + ResourceOrigin.NONE; 393 } 394 395 Enumeration e = scriptOriginGroup.getElements(); 396 while (e.hasMoreElements()) { 397 AbstractButton ab = (AbstractButton )e.nextElement(); 398 String ac = ab.getActionCommand(); 399 if (allowedScriptOrigin.equals(ac)) { 400 ab.setSelected(true); 401 } 402 } 403 404 String 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 ab = (AbstractButton )e.nextElement(); 412 String 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 host.setText(model.getString(PREFERENCE_KEY_PROXY_HOST)); 429 port.setText(model.getString(PREFERENCE_KEY_PROXY_PORT)); 430 431 cssMediaPanel.setMedia(model.getString(PREFERENCE_KEY_CSS_MEDIA)); 435 setTitle(Resources.getString(TITLE_DIALOG)); 439 } 440 441 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 (scriptOriginGroup.getSelection().getActionCommand())).intValue()); 473 model.setInteger(PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN, 474 (new Integer (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 486 protected void buildGUI(){ 487 JPanel panel = new JPanel (new BorderLayout ()); 488 489 Component config = buildConfigPanel(); 490 Component 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 503 protected JPanel buildButtonsPanel() { 504 JPanel p = new JPanel (new FlowLayout (FlowLayout.RIGHT)); 505 JButton okButton = new JButton (Resources.getString(LABEL_OK)); 506 okButton.setMnemonic(Resources.getCharacter(CONFIG_OK_MNEMONIC)); 507 JButton cancelButton = new JButton (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 (){ 513 public void actionPerformed(ActionEvent e){ 514 setVisible(false); 515 returnCode = OK_OPTION; 516 savePreferences(); 517 dispose(); 518 } 519 }); 520 521 cancelButton.addActionListener(new ActionListener (){ 522 public void actionPerformed(ActionEvent e){ 523 setVisible(false); 524 returnCode = CANCEL_OPTION; 525 dispose(); 526 } 527 }); 528 529 addKeyListener(new KeyAdapter (){ 530 public void keyPressed(KeyEvent 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 buildConfigPanelList(){ 543 String [] 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 list = new JList (configList); 551 list.addListSelectionListener(new ListSelectionListener (){ 552 public void valueChanged(ListSelectionEvent evt){ 553 if(!evt.getValueIsAdjusting()){ 554 configPanelSelector.select(list.getSelectedValue().toString()); 555 } 556 } 557 }); 558 list.setVisibleRowCount(4); 559 560 ClassLoader cl = this.getClass().getClassLoader(); 562 Map map= new Hashtable (); 563 map.put(Resources.getString(LABEL_USER_LANGUAGE), new ImageIcon (cl.getResource(Resources.getString(ICON_USER_LANGUAGE)))); 564 map.put(Resources.getString(LABEL_USER_STYLESHEET), new ImageIcon (cl.getResource(Resources.getString(ICON_USER_STYLESHEET)))); 565 map.put(Resources.getString(LABEL_BEHAVIOR), new ImageIcon (cl.getResource(Resources.getString(ICON_BEHAVIOR)))); 566 map.put(Resources.getString(LABEL_NETWORK), new ImageIcon (cl.getResource(Resources.getString(ICON_NETWORK)))); 567 568 list.setCellRenderer(new IconCellRenderer(map)); 569 570 list.setSelectedIndex(0); 571 572 return new JScrollPane (list); 573 } 574 575 protected Component buildConfigPanel(){ 576 JPanel configPanel = new JPanel (); 577 CardLayout cardLayout = new CardLayout (); 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 buildUserOptions(){ 601 JTabbedPane p = new JTabbedPane (); 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 buildUserLanguage(){ 612 languagePanel = new LanguageDialog.Panel(); 613 return languagePanel; 614 } 615 616 protected Component buildUserStyleSheet(){ 617 JPanel panel = new JPanel (new BorderLayout ()); 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 buildUserFont(){ 630 return new JButton ("User Font"); 631 } 632 633 protected Component buildBehavior(){ 634 JGridBagPanel p = new JGridBagPanel(); 635 showRendering 636 = new JCheckBox (Resources.getString(LABEL_SHOW_RENDERING)); 637 autoAdjustWindow 638 = new JCheckBox (Resources.getString(LABEL_AUTO_ADJUST_WINDOW)); 639 enableDoubleBuffering 640 = new JCheckBox (Resources.getString(LABEL_ENABLE_DOUBLE_BUFFERING)); 641 enableDoubleBuffering.addActionListener(new ActionListener () { 642 public void actionPerformed(ActionEvent evt) { 643 showRendering.setEnabled(!enableDoubleBuffering.isSelected()); 644 } 645 }); 646 showDebugTrace 647 = new JCheckBox (Resources.getString(LABEL_SHOW_DEBUG_TRACE)); 648 649 selectionXorMode 650 = new JCheckBox (Resources.getString(LABEL_SELECTION_XOR_MODE)); 651 652 isXMLParserValidating 653 = new JCheckBox (Resources.getString(LABEL_IS_XML_PARSER_VALIDATING)); 654 655 enforceSecureScripting 656 = new JCheckBox (Resources.getString(LABEL_SECURE_SCRIPTING_TOGGLE)); 657 658 grantScriptFileAccess 659 = new JCheckBox (Resources.getString(LABEL_GRANT_SCRIPT_FILE_ACCESS)); 660 661 grantScriptNetworkAccess 662 = new JCheckBox (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 () { 670 public void actionPerformed(ActionEvent e) { 671 grantScriptFileAccess.setEnabled(enforceSecureScripting.isSelected()); 672 grantScriptNetworkAccess.setEnabled(enforceSecureScripting.isSelected()); 673 } 674 }); 675 676 loadJava 677 = new JCheckBox (Resources.getString(LABEL_LOAD_JAVA)); 678 679 loadEcmascript 680 = new JCheckBox (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 scriptOriginPanel = new JPanel (); 687 688 scriptOriginGroup = new ButtonGroup (); 689 JRadioButton rb = null; 690 691 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_ANY)); 692 rb.setActionCommand("" + ResourceOrigin.ANY); 693 scriptOriginGroup.add(rb); 694 scriptOriginPanel.add(rb); 695 696 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_DOCUMENT)); 697 rb.setActionCommand("" + ResourceOrigin.DOCUMENT); 698 scriptOriginGroup.add(rb); 699 scriptOriginPanel.add(rb); 700 701 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_EMBED)); 702 rb.setActionCommand("" + ResourceOrigin.EMBEDED); 703 scriptOriginGroup.add(rb); 704 scriptOriginPanel.add(rb); 705 706 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_NONE)); 707 rb.setActionCommand("" + ResourceOrigin.NONE); 708 scriptOriginGroup.add(rb); 709 scriptOriginPanel.add(rb); 710 711 JPanel resourceOriginPanel = new JPanel (); 712 resourceOriginGroup = new ButtonGroup (); 713 714 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_ANY)); 715 rb.setActionCommand("" + ResourceOrigin.ANY); 716 resourceOriginGroup.add(rb); 717 resourceOriginPanel.add(rb); 718 719 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_DOCUMENT)); 720 rb.setActionCommand("" + ResourceOrigin.DOCUMENT); 721 resourceOriginGroup.add(rb); 722 resourceOriginPanel.add(rb); 723 724 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_EMBED)); 725 rb.setActionCommand("" + ResourceOrigin.EMBEDED); 726 resourceOriginGroup.add(rb); 727 resourceOriginPanel.add(rb); 728 729 rb = new JRadioButton (Resources.getString(LABEL_ORIGIN_NONE)); 730 rb.setActionCommand("" + ResourceOrigin.NONE); 731 resourceOriginGroup.add(rb); 732 resourceOriginPanel.add(rb); 733 734 JTabbedPane browserOptions = new JTabbedPane (); 735 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 (), 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 (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 (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 (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 (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 (), 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 buildNetwork(){ 774 JGridBagPanel p = new JGridBagPanel(); 775 host = new JTextField (Resources.getInteger(CONFIG_HOST_TEXT_FIELD_LENGTH)); 776 JLabel hostLabel = new JLabel (Resources.getString(LABEL_HOST)); 777 port = new JTextField (Resources.getInteger(CONFIG_PORT_TEXT_FIELD_LENGTH)); 778 JLabel portLabel = new JLabel (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 (""), 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 buildApplications(){ 795 return new JButton ("Applications"); 796 } 797 798 802 public int showDialog(){ 803 pack(); 804 show(); 805 return returnCode; 806 } 807 808 public static void main(String [] args){ 809 Map defaults = new Hashtable (); 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 e){ 830 System.err.println("Could not save options"); 831 e.printStackTrace(); 832 } 833 } 834 } 835 } 836 837 838 class ConfigurationPanelSelector { 839 private CardLayout layout; 840 private Container container; 841 842 public ConfigurationPanelSelector(Container container, 843 CardLayout layout){ 844 this.layout = layout; 845 this.container = container; 846 } 847 848 public void select(String panelName){ 849 layout.show(container, panelName); 850 } 851 } 852 853 class IconCellRendererOld extends JLabel implements ListCellRenderer { 854 Map iconMap; 855 856 public IconCellRendererOld(Map iconMap){ 857 this.iconMap = iconMap; 858 859 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 860 } 861 public Component getListCellRendererComponent 862 ( 863 JList list, 864 Object value, int index, boolean isSelected, boolean cellHasFocus) { 869 String s = value.toString(); 870 setText(s); 871 ImageIcon icon = (ImageIcon )iconMap.get(s); 872 if(icon != null){ 873 setIcon(icon); 874 setHorizontalAlignment(CENTER); 875 setHorizontalTextPosition(CENTER); 876 setVerticalTextPosition(BOTTOM); 877 } 878 setBackground(java.awt.Color.red); setForeground(list.getSelectionForeground()); 881 886 return this; 889 } 890 } 891 892 class IconCellRenderer extends JLabel 893 implements ListCellRenderer 894 { 895 protected Map map; 896 protected static Border noFocusBorder; 897 898 902 public IconCellRenderer(Map 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 getListCellRendererComponent( 912 JList list, 913 Object 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 940 941 setText(value.toString()); 942 ImageIcon icon = (ImageIcon )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 961 public void validate() {} 962 963 968 public void revalidate() {} 969 974 public void repaint(long tm, int x, int y, int width, int height) {} 975 976 981 public void repaint(Rectangle r) {} 982 983 988 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { 989 if (propertyName=="text") 991 super.firePropertyChange(propertyName, oldValue, newValue); 992 } 993 994 999 public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {} 1000 1001 1006 public void firePropertyChange(String propertyName, char oldValue, char newValue) {} 1007 1008 1013 public void firePropertyChange(String propertyName, short oldValue, short newValue) {} 1014 1015 1020 public void firePropertyChange(String propertyName, int oldValue, int newValue) {} 1021 1022 1027 public void firePropertyChange(String propertyName, long oldValue, long newValue) {} 1028 1029 1034 public void firePropertyChange(String propertyName, float oldValue, float newValue) {} 1035 1036 1041 public void firePropertyChange(String propertyName, double oldValue, double newValue) {} 1042 1043 1048 public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {} 1049} 1050 | Popular Tags |