📄 getplaypenpanel.java
字号:
package org.fife.rtext.plugins.rtextl10ngen;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.fife.ui.app.WizardPluginDialog;
import org.fife.ui.app.WizardDialogInfoPanel;
import org.fife.ui.rtextfilechooser.RDirectoryChooser;
/**
* The panel that gets the playpen for both the "Create L10n Playpen" and
* "Merge Playpen with RText source" wizards.
*
* @author Robert Futrell
* @version 1.0
*/
class GetPlaypenPanel extends WizardDialogInfoPanel implements ActionListener,
DocumentListener {
private JTextField playpenField;
private ResourceBundle msg;
private static final String BROWSE = "Browse";
/*****************************************************************************/
/**
* Constructor.
*
* @param header The header.
* @param desc The description text.
* @param msg The plugin's resource bundle.
*/
public GetPlaypenPanel(String desc, ResourceBundle msg) {
super(msg.getString("Plugin.Wizard.Common.PPen.Header"));
this.msg = msg;
setLayout(new BorderLayout());
JPanel contentPane = new JPanel();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel temp = new JPanel(new BorderLayout());
temp.add(new JLabel(desc));//, BorderLayout.WEST);
contentPane.add(temp);
contentPane.add(Box.createVerticalStrut(15));
temp = new JPanel(new BorderLayout());
temp.add(new JLabel(msg.getString("Plugin.Wizard.Common.PPen.Prompt")),
BorderLayout.WEST);
playpenField = new JTextField();
playpenField.getDocument().addDocumentListener(this);
JPanel temp2 = new JPanel(new BorderLayout());
temp2.setBorder(BorderFactory.createEmptyBorder(0,5,0,5));
temp2.add(playpenField);
temp.add(temp2);
JButton browseButton = new JButton(
msg.getString("Plugin.Wizard.Common.Browse"));
browseButton.setActionCommand(BROWSE);
browseButton.addActionListener(this);
temp.add(browseButton, BorderLayout.EAST);
contentPane.add(temp);
add(contentPane, BorderLayout.NORTH);
}
/*****************************************************************************/
/**
* Called when an action is performed in this panel.
*
* @param e The event.
*/
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
if (BROWSE.equals(actionCommand)) {
RDirectoryChooser chooser = new RDirectoryChooser(
(Dialog)SwingUtilities.windowForComponent(this));
chooser.setVisible(true);
String dir = chooser.getChosenDirectory();
if (dir!=null) {
playpenField.setText(dir);
}
}
}
/*****************************************************************************/
/**
* Never called.
*/
public void changedUpdate(DocumentEvent e) {
handlePlaypenChanged();
}
/*****************************************************************************/
/**
* Returns the directory specified by the user to use as the playpen.
*
* @return The playpen.
*/
public File getPlaypen() {
return new File(playpenField.getText());
}
/*****************************************************************************/
/**
* Called when the user changes the directory to use for the playpen.
*/
protected void handlePlaypenChanged() {
setNextButtonEnabled(playpenField.getDocument().getLength()>0);
}
/*****************************************************************************/
/**
* Called when the user selects a directory to use for the playpen.
*
* @param e A document event.
*/
public void insertUpdate(DocumentEvent e) {
handlePlaypenChanged();
}
/*****************************************************************************/
/**
* Called when this panel is displayed in the wizard.
*/
public void isDisplayed() {
handlePlaypenChanged();
}
/*****************************************************************************/
/**
* Called when the user modifies the playpen directory.
*
* @param e The document event.
*/
public void removeUpdate(DocumentEvent e) {
handlePlaypenChanged();
}
/*****************************************************************************/
/**
* Saves input from the user. This method is called when the user clicks
* the "Next" button after giving any input needed for this panel. The
* panel should use the <code>setWizarProperty</code> method of the
* wizard dialog to save entered data.
*
* @param dialog The wizard dialog.
*/
protected void saveUserInput(WizardPluginDialog dialog) {
dialog.setWizardProperty("Playpen", getPlaypen());
}
/*****************************************************************************/
/**
* Ensures all of the data entered by the user is valid. If it is,
* <code>null</code> should be returned. If it isn't, then a message
* is returned that is displayed, instructing the user on how to
* correct the error.
*
* @return <code>null</code> if all input in this panel is correct,
* or a message explaining an error if errors exist.
*/
public String validateInput() {
String desc = null;
File playpen = getPlaypen();
// If the playpen does not yet exist...
if (!playpen.isDirectory() ) {
// Check whether the parent exists. If it does, try to create
// the playpen.
File parent = playpen.getParentFile();
if (parent==null || parent.isDirectory()) {
if (!playpen.mkdir()) {
desc = msg.getString(
"Plugin.Wizard.Common.Error.DirectoryNotCreated");
desc = MessageFormat.format(desc,
new Object[] { playpen.getAbsolutePath() });
}
}
// If the parent does not exist, we cannot create the playpen!
else {
desc = msg.getString(
"Plugin.Wizard.Common.Error.DirectoryNotExist");
desc = MessageFormat.format(desc,
new Object[] { parent.getAbsolutePath() });
}
}
return desc;
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -