use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.
the class ScalableGraphicalFigure method getChildrenUtilizedAreaUnscaled.
/**
* Returns the area occupied by the children in UNSCALED coordinates
*/
public Rectangle getChildrenUtilizedAreaUnscaled() {
Rectangle r = null;
Iterator<?> iter = getChildren().iterator();
while (iter.hasNext()) {
IFigure fi = (IFigure) iter.next();
if (r == null) {
r = new Rectangle(fi.getBounds());
} else {
r.union(fi.getBounds());
}
}
return (r == null) ? new Rectangle(0, 0, 0, 0) : r;
}
use of org.eclipse.draw2d.IFigure 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);
}
}
}
use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.
the class DesignEditorMouseState method dealWithMouseDragged.
@Override
protected boolean dealWithMouseDragged(IFigure figure, int button, int eventX, int eventY, int state) {
boolean goForward = super.dealWithMouseDragged(figure, button, eventX, eventY, state);
if (goForward && mouseDown) {
StandardDrawingEditor editor = ui.getViewEditor();
// Update VIEW to ensure ME point is visible.
// If outside of the visible canvas, up-click should cancel!
stopMouseDragTimer = true;
stopDynamic = editor.movePointNearEdge(eventX, eventY, updateDelta);
switch(getMouseState()) {
case PotentialMovingFrame:
case PotentialMovingSelection:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(MovingFrames);
// fall through!
}
case MovingFrames:
{
updateDynamicMove(eventX, eventY, false);
break;
}
case PotentialTogglingSelection:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(TogglingSelection);
// fall through!
}
case TogglingSelection:
{
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialSelectingFrames:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(SelectingFrames);
// fall through!
}
case SelectingFrames:
{
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialCreatingTransition:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
// Do not allow transitions from menu headers or submenus
IFigure target = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, StructureViewUIModel.SOURCE_ONLY);
if ((target instanceof GraphicalParentWidget<?, ?>) && (((GraphicalParentWidget<?, ?>) target).canHaveChildren())) {
break;
}
setMouseState(CreatingTransition);
// Ensures proper default action
selection.deselectAll();
// fall through!
}
case CreatingTransition:
{
dynamicTransition(eventX, eventY);
DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
if (targetFigure != potentialTarget) {
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
}
potentialTarget = targetFigure;
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(true);
}
}
break;
}
case PotentialSelectTransition:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
handleMousePressed(StructureViewUIModel.NO_TRANSITION);
switch(getMouseState()) {
case PotentialMovingFrame:
{
setMouseState(MovingFrames);
updateDynamicMove(eventX, eventY, false);
break;
}
case PotentialSelectingFrames:
{
setMouseState(SelectingFrames);
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialCreatingTransition:
{
setMouseState(CreatingTransition);
dynamicTransition(eventX, eventY);
break;
}
}
break;
}
case PotentialToggleTransition:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
handleMousePressed(StructureViewUIModel.NO_TRANSITION);
setMouseState(TogglingSelection);
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialChangeTarget:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(ChangingTarget);
Point start = hitTransition.getStart();
hitTransition.setVisible(false);
double zoom = ui.getZoom();
double startX = start.x * zoom;
double startY = start.y * zoom;
ensureDynamicTransition(PrecisionUtilities.round(startX), PrecisionUtilities.round(startY));
// fall through!
}
case ChangingTarget:
{
dynamicTransitionTarget(eventX, eventY);
DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
if (targetFigure != potentialTarget) {
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
}
potentialTarget = targetFigure;
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(true);
}
}
break;
}
case PotentialChangeSource:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(ChangingSource);
hitTransition.setVisible(false);
ensureDynamicTransition(mouseDownX, mouseDownY);
Point endPt = hitTransition.getEnd();
double zoom = ui.getZoom();
double endX = endPt.x * zoom;
double endY = endPt.y * zoom;
dynamicTransitionTarget(PrecisionUtilities.round(endX), PrecisionUtilities.round(endY));
break;
}
case ChangingSource:
{
dynamicTransitionSource(eventX, eventY);
GraphicalSource<?> sourceFigure = ui.structureView.getSourceAtXY(eventX, eventY);
InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
if (sourceFigure != null) {
drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.DRAW_CURSOR));
} else {
drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.SELECT_CURSOR));
}
break;
}
case PotentialDuplicatingFrame:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
duplicatingDynamic = new ArrayList<RectangleFigure>();
//populate this from selection state
double zoom = ui.getZoom();
Iterator<DesignEditorFrame> selectedFrames = selection.getSelectedFrameFigures();
while (selectedFrames.hasNext()) {
RectangleFigure rect = new RectangleFigure();
DesignEditorFrame currFrame = selectedFrames.next();
//set size of new rectangle object
Rectangle frameSize = currFrame.getBounds();
frameSize.height = PrecisionUtilities.round(frameSize.height / zoom);
frameSize.width = PrecisionUtilities.round(frameSize.width / zoom);
frameSize.x = PrecisionUtilities.round(frameSize.x * zoom);
frameSize.y = PrecisionUtilities.round(frameSize.y * zoom);
rect.setBounds(frameSize);
//add new rectangle object to the array list
duplicatingDynamic.add(rect);
//display the new rectangle object
showSelectionArea(rect);
}
setMouseState(DuplicatingFrames);
// fall through!
}
case DuplicatingFrames:
{
updateDynamicDuplicate(eventX, eventY);
break;
}
}
// Repeating timer for causing events to repeat.
if ((updateDelta.x != 0) || (updateDelta.y != 0)) {
if (rootFigure == null) {
rootFigure = ui.getViewEditor().getInteractionFigure();
}
stopMouseDragTimer = false;
// Determine the new point the mouse "moved" too.
mouseDragTask.setNextMousePosition(eventX + updateDelta.x, eventY + updateDelta.y, button, state);
// Queue the event for 0.1 sec.
WindowUtil.GLOBAL_DISPLAY.timerExec(100, mouseDragTask);
}
}
lastX = eventX;
lastY = eventY;
cleanup();
return goForward;
}
use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.
the class DesignEditorMouseState method dealWithMouseDoubleClicked.
@Override
protected boolean dealWithMouseDoubleClicked(IFigure figure, int button, int x, int y, int state) {
boolean goForward = super.dealWithMouseDoubleClicked(figure, button, x, y, state);
ui.confirmRenameFrame();
if (goForward) {
IFigure target = ui.structureView.getFigureAtXY(x, y, StructureViewUIModel.FRAME_LABEL);
if (target instanceof DesignEditorFrame.FrameLabel) {
DesignEditorFrame.FrameLabel frameLabel = (DesignEditorFrame.FrameLabel) target;
ui.initiateFrameRename(frameLabel.getFrameFigure());
} else if (target instanceof DesignEditorFrame) {
Frame frame = ((DesignEditorFrame) target).getFrame();
ui.performAction(DesignEditorLID.EditFrame, new SingleFrameSelection(frame));
}
}
setMouseState(MouseUp);
cleanup();
return goForward;
}
use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.
the class DesignEditorUI method showContextMenu.
// Context menu stuff
@Override
public void showContextMenu(int x, int y) {
// Check which region was hit
IFigure fig = structureView.getFigureAtXY(x, y, StructureViewUIModel.NO_SOURCE);
// Invocation in empty space
if (fig == null) {
contextSelection.deselectAll();
showContextMenu(contextSelection, View.CONTEXT);
} else // Invocation on a Transition
if (fig instanceof DesignEditorTransition) {
DesignEditorTransition transitionFig = (DesignEditorTransition) fig;
//fig.setToolTip(null);
if (transitionFig.isSelected()) {
showContextMenu();
} else {
// Populate the context selection
contextSelection.setSelectedTransition(transitionFig);
showContextMenu(contextSelection, View.CONTEXT);
}
} else // Invocation on a Frame
{
// fig instanceof DesignEditorFrame
DesignEditorFrame frameFig = (DesignEditorFrame) fig;
if (frameFig.isSelected()) {
// Indicate the selection to be used visually
Iterator<DesignEditorFrame> figs = selection.getSelectedFrameFigures();
while (figs.hasNext()) {
frameFig = figs.next();
frameFig.dynamicHighlight(true);
}
showContextMenu();
} else {
// Indicate the context selection visually
frameFig.dynamicHighlight(true);
// Populate the context selection
contextSelection.setSelectedFrame(frameFig);
showContextMenu(contextSelection, View.CONTEXT);
}
view.getEditor().getLWS().getUpdateManager().performUpdate();
}
}
Aggregations