001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.demo;
018:
019: import com.l2fprod.common.swing.JButtonBar;
020: import com.l2fprod.common.swing.plaf.blue.BlueishButtonBarUI;
021: import com.l2fprod.common.swing.plaf.misc.IconPackagerButtonBarUI;
022: import com.l2fprod.common.util.ResourceManager;
023:
024: import java.awt.BorderLayout;
025: import java.awt.Component;
026: import java.awt.Dimension;
027: import java.awt.Font;
028: import java.awt.event.ActionEvent;
029:
030: import javax.swing.*;
031:
032: /**
033: * Demo of the JButtonBar. <br>
034: *
035: */
036: public class ButtonBarMain extends JPanel {
037:
038: static ResourceManager RESOURCE = ResourceManager
039: .get(ButtonBarMain.class);
040:
041: public ButtonBarMain() {
042: setLayout(new BorderLayout());
043:
044: JTabbedPane tabs = new JTabbedPane();
045: add("Center", tabs);
046:
047: { // with the mozilla L&F
048: JButtonBar toolbar = new JButtonBar(JButtonBar.VERTICAL);
049: toolbar.setUI(new BlueishButtonBarUI());
050: tabs.addTab("Mozilla L&F", new ButtonBarPanel(toolbar));
051: }
052:
053: { // with the icon packager L&F
054: JButtonBar toolbar = new JButtonBar(JButtonBar.VERTICAL);
055: toolbar.setUI(new IconPackagerButtonBarUI());
056: tabs.addTab("Icon Packager L&F",
057: new ButtonBarPanel(toolbar));
058: }
059: }
060:
061: static class ButtonBarPanel extends JPanel {
062:
063: private Component currentComponent;
064:
065: public ButtonBarPanel(JButtonBar toolbar) {
066: setLayout(new BorderLayout());
067:
068: add("West", toolbar);
069:
070: ButtonGroup group = new ButtonGroup();
071:
072: addButton(RESOURCE.getString("Main.welcome"),
073: "icons/welcome32x32.png", makePanel(RESOURCE
074: .getString("Main.welcome")), toolbar, group);
075:
076: addButton(RESOURCE.getString("Main.settings"),
077: "icons/propertysheet32x32.png", makePanel(RESOURCE
078: .getString("Main.settings")),
079:
080: toolbar, group);
081:
082: addButton(RESOURCE.getString("Main.sounds"),
083: "icons/fonts32x32.png", makePanel(RESOURCE
084: .getString("Main.sounds")), toolbar, group);
085:
086: addButton(RESOURCE.getString("Main.stats"),
087: "icons/folder32x32.png", makePanel(RESOURCE
088: .getString("Main.stats")), toolbar, group);
089: }
090:
091: private JPanel makePanel(String title) {
092: JPanel panel = new JPanel(new BorderLayout());
093: JLabel top = new JLabel(title);
094: top.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
095: top.setFont(top.getFont().deriveFont(Font.BOLD));
096: top.setOpaque(true);
097: top.setBackground(panel.getBackground().brighter());
098: panel.add("North", top);
099: panel.setPreferredSize(new Dimension(400, 300));
100: panel
101: .setBorder(BorderFactory.createEmptyBorder(4, 4, 4,
102: 4));
103: return panel;
104: }
105:
106: private void show(Component component) {
107: if (currentComponent != null) {
108: remove(currentComponent);
109: }
110: add("Center", currentComponent = component);
111: revalidate();
112: repaint();
113: }
114:
115: private void addButton(String title, String iconUrl,
116: final Component component, JButtonBar bar,
117: ButtonGroup group) {
118: Action action = new AbstractAction(title, new ImageIcon(
119: ButtonBarMain.class.getResource(iconUrl))) {
120: public void actionPerformed(ActionEvent e) {
121: show(component);
122: }
123: };
124:
125: JToggleButton button = new JToggleButton(action);
126: bar.add(button);
127:
128: group.add(button);
129:
130: if (group.getSelection() == null) {
131: button.setSelected(true);
132: show(component);
133: }
134: }
135: }
136:
137: public static void main(String[] args) throws Exception {
138: UIManager.setLookAndFeel(UIManager
139: .getSystemLookAndFeelClassName());
140:
141: JFrame frame = new JFrame("ButtonBar");
142: frame.getContentPane().setLayout(new BorderLayout());
143: frame.getContentPane().add("Center", new ButtonBarMain());
144: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
145: frame.pack();
146: frame.setLocation(100, 100);
147: frame.setVisible(true);
148: }
149:
150: }
|