|
@@ -12,6 +12,7 @@ public class Model extends Observable
|
|
|
private Thingy curThingy;
|
|
|
private Color curColour;
|
|
|
private int curThiccness;
|
|
|
+ private int totalLen;
|
|
|
public Color sideColour;
|
|
|
public Color controlColour;
|
|
|
|
|
@@ -22,6 +23,7 @@ public class Model extends Observable
|
|
|
this.thingies = new ArrayList();
|
|
|
this.curColour = Color.black;
|
|
|
this.curThiccness = 5;
|
|
|
+ this.totalLen = 0;
|
|
|
setChanged();
|
|
|
}
|
|
|
|
|
@@ -30,6 +32,7 @@ public class Model extends Observable
|
|
|
curThingy = new Thingy(curColour, curThiccness);
|
|
|
thingies.add(curThingy);
|
|
|
curThingy.addPoint(x, y);
|
|
|
+ totalLen++;
|
|
|
setChanged();
|
|
|
notifyObservers();
|
|
|
}
|
|
@@ -37,24 +40,46 @@ public class Model extends Observable
|
|
|
public void addPoint(int x, int y)
|
|
|
{
|
|
|
curThingy.addPoint(x, y);
|
|
|
+ totalLen++;
|
|
|
setChanged();
|
|
|
notifyObservers();
|
|
|
}
|
|
|
|
|
|
+ public int getTotalLen()
|
|
|
+ {
|
|
|
+ return totalLen;
|
|
|
+ }
|
|
|
+
|
|
|
public ArrayList<Thingy> getThingies()
|
|
|
{
|
|
|
return thingies;
|
|
|
}
|
|
|
|
|
|
- public void changeThingy(int x)
|
|
|
+ public void changeThingy(int x) // int x is the position in the slider we are at
|
|
|
{
|
|
|
- curThingy = thingies.get(x);
|
|
|
- if (thingies.size() >= 2)
|
|
|
+ int tempLen = 0;
|
|
|
+ int index;
|
|
|
+
|
|
|
+ for (int i = 0; i < thingies.size() && tempLen <= x; i++)
|
|
|
+ {
|
|
|
+ tempLen += thingies.get(i).getVisisbleLen();
|
|
|
+ index = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ Thingy tempThingy = thingies.get(index);
|
|
|
+ // off by one adjustments if we're at the end of a thingy
|
|
|
+ if (tempThingy.getVisisbleLen() == 0 && tempLen > x) tempThingy = thingies.get(index - 1);
|
|
|
+ if (tempThingy.getVisisbleLen() == tempThingy.getPoints().size() && tempLen < x) tempThingy = thingies.get(index + 1);
|
|
|
+
|
|
|
+ // now modify tempThingy
|
|
|
+ // if we want to go back in time
|
|
|
+ if (tempLen > x)
|
|
|
+ {
|
|
|
+ tempThingy.reduceLen();
|
|
|
+ }
|
|
|
+ else // go forwards
|
|
|
{
|
|
|
- for (int i = (x + 1); i < thingies.size(); i++)
|
|
|
- {
|
|
|
- thingies.remove(i);
|
|
|
- }
|
|
|
+ tempThingy.increaseLen();
|
|
|
}
|
|
|
setChanged();
|
|
|
notifyObservers();
|
|
@@ -125,17 +150,20 @@ class Thingy
|
|
|
private ArrayList<Point> points;
|
|
|
private Color colour;
|
|
|
private int thiccness;
|
|
|
+ private int visibleLen;
|
|
|
|
|
|
public Thingy(Color c, int x)
|
|
|
{
|
|
|
points = new ArrayList();
|
|
|
this.colour = c;
|
|
|
this.thiccness = x;
|
|
|
+ this.visibleLen = 0;
|
|
|
}
|
|
|
|
|
|
public void addPoint(int x, int y)
|
|
|
{
|
|
|
points.add(new Point(x, y));
|
|
|
+ visibleLen++;
|
|
|
}
|
|
|
|
|
|
public ArrayList<Point> getPoints()
|
|
@@ -152,4 +180,19 @@ class Thingy
|
|
|
{
|
|
|
return thiccness;
|
|
|
}
|
|
|
+
|
|
|
+ public int getVisisbleLen()
|
|
|
+ {
|
|
|
+ return visibleLen;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reduceLen()
|
|
|
+ {
|
|
|
+ visibleLen--;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void increaseLen()
|
|
|
+ {
|
|
|
+ visibleLen++;
|
|
|
+ }
|
|
|
}
|