use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method createSetBackgroundImageAction.
/**
* Create a ListenerAction to handle setting frame background image on
* multiple frames
*/
protected IListenerAction createSetBackgroundImageAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameSelectionState.class;
}
public boolean performAction(Object prms) {
// Get selected frames from parameters
FrameSelectionState seln = (FrameSelectionState) prms;
Frame[] frames = seln.getSelectedFrames();
// this code is from FrameEditorController
// load image
// Pull up interaction to select a file
String imageURL = interaction.selectImageFile();
// Check if the dialog was cancelled
if (imageURL != null) {
byte[] imageData;
try {
// Set the background to new image
imageData = GraphicsUtil.loadImageFromFile(imageURL);
setBackgroundImageOnFrames(frames, imageData, imageURL, DesignEditorLID.SetBackgroundImage);
return true;
} catch (IOException e) {
interaction.protestUnreadableFile();
imageData = null;
}
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Frame 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;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method createDeleteFrameAction.
// createNewTransition
protected IListenerAction createDeleteFrameAction() {
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)) {
if (interaction.confirmDeleteFrames(frames)) {
deleteFrames(frames);
return true;
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method renameFrame.
protected boolean renameFrame(final Frame renamedFrame, String tryName) {
final String oldName = renamedFrame.getName();
boolean notDone = true;
do {
if (tryName.length() == 0) {
tryName = interaction.protestNameCannotBeEmpty(DEFAULT_FRAME_PREFIX);
// If canceled, indicate so; otherwise, test again
if (tryName == null) {
return false;
}
} else {
Frame frameForName = design.getFrame(tryName);
// then no change is necessary!
if (frameForName == renamedFrame) {
notDone = false;
} else if (frameForName != null) {
// A non-null frame for the tryName indicates a collision
tryName = interaction.protestNameCollision(DEFAULT_FRAME_PREFIX);
// If canceled, indicate so; otherwise, test again
if (tryName == null) {
return false;
}
} else {
// Not canceled, not empty, and not a collision
notDone = false;
final String newName = tryName;
renamedFrame.setName(newName);
IUndoableEdit edit = new AUndoableEdit(DesignEditorLID.RenameFrame) {
@Override
public String getPresentationName() {
return renameFrame;
}
@Override
public void redo() {
super.redo();
Frame testFrame = design.getFrame(newName);
renamedFrame.setName(newName);
if (testFrame != null) {
makeFrameNameUnique(renamedFrame);
}
}
@Override
public void undo() {
super.undo();
Frame testFrame = design.getFrame(oldName);
renamedFrame.setName(oldName);
if (testFrame != null) {
makeFrameNameUnique(renamedFrame);
}
}
};
undoMgr.addEdit(edit);
}
}
} while (notDone);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignExportToHTML method buildFrameList.
/**
* Build the map which holds the frame names for a design.
* Changes which design will be used for building HTML pages
*/
protected void buildFrameList() {
frameLookUp.clear();
Set<String> usedNames = new HashSet<String>();
Iterator<Frame> iter = design.getFrames().iterator();
// Use a random generator if needed
Random rand = new Random();
while (iter.hasNext()) {
Frame frame = iter.next();
String name = cleanStringForFS(frame.getName());
while (usedNames.contains(name)) {
// Name is in use.
// Append a random number.
name = name.concat("+" + rand.nextInt(50));
}
// Now that the name is clean, use it.
frameLookUp.put(frame, name);
usedNames.add(name);
}
}
Aggregations