Class TspDemoControlPanel
- All Implemented Interfaces:
SimulationListener,ISimulationControlPanel,ImageObserver,MenuContainer,Serializable,Accessible
Structure
Follows the standard MDI composite control panel pattern:
- Left —
IconSimulationControlPanelproviding the standard play/pause/stop media buttons and progress bar. - Center — two labeled sliders:
- Number Cities (
MIN_CITIES..MAX_CITIES) — number of randomly placed cities. - River Crossing Penalty or Bonus (−1..+1) — adds a constant to the distance of any edge that crosses the river. Positive values penalize crossings (the tour avoids the river); negative values reward them (the tour seeks crossings).
- Number Cities (
- Right — Reset button that rebuilds the model and simulation from the current slider values.
State gating
The sliders are enabled in SimulationState.READY,
SimulationState.PAUSED, and SimulationState.TERMINATED. The
Reset button is enabled in those same three states plus
SimulationState.FAILED, so the user can always recover from a
failed run. This prevents the user from changing parameters while the
simulation thread is actively mutating the model.
Reset behavior
Pressing Reset calls ITspDemoResettable.requestReset(int, double) on the host if
it implements that interface, passing the current slider values. The host
(TspDemoView) is responsible for stopping the current engine,
building a new simulation with the new parameters, and restarting.
An optional auto-reset mode (autoResetOnSliderRelease) can trigger
a reset automatically when the user releases a slider knob in an editable
state. It is disabled by default.
River slider precision
JSlider operates on integers, so the river penalty slider is scaled
by RIVER_SCALE (10^RIVER_NUM_DECIMALS) internally
and divided back to a double in getRiverPenalty().
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum number of cities available on the city slider.static final intMinimum number of cities available on the city slider.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionConstruct with the standard MDI icon set.Construct with a caller-supplied icon set. -
Method Summary
Modifier and TypeMethodDescriptionvoidbind(ISimulationHost host) Bind this panel to the given simulation host.intReturn the city count currently selected on the slider.doubleReturn the river penalty currently selected on the slider.voidonDone(SimulationContext ctx) Called when the engine ends normally (reachesSimulationState.TERMINATED).voidonFail(SimulationContext ctx, Throwable error) Called when the engine fails (reachesSimulationState.FAILED).voidonProgress(SimulationContext ctx, ProgressInfo progress) Called for progress updates (indeterminate or determinate).voidonReady(SimulationContext ctx) Called when initialization completes and the engine reachesSimulationState.READY.voidonStateChange(SimulationContext ctx, SimulationState from, SimulationState to, String reason) Called on every state transition.voidunbind()Unbind this panel from its host.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.cnu.mdi.sim.SimulationListener
onCancelRequested, onCompleted, onInit, onMessage, onPause, onRefresh, onResume, onRun
-
Field Details
-
MIN_CITIES
public static final int MIN_CITIESMinimum number of cities available on the city slider.- See Also:
-
MAX_CITIES
public static final int MAX_CITIESMaximum number of cities available on the city slider.- See Also:
-
-
Constructor Details
-
TspDemoControlPanel
public TspDemoControlPanel()Construct with the standard MDI icon set. -
TspDemoControlPanel
Construct with a caller-supplied icon set.- Parameters:
icons- simulation icons (non-null)
-
-
Method Details
-
bind
Bind this panel to the given simulation host.Binds the embedded
basePanelto the same host, registers this panel as aSimulationListener, and applies the current engine state immediately.- Specified by:
bindin interfaceISimulationControlPanel- Parameters:
host- the simulation host (non-null; typicallyTspDemoView)
-
unbind
public void unbind()Unbind this panel from its host.Removes the listener from the engine and unbinds the embedded
basePanel. The panel becomes inert until bound again.- Specified by:
unbindin interfaceISimulationControlPanel
-
getCityCount
public int getCityCount()Return the city count currently selected on the slider.- Returns:
- number of cities in the range [
MIN_CITIES,MAX_CITIES]
-
getRiverPenalty
public double getRiverPenalty()Return the river penalty currently selected on the slider.- Returns:
- penalty in
[−1.0, +1.0]; positive values penalize river crossings, negative values reward them
-
onStateChange
public void onStateChange(SimulationContext ctx, SimulationState from, SimulationState to, String reason) Called on every state transition.- Specified by:
onStateChangein interfaceSimulationListener- Parameters:
ctx- simulation contextfrom- previous stateto- new statereason- human-readable reason (may be null)
-
onReady
Called when initialization completes and the engine reachesSimulationState.READY.- Specified by:
onReadyin interfaceSimulationListener- Parameters:
ctx- simulation context
-
onDone
Called when the engine ends normally (reachesSimulationState.TERMINATED).- Specified by:
onDonein interfaceSimulationListener- Parameters:
ctx- simulation context
-
onFail
Called when the engine fails (reachesSimulationState.FAILED).- Specified by:
onFailin interfaceSimulationListener- Parameters:
ctx- simulation contexterror- the exception/error that caused failure
-
onProgress
Called for progress updates (indeterminate or determinate). No-op — progress display is handled by the embeddedbasePanel.- Specified by:
onProgressin interfaceSimulationListener- Parameters:
ctx- simulation contextprogress- progress payload
-