public class LarsonScanner
extends javax.swing.JPanel
The Larson Scanner is named after Glen A. Larson, who produced the Battlestar Galactica and Knight Rider series, and is responsible for introducing scanning red light effects to the sci-fi TV viewing population of the 1970s and 80s.
Basically, a Larson Scanner is a red light which runs from left to right, to left, to right etc. with, usually, a nice fading effect. It's so simple, but oh so awesome!
A user by the name of Kreezxil made a request for ServerPackCreator to have some sort of progress-/thinking bar to indicate that ServerPackCreator is currently busy doing server pack things. And off I went to create this little over engineered thing. Enjoy!
| Modifier and Type | Class and Description |
|---|---|
static class |
LarsonScanner.ScannerConfig
Convenience-class with which to change or acquire the configuration of the LarsonScanner.
|
javax.swing.JPanel.AccessibleJPaneljavax.swing.JComponent.AccessibleJComponentlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW| Constructor and Description |
|---|
LarsonScanner()
Create a Larson Scanner with default settings.
|
LarsonScanner(short updateInterval)
Convenience constructor allowing you to specify the interval at which the position changes.
|
LarsonScanner(short interval,
@NotNull java.awt.Color backgroundColor)
Convenience constructor allowing you to specify the interval at which the position changes, as
well as the background colours for the scanner and the eye.
|
LarsonScanner(short interval,
@NotNull java.awt.Color backgroundColor,
@NotNull java.awt.Color eyeColor)
Convenience constructor allowing you to specify the interval at which the position changes, the
background colours for the scanner and the eye, and the color of the eye.
|
| Modifier and Type | Method and Description |
|---|---|
void |
drawOval(boolean useOval)
Whether to draw each element oval or rectangular.
|
void |
forceAspectRatio(boolean force)
Set the enforcement of an aspect ratio.
|
short[] |
getAlphas()
Get the currently set alphas for the elements in the eye.
|
LarsonScanner.ScannerConfig |
getCurrentConfig()
Get the current Larson Scanner configuration as a ScannerConfig.
|
short |
getDivider()
Get the divider with which the position of the eye is currently being in-/decremented.
|
java.awt.Color |
getEyeBackground()
Acquire the background colour of the eye.
|
java.awt.Color[] |
getEyeColours()
Get the array of colours currently used for all elements in the eye, left-to-right / 0-n.
|
float[] |
getFractions()
Get the currently set fractions for use in radial gradient creation.
|
float |
getGapPercent()
Get the percentage of the width between rectangular elements.
|
short |
getInterval()
Get the currently set interval at wich the eye is being updated.
|
byte |
getNumberOfElements()
Get the currently set number of elements in the eye.
|
double |
getPartitionDivider()
Get the partition divider which currently determines the width of the eye.
|
int |
getQualitySetting()
Get the integer indicating the last set rendering quality.
|
boolean |
isAspectRatioForced()
Whether the aspect ratio is currently being enforced.
|
boolean |
isCylonAnimation()
Get whether the eye is currently being animated using the Cylon-eye or Kitt-eye animation.
|
boolean |
isDividerActive()
Whether the divider is currently being used.
|
boolean |
isGradientActive()
Whether the eye is currently being drawn using gradients or solid colours.
|
boolean |
isRunning()
Whether the eye is currently being animated.
|
boolean |
isShapeOval()
Return whether the shape is currently set to oval.
|
void |
loadConfig(@NotNull LarsonScanner.ScannerConfig config)
Set the configuration of the Larson Scanner with values from the given config.
|
void |
loadDefaults()
Load the default values into the Larson Scanner and eye, resetting it.
|
void |
pause()
Pause the eye, freezing the animation.
|
void |
play()
Unpause the eye, continuing the animation.
|
void |
setAlphas(short[] alphas)
Set the alpha values for the elements in the eye, one for each element.
|
void |
setDivider(short newStepDivider)
Set the divider with which the position of the eye is being in-/decremented.
|
void |
setEyeBackground(@NotNull java.awt.Color backgroundColor)
Set the background colour for the eye.
|
void |
setEyeColour(@NotNull java.awt.Color color)
Set the colour for all elements in the eye to the same colour.
|
void |
setEyeColours(@NotNull java.awt.Color[] colours)
Set the colour for each element in the eye, from left to right.
|
void |
setFractions(float fractionOne,
float fractionTwo)
Set the fractions for the distribution of the colours along the gradients of each oval-shaped
element.
|
void |
setGapPercent(float percentile)
Set the width of the gap between rectangular shapes in percent.
|
void |
setInterval(short updateInterval)
Set the interval in milliseconds at which to fire the timer of the eye.
|
void |
setNumberOfElements(byte amount)
Set the number of elements in the eye.
|
void |
setPartitionDivider(double partitionDivider)
The partition divider controls the width of the eye in the Larson Scanner.
|
void |
setQualityHigh()
Set the rendering quality of the eye to high.
|
void |
setQualityLow()
Set the rendering quality of the eye to low.
|
void |
setQualityMedium()
Set the rendering quality of the eye to medium.
|
void |
toggleAspectRatio()
Toggle the enforcement of an aspect ratio.
|
void |
toggleCylonAnimation()
Toggle whether the eye os to be animated using the Cylon-eye or Kitt-eye animation.
|
void |
toggleDivider()
Toggle the use of the divider.
|
void |
toggleGradient()
Toggle the drawing of the eye between gradient and solid colours.
|
void |
togglePauseUnpause()
Toggle the animation of the eye on/off.
|
void |
toggleShape()
Toggle the eye between oval-shape and rectangle-shape.
|
void |
useCylonAnimation(boolean useCylonAnimation)
Whether to use the Cylon-eye animation or Kitt-eye animation.
|
void |
useDivider(boolean useDivider)
Whether to use a divider to in-/decrement across the width of the Larson Scanner.
|
void |
useGradient(boolean useGradient)
Whether to draw the eye using gradients.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIaddAncestorListener, 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, updateadd, 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, validateTreeaction, 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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic LarsonScanner()
Default settings are:
public LarsonScanner(short updateInterval)
LarsonScanner().updateInterval - Short Interval in milliseconds at which to scroll.public LarsonScanner(short interval,
@NotNull
@NotNull java.awt.Color backgroundColor)
LarsonScanner().interval - Short Interval in milliseconds at which to scroll.backgroundColor - Color The background colour for the scanner and the eye.public LarsonScanner(short interval,
@NotNull
@NotNull java.awt.Color backgroundColor,
@NotNull
@NotNull java.awt.Color eyeColor)
LarsonScanner().interval - Short Interval in milliseconds at which to scroll.backgroundColor - Color The background colour for the scanner and the eye.eyeColor - Color The color of the eye.public byte getNumberOfElements()
Byte The current number of elements in the eye.public void setNumberOfElements(byte amount)
throws java.lang.IllegalArgumentException
Default setting: 5
amount - Byte Number of elements in the eye.java.lang.IllegalArgumentException - if the number specified is smaller than 1 or an even number.public void setEyeColour(@NotNull
@NotNull java.awt.Color color)
Default setting: 255,0,0
color - Color The color to set all elements in the eye to.public java.awt.Color[] getEyeColours()
Color-array containing the colours of each element in the eye, left-to-right /
0-n.public void setEyeColours(@NotNull
@NotNull java.awt.Color[] colours)
throws java.lang.IllegalArgumentException
Color-array must
be the same size as the current number of elements in the eye.
Default setting: {255,0,0 , 255,0,0 , 255,0,0 , 255,0,0 , 255,0,0}
colours - Color-array of colours, one for each element in the eye, from left to
right.java.lang.IllegalArgumentException - if the size of the array is unequal to the current number of
elements in the eye.public java.awt.Color getEyeBackground()
Color The background colour of the eye.public void setEyeBackground(@NotNull
@NotNull java.awt.Color backgroundColor)
Default setting: 0,0,0
backgroundColor - Color The color to set the background of the eye to.public void drawOval(boolean useOval)
true to use oval-shapes,
false to use rectangular shapes.
Default setting: true
useOval - Boolean Whether to use oval or rectangular shapes.public void toggleShape()
public boolean isShapeOval()
Boolean true if oval, false otherwise.public void useGradient(boolean useGradient)
true to use gradients, false
to use solid colours. Depending on the shape, gradients are drawn in two ways:
n to the
height of element n. This is most beautiful when forcing the aspect ratio,
as radial gradients are best for circles, not ovals.
n, over the width of element n, for each element.
Default setting: true
useGradient - Boolean Whether to use gradients or solid colours.public void toggleGradient()
useGradient(boolean).public boolean isGradientActive()
useGradient(boolean).Boolean true when the eye is drawn using gradients.public void useDivider(boolean useDivider)
Increment: next position = current position + width of the Scanner / divider
Decrement: next position = current position - width of the Scanner / divider
Default setting: true
useDivider - Boolean Whether to in-/decrement using the divider. true
to use it.public void toggleDivider()
useDivider(boolean) for more information about the
divider and how it works.public boolean isDividerActive()
useDivider(boolean) for more
information about the divider and how it works.Boolean true if the divider is being used.public void useCylonAnimation(boolean useCylonAnimation)
useCylonAnimation - Boolean true to use the Cylon animation.public void toggleCylonAnimation()
useCylonAnimation(boolean).public boolean isCylonAnimation()
useCylonAnimation(boolean).Boolean true if the eye is being animated as a Cylon-eye.public void forceAspectRatio(boolean force)
If you plan on using different scanner and eye background colours, you should make use of this setting, otherwise the eye background colour will also prevail.
Default setting: false
force - Booleanpublic void toggleAspectRatio()
forceAspectRatio(boolean) for more
information about an aspect ratio enforcement.public boolean isAspectRatioForced()
forceAspectRatio(boolean)
for more information about an aspect ratio enforcement.Boolean true if the aspect ratio is being enforced.public void setFractions(float fractionOne,
float fractionTwo)
throws java.lang.IllegalArgumentException
Default setting: 0.4f, 1.0f
fractionOne - Float Fraction to distribute colour across a radial gradient.
Ranging from 0.0f to 1.0f, smaller than fractionTwo.fractionTwo - Float Fraction to distribute colour across a radial gradient.
Ranging from 0.0f to 1.0f, bigger than fractionOne.java.lang.IllegalArgumentException - if fractionOne is smaller than 0.0f, if fractionOne is bigger
or equal to 1.0f, if fractionOne is bigger than fractionTwo, or if fractionTwo is bigger
than 1.0f.public float[] getFractions()
setFractions(float, float) for more information.Float-array containing the two fractions currently set.public short[] getAlphas()
setAlphas(short[]) for
more information.Short-array containing the alpha-values with which the elements in the eye are
being drawn.public void setAlphas(short[] alphas)
throws java.lang.IllegalArgumentException
Note:
Alpha values are reset / automatically set / calculated when you change the number of elements in your configuration. So, if you plan on using custom alpha values and a custom amount of elements, make sure to update your alphas after changing the number of elements!
Depending on the currently set shape, these alpha values are used in different ways:
Default setting: 100, 200, 255, 200, 100
alphas - Short-array containing the alpha to draw an element with, one for each
element.java.lang.IllegalArgumentException - if the amount of alphas is unequal to the current number of
elements present in the eye.public short getInterval()
setInterval(short).Short The interval at which the eye is updated.public void setInterval(short updateInterval)
throws java.lang.IllegalArgumentException
n
milliseconds the position of the eye gets updated and the eye redrawn. Smaller values therefor
increase the speed at wich the eye scrolls across the screen, whilst bigger values decrease it.
Default setting: 100
updateInterval - Short the interval in milliseconds at which to update the eye.java.lang.IllegalArgumentExceptionpublic short getDivider()
useDivider(boolean).Short The divider with which the position of the eye is currently being
in-/decremented.public void setDivider(short newStepDivider)
throws java.lang.IllegalArgumentException
useDivider(boolean).
Default setting: 25
newStepDivider - Short The new divider with which to in-/decrement the position of
th eye.java.lang.IllegalArgumentExceptionpublic float getGapPercent()
Float The percentage of the width between rectangular elements.public void setGapPercent(float percentile)
throws java.lang.IllegalArgumentException
n% of the width of one element.
Default setting: 25.0f
percentile - Float Width of the gap between rectangular elements, in %.java.lang.IllegalArgumentException - if the specified percentage is smaller than 0.0f.public double getPartitionDivider()
Double The partition divider of the eye.public void setPartitionDivider(double partitionDivider)
throws java.lang.IllegalArgumentException
partitionDivider - Double The new partition divider to set for the eye.java.lang.IllegalArgumentException - if the specified divider is smaller than or equal to 0.0D.public void pause()
public void play()
public boolean isRunning()
false if the eye is stopped.Boolean Whether the eye animation is active. false if it is
stopped.public void togglePauseUnpause()
public int getQualitySetting()
setQualityLow(), setQualityMedium() and setQualityHigh() for more information.Integer Number representation of the last set rendering quality.public void setQualityHigh()
Default setting: low
public void setQualityMedium()
Default setting: low
public void setQualityLow()
Default setting: low
public void loadConfig(@NotNull
@NotNull LarsonScanner.ScannerConfig config)
throws java.lang.IllegalArgumentException
config - LarsonScanner.ScannerConfig The configuration from which to set the Larson Scanner
values.java.lang.IllegalArgumentException - if any of the configured values is invalid.public void loadDefaults()
LarsonScanner() for more information on what the defaults are.public LarsonScanner.ScannerConfig getCurrentConfig()
LarsonScanner.ScannerConfig The current configuration of the Larson Scanner.