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.Dimension;
024: import java.awt.Font;
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.ItemEvent;
030: import com.javujavu.javux.wings.Style;
031: import com.javujavu.javux.wings.WingButton;
032: import com.javujavu.javux.wings.WingCheckBox;
033: import com.javujavu.javux.wings.RadioGroup;
034: import com.javujavu.javux.wings.WingFont;
035: import com.javujavu.javux.wings.WingPanel;
036: import com.javujavu.javux.wings.WingScrollPane;
037: import com.javujavu.javux.wings.WingSkin;
038: import com.javujavu.javux.wings.WingTextPane;
039: import com.javujavu.javux.wings.item.LabelItem;
040: import com.javujavu.javux.wings.text.BoxNode;
041: import com.javujavu.javux.wings.text.ImageNode;
042:
043: public class TextPanePanel extends WingPanel {
044: private WingCheckBox cbLeftNoWrap;
045: private WingCheckBox cbLeftWordWrap;
046: private WingCheckBox cbLeftLineWrap;
047: private WingCheckBox cbRightNoWrap;
048: private WingCheckBox cbRightWordWrap;
049: private WingCheckBox cbRightLineWrap;
050: private WingTextPane taLeft;
051: private WingTextPane taRight;
052:
053: public TextPanePanel(WingSetPanel owner) {
054: this .setLayout(new GridBagLayout());
055: GridBagConstraints c = new GridBagConstraints();
056: c.weightx = 1;
057: c.weighty = 1;
058: c.fill = GridBagConstraints.BOTH;
059: c.insets = new Insets(8, 8, 8, 8);
060:
061: c.gridwidth = GridBagConstraints.REMAINDER;
062: WingTextPane ta;
063: WingScrollPane sp;
064: this .add(sp = new WingScrollPane(ta = new WingTextPane()), c);
065: sp.setPreferredSize(new Dimension(800, 100));
066: sp.setHorizontalScrollBarPolicy(WingScrollPane.SCROLLBAR_NEVER);
067: setText(ta, 1);
068:
069: c.insets = new Insets(0, 8, 8, 8);
070: c.gridwidth = 1;
071: this .add(sp = new WingScrollPane(ta = new WingTextPane()), c);
072: sp.setPreferredSize(new Dimension(400, 100));
073: ta.setEditable(false);
074: setText(ta, 2);
075: c.insets = new Insets(0, 0, 8, 8);
076: c.gridwidth = GridBagConstraints.REMAINDER;
077: this .add(sp = new WingScrollPane(ta = new WingTextPane()), c);
078: sp.setPreferredSize(new Dimension(400, 100));
079: sp.setHorizontalScrollBarPolicy(WingScrollPane.SCROLLBAR_NEVER);
080: ta.setEnabled(false);
081: setText(ta, 3);
082:
083: c.insets = new Insets(0, 8, 8, 8);
084: c.gridwidth = 1;
085: this .add(sp = new WingScrollPane(ta = new WingTextPane()), c);
086: sp.setPreferredSize(new Dimension(400, 100));
087: setText(ta, 4);
088: taLeft = ta;
089: c.insets = new Insets(0, 0, 8, 8);
090: c.gridwidth = GridBagConstraints.REMAINDER;
091: c.anchor = GridBagConstraints.CENTER;
092: WingPanel p;
093: this .add(p = new WingPanel(new GridBagLayout()), c);
094: p.setPreferredSize(new Dimension(400, 100));
095: GridBagConstraints c2 = new GridBagConstraints();
096: c2.fill = GridBagConstraints.HORIZONTAL;
097: c2.weightx = 1.0;
098: p.add(ta = new WingTextPane(), c2);
099: setText(ta, 5);
100: taRight = ta;
101:
102: c.insets = new Insets(0, 8, 8, 8);
103: c.gridwidth = 1;
104: c.weighty = 0;
105: this .add(p = new WingPanel(new GridLayout(1, 0)), c);
106:
107: WingButton b;
108: p.add(b = new WingButton("TopStyle"));
109: b.setStyleId("vpopup");
110: b.setTextPosition(LEFT);
111: b.setFastAction(true);
112: b
113: .setTooltip(new LabelItem(
114: "modify TopStyle of this WingTextPane\nTopStyle is an extra style overriding stylesheet settings \ndynamically at run time\nclick button to change settings",
115: WingSet.imgIcon, LEFT, RIGHT));
116: new TopStyleEditor(b, taLeft, 0, 0, false);
117:
118: p.add(cbLeftNoWrap = new WingCheckBox("no wrap", TOGGLE));
119: p.add(cbLeftWordWrap = new WingCheckBox("word wrap", TOGGLE));
120: p.add(cbLeftLineWrap = new WingCheckBox("line wrap", TOGGLE));
121: RadioGroup cg = new RadioGroup();
122: cg.add(cbLeftNoWrap);
123: cg.add(cbLeftWordWrap);
124: cg.add(cbLeftLineWrap);
125: cbLeftLineWrap.setSelected(true);
126: c.insets = new Insets(0, 0, 8, 8);
127: c.gridwidth = GridBagConstraints.REMAINDER;
128: this .add(p = new WingPanel(new GridLayout(1, 0)), c);
129: p.add(cbRightNoWrap = new WingCheckBox("no wrap", TOGGLE));
130: p.add(cbRightWordWrap = new WingCheckBox("word wrap", TOGGLE));
131: p.add(cbRightLineWrap = new WingCheckBox("line wrap", TOGGLE));
132: cg = new RadioGroup();
133: cg.add(cbRightNoWrap);
134: cg.add(cbRightWordWrap);
135: cg.add(cbRightLineWrap);
136: cbRightLineWrap.setSelected(true);
137: }
138:
139: protected static void setText(WingTextPane ta, int area) {
140:
141: if (area != 1) {
142: ta.append(new BoxNode(WingSkin.getStyle(null,
143: "wingsetdemo.text1", null), RIGHT));
144: ta
145: .insert(
146: -2,
147: // area==1 ? "text wrap"
148: area == 2 ? "readonly"
149: : area == 3 ? "disabled"
150: : area == 4 ? "choose text wrap below"
151: : area == 5 ? "no scroll pane"
152: : area == 6 ? "WingTextPane as tooltip"
153: : area == 7 ? "Scenario of movie: whatever"
154: : "",
155: null);
156: }
157: ta.append(new BoxNode(WingSkin.getStyle(null,
158: "wingsetdemo.text2", null)));
159: ta.insert(-2, new BoxNode(null, CENTER));
160: ta.insert(-3, " WingSetDemo ", WingSkin.getStyle(null,
161: "wingsetdemo.text3", null));
162: ta.insert(-3, " Episode2007");
163: ta.insert(-2, " Javu WingS\n", WingSkin.getStyle("green",
164: "wingsetdemo.text3", null));
165: ta.insert(-2, "Lightweight Java Component Set");
166: if (area == 5)
167: return;
168: ta.insert(-2, "\n\n");
169: if (area == 7)
170: return;
171: ta.insert(-2, new ImageNode(WingSet.imgGlasses, "8-)", null));
172: ta.insert(-2, " Keyboard shortcuts:\n\tCtrl-Insert or Ctrl-C ");
173: ta.insert(-2, new ImageNode(WingSet.imgSmile, ":-)", null));
174: ta.insert(-2, " Copy\n\tShift-Insert or Ctrl-V ");
175: ta.insert(-2, new ImageNode(WingSet.imgJokingly, ":-)", null));
176: ta.insert(-2, " Paste\n\tShift-Delete or Ctrl-X ");
177: ta.insert(-2, new ImageNode(WingSet.imgTongue, ":-P", null));
178: ta.insert(-2, " Cut\n\tCtrl-A ");
179: ta.insert(-2, new ImageNode(WingSet.imgSilence, ":-X", null));
180: ta.insert(-2, " Select All\n\n");
181:
182: ta
183: .insert(-2,
184: "WingFont styles: (antialiasing works under Java>=1.2)\n");
185: for (int i = 0; i < 21; i++) {
186: boolean bold;
187: boolean italic;
188: boolean underline;
189: boolean antialias;
190: int k = i - 5;
191: if (k >= 0) {
192: bold = ((k & 1) != 0);
193: italic = ((k & 2) != 0);
194: underline = ((k & 4) != 0);
195: antialias = ((k & 8) != 0);
196: } else {
197: bold = (i == 1);
198: italic = (i == 2);
199: underline = (i == 3);
200: antialias = (i == 4);
201: }
202: Style st = new Style();
203: int style = Font.PLAIN;
204: if (bold)
205: style |= Font.BOLD;
206: if (italic)
207: style |= Font.ITALIC;
208: st.font = new WingFont("Dialog", style, 14, underline,
209: antialias);
210: StringBuffer s = new StringBuffer();
211: s.append("font");
212: if (k == 0 || i == 0)
213: s.append(" plain");
214: if (bold)
215: s.append(" bold");
216: if (italic)
217: s.append(" italic");
218: if (underline)
219: s.append(" underline");
220: if (antialias)
221: s.append(" antialiasing");
222: s.append(" abcdef ABCDEF 12345 ;-)\n");
223: if (k == -1)
224: s.append("\n");
225: ta.insert(-2, s.toString(), st);
226:
227: }
228: ta.insert(-2, "\n");
229:
230: ta.append(new BoxNode(WingSkin.getStyle(null,
231: "wingsetdemo.text1", null), CENTER));
232: ta.insert(-2, "Animated icon ");
233: ta.insert(-2,
234: new ImageNode(WingSet.imgAnim, "[animated]", null));
235: if (area == 6)
236: return;
237: ta.append("\n\n");
238: for (int i = 0; i < 10; i++)
239: ta.append("very long line ");
240: ta.append("\n\n");
241: for (int i = 0; i < 5; i++)
242: ta.append("VeryLongWord");
243: ta.append("\n\n");
244: ta.setCaretPosition(0);
245: }
246:
247: public void wingProcessItemEvent(ItemEvent e) {
248: Object src = e.getSource();
249: if (e.getStateChange() == ItemEvent.SELECTED) {
250: if (src == cbLeftNoWrap || src == cbLeftWordWrap
251: || src == cbLeftLineWrap) {
252: taLeft.setWrap((src == cbLeftNoWrap) ? NO_WRAP
253: : (src == cbLeftWordWrap) ? WORD_WRAP
254: : LINE_WRAP);
255: } else if (src == cbRightNoWrap || src == cbRightWordWrap
256: || src == cbRightLineWrap) {
257: taRight.setWrap((src == cbRightNoWrap) ? NO_WRAP
258: : (src == cbRightWordWrap) ? WORD_WRAP
259: : LINE_WRAP);
260: }
261: }
262: }
263: }
|