use of org.eclipse.draw2d.geometry.Rectangle in project cogtool by cogtool.
the class DesignEditorFrame method resetFrameSize.
protected void resetFrameSize() {
// Update the size with the preferred size of the contents.
DoubleSize size = computeFrameSize(getScale());
int width = PrecisionUtilities.round(size.width);
int height = PrecisionUtilities.round(size.height);
// Set the initial size to force a repaint call.
// Call super, since we actually want to set the Size.. vs the current
// which will try and resize to the "current size"
// while this is actually a flag to force a paint.
super.setSize(width, height);
super.setPreferredSize(width, height);
// Force this to always take the extra space up by frameWidget Box
if (usesSpeaker) {
height -= speakerBox.getPreferredSize().height;
}
height -= (inputDeviceBox.getPreferredSize().height + inputDeviceBox.getInsets().getHeight());
height -= nameLabel.getPreferredSize().height;
frameWidgetBox.setSize(width, height);
frameWidgetBox.setPreferredSize(width, height);
if (usesSpeaker) {
int insetsWidth = getInsets().getWidth();
int speakerTextWidth = width - insetsWidth - (4 * SPEAKER_DIVIDER_WIDTH) - speakerImgWidth - LISTEN_TIME_WIDTH - 1;
Rectangle layoutConstraint = new Rectangle(speakerImgWidth + SPEAKER_DIVIDER_WIDTH, 0, speakerTextWidth, speakerImgHeight);
speakerLayout.setConstraint(speakerText, layoutConstraint);
layoutConstraint = new Rectangle(speakerImgWidth + SPEAKER_DIVIDER_WIDTH + speakerTextWidth, 0, SPEAKER_DIVIDER_WIDTH, speakerImgHeight);
speakerLayout.setConstraint(divider, layoutConstraint);
layoutConstraint = new Rectangle(speakerImgWidth + (2 * SPEAKER_DIVIDER_WIDTH) + speakerTextWidth, 0, LISTEN_TIME_WIDTH, speakerImgHeight);
speakerLayout.setConstraint(listenTime, layoutConstraint);
layoutConstraint = new Rectangle(speakerImgWidth + (3 * SPEAKER_DIVIDER_WIDTH) + speakerTextWidth + LISTEN_TIME_WIDTH, 0, SPEAKER_DIVIDER_WIDTH, speakerImgHeight);
speakerLayout.setConstraint(timeWestBorder, layoutConstraint);
}
}
use of org.eclipse.draw2d.geometry.Rectangle in project cogtool by cogtool.
the class FrameUIModel method setGraphicalWidgetMove.
/**
* Set the origin of the graphical widget to be displaced by the differences.
* Generally this is a temporary move; since it does not affect the model
* it is here for performance reasons.
*/
public void setGraphicalWidgetMove(double diffX, double diffY, GraphicalWidget<?> gw) {
Rectangle r = gw.getBounds();
setGraphicalWidgetOrigin(r.x + diffX, r.y + diffY, gw);
}
use of org.eclipse.draw2d.geometry.Rectangle in project cogtool by cogtool.
the class FrameUIModel method drawWidgets.
// addFrameChangeListeners
/**
* Loop through each element in the widgets & figures list and then
* draw them.
*
* By default the contents Figure would already have these added...
* Check to see if they are already there.. or remove all and insert all.
*/
public void drawWidgets() {
// Sort the items to be drawn into an order based on the level.
// Highest numbers go first, i.e. render widgets from back to front.
Collection<GraphicalWidget<?>> figures = figureList.values();
GraphicalWidget<?>[] figureArray = new GraphicalWidget[figures.size()];
figureArray = figures.toArray(figureArray);
Arrays.sort(figureArray, GraphicalWidgetBase.GraphicalWidgetLevelComparator.ONLY);
// Add the background
if (backgroundImage != null) {
// Add the background to the lowest layer 0
contents.add(backgroundImage, new Rectangle(backgroundImage.getBounds()), 0);
}
// Add each graphical widget from the array to the scalable figure
for (GraphicalWidget<?> figureItem : figureArray) {
// Add the figure to the contents
// Specify the bounds of the figure in the XY layout of the content
// Theoretically this could be removed...
// but doing so causes lots of rendering bugs
DoubleRectangle shapeBounds = figureItem.getModel().getEltBounds();
contents.add(figureItem, PrecisionUtilities.getDraw2DRectangle(shapeBounds), -1);
}
}
use of org.eclipse.draw2d.geometry.Rectangle in project cogtool by cogtool.
the class FrameUIModel method setGraphicalWidgetBounds.
/**
* Set the bounds of the graphical widget to the new coordinates.
* Generally this is a temporary move; since it does not affect the model
* it is here for performance reasons.
*/
public void setGraphicalWidgetBounds(double tempOriginX, double tempOriginY, double tempWidth, double tempHeight, GraphicalWidget<?> gw) {
Rectangle newBds = PrecisionUtilities.getDraw2DRectangle(tempOriginX, tempOriginY, tempWidth, tempHeight);
gw.setBounds(newBds);
// For some idiot reason, the setBounds call doesn't refresh the size
// during dynamics, so do the setSize to force it (sigh)
gw.setSize((newBds.width > 0) ? newBds.width : 1, (newBds.height > 0) ? newBds.height : 1);
}
use of org.eclipse.draw2d.geometry.Rectangle in project cogtool by cogtool.
the class FrameEditorUI method confirmRenameFigure.
protected void confirmRenameFigure() {
if ((editor != null) && editor.inUse()) {
String newTitle = editor.getText();
editor.cleanup();
// figure whose title is currently being edited
IFigure figure = (IFigure) editor.getData();
if (figure instanceof PotentialFigure) {
if ("".equals(newTitle)) {
// nothing to do if empty string on potential item!
return;
}
GraphicalTraversableWidget<?> parent = potentialUIFig.getFigureOwner();
TraversableWidget parentModel = (TraversableWidget) parent.getModel();
boolean isRightPotentialFigure = (figure == potentialUIFig.getRightFigure());
WidgetType type = null;
AParentWidget header = null;
SimpleWidgetGroup group = null;
boolean isSeparator = false;
if (parentModel instanceof MenuItem) {
type = WidgetType.MenuItem;
MenuItem parentItem = (MenuItem) parentModel;
if (isRightPotentialFigure) {
// position of selected figure is on the right
// parent menuitem becomes a submenu; figure to be
// created becomes a child of the submenu
parentItem.setSubmenu(true);
header = parentItem;
} else {
// if position is on the bottom and the parent is not a
// header, put the new widget in the same menu as the
// parent item
header = parentItem.getParent();
// previous item should hide children if it's a submenu
((GraphicalParentWidget<?, ?>) parent).closeChildren();
}
if (parentModel.getWidgetType() != WidgetType.Submenu) {
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof ContextMenu) {
header = (ContextMenu) parentModel;
type = WidgetType.MenuItem;
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
} else if (parentModel instanceof MenuHeader) {
// and hide children of the previous header
if (isRightPotentialFigure) {
type = WidgetType.Menu;
((GraphicalParentWidget<?, ?>) parent).closeChildren();
group = parentModel.getParentGroup();
} else {
header = (MenuHeader) parentModel;
type = WidgetType.MenuItem;
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof PullDownItem) {
type = WidgetType.PullDownItem;
if (!isRightPotentialFigure) {
PullDownItem parentItem = (PullDownItem) parentModel;
header = parentItem.getParent();
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof PullDownHeader) {
type = WidgetType.PullDownItem;
if (!isRightPotentialFigure) {
header = (PullDownHeader) parentModel;
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof ListItem) {
type = WidgetType.ListBoxItem;
group = parentModel.getParentGroup();
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
} else if (parentModel instanceof GridButton) {
type = parentModel.getWidgetType();
group = parentModel.getParentGroup();
}
Rectangle r = ((PotentialFigure) figure).getUnscaledBounds();
DoubleRectangle bounds = new DoubleRectangle(r.x, r.y, r.width, r.height);
performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(bounds, header, type, view.isAutomaticCreation(), newTitle, group, isSeparator));
} else {
boolean isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
performAction(FrameEditorLID.ChangeTitleProperty, new FrameEditorUI.ActionStringParameters(newTitle, selection, isSeparator), true);
}
}
}
Aggregations