📄 joonedit.java
字号:
JFileChooser saveDialog; if (getDrawingTitle() == null || getDrawingTitle().equals("")) { saveDialog = createSaveFileChooser(); } else { saveDialog = new JFileChooser(getDrawingTitle()); saveDialog.setDialogTitle("Save File..."); } getNetStorageFormatManager().registerFileFilters(saveDialog); if (saveDialog.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { NetStorageFormat foundFormat = getNetStorageFormatManager().findStorageFormat(saveDialog.getFileFilter()); if (foundFormat != null) { saveNeuralNet(foundFormat, saveDialog.getSelectedFile().getAbsolutePath()); // Disable automatic Save, require SaveAs after this. latestStorageFormat = null;// ((JooneStandardDrawingView)view()).setModified(false); } else { showStatus("Not a valid file format: " + saveDialog.getFileFilter().getDescription()); } } } /** * Shows a file dialog and saves the NeuralNet. */ public void promptSaveAsXML() { toolDone(); JFileChooser saveDialog; if (getDrawingTitle() == null || getDrawingTitle().equals("")) { saveDialog = createSaveFileChooser(); } else { saveDialog = new JFileChooser(getDrawingTitle()); saveDialog.setDialogTitle("Save File..."); } getXMLStorageFormatManager().registerFileFilters(saveDialog); if (saveDialog.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { NetStorageFormat foundFormat = getXMLStorageFormatManager().findStorageFormat(saveDialog.getFileFilter()); if (foundFormat != null) { saveNeuralNet(foundFormat, saveDialog.getSelectedFile().getAbsolutePath()); // Disable automatic Save, require SaveAs after this. latestStorageFormat = null;// ((JooneStandardDrawingView)view()).setModified(false); } else { showStatus("Not a valid file format: " + saveDialog.getFileFilter().getDescription()); } } } /** * Save a NeuralNet in a file */ protected void saveNeuralNet(NetStorageFormat storeFormat, String file) { try { NeuralNetDrawing nnd = (NeuralNetDrawing)drawing(); NeuralNet nn = nnd.getNeuralNet(); nn.getMonitor().setExporting(true);// setDrawingTitle(storeFormat.store(file, nn)); storeFormat.store(file, nn); nn.getMonitor().setExporting(false); } catch (IOException e) { showStatus(e.toString()); } } /** * The additional feature that is found in this * createOpenFileChooser is the ability to maintance * a list of history of directories that the user * has access previously, which is not found in the * original createOpenFileChooser and the ability * to preview the content of a text file. */ protected JFileChooser createOpenFileChooser(String fn) { if (m_openDialog == null) { m_openDialog = new JooneFileChooser(fn); } return m_openDialog; } protected JFileChooser createOpenFileChooser() { if (m_openDialog == null) { m_openDialog = new JooneFileChooser(); } return m_openDialog; } public StorageFormatManager createStorageFormatManager() { StorageFormatManager storageFormatManager = new StorageFormatManager(); storageFormatManager.setDefaultStorageFormat(new SerializationStorageFormat()); storageFormatManager.addStorageFormat(storageFormatManager.getDefaultStorageFormat()); return storageFormatManager; } public NetStorageFormatManager createNetStorageFormatManager() { NetStorageFormatManager storageFormatManager = new NetStorageFormatManager(); storageFormatManager.setDefaultStorageFormat(new StandardNetStorageFormat()); storageFormatManager.addStorageFormat(storageFormatManager.getDefaultStorageFormat()); return storageFormatManager; } public NetStorageFormatManager createXMLStorageFormatManager() { NetStorageFormatManager storageFormatManager = new NetStorageFormatManager(); storageFormatManager.setDefaultStorageFormat(new XMLNetStorageFormat()); storageFormatManager.addStorageFormat(storageFormatManager.getDefaultStorageFormat()); return storageFormatManager; } /** * Set the NetStorageFormatManager for binary format * The NetStorageFormatManager is used when storing and * restoring NeuralNets from the file system. */ private void setNetStorageFormatManager(NetStorageFormatManager storageFormatManager) { fNetStorageFormatManager = storageFormatManager; } /** * Return the NetStorageFormatManager for this application. * The NetStorageFormatManager is * used when storing and restoring NeuralNets from the file system. */ public NetStorageFormatManager getNetStorageFormatManager() { return fNetStorageFormatManager; } /** * Set the NetStorageFormatManager for XML format * The NetStorageFormatManager is used when storing and * restoring NeuralNets from the file system. */ private void setXMLStorageFormatManager(NetStorageFormatManager storageFormatManager) { xNetStorageFormatManager = storageFormatManager; } /** * Return the NetStorageFormatManager for this application. * The NetStorageFormatManager is * used when storing and restoring NeuralNets from the file system. */ public NetStorageFormatManager getXMLStorageFormatManager() { return xNetStorageFormatManager; } protected Drawing createDrawing() { return new NeuralNetDrawing(); } /** * Creates the drawing view used in this application. * You need to override this method to use a DrawingView * subclass in your application. By default a standard * DrawingView is returned. * @return the DrawingView */ protected StandardDrawingView createDrawingView() { Dimension d = getDrawingViewSize(); JooneStandardDrawingView newView = new JooneStandardDrawingView(this, d.width, d.height); newView.setBackground(Color.lightGray); return newView; } /** * Load a Drawing from a file */ protected void loadDrawing(StorageFormat restoreFormat, String file) { try { Drawing restoredDrawing = restoreFormat.restore(file); if (restoredDrawing != null) { //newWindow(); setDrawing(restoredDrawing); setDrawingTitle(file); } else { showStatus("Unknown file type: could not open file '" + file + "'"); } } catch (IOException e) { showStatus("Error: " + e); } } /** * Start the application by creating an instance and open * the editor window. * @param args Command arguments */ public static void main(String[] args) { if (args.length == 0) { JoonEdit window = new JoonEdit(); window.open(); } else { JoonEdit window = new JoonEdit(args[0]); window.open(); } } /** * Resets the NN to a new empty net. */ public void promptNew() { super.promptNew(); if (psp != null) { psp.setVisible(false); psp = null; } if (ps != null) { ps.setVisible(false); ps = null; } NeuralNetDrawing nnd = (NeuralNetDrawing)drawing(); nnd.setNeuralNet(new NeuralNet()); LayerFigure.setNumLayers(0); if (macroEditor != null) { macroEditor.setVisible(false); macroEditor = null; } ((JooneStandardDrawingView)view()).setModified(false); } /** * Opens the window and initializes its contents. */ public void open() { // Splash Screen URL url = JoonEdit.class.getResource(JoonEdit.DIAGRAM_IMAGES + "splash.gif") ; final ImageIcon img = new ImageIcon(url); JWindow frame = new JWindow(); JLabel info = new JLabel("Initializing....", SwingConstants.CENTER); info.setForeground(Color.black); try { //frame.setUndecorated(true); // JDK 1.3 JLabel pan = new JLabel(img) { public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setFont(new Font("Arial", Font.BOLD, 10)); g2.drawString("Neural Network Editor",15,145); g2.drawString("v " + getVersion(), 45, 158); g2.drawString( "(c) " + Calendar.getInstance().get(Calendar.YEAR) + " Paolo Marrone", 10, 171); } }; frame.getContentPane().add(pan, BorderLayout.CENTER); pan.setLayout(new BorderLayout()); pan.add(info, BorderLayout.SOUTH); pan.setBorder(BorderFactory.createRaisedBevelBorder()); info.setPreferredSize(new Dimension(pan.getWidth(), 24)); frame.pack(); center(frame); frame.setVisible(true); info.setText("Starting..."); // Prepare and open the main window super.open(); readParameters(); Iconkit kit = Iconkit.instance(); if (kit == null) throw new HJDError("Iconkit instance isn't set"); final Image icn = kit.loadImageResource(JoonEdit.DIAGRAM_IMAGES + "JooneIcon.gif"); this.setIconImage(icn); ((JooneStandardDrawingView)view()).setModified(false); } catch (Exception e) { info.setText(e.getMessage()); e.printStackTrace(); System.err.println(e.getMessage()); } finally { frame.dispose(); } } private void readParameters() { parameters = new EditorParameters(); ToolElement te; Vector elements = tParser.getElements(); for (int i=0; i < elements.size(); ++i) { te = (ToolElement)elements.elementAt(i); if (te.getType().compareToIgnoreCase("refreshing_rate") == 0) parameters.setRefreshingRate(Integer.parseInt((String)te.getParam("value"))); if (te.getType().compareToIgnoreCase("http_proxy") == 0) { String hostname = (String)te.getParam("host"); String port = (String)te.getParam("port"); String userid = (String)te.getParam("userid"); String passw = (String)te.getParam("passw"); log.info("Using proxy: http://"+hostname+":"+port); System.setProperty("proxySet", "true" ); System.setProperty("http.proxyHost", hostname ); System.setProperty("http.proxyPort", port ); Authenticator.setDefault( new httpAuthenticateProxy(userid, passw) ); } } } /** * Method to get the version. */ public static String getVersion() { return MAJOR_RELEASE + "." + MINOR_RELEASE + "." + BUILD + SUFFIX; } /** * Method to get the numeric version. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -