use of edu.cmu.cs.hcii.cogtool.model.DoubleRectangle in project cogtool by cogtool.
the class FrameUIModel method getBottomGridFigure.
@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getBottomGridFigure(GraphicalGridButton gridFig) {
GridButton gb = gridFig.getModel();
GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
Iterator<IWidget> gbs = group.iterator();
DoubleRectangle bds = gb.getEltBounds();
double startX = bds.x;
double startY = bds.y;
IWidget result = null;
double resultY = 0.0;
while (gbs.hasNext()) {
IWidget cur = gbs.next();
if (cur == gb) {
continue;
}
bds = cur.getEltBounds();
double curX = bds.x;
double curY = bds.y;
if (PrecisionUtilities.withinEpsilon(startX, curX, GridButtonGroup.PIXEL_EPSILON) && (curY > startY)) {
if ((result == null) || (curY < resultY)) {
result = cur;
resultY = curY;
}
}
}
return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleRectangle 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 edu.cmu.cs.hcii.cogtool.model.DoubleRectangle in project cogtool by cogtool.
the class ProjectController method populateProject.
/**
* On the assumption that the project is brand new, populate it
* with a new design and a new task, allowing the user to specify
* their names.
*
* @author mlh
*/
public void populateProject() {
// indicating an empty selection.
if (performAction(ProjectLID.NewProjectNewDesign, emptyDesignSelectionState, false)) {
// NewTask requires a task selection state; create one
// indicating an empty selection.
performAction(ProjectLID.NewTask, emptyTaskSelectionState, false);
}
// Open up the one design
List<Design> projectDesigns = project.getDesigns();
if (projectDesigns.size() > 0) {
Design design = projectDesigns.get(0);
Controller c = DesignEditorController.openController(design, project);
DoubleRectangle projectWinExtent = getExtent();
c.setLocation(projectWinExtent.x + 0.5 * projectWinExtent.width, projectWinExtent.y + 0.5 * projectWinExtent.height);
}
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleRectangle 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 edu.cmu.cs.hcii.cogtool.model.DoubleRectangle in project cogtool by cogtool.
the class FrameEditorMouseState method dealWithMouseReleased.
/**
* A mouse up event was called.
* Checks for context selection, then performs actions as dictated
* by the FSM.
*/
@Override
protected boolean dealWithMouseReleased(IFigure figure, int button, int x, int y, int state) {
boolean goForward = super.dealWithMouseReleased(figure, button, x, y, state);
// Clear any mouse drag timer, that may be running
stopMouseDragTimer = true;
if (goForward && isMouseDownValid) {
// Record the mouse down position
double zoom = ui.getZoom();
// The current mouse down position (scaled)
double currentScaledX = x / zoom;
double currentScaledY = y / zoom;
switch(getMouseState()) {
case PotentialCreatingWidget:
case PotentialMovingWidget:
case PotentialResizingWidget:
{
// Nothing to do; any action necessary was taken on "down".
break;
}
case PotentialReorderWidget:
case PotentialMovingSelection:
{
// Get whatever graphical widget under original down x,y
GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
MoveHalo halo = null;
FrameElement data = null;
if (wf == null) {
halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
if (halo != null) {
data = halo.getData();
if (data instanceof SimpleWidgetGroup) {
IWidget[] widgets = selection.getSelectedIWidgets();
SimpleWidgetGroup group = (SimpleWidgetGroup) data;
for (IWidget widget : widgets) {
if (widget.getParentGroup() != group) {
selection.deselectElement(widget);
}
}
break;
}
if (data instanceof IWidget) {
wf = ui.frameUI.getWidgetFigure((IWidget) data);
}
}
}
if (wf != null) {
selection.setSelectedSelnFig(wf);
} else {
if (halo == null) {
halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
if (halo != null) {
data = halo.getData();
}
}
if ((data != null) && (data instanceof FrameElementGroup)) {
selection.setSelectedSelnFig((FrameEltGroupHalo) halo);
}
}
break;
}
case PotentialTogglingSelection:
{
// If mouse down on a widget, toggle selection.
GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
MoveHalo halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
FrameElement data = null;
if (halo != null) {
data = halo.getData();
}
if (wf == null) {
if (data instanceof IWidget) {
wf = ui.frameUI.getWidgetFigure((IWidget) data);
}
}
if (wf != null) {
// If the widget is already selected, unselect it.
if (selection.isSelectionFigureSelected(wf)) {
selection.deselectSelnFig(wf);
} else {
selection.selectSelnFig(wf);
}
} else if (data instanceof SimpleWidgetGroup) {
Iterator<IWidget> widgets = ((SimpleWidgetGroup) data).iterator();
while (widgets.hasNext()) {
IWidget w = widgets.next();
selection.deselectElement(w);
}
} else if ((halo instanceof FrameEltGroupHalo) && (data instanceof FrameElementGroup)) {
FrameEltGroupHalo groupHalo = (FrameEltGroupHalo) halo;
if (selection.isElementSelected(data)) {
selection.deselectSelnFig(groupHalo);
} else {
selection.selectSelnFig(groupHalo);
}
} else {
selection.deselectAll();
}
break;
}
// Move is complete, so apply changes to the model.
case MovingWidgets:
{
// Get selection, and use the difference between current
// and start location.
double moveByX = currentScaledX - scaledMouseDownX;
double moveByY = currentScaledY - scaledMouseDownY;
FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection);
ui.performAction(CogToolLID.MoveWidgets, prms);
break;
}
case ReorderWidget:
{
boolean reorder = reorderWidget(x, y, reorderParms);
ui.clearUISupport(true);
isReordering = false;
if (reorder) {
ui.performAction(FrameEditorLID.Reorder, reorderParms);
} else {
selection.deselectElement(lastClickedWidget);
}
InteractionDrawingEditor editor = ui.getViewEditor();
editor.removeInteractionFigure(reorderFigure);
editor.removeInteractionFigure(dividerLine);
break;
}
// since the user may have flipped the orientation.
case ResizingWidget:
{
// Switch to quality mode rendering for graphical widgets
setWidgetFastRenderMode(false);
if (currentScaledX < 0.0) {
currentScaledX = 0.0;
}
if (currentScaledY < 0.0) {
currentScaledY = 0.0;
}
// Deal with any anchoring issues
if (ui.resizeHandlesUIFig.isTopLeftAnchored()) {
switch(currentResizeHandleType) {
case FrameEditorUI.TOP_RIGHT:
{
// Cannot change Y position
currentScaledY = initialResizeArea.y;
break;
}
case FrameEditorUI.BOTTOM_LEFT:
{
// Cannot change X position
currentScaledX = initialResizeArea.x;
break;
}
default:
{
break;
}
}
// Cannot move left of top-left
if (currentScaledX < initialResizeArea.x) {
currentScaledX = initialResizeArea.x;
}
// Cannot move above of top-left
if (currentScaledY < initialResizeArea.y) {
currentScaledY = initialResizeArea.y;
}
}
double width = Math.abs(currentScaledX - mouseFixedResizeX);
double height = Math.abs(currentScaledY - mouseFixedResizeY);
FrameEditorUI.ResizeParameters prms = new FrameEditorUI.ResizeParameters(initialResizeArea.x, initialResizeArea.y, Math.min(currentScaledX, mouseFixedResizeX), Math.min(currentScaledY, mouseFixedResizeY), width / initialResizeArea.width, height / initialResizeArea.height, selection);
ui.performAction(CogToolLID.ResizeWidgets, prms);
break;
}
// Finished a mouse drag operation to create a new widget
case CreatingWidget:
{
if (currentScaledX < 0.0) {
currentScaledX = 0.0;
}
if (currentScaledY < 0.0) {
currentScaledY = 0.0;
}
double width = Math.abs(scaledMouseDownX - currentScaledX);
double height = Math.abs(scaledMouseDownY - currentScaledY);
double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
// Turn off the bounding box drawn.
ui.stopDrawingTemporaryFigure();
// Create a rectangle for the new region.
DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
// width of 0. Probably this should be less then 2.
if ((region.width != 0.0) && (region.height != 0.0)) {
ui.performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(region, ui.getCurrentWidgetType(), ui.view.isAutomaticCreation()));
}
break;
}
// Finished a mouse drag operation to select a set of widgets
case TogglingSelection:
{
// Get the total area selected
double width = Math.abs(scaledMouseDownX - currentScaledX);
double height = Math.abs(scaledMouseDownY - currentScaledY);
// Get top left point.
double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
// Turn off the bounding box drawn.
ui.stopDrawingTemporaryFigure();
// Create the final region's area
DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
// Loop through all figures and check for intersections
Iterator<GraphicalWidget<?>> gwFigures = ui.getFrameUI().getFigureListIterator();
while (gwFigures.hasNext()) {
GraphicalWidget<?> gw = gwFigures.next();
if (!(gw instanceof GraphicalChildWidget<?, ?>)) {
Rectangle bounds = gw.getBounds();
if (region.intersects(bounds.x, bounds.y, bounds.width, bounds.height)) {
// If the widget is already selected, deselect it.
if (selection.isSelectionFigureSelected(gw)) {
selection.deselectSelnFig(gw);
} else {
selection.selectSelnFig(gw);
}
}
}
}
break;
}
case PotentialInsertDuplicateWidget:
case PotentialDuplicatingWidget:
{
GraphicalWidget<?> widgetFig = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
selection.setSelectedSelnFig(widgetFig);
break;
}
case DuplicatingWidgets:
{
double dx = currentScaledX - scaledMouseDownX;
double dy = currentScaledY - scaledMouseDownY;
// Remove all the rectangle figures from the display, clear the list
clearRectFigures();
ui.performAction(FrameEditorLID.Duplicate, new FrameEditorUI.DuplicateParameters(dx, dy, selection));
break;
}
case InsertDuplicateWidget:
{
double dx = currentScaledX - scaledMouseDownX;
double dy = currentScaledY - scaledMouseDownY;
isReordering = false;
if (reorderWidget(x, y, insertDuplicateParms)) {
insertDuplicateParms.moveByX = dx;
insertDuplicateParms.moveByY = dy;
ui.performAction(FrameEditorLID.InsertDuplicate, insertDuplicateParms);
} else {
selection.deselectElement(lastClickedWidget);
}
InteractionDrawingEditor editor = ui.getViewEditor();
editor.removeInteractionFigure(reorderFigure);
editor.removeInteractionFigure(dividerLine);
break;
}
case PotentialMovingGridButtons:
{
if (movedGridButtons != null) {
movedGridButtons = NO_GRID_BUTTONS;
}
break;
}
case MovingGridButtons:
{
// Get selection, and use the difference between current
// and start location.
double moveByX;
double moveByY;
GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
GridButton gb = (GridButton) gw.getModel();
DoublePoint start = gb.getShape().getOrigin();
if (moveIsVertical) {
moveByX = 0.0;
if (currentScaledY < minY) {
moveByY = (minY - start.y);
} else {
moveByY = currentScaledY - scaledMouseDownY;
}
} else {
moveByY = 0.0;
if (currentScaledX < minX) {
moveByX = (minX - start.x);
} else {
moveByX = currentScaledX - scaledMouseDownX;
}
}
if ((moveByX != 0.0) || (moveByY != 0.0)) {
FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection, false);
ui.performAction(CogToolLID.MoveWidgets, prms);
}
break;
}
}
// Clear the values used.
lastClickedWidget = null;
isMouseDownValid = false;
setMouseState(MouseUp);
}
cleanup();
return goForward;
}
Aggregations