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 a Gallery
whose
GalleryItem
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 which
GalleryItem
population is expensive (for example, retrieving
values from an external source).
Here is an example of using a Gallery
with style
VIRTUAL
:
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());
}
});
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.
NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT.
Modifier and Type | Field and Description |
---|---|
(package private) int |
antialias
Image quality : antialias
|
protected static boolean |
DEBUG
Used to enable debug logging in the Gallery widget.
|
(package private) AbstractGalleryGroupRenderer |
groupRenderer |
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.
|
(package private) boolean |
multi
Multi-selection flag
|
(package private) java.lang.Runnable |
redrawTimer |
protected int[] |
selectionFlags
Selection bit flags.
|
protected int |
translate
Current translation (scroll bar position).
|
(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 and Description |
---|
Gallery(org.eclipse.swt.widgets.Composite parent,
int style)
Create a Gallery
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected GalleryItem |
_getItem(GalleryItem parent,
int index)
This method is used by items to implement getItem( index )
|
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. |
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 int |
_indexOf(GalleryItem item)
Returns the index of a GalleryItem when it is a root Item
|
protected int |
_indexOf(GalleryItem parentItem,
GalleryItem item)
Returns the index of a GalleryItem when it is not a root Item
|
protected boolean |
_mouseDown(org.eclipse.swt.widgets.Event event)
Forward the mouseDown event to the corresponding group according to the
mouse position.
|
protected void |
_remove(GalleryItem parent,
int index) |
protected void |
_remove(int index) |
protected void |
_removeSelection(GalleryItem parent,
GalleryItem item) |
protected void |
_selectAll() |
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 the
SelectionListener 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.
|
void |
clear(int index)
Clear one item.
|
void |
clear(int index,
boolean all)
Clear one item and all its children if 'all' is true
|
void |
clearAll()
Clear all GalleryGroups
|
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. |
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 position
|
int |
getItemCount()
Return the number of root-level items in the receiver.
|
AbstractGalleryItemRenderer |
getItemRenderer()
Get current item renderer
|
GalleryItem[] |
getItems() |
GalleryItem[] |
getSelection() |
int |
getSelectionCount() |
int |
getVirtualGroupDefaultItemCount() |
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 item
|
protected 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) |
(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(GalleryItem item) |
void |
remove(int index) |
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() |
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 of
SWT.DEFAULT , SWT.OFF or
SWT.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 triggered
|
void |
setInterpolation(int interpolation)
Sets the gallery's interpolation setting to the parameter, which must be
one of
SWT.DEFAULT , SWT.NONE ,
SWT.LOW or SWT.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 status
|
void |
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 groups
|
void |
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.
|
protected void |
updateScrollBarsProperties()
Move the scrollbar to reflect the current visible items position.
|
protected void |
updateStructuralValues(boolean keepLocation)
Deprecated.
Use
updateStructuralValues(GalleryItem,boolean)
instead |
protected void |
updateStructuralValues(GalleryItem changedGroup,
boolean keepLocation)
Recalculate structural values using the group renderer
Gallery and item size will be updated. |
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
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, 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
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
protected static boolean DEBUG
GalleryItem[] items
protected int[] selectionFlags
boolean virtual
boolean virtualGroups
boolean virtualGroupsCompatibilityMode
int virtualGroupDefaultItemCount
boolean vertical
boolean multi
int interpolation
int antialias
int lastIndexOf
protected GalleryItem lastSingleClick
protected int translate
boolean lowQualityOnUserAction
protected int lastTranslateValue
protected int lastControlWidth
protected int lastControlHeight
protected int lastContentHeight
protected int lastContentWidth
protected int higherQualityDelay
AbstractGalleryItemRenderer itemRenderer
AbstractGalleryGroupRenderer groupRenderer
java.lang.Runnable redrawTimer
public Gallery(org.eclipse.swt.widgets.Composite parent, int style)
parent
- style
- - SWT.VIRTUAL switches in virtual mode. public int getItemCount()
public void setItemCount(int count)
public AbstractGalleryItemRenderer getItemRenderer()
public void setItemRenderer(AbstractGalleryItemRenderer itemRenderer)
itemRenderer
- public void addSelectionListener(org.eclipse.swt.events.SelectionListener listener)
SelectionListener
interface.
When widgetSelected
is called, the item field of the event
object is valid.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- org.eclipse.swt.SWTException
- SelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,
SelectionEvent
public void removeSelectionListener(org.eclipse.swt.events.SelectionListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- org.eclipse.swt.SWTException
- SelectionListener
,
addSelectionListener(SelectionListener)
public void removeTreeListener(org.eclipse.swt.events.SelectionListener listener)
listener
- public void addTreeListener(org.eclipse.swt.events.TreeListener listener)
listener
- 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)
item
- index
- gc
- x
- y
- public boolean isLowQualityOnUserAction()
public void setLowQualityOnUserAction(boolean lowQualityOnUserAction)
lowQualityOnUserAction
- setHigherQualityDelay(int)
public int getHigherQualityDelay()
setHigherQualityDelay(int)
public void setHigherQualityDelay(int higherQualityDelay)
higherQualityDelay
- setLowQualityOnUserAction(boolean)
public int getInterpolation()
setInterpolation(int)
public void setInterpolation(int interpolation)
SWT.DEFAULT
, SWT.NONE
,
SWT.LOW
or SWT.HIGH
.interpolation
- public int getAntialias()
setAntialias(int)
public void setAntialias(int antialias)
SWT.DEFAULT
, SWT.OFF
or
SWT.ON
.antialias
- protected void notifySelectionListeners(GalleryItem item, int index, boolean isDefault)
item
- protected void notifyTreeListeners(GalleryItem item, boolean state)
item
- index
- public void showItem(GalleryItem item)
item
- Item to showvoid _showItem(GalleryItem item)
protected void setSelected(GalleryItem item, boolean selected, boolean notifyListeners)
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.protected void _addSelection(GalleryItem item)
protected void _removeSelection(GalleryItem parent, GalleryItem item)
protected boolean isSelected(GalleryItem item)
public void deselectAll()
protected void _deselectAll(boolean notifyListeners)
notifyListeners
- If true, a selection event will be sent to all the current
selection listeners.void onMouseDoubleClick(org.eclipse.swt.widgets.Event e)
void onMouseUp(org.eclipse.swt.widgets.Event e)
void onDispose()
void onMouseDown(org.eclipse.swt.widgets.Event e)
void onMouseHandleLeft(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
void onMouseHandleRight(org.eclipse.swt.widgets.Event e, GalleryItem item, boolean down, boolean up)
e
- item
- : The item which is under the cursor or nulldown
- up
- void onPaint(org.eclipse.swt.graphics.GC gc)
public void refresh(int index)
Currently not implemented.
index
- public void redraw(GalleryItem item)
item
- protected void setData(GalleryItem galleryItem, int index)
galleryItem
- index
- protected void updateStructuralValues(boolean keepLocation)
updateStructuralValues(GalleryItem,boolean)
insteadkeepLocation
- if true, the current scrollbars position ratio is saved and
restored even if the gallery size has changed. (Visible items
stay visible)protected void updateStructuralValues(GalleryItem changedGroup, boolean keepLocation)
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)protected void updateScrollBarsProperties()
protected void scrollVertical()
protected void scrollHorizontal()
protected void addItem(GalleryItem item, int position)
public GalleryItem getItem(int index)
index
- index of the item.protected GalleryItem _getItem(GalleryItem parent, int index)
parent
- index
- protected GalleryItem _getItem(int index)
index
- protected GalleryItem _getItem(int index, boolean create)
index
- create
- protected boolean _mouseDown(org.eclipse.swt.widgets.Event event)
event
- The original MouseEventpublic GalleryItem getItem(org.eclipse.swt.graphics.Point coords)
coords
- 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.
coords
- public void clearAll(boolean all)
all
- If true, all children will be cleared. Only groups are cleared
otherwise.public void clearAll()
public void clear(int index)
index
- public void clear(int index, boolean all)
index
- all
- public int indexOf(GalleryItem item)
parentItem
- item
- protected int _indexOf(GalleryItem item)
parentItem
- item
- protected int _indexOf(GalleryItem parentItem, GalleryItem item)
parentItem
- item
- public GalleryItem[] getItems()
public boolean isUseControlColors()
setUseControlColors(boolean)
public void setUseControlColors(boolean useControlColors)
useControlColors
- public org.eclipse.swt.graphics.Color getBackground()
getBackground
in class org.eclipse.swt.widgets.Control
Control.getBackground()
public org.eclipse.swt.graphics.Color getBackground(boolean galleryOnly)
galleryOnly
- If TRUE, does not try to parent widget or Display defaults to
guess the real background color. Note : FALSE is the default
behavior.org.eclipse.swt.SWTException
- public org.eclipse.swt.graphics.Color getForeground()
getForeground
in class org.eclipse.swt.widgets.Control
Control.getForeground()
public org.eclipse.swt.graphics.Color getForeground(boolean galleryOnly)
galleryOnly
- If TRUE, does not try to parent widget or Display defaults to
guess the real foreground color. Note : FALSE is the default
behavior.org.eclipse.swt.SWTException
- public void setBackground(org.eclipse.swt.graphics.Color color)
setBackground
in class org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Control#setBackground(org.eclipse.swt.graphics
.Color)
public void setForeground(org.eclipse.swt.graphics.Color color)
setForeground
in class org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Control#setForeground(org.eclipse.swt.graphics
.Color)
public boolean isVertical()
public void setVertical(boolean vertical)
vertical
- public AbstractGalleryGroupRenderer getGroupRenderer()
public void setGroupRenderer(AbstractGalleryGroupRenderer groupRenderer)
public GalleryItem[] getSelection()
public int getSelectionCount()
public void selectAll()
protected void _selectAll()
public void setSelection(GalleryItem[] items)
public void removeAll()
public void remove(int index)
public void remove(GalleryItem item)
protected void _remove(int index)
protected void _remove(GalleryItem parent, int index)
protected java.lang.Object[] _arrayRemoveItem(java.lang.Object[] array, int index)
protected java.lang.Object[] _arrayAddItem(java.lang.Object[] array, java.lang.Object object, int index)
array
- object
- index
- : if index == -1, item is added at the end of the 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)
public void _setGalleryItems(GalleryItem[] items)
public boolean isVirtualGroups()
setVirtualGroups(boolean)
public void setVirtualGroups(boolean virtualGroups)
When 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
virtualGroups
- setVirtualGroupDefaultItemCount(int)
,
setVirtualGroupsCompatibilityMode(boolean)
public int getVirtualGroupDefaultItemCount()
setVirtualGroupDefaultItemCount(int)
public boolean isVirtualGroupsCompatibilityMode()
setVirtualGroupsCompatibilityMode(boolean)
public void setVirtualGroupsCompatibilityMode(boolean compatibilityMode)
compatibilityMode
- setVirtualGroups(boolean)
public void setVirtualGroupDefaultItemCount(int defaultItemCount)
defaultItemCount
- setVirtualGroups(boolean)