use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class FrameEditorController method renderUnRenderAll.
public static void renderUnRenderAll(Design d, boolean render, CogToolLID lid, UndoManager mgr) {
CompoundUndoableEdit edits = new CompoundUndoableEdit((render ? RENDER_ALL : UN_RENDER), lid);
for (Frame f : d.getFrames()) {
for (IWidget w : f.getWidgets()) {
renderWidget(w, render, w.isRendered(), edits);
}
}
edits.end();
if (edits.isSignificant()) {
mgr.addEdit(edits);
}
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DictEntryGenerator method generateEntries.
// TODO This whole mishmash of different flavors of progress bars, and
// Cancelables/Stoppables/Pausables is a mess. We shouldn't be using
// the type hierarchy to fiddle this stuff. Instead we should have a
// single interface for control of a background operation, subsuming
// all of Cancelable, Stoppable and Pausable, and a single ProgressBar
// type that takes a bunch of flags indicating what buttons it should
// display.
public void generateEntries(String goal, ITermSimilarity alg, Cancelable cancelable, Stoppable stoppable, boolean computeAll, List<String> computeErrors, ProgressCallback progressCallback) {
// TODO figure out how to deal with this for real, long term
// goal = clean(goal);
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
dict = new SimilarityDictionary();
design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
}
int initialSize = dict.size();
ITermSimilarity.Continuable cont = new ITermSimilarity.Continuable(cancelable, stoppable);
Iterator<Frame> frames = design.getFrames().iterator();
while (frames.hasNext() && cont.isContinuing()) {
Frame f = frames.next();
generateOneEntry(f.getSpeakerText(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
Set<SimpleWidgetGroup> swGrps = new HashSet<SimpleWidgetGroup>();
Iterator<IWidget> widgets = f.getWidgets().iterator();
while (widgets.hasNext() && cont.isContinuing()) {
IWidget w = widgets.next();
generateOneEntry(w.getTitle(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
if (!cont.isContinuing()) {
break;
}
generateOneEntry(w.getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
SimpleWidgetGroup swg = w.getParentGroup();
if (swg != null) {
swGrps.add(swg);
}
}
Iterator<FrameElementGroup> groups = f.getEltGroups().iterator();
while (groups.hasNext() && cont.isContinuing()) {
generateOneEntry(groups.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
Iterator<SimpleWidgetGroup> swgIter = swGrps.iterator();
while (swgIter.hasNext() && cont.isContinuing()) {
generateOneEntry(swgIter.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
}
if (stoppable.isStopped()) {
// Clean out the last entry if we were stopped, as it may not be
// correct. But only if we've added something.
int n = dict.size();
if (n > initialSize) {
dict.removeEntry(n - 1);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class FrameEditorController method updateFrameName.
// renameEltGroup
/**
* Update the frame's name.
* The name must be unique.
*
* @param frame
* @param newName
* @return
*/
private boolean updateFrameName(final Frame frame, String tryName) {
final String oldName = frame.getName();
boolean notDone = true;
do {
if (tryName.length() == 0) {
tryName = interaction.protestNameCannotBeEmpty("Frame");
// If canceled, indicate so; otherwise, test again
if (tryName == null) {
return false;
}
} else {
Frame frameForName = model.getDesign().getFrame(tryName);
// then no change is necessary!
if (frameForName == frame) {
notDone = false;
} else if (frameForName != null) {
// A non-null widget for the tryName indicates a collision
tryName = interaction.protestNameCollision("Frame");
// 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;
frame.setName(newName);
IUndoableEdit edit = new AUndoableEdit(DesignEditorLID.RenameFrame) {
@Override
public String getPresentationName() {
return CHG_FRAME_NAME;
}
@Override
public void redo() {
super.redo();
Frame testFrame = design.getFrame(newName);
frame.setName(newName);
if (testFrame != null) {
makeFrameNameUnique(frame);
}
}
@Override
public void undo() {
super.undo();
Frame testFrame = design.getFrame(oldName);
frame.setName(oldName);
if (testFrame != null) {
makeFrameNameUnique(frame);
}
}
};
undoMgr.addEdit(edit);
}
}
} while (notDone);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method moveFrames.
protected boolean moveFrames(double dx, double dy, FrameSelectionState selection) {
Frame[] frames = selection.getSelectedFrames();
if ((frames != null) && (frames.length > 0)) {
String editLabel;
if (frames.length > 1) {
editLabel = moveFrames;
} else {
editLabel = moveFrame;
}
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, DesignEditorLID.MoveFrames);
for (Frame frame : frames) {
moveFrame(frame, dx, dy, editSequence);
}
editSequence.end();
undoMgr.addEdit(editSequence);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method spaceFramesEqually.
/**
* Spaces the selected frames equally along a certain axis
* @param vertical true for vertical axis; false for horizontal
*/
protected boolean spaceFramesEqually(Map<Frame, DoubleRectangle> frameMap, final boolean vertical) {
final String undoRedoLabel = vertical ? SPACE_VERTICALLY : SPACE_HORIZONTALLY;
CogToolLID lid = vertical ? DesignEditorLID.SpaceVertically : DesignEditorLID.SpaceHorizontally;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(undoRedoLabel, lid);
// Order the widgets according to location
// (either from the left or from the top)
Comparator<Map.Entry<Frame, DoubleRectangle>> c = vertical ? frameVerticalComparator : frameHorizontalComparator;
@SuppressWarnings("unchecked") Map.Entry<Frame, DoubleRectangle>[] entries = new Map.Entry[frameMap.size()];
frameMap.entrySet().toArray(entries);
Arrays.sort(entries, c);
// Calculate the spacing between widgets
double sum = 0;
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
// this can then be used to do spacing.
for (Entry<Frame, DoubleRectangle> entrie : entries) {
DoubleRectangle bounds = entrie.getValue();
double size = vertical ? bounds.height : bounds.width;
double position = vertical ? bounds.y : bounds.x;
sum += size;
min = Math.min(min, position);
max = Math.max(max, size + position);
}
// Get the spacing to use between each item.
double spacing = ((max - min) - sum) / (entries.length - 1);
// Adjust the spacings to the correct values
for (Entry<Frame, DoubleRectangle> entrie : entries) {
// go through each frame and set the frame's origin
final Frame f = entrie.getKey();
final DoubleRectangle bounds = entrie.getValue();
// TODO (dfm) this is probably the place to walk over the design pre-flighting
// problems we want to warn the user about, and give the opportunity
// to skip the export if desired
// Determine the old point...
final double p_old = vertical ? bounds.y : bounds.x;
final double p_new = min;
// Set the new location
f.setFrameOrigin(vertical ? bounds.x : p_new, vertical ? p_new : bounds.y);
// Advance the pointer to the next location
min += spacing + (vertical ? bounds.height : bounds.width);
IUndoableEdit edit = new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return undoRedoLabel;
}
@Override
public void redo() {
super.redo();
f.setFrameOrigin(vertical ? bounds.x : p_new, vertical ? p_new : bounds.y);
}
@Override
public void undo() {
super.undo();
f.setFrameOrigin(vertical ? bounds.x : p_old, vertical ? p_old : bounds.y);
}
};
editSequence.addEdit(edit);
}
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
Aggregations