/** {@inheritDoc} */ public void activate(Segment s) { timedOut = timeout <= -1; currFrame = 0; if (assembly != null) { // If we have an assembly, make our state mirror // that of the assembly. Feature curr = assembly.getCurrentPart(); int i = lookForFeature(curr, selectFeatures); if (i != -1) { currState = i; activated = false; } else { i = lookForFeature(curr, activateFeatures); if (i != -1) { currState = i; if (startSelected) { assembly.setCurrentFeature(selectFeatures[i]); activated = false; } else { activated = true; } } else if (Debug.LEVEL > 0) { Debug.println("Handler " + getName() + " can't find current assembly state"); } } } }
/** {@inheritDoc} */ public boolean handleKeyPressed(RCKeyEvent ke, Show caller) { if ((ke.getBitMask() & MASK) == 0) { return false; } synchronized (show) { int newState = 0; if (ke == ke.KEY_ENTER) { newState = GRID_ACTIVATE; } else if (ke == ke.KEY_UP) { newState = (upDown[currState] >> 16) & 0xffff; } else if (ke == ke.KEY_DOWN) { newState = upDown[currState] & 0xffff; } else if (ke == ke.KEY_RIGHT) { newState = (rightLeft[currState] >> 16) & 0xffff; } else if (ke == ke.KEY_LEFT) { newState = rightLeft[currState] & 0xffff; } else if (Debug.ASSERT) { Debug.assertFail(); } if (newState == GRID_ACTIVATE) { if (!handlesActivation()) { return false; } setState(-1, true, true); return true; } else { setState(newState, false, true); return true; } } }
/** * Called from InvokeVisualCellCommand, and from internal methods. This is synchronized on our * show, to only occur during model updates. This method may also be called from a java_command or * from the director, within the animation thread. * * @param newState New state, -1 means "current" * @param newActivated New value for activated * @param runCommands If true, run the commands normally associated with entering this state due * to a keypress. * @param gridAlternate Alternate grid # to select, 0..max, or -1 to leave grid unchanged. */ public void setState(int newState, boolean newActivated, boolean runCommands, int gridAlternate) { synchronized (show) { if (gridAlternate != -1) { upDown = upDownAlternates[gridAlternate]; rightLeft = rightLeftAlternates[gridAlternate]; } if (newState == GRID_ACTIVATE) { newState = currState; newActivated = true; } else if (newState == -1) { newState = currState; } if (newState == currState && newActivated == activated) { if (activated) { // If activated, re-run any animations by // briefly setting the assembly to the selected // state. setState(newState, false, false); } else { return; } } if (Debug.LEVEL > 1) { Debug.println("RC handler state becomes " + stateNames[newState]); } Feature[] fs = newActivated ? activateFeatures : selectFeatures; Command[][] cs = newActivated ? activateCommands : selectCommands; if (fs != null && fs[newState] != null) { assembly.setCurrentFeature(fs[newState]); if (Debug.LEVEL > 1) { Debug.println(" Setting assembly to " + fs[newState]); } } if (runCommands && cs != null) { Command[] arr = cs[newState]; if (arr != null) { for (int i = 0; i < arr.length; i++) { show.runCommand(arr[i]); } } } currState = newState; activated = newActivated; } // end synchronized }