📄 jfreereportdesigner.java
字号:
/**
* ========================================================================================
* JFreeReport Designer : a graphical designer for JFreeReport - a free Java report library
* ========================================================================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner (taquera@sherito.org);
*
* (C) Copyright 2003, by Heiko Evermann (heiko@evermann.de) 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.
*
*/
package org.jfree.designer;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyEditorManager;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jfree.designer.db.DataPanel;
import org.jfree.designer.prefs.PreferencesDialog;
import org.jfree.designer.propertyeditors.BooleanPropertyEditor;
import org.jfree.designer.resources.ResourceBundleUtils;
import org.jfree.designer.text.TextEditPanel;
import org.jfree.designer.util.AbstractDesignerAction;
import org.jfree.designer.util.DowngradeActionMap;
import org.jfree.designer.visualeditor.VisualEditPanel;
import org.jfree.report.Boot;
import org.jfree.report.JFreeReport;
import org.jfree.report.modules.gui.base.components.ActionDowngrade;
import org.jfree.report.util.ImageUtils;
import org.jfree.report.util.Log;
import org.jfree.ui.ExtensionFileFilter;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.about.AboutFrame;
import org.jfree.util.Configuration;
import org.jfree.util.DefaultConfiguration;
public final class JFreeReportDesigner
extends JFrame
{
public static final String ABOUT_ACTION_KEY = "About";
public static final String DATABASE_ACTION_KEY = "Database";
public static final String EXIT_ACTION_KEY = "Exit";
public static final String NEW_REPORT_ACTION_KEY = "NewReport";
public static final String OPEN_REPORT_ACTION_KEY = "OpenReport";
public static final String PREFERENCES_ACTION_KEY = "Preferences";
public static final String REOPEN_REPORT_ACTION_KEY = "ReopenReport";
public static final String SAVE_AS_ACTION_KEY = "SaveAsReport";
public static final String SAVE_ACTION_KEY = "SaveReport";
private static final String RESOURCE_BASE_NAME =
"org.jfree.designer.resources.designer-resources";
private final class ExitAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public ExitAction ()
{
putValue(AbstractDesignerAction.NAME, resources.getString("action.exit.Name"));
putValue(ActionDowngrade.ACCELERATOR_KEY,
ResourceBundleUtils.createMenuKeystroke(resources.getString("action.exit.KeyStroke")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
windowExit();
}
}
private final class PreferencesAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public PreferencesAction ()
{
putValue(Action.NAME, resources.getString("action.preferences.Name"));
putValue(Action.SMALL_ICON,
ResourceBundleUtils.getIcon(resources.getString("action.preferences.SmallIcon")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
final PreferencesDialog d = new PreferencesDialog();
d.setLocationRelativeTo(JFreeReportDesigner.this);
d.show();
}
}
private final class DatabaseAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public DatabaseAction ()
{
putValue(Action.NAME, resources.getString("action.database.Name"));
putValue(ActionDowngrade.ACCELERATOR_KEY,
ResourceBundleUtils.createMenuKeystroke(resources.getString("action.database.KeyStroke")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
showMessageDialog("This feature is not yet implemented",
JOptionPane.ERROR_MESSAGE);
}
}
private final class AboutAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public AboutAction ()
{
putValue(Action.NAME, resources.getString("action.about.Name"));
putValue(Action.SMALL_ICON,
ResourceBundleUtils.getIcon(resources.getString("action.about.SmallIcon")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
final AboutFrame d = new AboutFrame(resources.getString("about.Title"),
JFreeReportDesignerInfo.getInstance());
//d.setLocationRelativeTo(JFreeReportDesigner.this);
d.show();
}
}
private final class NewReportAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public NewReportAction ()
{
putValue(Action.NAME, resources.getString("action.new-report.Name"));
putValue(Action.SMALL_ICON,
ResourceBundleUtils.getIcon(resources.getString("action.new-report.SmallIcon")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
newReport();
}
}
private final class OpenReportAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public OpenReportAction ()
{
putValue(Action.NAME, resources.getString("action.open-report.Name"));
putValue(Action.SMALL_ICON,
ResourceBundleUtils.getIcon(resources.getString("action.open-report.SmallIcon")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
openReport();
}
}
private final class ReopenReportAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public ReopenReportAction ()
{
putValue(Action.NAME, resources.getString("action.reopen-report.Name"));
putValue(Action.SMALL_ICON,
ResourceBundleUtils.getIcon(resources.getString("action.reopen-report.SmallIcon")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
reopenReport();
}
}
private final class SaveReportAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public SaveReportAction ()
{
putValue(Action.NAME, resources.getString("action.save-report.Name"));
putValue(Action.SMALL_ICON,
ResourceBundleUtils.getIcon(resources.getString("action.save-report.SmallIcon")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
saveReport();
}
}
private final class SaveAsReportAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public SaveAsReportAction ()
{
putValue(Action.NAME, resources.getString("action.save-report-as.Name"));
putValue(Action.SMALL_ICON,
ResourceBundleUtils.getIcon(resources.getString("action.save-report-as.SmallIcon")));
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
currentFile = null; // make saveReport ask again
saveReport();
}
}
private final class RecentFileAction
extends AbstractDesignerAction
{
/**
* Defines an <code>Action</code> object with a default description string and default
* icon.
*/
public RecentFileAction (final String filename)
{
putValue(Action.NAME, filename);
}
/**
* Invoked when an action occurs.
*/
public final void actionPerformed (final ActionEvent e)
{
loadReport(new File(getName()));
}
}
private final class TabChangeHandler
implements ChangeListener
{
private final JTabbedPane pane;
public TabChangeHandler (final JTabbedPane pane)
{
this.pane = pane;
}
/**
* Invoked when the target of the listener has changed its state.
*
* @param e a ChangeEvent object
*/
public final void stateChanged (final ChangeEvent e)
{
setSelectedEditor(pane.getSelectedIndex());
}
}
private static final class RootEditorContainer
{
private final JMenuBar editorMenuBar;
private final RootEditor editor;
public RootEditorContainer (final RootEditor editor,
final JMenuBar editorMenuBar)
{
this.editorMenuBar = editorMenuBar;
this.editor = editor;
}
public final JMenuBar getEditorMenuBar ()
{
return editorMenuBar;
}
public final RootEditor getEditor ()
{
return editor;
}
public final JToolBar getEditorToolbar ()
{
return editor.getToolbar();
}
}
// the tabbed pane
private JTabbedPane tabbedPane;
private RootEditorContainer[] rootEditors;
private int selectedRootEditor;
private JMenu menuReopen;
private ReopenReportAction reopenAction;
private File currentFile;
private JFileChooser fileChooser;
private ReportDefinitionManager reportDefinitionManager;
private DowngradeActionMap globalActions;
private JPanel toolbarContainer;
private JToolBar currentToolbar;
private ResourceBundle resources;
private ArrayList fileNames;
private final int MAX_RECENT_FILES = 5;
public JFreeReportDesigner ()
{
fileNames = new ArrayList();
resources = ResourceBundle.getBundle(RESOURCE_BASE_NAME);
fileChooser = new JFileChooser();
fileChooser.setFileFilter(new ExtensionFileFilter("Report definitions", ".xml"));
setTitle("JFreeReportDesigner");
initActions();
addWindowListener(new WindowAdapter()
{
public void windowClosing (final WindowEvent e)
{
windowExit();
}
});
// initialize Data
try
{
reportDefinitionManager = new ReportDefinitionManager
(new File(".").toURL(), globalActions);
}
catch (IOException ioe)
{
throw new RuntimeException("[RA] Failed to initialize.");
}
selectedRootEditor = -1;
// before the initialize is done, so that we have a clean initial state in the report definition manager
newReport();
if (reportDefinitionManager.getReportDefinitionText() == null)
{
throw new IllegalStateException();
}
initialize();
// just a dirty way to speed up testing ..
// loadReport (new File ("/home/user/jfreereport-demo/report2.xml"));
setSelectedEditor(0);
}
private void initActions ()
{
globalActions = new DowngradeActionMap();
globalActions.put(ABOUT_ACTION_KEY, new AboutAction());
globalActions.put(DATABASE_ACTION_KEY, new DatabaseAction());
globalActions.put(EXIT_ACTION_KEY, new ExitAction());
globalActions.put(NEW_REPORT_ACTION_KEY, new NewReportAction());
globalActions.put(OPEN_REPORT_ACTION_KEY, new OpenReportAction());
globalActions.put(PREFERENCES_ACTION_KEY, new PreferencesAction());
globalActions.put(REOPEN_REPORT_ACTION_KEY, new ReopenReportAction());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -