package NET.worlds.scape; import java.io.IOException; public class VideoControlAction extends Action { private final int play = 1; private final int stop = 2; private int mode = 1; private int repeat = 1; private VideoTexture videoTexture = null; private VideoWall videoWall = null; private static Object classCookie = new Object(); VideoControlAction() { } @Override public Persister trigger(Event e, Persister seqID) { if (!this.getVideoTexture()) { System.out.println("ERROR! Tried to attach VideoControlAction to something other than a Rect with a VideoTexture. or a VideoWall object."); return null; } else { switch (this.mode) { case 1: if (this.videoTexture == null) { this.videoWall.getVideoSurface().play(this.repeat); } else { this.videoTexture.getDirectShow().nPlay(this.repeat); } break; case 2: if (this.videoTexture == null) { this.videoWall.getVideoSurface().stop(); } else { this.videoTexture.getDirectShow().nStop(); } } return null; } } private boolean getVideoTexture() { if (this.videoTexture != null) { return true; } else { Object owner = this.getOwner(); if (owner != null && owner instanceof Rect) { Rect r = (Rect)owner; this.videoTexture = r.getVideoAttribute(); if (this.videoTexture != null) { return true; } else if (owner instanceof VideoWall) { this.videoWall = (VideoWall)owner; return true; } else { return false; } } else { return false; } } } @Override public void saveState(Saver s) throws IOException { s.saveVersion(1, classCookie); super.saveState(s); s.saveInt(this.mode); s.saveInt(this.repeat); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { switch (r.restoreVersion(classCookie)) { case 0: super.restoreState(r); this.mode = r.restoreInt(); break; case 1: super.restoreState(r); this.mode = r.restoreInt(); this.repeat = r.restoreInt(); } } @Override public Object properties(int index, int offset, int pmode, Object value) throws NoSuchPropertyException { Object ret = null; switch (index - offset) { case 0: if (pmode == 0) { ret = IntegerPropertyEditor.make(new Property(this, index, "1=Play, 2=Stop")); } else if (pmode == 1) { ret = new Integer(this.mode); } else if (pmode == 2) { this.mode = (Integer)value; } break; case 1: if (pmode == 0) { ret = IntegerPropertyEditor.make(new Property(this, index, "Repeat count (-1 for infinite)")); } else if (pmode == 1) { ret = new Integer(this.repeat); } else if (pmode == 2) { this.repeat = (Integer)value; } break; default: ret = super.properties(index, offset + 2, pmode, value); } return ret; } }