Skip to content

Commit

Permalink
Add Ellipse widget
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed Dec 18, 2015
1 parent 43bcf8d commit 5abd05b
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 0 deletions.
Binary file added org.csstudio.display.builder.model/icons/ellipse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions org.csstudio.display.builder.model/plugin.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ActionButtonWidget_Description=Button that can open related displays or write PVs
ActionButtonWidget_Name=Action Button
EllipseWidget_Description=An ellipse
EllipseWidget_Name=Ellipse
EmbeddedDisplayWidget_Description=Widget that embeds another display
EmbeddedDisplayWidget_Name=Embedded Display
GroupWidget_Description=Group of widgets
Expand Down
11 changes: 11 additions & 0 deletions org.csstudio.display.builder.model/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
type="org.csstudio.opibuilder.widgets.Rectangle">
</alternates>
</widget>
<widget
category="GRAPHIC"
class="org.csstudio.display.builder.model.widgets.EllipseWidget"
description="%EllipseWidget_Description"
icon="platform:/plugin/org.csstudio.display.builder.model/icons/ellipse.png"
name="%EllipseWidget_Name"
type="ellipse">
<alternates
type="org.csstudio.opibuilder.widgets.Ellipse">
</alternates>
</widget>
<widget
category="MONITOR"
class="org.csstudio.display.builder.model.widgets.ImageWidget"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2015 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.csstudio.display.builder.model.widgets;

import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.displayBackgroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.displayLineColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.displayLineWidth;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.displayTransparent;

import java.util.Arrays;
import java.util.List;

import org.csstudio.display.builder.model.BaseWidget;
import org.csstudio.display.builder.model.Widget;
import org.csstudio.display.builder.model.WidgetCategory;
import org.csstudio.display.builder.model.WidgetDescriptor;
import org.csstudio.display.builder.model.WidgetProperty;
import org.csstudio.display.builder.model.properties.WidgetColor;

/** Widget that displays a static ellipse
* @author Kay Kasemir
*/
@SuppressWarnings("nls")
public class EllipseWidget extends BaseWidget
{
/** Widget descriptor */
public static final WidgetDescriptor WIDGET_DESCRIPTOR =
new WidgetDescriptor("ellipse", WidgetCategory.GRAPHIC,
"Ellipse",
"platform:/plugin/org.csstudio.display.builder.model/icons/ellipse.png",
"An ellipse",
Arrays.asList("org.csstudio.opibuilder.widgets.Ellipse"))
{
@Override
public Widget createWidget()
{
return new EllipseWidget();
}
};

private WidgetProperty<WidgetColor> background;
private WidgetProperty<Boolean> transparent;
private WidgetProperty<WidgetColor> line_color;
private WidgetProperty<Integer> line_width;

public EllipseWidget()
{
super(WIDGET_DESCRIPTOR.getType());
}

@Override
protected void defineProperties(final List<WidgetProperty<?>> properties)
{
super.defineProperties(properties);
properties.add(background = displayBackgroundColor.createProperty(this, new WidgetColor(30, 144, 255)));
properties.add(transparent = displayTransparent.createProperty(this, false));
properties.add(line_color = displayLineColor.createProperty(this, new WidgetColor(0, 0, 255)));
properties.add(line_width = displayLineWidth.createProperty(this, 3));
}

/** @return Display 'background_color' */
public WidgetProperty<WidgetColor> displayBackgroundColor()
{
return background;
}

/** @return Display 'transparent' */
public WidgetProperty<Boolean> displayTransparent()
{
return transparent;
}

/** @return Display 'line_color' */
public WidgetProperty<WidgetColor> displayLineColor()
{
return line_color;
}

/** @return Display 'line_width' */
public WidgetProperty<Integer> displayLineWidth()
{
return line_width;
}
}
4 changes: 4 additions & 0 deletions org.csstudio.display.builder.representation.javafx/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
class="org.csstudio.display.builder.representation.javafx.widgets.RectangleRepresentation"
type="rectangle">
</representation>
<representation
class="org.csstudio.display.builder.representation.javafx.widgets.EllipseRepresentation"
type="ellipse">
</representation>
<representation
class="org.csstudio.display.builder.representation.javafx.widgets.TextEntryRepresentation"
type="textentry">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2015 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.csstudio.display.builder.representation.javafx.widgets;

import org.csstudio.display.builder.model.DirtyFlag;
import org.csstudio.display.builder.model.WidgetProperty;
import org.csstudio.display.builder.model.widgets.EllipseWidget;
import org.csstudio.display.builder.representation.javafx.JFXUtil;

import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.StrokeType;

/** Creates JavaFX item for model widget
* @author Kay Kasemir
*/
public class EllipseRepresentation extends JFXBaseRepresentation<Ellipse, EllipseWidget>
{
private final DirtyFlag dirty_position = new DirtyFlag();
private final DirtyFlag dirty_look = new DirtyFlag();
private Color background, line_color;

@Override
public Ellipse createJFXNode() throws Exception
{
final Ellipse ellipse = new Ellipse();
updateColors();
return ellipse;
}

@Override
protected void registerListeners()
{
// JFX Ellipse is based on center, not top-left corner,
// so can't use the default from super.registerListeners();
model_widget.positionVisible().addUntypedPropertyListener(this::positionChanged);
model_widget.positionX().addUntypedPropertyListener(this::positionChanged);
model_widget.positionY().addUntypedPropertyListener(this::positionChanged);
model_widget.positionWidth().addUntypedPropertyListener(this::positionChanged);
model_widget.positionHeight().addUntypedPropertyListener(this::positionChanged);

model_widget.displayBackgroundColor().addUntypedPropertyListener(this::lookChanged);
model_widget.displayTransparent().addUntypedPropertyListener(this::lookChanged);
model_widget.displayLineColor().addUntypedPropertyListener(this::lookChanged);
model_widget.displayLineWidth().addUntypedPropertyListener(this::lookChanged);
}

private void positionChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value)
{
dirty_position.mark();
toolkit.scheduleUpdate(this);
}

private void lookChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value)
{
updateColors();
dirty_look.mark();
toolkit.scheduleUpdate(this);
}

private void updateColors()
{
background = model_widget.displayTransparent().getValue()
? Color.TRANSPARENT
: JFXUtil.convert(model_widget.displayBackgroundColor().getValue());
line_color = JFXUtil.convert(model_widget.displayLineColor().getValue());
}

@Override
public void updateChanges()
{
// Not using default handling of X/Y super.updateChanges();
if (dirty_position.checkAndClear())
{
if (model_widget.positionVisible().getValue())
{
jfx_node.setVisible(true);
final int x = model_widget.positionX().getValue();
final int y = model_widget.positionY().getValue();
final int w = model_widget.positionWidth().getValue();
final int h = model_widget.positionHeight().getValue();
jfx_node.setCenterX(x + w/2);
jfx_node.setCenterY(y + h/2);
jfx_node.setRadiusX(w/2);
jfx_node.setRadiusY(h/2);
}
else
jfx_node.setVisible(false);
}
if (dirty_look.checkAndClear())
{
jfx_node.setFill(background);
jfx_node.setStroke(line_color);
jfx_node.setStrokeWidth(model_widget.displayLineWidth().getValue());
jfx_node.setStrokeType(StrokeType.INSIDE);
}
}
}

2 comments on commit 5abd05b

@claudio-rosati
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following must be modified too in order to have the stand-alone editor working:

  • org.csstudio.display.builder.model.WidgetFactory.registerKnownWidgets()
  • org.csstudio.display.builder.representation.javafx.JFXRepresentation.registerKnownRepresentations(...)

@kasemir
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

Furthermore, the Ellipse widget itself is static, it has no runtime support other than the default runtime support for rules and scripts.

For basic PV-based scripts, the default runtime will already check for a "pv_name" property and a "value" property, connecting to the PV and updating the value.
Widgets that have multiple PVs or do something else at runtime need to

  • provide a WidgetRuntime
  • register that via the org.csstudio.display.builder.runtime.widgets extension point
  • add that to the WidgetRuntimeFactory for standalone tests

The extension points do not require any changes to the original sources, meaning a new 'o.c.my_site' plugin can contribute new widget models, representations and runtimes, add that plugin to the dropins/ folder of a CSS product, and it'll then have the new widgets.
The 'manual' registration to WidgetFactory, JFXRepresentation and maybe WidgetRuntimeFactory of course requires modifying those sources, since the standalone versions don't necessarily use OSGi.
Actually, the standalone application org.csstudio.display.builder.rcp.RuntimeApplication does use OSGi, but the more conveniently started RuntimeDemoJavaFX for use during development rely on the manually registered widgets.

Please sign in to comment.