Substance API

View all API methods.

View all client properties.


API method

public static SubstanceWatermark getCurrentWatermark()

Description

Returns the current watermark.

Returns:

  • The current watermark.

See also


Sample code

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.util.Vector;

import javax.swing.*;

import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.watermark.WatermarkInfo;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#getCurrentWatermark()} API.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#getCurrentWatermark()
 */
public class GetCurrentWatermark extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public GetCurrentWatermark() {
    super("Get current watermark");

    this.setLayout(new BorderLayout());

    JPanel panel = new JPanel(new FlowLayout());

    // Get all watermark display names and set the vector as a model
    // for combobox.
    final JComboBox cb = new JComboBox(new Vector<String>(
        SubstanceLookAndFeel.getAllWatermarks().keySet()));
    cb
        .setSelectedItem(SubstanceLookAndFeel
            .getCurrentWatermarkName());

    cb.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent evt) {
        // Get the affected item
        final Object item = evt.getItem();

        if (evt.getStateChange() == ItemEvent.SELECTED) {
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              try {
                // Get the watermark info object based on
                // the selected watermark display name
                WatermarkInfo painterInfo = SubstanceLookAndFeel
                    .getAllWatermarks().get(
                        (Stringitem);
                // Set the global watermark based on the
                // watermark class name.
                SubstanceLookAndFeel
                    .setCurrentWatermark(painterInfo
                        .getClassName());
                SwingUtilities
                    .updateComponentTreeUI(GetCurrentWatermark.this);
              catch (Exception exc) {
              }
            };
          });
        }
      }
    });

    panel.add(new JLabel("All watermarks:"));
    panel.add(cb);

    this.add(panel, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    JButton getWatermark = new JButton("Get current watermark");
    getWatermark.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(GetCurrentWatermark.this,
            "Current watermark is of class "
                + SubstanceLookAndFeel
                    .getCurrentWatermark().getClass()
                    .getName());
      }
    });

    controls.add(getWatermark);
    this.add(controls, BorderLayout.SOUTH);

    this.setSize(400200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  /**
   * The main method for <code>this</code> sample. The arguments are
   * ignored.
   
   @param args
   *            Ignored.
   @throws Exception
   *             If some exception occured. Note that there is no special
   *             treatment of exception conditions in <code>this</code>
   *             sample code.
   */
  public static void main(String[] argsthrows Exception {
    UIManager.setLookAndFeel(new SubstanceLookAndFeel());
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        new GetCurrentWatermark().setVisible(true);
      }
    });
  }
}

The screenshot below shows the result of calling this API on the default (stripes) watermark. Note the class name and the watermark:

The screenshot below shows the result of calling this API after the binary watermark has been selected in the combobox. Note the class name and the watermark: