📄 savemacrodialog.java
字号:
/*
* 09/16/2004
*
* SaveMacroDialog.java - A dialog prompting the user to save a macro.
* 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.*;
import java.awt.event.*;
import java.io.File;
import java.util.ResourceBundle;
import javax.swing.*;
import org.fife.RUtilities;
import org.fife.ui.RButton;
import org.fife.ui.TitledPanel;
/**
* A dialog prompting the user to save a macro.
*
* @author Robert Futrell
* @version 0.5
*/
class SaveMacroDialog extends JDialog implements ActionListener {
private RText rtext;
private RButton okButton;
private RButton cancelButton;
private JTextField macroNameField;
/*****************************************************************************/
/**
* Creates a new <code>SaveMacroDialog</code>.
*
* @param rtext The owner of this dialog.
*/
public SaveMacroDialog(RText rtext) {
super(rtext);
this.rtext = rtext;
ResourceBundle bundle = rtext.getResourceBundle();
JPanel temp = new JPanel(new BorderLayout());
temp.setBorder(BorderFactory.createEmptyBorder(10,5,5,5));
// Panel to input the action's name.
JPanel namePanel = new JPanel(new BorderLayout());
JLabel label = RUtilities.createLabel(bundle, "MacroNameLabel",
"MacroNameLabelMnemonic");
namePanel.add(label, BorderLayout.WEST);
macroNameField = new JTextField(30);
label.setLabelFor(macroNameField);
namePanel.add(macroNameField);
temp.add(namePanel, BorderLayout.NORTH);
// Panel for the buttons.
okButton = RUtilities.createRButton(bundle, "OKButtonLabel",
"OKButtonMnemonic");
cancelButton = RUtilities.createRButton(bundle, "Cancel",
"CancelMnemonic");
okButton.setActionCommand("OKButtonPressed");
okButton.addActionListener(this);
cancelButton.setActionCommand("CancelButtonPressed");
cancelButton.addActionListener(this);
JPanel buttonPanel = new JPanel(new GridLayout(1,2, 5,0));
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
JPanel bottomPanel = new JPanel();
bottomPanel.add(buttonPanel);
temp.add(bottomPanel, BorderLayout.SOUTH);
// Create the content pane and put everything in it!
String saveMacro = bundle.getString("Dialog.SaveMacro.SaveMacro");
JPanel contentPane = new TitledPanel(saveMacro, temp,
TitledPanel.BEVEL_BORDER);
setContentPane(contentPane);
getRootPane().setDefaultButton(okButton);
setTitle(saveMacro);
setModal(true);
//setResizable(false);
setLocationRelativeTo(rtext);
pack();
}
/*****************************************************************************/
/**
* Listens for actions in this dialog.
*
* @param e The event that occured.
*/
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
// If they press "OK", save the action.
if (actionCommand.equals("OKButtonPressed")) {
String name = macroNameField.getText();
if (name!=null && name.length()>0) {
// Add macro extension to the end of it if it isn't already
// there.
if (!name.endsWith(RTextUtilities.MACRO_EXTENSION))
name += RTextUtilities.MACRO_EXTENSION;
File macroDir = RTextUtilities.getMacroDirectory();
if (macroDir.isDirectory()) {
File macroFile = new File(macroDir, name);
try {
rtext.getMainView().currentTextArea.
getCurrentMacro().
saveToFile(macroFile.getAbsolutePath());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Error saving macro -\n" + ex,
rtext.getResourceBundle()
.getString("ErrorDialogTitle"),
JOptionPane.ERROR_MESSAGE);
}
}
else {
ResourceBundle msg = rtext.getResourceBundle();
JOptionPane.showMessageDialog(this,
msg.getString("MacroInvalidDir"),
msg.getString("ErrorDialogTitle"),
JOptionPane.ERROR_MESSAGE);
}
this.setVisible(false);
}
}
// If they press "Cancel", just hide the dialog without saving the
// macro.
else if (actionCommand.equals("CancelButtonPressed")) {
this.setVisible(false);
}
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -