|
What this is
Other links
The source code/* * 10/23/2001 - 21:17:27 * * OptionsDialog.java - Global options dialog * Copyright (C) 1998, 1999, 2000 Slava Pestov * Portions copyright (C) 1999 mike dillon * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.jext.options; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.tree.*; import org.jext.*; import org.jext.gui.*; public class OptionsDialog extends JDialog implements ActionListener, TreeSelectionListener { private JTree paneTree; //private Hashtable panes;//not any more needed private JPanel cardPanel; private JLabel currentLabel; private JextHighlightButton ok, cancel, apply; private OptionGroup jextGroup, pluginsGroup; private static OptionsDialog theInstance; private OptionTreeModel theTree; private boolean toReload = false, //if the user clicks cancel, options must be reloaded isLoadingPlugs, isLoadingCore; //when it's building the dialog the first time, it must now use it to //select plugins which support the re-load()'ing of options. private String currPaneName; private Plugin currPlugin; //the plugin it's currently loading. private ArrayList cachPlugPanes, notCachPlugPanes, notCachPlugin; private JextFrame parent;//need to know this to show wait cursor after first load; commented out since it doesn't work //anyway //for UIOptions static OptionsDialog getInstance() { return theInstance; } /**Call this to show the dialog; every other method should not be called, except * (very rarely, however) by Jext kernel itself, with the only exceptions of * {@link #addOptionPane(OptionPane) addOptionPane} and * {@link #addOptionGroup(OptionGroup) addOptionGroup} methods. */ public static void showOptionDialog(JextFrame parent) { if (theInstance == null) theInstance = new OptionsDialog(parent); else theInstance.reload(); theInstance.setVisible(true); } private OptionsDialog(JextFrame _parent) { super(_parent, Jext.getProperty("options.title"), true); parent = _parent; parent.showWaitCursor(); cachPlugPanes = new ArrayList(20);//number of elements. It should be more than needed one. notCachPlugPanes = new ArrayList(20); notCachPlugin = new ArrayList(20); getContentPane().setLayout(new BorderLayout()); ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); JPanel stage = new JPanel(new BorderLayout(4, 8)); stage.setBorder(//BorderFactory.createCompoundBorder( //new SoftBevelBorder(SoftBevelBorder.RAISED), BorderFactory.createEmptyBorder(4, 4, 4, 4)); //new EtchedBorder(EtchedBorder.RAISED)); getContentPane().add(stage, BorderLayout.CENTER); // currentLabel displays the path of the currently selected // OptionPane at the top of the stage area currentLabel = new JLabel(); currentLabel.setHorizontalAlignment(JLabel.LEFT); currentLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black)); stage.add(currentLabel, BorderLayout.NORTH); cardPanel = new JPanel(new CardLayout()); stage.add(cardPanel, BorderLayout.CENTER); paneTree = new JTree(theTree = createOptionTreeModel()); paneTree.setCellRenderer(new PaneNameRenderer()); paneTree.putClientProperty("JTree.lineStyle", "Angled"); paneTree.setShowsRootHandles(true); paneTree.setRootVisible(false); getContentPane().add(new JScrollPane(paneTree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.WEST); JPanel buttons = new JPanel(); ok = new JextHighlightButton(Jext.getProperty("options.set.button")); ok.setMnemonic(Jext.getProperty("options.set.mnemonic").charAt(0)); ok.addActionListener(this); buttons.add(ok); getRootPane().setDefaultButton(ok); cancel = new JextHighlightButton(Jext.getProperty("general.cancel.button")); cancel.setMnemonic(Jext.getProperty("general.cancel.mnemonic").charAt(0)); cancel.addActionListener(this); buttons.add(cancel); apply = new JextHighlightButton(Jext.getProperty("options.apply.button")); apply.setMnemonic(Jext.getProperty("options.apply.mnemonic").charAt(0)); apply.addActionListener(this); buttons.add(apply); getContentPane().add(buttons, BorderLayout.SOUTH); addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { switch (evt.getKeyCode()) { case KeyEvent.VK_ENTER: ok(); break; case KeyEvent.VK_ESCAPE: cancel(); break; } } }); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { cancel(); } }); // compute the Jext branch TreePath jextPath = new TreePath(new Object[] { theTree.getRoot(), jextGroup , jextGroup.getMember(0) }); // register the Options dialog as a TreeSelectionListener. // this is done before the initial selection to ensure that the // first selected OptionPane is displayed on startup. paneTree.getSelectionModel().addTreeSelectionListener(this); // select the first member of the Jext group paneTree.setSelectionPath(jextPath); // register the MouseHandler to open and close branches paneTree.addMouseListener(new MouseHandler()); pack(); Utilities.centerComponent(this); parent.hideWaitCursor(); } private void ok(boolean close) { OptionTreeModel m = (OptionTreeModel) paneTree.getModel(); ((OptionGroup) m.getRoot()).save(); Jext.propertiesChanged(); if (close) setVisible(false); } private void ok() { ok(true); } private void cancel() { toReload = true; setVisible(false); } public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == ok) { ok(); } else if(source == cancel) { cancel(); } else if(source == apply) { ok(false); } } private void reload() { if (toReload) { parent.showWaitCursor(); reloadStdPanes(); reloadPluginPanes(); toReload = false; parent.hideWaitCursor(); } } private void reloadStdPanes() { ArrayList stdPanes = jextGroup.getMembers(); for (int i = 0; i < stdPanes.size(); i++ ) ((AbstractOptionPane) stdPanes.get(i)).load(); } private void reloadPluginPanes() { ((CardLayout) cardPanel.getLayout()).show(cardPanel, ((OptionPane) (jextGroup.getMember(0))).getName()); for (Iterator i = cachPlugPanes.iterator(); i.hasNext(); ) { OptionPane op = null; try { ( op = (OptionPane) (i.next()) ).load(); } catch(AbstractMethodError ame) {//This is when a plugin does not extends //AbstractOptionPane but implements directly the interface OptionPane, which has now new //methods ame.printStackTrace(); Utilities.showError("The option pane of the plugin containing " + op.getClass().toString() + " is not supported, and you will not see it in the option dialog. This is related to new Jext " + "release(from 3.2pre3). You should make aware of this Romain Guy, the plugin's author or " + "Blaisorblade |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.