diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/Messages.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/Messages.java index 463693e2f2..147cf72483 100644 --- a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/Messages.java +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015-2017 Oak Ridge National Laboratory. + * Copyright (c) 2015-2022 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 @@ -16,7 +16,11 @@ public class Messages public static String NavigateForward_TT; public static String OpenDataBrowser; public static String OpenInEditor; + public static String PrintImage; + public static String PrintPlot; public static String ReloadDisplay; + public static String SaveImageSnapshot; + public static String SavePlotSnapshot; public static String SendToLogbook; public static String Toolbar_Hide; public static String Toolbar_Show; diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/DataBrowserWidgetRuntime.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/DataBrowserWidgetRuntime.java index 8355b32d6f..20dbb09cf8 100644 --- a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/DataBrowserWidgetRuntime.java +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/DataBrowserWidgetRuntime.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015-2018 Oak Ridge National Laboratory. + * Copyright (c) 2015-2022 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 @@ -60,6 +60,8 @@ public void initialize(final DataBrowserWidget widget) runtime_actions.add(new ConfigureAction("Configure Plot", widget.runtimePropConfigure())); runtime_actions.add(new ToggleToolbarAction(widget)); runtime_actions.add(new OpenDataBrowserAction()); + runtime_actions.add(new PrintWidgetAction(widget, Messages.PrintPlot)); + runtime_actions.add(new SaveWidgetSnapshotAction(widget, Messages.SavePlotSnapshot)); } @Override diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/ImageWidgetRuntime.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/ImageWidgetRuntime.java index e8fcff6ff9..a11a9f3c88 100644 --- a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/ImageWidgetRuntime.java +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/ImageWidgetRuntime.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015-2018 Oak Ridge National Laboratory. + * Copyright (c) 2015-2022 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 @@ -20,6 +20,7 @@ import org.csstudio.display.builder.model.util.VTypeUtil; import org.csstudio.display.builder.model.widgets.plots.ImageWidget; import org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty; +import org.csstudio.display.builder.runtime.Messages; import org.csstudio.display.builder.runtime.RuntimeAction; import org.csstudio.display.builder.runtime.WidgetRuntime; import org.csstudio.display.builder.runtime.pv.PVFactory; @@ -164,6 +165,8 @@ public void initialize(final ImageWidget widget) super.initialize(widget); runtime_actions.add(new ConfigureAction("Configure Image", widget.runtimePropConfigure())); runtime_actions.add(new ToggleToolbarAction(widget)); + runtime_actions.add(new PrintWidgetAction(widget, Messages.PrintImage)); + runtime_actions.add(new SaveWidgetSnapshotAction(widget, Messages.SaveImageSnapshot)); } @Override diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/PrintWidgetAction.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/PrintWidgetAction.java new file mode 100644 index 0000000000..898c494992 --- /dev/null +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/PrintWidgetAction.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2022 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.runtime.internal; + +import org.csstudio.display.builder.model.Widget; +import org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation; +import org.csstudio.display.builder.runtime.RuntimeAction; +import org.phoebus.ui.javafx.PrintAction; + +import javafx.scene.Node; + +/** Action for runtime of widgets that should print individually + * @author Kay Kasemir + */ +@SuppressWarnings("nls") +public class PrintWidgetAction extends RuntimeAction +{ + private final Widget widget; + + public PrintWidgetAction(final Widget widget, final String title) + { + super(title, "/icons/print_edit.png"); + this.widget = widget; + } + + @Override + public void run() + { + final Node node = JFXBaseRepresentation.getJFXNode(widget); + PrintAction.print(node); + } +} diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/SaveWidgetSnapshotAction.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/SaveWidgetSnapshotAction.java new file mode 100644 index 0000000000..e831244cd9 --- /dev/null +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/SaveWidgetSnapshotAction.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2022 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.runtime.internal; + +import org.csstudio.display.builder.model.Widget; +import org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation; +import org.csstudio.display.builder.runtime.RuntimeAction; +import org.phoebus.ui.application.SaveSnapshotAction; + +import javafx.scene.Node; + +/** Action for runtime of widgets that should be saved individually + * @author Kay Kasemir + */ +@SuppressWarnings("nls") +public class SaveWidgetSnapshotAction extends RuntimeAction +{ + private final Widget widget; + + public SaveWidgetSnapshotAction(final Widget widget, final String title) + { + super(title, "/icons/save_edit.png"); + this.widget = widget; + } + + @Override + public void run() + { + final Node node = JFXBaseRepresentation.getJFXNode(widget); + SaveSnapshotAction.save(node); + } +} diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/StripchartWidgetRuntime.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/StripchartWidgetRuntime.java index ffaa84dca5..89b5a24f86 100644 --- a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/StripchartWidgetRuntime.java +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/StripchartWidgetRuntime.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Oak Ridge National Laboratory. + * Copyright (c) 2019-2022 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 @@ -48,6 +48,8 @@ public void initialize(final StripchartWidget widget) runtime_actions.add(new ConfigureAction("Configure Plot", widget.runtimePropConfigure())); runtime_actions.add(new ToggleToolbarAction(widget)); runtime_actions.add(new OpenDataBrowserAction()); + runtime_actions.add(new PrintWidgetAction(widget, Messages.PrintPlot)); + runtime_actions.add(new SaveWidgetSnapshotAction(widget, Messages.SavePlotSnapshot)); } @Override diff --git a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/XYPlotWidgetRuntime.java b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/XYPlotWidgetRuntime.java index 8a32806c27..51690464d6 100644 --- a/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/XYPlotWidgetRuntime.java +++ b/app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/internal/XYPlotWidgetRuntime.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015-2018 Oak Ridge National Laboratory. + * Copyright (c) 2015-2022 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 @@ -21,6 +21,7 @@ import org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty; import org.csstudio.display.builder.model.widgets.plots.XYPlotWidget; import org.csstudio.display.builder.model.widgets.plots.XYPlotWidget.MarkerProperty; +import org.csstudio.display.builder.runtime.Messages; import org.csstudio.display.builder.runtime.PVNameToValueBinding; import org.csstudio.display.builder.runtime.RuntimeAction; import org.csstudio.display.builder.runtime.WidgetRuntime; @@ -57,6 +58,8 @@ public void initialize(final XYPlotWidget widget) super.initialize(widget); runtime_actions.add(new ConfigureAction("Configure Plot", widget.runtimePropConfigure())); runtime_actions.add(new ToggleToolbarAction(widget)); + runtime_actions.add(new PrintWidgetAction(widget, Messages.PrintPlot)); + runtime_actions.add(new SaveWidgetSnapshotAction(widget, Messages.SavePlotSnapshot)); } @Override diff --git a/app/display/runtime/src/main/resources/org/csstudio/display/builder/runtime/messages.properties b/app/display/runtime/src/main/resources/org/csstudio/display/builder/runtime/messages.properties index 4dad42728e..9ea292a7a9 100644 --- a/app/display/runtime/src/main/resources/org/csstudio/display/builder/runtime/messages.properties +++ b/app/display/runtime/src/main/resources/org/csstudio/display/builder/runtime/messages.properties @@ -2,7 +2,11 @@ NavigateBack_TT=Open previous display NavigateForward_TT=Open next display OpenDataBrowser=Open Data Browser OpenInEditor=Open in Editor +PrintImage=Print Image... +PrintPlot=Print Plot... ReloadDisplay=Re-load Display +SaveImageSnapshot=Save Image... +SavePlotSnapshot=Save Plot... SendToLogbook=Send to Logbook... Toolbar_Hide=Hide Toolbar Toolbar_Show=Show Toolbar diff --git a/core/ui/src/main/java/org/phoebus/ui/Preferences.java b/core/ui/src/main/java/org/phoebus/ui/Preferences.java index 0d1ed5a6e6..3eaedb6728 100644 --- a/core/ui/src/main/java/org/phoebus/ui/Preferences.java +++ b/core/ui/src/main/java/org/phoebus/ui/Preferences.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017-2020 Oak Ridge National Laboratory. + * Copyright (c) 2017-2022 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 @@ -30,11 +30,12 @@ public class Preferences @Preference public static boolean status_show_user; @Preference public static String default_save_path; @Preference public static String layout_dir; + @Preference public static boolean print_landscape; static { AnnotatedPreferences.initialize(Preferences.class, "/phoebus_ui_preferences.properties"); - + // In case PVA library is included, sync its array formatting // (PVASettings cannot use Preferences.max_array_formatting // since the PVA library may be used standalone) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/SaveSnapshotAction.java b/core/ui/src/main/java/org/phoebus/ui/application/SaveSnapshotAction.java index a4e6e86bfe..8980e0cfa9 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/SaveSnapshotAction.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/SaveSnapshotAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015-2018 Oak Ridge National Laboratory. + * Copyright (c) 2015-2022 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 @@ -39,7 +39,8 @@ public SaveSnapshotAction(final Node node) setOnAction(event -> save(node)); } - private void save(final Node node) + /** @param node Node of which to save a snapshot */ + public static void save(final Node node) { final Window window = node.getScene().getWindow(); final ExtensionFilter[] file_extensions = new ExtensionFilter[] diff --git a/core/ui/src/main/java/org/phoebus/ui/javafx/PrintAction.java b/core/ui/src/main/java/org/phoebus/ui/javafx/PrintAction.java index 34a5dbbeae..eb4bd47321 100644 --- a/core/ui/src/main/java/org/phoebus/ui/javafx/PrintAction.java +++ b/core/ui/src/main/java/org/phoebus/ui/javafx/PrintAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017-2018 Oak Ridge National Laboratory. + * Copyright (c) 2017-2022 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 @@ -10,6 +10,7 @@ import java.util.Objects; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.ui.Preferences; import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import javafx.application.Platform; @@ -41,7 +42,8 @@ public PrintAction(final Node node) setOnAction(event -> Platform.runLater(() -> print(node))); } - private void print(final Node node) + /** @param node Node to print */ + public static void print(final Node node) { try { @@ -58,8 +60,11 @@ private void print(final Node node) // Scale image to full page final Printer printer = job.getPrinter(); final Paper paper = job.getJobSettings().getPageLayout().getPaper(); + final PageOrientation orient = Preferences.print_landscape + ? PageOrientation.LANDSCAPE + : PageOrientation.PORTRAIT; final PageLayout pageLayout = printer.createPageLayout(paper, - PageOrientation.LANDSCAPE, + orient, Printer.MarginType.DEFAULT); final double scaleX = pageLayout.getPrintableWidth() / screenshot.getWidth(); final double scaleY = pageLayout.getPrintableHeight() / screenshot.getHeight(); diff --git a/core/ui/src/main/resources/phoebus_ui_preferences.properties b/core/ui/src/main/resources/phoebus_ui_preferences.properties index 9e96b6f5e6..7dace0a3d6 100644 --- a/core/ui/src/main/resources/phoebus_ui_preferences.properties +++ b/core/ui/src/main/resources/phoebus_ui_preferences.properties @@ -58,4 +58,13 @@ status_show_user=true default_save_path= # Set the path to a folder with default layouts -layout_dir= \ No newline at end of file +layout_dir= + +# Compute print scaling in 'landscape' mode? +# Landscape mode is generally most suited for printouts +# of displays or plots, because the monitor tends to be 'wide'. +# At least on Mac OS X, however, the printing always appears to use +# portrait mode, so print layouts computed in landscape mode +# get cropped. +# Details can also depend on the printer driver. +print_landscape=true