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.BorderLayout;
024: import java.awt.Color;
025: import java.awt.GridBagConstraints;
026: import java.awt.GridBagLayout;
027: import java.awt.GridLayout;
028: import java.awt.Insets;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.awt.event.ItemEvent;
032: import java.awt.event.ItemListener;
033: import com.javujavu.javux.wings.WingButton;
034: import com.javujavu.javux.wings.WingLabel;
035: import com.javujavu.javux.wings.WingList;
036: import com.javujavu.javux.wings.WingPanel;
037: import com.javujavu.javux.wings.WingScrollPane;
038: import com.javujavu.javux.wings.extra.ColorItem;
039: import com.javujavu.javux.wings.item.LabelItem;
040:
041: public class ListPanel extends WingPanel implements ActionListener,
042: ItemListener {
043: private WingButton bAdd;
044: private WingButton bInsert;
045: private WingButton bRemove;
046: private WingList list1;
047: private WingList target;
048: private WingList list2;
049: private WingList list3;
050:
051: public ListPanel(WingSetPanel owner) {
052: this .setLayout(new GridBagLayout());
053: WingPanel panel = new WingPanel(new GridLayout(0, 2, 8, 8));
054: GridBagConstraints c = new GridBagConstraints();
055: c.insets = new Insets(10, 10, 10, 10);
056: c.anchor = GridBagConstraints.CENTER;
057: c.fill = GridBagConstraints.BOTH;
058: c.weightx = 1.0;
059: c.weighty = 1.0;
060: c.gridwidth = GridBagConstraints.REMAINDER;
061: this .add(panel, c);
062:
063: WingList list;
064: WingPanel panel2;
065: panel.add(panel2 = new WingPanel(new BorderLayout()));
066: panel2.add(new WingScrollPane(list1 = list = new WingList(
067: WingList.VERTICAL)));
068: WingPanel panel3;
069: panel2.add(panel3 = new WingPanel(new BorderLayout()),
070: BorderLayout.NORTH);
071: panel3.setStyleId("border2");
072: panel3
073: .add(new WingLabel("vertical alignment",
074: WingLabel.CENTER));
075: addItems(list);
076: list.addItem(new LabelItem("animated", WingSet.imgAnim));
077: list.setTooltip(new LabelItem(
078: "list with vertical alignment\ndefault style",
079: WingSet.imgEye));
080:
081: panel.add(panel2 = new WingPanel(new BorderLayout()));
082: panel2.add(new WingScrollPane(list2 = list = new WingList(
083: WingList.VERTICAL_WRAP)));
084: WingPanel p3;
085: panel2.add(p3 = new WingPanel(new GridBagLayout()),
086: BorderLayout.NORTH);
087: c = new GridBagConstraints();
088: c.weightx = 1.0;
089: p3.add(new WingLabel("vertical wrap alignment",
090: WingLabel.CENTER), c);
091: WingButton b;
092: c.weightx = 0.0;
093: p3.add(b = new WingButton("TopStyle"), c);
094: b.setStyleId("vpopup");
095: b.setTextPosition(LEFT);
096: b.setFastAction(true);
097: b
098: .setTooltip(new LabelItem(
099: "modify TopStyle of this WingList\nTopStyle is an extra style overriding stylesheet settings \ndynamically at run time\nclick button to change settings",
100: WingSet.imgIcon, LEFT, RIGHT));
101: new TopStyleEditor(b, list2, 0, 0, false);
102: addItems(list);
103: list.setTooltip(new LabelItem(
104: "list with vertical wrap alignment\ndefault style",
105: WingSet.imgDrink));
106:
107: panel.add(panel2 = new WingPanel(new BorderLayout()));
108: panel2.add(new WingScrollPane(list3 = list = new WingList(
109: WingList.HORIZONTAL_WRAP)));
110: panel2.add(new WingLabel("horizontal wrap alignment",
111: WingLabel.CENTER), BorderLayout.NORTH);
112: addItems(list);
113: list.setTooltip(new LabelItem(
114: "list with horizontal wrap alignment\ndefault style",
115: WingSet.imgTired));
116:
117: panel.add(panel2 = new WingPanel(new BorderLayout()));
118: panel2.add(new WingScrollPane(list = new WingList(
119: WingList.VERTICAL)));
120: panel2.add(new WingLabel("disabled list", WingLabel.CENTER),
121: BorderLayout.NORTH);
122: addItems(list);
123: list.setEnabled(false);
124: list.setTooltip(new LabelItem(
125: "disabled list with vetrical alignment\ndefault style",
126: WingSet.imgYawn));
127:
128: this .add(p3 = new WingPanel(new GridLayout(1, 0)));
129: p3.add(bAdd = new WingButton("add item"));
130: p3.add(bInsert = new WingButton("insert item"));
131: p3.add(bRemove = new WingButton("remove selected"));
132:
133: this .addActionListener(this );
134: this .addItemListener(this );
135: }
136:
137: static Object[] getItems() {
138: Object[] its = {
139: new LabelItem("text and icon 1", WingSet.imgSmile),
140: new LabelItem("text and icon 2", WingSet.imgGlasses),
141: new LabelItem("text and icon 3", WingSet.imgTongue),
142: new LabelItem("text and icon 4", WingSet.imgSilence),
143: "text item 1", "text item 2", WingSet.imgAngel,
144: WingSet.imgTired, "text item 3",
145: new ColorItem("color red", Color.red),
146: new ColorItem("color green", Color.green),
147: new ColorItem("color blue", Color.blue),
148: new ColorItem("color magenta", Color.magenta),
149: new ColorItem("color orange", Color.orange) };
150: return its;
151: }
152:
153: static void addItems(WingList list) {
154: Object[] its = getItems();
155: for (int i = 0; i < its.length; i++)
156: list.addItem(its[i]);
157: }
158:
159: static private Object makeItem() {
160: Object[] its = getItems();
161: return its[(int) (Math.random() * its.length)];
162: }
163:
164: public void actionPerformed(ActionEvent e) {
165: if (target == null)
166: target = list1;
167: Object src = e.getSource();
168: if (src == bAdd) {
169: target.addItem(makeItem());
170: } else if (src == bInsert) {
171: int i = target.getSelectedIndex();
172: if (i == -1)
173: i = 0;
174: target.insertItem(makeItem(), i);
175: } else if (src == bRemove) {
176: int i = target.getSelectedIndex();
177: if (i != -1)
178: target.removeItem(i);
179: }
180: }
181:
182: public void itemStateChanged(ItemEvent e) {
183: Object src = e.getSource();
184: if (src == list1)
185: target = list1;
186: else if (src == list2)
187: target = list2;
188: else if (src == list3)
189: target = list3;
190: }
191: }
|