use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method createDuplicateFrameAction.
protected IListenerAction createDuplicateFrameAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignEditorUI.DuplicateParameters.class;
}
public boolean performAction(Object prms) {
// From DesignEditorUI
DesignEditorUI.DuplicateParameters parameters = (DesignEditorUI.DuplicateParameters) prms;
Frame[] framesToDuplicate = parameters.selection.getSelectedFrames();
if ((framesToDuplicate != null) && (framesToDuplicate.length > 0)) {
FrameSubsetDuplicator duplicator = new FrameSubsetDuplicator(framesToDuplicate);
Frame[] duplicatedFrames = new Frame[framesToDuplicate.length];
for (int i = 0; i < framesToDuplicate.length; i++) {
Frame duplicatedFrame = duplicator.getOrDuplicate(framesToDuplicate[i]);
duplicatedFrames[i] = duplicatedFrame;
duplicatedFrame.moveFrameOrigin(parameters.dx, parameters.dy);
}
design.addFrames(duplicatedFrames);
undoMgr.addEdit(createDuplicateFramesEdit(duplicatedFrames));
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method createFrame.
// addFrame
protected Frame createFrame(String frameName, double x, double y) {
Frame frame = new Frame(frameName, design.getDeviceTypes());
frame.setFrameOrigin(x, y);
return frame;
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method createEditFrameAction.
protected IListenerAction createEditFrameAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameSelectionState.class;
}
public boolean performAction(Object prms) {
FrameSelectionState selection = (FrameSelectionState) prms;
Frame[] frames = selection.getSelectedFrames();
if ((frames == null) || (frames.length == 0)) {
interaction.protestNoSelection();
return false;
}
for (Frame frame : frames) {
try {
FrameEditorController.openController(frame, design, project);
} catch (GraphicsUtil.ImageException ex) {
interaction.protestInvalidImageFile();
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Frame 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.Frame in project cogtool by cogtool.
the class DesignEditorController method getBackgroundImageData.
/**
* Returns a Map mapping IFrames to their current background image
* and bounds in an ImageData object
*
* @param frames an array of IFrames
* @return a Hashtable mapping IFrames to their current background images
*/
protected Map<Frame, ImageData> getBackgroundImageData(Frame[] frames) {
Map<Frame, ImageData> previousImagesData = new HashMap<Frame, ImageData>();
for (Frame f : frames) {
String imgPath = (String) f.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
// Save previous data for undo operation
previousImagesData.put(f, new ImageData(f.getBackgroundBounds(), f.getBackgroundImage(), imgPath));
}
return previousImagesData;
}
Aggregations