⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optionsdialog.java

📁 java写的多功能文件编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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 <blaisorblade_work (at) yahoo.it, who will provide an upgraded version " +        "of the plugin.Thanks");        //I hope this will never happen, but it has happened with the Java plugin(JBrowse option pane).      } catch(Throwable t)  {        t.printStackTrace();      }    }    for (Iterator i = notCachPlugPanes.iterator(); i.hasNext(); )      cardPanel.remove(( (OptionPane) i.next()).getComponent());    for (Iterator i = notCachPlugin.iterator(); i.hasNext(); )    {      Plugin plug = null;      try {	( plug = (Plugin) (i.next()) ).createOptionPanes(this);      } 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 " + plug.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 <blaisorblade_work (at) yahoo.it, who will provide an upgraded version " +        "of the plugin.Thanks");        //I hope this will never happen, but it has happened with the Java plugin(JBrowse option pane).      } catch(Throwable t)  {        t.printStackTrace();      }    }     ((CardLayout) cardPanel.getLayout()).show(cardPanel, currPaneName);  }  /**Use this method or addOptionPane to add your option pane to Jext. You must use this one   * and not anything else! See Jext Docs(the Plugin section is very good).   * If you use OptionGroup.addOptionPane after adding the pane, it is a bug.   * The pane must be added both to the tree and to a CardLayout to show it.   * Also, it must be managed to be eventually cached.*/  public void addOptionGroup(OptionGroup group)  {    addOptionGroup(group, pluginsGroup);  }  /**Use this method or addOptionGroup to add your option pane to Jext. You must use this one   * and not anything else! See Jext Docs(the Plugin section is very good).   * If you use OptionGroup.addOptionPane after adding the pane, it is a bug.   * The pane must be added both to the tree and to a CardLayout to show it.   * Also, it must be managed to be eventually cached.*/  public void addOptionPane(OptionPane pane)  {    addOptionPane(pane, pluginsGroup);  }  private void addOptionGroup(OptionGroup child, OptionGroup parent)  {    ArrayList enum = child.getMembers();    for (int i = 0; i < enum.size(); i++)    {      Object elem = enum.get(i);      if (elem instanceof OptionPane)      {        addOptionPane((OptionPane) elem, child);      } else if (elem instanceof OptionGroup) {        addOptionGroup((OptionGroup) elem, child);      }    }    parent.addOptionGroup(child);  }  private void addOptionPane(OptionPane pane, OptionGroup parent)  {    String name = pane.getName();    cardPanel.add(pane.getComponent(), name);    if (isLoadingPlugs || isLoadingCore)      parent.addOptionPane(pane);    //Let's trace reloadable panes and the ones I must rebuild.    if (isLoadingPlugs) {      if (pane.isCacheable() == true)        cachPlugPanes.add(pane);      else {        notCachPlugPanes.add(pane);        if (currPlugin != null)        {          notCachPlugin.add(currPlugin);//a value is given to currPlugin in createOptionTreeModel()          currPlugin = null;//so every plugin is added to notCachPlugin only one time.          //NOTE: when a single plugin has both reloadable and not reloadable plugin panes, all this code is likely to be          //buggy.        }      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -