📄 alganimframe.java
字号:
* @see AlgAnimFrame#getComPanel * @param n The text field to display the string. First is <b>0</b>. * @param s The string to be displayed. */ public void setText( int n, String s ) { cpanel.setText( n, s ); } /** * Highlights the specified line of the source code on the text panel. * If the line is beyond the scroll pane, it will be scrolled to the * center of the window. * @param n The line to be highlighted. */ public void Highlight( int n ) { if (tf.getTextPanel().getNumLines() < 1) return; if (!((Component)tf).isShowing()) return; tf.getTextPanel().Highlight(n); int numLineVisible = tf.getTextPanel().size().height/tf.getTextPanel().getLineSpace(); if ( (n < (tf.getTextPanel().getStart() + 2)) || (n > (tf.getTextPanel().getStart() + numLineVisible - 2))) { int max = tf.getVertScrollbar().getMaximum(); int min = tf.getVertScrollbar().getMinimum(); int startLine = n - numLineVisible/2; if (startLine > 0) { tf.getTextPanel().setStart(startLine); tf.getVertScrollbar().setValue(startLine * (max - min) / tf.getTextPanel().getNumLines()); } else { tf.getTextPanel().setStart(0); tf.getVertScrollbar().setValue(0); } } try { Thread.sleep(delay/4); } catch (InterruptedException e) {} } /** * Restore the drawing panel at the end of the animation or during * initialization. */ public void restoreDrawingPanel() { alg.restoreDrawingPanel(); } /** * Start the animation algorithm if the <b>run</b> or <b>step</b> * button is pressed. */ public void startAlg() { if (!stepWait) { ((ImageButton)runItem).setDisable(); dataMenu.disable(); } ((ImageButton)stopItem).setEnable(); ((ImageButton)stepItem).setEnable(); if (alg.isAlive() && !stepWait) { alg.stop(); alg = new AlgThread(this); alg.start(); } else if (alg.isAlive() && stepWait) { //alg.resume(); step = !step; stepWait = false; } else { // alg.isAlive() == false alg = new AlgThread(this); alg.start(); } } /** * This method is invoked at the end of the animation or when * the <b>stop</b> button is pressed. It restores the buttons * status on the control panel. */ public void finishAlg() { ((ImageButton)stopItem).setDisable(); ((ImageButton)runItem).setEnable(); ((ImageButton)skipItem).setEnable(); dataMenu.enable(); ((ImageButton)stepItem).setEnable(); step = false; alg.restoreDrawingPanel(); } /** * This method is called when the <b>step</b> execution mode is used. * It is normally added to the line where the execution will wait * for the <b>step</b> button to be pressed. */ public void waitStep() { if (step) { setText(0, "Click NEXT STEP..."); ((ImageButton)stepItem).setEnable(); repaint(); step = false; stepWait = true; while (!step) { try { Thread.sleep(100); } catch (InterruptedException e) {} } if (!stepWait) step = false; } } /** * This method is called when the <b>skip</b> execution mode is used. * It is normally added to the line where the execution will wait * after the <b>skip</b> button to be pressed. */ public void waitSkip() { alg.waitSkip(); } /** * Sets the attribute which indicate if the <b>skip</b> execution * mode is current. */ public void setSkip(boolean skip) { dpAfter.setSkip(skip); } /** * Sets the attribute which indicate if the <b>step</b> execution * mode is current. */ public void setStep(boolean step) { //setText(2, "Stepping through the next line(s)..."); this.step = step; ((ImageButton)stepItem).setDisable(); ((ImageButton)runItem).setEnable(); dataMenu.enable(); if (step) { ((ImageButton)stepItem).setDisable(); stepWait = true; } else stepWait = false; } /** * Returns the reference to the AlgThread which contains the details and * execution sequences of the algorithm. * @see AlgThread */ public AlgThread getAlg() { return alg; } /** * Set the delay for highlighting text. */ public void setDelay(int delay) { this.delay = delay; } /** * Get the delay for highlighting text. */ public int getDelay() { return delay; } /** * Get the applet which contains a button to start up this window. * @return Returns the applet which contains the button to start up * this window. */ public AlgAnimApp getApplet() { return parentApp; } /** * Returns an instance of the drawing panel which is cast to its super class * <code>Panel</code>. */ public DrawingPanel getDrawingPanel() { return dpAfter; } public DrawingPanel getBeforeDp() { return dpBefore; } /** * Sets the drawing panel which is cast to its super class * <code>Panel</code>. This instance is used to set the GridBagConstraint * of the layout manager. * @see DrawingPanel */ public void setDrawingPanel(DrawingPanel panel) { this.dpAfter = panel; } /** * Returns an instance of the <code>TextFrame</code> used to set the layout * constraints and highlight certain lines of the source code. * @see TextFrame */ public TextFrame getTextFrame() { return tf; } /** * Get the commentary panel that displays messages of any type. * @return Commentary panel, in which each text field within can be set to * display text string from this class. * @see ComPanel */ public ComPanel getComPanel() { return cpanel; } /** * Get the index of selected choice from the 'Select' pull menu. * @return The choice of the data selected. */ public int getDataChoice() { return dataSelected; } /** * Get the skip button from the control panel. * @return The skip button. */ public Button getSkipItem() { return skipItem; } /** * Get the run button from the control panel. * @return The run button. */ public Button getRunItem() { return runItem; } /** * Get the stop button from the control panel. * @return The stop button. */ public Button getStopItem() { return stopItem; } /** * Obtain the status of the preferred animation style. * @return True is the animation is kept to a minimum for the animated * algorithm; false otherwise. */ public boolean isNoAnim() { return noAnim; } /** * Get the menu item which specify if the animation is enabled. * @return The checkbox menu item to enable the Animation of the alg. */ public CheckboxMenuItem getEnableAnim() { return enableAnim; } /** * Get the menu item which specify if the animation is disabled. * @return The checkbox menu item to disable the Animation of the alg. */ public CheckboxMenuItem getDisableAnim() { return disableAnim; }} // class AlgAnimApp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -