📄 generaloptionpanel.java
字号:
/*
* 12/07/2004
*
* GeneralOptionPanel.java - Option panel for general RText 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.io.File;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.fife.RUtilities;
import org.fife.ui.OptionsDialog;
import org.fife.ui.OptionsDialogPanel;
import org.fife.ui.RButton;
import org.fife.ui.UIUtilities;
import org.fife.ui.rtextfilechooser.RDirectoryChooser;
/**
* Option panel for general RText options.
*
* @author Robert Futrell
* @version 0.1
*/
class GeneralOptionPanel extends OptionsDialogPanel
implements ActionListener {
private JTextField dirField;
private RButton dirBrowseButton;
private static final String NEW_FILE_DIR_PROPERTY = "newFileDirectory";
/*****************************************************************************/
/**
* Constructor.
*
* @param rtext The owning RText instance.
* @param msg The resource bundle to use.
*/
public GeneralOptionPanel(final RText rtext, final ResourceBundle msg) {
super(msg.getString("OptGenName"));
Dimension spacer = new Dimension(5,5);
// Set up our border and layout.
setBorder(UIUtilities.getEmpty5Border());
setLayout(new BorderLayout());
// Create a panel for stuff aligned at the top.
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
topPanel.setBorder(new OptionPanelBorder(
msg.getString("OptGenTitle")));
// Create a panel for selecting the "new file directory."
JPanel dirPanel = new JPanel();
dirPanel.setLayout(new BoxLayout(dirPanel, BoxLayout.X_AXIS));
JLabel dirLabel = new JLabel(msg.getString("OptGenWD"));
dirField = new JTextField();
dirField.setEditable(false);
dirLabel.setLabelFor(dirField);
dirBrowseButton = new RButton(msg.getString("Browse"));
dirBrowseButton.setActionCommand("Browse");
dirBrowseButton.addActionListener(this);
dirPanel.add(dirLabel);
dirPanel.add(Box.createRigidArea(spacer));
dirPanel.add(dirField);
dirPanel.add(Box.createRigidArea(spacer));
dirPanel.add(dirBrowseButton);
dirPanel.add(Box.createHorizontalGlue());
topPanel.add(dirPanel);
add(topPanel, BorderLayout.NORTH);
}
/*****************************************************************************/
/**
* Called whenever an action occurs in this dialog.
*
* @param e The action event that occured.
*/
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
if (actionCommand.equals("Browse")) {
OptionsDialog od = getOptionsDialog();
RDirectoryChooser dc = new RDirectoryChooser(od);
dc.setVisible(true);
String chosenDir = dc.getChosenDirectory();
if (chosenDir!=null) {
File dir = new File(chosenDir);
if (dir.isDirectory() &&
!chosenDir.equals(dirField.getText())) {
dirField.setText(chosenDir);
hasUnsavedChanges = true;
firePropertyChange(NEW_FILE_DIR_PROPERTY,
null, chosenDir);
}
}
}
}
/*****************************************************************************/
/**
* 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
* whenever the user clicks "OK" or "Apply" on the options dialog to
* ensure all input is valid. If it isn't, the component with invalid
* data will be given focus and the user will be prompted to fix it.<br>
*
*
* @return <code>null</code> always.
*/
public OptionsPanelCheckResult ensureValidInputs() {
return null;
}
/*****************************************************************************/
/**
* Returns the <code>JComponent</code> at the "top" of this Options
* panel.
*/
public JComponent getTopJComponent() {
return dirBrowseButton;
}
/*****************************************************************************/
/**
* Returns the working directory chosen by the user.
*
* @return The working directory.
* @see #setWorkingDirectory
*/
public String getWorkingDirectory() {
return dirField.getText();
}
/*****************************************************************************/
/**
* Sets the working directory displayed.
*
* @param directory The working directory to display.
* @see #getWorkingDirectory
*/
public void setWorkingDirectory(String directory) {
dirField.setText(directory);
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -