I’m trying to use JGoPalette in my application along side my JGoView as a tool palette. Essentially, drag an icon from the palette onto the JGoView and a new object of that type is added to the diagram.
<I wanted to post a screen capture, but the Insert Image function is not working >
I'm using JGoIconicNodes in the palette to have a 32x32 icon with a label underneath it (default positioning).
My problem is that I can't figure out how to center my JGoIconicNodes in the vertical palette so they line up neatly. The label text is a slightly different length for each and they are left aligning to the palette grid. I've played with a number of settings and can't figure out how to center them.
Clues? I'm sure this must be a common need.
Here's my code if it helps.
private void createPallete(Composite parent) {
//Create the pallete
palette = new JGoPalette(parent, SWT.VERTICAL | SWT.V_SCROLL);
//Place in the grid
GridData gridData = new GridData();
gridData.widthHint = 70;
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
palette.setLayoutData(gridData);
//Create icons for the palette
createPaletteNode("Content", "icons/Content_32.gif");
createPaletteNode("Question", "icons/Question_32.gif");
createPaletteNode("Jump", "icons/Jump_32.gif");
createPaletteNode("Browser App", "icons/BrowserApp_32.gif");
createPaletteNode("Desktop App", "icons/DesktopApp_32.gif");
}
private void createPaletteNode(String text, String iconFile) {
JGoIconicNode node = new JGoIconicNode(text);
node.getLabel().setFontSize(8);
ImageDescriptor imageDescriptor =
AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, iconFile);
ImageData imageData = imageDescriptor.getImageData();
JGoImage img = new JGoImage();
img.setResizable(false);
img.setImage(imageData);
img.setSize(img.getImage().width, img.getImage().height);
node.setIcon(img);
palette.getDocument().addObjectAtTail(node);
}
//Create the pallete
palette = new JGoPalette(parent, SWT.VERTICAL | SWT.V_SCROLL);
//Place in the grid
GridData gridData = new GridData();
gridData.widthHint = 70;
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
palette.setLayoutData(gridData);
//Create icons for the palette
createPaletteNode("Content", "icons/Content_32.gif");
createPaletteNode("Question", "icons/Question_32.gif");
createPaletteNode("Jump", "icons/Jump_32.gif");
createPaletteNode("Browser App", "icons/BrowserApp_32.gif");
createPaletteNode("Desktop App", "icons/DesktopApp_32.gif");
}
private void createPaletteNode(String text, String iconFile) {
JGoIconicNode node = new JGoIconicNode(text);
node.getLabel().setFontSize(8);
ImageDescriptor imageDescriptor =
AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, iconFile);
ImageData imageData = imageDescriptor.getImageData();
JGoImage img = new JGoImage();
img.setResizable(false);
img.setImage(imageData);
img.setSize(img.getImage().width, img.getImage().height);
node.setIcon(img);
palette.getDocument().addObjectAtTail(node);
}