/** {@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"); } } } }
/** * 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 }