use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.
the class AnnotationEditPolicy method getDirectEditCommand.
/**
* {@inheritDoc}
*/
@Override
protected Command getDirectEditCommand(final DirectEditRequest edit) {
StyledTextEditor ste = (StyledTextEditor) edit.getCellEditor();
AnnotationData newAnnoData = (AnnotationData) ste.getValue();
AnnotationEditPart annoPart = (AnnotationEditPart) getHost();
Annotation oldAnno = annoPart.getModel();
Rectangle oldFigBounds = annoPart.getFigure().getBounds().getCopy();
// y-coordinate is the only dimension that doesn't change
newAnnoData.setY(oldFigBounds.y);
// trim was never really verified (was always 0 on my platform),
// see also StyledTextEditorLocator#relocate
Composite compositeEditor = (Composite) ste.getControl();
org.eclipse.swt.graphics.Rectangle trim = compositeEditor.computeTrim(0, 0, 0, 0);
if (annoPart instanceof NodeAnnotationEditPart) {
// the width and height grow with the text entered
newAnnoData.setX(compositeEditor.getBounds().x);
newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
newAnnoData.setWidth(compositeEditor.getBounds().width - trim.width);
} else {
// with workflow annotations only the height grows with the text
newAnnoData.setX(oldFigBounds.x);
newAnnoData.setHeight(compositeEditor.getBounds().height - trim.height);
newAnnoData.setWidth(oldFigBounds.width - trim.width);
}
if (hasAnnotationDataChanged(oldAnno, newAnnoData)) {
return new AnnotationEditCommand(annoPart, oldAnno, newAnnoData);
}
return null;
}
use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.
the class AnnotationEditPart method toSWTStyleRanges.
public static StyleRange[] toSWTStyleRanges(final AnnotationData t, final Font defaultFont) {
AnnotationData.StyleRange[] knimeStyleRanges = t.getStyleRanges();
ArrayList<StyleRange> swtStyleRange = new ArrayList<StyleRange>(knimeStyleRanges.length);
for (AnnotationData.StyleRange knimeSR : knimeStyleRanges) {
StyleRange swtStyle = new StyleRange();
Font f = FontStore.INSTANCE.getAnnotationFont(knimeSR, defaultFont);
swtStyle.font = f;
if (knimeSR.getFgColor() >= 0) {
int rgb = knimeSR.getFgColor();
RGB rgbObj = RGBintToRGBObj(rgb);
swtStyle.foreground = new Color(null, rgbObj);
}
swtStyle.start = knimeSR.getStart();
swtStyle.length = knimeSR.getLength();
swtStyleRange.add(swtStyle);
}
return swtStyleRange.toArray(new StyleRange[swtStyleRange.size()]);
}
use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.
the class AddAnnotationCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// adapt location to the viewport location and the zoom factor
// this seems to be a workaround for a bug in the framework
ZoomManager zoomManager = (ZoomManager) m_viewer.getProperty(ZoomManager.class.toString());
// adjust the location according to the viewport position
// seems to be a workaround for a bug in the framework
// (should imediately deliver the correct view position and not
// the position of the viewport)
PrecisionPoint location = new PrecisionPoint(m_location.x, m_location.y);
WorkflowEditor.adaptZoom(zoomManager, location, true);
m_anno = new WorkflowAnnotation();
AnnotationData data = new AnnotationData();
// it is a workflow annotation
data.setBgColor(INITIAL_FLOWANNO_COLOR);
data.setDimension((int) location.preciseX, (int) location.preciseY, DEFAULT_WIDTH, DEFAULT_HEIGHT);
data.setBorderSize(AnnotationEditPart.getAnnotationDefaultBorderSizePrefValue());
data.setBorderColor(INITAL_FLOWBORDER_COLOR);
data.setText(INITIAL_FLOWANNO_TEXT);
data.setStyleRanges(new AnnotationData.StyleRange[0]);
m_anno.copyFrom(data, true);
WorkflowManager hostWFM = getHostWFM();
hostWFM.addWorkflowAnnotation(m_anno);
m_viewer.deselectAll();
// select the new ones....
if (m_viewer.getRootEditPart().getContents() != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureAnnotationSelection(Collections.singleton(m_anno));
}
}
use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.
the class AnnotationEditPolicy method hasAnnotationDataChanged.
/**
* Compares the content of the new and the old annotation data. If they
* are equal, no change command is executed.
* @param oldAnno Old annotation (may be a default node annotation)
* @param newAnnoData The new annotation data (not a default one)
* @return If they are equally (a default with "Node x" equals a non-default
* with "Node x")
*/
private static boolean hasAnnotationDataChanged(final Annotation oldAnno, final AnnotationData newAnnoData) {
AnnotationData oldAnnoRealData = new AnnotationData();
// copy bounds, overwrite text later
oldAnnoRealData.copyFrom(newAnnoData, true);
oldAnnoRealData.copyFrom(oldAnno.getData(), false);
// need to set text explicitely - default node annotations have
// no text (it's determined during rendering)
oldAnnoRealData.setText(AnnotationEditPart.getAnnotationText(oldAnno));
return !oldAnnoRealData.equals(newAnnoData);
}
use of org.knime.core.node.workflow.AnnotationData in project knime-core by knime.
the class AnnotationEditPart method toAnnotationData.
/**
* @param s the component with the styled text to convert.
* @return
*/
public static AnnotationData toAnnotationData(final StyledText s) {
AnnotationData result = new AnnotationData();
result.setText(s.getText());
result.setBgColor(colorToRGBint(s.getBackground()));
result.setBorderColor(AnnotationEditPart.colorToRGBint(s.getMarginColor()));
// annotations have the same margin top/left/right/bottom.
result.setBorderSize(s.getRightMargin());
result.setDefaultFontSize(s.getFont().getFontData()[0].getHeight());
TextAlignment alignment;
switch(s.getAlignment()) {
case SWT.RIGHT:
alignment = TextAlignment.RIGHT;
break;
case SWT.CENTER:
alignment = TextAlignment.CENTER;
break;
default:
alignment = TextAlignment.LEFT;
}
result.setAlignment(alignment);
StyleRange[] swtStyleRange = s.getStyleRanges();
ArrayList<AnnotationData.StyleRange> wfStyleRanges = new ArrayList<AnnotationData.StyleRange>(swtStyleRange.length);
for (StyleRange sr : swtStyleRange) {
if (sr.isUnstyled()) {
continue;
}
AnnotationData.StyleRange waSr = new AnnotationData.StyleRange();
Color fg = sr.foreground;
if (fg != null) {
int rgb = colorToRGBint(fg);
waSr.setFgColor(rgb);
}
FontStore.saveAnnotationFontToStyleRange(waSr, sr.font);
waSr.setStart(sr.start);
waSr.setLength(sr.length);
wfStyleRanges.add(waSr);
}
result.setStyleRanges(wfStyleRanges.toArray(new AnnotationData.StyleRange[wfStyleRanges.size()]));
return result;
}
Aggregations