Substance API

View all API methods.

View all client properties.


API method

public static ImageWatermarkKind getImageWatermarkKind()

Description

Returns the global kind for image-based watermarks.

Returns:

  • The global kind for image-based watermarks.

See also


Sample code

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import org.jvnet.substance.SubstanceDefaultListCellRenderer;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.utils.SubstanceConstants.ImageWatermarkKind;
import org.jvnet.substance.watermark.SubstanceImageWatermark;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#getImageWatermarkKind()} and
 {@link SubstanceLookAndFeel#setImageWatermarkKind(org.jvnet.substance.utils.SubstanceConstants.ImageWatermarkKind)}
 * APIs.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#getImageWatermarkKind()
 @see SubstanceLookAndFeel#setImageWatermarkKind(org.jvnet.substance.utils.SubstanceConstants.ImageWatermarkKind)
 */
public class GetSetImageWatermarkKind extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public GetSetImageWatermarkKind() {
    super("Get / set image watermark kind");

    this.setLayout(new BorderLayout());

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

    // Get all image watermark kinds and set the array as a model
    // for combobox.
    final JComboBox cb = new JComboBox(ImageWatermarkKind.values());
    cb.setRenderer(new SubstanceDefaultListCellRenderer() {
      @Override
      public Component getListCellRendererComponent(JList list,
          Object value, int index, boolean isSelected,
          boolean cellHasFocus) {
        ImageWatermarkKind iwk = (ImageWatermarkKindvalue;
        return super.getListCellRendererComponent(list, iwk.name(),
            index, isSelected, cellHasFocus);
      }
    });
    cb.setSelectedItem(SubstanceLookAndFeel.getImageWatermarkKind());

    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() {
              // Set the global image watermark kind
              SubstanceLookAndFeel
                  .setImageWatermarkKind((ImageWatermarkKinditem);
              repaint();
            };
          });
        }
      }
    });

    panel.add(new JLabel("All image watermark kinds:"));
    panel.add(cb);

    this.add(panel, BorderLayout.CENTER);

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

    JButton getImageWatermarkKind = new JButton(
        "Get current image watermark kind");
    getImageWatermarkKind.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(GetSetImageWatermarkKind.this,
            "Current image watermark kind is "
                + SubstanceLookAndFeel.getImageWatermarkKind()
                    .name());
      }
    });

    controls.add(getImageWatermarkKind);
    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());
    SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark(
        GetSetImageWatermarkKind.class
            .getResourceAsStream("dukeplug.gif")));
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        new GetSetImageWatermarkKind().setVisible(true);
      }
    });
  }
}

The screenshot below shows the result of calling this API for the default image watermark kind (no call to setImageWatermarkKind() has been made. Note that the image watermark is screen-centered (the dialog itself is screen-centered):

The screenshot below shows the result of calling this API after setImageWatermarkKind() has been called with ImageWatermarkKind.APP_TILE. Note that the image watermark is tiled and anchored to the dialog top-left corner: