use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class DesignEditorUI method resetVisibleArea.
// createTransitionSelectionHandler
public void resetVisibleArea() {
StandardDrawingEditor e = view.getEditor();
e.getLWS().getUpdateManager().performUpdate();
DoubleSize extent = structureView.getPreferredSize();
e.setMinVisibleArea(PrecisionUtilities.round(extent.width), PrecisionUtilities.round(extent.height), false);
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class FrameUIModel method getPreferredSize.
/**
* Compute the preferred size of the widgets based on a given scale.
*/
public DoubleSize getPreferredSize(double scaleFactor) {
// Compute the area needed for all widgets
Rectangle r = computeWidgetArea();
// Add the background image area
r.union(backgroundImage.getBounds());
// Apply scaling to result.
return new DoubleSize(r.width * scaleFactor, r.height * scaleFactor);
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize 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();
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class DesignEditorFrame method getChildrenUtilizedAreaUnscaled.
public Rectangle getChildrenUtilizedAreaUnscaled() {
DoubleSize size = computeFrameSize(1.0);
int width = PrecisionUtilities.round(size.width);
int height = PrecisionUtilities.round(size.height);
return new Rectangle(0, 0, width, height);
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class FrameEditorController method reorderWidget.
private boolean reorderWidget(final IWidget widget, final SimpleWidgetGroup newGroup, final int newIndex) {
final SimpleWidgetGroup prevGroup = widget.getParentGroup();
final int prevIndex = prevGroup.indexOf(widget);
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
if (index == prevIndex) {
return true;
}
}
DoublePoint prevGroupStartPos = prevGroup.get(0).getShape().getOrigin();
final double prevGroupStartX = prevGroupStartPos.x;
final double prevGroupStartY = prevGroupStartPos.y;
DoubleSize prevSize = widget.getShape().getSize();
final double prevWidth = prevSize.width;
final double prevHeight = prevSize.height;
DoubleRectangle newBds = newGroup.get(0).getEltBounds();
double heightFactor = (widget instanceof ListItem) ? getHeightFactor(widget, newGroup) : 1.0;
final double newWidth = newBds.width;
final double newHeight = newBds.height * heightFactor;
final double newGroupStartX = newBds.x;
final double newGroupStartY = newBds.y;
Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
final boolean groupRendered = ((Boolean) rendered).booleanValue();
final boolean widgetRendered = widget.isRendered();
reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {
@Override
public String getPresentationName() {
return REORDER_WIDGET;
}
@Override
public void redo() {
super.redo();
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
}
reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
noteEditCheckRegenerate(prevGroup, newGroup, this);
}
@Override
public void undo() {
super.undo();
reorderGroupWidget(widget, prevWidth, prevHeight, prevIndex, newGroup, prevGroup, newGroupStartX, newGroupStartY, prevGroupStartX, prevGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(widgetRendered);
}
noteEditCheckRegenerate(newGroup, prevGroup, this);
}
};
noteEditCheckRegenerate(prevGroup, newGroup, edit);
undoMgr.addEdit(edit);
return true;
}
Aggregations