Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print/Save XYPlot widget #2227

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions core/ui/src/main/java/org/phoebus/ui/Preferences.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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[]
Expand Down
11 changes: 8 additions & 3 deletions core/ui/src/main/java/org/phoebus/ui/javafx/PrintAction.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion core/ui/src/main/resources/phoebus_ui_preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ status_show_user=true
default_save_path=

# Set the path to a folder with default layouts
layout_dir=
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