use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorController method moveGridButton.
/**
* Special case of moveWidget; moves all buttons below or to the right of
* gb in its group and updates the horizontal and vertical offsets as
* necessary.
*/
private void moveGridButton(ListenerIdentifier lid, String presentationLabel, GridButton gb, double widgetMoveByX, double widgetMoveByY, double newHoriz, double newVert, IUndoableEditSequence editSequence) {
// move the list of buttons affected
DoublePoint oldLocation = gb.getShape().getOrigin();
double oldX = oldLocation.x;
double oldY = oldLocation.y;
GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
boolean vertical = (widgetMoveByX == 0);
double oldHoriz = gb.getHorizSpace();
double oldVert = gb.getVertSpace();
ReadOnlyList<? extends GridButton> movedButtons = gbg.getMovedButtons(vertical, oldX, oldY);
for (int i = 0; i < movedButtons.size(); i++) {
GridButton g = movedButtons.get(i);
DoublePoint p = g.getShape().getOrigin();
double tempX = Math.max(p.x + widgetMoveByX, 0.0);
double tempY = Math.max(p.y + widgetMoveByY, 0.0);
g.setWidgetOrigin(tempX, tempY);
}
if (vertical) {
gb.setVertSpace(newVert);
} else {
List<GridButton> column = gbg.getColumn(gb);
for (int i = 0; i < column.size(); i++) {
GridButton g = column.get(i);
g.setHorizSpace(newHoriz);
}
}
DemoStateManager.IDesignUndoableEdit edit = moveGridButtonsEdit(lid, presentationLabel, movedButtons, widgetMoveByX, widgetMoveByY, oldHoriz, oldVert, newHoriz, newVert, gb);
editSequence.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class DesignEditorCmd method getFirstChildPosition.
private static DoublePoint getFirstChildPosition(AParentWidget parent) {
AShape parentShape = parent.getShape();
DoublePoint pos = parentShape.getOrigin();
DoubleSize extent = parentShape.getSize();
switch(parent.getChildrenLocation()) {
case AParentWidget.CHILDREN_BELOW:
{
pos.y += extent.height;
break;
}
case AParentWidget.CHILDREN_RIGHT:
{
pos.x += extent.width;
break;
}
case AParentWidget.CHILDREN_CENTER:
{
pos.x += extent.width / 2.0;
pos.y += extent.height / 2.0;
break;
}
}
return pos;
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class DesignEditorController method createImportImageDirectory.
protected IListenerAction createImportImageDirectory() {
return new AListenerAction() {
public boolean performAction(Object actionParms) {
// Ask for a directory of images
String filePath = interaction.askForImageDir();
if (filePath != null) {
File dir = new File(filePath);
if (dir.isDirectory()) {
final File[] files = dir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
String name = pathname.getName();
Matcher imageFileNameMatcher = IMAGE_FILE_NAME.matcher(name);
if (imageFileNameMatcher.matches()) {
// Test for Mac resource forks
if (name.startsWith("._")) {
String realName = name.substring(2);
String fullPath = pathname.getParent() + FileUtil.FILE_SEP + realName;
return !new File(fullPath).exists();
}
return true;
}
return false;
}
});
// Find an unoccupied starting position by cascading.
DoublePoint origin = new DoublePoint(10.0, 10.0);
// Check if only the default frame is present;
// if so, and it hasn't been significantly modified or
// used, indicate that it should be deleted when
// the images are imported.
Frame frameToDelete = design.getFrame(DesignEditorController.INITIAL_FRAME_NAME);
if ((frameToDelete == null) || (design.getFrames().size() > 1) || (frameToDelete.getWidgets().size() > 0) || (frameToDelete.getBackgroundImage() != null)) {
frameToDelete = null;
}
ImportImageDirThread workThread = new ImportImageDirThread(files, origin.x, origin.y, frameToDelete);
ThreadManager.startNewThread(workThread);
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class Controller method assignActions.
/**
* Registers the set of <code>IListenerAction</code> instances
* that implement the semantic actions that are possible.
* <p>
* For this class, this consists of the actions that all windows support.
*
* @author mlh
*/
protected void assignActions() {
UI ui = getUI();
if (ui != null) {
ui.setAction(CogToolLID.About, ui.popAboutBox());
// Set "open" action
ui.setAction(CogToolLID.OpenProject, new AListenerAction() {
public boolean performAction(Object prms) {
// open expects null in that case.
if (!(prms instanceof DoublePoint)) {
prms = null;
}
// Ask the user to select a CogTool project to open
File[] openLocs = getUI().getStandardInteraction().selectFileSources();
return open((DoublePoint) prms, openLocs);
}
});
ui.setAction(CogToolLID.OpenProjectFile, new IListenerAction() {
public Class<?> getParameterClass() {
return String.class;
}
public boolean performAction(Object actionParms) {
File[] openLoc = { new File((String) actionParms) };
return open(null, openLoc);
}
});
// Set "new project" action
ui.setAction(CogToolLID.NewProject, createNewProjectAction());
// Set "quit/exit" action
ui.setAction(CogToolLID.ExitApplication, createExitAction());
ui.setAction(CogToolLID.ClearRecent, new AListenerAction() {
public boolean performAction(Object actionParms) {
CogToolPref.clearRecent();
Interaction interaction = getUI().getStandardInteraction();
interaction.setStatusMessage(L10N.get("AC.RecentClear", "Recent file data cleared."));
return true;
}
});
}
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class DesignEditorController method createNewFrameAction.
protected IListenerAction createNewFrameAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
// Find an unoccupied starting position by cascading.
DoublePoint origin = new DoublePoint(10.0, 10.0);
DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
Frame frame = createNewFrame(origin.x, origin.y);
ui.initiateFrameRename(frame);
return true;
}
};
}
Aggregations