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.4+
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.
Constructor | Description |
---|---|
Gallery(org.eclipse.swt.widgets.Composite parent,
int style) |
Create a Gallery
|
Modifier and Type | Method | Description |
---|---|---|
void |
_setGalleryItems(GalleryItem[] items) |
|
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() |
|
boolean |
isUseControlColors() |
|
boolean |
isVertical() |
Checks if the Gallery was created with SWT.V_SCROLL (ie has a vertical
scroll bar).
|
boolean |
isVirtualGroups() |
|
boolean |
isVirtualGroupsCompatibilityMode() |
|
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.
|
void |
selectAll() |
Selects all of the items in the receiver.
|
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) |
|
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.
|
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.
|
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
changed, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
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
- 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
- public void showItem(GalleryItem item)
item
- Item to showpublic void deselectAll()
public void refresh(int index)
Currently not implemented.
index
- public void redraw(GalleryItem item)
item
- public GalleryItem getItem(int index)
index
- index of the item.public 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
- 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
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
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
public void setForeground(org.eclipse.swt.graphics.Color color)
setForeground
in class org.eclipse.swt.widgets.Control
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()
public void setSelection(GalleryItem[] items)
public void removeAll()
public void remove(int index)
public void remove(GalleryItem item)
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)