Class PrintDialog

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class PrintDialog extends GObject

Asynchronous API to present a print dialog to the user.

GtkPrintDialog collects the arguments that are needed to present the dialog, such as a title for the dialog and whether it should be modal.

The dialog is shown with the setup(Window, Cancellable, AsyncReadyCallback) function.

The actual printing can be done with print(Window, PrintSetup, Cancellable, AsyncReadyCallback) or printFile(Window, PrintSetup, File, Cancellable, AsyncReadyCallback). These APIs follows the GIO async pattern, and the results can be obtained by calling the corresponding finish methods.

Since:
4.14
  • Constructor Details

    • PrintDialog

      public PrintDialog(MemorySegment address)
      Create a PrintDialog instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • PrintDialog

      public PrintDialog()
      Create a new PrintDialog.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the PrintDialog class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected PrintDialog asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getAcceptLabel

      public String getAcceptLabel()
      Returns the label that will be shown on the accept button of the print dialog.
      Returns:
      the accept label
      Since:
      4.14
    • getModal

      public boolean getModal()
      Returns whether the print dialog blocks interaction with the parent window while it is presented.
      Returns:
      whether the print dialog is modal
      Since:
      4.14
    • getPageSetup

      public @Nullable PageSetup getPageSetup()
      Returns the page setup.
      Returns:
      the page setup
      Since:
      4.14
    • getPrintSettings

      public @Nullable PrintSettings getPrintSettings()
      Returns the print settings for the print dialog.
      Returns:
      the settings
      Since:
      4.14
    • getTitle

      public String getTitle()
      Returns the title that will be shown on the print dialog.
      Returns:
      the title
      Since:
      4.14
    • print

      public void print(@Nullable Window parent, @Nullable PrintSetup setup, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      This function prints content from a stream.

      If you pass NULL as setup, then this method will present a print dialog. Otherwise, it will attempt to print directly, without user interaction.

      The callback will be called when the printing is done.

      Parameters:
      parent - the parent GtkWindow
      setup - the GtkPrintSetup to use
      cancellable - a GCancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.14
    • printFile

      public void printFile(@Nullable Window parent, @Nullable PrintSetup setup, File file, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      This function prints a file.

      If you pass NULL as setup, then this method will present a print dialog. Otherwise, it will attempt to print directly, without user interaction.

      Parameters:
      parent - the parent GtkWindow
      setup - the GtkPrintSetup to use
      file - the GFile to print
      cancellable - a GCancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.14
    • printFileFinish

      public boolean printFileFinish(AsyncResult result) throws GErrorException

      Finishes the printFile(Window, PrintSetup, File, Cancellable, AsyncReadyCallback) call and returns the results.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - a GAsyncResult
      Returns:
      Whether the call was successful
      Throws:
      GErrorException - see GError
      Since:
      4.14
    • printFinish

      public OutputStream printFinish(AsyncResult result) throws GErrorException

      Finishes the print(Window, PrintSetup, Cancellable, AsyncReadyCallback) call and returns the results.

      If the call was successful, the content to be printed should be written to the returned output stream. Otherwise, NULL is returned.

      The overall results of the print operation will be returned in the OutputStream#close call, so if you are interested in the results, you need to explicitly close the output stream (it will be closed automatically if you just unref it). Be aware that the close call may not be instant as it operation will for the printer to finish printing.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - a GAsyncResult
      Returns:
      a OutputStream
      Throws:
      GErrorException - see GError
      Since:
      4.14
    • setAcceptLabel

      public void setAcceptLabel(String acceptLabel)
      Sets the label that will be shown on the accept button of the print dialog shown for setup(Window, Cancellable, AsyncReadyCallback).
      Parameters:
      acceptLabel - the new accept label
      Since:
      4.14
    • setModal

      public void setModal(boolean modal)
      Sets whether the print dialog blocks interaction with the parent window while it is presented.
      Parameters:
      modal - the new value
      Since:
      4.14
    • setPageSetup

      public void setPageSetup(PageSetup pageSetup)
      Set the page setup for the print dialog.
      Parameters:
      pageSetup - the new page setup
      Since:
      4.14
    • setPrintSettings

      public void setPrintSettings(PrintSettings printSettings)
      Sets the print settings for the print dialog.
      Parameters:
      printSettings - the new print settings
      Since:
      4.14
    • setTitle

      public void setTitle(String title)
      Sets the title that will be shown on the print dialog.
      Parameters:
      title - the new title
      Since:
      4.14
    • setup

      public void setup(@Nullable Window parent, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      This function presents a print dialog to let the user select a printer, and set up print settings and page setup.

      The callback will be called when the dialog is dismissed. The obtained Gtk.PrintSetup can then be passed to print(Window, PrintSetup, Cancellable, AsyncReadyCallback) or printFile(Window, PrintSetup, File, Cancellable, AsyncReadyCallback).

      One possible use for this method is to have the user select a printer, then show a page setup UI in the application (e.g. to arrange images on a page), then call print(Window, PrintSetup, Cancellable, AsyncReadyCallback) on this PrintDialog to do the printing without further user interaction.

      Parameters:
      parent - the parent GtkWindow
      cancellable - a GCancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      4.14
    • setupFinish

      public PrintSetup setupFinish(AsyncResult result) throws GErrorException

      Finishes the setup(Window, Cancellable, AsyncReadyCallback) call.

      If the call was successful, it returns a Gtk.PrintSetup which contains the print settings and page setup information that will be used to print.

      Note that this function returns a Gtk.DialogError.DISMISSED error if the user cancels the dialog.

      Parameters:
      result - a GAsyncResult
      Returns:
      the resulting [struct@Gtk.PrintSetup]
      Throws:
      GErrorException - see GError
      Since:
      4.14
    • builder

      public static PrintDialog.Builder<? extends PrintDialog.Builder> builder()
      A PrintDialog.Builder object constructs a PrintDialog with the specified properties. Use the various set...() methods to set properties, and finish construction with PrintDialog.Builder.build().
      Returns:
      the builder object