📄 viewerpanel.java
字号:
application.msgs.stdin.addMessageListener (showStdIO); } public ViewerPanel(String theTitle, Application appl, DataPane datapane, SourcePane sourcepane, IOPane iopane, MessageDispatcher theDispatcher, boolean wide, boolean doAutoArrange, int initialFontSize, String helpString, int theFramePause, int theAlgorithmPause, Button menusButton, Vector menuBar) { application = appl; dataPane = datapane; sourcePane = sourcepane; ioPane = iopane; dispatcher = theDispatcher; pausingAtFrames = true; showDataPane = false; showSourcePane = false; showIOPane = false; wideGraphics = wide; helpCommand = helpString; aboutString = ""; framePause = theFramePause; algorithmPause = theAlgorithmPause; buildMenu(sourcePane.getMenuItems(), menuBar); if (application.dataWindow != null) application.dataWindow.setTitle(theTitle); setLayout(new BorderLayout()); ActionListener cont = new ActionListener() { public void actionPerformed(ActionEvent e) { continueAnimation(); }}; ItemListener pause = new ItemListener() { public void itemStateChanged (ItemEvent e) { Checkbox box = (Checkbox)(e.getSource()); pausing (box.getState()); } }; ActionListener setFont = new ActionListener() { public void actionPerformed(ActionEvent e) { FontSizeWidget w = (FontSizeWidget)(e.getSource()); dispatcher.addPriorityMessage (new ParameterizedMessage (application.msgs.changeFontSize, w.getValue())); } }; application.msgs.changeFontSize.addMessageListener (new MessageListener() { public void messageReceived (String kind, Vector params) { Integer sz = (Integer)params.elementAt(0); setFontSize (sz.intValue()); } }); ItemListener auto = new ItemListener() { public void itemStateChanged (ItemEvent e) { Checkbox box = (Checkbox)(e.getSource()); autoArranging(box.getState()); } }; ActionListener doArrange = new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (dispatcher) { dataPane.forceArrangeData(); } } }; toolBar = new Toolbar (cont, pause, setFont, auto, doArrange, menusButton, initialFontSize, doAutoArrange, (framePause >= 0)); add ("North", toolBar); KeyAdapter shortcuts = new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); Debug.show (Debug.events, "data panel Key event: " + e); if (e.isAltDown()) { if (c == 'r') arrangeData(); else if ((c == 'c') && continueItem.isEnabled()) continueAnimation(); } } }; dataPane.addKeyListener(shortcuts); sourcePane.addKeyListener(shortcuts); datapane.requestFocus(); pausing (true); autoArranging (doAutoArrange); dataPane.setFontSize (initialFontSize); sourcePane.setFontSize (initialFontSize); ioPane.setFontSize (initialFontSize); setMessageResponses(); // Initially, display data and source panes, but not I/O splitPane = null; configurePanes (wide, true, sourcePane.getNumberOfFiles() > 0, false); } private void printCanvas () { /* Toolkit tk = Toolkit.getDefaultToolkit(); PrintJob pjob = tk.getPrintJob (this, "AlgAE", null); DVGraphicsInfo dvgi = dataPane.graphicsInfo(); Graphics saved = dvgi.g; dvgi.g = pjob.getGraphics(); ((DataCanvas)dataPane.getCanvas()).graph.draw(dvgi.g); pjob.end(); dvgi.g = saved; */ FileDialog fd = new FileDialog (application.dialogParent(), "Save Postscript at", FileDialog.SAVE); fd.show(); application.dialogDone(); String fullFileName = fd.getDirectory() + fd.getFile(); try { OutputStream psOut = new BufferedOutputStream (new FileOutputStream (fullFileName)); GraphicsInfo gi = dispatcher.getGraphics(); PSGr psg = new PSGr (psOut, gi.getCanvas().getGraphics()); Graphics saved = gi.g; psg.setFont (saved.getFont()); gi.g = psg; ((DataCanvas)dataPane.getCanvas()).graph.display(gi); psOut.close(); gi.g = saved; } catch (java.io.IOException e) {Debug.error ("Unable to open " + fullFileName + "\nfor postscript output"); } } private void showHelp() { if (application.isAnApplet()) { try { URL url = new URL(helpCommand); application.applet.getAppletContext().showDocument (url, "AlgAE Help"); } catch (java.net.MalformedURLException e) { Debug.error ("Cannot display help document: " + helpCommand + "\n\n" + e); } } else { // Execute the help string as a command try { Runtime.getRuntime().exec (helpCommand); } catch (IOException e) { Debug.error ("Cannot execute help command: " + helpCommand + "\n\n" + e); } catch (SecurityException e) { Debug.error ("Cannot execute help command: " + helpCommand + "\n\n" + e); } } } private void isolatePane (Component pane) { if (pane.getParent() != null) { pane.getParent().remove (pane); pane.setVisible (false); } } private void configurePanes (boolean wideGraphics0, boolean showDataPane0, boolean showSourcePane0, boolean showIOPane0) { if ((wideGraphics0 != wideGraphics) || (showDataPane0 != showDataPane) || (showSourcePane0 != showSourcePane) || (showIOPane0 != showIOPane) || (splitPane == null)) { if (splitPane != null) { isolatePane (dataPane); isolatePane (sourcePane); isolatePane (ioPane); remove (splitPane); } wideGraphics = wideGraphics0; showDataPane = showDataPane0; showSourcePane = showSourcePane0; showIOPane = showIOPane0; int paneCount = 0; if (showDataPane0) ++paneCount; if (showSourcePane0) ++paneCount; if (showIOPane0) ++paneCount; switch (paneCount) { case 0: // Have to display SOMETHING! showDataPane = true; case 1: // Showing a single pane if (showDataPane) splitPane = dataPane; else if (showSourcePane) splitPane = sourcePane; else // if (showIOPane) splitPane = ioPane; splitPane.setVisible (true); break; case 2: // Showing 2 of the 3 panes if (!showDataPane) { // show source and IO sourcePane.setVisible (true); ioPane.setVisible (true); if (wideGraphics) splitPane = new HSplitPane (sourcePane, ioPane, 0.66); else splitPane = new VSplitPane (sourcePane, ioPane, 0.66); } else if (!showSourcePane) { // show data and IO dataPane.setVisible (true); ioPane.setVisible (true); if (wideGraphics) splitPane = new VSplitPane (dataPane, ioPane, 0.66); else splitPane = new HSplitPane (dataPane, ioPane, 0.66); } else { // show data and source dataPane.setVisible (true); sourcePane.setVisible (true); if (wideGraphics) splitPane = new VSplitPane (dataPane, sourcePane, 0.6); else splitPane = new HSplitPane (dataPane, sourcePane, 0.6); } break; case 3: // Showing all panes dataPane.setVisible (true); sourcePane.setVisible (true); ioPane.setVisible (true); if (wideGraphics) { HSplitPane hpane = new HSplitPane (sourcePane, ioPane, 0.66); splitPane = new VSplitPane (dataPane, hpane, 0.6); } else { VSplitPane vpane = new VSplitPane (sourcePane, ioPane, 0.66); splitPane = new HSplitPane (dataPane, vpane, 0.6); } } add ("Center", splitPane); showDataItem.setState (showDataPane); showSourceItem.setState (showSourcePane); showIOItem.setState (showIOPane); invalidate(); validate(); repaint(); } } private void speedSettings() { if (speedDialog == null) speedDialog = new SpeedDialog(application.dialogParent()); synchronized (dispatcher) { GraphicsInfo dvgi = dispatcher.getGraphics(); dvgi.cancelInterpolation(); speedDialog.setNumSteps (dvgi.getInterpolationTotal()); speedDialog.setStepInterval (dispatcher.getInterpolationInterval()/1000.0); speedDialog.setAutoArrange (dvgi.autoArranging); speedDialog.setArrangeEffort (dvgi.repositionEffort); speedDialog.setVisible(true); int nSteps = speedDialog.getNumSteps(); dvgi.setInterpolation (nSteps, nSteps); dispatcher.setInterpolationInterval (speedDialog.getStepInterval ()); if (dvgi.autoArranging != speedDialog.getAutoArrange ()) autoArranging (speedDialog.getAutoArrange ()); dvgi.repositionEffort = speedDialog.getArrangeEffort (); application.dialogDone(); } } public void pausing (boolean b) { Debug.show (Debug.messageSynch, "ViewerPanel.pausing: ", b); synchronized (dispatcher) { if (b != pausingAtFrames) { toolBar.setPausing (b); pausingItem.setState (b); repaint(); pausingAtFrames = b; ParameterizedMessage pmsg = (b) ? new ParameterizedMessage(application.msgs.pausing) : new ParameterizedMessage(application.msgs.nopausing); dispatcher.send (pmsg); } } } public void autoArranging (boolean b) { Debug.show (Debug.messageSynch, "ViewerPanel.autoArr: ", b); synchronized (dispatcher) { toolBar.setAutoArranging (b); autoArrangeItem.setState (b); repaint(); dataPane.setAutoArranging (b); } } Toolbar getToolbar() { return toolBar; } private void setFontSize (int size) { dataPane.setFontSize (size); sourcePane.setFontSize (size); ioPane.setFontSize (size); Debug.show (Debug.messageSynch, "VP.setFontSize size: " + size + "\tauto: " + dataPane.getAutoArranging()); arrangeData(); } private void setFontSize() { FontDialog d = new FontDialog(application.dialogParent(), dataPane.fontSize()); application.dialogDone(); setFontSize(d.getFontSize()); } int continueCount = 0; private void continueAnimation() { continueItem.setEnabled (false); toolBar.disableContinue(); dispatcher.permitContinuation(); dispatcher.send (new ParameterizedMessage(application.msgs.continuing)); } private void arrangeData() { dataPane.arrangeData(); dataPane.repaint(); } /** * A thread used by the replay tool used to simulate a user pressing * the continue button and other user input. * * @author Steven J. Zeil */ class InputSimulator extends Thread { private int interval; /** * Construct a timer thread. */ InputSimulator (int seconds) { super("InputSimulator"); Debug.show (Debug.timer, "InputSimulator constructed"); interval = seconds; } /** * Start the clock ticking. */ public void run() { Debug.show (Debug.timer, "Starting thread\n"); try { sleep(1000*interval); } catch (InterruptedException e) {} continueAnimation(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -