Example usage for java.beans PropertyChangeEvent getOldValue

List of usage examples for java.beans PropertyChangeEvent getOldValue

Introduction

In this page you can find the example usage for java.beans PropertyChangeEvent getOldValue.

Prototype

public Object getOldValue() 

Source Link

Document

Gets the old value for the property, expressed as an Object.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Register for the event
    LogManager.getLogManager().addPropertyChangeListener(new PropertyChangeListener() {
        // This method is called when configuration file is reread
        public void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            Object oldValue = evt.getOldValue();
            Object newValue = evt.getOldValue();
            // All values are null
        }// ww w .  j av  a2  s.  com
    });
}

From source file:ActiveTray.java

public static void main(String args[]) throws Exception {
    if (SystemTray.isSupported() == false) {
        System.err.println("No system tray available");
        return;//from w w w  .ja  va2 s .co  m
    }
    final SystemTray tray = SystemTray.getSystemTray();
    PropertyChangeListener propListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            TrayIcon oldTray[] = (TrayIcon[]) evt.getOldValue();
            TrayIcon newTray[] = (TrayIcon[]) evt.getNewValue();
            System.out.println(oldTray.length + " / " + newTray.length);
        }
    };
    tray.addPropertyChangeListener("trayIcons", propListener);
    Image image = Toolkit.getDefaultToolkit().getImage("jpgIcon.jpg");
    PopupMenu popup = new PopupMenu();
    MenuItem item = new MenuItem("Hello, World");
    final TrayIcon trayIcon = new TrayIcon(image, "Tip Text", popup);
    ActionListener menuActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            trayIcon.displayMessage("Good-bye", "Cruel World", TrayIcon.MessageType.WARNING);
        }
    };
    item.addActionListener(menuActionListener);
    popup.add(item);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
        }
    };
    trayIcon.addActionListener(actionListener);
    tray.add(trayIcon);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JToolBar toolbar = new JToolBar();
    toolbar.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("orientation".equals(propName)) {
                Integer oldValue = (Integer) evt.getOldValue();
                Integer newValue = (Integer) evt.getNewValue();
                if (newValue.intValue() == JToolBar.HORIZONTAL) {
                    System.out.println("horizontal orientation");
                } else {
                    System.out.println("vertical orientation");
                }/*  ww  w.  j av  a2 s  .c  om*/
            }
        }
    });
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;//ww  w .  jav  a2 s  .co  m
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/*from w  ww .  java 2s. c  o m*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);
    PropertyChangeListener[] listeners = tray.getPropertyChangeListeners("trayIcons");

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/*ww  w .  ja  va 2 s.c o  m*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);

    Dimension size = tray.getTrayIconSize();

    TrayIcon[] icons = tray.getTrayIcons();

    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/* w ww  . ja v  a  2 s  .  com*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);

    Dimension size = tray.getTrayIconSize();

    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    tray.removePropertyChangeListener("trayIcons", pcl);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:SystemTrayDemo1.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/* www  .ja v  a 2s  .c o  m*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                System.out.println("Old tray icon array contents: ");
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
                System.out.println();
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                System.out.println("New tray icon array contents: ");
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
                System.out.println();
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    g.setColor(Color.yellow);
    int ovalSize = (size.width < size.height) ? size.width : size.height;
    ovalSize /= 2;
    g.fillOval(size.width / 4, size.height / 4, ovalSize, ovalSize);

    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.FILE_VIEW_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//w  w w .j  a  va 2  s  .c  om
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JFileChooser chooser = new JFileChooser();

    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser) evt.getSource();
                File oldDir = (File) evt.getOldValue();
                File newDir = (File) evt.getNewValue();

                File curDir = chooser.getCurrentDirectory();
            }//  w  w w .j  a va 2s. co m
        }
    });
}