WebToolBar wigToolBar = new WebToolBar ( WebToolBar.HORIZONTAL );
wigToolBar.setFloatable ( false );
wigToolBar.setToolbarStyle ( ToolbarStyle.attached );
imagegalleryPanel.add ( wigToolBar, BorderLayout.NORTH );
final WebImageGallery wig = new WebImageGallery ();
wig.setPreferredColumnCount ( 3 );
wig.setTransferHandler ( new GalleryTransferHandler ( wig ) );
wig.addImage ( loadIcon ( "1.jpg" ) );
wig.addImage ( loadIcon ( "2.jpg" ) );
wig.addImage ( loadIcon ( "3.jpg" ) );
wig.addImage ( loadIcon ( "4.jpg" ) );
wig.addImage ( loadIcon ( "5.jpg" ) );
imagegalleryPanel.add ( wig.getView ( false ), BorderLayout.CENTER );
WebButton add = new WebButton ( "Add", loadIcon ( "add.png" ) );
add.setRound ( StyleConstants.smallRound );
add.addActionListener ( new ActionListener ()
{
private WebFileChooser fileChooser = null;
@Override
public void actionPerformed ( ActionEvent e )
{
if ( fileChooser == null )
{
fileChooser = new WebFileChooser ();
fileChooser.setDialogTitle ( "Choose an image to add" );
fileChooser.setMultiSelectionEnabled ( true );
fileChooser.setAcceptAllFileFilterUsed ( false );
fileChooser.addChoosableFileFilter ( GlobalConstants.IMAGES_FILTER );
}
if ( fileChooser.showOpenDialog ( owner ) == WebFileChooser.APPROVE_OPTION )
{
for ( File file : fileChooser.getSelectedFiles () )
{
wig.addImage ( 0, new ImageIcon ( file.getAbsolutePath () ) );
}
wig.setSelectedIndex ( 0 );
}
}
} );
wigToolBar.add ( add );
WebButton remove = new WebButton ( "Remove", loadIcon ( "remove.png" ) );
remove.setRound ( StyleConstants.smallRound );
remove.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
wig.removeImage ( wig.getSelectedIndex () );
}
} );
wigToolBar.add ( remove );
WebLabel infoLabel = new WebLabel ( "To add an image simply drag it to the gallery", loadIcon ( "info.png" ), WebLabel.CENTER );