📄 joonedit.java
字号:
package org.joone.edit;/** * JoonEdit * */import java.util.*;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.awt.print.*;import java.io.*;import java.net.*;import javax.help.*;import CH.ifa.draw.standard.*;import CH.ifa.draw.figures.*;import CH.ifa.draw.contrib.*;import CH.ifa.draw.framework.*;import CH.ifa.draw.util.*;import CH.ifa.draw.application.*;import org.joone.net.*;import org.joone.log.*;import org.joone.samples.editor.som.*;/** * This is the main class to start the JoonEdit application. * * @see CH.ifa.draw.application.DrawApplication */public class JoonEdit extends DrawApplication { /** * Logger * */ private static final ILogger log = LoggerFactory.getLogger( JoonEdit.class ); // This release version of Editor private static final int MAJOR_RELEASE = 2; private static final int MINOR_RELEASE = 0; private static final int BUILD = 0; private static final String SUFFIX = "RC1"; public static final String INI_FILE_NAME = "joonedit.config"; // Recommended release version of Engine to function with this Editor private static final int RECO_ENG_MAJOR_RELEASE = 1; private static final int RECO_ENG_MINOR_RELEASE = 2; private static final int RECO_ENG_BUILD = 5; /** * Path where to find the pictures (relatively to where the class files are stored) */ public static final String DIAGRAM_IMAGES = "/org/joone/images/"; public static final String MENU_IMAGES = "/org/joone/images/menu/"; private PropertySheet psp; private InputStream XMLParamsFile; private JooneFileChooser m_openDialog = null; private NetStorageFormatManager fNetStorageFormatManager; private NetStorageFormatManager xNetStorageFormatManager; private ToolsSAXParser tParser; private EditorParameters parameters; private MonitorPropertySheet ps; private static final long serialVersionUID = -4579162097589626753L; private AboutFrame af = null; private TodoFrame tf = null; private StorageFormat latestStorageFormat; private JMacroEditor macroEditor; private IniFile iniFile = null; // Have to keep track of width and height manually // because JHotDraw overrides default size. private int width = 800; private int height = 600; private class httpAuthenticateProxy extends Authenticator { private String userid; private String passw; public httpAuthenticateProxy(String userid, String passw) { this.userid = userid; this.passw = passw; } protected PasswordAuthentication getPasswordAuthentication() { // username, password // sets http authentication return new PasswordAuthentication(userid,passw.toCharArray()); } } /** * Create a new instance of JoonEdit application * @param params Contains the name (with its path) of the XML parameter file * (see org.joone.data.layers.xml for an example) */ public JoonEdit(String params) { super("JoonEdit - Joone Neural Net Editor"); try { initJoonEdit(new FileInputStream(params)); } catch (FileNotFoundException fnfe) { log.fatal( "FileNotFoundException thrown with params " + params + ". Message is " + fnfe.getMessage(), fnfe); System.exit(0); // TO DO Define a proper return code ? } } public JoonEdit() { super("JoonEdit - Joone Neural Net Editor"); InputStream is = getClass().getResourceAsStream("/org/joone/data/layers.xml"); initJoonEdit(is); } private void initJoonEdit(InputStream isParams) { XMLParamsFile = isParams; fNetStorageFormatManager = createNetStorageFormatManager(); xNetStorageFormatManager = createXMLStorageFormatManager(); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Close handled by Joone. readIniFile(); } public static void center(Window frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); frame.setLocation( screenSize.width / 2 - (frameSize.width / 2), screenSize.height / 2 - (frameSize.height / 2)); } protected JComponent createContents(StandardDrawingView view) { JPanel jpan = new JPanel(); jpan.setLayout(new BorderLayout()); JScrollPane rsp = (JScrollPane)super.createContents(view); JPanel ptools = new JPanel(new BorderLayout()); JToolBar[] tools = new JToolBar[2]; for (int i=0; i < tools.length; ++i) { tools[i] = createToolPalette(); } createMyTools(tools); ptools.add(tools[0], BorderLayout.NORTH); ptools.add(tools[1], BorderLayout.SOUTH); jpan.add(ptools, BorderLayout.NORTH); jpan.add(rsp, BorderLayout.CENTER); return jpan; } protected void createTools(JToolBar palette) { super.createTools(palette); palette.addSeparator(); Tool tool = new TextTool(view(), new TextFigure()); palette.add(createToolButton(IMAGES+"TEXT", "Label", tool)); tool = new ConnectedTextTool(view(), new TextFigure()); palette.add(createToolButton(IMAGES+"ATEXT", "Connected Text Tool", tool)); palette.addSeparator(); tool = new CreationTool(view(), new RectangleFigure()); palette.add(createToolButton(IMAGES+"RECT", "Rectangle Tool", tool)); tool = new CreationTool(view(), new RoundRectangleFigure()); palette.add(createToolButton(IMAGES+"RRECT", "Round Rectangle Tool", tool)); tool = new CreationTool(view(), new EllipseFigure()); palette.add(createToolButton(IMAGES+"ELLIPSE", "Ellipse Tool", tool)); tool = new CreationTool(view(), new TriangleFigure()); palette.add(createToolButton(IMAGES+"TRIANGLE", "Triangle Tool", tool)); tool = new CreationTool(view(), new DiamondFigure()); palette.add(createToolButton(IMAGES+"DIAMOND", "Diamond Tool", tool)); tool = new PolygonTool(view()); palette.add(createToolButton(IMAGES+"POLYGON", "Polygon Tool", tool)); tool = new CreationTool(view(), new LineFigure()); palette.add(createToolButton(IMAGES+"LINE", "Line Tool", tool)); tool = new BorderTool(view()); palette.add(createToolButton(IMAGES+"BORDDEC", "Border Tool", tool)); tool = new ScribbleTool(view()); palette.add(createToolButton(IMAGES+"SCRIBBL", "Scribble Tool", tool)); } /** * Create the tools for the toolbar. The tools are * described in the XML file passed as parameter of the application * * @param palette toolbar to which the tools should be added */ protected void createMyTools(JToolBar[] palettes) { LayerFigureCreationTool LFCtool; SynapseCreationTool SCtool; ToolElement te; tParser = new ToolsSAXParser(XMLParamsFile); Vector elements = tParser.getElements(); JToolBar palette = palettes[0]; for (int i=0; i < elements.size(); ++i) { te = (ToolElement)elements.elementAt(i); if (te.getType().compareToIgnoreCase("break") == 0) { palette = palettes[1]; } if (te.getType().compareToIgnoreCase("separator") == 0) { palette.addSeparator(); } if (te.getType().compareToIgnoreCase("layer") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.LayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type")+" layer", LFCtool)); } if (te.getType().compareToIgnoreCase("input_layer") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.InputLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type")+" layer", LFCtool)); } if (te.getType().compareToIgnoreCase("output_layer") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.OutputLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type")+" layer", LFCtool)); } if (te.getType().compareToIgnoreCase("teacher_layer") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.TeacherLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type")+" layer", LFCtool)); } if (te.getType().compareToIgnoreCase("input_plugin") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.InputPluginLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("monitor_plugin") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.MonitorPluginFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("input_switch") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.InputSwitchLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("input_connector") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.InputConnectorLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("output_switch") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.OutputSwitchLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("script_plugin") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.ScriptPluginFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("learning_switch") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.LearningSwitchLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("synapse") == 0) { SCtool = new SynapseCreationTool(view(), "org.joone.edit.LayerConnection"); SCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)SCtool.getParam("image"), "New "+(String)SCtool.getParam("type"), SCtool)); } if (te.getType().compareToIgnoreCase("output_plugin") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.OutputPluginLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } if (te.getType().compareToIgnoreCase("chart_handle") == 0) { LFCtool = new LayerFigureCreationTool(view(), "org.joone.edit.ChartHandleLayerFigure"); LFCtool.setParams(te.getParams()); palette.add(createToolButton(DIAGRAM_IMAGES+(String)LFCtool.getParam("image"), "New "+(String)LFCtool.getParam("type"), LFCtool)); } } } /** * Create a special selection tool which reacts on the right mouse button * to show a popup menu. * * @return selection tool with special behaviour for the right mouse button */ protected Tool createSelectionTool() { DelegationSelectionTool dst = new DelegationSelectionTool(view()); psp = new PropertySheet(500,100); dst.setPropertyPanel(psp); return dst; } /** * Create the menues for a given menu bar. * * @param mb menu bar to which the menus should be added */ protected void createMenus(JMenuBar mb) { mb.add(createFileMenu()); mb.add(createEditMenu()); mb.add(createAlignmentMenu()); mb.add(createAttributesMenu()); mb.add(createToolsMenu()); mb.add(createWindowMenu()); mb.add(createHelpMenu()); } /** * Have to override this because it is hard coded in JHotDraw :-< */ protected Dimension defaultSize() { return new Dimension(width, height);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -