Package org.openstreetmap.josm.gui
Class ScrollViewport
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.openstreetmap.josm.gui.ScrollViewport
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public class ScrollViewport extends JPanel
A viewport with UP and DOWN arrow buttons, so that the user can make the content scroll. This should be used for long, vertical toolbars.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ScrollViewport.ScrollViewPortMouseListener
-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description static int
ALL_DIRECTION
Allow scrolling in both directionsprivate int
allowedScrollDirections
private List<JButton>
buttons
private JComponent
component
static int
DOWN_DIRECTION
Direction flag for downwardsstatic int
HORIZONTAL_DIRECTION
Allow horizontal scrollingstatic int
LEFT_DIRECTION
Direction flag for leftprivate static int
NO_SCROLL
private ComponentAdapter
refreshButtonsOnResize
static int
RIGHT_DIRECTION
Direction flag for rightprivate int
scrollDirection
private Timer
timer
static int
UP_DIRECTION
Direction flag for upwardsstatic int
VERTICAL_DIRECTION
Allow vertical scrollingprivate JViewport
vp
-
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_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, 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
Constructors Constructor Description ScrollViewport(int direction)
Create a new scroll viewportScrollViewport(JComponent c, int direction)
Create a new scroll viewport
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(JComponent c)
Sets the component to be used as content.private void
addScrollButton(int direction, String icon, String borderLayoutPosition)
Dimension
getMinimumSize()
Dimension
getPreferredSize()
Point
getViewPosition()
Gets the position (offset) of the view areaRectangle
getViewRect()
Gets the current visible part of the viewDimension
getViewSize()
Gets the size of the viewvoid
scroll()
Scrolls in the currently selected scroll direction.void
scroll(int deltaX, int deltaY)
Scrolls by the given offsetvoid
showOrHideButtons()
Update the visibility of the buttons Only show them if the Viewport is too small for the content.-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods 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, getNextFocusableComponent, getPopupLocation, 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, update
-
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, 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, transferFocusUpCycle
-
-
-
-
Field Detail
-
NO_SCROLL
private static final int NO_SCROLL
- See Also:
- Constant Field Values
-
UP_DIRECTION
public static final int UP_DIRECTION
Direction flag for upwards- See Also:
- Constant Field Values
-
DOWN_DIRECTION
public static final int DOWN_DIRECTION
Direction flag for downwards- See Also:
- Constant Field Values
-
LEFT_DIRECTION
public static final int LEFT_DIRECTION
Direction flag for left- See Also:
- Constant Field Values
-
RIGHT_DIRECTION
public static final int RIGHT_DIRECTION
Direction flag for right- See Also:
- Constant Field Values
-
VERTICAL_DIRECTION
public static final int VERTICAL_DIRECTION
Allow vertical scrolling- See Also:
- Constant Field Values
-
HORIZONTAL_DIRECTION
public static final int HORIZONTAL_DIRECTION
Allow horizontal scrolling- See Also:
- Constant Field Values
-
ALL_DIRECTION
public static final int ALL_DIRECTION
Allow scrolling in both directions- See Also:
- Constant Field Values
-
component
private JComponent component
-
scrollDirection
private int scrollDirection
-
allowedScrollDirections
private final int allowedScrollDirections
-
refreshButtonsOnResize
private final transient ComponentAdapter refreshButtonsOnResize
-
-
Constructor Detail
-
ScrollViewport
public ScrollViewport(JComponent c, int direction)
Create a new scroll viewport- Parameters:
c
- The component to display as content.direction
- The direction to scroll. Should be one ofVERTICAL_DIRECTION
,HORIZONTAL_DIRECTION
,ALL_DIRECTION
-
ScrollViewport
public ScrollViewport(int direction)
Create a new scroll viewport- Parameters:
direction
- The direction to scroll. Should be one ofVERTICAL_DIRECTION
,HORIZONTAL_DIRECTION
,ALL_DIRECTION
-
-
Method Detail
-
addScrollButton
private void addScrollButton(int direction, String icon, String borderLayoutPosition)
-
scroll
public void scroll()
Scrolls in the currently selected scroll direction.
-
scroll
public void scroll(int deltaX, int deltaY)
Scrolls by the given offset- Parameters:
deltaX
- offset xdeltaY
- offset y
-
showOrHideButtons
public void showOrHideButtons()
Update the visibility of the buttons Only show them if the Viewport is too small for the content.
-
getViewRect
public Rectangle getViewRect()
Gets the current visible part of the view- Returns:
- The current view rect
-
getViewSize
public Dimension getViewSize()
Gets the size of the view- Returns:
- The size
-
getViewPosition
public Point getViewPosition()
Gets the position (offset) of the view area- Returns:
- The offset
-
getPreferredSize
public Dimension getPreferredSize()
- Overrides:
getPreferredSize
in classJComponent
-
getMinimumSize
public Dimension getMinimumSize()
- Overrides:
getMinimumSize
in classJComponent
-
add
public void add(JComponent c)
Sets the component to be used as content.- Parameters:
c
- The component
-
-