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 docrobot;
020:
021: import java.awt.BorderLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.net.URL;
025: import java.text.SimpleDateFormat;
026: import java.util.Date;
027:
028: import javax.swing.*;
029:
030: import org.jdesktop.swingx.JXStatusBar;
031: import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;
032:
033: public class StatusBarFrame extends JFrame {
034: public StatusBarFrame() {
035: super ("JXStatusBar example");
036:
037: this .setLayout(new BorderLayout());
038:
039: JMenuBar jmb = new JMenuBar();
040: jmb.add(new JMenu("File"));
041: jmb.add(new JMenu("Edit"));
042: jmb.add(new JMenu("Source"));
043: jmb.add(new JMenu("Refactor"));
044: jmb.add(new JMenu("Navigate"));
045: jmb.add(new JMenu("Search"));
046: jmb.add(new JMenu("Project"));
047: this .setJMenuBar(jmb);
048:
049: this .add(getToolbar("", 22), BorderLayout.NORTH);
050:
051: JXStatusBar statusBar = new JXStatusBar();
052: this .add(statusBar, BorderLayout.SOUTH);
053:
054: JLabel statusLabel = new JLabel("Smart Insert");
055: JXStatusBar.Constraint c1 = new JXStatusBar.Constraint();
056: c1.setFixedWidth(100);
057: statusBar.add(statusLabel, c1);
058:
059: JXStatusBar.Constraint c2 = new JXStatusBar.Constraint(
060: JXStatusBar.Constraint.ResizeBehavior.FILL);
061: SimpleDateFormat sdf = new SimpleDateFormat(
062: "MMMMM dd, yyyy hh:mm aaa");
063: final JLabel tabLabel = new JLabel("Created on "
064: + sdf.format(new Date()));
065: statusBar.add(tabLabel, c2);
066:
067: JLabel statusLabel2 = new JLabel("5 new messages");
068: JXStatusBar.Constraint c3 = new JXStatusBar.Constraint();
069: c3.setFixedWidth(80);
070: statusBar.add(statusLabel2, c3);
071:
072: this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
073: this .setSize(500, 350);
074: this .setLocationRelativeTo(null);
075: }
076:
077: public static JToolBar getToolbar(String label, int size) {
078: JToolBar toolBar = new JToolBar();
079: // toolBar.setLayout(new BoxLayout(toolBar,BoxLayout.LINE_AXIS));
080: // toolBar.setFloatable(false);
081:
082: JButton buttonCut = new JButton(getIcon(size + "/edit-cut"));
083: toolBar.add(buttonCut);
084: JButton buttonCopy = new JButton(getIcon(size + "/edit-copy"));
085: toolBar.add(buttonCopy);
086: JButton buttonPaste = new JButton(getIcon(size + "/edit-paste"));
087: toolBar.add(buttonPaste);
088: JButton buttonSelectAll = new JButton(getIcon(size
089: + "/edit-select-all"));
090: toolBar.add(buttonSelectAll);
091: JButton buttonDelete = new JButton(getIcon(size
092: + "/edit-delete"));
093: toolBar.add(buttonDelete);
094: toolBar.addSeparator();
095:
096: JToggleButton buttonFormatCenter = new JToggleButton(
097: getIcon(size + "/format-justify-center"));
098: toolBar.add(buttonFormatCenter);
099: JToggleButton buttonFormatLeft = new JToggleButton(getIcon(size
100: + "/format-justify-left"));
101: toolBar.add(buttonFormatLeft);
102: JToggleButton buttonFormatRight = new JToggleButton(
103: getIcon(size + "/format-justify-right"));
104: toolBar.add(buttonFormatRight);
105: JToggleButton buttonFormatFill = new JToggleButton(getIcon(size
106: + "/format-justify-fill"));
107: toolBar.add(buttonFormatFill);
108: toolBar.addSeparator();
109:
110: toolBar.add(Box.createGlue());
111: JButton buttonExit = new JButton(
112: getIcon(size + "/process-stop"));
113: buttonExit.addActionListener(new ActionListener() {
114: public void actionPerformed(ActionEvent e) {
115: System.exit(0);
116: }
117: });
118: toolBar.add(buttonExit);
119:
120: return toolBar;
121: }
122:
123: public static Icon getIcon(String iconName) {
124: ClassLoader cl = Thread.currentThread().getContextClassLoader();
125: URL url = cl.getResource("test/check/icons/" + iconName
126: + ".gif");
127: if (url != null)
128: return new ImageIcon(url);
129: url = cl.getResource("test/check/icons/" + iconName + ".png");
130: if (url != null)
131: return new ImageIcon(url);
132: return null;
133: }
134:
135: public static void main(String[] args) throws Exception {
136: JFrame.setDefaultLookAndFeelDecorated(true);
137: UIManager
138: .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
139: // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
140: SwingUtilities.invokeLater(new Runnable() {
141: public void run() {
142: new StatusBarFrame().setVisible(true);
143: }
144: });
145: }
146: }
|