001: /*
002: * Javu WingS - Lightweight Java Component Set
003: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004: * e-mail: ksadlocha@programics.com
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: package com.javujavu.javux.demo;
022:
023: import java.awt.Component;
024: import java.awt.GridBagConstraints;
025: import java.awt.GridBagLayout;
026: import java.awt.GridLayout;
027: import java.awt.Insets;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import com.javujavu.javux.wings.WingButton;
031: import com.javujavu.javux.wings.WingImage;
032: import com.javujavu.javux.wings.WingPanel;
033: import com.javujavu.javux.wings.WingTabbedPane;
034: import com.javujavu.javux.wings.item.LabelItem;
035:
036: public class TabbedPanePanel extends WingPanel {
037: private static String[] ids = { "aztec3", "border1", "border3",
038: "aztec", "green_icon", "turtle_icon", "green", "aztec2",
039: "aztec4", "red", "aztec5", null };
040:
041: private static WingImage imgs[];
042: private WingTabbedPane pane;
043:
044: private WingButton bRemove;
045:
046: public TabbedPanePanel(WingSetPanel owner) {
047: this .setLayout(new GridBagLayout());
048: pane = new WingTabbedPane();
049: GridBagConstraints c = new GridBagConstraints();
050: c.insets = new Insets(10, 10, 10, 10);
051: c.anchor = GridBagConstraints.CENTER;
052: c.fill = GridBagConstraints.BOTH;
053: c.weightx = 1.0;
054: c.weighty = 1.0;
055: this .add(pane, c);
056:
057: pane
058: .setTooltip(new LabelItem(
059: "Tab navigation:\nCtrl+PageUp/Ctrl+PageDown - previous/next page\nRIGHT mouse button on tab bar opens quick menu",
060: WingSet.imgBomb, LEFT, RIGHT));
061:
062: WingPanel p = new WingPanel(new GridLayout(1, 0));
063: WingButton b;
064: p.add(b = new WingButton("+"));
065: b.setStyleId("tool");
066: b.setWingFocusable(false);
067: b.setTooltip("Add a new random tab");
068: b.addActionListener(new ActionListener() {
069: public void actionPerformed(ActionEvent e) {
070: addPanel();
071: if (pane.getTabCount() == 1)
072: bRemove.setEnabled(true);
073: }
074: });
075: p.add(b = new WingButton());
076: b.setStyleId("close.tool");
077: b.setTooltip("Close selected tab");
078: b.setWingFocusable(false);
079: b.addActionListener(new ActionListener() {
080: public void actionPerformed(ActionEvent e) {
081: Component c2 = pane.getSelectedComponent();
082: if (c2 != null)
083: pane.removeTab(c2);
084: if (pane.getTabCount() == 0)
085: bRemove.setEnabled(false);
086: }
087: });
088: bRemove = b;
089: pane.setButton(p);
090:
091: imgs = new WingImage[8];
092: imgs[0] = WingSet.imgSmile;
093: imgs[1] = WingSet.imgTongue;
094: imgs[2] = WingSet.imgGlasses;
095: imgs[3] = WingSet.imgSilence;
096: imgs[4] = WingSet.imgUgly;
097: imgs[5] = WingSet.imgYawn;
098:
099: for (int i = 0; i < ids.length; i++)
100: addPanel();
101: }
102:
103: private int init;
104:
105: private void addPanel() {
106: String id = ids[(int) (Math.random() * ids.length)];
107: WingImage img = imgs[(int) (Math.random() * imgs.length)];
108: if (init < ids.length) {
109: id = ids[init];
110: img = imgs[init % imgs.length];
111: init++;
112: }
113: final WingPanel p = PanelPanel.panel(id);
114: WingButton b;
115: Object idt = (img != null) ? ((id != null) ? (Object) new LabelItem(
116: id, img)
117: : img)
118: : id;
119: pane.addTab(idt, null, p, b = new WingButton());
120: b.setStyleId("tab.close");
121: b.setTooltip("Close tab");
122: b.setWingFocusable(false);
123: b.addActionListener(new ActionListener() {
124: public void actionPerformed(ActionEvent e) {
125: pane.removeTab(p);
126: }
127: });
128: }
129: }
|