use of org.eclipse.draw2d.XYLayout in project cogtool by cogtool.
the class StructureViewUIModel method setUpContents.
protected void setUpContents() {
contents = new ScalableFrameFigure(GraphicsUtil.defaultWidgetColor);
contents.setScale(1.0);
contents.setLayoutManager(new XYLayout());
installFrames();
// Resize to preferred size.
DoubleSize s = getPreferredSize();
contents.setSize(PrecisionUtilities.round(s.width), PrecisionUtilities.round(s.height));
}
use of org.eclipse.draw2d.XYLayout in project cogtool by cogtool.
the class FrameUIModel method setUpFrameContents.
/**
* Set up the contents of the frame.
* This creates the scalable figure and sets the initial scaling.
*
* The layout manager is also created with an XYLayout to allow absolute
* positioning of elements.
*
* All structures needed to support drawing and selecting objects are
* created here.
*
* @param double Scale: used to set the initial size of the contents.
*/
protected void setUpFrameContents(double scale) {
// Set up the content pane
// Create the underlying contents pane.
// And set the contents pane's default widget color.
contents = new ScalableFrameFigure(frame.getWidgetColor());
contents.setScale(scale);
contents.setLayoutManager(new XYLayout());
// Create a new graphical widget for each widget in Frame.
Iterator<IWidget> modelWidgets = frame.getWidgets().iterator();
while (modelWidgets.hasNext()) {
IWidget w = modelWidgets.next();
createGraphicalWidget(w);
}
// Initialize the background image
backgroundImage = new ImageFigure();
final byte[] bgImg = frame.getBackgroundImage();
if (bgImg != null) {
if (lazyLoading) {
// Use a thread to load the image, then set it later
ThreadManager.IWorkThread imageLoadThread = new CogToolWorkThread() {
protected Image img = null;
public void doWork() {
// Performed by the scheduled thread
img = new Image(null, new ByteArrayInputStream(bgImg));
}
@Override
public void doneCallback() {
// Performed by the main UI thread
if (img != null) {
if (isDisposed) {
img.dispose();
} else {
backgroundImage.setImage(img);
}
}
// TODO: We might want to add a real logging package
if (exBucket.containsExceptions()) {
// TODO: It is unclear what to do here. Maybe
// we should just replace failed images with red
// Xs rather than popping up a dialog box
System.err.println(exBucket);
// RcvrExceptionHandler.recoverWorkThread(this,
// interaction);
}
}
};
ThreadManager.startNewThread(imageLoadThread, 2);
} else {
try {
// = AUIModel.imageCache.get(frame);
Image img = null;
if (img == null) {
img = new Image(null, new ByteArrayInputStream(bgImg));
// AUIModel.imageCache.put(frame, img);
}
backgroundImage.setImage(img);
} catch (SWTException ex) {
throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
}
}
backgroundImage.setBounds(PrecisionUtilities.getDraw2DRectangle(frame.getBackgroundBounds()));
}
// Always align the picture to top left corner
backgroundImage.setAlignment(PositionConstants.NORTH | PositionConstants.WEST);
// Resize to preferred size.
DoubleSize s = getPreferredSize();
// Set the size of the contents area to fit all elements.
contents.setSize(PrecisionUtilities.round(s.width), PrecisionUtilities.round(s.height));
// Draw all widgets.
drawWidgets();
}
Aggregations