use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameUIModel method getNextInGroup.
public GraphicalWidget<?> getNextInGroup(GraphicalWidget<?> fromWidgetFig) {
IWidget modelWidget = fromWidgetFig.getModel();
SimpleWidgetGroup group = modelWidget.getParentGroup();
if (group != null) {
int widgetIndex = group.indexOf(modelWidget);
if (widgetIndex < group.size() - 1) {
return getWidgetFigure(group.get(widgetIndex + 1));
}
}
return null;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameUIModel method getLastInGroup.
public GraphicalWidget<?> getLastInGroup(GraphicalWidget<?> fromWidgetFig) {
IWidget modelWidget = fromWidgetFig.getModel();
SimpleWidgetGroup group = modelWidget.getParentGroup();
if (group != null) {
int widgetIndex = group.size() - 1;
return getWidgetFigure(group.get(widgetIndex));
}
return null;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameUIModel method getRightGridFigure.
@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getRightGridFigure(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 addFrameChangeListeners.
/**
* Add listeners for when things change on the frame.
*/
protected void addFrameChangeListeners() {
AlertHandler frameChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.WidgetChange chg = (Frame.WidgetChange) alert;
IWidget chgWidget = chg.getChangeElement();
if (chg != null) {
// action dictated by the change.
switch(chg.action) {
// Add the graphical representation of the widget
case Frame.WidgetChange.ELEMENT_ADD:
createGraphicalWidget(chgWidget);
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
break;
// Remove the graphical representation of the widget
case Frame.WidgetChange.ELEMENT_DELETE:
removeWidget(chgWidget);
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
break;
// Update all existing widgets to the new color
case Frame.WidgetChange.WIDGET_COLORS_CHANGED:
Iterator<GraphicalWidget<?>> gws = figureList.values().iterator();
// Update graphical widgets
while (gws.hasNext()) {
GraphicalWidget<?> gw = gws.next();
gw.setColor(frame.getWidgetColor());
// gw.setFastMode(false);
}
// Update potential temporary widget
contents.setWidgetColor(frame.getWidgetColor());
break;
}
}
// Draw the viewable widgets.
// Adds any new items from the lists.. or moves them
drawWidgets();
}
};
// Add the new handler for frame changes to the list of things to
// alert to changes on the frame
frame.addHandler(this, Frame.WidgetChange.class, frameChangeHandler);
// A separate handler is required to take care of changes of the
// background on the frame.
AlertHandler frameBackgroundChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.BackgroundImageChange chg = (Frame.BackgroundImageChange) alert;
if (chg != null) {
// Dispose the old background image if there was one
if (backgroundImage.getImage() != null) {
backgroundImage.getImage().dispose();
}
byte[] bgImg = frame.getBackgroundImage();
// If the image is null, don't create it.
if (bgImg != null) {
// the cache is probably out of date
try {
Image img = new Image(null, new ByteArrayInputStream(bgImg));
// AUIModel.imageCache.put(frame, img);
// set the new image to the background
backgroundImage.setImage(img);
// get the size of the image
org.eclipse.swt.graphics.Rectangle bounds = img.getBounds();
// resize background image with the new bounds
backgroundImage.setSize(bounds.width, bounds.height);
} catch (SWTException ex) {
throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
}
} else {
// Clear the background image.
backgroundImage.setImage(null);
backgroundImage.setSize(0, 0);
}
}
drawWidgets();
// Need to raise Alert after draw widgets since
// the alert call seems to reset the "bounds"
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, null));
}
};
// Add this handler to the list for changes in the background image
frame.addHandler(this, Frame.BackgroundImageChange.class, frameBackgroundChangeHandler);
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameUIModel method getTopGridFigure.
@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getTopGridFigure(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 resultY = 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(startX, curX, GridButtonGroup.PIXEL_EPSILON) && (curY < startY)) {
if ((result == null) || (curY > resultY)) {
result = cur;
resultY = curY;
}
}
}
return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Aggregations