Class PrintSettings

All Implemented Interfaces:
Proxy

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

Collects the settings of a print dialog in a system-independent way.

The main use for this object is that once you’ve printed you can get a settings object that represents the settings the user chose, and the next time you print you can pass that object in so that the user doesn’t have to re-set all his settings.

Its also possible to enumerate the settings so that you can easily save the settings for the next time your app runs, or even store them in a document. The predefined keys try to use shared values as much as possible so that moving such a document between systems still works.

  • Constructor Details

    • PrintSettings

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

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

    • getType

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

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

      protected PrintSettings 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
    • fromFile

      public static PrintSettings fromFile(String fileName) throws GErrorException

      Reads the print settings from fileName.

      Returns a new GtkPrintSettings object with the restored settings, or null if an error occurred. If the file could not be loaded then error is set to either a GFileError or GKeyFileError.

      See toFile(String).

      Parameters:
      fileName - the filename to read the settings from
      Returns:
      the restored GtkPrintSettings
      Throws:
      GErrorException - see GError
    • fromGvariant

      public static PrintSettings fromGvariant(Variant variant)

      Deserialize print settings from an a{sv} variant.

      The variant must be in the format produced by toGvariant().

      Parameters:
      variant - an a{sv} GVariant
      Returns:
      a new GtkPrintSettings object
    • fromKeyFile

      public static PrintSettings fromKeyFile(KeyFile keyFile, @Nullable String groupName) throws GErrorException

      Reads the print settings from the group groupName in keyFile.

      Returns a new GtkPrintSettings object with the restored settings, or null if an error occurred. If the file could not be loaded then error is set to either GFileError or GKeyFileError.

      Parameters:
      keyFile - the GKeyFile to retrieve the settings from
      groupName - the name of the group to use, or null to use the default “Print Settings”
      Returns:
      the restored GtkPrintSettings
      Throws:
      GErrorException - see GError
    • copy

      public PrintSettings copy()
      Copies a GtkPrintSettings object.
      Returns:
      a newly allocated copy of this PrintSettings
    • foreach

      public void foreach(@Nullable PrintSettingsFunc func)
      Calls func for each key-value pair of settings.
      Parameters:
      func - the function to call
    • getString

      public @Nullable String getString(String key)
      Looks up the string value associated with key.
      Parameters:
      key - a key
      Returns:
      the string value for key
    • getBool

      public boolean getBool(String key)

      Returns the boolean represented by the value that is associated with key.

      The string “true” represents true, any other string false.

      Parameters:
      key - a key
      Returns:
      true, if key maps to a true value.
    • getCollate

      public boolean getCollate()
      Gets the value of GTK_PRINT_SETTINGS_COLLATE.
      Returns:
      whether to collate the printed pages
    • getDefaultSource

      public @Nullable String getDefaultSource()
      Gets the value of GTK_PRINT_SETTINGS_DEFAULT_SOURCE.
      Returns:
      the default source
    • getDither

      public @Nullable String getDither()
      Gets the value of GTK_PRINT_SETTINGS_DITHER.
      Returns:
      the dithering that is used
    • getDouble

      public double getDouble(String key)
      Returns the double value associated with key, or 0.
      Parameters:
      key - a key
      Returns:
      the double value of key
    • getDoubleWithDefault

      public double getDoubleWithDefault(String key, double def)

      Returns the floating point number represented by the value that is associated with key, or defaultVal if the value does not represent a floating point number.

      Floating point numbers are parsed with g_ascii_strtod().

      Parameters:
      key - a key
      def - the default value
      Returns:
      the floating point number associated with key
    • getDuplex

      public PrintDuplex getDuplex()
      Gets the value of GTK_PRINT_SETTINGS_DUPLEX.
      Returns:
      whether to print the output in duplex.
    • getFinishings

      public @Nullable String getFinishings()
      Gets the value of GTK_PRINT_SETTINGS_FINISHINGS.
      Returns:
      the finishings
    • getInt

      public int getInt(String key)
      Returns the integer value of key, or 0.
      Parameters:
      key - a key
      Returns:
      the integer value of key
    • getIntWithDefault

      public int getIntWithDefault(String key, int def)
      Returns the value of key, interpreted as an integer, or the default value.
      Parameters:
      key - a key
      def - the default value
      Returns:
      the integer value of key
    • getLength

      public double getLength(String key, Unit unit)

      Returns the value associated with key, interpreted as a length.

      The returned value is converted to units.

      Parameters:
      key - a key
      unit - the unit of the return value
      Returns:
      the length value of key, converted to unit
    • getMediaType

      public @Nullable String getMediaType()

      Gets the value of GTK_PRINT_SETTINGS_MEDIA_TYPE.

      The set of media types is defined in PWG 5101.1-2002 PWG.

      Returns:
      the media type
    • getNCopies

      public int getNCopies()
      Gets the value of GTK_PRINT_SETTINGS_N_COPIES.
      Returns:
      the number of copies to print
    • getNumberUp

      public int getNumberUp()
      Gets the value of GTK_PRINT_SETTINGS_NUMBER_UP.
      Returns:
      the number of pages per sheet
    • getNumberUpLayout

      public NumberUpLayout getNumberUpLayout()
      Gets the value of GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
      Returns:
      layout of page in number-up mode
    • getOrientation

      public PageOrientation getOrientation()
      Get the value of GTK_PRINT_SETTINGS_ORIENTATION, converted to a GtkPageOrientation.
      Returns:
      the orientation
    • getOutputBin

      public @Nullable String getOutputBin()
      Gets the value of GTK_PRINT_SETTINGS_OUTPUT_BIN.
      Returns:
      the output bin
    • getPageRanges

      public PageRange[] getPageRanges()
      Gets the value of GTK_PRINT_SETTINGS_PAGE_RANGES.
      Returns:
      an array of GtkPageRanges. Use g_free() to free the array when it is no longer needed.
    • getPageSet

      public PageSet getPageSet()
      Gets the value of GTK_PRINT_SETTINGS_PAGE_SET.
      Returns:
      the set of pages to print
    • getPaperHeight

      public double getPaperHeight(Unit unit)
      Gets the value of GTK_PRINT_SETTINGS_PAPER_HEIGHT, converted to unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the paper height, in units of unit
    • getPaperSize

      public @Nullable PaperSize getPaperSize()
      Gets the value of GTK_PRINT_SETTINGS_PAPER_FORMAT, converted to a GtkPaperSize.
      Returns:
      the paper size
    • getPaperWidth

      public double getPaperWidth(Unit unit)
      Gets the value of GTK_PRINT_SETTINGS_PAPER_WIDTH, converted to unit.
      Parameters:
      unit - the unit for the return value
      Returns:
      the paper width, in units of unit
    • getPrintPages

      public PrintPages getPrintPages()
      Gets the value of GTK_PRINT_SETTINGS_PRINT_PAGES.
      Returns:
      which pages to print
    • getPrinter

      public @Nullable String getPrinter()
      Convenience function to obtain the value of GTK_PRINT_SETTINGS_PRINTER.
      Returns:
      the printer name
    • getPrinterLpi

      public double getPrinterLpi()
      Gets the value of GTK_PRINT_SETTINGS_PRINTER_LPI.
      Returns:
      the resolution in lpi (lines per inch)
    • getQuality

      public PrintQuality getQuality()
      Gets the value of GTK_PRINT_SETTINGS_QUALITY.
      Returns:
      the print quality
    • getResolution

      public int getResolution()
      Gets the value of GTK_PRINT_SETTINGS_RESOLUTION.
      Returns:
      the resolution in dpi
    • getResolutionX

      public int getResolutionX()
      Gets the value of GTK_PRINT_SETTINGS_RESOLUTION_X.
      Returns:
      the horizontal resolution in dpi
    • getResolutionY

      public int getResolutionY()
      Gets the value of GTK_PRINT_SETTINGS_RESOLUTION_Y.
      Returns:
      the vertical resolution in dpi
    • getReverse

      public boolean getReverse()
      Gets the value of GTK_PRINT_SETTINGS_REVERSE.
      Returns:
      whether to reverse the order of the printed pages
    • getScale

      public double getScale()
      Gets the value of GTK_PRINT_SETTINGS_SCALE.
      Returns:
      the scale in percent
    • getUseColor

      public boolean getUseColor()
      Gets the value of GTK_PRINT_SETTINGS_USE_COLOR.
      Returns:
      whether to use color
    • hasKey

      public boolean hasKey(String key)
      Returns true, if a value is associated with key.
      Parameters:
      key - a key
      Returns:
      true, if key has a value
    • loadFile

      public boolean loadFile(String fileName) throws GErrorException

      Reads the print settings from fileName.

      If the file could not be loaded then error is set to either a GFileError or GKeyFileError.

      See toFile(String).

      Parameters:
      fileName - the filename to read the settings from
      Returns:
      true on success
      Throws:
      GErrorException - see GError
    • loadKeyFile

      public boolean loadKeyFile(KeyFile keyFile, @Nullable String groupName) throws GErrorException

      Reads the print settings from the group groupName in keyFile.

      If the file could not be loaded then error is set to either a GFileError or GKeyFileError.

      Parameters:
      keyFile - the GKeyFile to retrieve the settings from
      groupName - the name of the group to use, or null to use the default “Print Settings”
      Returns:
      true on success
      Throws:
      GErrorException - see GError
    • set

      public void set(String key, @Nullable String value)
      Associates value with key.
      Parameters:
      key - a key
      value - a string value
    • setBool

      public void setBool(String key, boolean value)
      Sets key to a boolean value.
      Parameters:
      key - a key
      value - a boolean
    • setCollate

      public void setCollate(boolean collate)
      Sets the value of GTK_PRINT_SETTINGS_COLLATE.
      Parameters:
      collate - whether to collate the output
    • setDefaultSource

      public void setDefaultSource(String defaultSource)
      Sets the value of GTK_PRINT_SETTINGS_DEFAULT_SOURCE.
      Parameters:
      defaultSource - the default source
    • setDither

      public void setDither(String dither)
      Sets the value of GTK_PRINT_SETTINGS_DITHER.
      Parameters:
      dither - the dithering that is used
    • setDouble

      public void setDouble(String key, double value)
      Sets key to a double value.
      Parameters:
      key - a key
      value - a double value
    • setDuplex

      public void setDuplex(PrintDuplex duplex)
      Sets the value of GTK_PRINT_SETTINGS_DUPLEX.
      Parameters:
      duplex - a GtkPrintDuplex value
    • setFinishings

      public void setFinishings(String finishings)
      Sets the value of GTK_PRINT_SETTINGS_FINISHINGS.
      Parameters:
      finishings - the finishings
    • setInt

      public void setInt(String key, int value)
      Sets key to an integer value.
      Parameters:
      key - a key
      value - an integer
    • setLength

      public void setLength(String key, double value, Unit unit)
      Associates a length in units of unit with key.
      Parameters:
      key - a key
      value - a length
      unit - the unit of length
    • setMediaType

      public void setMediaType(String mediaType)

      Sets the value of GTK_PRINT_SETTINGS_MEDIA_TYPE.

      The set of media types is defined in PWG 5101.1-2002 PWG.

      Parameters:
      mediaType - the media type
    • setNCopies

      public void setNCopies(int numCopies)
      Sets the value of GTK_PRINT_SETTINGS_N_COPIES.
      Parameters:
      numCopies - the number of copies
    • setNumberUp

      public void setNumberUp(int numberUp)
      Sets the value of GTK_PRINT_SETTINGS_NUMBER_UP.
      Parameters:
      numberUp - the number of pages per sheet
    • setNumberUpLayout

      public void setNumberUpLayout(NumberUpLayout numberUpLayout)
      Sets the value of GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
      Parameters:
      numberUpLayout - a GtkNumberUpLayout value
    • setOrientation

      public void setOrientation(PageOrientation orientation)
      Sets the value of GTK_PRINT_SETTINGS_ORIENTATION.
      Parameters:
      orientation - a page orientation
    • setOutputBin

      public void setOutputBin(String outputBin)
      Sets the value of GTK_PRINT_SETTINGS_OUTPUT_BIN.
      Parameters:
      outputBin - the output bin
    • setPageRanges

      public void setPageRanges(@Nullable PageRange @Nullable [] pageRanges)
      Sets the value of GTK_PRINT_SETTINGS_PAGE_RANGES.
      Parameters:
      pageRanges - an array of GtkPageRanges
    • setPageSet

      public void setPageSet(PageSet pageSet)
      Sets the value of GTK_PRINT_SETTINGS_PAGE_SET.
      Parameters:
      pageSet - a GtkPageSet value
    • setPaperHeight

      public void setPaperHeight(double height, Unit unit)
      Sets the value of GTK_PRINT_SETTINGS_PAPER_HEIGHT.
      Parameters:
      height - the paper height
      unit - the units of height
    • setPaperSize

      public void setPaperSize(PaperSize paperSize)
      Sets the value of GTK_PRINT_SETTINGS_PAPER_FORMAT, GTK_PRINT_SETTINGS_PAPER_WIDTH and GTK_PRINT_SETTINGS_PAPER_HEIGHT.
      Parameters:
      paperSize - a paper size
    • setPaperWidth

      public void setPaperWidth(double width, Unit unit)
      Sets the value of GTK_PRINT_SETTINGS_PAPER_WIDTH.
      Parameters:
      width - the paper width
      unit - the units of width
    • setPrintPages

      public void setPrintPages(PrintPages pages)
      Sets the value of GTK_PRINT_SETTINGS_PRINT_PAGES.
      Parameters:
      pages - a GtkPrintPages value
    • setPrinter

      public void setPrinter(String printer)
      Convenience function to set GTK_PRINT_SETTINGS_PRINTER to printer.
      Parameters:
      printer - the printer name
    • setPrinterLpi

      public void setPrinterLpi(double lpi)
      Sets the value of GTK_PRINT_SETTINGS_PRINTER_LPI.
      Parameters:
      lpi - the resolution in lpi (lines per inch)
    • setQuality

      public void setQuality(PrintQuality quality)
      Sets the value of GTK_PRINT_SETTINGS_QUALITY.
      Parameters:
      quality - a GtkPrintQuality value
    • setResolution

      public void setResolution(int resolution)
      Sets the values of GTK_PRINT_SETTINGS_RESOLUTION, GTK_PRINT_SETTINGS_RESOLUTION_X and GTK_PRINT_SETTINGS_RESOLUTION_Y.
      Parameters:
      resolution - the resolution in dpi
    • setResolutionXy

      public void setResolutionXy(int resolutionX, int resolutionY)
      Sets the values of GTK_PRINT_SETTINGS_RESOLUTION, GTK_PRINT_SETTINGS_RESOLUTION_X and GTK_PRINT_SETTINGS_RESOLUTION_Y.
      Parameters:
      resolutionX - the horizontal resolution in dpi
      resolutionY - the vertical resolution in dpi
    • setReverse

      public void setReverse(boolean reverse)
      Sets the value of GTK_PRINT_SETTINGS_REVERSE.
      Parameters:
      reverse - whether to reverse the output
    • setScale

      public void setScale(double scale)
      Sets the value of GTK_PRINT_SETTINGS_SCALE.
      Parameters:
      scale - the scale in percent
    • setUseColor

      public void setUseColor(boolean useColor)
      Sets the value of GTK_PRINT_SETTINGS_USE_COLOR.
      Parameters:
      useColor - whether to use color
    • toFile

      public boolean toFile(String fileName) throws GErrorException

      This function saves the print settings from this PrintSettings to fileName.

      If the file could not be written then error is set to either a GFileError or GKeyFileError.

      Parameters:
      fileName - the file to save to
      Returns:
      true on success
      Throws:
      GErrorException - see GError
    • toGvariant

      public Variant toGvariant()
      Serialize print settings to an a{sv} variant.
      Returns:
      a new, floating, GVariant
    • toKeyFile

      public void toKeyFile(KeyFile keyFile, @Nullable String groupName)
      This function adds the print settings from this PrintSettings to keyFile.
      Parameters:
      keyFile - the GKeyFile to save the print settings to
      groupName - the group to add the settings to in keyFile, or null to use the default “Print Settings”
    • unset

      public void unset(String key)

      Removes any value associated with key.

      This has the same effect as setting the value to null.

      Parameters:
      key - a key
    • builder

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