📄 uioptionpanel.java
字号:
/*
* 03/25/2004
*
* UIOptionPanel.java - Option panel for overall user interface
* (non-textarea) related options.
* Copyright (C) 2004 Robert Futrell
* email@address.com
* www.website.com
*
* This file is a part of RText.
*
* RText 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.
*
* RText 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.fife.rtext;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.Iterator;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SpringLayout;
import javax.swing.UIManager;
import org.fife.RUtilities;
import org.fife.ui.OptionsDialogPanel;
import org.fife.ui.RButton;
import org.fife.ui.RColorSwatchesButton;
import org.fife.ui.rtextarea.IconGroup;
import org.fife.ui.SpecialValueComboBox;
import org.fife.ui.StatusBar;
import org.fife.ui.UIUtilities;
import org.fife.ui.app.ExtendedLookAndFeelInfo;
/**
* Option panel for user-interface specific options (that don't have to
* do with the text area).
*
* @author Robert Futrell
* @version 1.0
*/
class UIOptionPanel extends OptionsDialogPanel implements ActionListener,
PropertyChangeListener {
private int mainViewStyle;
private int documentSelectionPlacement;
private int statusBarStyle;
private JComboBox viewCombo;
private JComboBox docSelCombo;
private SpecialValueComboBox lnfCombo;
private SpecialValueComboBox imageLnFCombo;
private JComboBox statusBarCombo;
private JCheckBox highlightModifiedCheckBox;
private RColorSwatchesButton hmColorButton;
/*****************************************************************************/
/**
* Constructor.
*/
public UIOptionPanel(final RText rtext, final ResourceBundle msg) {
super(msg.getString("OptUIName"));
Dimension spacer = new Dimension(5,5);
// Set up our border and layout.
setBorder(UIUtilities.getEmpty5Border());
setLayout(new BorderLayout());
// Create a panel to put everything in. We'll add this panel to our
// "North" so it doesn't stretch when the user resizes the dialog.
JPanel everything = new JPanel();
everything.setLayout(new BoxLayout(everything, BoxLayout.Y_AXIS));
viewCombo = new JComboBox();
viewCombo.setActionCommand("ViewComboBox");
viewCombo.addActionListener(this);
viewCombo.addItem(msg.getString("OptUITV"));
viewCombo.addItem(msg.getString("OptUISPV"));
viewCombo.addItem(msg.getString("OptUIMDIV"));
docSelCombo = new JComboBox();
docSelCombo.setActionCommand("DocSelCombo");
docSelCombo.addActionListener(this);
docSelCombo.addItem(msg.getString("OptUITop"));
docSelCombo.addItem(msg.getString("OptUILeft"));
docSelCombo.addItem(msg.getString("OptUIBottom"));
docSelCombo.addItem(msg.getString("OptUIRight"));
// Add a panel for the "Layout" stuff.
JPanel springPanel = new JPanel(new SpringLayout());
springPanel.add(new JLabel(msg.getString("OptUIViewT")));
springPanel.add(viewCombo);
springPanel.add(new JLabel(msg.getString("OptUIDSPT")));
springPanel.add(docSelCombo);
RUtilities.makeSpringCompactGrid(springPanel,
2,2, // rows,cols,
0,0, // initial-x, initial-y,
5,5); // x-spacing, y-spacing.
JPanel temp = new JPanel(new BorderLayout());
temp.setBorder(new OptionPanelBorder(msg.getString("OptUILT")));
temp.add(springPanel, BorderLayout.WEST);
everything.add(temp);
lnfCombo = createLookAndFeelComboBox(rtext);
lnfCombo.setActionCommand("LookAndFeelComboBox");
lnfCombo.addActionListener(this);
imageLnFCombo = new SpecialValueComboBox();
imageLnFCombo.setActionCommand("IconComboBox");
imageLnFCombo.addActionListener(this);
Collection iconGroups = rtext.getIconGroupMap().values();
for (Iterator i=iconGroups.iterator(); i.hasNext(); ) {
IconGroup group = (IconGroup)i.next();
imageLnFCombo.addSpecialItem(group.getName(), group.getName());
}
statusBarCombo = new JComboBox();
statusBarCombo.setActionCommand("StatusBarComboBox");
statusBarCombo.addActionListener(this);
statusBarCombo.addItem(msg.getString("OptUIW95A"));
statusBarCombo.addItem(msg.getString("OptUIWXPA"));
// Add a panel for the "Appearance" stuff.
springPanel = new JPanel(new SpringLayout());
springPanel.add(new JLabel(msg.getString("OptUILnFT")));
springPanel.add(lnfCombo);
springPanel.add(new JLabel(msg.getString("OptUIIAT")));
springPanel.add(imageLnFCombo);
springPanel.add(new JLabel(msg.getString("OptUISBT")));
springPanel.add(statusBarCombo);
RUtilities.makeSpringCompactGrid(springPanel,
3,2, // rows,cols,
0,0, // initial-x, initial-y,
5,5); // x-spacing, y-spacing.
temp = new JPanel(new BorderLayout());
temp.setBorder(new OptionPanelBorder(msg.getString("OptUIAT")));
temp.add(springPanel, BorderLayout.WEST);
everything.add(temp);
// Add a panel for the "modified filenames" color button.
JPanel miscPanel = new JPanel();
miscPanel.setLayout(new BoxLayout(miscPanel, BoxLayout.X_AXIS));
highlightModifiedCheckBox = new JCheckBox(msg.getString("OptUIHMDN"));
highlightModifiedCheckBox.setActionCommand("HighlightModifiedCheckBox");
highlightModifiedCheckBox.addActionListener(this);
miscPanel.add(highlightModifiedCheckBox);
hmColorButton = new RColorSwatchesButton(Color.RED);
hmColorButton.addPropertyChangeListener(this);
miscPanel.add(hmColorButton);
miscPanel.add(Box.createHorizontalGlue());
everything.add(miscPanel);
// Add everything "to the north" so the spacing between stuff doesn't
// change then the user stretches the dialog.
add(everything, BorderLayout.NORTH);
}
/*****************************************************************************/
/**
* Listens for actions being performed in this panel.
*/
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
if (actionCommand.equals("ViewComboBox")) {
hasUnsavedChanges = true;
int old = mainViewStyle;
mainViewStyle = viewCombo.getSelectedIndex();
firePropertyChange("UIOptionPanel.mainViewStyle", old, mainViewStyle);
}
else if (actionCommand.equals("DocSelCombo")) {
hasUnsavedChanges = true;
int old = documentSelectionPlacement;
documentSelectionPlacement = docSelCombo.getSelectedIndex() +
JTabbedPane.TOP;
firePropertyChange("UIOptionPanel.documentSelectionPlacement",
old, documentSelectionPlacement);
}
else if (actionCommand.equals("LookAndFeelComboBox")) {
hasUnsavedChanges = true;
String newLnF = lnfCombo.getSelectedSpecialItem();
firePropertyChange("UIOptionPanel.lookAndFeel", null, newLnF);
}
else if (actionCommand.equals("IconComboBox")) {
hasUnsavedChanges = true;
String name = imageLnFCombo.getSelectedSpecialItem();
firePropertyChange("UIOptionPanel.iconStyle", null, name);
}
else if (actionCommand.equals("StatusBarComboBox")) {
hasUnsavedChanges = true;
int old = statusBarStyle;
statusBarStyle = statusBarCombo.getSelectedIndex();
firePropertyChange("UIOptionPanel.statusBarStyle", old, statusBarStyle);
}
else if (actionCommand.equals("HighlightModifiedCheckBox")) {
boolean highlight = highlightModifiedDocumentDisplayNames();
hmColorButton.setEnabled(highlight);
hasUnsavedChanges = true;
firePropertyChange("UIOptionPanel.highlightModified", !highlight, highlight);
}
}
/*****************************************************************************/
/**
* Creates and returns a special value combo box containing all available
* Look and Feels.
*
* @param rtext The parent RText instance.
* @return The combo box.
*/
private SpecialValueComboBox createLookAndFeelComboBox(final RText rtext) {
SpecialValueComboBox combo = new SpecialValueComboBox();
String osName = System.getProperty("os.name").toLowerCase();
boolean osIsWindows = osName!=null && osName.indexOf("windows")>-1;
// Add Look and Feels shipped with Swing.
UIManager.LookAndFeelInfo[] infos = UIManager.
getInstalledLookAndFeels();
for (int i=0; i<infos.length; i++) {
// NOTE: It would be nice if we could check the
// LookAndFeel.isSupportedLookAndFeel() method, but that would
// require loading each LnF class (and their required
// subclasses?), which we're trying to avoid.
// We'll assume Windows supports all LnFs, and any other OS does
// NOT support a standard Look with "Windows" in the name.
String name = infos[i].getName();
if (osIsWindows || !(name.toLowerCase().indexOf("windows")>-1)) {
combo.addSpecialItem(name, infos[i].getClassName());
}
}
// Add the Office Looks if we're on Windows.
if (osIsWindows) {
combo.addSpecialItem("MS Office XP",
"org.fife.plaf.OfficeXP.OfficeXPLookAndFeel");
combo.addSpecialItem("MS Office 2003",
"org.fife.plaf.Office2003.Office2003LookAndFeel");
combo.addSpecialItem("Visual Studio 2005",
"org.fife.plaf.VisualStudio2005.VisualStudio2005LookAndFeel");
}
// Add any 3rd party Look and Feels in the lnfs subdirectory.
ExtendedLookAndFeelInfo[] info = rtext.get3rdPartyLookAndFeelInfo();
int count = info==null ? 0 : info.length;
if (count>0) {
for (int i=0; i<count; i++) {
combo.addSpecialItem(info[i].getName(),
info[i].getClassName());
}
}
return combo;
}
/*****************************************************************************/
/**
* Checks whether or not all input the user specified on this panel is
* valid. This should be overridden to check, for example, whether
* text fields have valid values, etc. This method will be called
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -