use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameUIModel method getLeftGridFigure.
@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getLeftGridFigure(GraphicalGridButton gridFig) {
GridButton gb = gridFig.getModel();
GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
Iterator<IWidget> gbs = group.iterator();
DoubleRectangle bds = gb.getEltBounds();
double startX = bds.x;
double startY = bds.y;
IWidget result = null;
double resultX = 0.0;
while (gbs.hasNext()) {
IWidget cur = gbs.next();
if (cur == gb) {
continue;
}
bds = cur.getEltBounds();
double curX = bds.x;
double curY = bds.y;
if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX < startX)) {
if ((result == null) || (curX > resultX)) {
result = cur;
resultX = curX;
}
}
}
return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameUIModel method setUpFrameContents.
/**
* Set up the contents of the frame.
* This creates the scalable figure and sets the initial scaling.
*
* The layout manager is also created with an XYLayout to allow absolute
* positioning of elements.
*
* All structures needed to support drawing and selecting objects are
* created here.
*
* @param double Scale: used to set the initial size of the contents.
*/
protected void setUpFrameContents(double scale) {
// Set up the content pane
// Create the underlying contents pane.
// And set the contents pane's default widget color.
contents = new ScalableFrameFigure(frame.getWidgetColor());
contents.setScale(scale);
contents.setLayoutManager(new XYLayout());
// Create a new graphical widget for each widget in Frame.
Iterator<IWidget> modelWidgets = frame.getWidgets().iterator();
while (modelWidgets.hasNext()) {
IWidget w = modelWidgets.next();
createGraphicalWidget(w);
}
// Initialize the background image
backgroundImage = new ImageFigure();
final byte[] bgImg = frame.getBackgroundImage();
if (bgImg != null) {
if (lazyLoading) {
// Use a thread to load the image, then set it later
ThreadManager.IWorkThread imageLoadThread = new CogToolWorkThread() {
protected Image img = null;
public void doWork() {
// Performed by the scheduled thread
img = new Image(null, new ByteArrayInputStream(bgImg));
}
@Override
public void doneCallback() {
// Performed by the main UI thread
if (img != null) {
if (isDisposed) {
img.dispose();
} else {
backgroundImage.setImage(img);
}
}
// TODO: We might want to add a real logging package
if (exBucket.containsExceptions()) {
// TODO: It is unclear what to do here. Maybe
// we should just replace failed images with red
// Xs rather than popping up a dialog box
System.err.println(exBucket);
// RcvrExceptionHandler.recoverWorkThread(this,
// interaction);
}
}
};
ThreadManager.startNewThread(imageLoadThread, 2);
} else {
try {
// = AUIModel.imageCache.get(frame);
Image img = null;
if (img == null) {
img = new Image(null, new ByteArrayInputStream(bgImg));
// AUIModel.imageCache.put(frame, img);
}
backgroundImage.setImage(img);
} catch (SWTException ex) {
throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
}
}
backgroundImage.setBounds(PrecisionUtilities.getDraw2DRectangle(frame.getBackgroundBounds()));
}
// Always align the picture to top left corner
backgroundImage.setAlignment(PositionConstants.NORTH | PositionConstants.WEST);
// Resize to preferred size.
DoubleSize s = getPreferredSize();
// Set the size of the contents area to fit all elements.
contents.setSize(PrecisionUtilities.round(s.width), PrecisionUtilities.round(s.height));
// Draw all widgets.
drawWidgets();
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class DesignEditorFrame method addTransitionChangeHandler.
public void addTransitionChangeHandler(AlertHandler handler) {
Iterator<IWidget> sources = frame.getWidgets().iterator();
while (sources.hasNext()) {
IWidget widget = sources.next();
widget.addHandler(this, TransitionSource.TransitionChange.class, handler);
}
Iterator<InputDevice> devices = frame.getInputDevices().iterator();
while (devices.hasNext()) {
InputDevice device = devices.next();
device.addHandler(this, TransitionSource.TransitionChange.class, handler);
}
transitionChangeHandler = handler;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class DesignEditorFrame method dispose.
public void dispose() {
frameUIModel.removeAllHandlers(this);
frameUIModel.dispose();
Iterator<IWidget> sources = frame.getWidgets().iterator();
while (sources.hasNext()) {
IWidget widget = sources.next();
widget.removeAllHandlers(this);
}
Iterator<InputDevice> devices = frame.getInputDevices().iterator();
while (devices.hasNext()) {
InputDevice device = devices.next();
device.removeAllHandlers(this);
}
frame.removeAllHandlers(this);
// Need to dispose all InputSources that were created by this class
Iterator<GraphicalDevice> iter = inputDevices.values().iterator();
while (iter.hasNext()) {
GraphicalDevice d = iter.next();
d.dispose();
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class ChoiceWireRenderer method paintForeground.
public void paintForeground(Graphics g) {
g.pushState();
try {
GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
IWidget attributed = gw.getModel();
boolean isAuto = attributed.isStandard();
// this.choiceFigure.paintFigure(g);
if (kind == CHECK) {
g.drawRectangle(choiceX, choiceY, choiceWidth - 1, choiceHeight - 1);
if (isAuto && selected) {
int right = choiceX + choiceWidth;
int bottom = choiceY + choiceHeight;
g.drawLine(choiceX, choiceY, right, bottom);
g.drawLine(right, choiceY, choiceX, bottom);
}
} else {
g.drawOval(choiceX, choiceY, choiceWidth - 1, choiceHeight - 1);
if (isAuto && selected) {
g.setBackgroundColor(ColorConstants.black);
int w = PrecisionUtilities.round((choiceWidth - 1) * 0.5);
int h = PrecisionUtilities.round((choiceHeight - 1) * 0.5);
int x = PrecisionUtilities.round((choiceWidth - w - 1) / 2.0);
int y = PrecisionUtilities.round((choiceHeight - h - 1) / 2.0);
x = choiceX + x;
y = choiceY + y;
g.fillOval(x, y, w, h);
}
}
choiceLabel.paint(g);
} finally {
g.popState();
}
}
Aggregations