Commit e6364dd0 authored by Johannes Eder's avatar Johannes Eder
Browse files

Merge branch '4016' into 'master'

4016

See merge request af3/af3!381
parents ede784ad e8b0ef7e
......@@ -7,5 +7,6 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="output" path="build"/>
</classpath>
......@@ -66,6 +66,13 @@
icon="icons/SystemSchedule.gif"
restorable="true">
</view>
<view
class="org.fortiss.af3.schedule.ui.ganttchartview.fx.ScheduleViewFX"
id="org.fortiss.af3.schedule.ui.ganttchartview.fx.ScheduleViewFX"
name="Schedule View FX"
icon="icons/SystemSchedule.gif"
restorable="true">
</view>
</extension>
<!-- Model Editor Bindings -->
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ScrollBar?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<GridPane fx:id="mainPane" prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" prefWidth="275.0" />
<ColumnConstraints hgrow="ALWAYS" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox minWidth="275.0">
<children>
<Region prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Scale" wrappingWidth="311.677734375">
<font>
<Font size="15.0" />
</font>
</Text>
<Slider id="slider" fx:id="slider" blockIncrement="1.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="1" prefWidth="857.0" showTickMarks="true" snapToTicks="true" value="1.0" />
<Region prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Number of periods to display" wrappingWidth="311.677734375">
<font>
<Font size="15.0" />
</font>
</Text>
<Spinner id="numPeriodsSpinner" fx:id="numPeriodsSpinner">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory initialValue="1" max="10" min="1" />
</valueFactory>
</Spinner>
<Region prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
<CheckBox id="displayPeriodsSchedulableEntitiesCheckBox" fx:id="displayPeriodsSchedulableEntitiesCheckBox" mnemonicParsing="false" onAction="#onActionDisplayPeriodsSchedulable" selected="true" text="Display periods of schedulable entities" />
<Region prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
<CheckBox id="displayPeriodsSchedulesCheckBox" fx:id="displayPeriodsSchedulesCheckBox" mnemonicParsing="false" onAction="#onActionDisplayPeriods" selected="true" text="Display periods of schedules" />
<Region prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
</children>
</VBox>
<GridPane GridPane.columnIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="0.0" percentHeight="90.0" vgrow="ALWAYS" />
<RowConstraints minHeight="10.0" percentHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Pane id="canvasPane" fx:id="canvasPane" GridPane.hgrow="ALWAYS">
<children>
<Canvas id="canvas" fx:id="canvas" height="600" onMouseMoved="#onMouseMoved" onMousePressed="#onMousePressed" onMouseReleased="#onMouseReleased" width="600" />
</children>
</Pane>
<ScrollBar id="scrollBar" fx:id="scrollBar" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</GridPane>
AbstractObjectToDrawFX.java 81b5892711f72c44f775b01b87260b89c685e77b GREEN
LabelToDrawFX.java 583cb93083db0ee96a94c5358858d35f0f9c5946 GREEN
LineToDrawFX.java 79e2fe830196fb2a301b47aca668e27cdf4f3abc GREEN
ScheduleModelElementToDrawFX.java 7863a2dafd0f1e3f8595fda035cb4ed31758224a GREEN
ScheduleViewCanvasFX.java cc83a8d9888c8e02089f496134f5d7b55105a540 GREEN
ScheduleViewColorsFX.java 1574aa027bd79b4f1f496e4c34413e77d45d9134 GREEN
ScheduleViewCompositeFX.java 228c207869a336f72cbfd6ca2d6c70cf07a1b3f5 GREEN
ScheduleViewFX.java 1e66beb93bc734c897a586415264649d3436cb4f GREEN
ScheduleViewGraphModelFX.java 49b7d919b5ec3de67b683c74b8763c0b127f4b04 GREEN
ScheduleViewLayoutDataFX.java 35401925ec4f1421998c2e269f7fda9df3133666 GREEN
ScheduleViewModelFX.java 004e5b8879b38ebe5aa03c7009acd426f15f270c GREEN
/*-------------------------------------------------------------------------+
| Copyright 2014 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.schedule.ui.ganttchartview.fx;
import java.math.BigDecimal;
import javafx.scene.paint.Color;
/**
* Base class for fx schedule graph model objects.
*
* @author eisenmann
*/
public abstract class AbstractObjectToDrawFX {
/** X coordinate of the object. */
private BigDecimal startingPoint_X;
/** Y coordinate of the object. */
private BigDecimal startingPoint_Y;
/** Width of the object. */
private BigDecimal width;
/** Flag that indicates if the object is drawn with/without a border. */
private boolean isBorder;
/** Background color of the object. */
private Color color;
/** Constructor. */
public AbstractObjectToDrawFX(BigDecimal startingPoint_x, BigDecimal startingPoint_y,
BigDecimal width, boolean withBorder, Color color) {
this.startingPoint_X = startingPoint_x;
this.startingPoint_Y = startingPoint_y;
this.width = width;
this.isBorder = withBorder;
this.color = color;
}
/** Returns {@link #getStartingPoint_X()}. */
public BigDecimal getStartingPoint_X() {
return startingPoint_X;
}
/** Returns {@link #startingPoint_Y}. */
public BigDecimal getStartingPoint_Y() {
return startingPoint_Y;
}
/** Returns {@link #width}. */
public BigDecimal getWidth() {
return width;
}
/** Returns {@link #isBorder}. */
public boolean hasBorder() {
return isBorder;
}
/** Returns {@link #color}. */
public Color getColor() {
return color;
}
/** Returns the object's name. */
abstract public String getName();
}
/*-------------------------------------------------------------------------+
| Copyright 2014 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.schedule.ui.ganttchartview.fx;
import static org.fortiss.af3.schedule.ui.utils.ScheduleViewUtilsFX.drawSubscriptedCaptionCentered;
import java.math.BigDecimal;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.schedule.model.ResourceSchedule;
import org.fortiss.af3.schedule.model.Schedule;
import org.fortiss.af3.schedule.model.SubSchedule;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
/**
* Label to be drawn in the fx schedule view.
*
* @author eisenmann
*/
public class LabelToDrawFX extends AbstractObjectToDrawFX {
/** Label text. */
private String labelName;
/** Constructor. */
public LabelToDrawFX(BigDecimal startingPoint_x, BigDecimal startingPoint_y, BigDecimal width,
boolean withBorder, Color color, String labelName) {
super(startingPoint_x, startingPoint_y, width, withBorder, color);
this.labelName = labelName;
}
/** {@inheritDoc} */
@Override
public String getName() {
return labelName;
}
/** Draws a {@link LabelToDrawFX}. */
public static void drawLabel(GraphicsContext gc, LabelToDrawFX label, int x, int y, int width,
int height, Font font) {
drawSubscriptedCaptionCentered(label.getName(), "", new Rectangle(x, y, width, height), gc,
font, font);
}
/** Creates a new label for a given {@link Schedule}. */
public static LabelToDrawFX createLabel(Schedule schedule, int y, int width, Color color,
Map<EObject, Color> objectToColor) {
INamedElement resource = null;
String labelString;
if(schedule instanceof ResourceSchedule) {
ResourceSchedule resSched = (ResourceSchedule)schedule;
resource = (INamedElement)(resSched.getResource());
labelString = resource.getName();
if(resource instanceof ExecutionUnit) {
long frequency = resSched.getFrequency();
labelString = labelString + " [fr: " + frequency + "]";
}
} else if(schedule instanceof SubSchedule) {
resource = schedule;
labelString = resource.getName();
} else {
throw new UnknownError("Unknown schedule " + schedule.getClass());
}
objectToColor.put(resource, color);
return new LabelToDrawFX(BigDecimal.ZERO, BigDecimal.valueOf(y), BigDecimal.valueOf(width),
false, color, labelString);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2014 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.schedule.ui.ganttchartview.fx;
import java.math.BigDecimal;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
/**
* Line to be drawn in the fx schedule view.
*
* @author eisenmann
*/
public class LineToDrawFX extends AbstractObjectToDrawFX {
/** Flag that indicates if the line is horizontal or vertical. */
private boolean isHorizontal;
/** Line label. */
private String label;
/** Constructor. */
public LineToDrawFX(BigDecimal startingPoint_x, BigDecimal startingPoint_y, BigDecimal length,
boolean isHorizontal, Color color, String label) {
super(startingPoint_x, startingPoint_y, length, false, color);
this.isHorizontal = isHorizontal;
this.label = label;
}
/** {@inheritDoc} */
@Override
public String getName() {
return label;
}
/** Returns {@link #isHorizontal()}. */
public boolean isHorizontal() {
return isHorizontal;
}
/** Draws a {@link LineToDrawFX}. */
public static void drawLine(GraphicsContext gc, LineToDrawFX line, Color color1, Color color2,
ScheduleViewLayoutDataFX layoutData) {
int x = layoutData.objectSpaceToDiagramSpaceX(line.getStartingPoint_X());
int y = layoutData.objectSpaceToDiagramSpaceY(line.getStartingPoint_Y());
int width = layoutData.scaleLengthObjectSpaceToDiagramSpaceX(line.getWidth());
gc.setFill(color1);
int x2, y2, xLabel, yLabel;
if(line.isHorizontal()) {
x2 = x + width;
y2 = y;
xLabel = x + (width / 2);
yLabel = y - 10;
} else {
x2 = x;
y2 = y + width;
xLabel = x;
yLabel = y + (width / 2);
}
double lineWidth = gc.getLineWidth();
gc.setLineWidth(lineWidth + 2);
// gc.setBackground(color2);
gc.beginPath();
gc.moveTo(x, y);
gc.lineTo(x2, y2);
gc.stroke();
gc.setFill(Color.BLACK);
gc.fillText(line.getName(), xLabel, yLabel);
gc.setFill(color2);
gc.setLineWidth(lineWidth);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2014 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.schedule.ui.ganttchartview.fx;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.math.BigDecimal.valueOf;
import static org.fortiss.af3.schedule.ui.utils.ScheduleViewUtilsFX.drawInfoLabel;
import static org.fortiss.af3.schedule.ui.utils.ScheduleViewUtilsFX.drawSubscriptedCaptionCentered;
import static org.fortiss.af3.schedule.utils.ScheduleUtils.getPhase;
import java.math.BigDecimal;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.schedule.model.ResourceAllocation;
import org.fortiss.af3.schedule.model.ResourceAllocationFragment;
import org.fortiss.af3.schedule.utils.ScheduleUtils;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
/**
* Schedule Model ELement (Task, Bus,..) to be drawn in the fx scheduling view
*
* @author eisenmann
*/
public class ScheduleModelElementToDrawFX extends AbstractObjectToDrawFX {
/** The Object to be drawn */
private EObject object;
/** Constructor. */
public ScheduleModelElementToDrawFX(EObject object, BigDecimal startingPoint_x,
BigDecimal startingPoint_y, BigDecimal width, boolean withBorder, Color color) {
super(startingPoint_x, startingPoint_y, width, withBorder, color);
this.object = object;
}
/** Returns the {@link #object}. */
public EObject getObject() {
return object;
}
/** Returns the name of {@link #object} */
@Override
public String getName() {
if(object instanceof INamedElement) {
return ((INamedElement)object).getName();
}
return object.toString();
}
/** Draws a {@link ScheduleModelElementToDrawFX}. */
public static void drawScheduleModelElement(GraphicsContext gc,
ScheduleModelElementToDrawFX scheduleModelElement, int x, int y, int width,
int maxWidth, int height, Font font) {
int x2 = x + width;
x = max(x, -1);
// Ensure that width is in the range [1; maxWidth]
width = max(min(x2 - x, maxWidth), 1);
Rectangle rectangle = new Rectangle(x, y, width, height);
if(scheduleModelElement.hasBorder()) {
gc.setGlobalAlpha(190f / 255);
gc.setFill(scheduleModelElement.getColor());
gc.fillRect(x, y, width, height);
gc.setGlobalAlpha(1.0);
gc.setStroke(Color.BLACK);
gc.strokeRect(x, y, width, height);
}
drawSubscriptedCaptionCentered(scheduleModelElement.getName(), "", rectangle, gc, font,
font);
BigDecimal period = null;
ResourceAllocation ra = null;
final EObject object2 = scheduleModelElement.getObject();
if(object2 instanceof ResourceAllocation) {
ra = (ResourceAllocation)object2;
} else if(object2 instanceof ResourceAllocationFragment) {
ra = (ResourceAllocation)object2.eContainer();
}
period = ScheduleUtils.getPeriod(ra);
if(period != null && period.compareTo(BigDecimal.ZERO) != 0) {
String periodLabel = "p=" + period;
double lineHeight = gc.getFont().getSize();
// Suppress rendering of period label unless the is enough space in the first text row
// of the Gantt chart bar, where the task/message name label is rendered in the center.
if(3 * lineHeight < height) {
drawInfoLabel(gc, periodLabel, rectangle);
}
}
}
/** Creates a {@link ScheduleModelElementToDrawFX} for the given {@link ResourceAllocation}. */
public static ScheduleModelElementToDrawFX createScheduleModelElement(
ResourceAllocation resourceAllocation, BigDecimal roundOffset, int y, Color color) {
BigDecimal phase = getPhase(resourceAllocation);
if(phase == null) {
phase = BigDecimal.ZERO;
}
if(resourceAllocation.getDuration() == null) {
return null;
}
return new ScheduleModelElementToDrawFX(resourceAllocation, roundOffset.add(phase),
valueOf(y), resourceAllocation.getDuration(), true, color);
}
/**
* Creates a {@link ScheduleModelElementToDrawFX} for the given
* {@link ResourceAllocationFragment}
* .
*/
public static ScheduleModelElementToDrawFX createScheduleModelElement(
ResourceAllocationFragment fragment, BigDecimal roundOffset, int y, Color color) {
BigDecimal phase = getPhase(fragment);
if(phase == null) {
return null;
}
if(fragment.getDuration() == null) {
return null;
}
return new ScheduleModelElementToDrawFX(fragment, roundOffset.add(phase), valueOf(y),
fragment.getDuration(), true, color);
}
}
/*-------------------------------------------------------------------------+
| Copyright 2012 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.schedule.ui.ganttchartview.fx;
import static java.lang.Math.round;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.schedule.model.ResourceAllocation;
import org.fortiss.af3.schedule.model.SchedulableEntity;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.IIdLabeled;
import javafx.scene.paint.Color;
/**
* Fx Scheduling View Colors (e.g. initialization of 12 base colors
*
* @author eisenmann
*/
public class ScheduleViewColorsFX {
/** Initialized base colors. */
private static final Color[] SERIES_BASE_COLORS = initColors();
/** Cached colors if more than the base colors are required. */
private static final Map<Integer, Color> colorCache = new HashMap<Integer, Color>();
/**
* Initializes 12 base colors.