Class Gallery
- java.lang.Object
-
- org.eclipse.swt.widgets.Widget
-
- org.eclipse.swt.widgets.Control
-
- org.eclipse.swt.widgets.Scrollable
-
- org.eclipse.swt.widgets.Composite
-
- org.eclipse.swt.widgets.Canvas
-
- org.eclipse.nebula.widgets.gallery.Gallery
-
- All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable
public class Gallery extends org.eclipse.swt.widgets.Canvas
SWT Widget that displays an image gallery
see http://www.eclipse.org/nebula/widgets/gallery/gallery.php
This widget requires jdk-1.8+Style
VIRTUAL
is used to create aGallery
whoseGalleryItem
s are to be populated by the client on an on-demand basis instead of up-front. This can provide significant performance improvements for galleries that are very large or for whichGalleryItem
population is expensive (for example, retrieving values from an external source).Here is an example of using a
Gallery
with styleVIRTUAL
:final Gallery gallery = new Gallery(parent, SWT.VIRTUAL | V_SCROLL | SWT.BORDER); gallery.setGroupRenderer(new DefaultGalleryGroupRenderer()); gallery.setItemRenderer(new DefaultGalleryItemRenderer()); gallery.setItemCount(1000000); gallery.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { GalleryItem item = (GalleryItem) event.item; int index = gallery.indexOf(item); item.setText("Item " + index); System.out.println(item.getText()); } });
- Styles:
- SINGLE, MULTI, VIRTUAL, V_SCROLL, H_SCROLL
Note: Only one of the styles SINGLE and MULTI may be specified.
Note: Only one of the styles V_SCROLL and H_SCROLL may be specified.
- Events:
- Selection, DefaultSelection, SetData, PaintItem
NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
antialias
Image quality : antialiasprivate org.eclipse.swt.graphics.Color
backgroundColor
Background color, if Control#getBackground() is not used.private static java.lang.String
BUG_PLATFORM_LINUX_GTK_174932
protected static boolean
DEBUG
Used to enable debug logging in the Gallery widget.private org.eclipse.swt.graphics.Color
foregroundColor
Foreground color, if Control#getForeground() is not used.private int
gHeight
(package private) AbstractGalleryGroupRenderer
groupRenderer
private int
gWidth
protected int
higherQualityDelay
(package private) int
interpolation
Image quality : interpolation(package private) AbstractGalleryItemRenderer
itemRenderer
(package private) GalleryItem[]
items
protected int
lastContentHeight
protected int
lastContentWidth
protected int
lastControlHeight
protected int
lastControlWidth
(package private) int
lastIndexOf
protected GalleryItem
lastSingleClick
Keeps track of the last selected item.protected int
lastTranslateValue
(package private) boolean
lowQualityOnUserAction
Low quality on user action : decrease drawing quality on scrolling or resize.private boolean
mouseClickHandled
Keep track of processing the current mouse event.(package private) boolean
multi
Multi-selection flag(package private) java.lang.Runnable
redrawTimer
private GalleryItem[]
selection
protected int[]
selectionFlags
Selection bit flags.protected int
translate
Current translation (scroll bar position).private boolean
useControlColors
If set to true, the gallery will get colors from parent Control.(package private) boolean
vertical
Scrolling direction flag.(package private) boolean
virtual
Virtual mode flag.(package private) int
virtualGroupDefaultItemCount
(package private) boolean
virtualGroups
Ultra virtual : non visible groups are not initialized.(package private) boolean
virtualGroupsCompatibilityMode
-
Constructor Summary
Constructors Constructor Description Gallery(org.eclipse.swt.widgets.Composite parent, int style)
Create a Gallery
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
_addDisposeListeners()
Add internal dispose listeners to this gallery.private void
_addItem(GalleryItem item, int position)
private void
_addKeyListeners()
private void
_addMouseListeners()
Add internal mouse listeners to this gallery.private void
_addPaintListeners()
Add internal paint listeners to this gallery.private void
_addResizeListeners()
Add internal resize listeners to this gallery.private void
_addScrollBarsListeners()
Add internal scrollbars listeners to this gallery.protected void
_addSelection(GalleryItem item)
protected java.lang.Object[]
_arrayAddItem(java.lang.Object[] array, java.lang.Object object, int index)
Adds an item to an array.protected int
_arrayIndexOf(int[] array, int value)
protected int
_arrayIndexOf(java.lang.Object[] array, java.lang.Object value)
protected int[]
_arrayRemoveItem(int[] array, int index)
protected java.lang.Object[]
_arrayRemoveItem(java.lang.Object[] array, int index)
protected void
_deselectAll(boolean notifyListeners)
Deselects all items and send selection event depending on parameter.private void
_drawGroup(org.eclipse.swt.graphics.GC gc, int index)
Handle the drawing of root itemsprivate GalleryItem
_getGroup(org.eclipse.swt.graphics.Point coords)
Get group at pixel positionprotected GalleryItem
_getItem(int index)
Get the item at index.
If SWT.VIRTUAL is used and the item has not been used yet, the item is created and a SWT.SetData is fired.
This is the internal implementation of this method : checkWidget() is not used.protected GalleryItem
_getItem(int index, boolean create)
Get the item at 'index'.
If SWT.VIRTUAL is used, 'create' is true and the item has not been used yet, the item is created and a SWT.SetData is fired.protected GalleryItem
_getItem(GalleryItem parent, int index)
This method is used by items to implement getItem( index )protected int
_indexOf(GalleryItem item)
Returns the index of a GalleryItem when it is a root Itemprotected int
_indexOf(GalleryItem parentItem, GalleryItem item)
Returns the index of a GalleryItem when it is not a root Itemprotected boolean
_mouseDown(org.eclipse.swt.widgets.Event event)
Forward the mouseDown event to the corresponding group according to the mouse position.protected void
_remove(int index)
protected void
_remove(GalleryItem parent, int index)
private void
_removeSelection(GalleryItem item)
protected void
_removeSelection(GalleryItem parent, GalleryItem item)
protected void
_selectAll()
private void
_setDefaultRenderers()
void
_setGalleryItems(GalleryItem[] items)
(package private) void
_showItem(GalleryItem item)
protected void
addItem(GalleryItem item, int position)
void
addSelectionListener(org.eclipse.swt.events.SelectionListener listener)
Adds the listener to the collection of listeners who will be notified when the receiver's selection changes, by sending it one of the messages defined in theSelectionListener
interface.void
addTreeListener(org.eclipse.swt.events.TreeListener listener)
Adds the listener to the collection of listeners who will be notified when an item in the receiver is expanded or collapsed by sending it one of the messages defined in the TreeListener interface.private int
calculateSize(GalleryItem onlyUpdateGroup)
Calculate full height (or width) of the Gallery.void
clear(int index)
Clear one item.void
clear(int index, boolean all)
Clear one item and all its children if 'all' is truevoid
clearAll()
Clear all GalleryGroupsvoid
clearAll(boolean all)
Clear all Gallery items.
If the Gallery is virtual, the item count is not reseted and all items will be created again at their first use.void
deselectAll()
Deselects all items.int
getAntialias()
org.eclipse.swt.graphics.Color
getBackground()
org.eclipse.swt.graphics.Color
getBackground(boolean galleryOnly)
Returns the receiver's background color.org.eclipse.swt.graphics.Color
getForeground()
org.eclipse.swt.graphics.Color
getForeground(boolean galleryOnly)
Returns the receiver's foreground color.GalleryItem
getGroup(org.eclipse.swt.graphics.Point coords)
Get group at pixel position (relative to client area).AbstractGalleryGroupRenderer
getGroupRenderer()
int
getHigherQualityDelay()
int
getInterpolation()
GalleryItem
getItem(int index)
Get the item at index.
If SWT.VIRTUAL is used and the item has not been used yet, the item is created and a SWT.SetData event is fired.GalleryItem
getItem(org.eclipse.swt.graphics.Point coords)
Get item at pixel positionint
getItemCount()
Return the number of root-level items in the receiver.AbstractGalleryItemRenderer
getItemRenderer()
Get current item rendererGalleryItem[]
getItems()
private boolean
getOrder(GalleryItem before, GalleryItem after)
GalleryItem[]
getSelection()
int
getSelectionCount()
int
getVirtualGroupDefaultItemCount()
private int[]
getVisibleItems(org.eclipse.swt.graphics.Rectangle clipping)
int
indexOf(GalleryItem item)
Returns the index of a GalleryItem.boolean
isLowQualityOnUserAction()
protected boolean
isSelected(GalleryItem item)
boolean
isUseControlColors()
boolean
isVertical()
Checks if the Gallery was created with SWT.V_SCROLL (ie has a vertical scroll bar).boolean
isVirtualGroups()
boolean
isVirtualGroupsCompatibilityMode()
protected void
notifySelectionListeners(GalleryItem item, int index, boolean isDefault)
Send a selection event for a gallery itemprotected void
notifyTreeListeners(GalleryItem item, boolean state)
Send an Expand event for a GalleryItem(package private) void
onDispose()
Clean up the Gallery and renderers on dispose.(package private) void
onMouseDoubleClick(org.eclipse.swt.widgets.Event e)
(package private) void
onMouseDown(org.eclipse.swt.widgets.Event e)
(package private) void
onMouseHandleLeft(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
private void
onMouseHandleLeftMod1(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
private void
onMouseHandleLeftShift(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
(package private) void
onMouseHandleRight(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
Handle right click.(package private) void
onMouseUp(org.eclipse.swt.widgets.Event e)
(package private) void
onPaint(org.eclipse.swt.graphics.GC gc)
void
redraw(GalleryItem item)
Redraw the item given as parameter.void
refresh(int index)
Refresh item by firering SWT.SetData.void
remove(int index)
void
remove(GalleryItem item)
void
removeAll()
void
removeSelectionListener(org.eclipse.swt.events.SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when the receiver's selection changes.void
removeTreeListener(org.eclipse.swt.events.SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when items in the receiver are expanded or collapsed.protected void
scrollHorizontal()
protected void
scrollVertical()
private void
select(int from, int to)
private void
select(GalleryItem from, GalleryItem to)
void
selectAll()
Selects all of the items in the receiver.protected void
sendPaintItemEvent(org.eclipse.swt.widgets.Item item, int index, org.eclipse.swt.graphics.GC gc, int x, int y, int width, int height)
Send SWT.PaintItem for one item.void
setAntialias(int antialias)
Sets the gallery's anti-aliasing value to the parameter, which must be one ofSWT.DEFAULT
,SWT.OFF
orSWT.ON
.void
setBackground(org.eclipse.swt.graphics.Color color)
protected void
setData(GalleryItem galleryItem, int index)
Sends SWT.SetData event.void
setForeground(org.eclipse.swt.graphics.Color color)
void
setGroupRenderer(AbstractGalleryGroupRenderer groupRenderer)
void
setHigherQualityDelay(int higherQualityDelay)
Set the delay after the last user action before the redraw at higher quality is triggeredvoid
setInterpolation(int interpolation)
Sets the gallery's interpolation setting to the parameter, which must be one ofSWT.DEFAULT
,SWT.NONE
,SWT.LOW
orSWT.HIGH
.void
setItemCount(int count)
Sets the number of root-level items contained in the receiver.void
setItemRenderer(AbstractGalleryItemRenderer itemRenderer)
Set item receiver.void
setLowQualityOnUserAction(boolean lowQualityOnUserAction)
If set to true, the gallery will disable antialiasing and interpolation while the user is resizing or scrolling the gallery.protected void
setSelected(GalleryItem item, boolean selected, boolean notifyListeners)
Toggle item selection statusvoid
setSelection(GalleryItem[] items)
void
setUseControlColors(boolean useControlColors)
Set useControlColors to true in order to get colors from parent Control (SWT default).void
setVertical(boolean vertical)
Deprecated.void
setVirtualGroupDefaultItemCount(int defaultItemCount)
Set the item count used when a group is not yet initialized (with virtual groups).void
setVirtualGroups(boolean virtualGroups)
Enable virtual groupsvoid
setVirtualGroupsCompatibilityMode(boolean compatibilityMode)
Enable the compatibility workaround for problems with the ultra virtual mode.void
showItem(GalleryItem item)
Scroll the Gallery in order to make 'item' visible.private void
updateItem(GalleryItem parentItem, int i, boolean create)
If table is virtual and item at pos i has not been set, call the callback listener to set its value.private void
updateScrollBarProperties(org.eclipse.swt.widgets.ScrollBar bar, int clientSize, int totalSize)
Move the scrollbar to reflect the current visible items position.protected void
updateScrollBarsProperties()
Move the scrollbar to reflect the current visible items position.protected void
updateStructuralValues(boolean keepLocation)
Deprecated.UseupdateStructuralValues(GalleryItem,boolean)
insteadprotected void
updateStructuralValues(GalleryItem changedGroup, boolean keepLocation)
Recalculate structural values using the group renderer
Gallery and item size will be updated.private void
validateTranslation()
Check the current translation value.-
Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
-
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
-
-
-
-
Field Detail
-
BUG_PLATFORM_LINUX_GTK_174932
private static final java.lang.String BUG_PLATFORM_LINUX_GTK_174932
- See Also:
- Constant Field Values
-
DEBUG
protected static boolean DEBUG
Used to enable debug logging in the Gallery widget.
-
items
GalleryItem[] items
-
selection
private GalleryItem[] selection
-
selectionFlags
protected int[] selectionFlags
Selection bit flags. Each 'int' contains flags for 32 items.
-
virtual
boolean virtual
Virtual mode flag.
-
virtualGroups
boolean virtualGroups
Ultra virtual : non visible groups are not initialized.
-
virtualGroupsCompatibilityMode
boolean virtualGroupsCompatibilityMode
-
virtualGroupDefaultItemCount
int virtualGroupDefaultItemCount
-
vertical
boolean vertical
Scrolling direction flag. True : V_SCROLL, false : H_SCROLL.
-
multi
boolean multi
Multi-selection flag
-
interpolation
int interpolation
Image quality : interpolation
-
antialias
int antialias
Image quality : antialias
-
gHeight
private int gHeight
-
gWidth
private int gWidth
-
lastIndexOf
int lastIndexOf
-
lastSingleClick
protected GalleryItem lastSingleClick
Keeps track of the last selected item. This is necessary to support "Shift+Mouse button" where we have to select all items between the previous and the current item and keyboard navigation.
-
translate
protected int translate
Current translation (scroll bar position). Can be used by renderer during paint.
-
lowQualityOnUserAction
boolean lowQualityOnUserAction
Low quality on user action : decrease drawing quality on scrolling or resize. (faster)
-
lastTranslateValue
protected int lastTranslateValue
-
lastControlWidth
protected int lastControlWidth
-
lastControlHeight
protected int lastControlHeight
-
lastContentHeight
protected int lastContentHeight
-
lastContentWidth
protected int lastContentWidth
-
higherQualityDelay
protected int higherQualityDelay
-
mouseClickHandled
private boolean mouseClickHandled
Keep track of processing the current mouse event.
-
backgroundColor
private org.eclipse.swt.graphics.Color backgroundColor
Background color, if Control#getBackground() is not used.- See Also:
useControlColors
-
foregroundColor
private org.eclipse.swt.graphics.Color foregroundColor
Foreground color, if Control#getForeground() is not used.- See Also:
useControlColors
-
useControlColors
private boolean useControlColors
If set to true, the gallery will get colors from parent Control. This may generate more objects and slightly slow down the application. See Bug 279822 : https://bugs.eclipse.org/bugs/show_bug.cgi?id=279822
-
itemRenderer
AbstractGalleryItemRenderer itemRenderer
-
groupRenderer
AbstractGalleryGroupRenderer groupRenderer
-
redrawTimer
java.lang.Runnable redrawTimer
-
-
Constructor Detail
-
Gallery
public Gallery(org.eclipse.swt.widgets.Composite parent, int style)
Create a Gallery- Parameters:
parent
-style
- - SWT.VIRTUAL switches in virtual mode.
SWT.V_SCROLL add vertical slider and switches to vertical mode.
SWT.H_SCROLL add horizontal slider and switches to horizontal mode.
if both V_SCROLL and H_SCROLL are specified, the gallery is in vertical mode by default. Mode can be changed afterward using setVertical
SWT.MULTI allows only several items to be selected at the same time.
-
-
Method Detail
-
getItemCount
public int getItemCount()
Return the number of root-level items in the receiver. Does not include children.- Returns:
-
setItemCount
public void setItemCount(int count)
Sets the number of root-level items contained in the receiver. Only work in VIRTUAL mode.
-
getItemRenderer
public AbstractGalleryItemRenderer getItemRenderer()
Get current item renderer- Returns:
-
setItemRenderer
public void setItemRenderer(AbstractGalleryItemRenderer itemRenderer)
Set item receiver. Usually, this does not trigger gallery update. redraw must be called right after setGroupRenderer to reflect this change.- Parameters:
itemRenderer
-
-
addSelectionListener
public void addSelectionListener(org.eclipse.swt.events.SelectionListener listener)
Adds the listener to the collection of listeners who will be notified when the receiver's selection changes, by sending it one of the messages defined in theSelectionListener
interface.When
widgetSelected
is called, the item field of the event object is valid.- Parameters:
listener
- the listener which should be notified- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
SelectionListener
,removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,SelectionEvent
-
removeSelectionListener
public void removeSelectionListener(org.eclipse.swt.events.SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when the receiver's selection changes.- Parameters:
listener
- the listener which should no longer be notified- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
SelectionListener
,addSelectionListener(SelectionListener)
-
removeTreeListener
public void removeTreeListener(org.eclipse.swt.events.SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when items in the receiver are expanded or collapsed.- Parameters:
listener
-
-
addTreeListener
public void addTreeListener(org.eclipse.swt.events.TreeListener listener)
Adds the listener to the collection of listeners who will be notified when an item in the receiver is expanded or collapsed by sending it one of the messages defined in the TreeListener interface.- Parameters:
listener
-
-
sendPaintItemEvent
protected void sendPaintItemEvent(org.eclipse.swt.widgets.Item item, int index, org.eclipse.swt.graphics.GC gc, int x, int y, int width, int height)
Send SWT.PaintItem for one item.- Parameters:
item
-index
-gc
-x
-y
-
-
isLowQualityOnUserAction
public boolean isLowQualityOnUserAction()
- Returns:
-
setLowQualityOnUserAction
public void setLowQualityOnUserAction(boolean lowQualityOnUserAction)
If set to true, the gallery will disable antialiasing and interpolation while the user is resizing or scrolling the gallery. This enables faster redraws at the cost of lower image quality. When every redraw is finished a last one will be issued using the default (higher) quality.- Parameters:
lowQualityOnUserAction
-- See Also:
setHigherQualityDelay(int)
-
getHigherQualityDelay
public int getHigherQualityDelay()
- Returns:
- See Also:
setHigherQualityDelay(int)
-
setHigherQualityDelay
public void setHigherQualityDelay(int higherQualityDelay)
Set the delay after the last user action before the redraw at higher quality is triggered- Parameters:
higherQualityDelay
-- See Also:
setLowQualityOnUserAction(boolean)
-
getInterpolation
public int getInterpolation()
- Returns:
- See Also:
setInterpolation(int)
-
setInterpolation
public void setInterpolation(int interpolation)
Sets the gallery's interpolation setting to the parameter, which must be one ofSWT.DEFAULT
,SWT.NONE
,SWT.LOW
orSWT.HIGH
.- Parameters:
interpolation
-
-
getAntialias
public int getAntialias()
- Returns:
- See Also:
setAntialias(int)
-
setAntialias
public void setAntialias(int antialias)
Sets the gallery's anti-aliasing value to the parameter, which must be one ofSWT.DEFAULT
,SWT.OFF
orSWT.ON
.- Parameters:
antialias
-
-
notifySelectionListeners
protected void notifySelectionListeners(GalleryItem item, int index, boolean isDefault)
Send a selection event for a gallery item- Parameters:
item
-
-
notifyTreeListeners
protected void notifyTreeListeners(GalleryItem item, boolean state)
Send an Expand event for a GalleryItem- Parameters:
item
-index
-
-
_setDefaultRenderers
private void _setDefaultRenderers()
-
_addDisposeListeners
private void _addDisposeListeners()
Add internal dispose listeners to this gallery.
-
_addPaintListeners
private void _addPaintListeners()
Add internal paint listeners to this gallery.
-
_addResizeListeners
private void _addResizeListeners()
Add internal resize listeners to this gallery.
-
_addScrollBarsListeners
private void _addScrollBarsListeners()
Add internal scrollbars listeners to this gallery.
-
_addKeyListeners
private void _addKeyListeners()
-
showItem
public void showItem(GalleryItem item)
Scroll the Gallery in order to make 'item' visible.- Parameters:
item
- Item to show
-
_showItem
void _showItem(GalleryItem item)
-
_addMouseListeners
private void _addMouseListeners()
Add internal mouse listeners to this gallery.
-
select
private void select(int from, int to)
-
select
private void select(GalleryItem from, GalleryItem to)
-
getOrder
private boolean getOrder(GalleryItem before, GalleryItem after)
-
setSelected
protected void setSelected(GalleryItem item, boolean selected, boolean notifyListeners)
Toggle item selection status- Parameters:
item
- Item which state is to be changed.selected
- true is the item is now selected, false if it is now unselected.notifyListeners
- If true, a selection event will be sent to all the current selection listeners.
-
_addSelection
protected void _addSelection(GalleryItem item)
-
_removeSelection
private void _removeSelection(GalleryItem item)
-
_removeSelection
protected void _removeSelection(GalleryItem parent, GalleryItem item)
-
isSelected
protected boolean isSelected(GalleryItem item)
-
deselectAll
public void deselectAll()
Deselects all items.
-
_deselectAll
protected void _deselectAll(boolean notifyListeners)
Deselects all items and send selection event depending on parameter.- Parameters:
notifyListeners
- If true, a selection event will be sent to all the current selection listeners.
-
onMouseDoubleClick
void onMouseDoubleClick(org.eclipse.swt.widgets.Event e)
-
onMouseUp
void onMouseUp(org.eclipse.swt.widgets.Event e)
-
onDispose
void onDispose()
Clean up the Gallery and renderers on dispose.
-
onMouseDown
void onMouseDown(org.eclipse.swt.widgets.Event e)
-
onMouseHandleLeftMod1
private void onMouseHandleLeftMod1(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
-
onMouseHandleLeftShift
private void onMouseHandleLeftShift(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
-
onMouseHandleLeft
void onMouseHandleLeft(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
-
onMouseHandleRight
void onMouseHandleRight(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
Handle right click.- Parameters:
e
-item
- : The item which is under the cursor or nulldown
-up
-
-
onPaint
void onPaint(org.eclipse.swt.graphics.GC gc)
-
getVisibleItems
private int[] getVisibleItems(org.eclipse.swt.graphics.Rectangle clipping)
-
refresh
public void refresh(int index)
Refresh item by firering SWT.SetData.Currently not implemented.
- Parameters:
index
-
-
redraw
public void redraw(GalleryItem item)
Redraw the item given as parameter.- Parameters:
item
-
-
_drawGroup
private void _drawGroup(org.eclipse.swt.graphics.GC gc, int index)
Handle the drawing of root items- Parameters:
gc
-index
-
-
updateItem
private void updateItem(GalleryItem parentItem, int i, boolean create)
If table is virtual and item at pos i has not been set, call the callback listener to set its value.
-
setData
protected void setData(GalleryItem galleryItem, int index)
Sends SWT.SetData event. Used if SWT.VIRTUAL- Parameters:
galleryItem
-index
-
-
updateStructuralValues
protected void updateStructuralValues(boolean keepLocation)
Deprecated.UseupdateStructuralValues(GalleryItem,boolean)
insteadRecalculate structural values using the group renderer
Gallery and item size will be updated.- Parameters:
keepLocation
- if true, the current scrollbars position ratio is saved and restored even if the gallery size has changed. (Visible items stay visible)
-
updateStructuralValues
protected void updateStructuralValues(GalleryItem changedGroup, boolean keepLocation)
Recalculate structural values using the group renderer
Gallery and item size will be updated.- Parameters:
changedGroup
- the group that was modified since the last layout. If the group renderer or more that one group have changed, use null as parameter (full update)keepLocation
- if true, the current scrollbars position ratio is saved and restored even if the gallery size has changed. (Visible items stay visible)
-
calculateSize
private int calculateSize(GalleryItem onlyUpdateGroup)
Calculate full height (or width) of the Gallery. The group renderer is used to calculate the size of each group.- Returns:
-
updateScrollBarsProperties
protected void updateScrollBarsProperties()
Move the scrollbar to reflect the current visible items position.
The bar which is moved depends of the current gallery scrolling : vertical or horizontal.
-
updateScrollBarProperties
private void updateScrollBarProperties(org.eclipse.swt.widgets.ScrollBar bar, int clientSize, int totalSize)
Move the scrollbar to reflect the current visible items position.- Parameters:
bar
- - the scroll bar to moveclientSize
- - Client (visible) area sizetotalSize
- - Total Size
-
validateTranslation
private void validateTranslation()
Check the current translation value. Must be > 0 and < gallery size.
Invalid values are fixed.
-
scrollVertical
protected void scrollVertical()
-
scrollHorizontal
protected void scrollHorizontal()
-
addItem
protected void addItem(GalleryItem item, int position)
-
_addItem
private void _addItem(GalleryItem item, int position)
-
getItem
public GalleryItem getItem(int index)
Get the item at index.
If SWT.VIRTUAL is used and the item has not been used yet, the item is created and a SWT.SetData event is fired.- Parameters:
index
- index of the item.- Returns:
- the GalleryItem or null if index is out of bounds
-
_getItem
protected GalleryItem _getItem(GalleryItem parent, int index)
This method is used by items to implement getItem( index )- Parameters:
parent
-index
-- Returns:
-
_getItem
protected GalleryItem _getItem(int index)
Get the item at index.
If SWT.VIRTUAL is used and the item has not been used yet, the item is created and a SWT.SetData is fired.
This is the internal implementation of this method : checkWidget() is not used.- Parameters:
index
-- Returns:
- The item at 'index' (not null)
-
_getItem
protected GalleryItem _getItem(int index, boolean create)
Get the item at 'index'.
If SWT.VIRTUAL is used, 'create' is true and the item has not been used yet, the item is created and a SWT.SetData is fired.- Parameters:
index
-create
-- Returns:
- The item at 'index' or null if there was no item and 'create' was false.
-
_mouseDown
protected boolean _mouseDown(org.eclipse.swt.widgets.Event event)
Forward the mouseDown event to the corresponding group according to the mouse position.- Parameters:
event
- The original MouseEvent- Returns:
- true if Gallery should continue standard mouse click handling
-
getItem
public GalleryItem getItem(org.eclipse.swt.graphics.Point coords)
Get item at pixel position- Parameters:
coords
-- Returns:
- GalleryItem or null
-
_getGroup
private GalleryItem _getGroup(org.eclipse.swt.graphics.Point coords)
Get group at pixel position- Parameters:
coords
-- Returns:
- GalleryItem or null
-
getGroup
public GalleryItem getGroup(org.eclipse.swt.graphics.Point coords)
Get group at pixel position (relative to client area).
This is an experimental API which is exposing an internal method, it may become deprecated at some point.
- Parameters:
coords
-- Returns:
-
clearAll
public void clearAll(boolean all)
Clear all Gallery items.
If the Gallery is virtual, the item count is not reseted and all items will be created again at their first use.- Parameters:
all
- If true, all children will be cleared. Only groups are cleared otherwise.
-
clearAll
public void clearAll()
Clear all GalleryGroups
-
clear
public void clear(int index)
Clear one item.- Parameters:
index
-
-
clear
public void clear(int index, boolean all)
Clear one item and all its children if 'all' is true- Parameters:
index
-all
-
-
indexOf
public int indexOf(GalleryItem item)
Returns the index of a GalleryItem.- Parameters:
parentItem
-item
-- Returns:
-
_indexOf
protected int _indexOf(GalleryItem item)
Returns the index of a GalleryItem when it is a root Item- Parameters:
parentItem
-item
-- Returns:
-
_indexOf
protected int _indexOf(GalleryItem parentItem, GalleryItem item)
Returns the index of a GalleryItem when it is not a root Item- Parameters:
parentItem
-item
-- Returns:
-
getItems
public GalleryItem[] getItems()
-
isUseControlColors
public boolean isUseControlColors()
- Returns:
- true if Gallery uses parent colors.
- See Also:
setUseControlColors(boolean)
-
setUseControlColors
public void setUseControlColors(boolean useControlColors)
Set useControlColors to true in order to get colors from parent Control (SWT default). This may generate more objects on painting and slightly slow down the application. See Bug 279822 : https://bugs.eclipse.org/bugs/show_bug.cgi?id=279822 If enabled, you'll get new Color objects each time you call getXXXColor() on Gallery or GalleryItem. Default is false : colors are stored locally in Gallery, and you'll get the same object each time you call getXXXColor() on Gallery orGalleryItem. The Gallery may not catch color changes on parent control.- Parameters:
useControlColors
-
-
getBackground
public org.eclipse.swt.graphics.Color getBackground()
- Overrides:
getBackground
in classorg.eclipse.swt.widgets.Control
- See Also:
Control.getBackground()
-
getBackground
public org.eclipse.swt.graphics.Color getBackground(boolean galleryOnly)
Returns the receiver's background color.- Parameters:
galleryOnly
- If TRUE, does not try to parent widget or Display defaults to guess the real background color. Note : FALSE is the default behavior.- Returns:
- The background color or null if galleryOnly was used and the gallery has not foreground color set.
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getForeground
public org.eclipse.swt.graphics.Color getForeground()
- Overrides:
getForeground
in classorg.eclipse.swt.widgets.Control
- See Also:
Control.getForeground()
-
getForeground
public org.eclipse.swt.graphics.Color getForeground(boolean galleryOnly)
Returns the receiver's foreground color.- Parameters:
galleryOnly
- If TRUE, does not try to parent widget or Display defaults to guess the real foreground color. Note : FALSE is the default behavior.- Returns:
- The foreground color or null if galleryOnly was used and the gallery has not foreground color set.
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setBackground
public void setBackground(org.eclipse.swt.graphics.Color color)
- Overrides:
setBackground
in classorg.eclipse.swt.widgets.Control
- See Also:
Control.setBackground(org.eclipse.swt.graphics .Color)
-
setForeground
public void setForeground(org.eclipse.swt.graphics.Color color)
- Overrides:
setForeground
in classorg.eclipse.swt.widgets.Control
- See Also:
Control.setForeground(org.eclipse.swt.graphics .Color)
-
isVertical
public boolean isVertical()
Checks if the Gallery was created with SWT.V_SCROLL (ie has a vertical scroll bar).- Returns:
- true if the gallery has the SWT.V_SCROLL style.
-
setVertical
public void setVertical(boolean vertical)
Deprecated.- Parameters:
vertical
-
-
getGroupRenderer
public AbstractGalleryGroupRenderer getGroupRenderer()
-
setGroupRenderer
public void setGroupRenderer(AbstractGalleryGroupRenderer groupRenderer)
-
getSelection
public GalleryItem[] getSelection()
-
getSelectionCount
public int getSelectionCount()
-
selectAll
public void selectAll()
Selects all of the items in the receiver.
-
_selectAll
protected void _selectAll()
-
setSelection
public void setSelection(GalleryItem[] items)
-
removeAll
public void removeAll()
-
remove
public void remove(int index)
-
remove
public void remove(GalleryItem item)
-
_remove
protected void _remove(int index)
-
_remove
protected void _remove(GalleryItem parent, int index)
-
_arrayRemoveItem
protected java.lang.Object[] _arrayRemoveItem(java.lang.Object[] array, int index)
-
_arrayAddItem
protected java.lang.Object[] _arrayAddItem(java.lang.Object[] array, java.lang.Object object, int index)
Adds an item to an array.- Parameters:
array
-object
-index
- : if index == -1, item is added at the end of the array.- Returns:
-
_arrayIndexOf
protected int _arrayIndexOf(int[] array, int value)
-
_arrayIndexOf
protected int _arrayIndexOf(java.lang.Object[] array, java.lang.Object value)
-
_arrayRemoveItem
protected int[] _arrayRemoveItem(int[] array, int index)
-
_setGalleryItems
public void _setGalleryItems(GalleryItem[] items)
-
isVirtualGroups
public boolean isVirtualGroups()
- Returns:
- See Also:
setVirtualGroups(boolean)
-
setVirtualGroups
public void setVirtualGroups(boolean virtualGroups)
Enable virtual groupsWhen a gallery has the SWT.VIRTUAL flag, only items are initialized on display. All groups need to be initialized from the beginning to calculate the total size of the content.
Virtual groups enable creating groups AND items lazily at the cost of a poor approximation of the total size of the content.
While a group isn't initialized, the item count defined as default item count is used.
When a group comes into view, it is initialized using the setData event, and the size of the gallery content is updated to match the real value.
From the developer point of view, virtual groups uses exactly the same code as the standard virtual mode of SWT.
This mode can create visual glitches with code that automatically scrolls the widget such as SAT Smooth Scrolling. In that case, you can enable the compatibility mode which is little less lazy that the default virtual groups, but still better than the standard virtual mode
- Parameters:
virtualGroups
-- See Also:
setVirtualGroupDefaultItemCount(int)
,setVirtualGroupsCompatibilityMode(boolean)
-
getVirtualGroupDefaultItemCount
public int getVirtualGroupDefaultItemCount()
- Returns:
- See Also:
setVirtualGroupDefaultItemCount(int)
-
isVirtualGroupsCompatibilityMode
public boolean isVirtualGroupsCompatibilityMode()
- Returns:
- See Also:
setVirtualGroupsCompatibilityMode(boolean)
-
setVirtualGroupsCompatibilityMode
public void setVirtualGroupsCompatibilityMode(boolean compatibilityMode)
Enable the compatibility workaround for problems with the ultra virtual mode.- Parameters:
compatibilityMode
-- See Also:
setVirtualGroups(boolean)
-
setVirtualGroupDefaultItemCount
public void setVirtualGroupDefaultItemCount(int defaultItemCount)
Set the item count used when a group is not yet initialized (with virtual groups). Since the virtual groups make the size of the gallery change while scrolling, a fine tuned item count can improve the accuracy of the slider.- Parameters:
defaultItemCount
-- See Also:
setVirtualGroups(boolean)
-
-