📄 attributeeditordialog.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* web: http://yale.cs.uni-dortmund.de/
*
* 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 (at your option) 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 edu.udo.cs.yale.gui;
import edu.udo.cs.yale.operator.Operator;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.AbstractAction;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
/**
* @version $Id: AttributeEditorDialog.java,v 2.5 2004/08/27 11:57:33 ingomierswa Exp $
*
* @see edu.udo.cs.yale.gui.AttributeEditor
*/
public class AttributeEditorDialog extends JDialog {
private AttributeEditor attributeEditor;
private class OpenAttributeFileAction extends AbstractAction {
private OpenAttributeFileAction() {
super("Open attribute description file...");
putValue(SHORT_DESCRIPTION, "Open an existing XML attribute description file.");
putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
}
public void actionPerformed(ActionEvent e) {
attributeEditor.openAttributeFile();
}
}
private class SaveAttributeFileAction extends AbstractAction {
private SaveAttributeFileAction() {
super("Save attribute description file...");
putValue(SHORT_DESCRIPTION, "Save current attribute descriptions to XML file.");
putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
}
public void actionPerformed(ActionEvent e) {
saveAttributes();
}
}
private class LoadDataAction extends AbstractAction {
private LoadDataAction() {
super("Load data...");
putValue(SHORT_DESCRIPTION, "Open data file and append additional columns to table.");
putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_D));
}
public void actionPerformed(ActionEvent e) {
loadData();
}
}
private class SaveDataAction extends AbstractAction {
private SaveDataAction() {
super("Save data...");
putValue(SHORT_DESCRIPTION, "Save the contents of the table to a single data file.");
putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_V));
}
public void actionPerformed(ActionEvent e) {
saveData();
}
}
private class ClearAction extends AbstractAction {
private ClearAction() {
super("Clear");
putValue(SHORT_DESCRIPTION, "Clear the table.");
putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_C));
}
public void actionPerformed(ActionEvent e) {
clear();
}
}
public AttributeEditorDialog(JFrame owner, Operator exampleSource, File file) {
this(owner, exampleSource);
if (file != null)
attributeEditor.openAttributeFile(file);
}
public AttributeEditorDialog(JFrame owner, Operator exampleSource) {
super(owner, "Attribute Editor", true);
attributeEditor = new AttributeEditor(exampleSource);
getContentPane().add(new JScrollPane(attributeEditor), BorderLayout.CENTER);
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.add(new OpenAttributeFileAction());
fileMenu.add(new SaveAttributeFileAction());
fileMenu.add(new LoadDataAction());
fileMenu.add(new SaveDataAction());
menuBar.add(fileMenu);
JMenu tableMenu = new JMenu("Table");
tableMenu.add(attributeEditor.GUESS_TYPE_ACTION);
tableMenu.add(attributeEditor.REMOVE_COLUMN_ACTION);
tableMenu.add(new ClearAction());
menuBar.add(tableMenu);
setJMenuBar(menuBar);
pack();
}
private void loadData() {
File file = SwingTools.chooseFile(this, null, true);
if (file != null) {
try {
attributeEditor.readFile(file);
} catch (java.io.IOException e) {
JOptionPane.showMessageDialog(this, e.toString(), "Error loading "+file, JOptionPane.ERROR_MESSAGE);
}
}
}
private void saveAttributes() {
attributeEditor.saveAttributeFile();
}
private void saveData() {
File file = SwingTools.chooseFile(this, null, false);
if (file != null) {
try {
attributeEditor.writeData(file);
} catch (java.io.IOException e) {
JOptionPane.showMessageDialog(this, e.toString(), "Error saving data file "+file, JOptionPane.ERROR_MESSAGE);
}
}
}
private void clear() {
attributeEditor.clear();
}
public File getFile() {
return attributeEditor.getFile();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -