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.GridLayout;
028: import java.awt.Insets;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ItemEvent;
031: import java.awt.event.ItemListener;
032: import com.javujavu.javux.wings.WingCheckBox;
033: import com.javujavu.javux.wings.WingLabel;
034: import com.javujavu.javux.wings.WingPanel;
035: import com.javujavu.javux.wings.WingProgress;
036: import com.javujavu.javux.wings.WingTimer;
037:
038: public class ProgressPanel extends WingPanel implements ItemListener {
039: private WingProgress p1;
040: private WingProgress p2;
041: private WingProgress p3;
042: private WingProgress p4;
043: private WingCheckBox cbRunLeft;
044: private int v;
045: // private Thread thread;
046: private WingTimer timer;
047: private WingProgress p21;
048: private WingProgress p22;
049: private WingProgress p23;
050: private WingCheckBox cbRunRight;
051: private WingProgress p5;
052: private WingProgress p24;
053: private WingProgress p25;
054:
055: public ProgressPanel(WingSetPanel owner) {
056: this .setLayout(new GridBagLayout());
057:
058: timer = new WingTimer(100, true, this , false);
059:
060: WingPanel panel = new WingPanel(new GridLayout(0, 2, 8, 8));
061: GridBagConstraints c = new GridBagConstraints();
062: c.insets = new Insets(10, 10, 10, 10);
063: c.anchor = GridBagConstraints.CENTER;
064: c.fill = GridBagConstraints.BOTH;
065: c.weightx = 1.0;
066: c.weighty = 1.0;
067: this .add(panel, c);
068:
069: WingPanel left, leftAll;
070: panel.add(leftAll = new WingPanel(new BorderLayout()));
071: leftAll.add(left = new WingPanel(new GridBagLayout()),
072: BorderLayout.CENTER);
073: left.setStyleId("border1");
074:
075: c = new GridBagConstraints();
076: c.insets = new Insets(2, 2, 0, 2);
077: c.gridwidth = GridBagConstraints.REMAINDER;
078: left.add(new WingLabel("horizontal WingProgress"), c);
079: left.add(p1 = new WingProgress(HORIZONTAL), c);
080: left.add(new WingLabel("with text"), c);
081: left.add(p2 = new WingProgress(HORIZONTAL), c);
082: p2.setText("progress text");
083: left.add(new WingLabel("with empty text"), c);
084: left.add(p3 = new WingProgress(HORIZONTAL), c);
085: p3.setText("");
086: left.add(new WingLabel("styleID= noimage"), c);
087: left.add(p4 = new WingProgress(HORIZONTAL), c);
088: p4.setStyleId("noimage");
089: left.add(new WingLabel("prefferedSize= 150,8"), c);
090: left.add(p5 = new WingProgress(HORIZONTAL), c);
091: p5.setText("");
092: p5.setPreferredSize(new Dimension(150, 8));
093: c.insets = new Insets(6, 2, 6, 2);
094: left.add(cbRunLeft = new WingCheckBox("Run", TOGGLE), c);
095: cbRunLeft.setSelected(true);
096:
097: WingPanel right, rightAll;
098: panel.add(rightAll = new WingPanel(new BorderLayout()));
099: rightAll.add(right = new WingPanel(new GridBagLayout()),
100: BorderLayout.CENTER);
101: right.setStyleId("border1");
102:
103: c.insets = new Insets(6, 5, 6, 5);
104: c.gridwidth = 1;
105: right.add(p21 = new WingProgress(VERTICAL), c);
106: right.add(p22 = new WingProgress(VERTICAL), c);
107: p22.setText("");
108: right.add(p23 = new WingProgress(VERTICAL), c);
109: p23.setText("long text");
110: right.add(p24 = new WingProgress(VERTICAL), c);
111: p24.setText("");
112: p24.setPreferredSize(new Dimension(8, 150));
113: c.gridwidth = GridBagConstraints.REMAINDER;
114: right.add(p25 = new WingProgress(VERTICAL), c);
115: p25.setText("");
116: p25.setPreferredSize(new Dimension(12, 50));
117: right.add(cbRunRight = new WingCheckBox("Run", TOGGLE), c);
118: cbRunRight.setSelected(true);
119:
120: this .addItemListener(this );
121: }
122:
123: public void addNotify() {
124: super .addNotify();
125: timer.start();
126: }
127:
128: public void itemStateChanged(ItemEvent e) {
129: if (e.getSource() == cbRunLeft || e.getSource() == cbRunRight) {
130: if (!cbRunLeft.isSelected() && !cbRunRight.isSelected())
131: timer.stop();
132: else
133: timer.start();
134: }
135: }
136:
137: public void wingProcessActionEvent(ActionEvent e) {
138: if (e.getSource() == timer) {
139: if (isVisible()) {
140: v = (v + 1) % 220;
141: int sv = (v <= 100) ? v
142: : (v >= 110 && v <= 210) ? (210 - v) : -1;
143: if (sv != -1 && cbRunLeft.isSelected()) {
144: p1.setValue(sv);
145: p2.setValue(sv);
146: p3.setValue(sv);
147: p4.setValue(sv);
148: p5.setValue(sv);
149: }
150: if (sv != -1 && cbRunRight.isSelected()) {
151: p21.setValue(sv);
152: p22.setValue(sv);
153: p23.setValue(sv);
154: p24.setValue(sv);
155: p25.setValue(sv);
156: }
157: }
158: } else
159: super.wingProcessActionEvent(e);
160: }
161: }
|