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.JOutlookBar;
020: import com.l2fprod.common.swing.PercentLayout;
021: import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
022: import com.l2fprod.common.swing.plaf.metal.MetalLookAndFeelAddons;
023: import com.l2fprod.common.swing.plaf.windows.WindowsLookAndFeelAddons;
024:
025: import java.awt.BorderLayout;
026:
027: import javax.swing.ImageIcon;
028: import javax.swing.JButton;
029: import javax.swing.JFrame;
030: import javax.swing.JPanel;
031: import javax.swing.JScrollPane;
032: import javax.swing.JTabbedPane;
033: import javax.swing.JTree;
034: import javax.swing.SwingConstants;
035: import javax.swing.UIManager;
036: import javax.swing.plaf.ButtonUI;
037:
038: /**
039: * OutlookBarMain. <br>
040: *
041: */
042: public class OutlookBarMain extends JPanel {
043:
044: public OutlookBarMain() throws Exception {
045: setLayout(new BorderLayout());
046:
047: JTabbedPane tabs = new JTabbedPane();
048:
049: { // the metal look and feel
050: UIManager.setLookAndFeel(UIManager
051: .getCrossPlatformLookAndFeelClassName());
052: LookAndFeelAddons.setAddon(MetalLookAndFeelAddons.class);
053: tabs.addTab("Metal L&F",
054: makeOutlookPanel(SwingConstants.CENTER));
055: }
056:
057: UIManager.setLookAndFeel(UIManager
058: .getSystemLookAndFeelClassName());
059:
060: { // the windows look and feel
061: LookAndFeelAddons.setAddon(WindowsLookAndFeelAddons.class);
062: tabs.addTab("Windows L&F",
063: makeOutlookPanel(SwingConstants.LEFT));
064: }
065:
066: add("Center", tabs);
067: }
068:
069: JPanel makeOutlookPanel(int alignment) {
070: JOutlookBar outlook = new JOutlookBar();
071: outlook.setTabPlacement(JTabbedPane.LEFT);
072: addTab(outlook, "Folders");
073: addTab(outlook, "Backup");
074:
075: // show it is possible to add any component to the bar
076: JTree tree = new JTree();
077: outlook.addTab("A JTree", outlook.makeScrollPane(tree));
078:
079: outlook.addTab("Disabled", new JButton());
080: outlook.setEnabledAt(3, false);
081: outlook.setAllTabsAlignment(alignment);
082:
083: JPanel panel = new JPanel(new PercentLayout(
084: PercentLayout.HORIZONTAL, 3));
085: panel.add(outlook, "100");
086: return panel;
087: }
088:
089: void addTab(JOutlookBar tabs, String title) {
090: JPanel panel = new JPanel();
091: panel.setLayout(new PercentLayout(PercentLayout.VERTICAL, 0));
092: panel.setOpaque(false);
093:
094: String[] buttons = new String[] { "Inbox",
095: "icons/outlook-inbox.gif", "Outbox",
096: "icons/outlook-outbox.gif", "Drafts",
097: "icons/outlook-inbox.gif", "Templates",
098: "icons/outlook-inbox.gif", "Deleted Items",
099: "icons/outlook-trash.gif", };
100:
101: for (int i = 0, c = buttons.length; i < c; i += 2) {
102: JButton button = new JButton(buttons[i]);
103: try {
104: button.setUI((ButtonUI) Class.forName(
105: (String) UIManager.get("OutlookButtonUI"))
106: .newInstance());
107: } catch (Exception e) {
108: e.printStackTrace();
109: }
110: button.setIcon(new ImageIcon(OutlookBarMain.class
111: .getResource(buttons[i + 1])));
112: panel.add(button);
113: }
114:
115: JScrollPane scroll = tabs.makeScrollPane(panel);
116: tabs.addTab("", scroll);
117:
118: // this to test the UI gets notified of changes
119: int index = tabs.indexOfComponent(scroll);
120: tabs.setTitleAt(index, title);
121: tabs.setToolTipTextAt(index, title + " Tooltip");
122: }
123:
124: public static void main(String[] args) throws Exception {
125: UIManager.setLookAndFeel(UIManager
126: .getSystemLookAndFeelClassName());
127:
128: JFrame frame = new JFrame("JOutlookBar");
129: frame.getContentPane().setLayout(new BorderLayout());
130: frame.getContentPane().add("Center", new OutlookBarMain());
131: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
132: frame.pack();
133: frame.setLocation(100, 100);
134: frame.setVisible(true);
135: }
136:
137: }
|