use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class FramePropertiesPane method update.
public void update(Frame frame) {
Object pathObj = frame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
if (NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
imagePath.setVisible(false);
imagePathText.setVisible(false);
} else {
String imgPath = (String) pathObj;
imagePath.setVisible(true);
imagePathText.setVisible(true);
imagePathText.setText(imgPath);
imagePathText.setSelection(imgPath.length());
}
Set<TransitionSource> children = new LinkedHashSet<TransitionSource>();
children.addAll(frame.getWidgets());
children.addAll(frame.getInputDevices());
widgetUpdater.updateTree(children.iterator());
if (eltGroupTreeLabel != null) {
Set<FrameElementGroup> grps = frame.getEltGroups();
if (!CogToolPref.NESTED_GROUPS_SHOWN_AT_TOP_LEVEL.getBoolean()) {
grps = filterNestedGroups(grps);
}
eltGroupUpdater.updateTree(grps.iterator());
Set<SimpleWidgetGroup> implicitGroups = new HashSet<SimpleWidgetGroup>();
for (IWidget w : frame.getWidgets()) {
SimpleWidgetGroup g = w.getParentGroup();
if (g != null) {
implicitGroups.add(g);
}
}
implicitGroupUpdater.updateTree(implicitGroups.iterator());
}
setFrameName(frame);
}
use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class HCIPACmd method buildActionStepInsert.
protected static void buildActionStepInsert(AUndertaking task, AScriptStep step, Demonstration demo, StringBuilder php) {
int hcipaStep = task.getTaskGroup().getUndertakings().indexOf(task) + 1;
Frame curFrame = step.getCurrentFrame();
TransitionSource src = step.getStepFocus();
String labelAction;
if (src == null) {
labelAction = "None";
} else {
labelAction = quotePHP(quoteSQL(src.getLabel()));
}
int order = demo.getSteps().indexOf(step) + 1;
byte[] bkgImage = curFrame.getBackgroundImage();
if (bkgImage != null) {
ImageData imgData = new ImageData(new ByteArrayInputStream(bkgImage));
bkgImage = GraphicsUtil.convertImageType(imgData, SWT.IMAGE_JPEG);
int imgSize = bkgImage.length;
String imgName = (String) curFrame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
php.append("\t$imgType = \"'image/jpeg'\";\n\t");
php.append("$imgLength = " + imgSize + ";\n\t");
php.append("$bkgImage = '0x' . bin2hex(base64_decode(str_replace(array('.', '_', '-'), array('+', '/', '='), \"");
php.append(Base64.encode(bkgImage));
php.append("\")));\n\n\t");
if ((imgName == null) || NullSafe.equals(WidgetAttributes.NO_IMAGE, imgName)) {
php.append("$imgName = 'null';\n\t");
} else {
php.append("$imgName = \"'\" . mysql_real_escape_string(basename(\n<<<SQL__INSERT__STRING\n");
php.append(imgName);
php.append("\nSQL__INSERT__STRING\n)) . \"'\";\n\n\t");
}
} else {
php.append("\t$imgType = 'null';\n\t");
php.append("$imgLength = 'null';\n\t");
php.append("$bkgImage = 'null';\n\t");
php.append("$imgName = 'null';\n\n\t");
}
php.append("Add_Task_Action($deviceId,\n\t");
php.append(hcipaStep + ",\n\t" + order + ",\n\t");
php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
php.append("\"" + quotePHP(quoteSQL(curFrame.getName())) + "\",\n\t");
php.append("\"" + labelAction + "\");\n\n");
// php.append("$sqlStmt =\n<<<SQL__INSERT__STRING\n\t");
// php.append(SQL_INSERT + "HCIPA_Actions (hcipa_id,\n\thcipa_step,\n\t");
// php.append("hcipa_order,\n\tImage,\n\tImage_Name,\n\tImage_Size,\n\tImage_Type,\n\t");
// php.append("Next_User_Action,\n\tLabel_User_Action)\n\t");
// php.append(SQL_VALUES + " ($deviceId,\n\t" + hcipaStep + ",\n\t" + order + ",\n\t");
// php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
// php.append("'" + quoteSQL(curFrame.getName()) + "',\n\t'" + labelAction + "'");
// php.append(")\n");
// php.append("SQL__INSERT__STRING\n;\n\n\t");
// php.append("mysql_query($sqlStmt);\n\n");
}
use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class DemoScriptCmd method exportScriptToCSV.
public static boolean exportScriptToCSV(Script script, Project project, Interaction interaction, IUndoableEditSequence editSeq) {
Demonstration demo = script.getDemonstration();
TaskApplication ta = demo.getTaskApplication();
Design design = ta.getDesign();
AUndertaking task = ta.getTask();
String name = project.getName();
name += "_" + design.getName();
name += "_" + task.getName();
File dest = null;
if (interaction != null) {
dest = interaction.selectCSVFileDest(name);
} else {
dest = new File(CogTool.exportCSVKludgeDir, name + ".txt");
}
if (dest == null) {
return false;
}
FileWriter fw = null;
BufferedWriter buffer = null;
try {
fw = new FileWriter(dest);
buffer = new BufferedWriter(fw);
CSVSupport.writeCell("Format version:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(FORMAT_VERSION, buffer);
CSVSupport.addLineEnding(buffer);
Date now = new Date();
String date = DateFormat.getDateTimeInstance().format(now);
CSVSupport.writeCell("Date and Time:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(date, buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Project Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(project.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Design Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(design.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Task Hierarchy:", buffer);
String taskName = task.getFullName();
String[] cells = taskName.split(":");
for (String cell : cells) {
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(cell, buffer);
}
CSVSupport.addLineEnding(buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.addLineEnding(buffer);
buffer.write("\"Frame\",\"Action\",\"Widget-Name\"," + "\"Displayed-Label\",\"Widget-Type\"");
CSVSupport.addLineEnding(buffer);
IWidget lastMovedToWidget = null;
Iterator<DefaultModelGeneratorState> stepStates = script.getStepStates().iterator();
while (stepStates.hasNext()) {
DefaultModelGeneratorState stepState = stepStates.next();
AScriptStep step = stepState.getScriptStep();
TransitionSource stepFocus = step.getStepFocus();
String frameName = step.getCurrentFrame().getName();
String actionName = KeyDisplayUtil.convertActionToMenuText(step.getLocalizedString());
if ((!(step instanceof LookAtScriptStep)) && (!(step instanceof ThinkScriptStep)) && (!(step instanceof TextActionSegment))) {
actionName = step.getLocalizedActionString(actionName, lastMovedToWidget);
}
lastMovedToWidget = stepState.getLastMovedToWidget();
String widgetName = "";
String widgetType = "";
String widgetTitle = "";
if (stepFocus != null) {
widgetName = stepFocus.getName();
if (stepFocus instanceof IWidget) {
IWidget w = (IWidget) stepFocus;
widgetType = w.getWidgetType().toString();
String s = w.getTitle();
if (s != null) {
widgetTitle = s;
}
}
}
CSVSupport.writeCell(frameName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(actionName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetTitle, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetType, buffer);
CSVSupport.addLineEnding(buffer);
}
Frame resultFrame = demo.getResultFrame();
if (resultFrame != null) {
CSVSupport.writeCell(resultFrame.getName(), buffer);
}
if (interaction != null) {
interaction.setStatusMessage(L10N.get("DSO.ExportCompletedPre", "Export completed to ") + dest + L10N.get("DSO.ExportCompletePost", "."));
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error", e.getMessage());
} else {
e.printStackTrace();
}
return false;
} finally {
try {
if (buffer != null) {
buffer.close();
}
if (fw != null) {
fw.close();
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error on Close", e.getMessage());
} else {
e.printStackTrace();
}
return false;
}
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class DesignEditorController method createEditTransitionAction.
// createEditDesignAction
protected IListenerAction createEditTransitionAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignEditorUI.EditTransitionParameters.class;
}
public boolean performAction(Object prms) {
DesignEditorUI.EditTransitionParameters parms = (DesignEditorUI.EditTransitionParameters) prms;
Transition[] transitions = parms.selection.getSelectedTransitions();
// Probably only one transition selected
if ((transitions != null) && (transitions.length > 0)) {
if (transitions.length == 1) {
TransitionSource source = transitions[0].getSource();
AAction action = transitions[0].getAction();
int limitMode = ActionProperties.determineChangeActionMode(source);
int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
if (!interaction.determineNewAction(transitions[0], properties, parms.useWhichParts, deviceTypes, limitMode, L10N.get("DE.ChangeActionType", "Change Action Type"))) {
return false;
}
action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
if (action == null) {
return false;
}
action = EditActionCmd.ensureActionIsUnique(source, action, properties, deviceTypes, limitMode, transitions[0], interaction);
if (action == null) {
return false;
}
return changeTransitionsAction(transitions, action, properties.delayInSecs, properties.delayLabel);
} else {
interaction.protestMultipleTransitionSelection();
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class DesignEditorController method deleteTransitions.
protected void deleteTransitions(final Transition[] transitions) {
// For redo, must save the corresponding source for each Transition
if ((transitions != null) && (transitions.length > 0)) {
final TransitionSource[] sources = new TransitionSource[transitions.length];
for (int i = 0; i < transitions.length; i++) {
Transition t = transitions[i];
sources[i] = t.getSource();
sources[i].removeTransition(t);
}
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(DesignEditorLID.DeleteTransition, demoStateMgr) {
@Override
public String getPresentationName() {
return (transitions.length > 1) ? deleteTransitions : deleteTransition;
}
@Override
public void redo() {
super.redo();
for (int i = 0; i < transitions.length; i++) {
Transition t = transitions[i];
sources[i].removeTransition(t);
}
stateMgr.noteTransitionsEdit(transitions, this);
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < transitions.length; i++) {
Transition t = transitions[i];
sources[i].addTransition(t);
}
stateMgr.noteTransitionsEdit(transitions, this);
}
};
demoStateMgr.noteTransitionsEdit(transitions, edit);
undoMgr.addEdit(edit);
}
}
Aggregations