📄 aliasarray.java
字号:
package edu.odu.cs.zeil.AlgAE.Demos.Utils;import edu.odu.cs.zeil.AlgAE.Server.Rendering;import edu.odu.cs.zeil.AlgAE.Server.Visible;import edu.odu.cs.zeil.AlgAE.Server.VisibleRendering;import edu.odu.cs.zeil.AlgAE.Demos.Utils.Alias;import edu.odu.cs.zeil.AlgAE.Demos.Utils.Indexable;import java.awt.Color;/** * Useful class for portraying arrays within algorithm animations. * Since Arrays cannot themselves be made Visible, this class provides * for a separate object that containing an array of aliases for the * components of a conventional array. * * @author Steven Zeil */public class AliasArray implements Visible, Indexable{ private VisibleRendering vr; private Visible[] theArray; private Alias[] aliases; public AliasArray (Visible[] array, Color color, boolean vertical, Color componentColor, boolean componentVertical) { theArray = array; aliases = new Alias[theArray.length]; for (int i = 0; i < theArray.length; ++i) aliases[i] = new Alias (theArray[i], componentColor, componentVertical); vr = new VisibleRendering (this, color, vertical); } /** * Returns the object (alias) at position i **/ public Object elementAt(int i) { return aliasAt(i); } /** * Returns the alias at position i **/ public Alias aliasAt(int i) { if (i >= 0 && i < theArray.length) return aliases[i]; else return null; } /** * Returns the number of elements in this collection **/ public int size() { return theArray.length; } private int inRange (int x, int inclusiveMin, int inclusiveMax) { return (x < inclusiveMin) ? inclusiveMin : ((x > inclusiveMax) ? inclusiveMax : x); } /** * Highlights a range of aliases from start..finish-1 */ public void highlight (int start, int finish, int increment) { start = inRange (start, 0, theArray.length); finish = inRange (finish, 0, theArray.length); for (int i = start; i < finish; i += increment) aliases[i].getRendering().highlight(); } /** * Highlights a range of aliases from start..finish-1 */ public void highlight (int start, int finish, int increment, Color c) { start = inRange (start, 0, theArray.length); finish = inRange (finish, 0, theArray.length); for (int i = start; i < finish; i += increment) aliases[i].getRendering().highlight(c); } /** * unhighlights a range of aliases from start..finish-1 */ public void unHighlight (int start, int finish, int increment) { start = inRange (start, 0, theArray.length); finish = inRange (finish, 0, theArray.length); for (int i = start; i < finish; i += increment) aliases[i].getRendering().unHighlight(); } /** * Changes colors of range of aliases from start..finish-1 */ public void setColor (int start, int finish, int increment, Color c) { start = inRange (start, 0, theArray.length); finish = inRange (finish, 0, theArray.length); for (int i = start; i < finish; i += increment) aliases[i].getRendering().setColor(c); } /** * This function returns the VisibleRendering data member * * @return the rendering information for this object. **/ public Rendering getRendering() { return vr; } /** * Produce the text string to be displayed in the picture of the object. * * @return the text string to be displayed **/ public String getAlgAEText() { return ""; } /** * If an object <CODE>s</CODE> is to be portrayed as having * pointers/references/arrows to other Visible objects, then when * <CODE>s.touchAllPointers()</CODE> is called, * the body of <CODE>touchAllPointers</CODE> should call, for each arrow * from <CODE>s</CODE> to another Visible object <CODE>p</CODE>, * <CODE>s.getRendering().touch(p, dir)</CODE> or * <CODE>s.getRendering().touch(p, dir, label)</CODE>. * <P> * <CODE>dir</CODE> is the "exit" direction from which the AlgAE system * will draw the arrow from <CODE>s</CODE> to <CODE>p</CODE>. **/ public void touchAllPointers() { } /** * If an object <CODE>s</CODE> is to be portrayed as a compound structure * containing other Visible objects, then when * <CODE>s.touchAllComponents()</CODE> is called, * the body of <CODE>touchAllComponents</CODE> should call, for each * contained Visible component <CODE>p</CODE>, * <CODE>s.getRendering().touch(p)</CODE>. * <P> * Note that the the distinction between a "Pointer" and a "Component" * is a logical distinction, as they are both typically implemented as * simple data members of the Visible class. It is up to the designer * of the algorithm animation to decide what to portray as references and * what to portray as contained components. **/ public void touchAllComponents() { for (int i = 0; i < theArray.length; ++i) { Visible v = theArray[i]; aliases[i].setAliased (v); vr.touch (aliases[i]); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -