/*******************************************************************************
* Copyright (c) 2006-2007 Nicolas Richeton.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors :
* Nicolas Richeton (nicolas.richeton@gmail.com) - initial implementation
*******************************************************************************/
package org.eclipse.nebula.snippets.gallery;
import org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer;
import org.eclipse.nebula.widgets.gallery.Gallery;
import org.eclipse.nebula.widgets.gallery.GalleryItem;
import org.eclipse.nebula.widgets.gallery.NoGroupRenderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* <p>This snippet displays a simple gallery with an hover effect. </p>
*
* <p>
* NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT. THIS IS A
* PRE-RELEASE ALPHA VERSION. USERS SHOULD EXPECT API CHANGES IN FUTURE
* VERSIONS.
* </p>
* @see HoverListener
* @author Nicolas Richeton (nicolas.richeton@gmail.com)
*/
public class SnippetHover {
public static void main(String[] args) {
Display display = new Display();
Image itemImage = new Image(display, Program
.findProgram("jpg").getImageData()); //$NON-NLS-1$
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Gallery gallery = new Gallery(shell, SWT.V_SCROLL | SWT.MULTI);
// Renderers
NoGroupRenderer gr = new NoGroupRenderer();
gr.setMinMargin(2);
gr.setItemHeight(56);
gr.setItemWidth(72);
gr.setAutoMargin(true);
gallery.setGroupRenderer(gr);
DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
gallery.setItemRenderer(ir);
GalleryItem group = new GalleryItem(gallery, SWT.NONE);
for (int i = 0; i < 100; i++) {
GalleryItem item = new GalleryItem(group, SWT.NONE);
if (itemImage != null) {
item.setImage(itemImage);
}
item.setText("Item " + i); //$NON-NLS-1$
}
new HoverListener(gallery, Display.getCurrent().getSystemColor(
SWT.COLOR_WHITE), Display.getCurrent().getSystemColor(
SWT.COLOR_CYAN), 500, 5000);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
if (itemImage != null)
itemImage.dispose();
display.dispose();
}
}