|
SimpleListDemo
ListView.java
import aLibrary.*;
import java.awt.*;
public class ListView extends AView {
private MyList dispList;
//------------------------------------------------------------------------------
public ListView(MyList l) {
super(25,25,800,100);
dispList = l;
int j=dispList.index();
drawPointer(70*j+5,20);
dispList.start();
for(int i=0; i<dispList.count(); i++) {
drawArrow(70*i,13,30);
drawItem(70*i+30,0,40,25,dispList.item());
dispList.forth();
}
dispList.start();
for(int i=0;i<j;i++)
dispList.forth();
}
//------------------------------------------------------------------------------
private void drawArrow(int x,int y,int l) {
ALine arrowB, arrowH1, arrowH2;
arrowB = new ALine(x,y,x+l,y);
arrowH1 = new ALine(x+l,y,x+l-6,y-4);
arrowH2 = new ALine(x+l,y,x+l-6,y+4);
arrowB.place(this);
arrowH1.place(this);
arrowH2.place(this);
}
//------------------------------------------------------------------------------
private void drawItem(int x,int y,int w,int h,Object A) {
ARectangle outerRect, innerRect;
innerRect = new ARectangle(x,y,w,h);
innerRect.setColor(Color.lightGray);
innerRect.setToFill();
outerRect = new ARectangle(x,y,w,h);
innerRect.place(this);
outerRect.place(this);
ALabel blah=new ALabel(x+2,y+2,w,h);
if(A instanceof String) {
blah.setText((String) A);
}
else {
blah.setText("Not a String");
}
blah.place(this);
}
//------------------------------------------------------------------------------
private void drawPointer(int x,int y) {
AOval theBaseO, theBaseI;
ALine arrowB1, arrowB2, arrowH1, arrowH2;
ALabel theLabel;
arrowH1 = new ALine(x+12,y,x+5,y+10);
arrowH2 = new ALine(x+12,y,x+19,y+10);
arrowB1 = new ALine(x+9,y+5,x+9,y+30);
arrowB2 = new ALine(x+15,y+5,x+15,y+30);
theBaseO = new AOval(x,y+25,24,24);
theBaseI = new AOval(x,y+25,24,24);
theBaseI.setColor(Color.yellow);
theBaseI.setToFill();
theLabel = new ALabel(x+5,y+29,15,15);
theLabel.setFontSize(12);
theLabel.setText("" + dispList.index());
arrowH1.place(this);
arrowH2.place(this);
arrowB1.place(this);
arrowB2.place(this);
theBaseI.place(this);
theBaseO.place(this);
theLabel.place(this);
}
}
|