Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » ZoomExample with ImageFigure
ZoomExample with ImageFigure [message #246955] Wed, 21 January 2009 06:17
Shawn Spiars is currently offline Shawn SpiarsFriend
Messages: 16
Registered: July 2009
Junior Member
I'm trying to get the ZoomExample to work with an ImageFigure which
contains a rather large jpg image (2700 X 4300 pixels). The image shows
up but it's too large and since there are no scroll bars the image is
truncated. I'd like to get the image to start out at a smaller scale. I
tried to attach the image here, but it's too large for the newsgroup.
Any help would be appreciated.

Thanks,
Shawn

package org.eclipse.draw2d.examples.zoom;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import org.eclipse.draw2d.ButtonBorder;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.GroupBoxBorder;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.SchemeBorder;
import org.eclipse.draw2d.ScrollBar;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ZoomImageExample {

private static Figure contents;

public static void main(String args[]){
Display d = new Display();
final Shell shell = new Shell(d);
shell.setSize(800, 800);
LightweightSystem lws = new LightweightSystem(shell);

Figure fig = new Figure();
fig.setLayoutManager(new ToolbarLayout());

final ScrollBar bar = new ScrollBar();
final Label l = new Label("«Zoom»");

l.setBorder(new SchemeBorder(ButtonBorder.SCHEMES.BUTTON_SCROLLBAR));
bar.setThumb(l);
bar.setHorizontal(true);
bar.setMaximum(200);
bar.setMinimum(0);
bar.setExtent(25);

final ZoomContainer panel = new ZoomContainer();
panel.setBorder(new GroupBoxBorder("Zooming figure"));
panel.setMinimumSize(new Dimension(5,5));
panel.setPreferredSize(500, 500);
fig.add(bar);
fig.add(panel);

bar.addPropertyChangeListener("value", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
float z = (bar.getValue()+10) * 0.02f;
panel.setZoom(z);
}
});

panel.add(getContents());
bar.setValue(40);

lws.setContents(fig);

shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();
}

protected static Figure getContents() {
if (contents == null)
contents = createContents();
return contents;
}

private static Figure createContents() {
Figure contents = new Figure();
XYLayout layout = new XYLayout();
contents.setLayoutManager(layout);

String path = "c:/dev/page.jpg";
Image image = new Image(Display.getDefault(), path);
ImageFigure imageFigure = new ImageFigure(image);

layout.setConstraint(imageFigure, new Rectangle(0,0,-1,-1));

contents.add(imageFigure);

return contents;
}

}
Previous Topic:[Announce] GEF 3.5.0 I200901191850 is available
Next Topic:CompoundDirectedGraphLayout has no effect
Goto Forum:
  


Current Time: Tue Apr 23 06:49:13 GMT 2024

Powered by FUDForum. Page generated in 0.03490 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top