com.realtime.crossfire.jxclient.gui.gui
Class GUIScrollBar

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.realtime.crossfire.jxclient.gui.gui.GUIElement
                  extended by com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement
                      extended by com.realtime.crossfire.jxclient.gui.gui.GUIScrollBar
All Implemented Interfaces:
ScrollableListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class GUIScrollBar
extends ActivatableGUIElement
implements ScrollableListener

A scroll bar gui element.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  java.awt.Color colorBackground
          The background color of the slider.
private  java.awt.Color colorForeground
          The foreground color of the slider.
private  int offset
          The offset between the mouse and the top border of the slider while dragging.
private  boolean proportionalSlider
          If set, make the slider size reflect the visible area; if unset, display the slider as a square.
private  GUIScrollable2 scrollable
          The target element to scroll.
private  boolean scrolling
          Set while dragging is active.
private static long serialVersionUID
          The serial version UID.
private  int sliderPos
          The scroll location; it need not be within the scroll range.
private  int sliderSize
          The height of the slider.
private  int valueMin
          The minimum scroll value.
private  int valueSize
          The size of the scroll values.
 
Fields inherited from class com.realtime.crossfire.jxclient.gui.gui.GUIElement
bufferedImageSync
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GUIScrollBar(TooltipManager tooltipManager, GUIElementListener elementListener, java.lang.String name, Extent extent, boolean proportionalSlider, GUIScrollable2 scrollable, java.awt.Color colorBackground, java.awt.Color colorForeground)
          Creates a new instance.
 
Method Summary
protected  void activeChanged()
          Will be called whenever the active state has changed.
 void dispose()
          Releases all allocated resources.
private  int getSliderHeightPixels()
          Returns the height of the slider in pixels.
private  int getSliderPos(int yPixels)
          Returns the current slider position in slider-coordinates.
private  int getSliderPosPixels(int sh)
          Returns the y-coordinate of the slider.
 void mouseDragged(java.awt.event.MouseEvent e)
          Will be called when the mouse moves within this component while the button is pressed.
 void mousePressed(java.awt.event.MouseEvent e)
          Will be called when the user has pressed the mouse inside this element.
 void mouseReleased(java.awt.event.MouseEvent e)
          Will be called when the user has released the mouse.
protected  void render(java.awt.Graphics2D g2)
          Paints the element's contents into the passed graphics.
private  void setPosition(int pos)
          Sets the position of the slider.
 void setRange(int valueMin, int valueMax, int sliderPos, int sliderSize)
          Sets the scroll range.
 
Methods inherited from class com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement
isActive, setActive
 
Methods inherited from class com.realtime.crossfire.jxclient.gui.gui.GUIElement
createBufferGraphics, getElementX, getElementY, getGui, getName, getTooltipText, hasBufferedImage, isChanged, isDefault, isElementAtPoint, isElementVisible, isIgnore, mouseClicked, mouseEntered, mouseExited, mouseMoved, paintComponent, resetChanged, setChanged, setChangedListener, setChangedNoListeners, setDefault, setElementLocation, setElementSize, setElementVisible, setGui, setIgnore, setTooltipText, setTooltipText, toString, updateResolution, updateResolutionConstant
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, update, updateUI
 
Methods 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, validateTree
 
Methods 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, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

colorBackground

@NotNull
private final java.awt.Color colorBackground
The background color of the slider.


colorForeground

@NotNull
private final java.awt.Color colorForeground
The foreground color of the slider.


offset

private int offset
The offset between the mouse and the top border of the slider while dragging.


proportionalSlider

private final boolean proportionalSlider
If set, make the slider size reflect the visible area; if unset, display the slider as a square.


scrollable

@NotNull
private final GUIScrollable2 scrollable
The target element to scroll.


scrolling

private boolean scrolling
Set while dragging is active.


serialVersionUID

private static final long serialVersionUID
The serial version UID.

See Also:
Constant Field Values

sliderPos

private int sliderPos
The scroll location; it need not be within the scroll range.


sliderSize

private int sliderSize
The height of the slider.


valueMin

private int valueMin
The minimum scroll value.


valueSize

private int valueSize
The size of the scroll values.

Constructor Detail

GUIScrollBar

public GUIScrollBar(@NotNull
                    TooltipManager tooltipManager,
                    @NotNull
                    GUIElementListener elementListener,
                    @NotNull
                    java.lang.String name,
                    @NotNull
                    Extent extent,
                    boolean proportionalSlider,
                    @NotNull
                    GUIScrollable2 scrollable,
                    @NotNull
                    java.awt.Color colorBackground,
                    @NotNull
                    java.awt.Color colorForeground)
Creates a new instance.

Parameters:
tooltipManager - the tooltip manager to update
elementListener - the element listener to notify
name - the name of this element
extent - the extent of this element
proportionalSlider - if set, make the slider size reflect the visible area; if unset, display the slider as a square
scrollable - the target element to scroll
colorBackground - the background color of the slider
colorForeground - the foreground color of the slider
Method Detail

activeChanged

protected void activeChanged()
Will be called whenever the active state has changed.

Specified by:
activeChanged in class ActivatableGUIElement

dispose

public void dispose()
Releases all allocated resources.

Overrides:
dispose in class GUIElement

getSliderHeightPixels

private int getSliderHeightPixels()
Returns the height of the slider in pixels.

Returns:
the height of the slider in pixels

getSliderPos

private int getSliderPos(int yPixels)
Returns the current slider position in slider-coordinates.

Parameters:
yPixels - the y-coordinate within the gui element
Returns:
the position in slider-coordinates

getSliderPosPixels

private int getSliderPosPixels(int sh)
Returns the y-coordinate of the slider.

Parameters:
sh - the height of the slider in pixels
Returns:
The y-coordinate.

mouseDragged

public void mouseDragged(@NotNull
                         java.awt.event.MouseEvent e)
Will be called when the mouse moves within this component while the button is pressed. This event will be delivered after GUIElement.mouseMoved(MouseEvent).

Note: if the mouse leaves this element's bounding box while the mouse button is still pressed, further mouseDragged (but no mouseMoved) events will be generated.

Overrides:
mouseDragged in class GUIElement
Parameters:
e - the mouse event relative to this element

mousePressed

public void mousePressed(@NotNull
                         java.awt.event.MouseEvent e)
Will be called when the user has pressed the mouse inside this element.

Overrides:
mousePressed in class ActivatableGUIElement
Parameters:
e - the mouse event relative to this element

mouseReleased

public void mouseReleased(@NotNull
                          java.awt.event.MouseEvent e)
Will be called when the user has released the mouse. This event may be delivered even if no previous GUIElement.mousePressed(MouseEvent) has been delivered before.

Overrides:
mouseReleased in class GUIElement
Parameters:
e - the mouse event relative to this element

render

protected void render(@NotNull
                      java.awt.Graphics2D g2)
Paints the element's contents into the passed graphics.

Specified by:
render in class GUIElement
Parameters:
g2 - the graphics to paint to

setPosition

private void setPosition(int pos)
Sets the position of the slider. Invalid values are set to the nearest valid value.

Parameters:
pos - the slider position

setRange

public void setRange(int valueMin,
                     int valueMax,
                     int sliderPos,
                     int sliderSize)
Sets the scroll range.

Specified by:
setRange in interface ScrollableListener
Parameters:
valueMin - The minimum scroll value.
valueMax - The maximum scroll value.
sliderPos - The scroll location; it need not within the scroll range.
sliderSize - The size of the slider itself.