001: /*
002: * Copyright 2005-2008 Kirill Grouchnikov, based on work by
003: * Sun Microsystems, Inc. All rights reserved.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018: */
019: package test;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023:
024: import javax.swing.*;
025: import javax.swing.plaf.metal.MetalLookAndFeel;
026:
027: import org.jdesktop.swingx.JXStatusBar;
028: import org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel;
029:
030: import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
031:
032: public class TestStatusBar extends JFrame {
033: public TestStatusBar() {
034: this .setLayout(new BorderLayout());
035:
036: JXStatusBar statusBar = new JXStatusBar();
037: this .add(statusBar, BorderLayout.SOUTH);
038:
039: final JLabel statusLabel = new JLabel("");
040: JXStatusBar.Constraint c1 = new JXStatusBar.Constraint();
041: c1.setFixedWidth(100);
042: statusBar.add(statusLabel, c1);
043: Toolkit.getDefaultToolkit().addAWTEventListener(
044: new AWTEventListener() {
045: public void eventDispatched(AWTEvent event) {
046: if (event instanceof MouseEvent) {
047: MouseEvent me = (MouseEvent) event;
048: if (me.getID() == MouseEvent.MOUSE_MOVED) {
049: Point p = me.getPoint();
050: statusLabel.setText(p.x + ":" + p.y);
051: }
052: }
053: }
054: }, AWTEvent.MOUSE_MOTION_EVENT_MASK);
055:
056: JPanel controls = new JPanel(new FlowLayout());
057: final JButton winLaf = new JButton("Windows LAF");
058: final JButton metalLaf = new JButton("Metal LAF");
059: metalLaf.setEnabled(false);
060: winLaf.addActionListener(new ActionListener() {
061: public void actionPerformed(ActionEvent e) {
062: SwingUtilities.invokeLater(new Runnable() {
063: public void run() {
064: try {
065: winLaf.setEnabled(false);
066: metalLaf.setEnabled(true);
067: UIManager
068: .setLookAndFeel(new WindowsLookAndFeel());
069: SwingUtilities
070: .updateComponentTreeUI(TestStatusBar.this );
071: } catch (Exception exc) {
072: exc.printStackTrace();
073: }
074: }
075: });
076: }
077: });
078: metalLaf.addActionListener(new ActionListener() {
079: public void actionPerformed(ActionEvent e) {
080: SwingUtilities.invokeLater(new Runnable() {
081: public void run() {
082: try {
083: winLaf.setEnabled(true);
084: metalLaf.setEnabled(false);
085: UIManager
086: .setLookAndFeel(new MetalLookAndFeel());
087: SwingUtilities
088: .updateComponentTreeUI(TestStatusBar.this );
089: } catch (Exception exc) {
090: exc.printStackTrace();
091: }
092: }
093: });
094: }
095: });
096: controls.add(winLaf);
097: controls.add(metalLaf);
098:
099: this .add(controls, BorderLayout.CENTER);
100:
101: this .setSize(400, 300);
102: this .setLocationRelativeTo(null);
103: this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
104: }
105:
106: public static void main(String[] args) throws Exception {
107: UIManager
108: .setLookAndFeel(new SubstanceRavenGraphiteLookAndFeel());
109: SwingUtilities.invokeLater(new Runnable() {
110: public void run() {
111: new TestStatusBar().setVisible(true);
112: }
113: });
114: }
115: }
|