configdescriptioneditor.java
来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 1,342 行 · 第 1/3 页
JAVA
1,342 行
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner (taquera@sherito.org);
*
* (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ------------------------------
* ConfigDescriptionEditor.java
* ------------------------------
* (C)opyright 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: ConfigDescriptionEditor.java,v 1.9 2003/11/07 18:33:51 taqua Exp $
*
* Changes
* -------------------------
* 26-Aug-2003 : Initial version
*
*/
package org.jfree.report.modules.gui.config;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.jfree.report.modules.gui.base.components.AbstractActionDowngrade;
import org.jfree.report.modules.gui.base.components.ActionButton;
import org.jfree.report.modules.gui.base.components.ActionRadioButton;
import org.jfree.report.modules.gui.config.model.ClassConfigDescriptionEntry;
import org.jfree.report.modules.gui.config.model.ConfigDescriptionEntry;
import org.jfree.report.modules.gui.config.model.ConfigDescriptionModel;
import org.jfree.report.modules.gui.config.model.EnumConfigDescriptionEntry;
import org.jfree.report.modules.gui.config.model.TextConfigDescriptionEntry;
import org.jfree.report.modules.gui.config.resources.ConfigResources;
import org.jfree.report.util.Log;
import org.jfree.report.util.ReportConfiguration;
import org.jfree.report.util.StringUtil;
import org.jfree.ui.ExtensionFileFilter;
/**
* The config description editor is used to edit the configuration
* metadata used in the ConfigEditor to describe the ReportConfiguration
* keys.
*
* @author Thomas Morgner
*/
public class ConfigDescriptionEditor extends JFrame
{
/** An internal constant to activate the class detail editor. */
private static final String CLASS_DETAIL_EDITOR_NAME = "Class";
/** An internal constant to activate the enumeration detail editor. */
private static final String ENUM_DETAIL_EDITOR_NAME = "Enum";
/** An internal constant to activate the text detail editor. */
private static final String TEXT_DETAIL_EDITOR_NAME = "Text";
/**
* Handles close requests in this editor.
*/
private class CloseAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public CloseAction()
{
putValue(NAME, getResources().getString("action.exit.name"));
}
/**
* Handles the close request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
attempExit();
}
}
/**
* Handles save requests in this editor.
*/
private class SaveAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public SaveAction()
{
putValue(NAME, getResources().getString("action.save.name"));
putValue(SMALL_ICON, getResources().getObject("action.save.small-icon"));
}
/**
* Handles the save request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
save();
}
}
/**
* Handles import requests in this editor. Imports try to build a
* new description model from a given report configuration.
*/
private class ImportAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public ImportAction()
{
putValue(NAME, getResources().getString("action.import.name"));
putValue(SMALL_ICON, getResources().getObject("action.import.small-icon"));
}
/**
* Handles the import request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
final ConfigDescriptionModel model = getModel();
model.importFromConfig(ReportConfiguration.getGlobalConfig());
model.sort();
setStatusText(getResources().getString ("config-description-editor.import-complete"));
}
}
/**
* Handles requests to add a new entry in this editor.
*/
private class AddEntryAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public AddEntryAction()
{
putValue(NAME, getResources().getString("action.add-entry.name"));
putValue(SMALL_ICON, getResources().getObject("action.add-entry.small-icon"));
}
/**
* Handles the add-entry request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
final TextConfigDescriptionEntry te =
new TextConfigDescriptionEntry
(getResources().getString ("config-description-editor.unnamed-entry"));
final ConfigDescriptionModel model = getModel();
model.add(te);
getEntryList().setSelectedIndex(model.getSize() - 1);
}
}
/**
* Handles requests to remove an entry from this editor.
*/
private class RemoveEntryAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public RemoveEntryAction()
{
putValue(NAME, getResources().getString("action.remove-entry.name"));
putValue(SMALL_ICON, getResources().getObject("action.remove-entry.small-icon"));
}
/**
* Handles the remove entry request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
final int[] selectedEntries = getEntryList().getSelectedIndices();
final ConfigDescriptionModel model = getModel();
for (int i = selectedEntries.length - 1; i >= 0; i--)
{
model.remove(model.get(selectedEntries[i]));
}
getEntryList().clearSelection();
}
}
/**
* Handles load requests in this editor.
*/
private class LoadAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public LoadAction()
{
putValue(NAME, getResources().getString("action.load.name"));
putValue(SMALL_ICON, getResources().getObject("action.load.small-icon"));
}
/**
* Handles the laod request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
load();
}
}
/**
* Handles update requests in the detail editor.
*/
private class UpdateAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public UpdateAction()
{
putValue(NAME, getResources().getString ("action.update.name"));
}
/**
* Handles the update request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
updateSelectedEntry();
}
}
/**
* Handles cancel requests in the detail editor.
*/
private class CancelAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public CancelAction()
{
putValue(NAME, getResources().getString ("action.cancel.name"));
}
/**
* Handles the cancel request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
final ConfigDescriptionEntry ce = getSelectedEntry();
setSelectedEntry(null);
setSelectedEntry(ce);
}
}
/**
* Handles editor type selections within the detail editor.
*/
private class SelectTypeAction extends AbstractActionDowngrade
{
/** the selected type. */
private final int type;
/**
* Creates a new select type action for the given name and type.
*
* @param name the name of the action.
* @param type the type that should be selected whenever this action
* gets called.
*/
public SelectTypeAction(final String name, final int type)
{
putValue(NAME, name);
this.type = type;
}
/**
* Handles the select type request.
*
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
setEntryType(type);
}
}
/**
* Handles the list selection in the list of available config keys.
*/
private class ConfigListSelectionListener implements ListSelectionListener
{
/**
* Defaultconstructor.
*/
public ConfigListSelectionListener()
{
}
/**
* Called whenever the value of the selection changes.
* @param e the event that characterizes the change.
*/
public void valueChanged(final ListSelectionEvent e)
{
if (getEntryList().getSelectedIndex() == -1)
{
setSelectedEntry(null);
}
else
{
setSelectedEntry(getModel().get(getEntryList().getSelectedIndex()));
}
}
}
/**
* Handles list selections in the enumeration detail editor.
*/
private class EnumerationListSelectionHandler implements ListSelectionListener
{
/**
* Defaultconstructor.
*/
public EnumerationListSelectionHandler()
{
}
/**
* Called whenever the value of the selection changes.
* @param e the event that characterizes the change.
*/
public void valueChanged(final ListSelectionEvent e)
{
if (getEnumEntryList().getSelectedIndex() == -1)
{
getEnumEntryEditField().setText("");
}
else
{
getEnumEntryEditField().setText((String) getEnumEntryListModel().get
(getEnumEntryList().getSelectedIndex()));
}
}
}
/**
* A ShortCut action to redefine the entries of the enumeration detail
* editor to represent a boolean value.
*/
private class SetBooleanEnumEntryAction extends AbstractActionDowngrade
{
/**
* Defaultconstructor.
*/
public SetBooleanEnumEntryAction()
{
putValue(NAME, getResources().getString ("action.boolean.name"));
}
/**
* Handles the boolean redefinition request.
* @param e not used.
*/
public void actionPerformed(final ActionEvent e)
{
DefaultListModel enumEntryListModel = getEnumEntryListModel();
enumEntryListModel.clear();
getEnumEntryEditField().setText("");
enumEntryListModel.addElement("true");
enumEntryListModel.addElement("false");
}
}
/**
* Handles the request to add a new enumeration entry to the detail
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?