use of org.eclipse.draw2d.geometry.Dimension in project yamcs-studio by yamcs.
the class ArrayLayoutEditPolicy method createWidgetCreateCommand.
@Override
protected Command createWidgetCreateCommand(CreateRequest request) {
AbstractContainerModel container = (AbstractContainerModel) getHost().getModel();
if (!container.getChildren().isEmpty())
return null;
CompoundCommand result = new CompoundCommand("Create widget in array");
Dimension size = ((Rectangle) getConstraintFor(request)).getSize();
AbstractWidgetModel widget = (AbstractWidgetModel) request.getNewObject();
if (size == null || size.width < 1 || size.height < 1)
size = widget.getSize();
addUpdateContainerCommands(container, size, result);
WidgetCreateCommand widgetCreateCommand = new WidgetCreateCommand(widget, container, (Rectangle) getConstraintFor(request), false, true);
result.add(widgetCreateCommand);
return result;
}
use of org.eclipse.draw2d.geometry.Dimension in project yamcs-studio by yamcs.
the class ImageBoolButtonEditPart method autoSizeWidget.
private void autoSizeWidget(final ImageBoolButtonFigure imageFigure) {
if (!getWidgetModel().isAutoSize())
return;
maxAttempts = 10;
Runnable task = new Runnable() {
@Override
public void run() {
if (maxAttempts-- > 0 && imageFigure.isLoadingImage()) {
Display.getDefault().timerExec(100, this);
return;
}
ImageBoolButtonModel model = getWidgetModel();
Dimension d = imageFigure.getAutoSizedDimension();
if (model.isAutoSize() && !model.isStretch() && d != null)
model.setSize(d.width, d.height);
}
};
Display.getDefault().timerExec(100, task);
}
use of org.eclipse.draw2d.geometry.Dimension in project yamcs-studio by yamcs.
the class ImageEditPart method registerPropertyChangeHandlers.
/**
* {@inheritDoc}
*/
@Override
protected void registerPropertyChangeHandlers() {
// changes to the filename property
IWidgetPropertyChangeHandler handle = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
ImageFigure imageFigure = (ImageFigure) figure;
IPath absolutePath = (IPath) newValue;
if (!absolutePath.isAbsolute())
absolutePath = ResourceUtil.buildAbsolutePath(getWidgetModel(), absolutePath);
imageFigure.setFilePath(absolutePath);
autoSizeWidget(imageFigure);
return false;
}
};
setPropertyChangeHandler(ImageModel.PROP_IMAGE_FILE, handle);
// changes to the stretch property
handle = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
ImageFigure imageFigure = (ImageFigure) figure;
imageFigure.setStretch((Boolean) newValue);
autoSizeWidget(imageFigure);
return false;
}
};
setPropertyChangeHandler(ImageModel.PROP_STRETCH, handle);
// changes to the autosize property
handle = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
ImageFigure imageFigure = (ImageFigure) figure;
imageFigure.setAutoSize((Boolean) newValue);
ImageModel model = (ImageModel) getModel();
Dimension d = imageFigure.getAutoSizedDimension();
if ((Boolean) newValue && !model.getStretch() && d != null)
model.setSize(d.width, d.height);
return false;
}
};
setPropertyChangeHandler(ImageModel.PROP_AUTOSIZE, handle);
// changes to the stop animation property
handle = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
ImageFigure imageFigure = (ImageFigure) figure;
imageFigure.setAnimationDisabled((Boolean) newValue);
return false;
}
};
setPropertyChangeHandler(ImageModel.PROP_NO_ANIMATION, handle);
// changes to the align to nearest second property
handle = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
ImageFigure imageFigure = (ImageFigure) figure;
imageFigure.setAlignedToNearestSecond((Boolean) newValue);
return false;
}
};
setPropertyChangeHandler(ImageModel.PROP_ALIGN_TO_NEAREST_SECOND, handle);
// changes to the border width property
handle = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
ImageFigure imageFigure = (ImageFigure) figure;
imageFigure.resizeImage();
autoSizeWidget(imageFigure);
return false;
}
};
setPropertyChangeHandler(ImageModel.PROP_BORDER_WIDTH, handle);
setPropertyChangeHandler(ImageModel.PROP_BORDER_STYLE, handle);
// size change handlers - so we can stretch accordingly
handle = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
ImageFigure imageFigure = (ImageFigure) figure;
imageFigure.resizeImage();
autoSizeWidget(imageFigure);
return false;
}
};
setPropertyChangeHandler(ImageModel.PROP_HEIGHT, handle);
setPropertyChangeHandler(ImageModel.PROP_WIDTH, handle);
FigureTransparencyHelper.addHandler(this, figure);
registerCropPropertyHandlers();
registerImageRotationPropertyHandlers();
}
use of org.eclipse.draw2d.geometry.Dimension in project yamcs-studio by yamcs.
the class IntensityGraphEditPart method registerPropertyChangeHandlers.
@Override
protected void registerPropertyChangeHandlers() {
innerUpdateGraphAreaSizeProperty();
registerAxisPropertyChangeHandler();
registerROIPropertyChangeHandlers();
registerROIAmountChangeHandler();
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
if (newValue == null)
return false;
VType value = (VType) newValue;
if (value instanceof VNumberArray) {
setValue(((VNumberArray) value).getData());
return false;
}
((IntensityGraphFigure) figure).setDataArray(VTypeHelper.getDoubleArray(value));
return false;
}
};
setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVVALUE, handler);
getWidgetModel().getProperty(IntensityGraphModel.PROP_MIN).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
((IntensityGraphFigure) figure).setMin((Double) evt.getNewValue());
figure.repaint();
innerUpdateGraphAreaSizeProperty();
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_MAX).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
((IntensityGraphFigure) figure).setMax((Double) evt.getNewValue());
figure.repaint();
innerUpdateGraphAreaSizeProperty();
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_STYLE).removeAllPropertyChangeListeners();
getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_STYLE).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
figure.setBorder(BorderFactory.createBorder(BorderStyle.values()[(Integer) evt.getNewValue()], getWidgetModel().getBorderWidth(), getWidgetModel().getBorderColor(), getWidgetModel().getName()));
innerUpdateGraphAreaSizeProperty();
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_WIDTH).removeAllPropertyChangeListeners();
getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_WIDTH).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
figure.setBorder(BorderFactory.createBorder(getWidgetModel().getBorderStyle(), (Integer) evt.getNewValue(), getWidgetModel().getBorderColor(), getWidgetModel().getName()));
innerUpdateGraphAreaSizeProperty();
}
});
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) figure).setDataWidth((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_DATA_WIDTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) figure).setDataHeight((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_DATA_HEIGHT, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) figure).setColorMap((ColorMap) newValue);
return true;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_COLOR_MAP, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) figure).setCropLeft((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_LEFT, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) figure).setCropRight((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_RIGHT, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) figure).setCropTop((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_TOP, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) figure).setCropBottom((Integer) newValue);
return true;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_BOTTOM, handler);
getWidgetModel().getProperty(IntensityGraphModel.PROP_SHOW_RAMP).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
((IntensityGraphFigure) getFigure()).setShowRamp((Boolean) evt.getNewValue());
Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
innerTrig = true;
getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_GRAPH_AREA_WIDTH, getWidgetModel().getWidth() - d.width);
innerTrig = false;
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_WIDTH).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!innerTrig) {
// if it is not triggered from inner
innerTrig = true;
Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_GRAPH_AREA_WIDTH, ((Integer) evt.getNewValue()) - d.width);
// reset innerTrig to false after each inner triggering
innerTrig = false;
} else
// if it is triggered from inner, do nothing
innerTrig = false;
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_GRAPH_AREA_WIDTH).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!innerTrig) {
innerTrig = true;
Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_WIDTH, ((Integer) evt.getNewValue()) + d.width);
// reset innerTrig to false after each inner triggering
innerTrig = false;
} else
innerTrig = false;
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_HEIGHT).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!innerTrig) {
innerTrig = true;
Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_GRAPH_AREA_HEIGHT, ((Integer) evt.getNewValue()) - d.height);
// reset innerTrig to false after each inner triggering
innerTrig = false;
} else
innerTrig = false;
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_GRAPH_AREA_HEIGHT).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!innerTrig) {
innerTrig = true;
Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_HEIGHT, ((Integer) evt.getNewValue()) + d.height);
// reset innerTrig to false after each inner triggering
innerTrig = false;
} else
innerTrig = false;
}
});
getWidgetModel().getProperty(IntensityGraphModel.PROP_RGB_MODE).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
updatePropSheet();
((IntensityGraphFigure) getFigure()).setInRGBMode((Boolean) (evt.getNewValue()));
}
});
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) getFigure()).setColorDepth(getWidgetModel().getColorDepth());
return false;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_COLOR_DEPTH, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) getFigure()).setSingleLineProfiling((Boolean) newValue);
return false;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_SINGLE_LINE_PROFILING, handler);
handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
((IntensityGraphFigure) getFigure()).setROIColor(((OPIColor) newValue).getSWTColor());
return false;
}
};
setPropertyChangeHandler(IntensityGraphModel.PROP_ROI_COLOR, handler);
}
use of org.eclipse.draw2d.geometry.Dimension in project yamcs-studio by yamcs.
the class LinkingContainerEditpart method configureDisplayModel.
/**
* @param path the path of the OPI file
*/
private synchronized void configureDisplayModel() {
// This need to be executed after GUI created.
if (getWidgetModel().getDisplayModel() == null) {
IPath path = resolveMacros(getWidgetModel().getOPIFilePath());
log.info(path.toString());
final DisplayModel tempDisplayModel = new DisplayModel(path);
getWidgetModel().setDisplayModel(tempDisplayModel);
try {
if (!path.isEmpty())
XMLUtil.fillDisplayModelFromInputStream(ResourceUtil.pathToInputStream(path), tempDisplayModel, getViewer().getControl().getDisplay());
} catch (Exception e) {
OPIBuilderPlugin.getLogger().log(Level.WARNING, "Could not reload the linking container.", e);
}
}
LinkingContainerModel widgetModel = getWidgetModel();
DisplayModel displayModel = widgetModel.getDisplayModel();
widgetModel.setDisplayModelViewer((GraphicalViewer) getViewer());
widgetModel.setDisplayModelDisplayID(widgetModel.getRootDisplayModel(false).getDisplayID());
UIBundlingThread.getInstance().addRunnable(new Runnable() {
@Override
public void run() {
LinkingContainerModel widgetModel = getWidgetModel();
widgetModel.setDisplayModelExecutionMode(getExecutionMode());
widgetModel.setDisplayModelOpiRuntime(widgetModel.getRootDisplayModel(false).getOpiRuntime());
}
});
updateConnectionListForLinkedOpi(displayModel);
if (originalPoints != null && !originalPoints.isEmpty()) {
// update connections after the figure is repainted.
getViewer().getControl().getDisplay().asyncExec(() -> updateConnectionList());
}
UIBundlingThread.getInstance().addRunnable(() -> {
layout();
if (// getExecutionMode() == ExecutionMode.RUN_MODE &&
!getWidgetModel().isAutoFit() && !getWidgetModel().isAutoSize()) {
Rectangle childrenRange = GeometryUtil.getChildrenRange(LinkingContainerEditpart.this);
getWidgetModel().setChildrenGeoSize(new Dimension(childrenRange.width + childrenRange.x + figure.getInsets().left + figure.getInsets().right - 1, childrenRange.height + childrenRange.y + figure.getInsets().top + figure.getInsets().bottom - 1));
getWidgetModel().scaleChildren();
}
((LinkingContainerFigure) getFigure()).setShowScrollBars(getWidgetModel().isShowScrollBars());
((LinkingContainerFigure) getFigure()).setZoomToFitAll(getWidgetModel().isAutoFit());
((LinkingContainerFigure) getFigure()).updateZoom();
});
// Add scripts on display model
if (getExecutionMode() == ExecutionMode.RUN_MODE) {
widgetModel.getScriptsInput().getScriptList().addAll(widgetModel.getDisplayModel().getScriptsInput().getScriptList());
}
// tempDisplayModel.removeAllChildren();
LinkedHashMap<String, String> map = new LinkedHashMap<>();
AbstractContainerModel loadTarget = displayModel;
if (!widgetModel.getGroupName().trim().equals("")) {
// $NON-NLS-1$
AbstractWidgetModel group = displayModel.getChildByName(widgetModel.getGroupName());
if (group != null && group instanceof AbstractContainerModel) {
loadTarget = (AbstractContainerModel) group;
}
}
// Load "LCID" macro whose value is unique to this instance of Linking Container.
if (widgetModel.getExecutionMode() == ExecutionMode.RUN_MODE) {
map.put("LCID", "LCID_" + getLinkingContainerID());
}
// Load system macro
if (displayModel.getMacrosInput().isInclude_parent_macros()) {
map.putAll(displayModel.getParentMacroMap());
}
// Load macro from its macrosInput
map.putAll(displayModel.getMacrosInput().getMacrosMap());
// It also include the macros on this linking container
// which includes the macros from action and global macros if included
// It will replace the old one too.
map.putAll(widgetModel.getMacroMap());
widgetModel.setMacroMap(map);
widgetModel.removeAllChildren();
widgetModel.addChildren(loadTarget.getChildren(), true);
widgetModel.setDisplayModel(displayModel);
DisplayModel parentDisplay = widgetModel.getRootDisplayModel();
parentDisplay.syncConnections();
DisplayModel parentDisplay2 = widgetModel.getRootDisplayModel(false);
if (parentDisplay != parentDisplay2)
parentDisplay2.syncConnections();
if (getWidgetModel().isAutoSize()) {
performAutosize();
}
}
Aggregations