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.Dimension;
025: import java.awt.GridBagConstraints;
026: import java.awt.GridBagLayout;
027: import java.awt.Insets;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import java.awt.event.AdjustmentEvent;
031: import java.awt.event.AdjustmentListener;
032: import java.awt.event.ItemEvent;
033: import java.awt.event.ItemListener;
034: import com.javujavu.javux.wings.RadioGroup;
035: import com.javujavu.javux.wings.WingCheckBox;
036: import com.javujavu.javux.wings.WingLabel;
037: import com.javujavu.javux.wings.WingPanel;
038: import com.javujavu.javux.wings.WingScroll;
039: import com.javujavu.javux.wings.WingScrollPane;
040: import com.javujavu.javux.wings.WingSpinner;
041: import com.javujavu.javux.wings.WingSplitPane;
042: import com.javujavu.javux.wings.WingTextPane;
043: import com.javujavu.javux.wings.item.LabelItem;
044:
045: public class ScrollbarPanel extends WingPanel implements ItemListener,
046: ActionListener, AdjustmentListener {
047: private WingSpinner[] spValue = new WingSpinner[4];
048: private WingSpinner[] spExtent = new WingSpinner[4];
049: private WingSpinner[] spMinimum = new WingSpinner[4];
050: private WingSpinner[] spMaximum = new WingSpinner[4];
051: private WingScroll[] sb = new WingScroll[4];;
052: private WingCheckBox rbVAlways;
053: private WingCheckBox rbVAsNeeded;
054: private WingCheckBox rbVNever;
055: private WingCheckBox rbHAlways;
056: private WingCheckBox rbHAsNeeded;
057: private WingCheckBox rbHNever;
058: private WingScrollPane scrollPane;
059: private WingCheckBox rbWrapNone;
060: private WingCheckBox rbWrapWord;
061: private WingCheckBox rbWrapLine;
062: private WingTextPane textPane;
063:
064: public ScrollbarPanel(WingSetPanel owner) {
065: this .setLayout(new GridBagLayout());
066: WingSplitPane sp = new WingSplitPane(HORIZONTAL);
067: GridBagConstraints c = new GridBagConstraints();
068: c.insets = new Insets(10, 10, 10, 10);
069: c.anchor = GridBagConstraints.CENTER;
070: c.fill = GridBagConstraints.BOTH;
071: c.weightx = 1.0;
072: c.weighty = 1.0;
073: this .add(sp, c);
074: sp.setResizeWeight(0.5);
075: WingPanel p = new WingPanel(new BorderLayout());
076: p.setPreferredSize(new Dimension(200, 200));
077: sp.setLeftComponent(p);
078: p.add(sb[0] = new WingScroll(HORIZONTAL), BorderLayout.NORTH);
079: p.add(sb[1] = new WingScroll(HORIZONTAL, 10, 10, 5, 110),
080: BorderLayout.SOUTH);
081: sb[1].setStyleId("custom_scroll");
082: p.add(sb[2] = new WingScroll(VERTICAL, 2, 1, 0, 5),
083: BorderLayout.WEST);
084: p.add(sb[3] = new WingScroll(VERTICAL), BorderLayout.EAST);
085: sb[0].setValues(50, 10, 0, 110);
086: // sb2.setValues(10,10,5,110);
087: // sb3.setValues(2, 1, 0, 5);
088: sb[3].setValues(700, 10, 0, 1100);
089: WingPanel p2 = new WingPanel(new GridBagLayout());
090: p.add(p2);
091: c = new GridBagConstraints();
092: c.insets = new Insets(1, 1, 1, 1);
093: c.gridwidth = 1;
094: p2.add(new WingLabel(""), c);
095: p2.add(new WingLabel("value"), c);
096: p2.add(new WingLabel("extent"), c);
097: p2.add(new WingLabel("minimum"), c);
098: c.gridwidth = GridBagConstraints.REMAINDER;
099: p2.add(new WingLabel("maximum"), c);
100: for (int i = 0; i < 4; i++) {
101: c.gridwidth = 1;
102: c.weightx = 0;
103: p2.add(new WingLabel(i == 0 ? "top" : i == 1 ? "bottom"
104: : i == 2 ? "left" : "right"), c);
105: c.weightx = 1.0;
106: p2.add(spValue[i] = new WingSpinner(), c);
107: p2.add(spExtent[i] = new WingSpinner(), c);
108: p2.add(spMinimum[i] = new WingSpinner(), c);
109: c.gridwidth = GridBagConstraints.REMAINDER;
110: p2.add(spMaximum[i] = new WingSpinner(), c);
111: }
112: String s = "\n\nScrolling with MOUSE WHEEL works on Java>=1.4";
113: sb[0].setTooltip(new LabelItem(
114: "WingScroll orientation HORIZONTAL\ndefault style" + s,
115: WingSet.imgCrying));
116: sb[1]
117: .setTooltip(new LabelItem(
118: "WingScroll orientation HORIZONTAL\nstyle: custom_scroll (stylesheet wingsetdemo.ini)"
119: + s, WingSet.imgConfused));
120: sb[2].setTooltip(new LabelItem(
121: "WingScroll orientation VERTICAL\ndefault style" + s,
122: WingSet.imgUgly));
123: sb[3].setTooltip(new LabelItem(
124: "WingScroll orientation VERTICAL\ndefault style" + s,
125: WingSet.imgTired));
126:
127: for (int i = 0; i < 4; i++) {
128: sb[i].addAdjustmentListener(this );
129: sb[i].addAdjustmentListener(owner.eventTracer);
130: }
131:
132: WingSplitPane sp2;
133: sp.setRightComponent(sp2 = new WingSplitPane(VERTICAL));
134: sp2.setResizeWeight(0.5);
135: sp2.setTopComponent(scrollPane = new WingScrollPane(
136: textPane = new WingTextPane()));
137: scrollPane.setPreferredSize(new Dimension(100, 100));
138: textPane.setText("WingTextPane inside WingScrollPane\n");
139: textPane.append("set ScrollBarPolicy below\n\n");
140: textPane.append("\n\n");
141: for (int i = 0; i < 7; i++)
142: textPane.append(" 123456789");
143: textPane.append("\n\n");
144: for (int i = 0; i < 6; i++)
145: textPane.append("123456789");
146: textPane.append("\n\n");
147: textPane.setWrap(NO_WRAP);
148:
149: textPane.setTooltip(new LabelItem(
150: "WingTextPane inside WingScrollPane\nset scrollbar policy and text wrap below"
151: + s, WingSet.imgSmile));
152:
153: WingScrollPane sc2;
154: sp2.setBottomComponent(sc2 = new WingScrollPane(
155: p2 = new WingPanel(new GridBagLayout()), false));
156: sc2.setPreferredSize(new Dimension(100, 100));
157:
158: c = new GridBagConstraints();
159: c.fill = GridBagConstraints.HORIZONTAL;
160: c.gridy = 0;
161: c.insets = new Insets(1, 1, 1, 1);
162: c.gridwidth = 2;
163: p2.add(new WingLabel("scrollbar policy", CENTER), c);
164: c.gridwidth = 1;
165: c.gridy++;
166: p2.add(new WingLabel("vertical", CENTER), c);
167: p2.add(new WingLabel("horizontal", CENTER), c);
168: p2.add(new WingLabel("text wrap", CENTER), c);
169: c.gridy++;
170: p2.add(rbVAlways = new WingCheckBox("always", RADIO), c);
171: p2.add(rbHAlways = new WingCheckBox("always", RADIO), c);
172: p2.add(rbWrapNone = new WingCheckBox("none", RADIO), c);
173: c.gridy++;
174: p2.add(rbVAsNeeded = new WingCheckBox("as needed", RADIO), c);
175: p2.add(rbHAsNeeded = new WingCheckBox("as needed", RADIO), c);
176: p2.add(rbWrapWord = new WingCheckBox("word wrap", RADIO), c);
177: c.gridy++;
178: p2.add(rbVNever = new WingCheckBox("never", RADIO), c);
179: p2.add(rbHNever = new WingCheckBox("never", RADIO), c);
180: p2.add(rbWrapLine = new WingCheckBox("line wrap", RADIO), c);
181:
182: RadioGroup g = new RadioGroup();
183: g.add(rbVAlways);
184: g.add(rbVAsNeeded);
185: g.add(rbVNever);
186: rbVAsNeeded.setSelected(true);
187:
188: g = new RadioGroup();
189: g.add(rbHAlways);
190: g.add(rbHAsNeeded);
191: g.add(rbHNever);
192: rbHAsNeeded.setSelected(true);
193:
194: g = new RadioGroup();
195: g.add(rbWrapNone);
196: g.add(rbWrapLine);
197: g.add(rbWrapWord);
198: rbWrapNone.setSelected(true);
199:
200: this .addItemListener(this );
201: this .addActionListener(this );
202:
203: for (int i = 0; i < 4; i++)
204: updateValues(sb[i]);
205: }
206:
207: public void actionPerformed(ActionEvent e) {
208: Object src = e.getSource();
209: for (int i = 0; i < 4; i++) {
210: if (src == spValue[i] || src == spExtent[i]
211: || src == spMinimum[i] || src == spMaximum[i]) {
212: sb[i].setValues(spValue[i].getValue(), spExtent[i]
213: .getValue(), spMinimum[i].getValue(),
214: spMaximum[i].getValue());
215: updateValues(sb[i]);
216: }
217: }
218: }
219:
220: public void adjustmentValueChanged(AdjustmentEvent e) {
221: updateValues((WingScroll) e.getSource());
222: }
223:
224: private void updateValues(WingScroll sb) {
225: for (int i = 0; i < 4; i++) {
226: if (sb == this .sb[i]) {
227: spValue[i].setValue(sb.getValue());
228: spExtent[i].setValue(sb.getVisibleAmount());
229: spMaximum[i].setValue(sb.getMaximum());
230: spMinimum[i].setValue(sb.getMinimum());
231: }
232: }
233: }
234:
235: public void itemStateChanged(ItemEvent e) {
236: Object src = e.getSource();
237: int policy = (src == rbHAlways || src == rbVAlways) ? SCROLLBAR_ALWAYS
238: : (src == rbHNever || src == rbVNever) ? SCROLLBAR_NEVER
239: : SCROLLBAR_AS_NEEDED;
240: if (src == rbHAlways || src == rbHAsNeeded || src == rbHNever) {
241: scrollPane.setHorizontalScrollBarPolicy(policy);
242: } else if (src == rbVAlways || src == rbVAsNeeded
243: || src == rbVNever) {
244: scrollPane.setVerticalScrollBarPolicy(policy);
245: } else if (src == rbWrapNone || src == rbWrapWord
246: || src == rbWrapLine) {
247: textPane
248: .setWrap((rbWrapNone.isSelected()) ? NO_WRAP
249: : (rbWrapWord.isSelected()) ? WORD_WRAP
250: : LINE_WRAP);
251: }
252: }
253: }
|