Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));
g2d.setFont(rulerFont);
- g2d.setColor(Color.BLACK);
-
- String str = Double.toString(max);
- g2d.drawString(str, (int)(colorBarBoxLeft + colorBarBoxWidth - 30), (int)(colorBarBoxTop + colorBarBoxHeight));
-
- str = Double.toString(min);
- g2d.drawString(str, (int)colorBarBoxLeft + 1, (int)(colorBarBoxTop + colorBarBoxHeight));
+ double interval = (max - min) / intensities.size();
- for (RGBIntensity intensity : intensities) {
+ for (int j = 0; j < intensities.size(); j++) {
+
+ RGBIntensity intensity = intensities.get(j);
g2d.setColor(new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue(), 1f));
Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft, colorVerticalTop, colorVerticalWidth, colorVerticalHeigth);
g2d.fill(colorVertical);
+
+ double value = min + j * interval;
+ String str = Double.toString(value);
+ if (str.length() > 4) {
+ str = str.substring(0, 3);
+ }
+ g2d.setColor(Color.BLACK);
+ g2d.drawString(str, (float)(colorVerticalLeft - 8), (float)(colorBarBoxTop + colorBarBoxHeight));
colorVerticalLeft = colorVerticalLeft + colorVerticalWidth;
}
g2d.setColor(Color.BLACK);
+
+ String str = Double.toString(max);
+ g2d.drawString(str, (float)(colorVerticalLeft - 8), (float)(colorBarBoxTop + colorBarBoxHeight));
+
str = object.getKey() + " - " + label + " [" + unit + "]";
- g2d.drawString(str, (int)colorBarBoxLeft + 5, (int)colorBarBoxTop + 10);
+ g2d.drawString(str, (float)colorBarBoxLeft + 5, (float)colorBarBoxTop + 10);
}
}
}
double sizeBarBoxTop = (sizeBarBoxTopInitial + (colorBarBoxHeight * i));
i++;
-// double backgroundBoxPaddingRight = 20;
-// double backgroundBoxHeight = 50;
-// double backgroundBoxWidth = 300;
-// double backgroundBoxRight = bounds.getMaxX() - backgroundBoxPaddingRight;
-// double backgroundBoxLeft = backgroundBoxRight - backgroundBoxWidth;
-// double backgroundBoxTop = bounds.getMaxY();// + (initialPosition + (position * i));
+
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
g2d.setColor(new Color(0.9f, 0.9f, 0.9f, 0.95f));
Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));
g2d.setFont(rulerFont);
- g2d.setColor(Color.BLACK);
-
- String str = Double.toString(max);
- g2d.drawString(str, (int)(sizeBarBoxLeft + sizeBarBoxWidth - 30), (int)(sizeBarBoxTop + sizeBarBoxHeight));
-
- str = Double.toString(min);
- g2d.drawString(str, (int)sizeBarBoxLeft + 1, (int)(sizeBarBoxTop + sizeBarBoxHeight));
-
+
+ double interval = (max - min) / sizes.size();
- g2d.setColor(new Color((float)0, (float)0, (float)0.8, 0.8f));
- for (Double size: sizes) {
+ for (int j = 0; j < sizes.size(); j++) {
+
+ Double size = sizes.get(j);
+
+ g2d.setColor(new Color((float)0, (float)0, (float)0.8, 0.8f));
+ double sizedWidth = (size / 5) * sizeVerticalHeigth;
+ Rectangle2D rect = new Rectangle2D.Double(sizeVerticalLeft, (sizeVerticalTop), sizedWidth, sizeVerticalHeigth);
+ g2d.fill(rect);
- Ellipse2D ellipse = new Ellipse2D.Double(sizeVerticalLeft + sizeVerticalWidth / 2, (sizeVerticalTop), size * sizeVerticalHeigth, size * sizeVerticalHeigth);
- g2d.fill(ellipse);
+ double value = min + j * interval;
+ String str = Double.toString(value);
+ if (str.length() > 4) {
+ str = str.substring(0, 3);
+ }
+ g2d.setColor(Color.BLACK);
+ g2d.drawString(str, (float)(sizeVerticalLeft - 8), (float)(sizeBarBoxTop + sizeBarBoxHeight));
sizeVerticalLeft = sizeVerticalLeft + sizeVerticalWidth;
}
g2d.setColor(Color.BLACK);
+
+ String str = Double.toString(max);
+ g2d.drawString(str, (int)(sizeBarBoxLeft + sizeBarBoxWidth - 30), (int)(sizeBarBoxTop + sizeBarBoxHeight));
+
str = object.getKey() + " - " + label + " [" + unit + "]";
g2d.drawString(str, (int)sizeBarBoxLeft + 5, (int)sizeBarBoxTop + 10);
}
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IEditorPart;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.request.UniqueRead;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.RemoverUtil;
import org.simantics.db.procedure.Listener;
import org.simantics.district.network.DistrictNetworkUtil;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.district.network.visualisations.model.SizeBarOptions;
import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsLocation;
import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsSize;
-import org.simantics.ui.workbench.IResourceEditorPart;
import org.simantics.utils.datastructures.Pair;
-import org.simantics.utils.ui.workbench.WorkbenchUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private List<Supplier<Pair<String, DynamicColorContribution>>> colorSuppliers;
+ private Button removeVisualisationTemplateButton;
+
+ private Button applyButton;
+
public DynamicVisualisationsUI(Composite parent, int style) {
super(parent, style);
-
- defaultInitializeUI();
+// ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
+// scrolledComposite.setLayout(new GridLayout(1, false));
+// scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+//
+// Composite firstContent = new Composite(scrolledComposite, SWT.NONE);
+// firstContent.setLayout(new GridLayout(1, false));
+// firstContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ defaultInitializeUI(this);
+
+// scrolledComposite.setContent(firstContent);
+// scrolledComposite.setExpandHorizontal(true);
+// scrolledComposite.setExpandVertical(true);
+// scrolledComposite.setMinSize(firstContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
}
- private void defaultInitializeUI() {
- GridDataFactory.fillDefaults().grab(true, true).applyTo(this);
- GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(this);
+ private void defaultInitializeUI(Composite parent) {
- Composite selectionComposite = new Composite(this, SWT.NONE);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
+ GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(parent);
+
+ Composite selectionComposite = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(selectionComposite);
GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(selectionComposite);
}
});
- Composite coloringObjectsComposite = new Composite(this, SWT.NONE);
+ Composite coloringObjectsComposite = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(coloringObjectsComposite);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(coloringObjectsComposite);
initializeColoringObjects(coloringObjectsComposite);
- Composite colorBarsComposite = new Composite(this, SWT.NONE);
+ Composite colorBarsComposite = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(colorBarsComposite);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(colorBarsComposite);
initializeColorBars(colorBarsComposite);
- Composite objectSizesComposite = new Composite(this, SWT.NONE);
+ Composite objectSizesComposite = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(objectSizesComposite);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(objectSizesComposite);
initializeObjectSizes(objectSizesComposite);
- Composite sizeBarsComposite = new Composite(this, SWT.NONE);
+ Composite sizeBarsComposite = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(sizeBarsComposite);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(sizeBarsComposite);
initializeSizeBars(sizeBarsComposite);
- Button saveVisualisationTemplateButton = new Button(this, SWT.NONE);
- saveVisualisationTemplateButton.setText("Save");
- saveVisualisationTemplateButton.setEnabled(visualisation == null || visualisation.getVisualisationResource() != null);
- saveVisualisationTemplateButton.addSelectionListener(new SelectionAdapter() {
+ Composite buttonBarsComposite = new Composite(parent, SWT.NONE);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonBarsComposite);
+ GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonBarsComposite);
+
+ Button saveVisualisationTemplateAsButton = new Button(buttonBarsComposite, SWT.NONE);
+ saveVisualisationTemplateAsButton.setText("Save as visualisation template");
+ saveVisualisationTemplateAsButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+ showSaveVisualisationTemplateDialog(e.widget.getDisplay().getActiveShell());
}
});
- Button saveVisualisationTemplateAsButton = new Button(this, SWT.NONE);
- saveVisualisationTemplateAsButton.setText("Save as visualisation template");
- saveVisualisationTemplateAsButton.addSelectionListener(new SelectionAdapter() {
+ applyButton = new Button(buttonBarsComposite, SWT.NONE);
+ applyButton.setText("Apply");
+ applyButton.setEnabled(visualisation != null);
+ applyButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- showSaveVisualisationTemplateDialog(e.widget.getDisplay().getActiveShell());
+ persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
+ }
+ });
+
+ removeVisualisationTemplateButton = new Button(buttonBarsComposite, SWT.NONE);
+ removeVisualisationTemplateButton.setText("Remove");
+ removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
+ removeVisualisationTemplateButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ removeVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource()));
}
});
}
+ protected void removeVisualisationTemplate(String name, Optional<Resource> of) {
+ if (of.isPresent()) {
+ Resource visualisation = of.get();
+ Simantics.getSession().asyncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ RemoverUtil.remove(graph, visualisation);
+ }
+ });
+ }
+ }
+
private void showSaveVisualisationTemplateDialog(Shell shell) {
InputDialog dialog = new InputDialog(shell, "Save visualisation template", "Give template a name", "", new IInputValidator() {
LOGGER.error("Could not create coloring objecst", e);
}
}
- {
- Button applyButton = new Button(group, SWT.NONE);
- applyButton.setText("Apply");
- applyButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<Pair<String, DynamicColorContribution>> collect = colorSuppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
- Simantics.getSession().asyncRequest(new WriteRequest() {
-
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- DistrictNetworkUtil.setColorContributions(graph, visualisation.getVisualisationResource(), collect);
- }
- });
- }
- });
- }
}
private void createColoringObjectHeaderRow(Composite parent) {
// break;
// }
// }
+ usedButton.setSelection(sizeContribution.isUsed());
+ defaultButton.setSelection(sizeContribution.isUseDefault());
+
+ minText.setEnabled(!sizeContribution.isUseDefault());
+ maxText.setEnabled(!sizeContribution.isUseDefault());
+ sizeMapCombo.setEnabled(!sizeContribution.isUseDefault());
}
}
Group group = new Group(parent, SWT.NONE);
group.setText("Color Bars");
GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
- GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group);
+ GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group);
createColorBars(group);
}
label.setText("Size");
colorSizeCombo = new Combo(parent, SWT.READ_ONLY);
colorSizeCombo.setItems(Stream.of(ColorBarsSize.values()).map(size -> size.toString()).toArray(String[]::new));
-
- Button applyButton = new Button(parent, SWT.NONE);
- applyButton.setText("Apply");
-
- applyButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- // persist changes
- IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
- if (activeEditor instanceof IResourceEditorPart) {
-
- String colorLocation = colorLocationCombo.getItem(colorLocationCombo.getSelectionIndex());
- String colorSize = colorSizeCombo.getItem(colorSizeCombo.getSelectionIndex());
-
- ColorBarOptions options = new ColorBarOptions()
- .showColorBars(showColorButton.getSelection())
- .showColorBarsTicks(colorTicksButton.getSelection())
- .withLocation(ColorBarsLocation.valueOf(colorLocation))
- .withSize(ColorBarsSize.valueOf(colorSize));
-
- Simantics.getSession().asyncRequest(new WriteRequest() {
-
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- DistrictNetworkUtil.setColorBarOptions(graph, visualisation.getVisualisationResource(), options);
- }
- });
- }
- }
- });
}
private void initializeObjectSizes(Composite parent) {
} catch (DatabaseException e) {
LOGGER.error("Could not create object sizes", e);
}
-
- {
- Button applyButton = new Button(parent, SWT.NONE);
- applyButton.setText("Apply");
- applyButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<Pair<String, DynamicSizeContribution>> collect = sizeSuppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
- Simantics.getSession().asyncRequest(new WriteRequest() {
-
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- DistrictNetworkUtil.setSizeContributions(graph, visualisation.getVisualisationResource(), collect);
- }
- });
- }
- });
- }
}
private void initializeSizeBars(Composite parent) {
Group group = new Group(parent, SWT.NONE);
group.setText("Size Bars");
GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
- GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group);
+ GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group);
createSizeBars(group);
}
label.setText("Size");
sizeSizeCombo = new Combo(parent, SWT.READ_ONLY);
sizeSizeCombo.setItems(Stream.of(SizeBarsSize.values()).map(size -> size.toString()).toArray(String[]::new));
-
- Button applyButton = new Button(parent, SWT.READ_ONLY);
- applyButton.setText("Apply");
-
- applyButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- // persist changes
- IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
- if (activeEditor instanceof IResourceEditorPart) {
-
- String sizeLocation = sizeLocationCombo.getItem(sizeLocationCombo.getSelectionIndex());
- String sizeSize = sizeSizeCombo.getItem(sizeSizeCombo.getSelectionIndex());
-
- SizeBarOptions options = new SizeBarOptions()
- .showSizeBars(showSizeButton.getSelection())
- .showSizeBarsTicks(sizeTicksButton.getSelection())
- .withLocation(SizeBarsLocation.valueOf(sizeLocation))
- .withSize(SizeBarsSize.valueOf(sizeSize));
-
- Simantics.getSession().asyncRequest(new WriteRequest() {
-
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- DistrictNetworkUtil.setSizeBarOptions(graph, visualisation.getVisualisationResource(), options);
- }
- });
- }
- }
- });
}
public void setDiagramResource(Resource diagramResource) {
if (getParent().isDisposed())
return;
+ applyButton.setEnabled(visualisation != null);
String[] items = templateSelectionCombo.getItems();
for (int i = 0; i < items.length; i++) {
break;
}
}
+
+
+ removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null);
});
}
}
if (getParent().isDisposed())
return;
templateSelectionCombo.setItems(visualisations.stream().map(NamedResource::getName).collect(Collectors.toList()).toArray(new String[visualisations.size()]));
+
+ if (visualisation != null) {
+ String[] items = templateSelectionCombo.getItems();
+ for (int i = 0; i < items.length; i++) {
+ if (visualisation.getName().equals(items[i])) {
+ templateSelectionCombo.select(i);
+ break;
+ }
+ }
+ }
+
});
}
}