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.Dimension;
026: import java.awt.GridBagConstraints;
027: import java.awt.GridBagLayout;
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 java.awt.event.KeyEvent;
034: import com.javujavu.javux.wings.WingButton;
035: import com.javujavu.javux.wings.WingCheckBox;
036: import com.javujavu.javux.wings.WingCombo;
037: import com.javujavu.javux.wings.WingDialog;
038: import com.javujavu.javux.wings.WingLabel;
039: import com.javujavu.javux.wings.WingMenu;
040: import com.javujavu.javux.wings.WingPanel;
041: import com.javujavu.javux.wings.WingScrollPane;
042: import com.javujavu.javux.wings.WingTextField;
043: import com.javujavu.javux.wings.WingTextPane;
044: import com.javujavu.javux.wings.dialogs.WingMessageBox;
045: import com.javujavu.javux.wings.extra.ColorItem;
046: import com.javujavu.javux.wings.extra.WingFileDialog;
047: import com.javujavu.javux.wings.item.LabelItem;
048:
049: public class DialogsPanel extends WingPanel implements ActionListener {
050: private WingButton bOK;
051: private WingButton bYesNo;
052: private WingButton bYesNoCancel;
053: private WingButton bYesYesYes;
054: private WingTextField tfResult;
055: private WingButton bFields2x1;
056: private WingButton bFields1x2;
057: private WingButton bFields2x3;
058: private WingButton bFields3x2;
059: private WingButton bComplex1;
060: private WingButton bComplex2;
061: private WingButton bComplex3;
062: private WingButton bCustomStyle;
063: private WingButton[] bFile;
064: private WingTextField tfPath;
065: private WingDialog dlg;
066:
067: public DialogsPanel(WingSetPanel owner) {
068: this .setLayout(new GridBagLayout());
069: WingPanel panelAll, panel;
070: panelAll = new WingPanel(new BorderLayout());
071: panelAll.add(panel = new WingPanel(new GridBagLayout()),
072: BorderLayout.CENTER);
073: panel.setStyleId("border1");
074: GridBagConstraints c = new GridBagConstraints();
075: c.insets = new Insets(20, 20, 20, 20);
076: c.anchor = GridBagConstraints.CENTER;
077: c.fill = GridBagConstraints.BOTH;
078: c.weightx = 1.0;
079: c.weighty = 1.0;
080: this .add(panelAll, c);
081:
082: c = new GridBagConstraints();
083: c.insets = new Insets(8, 8, 8, 8);
084: // c.weighty= 1.0;
085: c.gridwidth = 1;
086: c.fill = GridBagConstraints.HORIZONTAL;
087: panel.add(bOK = new WingButton("OK"), c);
088: panel.add(bYesNo = new WingButton("Yes No"), c);
089: panel.add(bYesNoCancel = new WingButton("Yes No Cancel"), c);
090: c.gridwidth = GridBagConstraints.REMAINDER;
091: panel.add(bYesYesYes = new WingButton("Yes Yes Yes"), c);
092:
093: c.insets = new Insets(0, 8, 8, 8);
094: c.gridwidth = 1;
095: panel.add(bComplex1 = new WingButton("Complex 1"), c);
096: panel.add(bComplex2 = new WingButton("Complex 2"), c);
097: panel.add(bComplex3 = new WingButton("Popup Test"), c);
098: // panel.add(new WingLabel(), c);
099: c.gridwidth = GridBagConstraints.REMAINDER;
100: panel.add(bCustomStyle = new WingButton("Custom Style"), c);
101:
102: c.gridwidth = 1;
103: panel.add(bFields1x2 = new WingButton("Fields 1x2"), c);
104: panel.add(bFields2x1 = new WingButton("Fields 2x1"), c);
105: panel.add(bFields2x3 = new WingButton("Fields 2x3"), c);
106: c.gridwidth = GridBagConstraints.REMAINDER;
107: panel.add(bFields3x2 = new WingButton("Fields 3x2"), c);
108:
109: c.gridwidth = 2;
110: panel.add(new WingLabel("dialog result: ", RIGHT), c);
111: c.gridwidth = GridBagConstraints.REMAINDER;
112: panel.add(tfResult = new WingTextField(10), c);
113:
114: bFile = new WingButton[8];
115: c.gridwidth = 1;
116: panel.add(bFile[0] = new WingButton("File Open"), c);
117: panel.add(bFile[1] = new WingButton("File Save"), c);
118: panel.add(bFile[2] = new WingButton("Dir Open"), c);
119: c.gridwidth = GridBagConstraints.REMAINDER;
120: panel.add(bFile[3] = new WingButton("Dir Save"), c);
121:
122: c.gridwidth = 1;
123: panel.add(bFile[4] = new WingButton("Image Open"), c);
124: panel.add(bFile[5] = new WingButton("Image Save"), c);
125: panel.add(bFile[6] = new WingButton("File/Dir Open"), c);
126: c.gridwidth = GridBagConstraints.REMAINDER;
127: panel.add(bFile[7] = new WingButton("File/Dir Save"), c);
128:
129: c.gridwidth = 1;
130: panel.add(new WingLabel("path:"), c);
131: c.gridwidth = GridBagConstraints.REMAINDER;
132: panel.add(tfPath = new WingTextField(), c);
133:
134: this .addActionListener(this );
135:
136: if (WingSet.isApplet) {
137: for (int i = 0; i < bFile.length; i++) {
138: bFile[i].setEnabled(false);
139: }
140: tfPath.setEnabled(false);
141: tfPath.setText("File dialog is not for applets");
142: }
143: }
144:
145: public void loadSkin() {
146: super .loadSkin();
147: WingDialog dialog = dlg;
148: if (dialog != null)
149: updateSkin(dialog);
150: }
151:
152: public void actionPerformed(ActionEvent e) {
153: Object src = e.getSource();
154: WingMessageBox m = null;
155: if (src == bOK) {
156: m = new WingMessageBox(
157: getParentFrame(),
158: "OK Message Box",
159: new LabelItem("OK Message Box", WingSet.imgGlasses),
160: "OK", null, null);
161: } else if (src == bYesNo) {
162: m = new WingMessageBox(getParentFrame(),
163: "Yes No Message Box", new LabelItem(
164: "Yes No Message Box", WingSet.imgSad, LEFT,
165: LEFT), "Yes", "No", null);
166: } else if (src == bYesNoCancel) {
167: m = new WingMessageBox(getParentFrame(),
168: "Yes No Cancel Message Box", new LabelItem(
169: "Yes No Cancel Message Box",
170: WingSet.imgSeek), "Yes", "No", "Cancel");
171: } else if (src == bYesYesYes) {
172: m = new WingMessageBox(
173: getParentFrame(),
174: "Yes Yes Yes Message Box",
175: new LabelItem(
176: "Yes Yes Yes Message Box\nThere is only one country\nwhere this dialog can be useful ;-)",
177: WingSet.imgTongue), new LabelItem("Yes!",
178: WingSet.imgSmile), new LabelItem("Yes!",
179: WingSet.imgGnash), new LabelItem("Yes!",
180: WingSet.imgSad));
181: } else if (src == bFields1x2) {
182: Object[] content = {
183: new LabelItem("field 1,1", WingSet.imgCrying),
184: new LabelItem("field 1,2", WingSet.imgYawn) };
185: m = new WingMessageBox(getParentFrame(),
186: "Message Box Fields 1x2", content, "OK", null, null);
187: } else if (src == bFields2x1) {
188: Object[][] content = { {
189: new LabelItem("field 1,1", WingSet.imgCrying),
190: new LabelItem("field 2,1", WingSet.imgYawn) } };
191: m = new WingMessageBox(getParentFrame(),
192: "Message Box Fields 2x1", content, "Yes", "No",
193: null);
194: } else if (src == bFields2x3) {
195: Object[][] content = {
196: { new LabelItem("field 1,1", WingSet.imgCrying),
197: new LabelItem("field 2,1", WingSet.imgYawn) },
198: { new LabelItem("field 1,2", WingSet.imgAngel),
199: new LabelItem("field 2,2", WingSet.imgUgly) },
200: {
201: new LabelItem("field 1,3",
202: WingSet.imgConfused),
203: new LabelItem("field 2,3", WingSet.imgTired) } };
204: m = new WingMessageBox(getParentFrame(),
205: "Message Box Fields 2x3", content, "OK", null, null);
206: } else if (src == bFields3x2) {
207: Object[][] content = {
208: {
209: new LabelItem("field 1,1",
210: WingSet.imgCrying),
211: new LabelItem("field 2,1", WingSet.imgYawn),
212: new LabelItem("field 3,1", WingSet.imgAngel) },
213: {
214: new LabelItem("field 1,2", WingSet.imgUgly),
215: new LabelItem("field 2,2",
216: WingSet.imgConfused),
217: new LabelItem("field 3,2", WingSet.imgTired) } };
218: m = new WingMessageBox(getParentFrame(),
219: "Message Box Fields 3x2", content, "Yes", "No",
220: null);
221: } else if (src == bComplex1) {
222: WingScrollPane sp1;
223: WingScrollPane sp2;
224: WingTextPane ta;
225: Object[] content = {
226: new LabelItem("Movie Wizard", WingSet.imgJokingly,
227: CENTER, RIGHT), "Step 1 create characters",
228: sp1 = new WingScrollPane(TablePanel.makeTable()),
229: "Step 2 write scenario",
230: sp2 = new WingScrollPane(ta = new WingTextPane()) };
231: sp1.setPreferredSize(new Dimension(440, 120));
232: sp2.setPreferredSize(new Dimension(440, 120));
233: TextPanePanel.setText(ta, 7);
234: m = new WingMessageBox(null, getParentFrame(),
235: "Complex Message Box 1", content, "Approve",
236: "Disapprove", "Cancel", 5, false,
237: GridBagConstraints.HORIZONTAL,
238: GridBagConstraints.BOTH, LEFT);
239: } else if (src == bComplex2) {
240: WingCombo cb1, cb2, cb3, cb4;
241: Object[][] content = {
242: { new LabelItem("Character Wizard",
243: WingSet.imgGlasses, CENTER, RIGHT) },
244: { new WingLabel("Title:", RIGHT),
245: new WingTextField("Truman Show", 20) },
246: { new LabelItem("First Name:", null, RIGHT, LEFT),
247: cb1 = new WingCombo() },
248: { new WingLabel("Last Name:", RIGHT),
249: cb2 = new WingCombo(true) },
250: { new WingLabel("Belt:", RIGHT),
251: cb3 = new WingCombo() },
252: { new WingLabel("Icon:", RIGHT),
253: cb4 = new WingCombo() } };
254: TablePanel.fillCombo(cb1, 1);
255: TablePanel.fillCombo(cb2, 2);
256: TablePanel.fillCombo(cb3, 3);
257: TablePanel.fillCombo(cb4, 4);
258: m = new WingMessageBox(getParentFrame(),
259: "Complex Message Box 2", content, new LabelItem(
260: "Kill ", WingSet.imgAngel, CENTER, LEFT),
261: new LabelItem(" Spare", WingSet.imgThumbsup),
262: null);
263: } else if (src == bComplex3) {
264: WingCombo cb1, cb2;
265: final WingCheckBox cbLightPopups = new WingCheckBox(
266: "enable lightweight popups");
267: final WingCheckBox cbHeavyPopups = new WingCheckBox(
268: "enable heavyweight popups");
269: WingLabel l1;
270: WingMenu m2;
271: WingButton b;
272: final WingButton b2 = new WingButton("Another message box");
273: final WingButton b3 = new WingButton("Wild popup menu");
274: b3.setStyleId("vpopup");
275: WingPanel p2 = new WingPanel(new GridBagLayout());
276: p2.setStyleId("border1");
277: GridBagConstraints c = new GridBagConstraints();
278: c.insets = new Insets(5, 5, 5, 5);
279: c.weightx = 1;
280: c.fill = GridBagConstraints.HORIZONTAL;
281: c.gridwidth = GridBagConstraints.REMAINDER;
282: p2.add(new WingLabel(new LabelItem("Debug Settings:",
283: WingSet.imgStop)), c);
284: c.gridwidth = 1;
285: c.insets = new Insets(0, 5, 5, 5);
286: p2.add(cbLightPopups, c);
287: p2.add(cbHeavyPopups, c);
288:
289: Object[][] content = {
290: { new LabelItem("Popup window test",
291: WingSet.imgScared, CENTER, RIGHT) },
292: { l1 = new WingLabel(new LabelItem(
293: "Label with tooltip", WingSet.imgMusic)) },
294: { new LabelItem("Menu:", WingSet.imgBomb),
295: m2 = new WingMenu(HORIZONTAL) },
296: { new LabelItem("Combo:", WingSet.imgBomb),
297: cb1 = new WingCombo() },
298: {
299: new LabelItem("Editable Combo:",
300: WingSet.imgBomb),
301: cb2 = new WingCombo(true) },
302: { b = new WingButton("Button with popup menu") },
303: { b3, b2 }, { p2 } };
304: b.setStyleId("vpopup");
305: l1.setTooltip(new LabelItem("Label with tooltip",
306: WingSet.imgGlasses, LEFT, RIGHT));
307: m2.add(MenuPanel.makeSubs("Wild Submenus", 8));
308: WingMenu m3;
309: m2.add(m3 = new WingMenu("\u0332Very Long Menu",
310: KeyEvent.VK_V, KeyEvent.ALT_MASK));
311: for (int i = 1; i < 420; i++)
312: m3.add("Itemmmm.........................mmm " + i);
313: m2.add("item");
314: b.setFastAction(true);
315: b
316: .setTooltip(new LabelItem(
317: "button with a TopStyle\nTopStyle is an extra style overriding stylesheet settings \ndynamically at run time\nclick to change settings\n\nstyle: vmenu (stylesheet wingsetdemo.ini)",
318: WingSet.imgIcon, LEFT, RIGHT));
319: new TopStyleEditor(b, b, 18, 8, true);
320: TablePanel.fillCombo(cb1, 1);
321: TablePanel.fillCombo(cb2, 2);
322:
323: int ic1 = cb1.getItemCount(), ic2 = cb2.getItemCount();
324: for (int j = 0; j < 2; j++)
325: for (int i = 0, k = 20 + j * 80; i < k; i++) {
326: Color col = Color.getHSBColor((float) 1.0 / k * i,
327: (float) 0.9, (float) 0.8);
328: cb1.addItem(new ColorItem(ComboPanel.colorName(col)
329: + " "
330: + cb1.getItem(cb1.getItemCount() % ic1)
331: .toString(), col));
332: cb2.addItem(new ColorItem(cb2.getItem(
333: cb2.getItemCount() % ic2).toString()
334: + " " + ComboPanel.colorName(col), col));
335: }
336:
337: cbLightPopups.setSelected(lightPopups);
338: cbHeavyPopups.setSelected(heavyPopups);
339:
340: ItemListener l = new ItemListener() {
341: public void itemStateChanged(ItemEvent e) {
342: enablePopups(cbLightPopups.isSelected(),
343: cbHeavyPopups.isSelected());
344: }
345: };
346: cbLightPopups.addItemListener(l);
347: cbHeavyPopups.addItemListener(l);
348: b2.addActionListener(new ActionListener() {
349: public void actionPerformed(ActionEvent e) {
350: WingCombo cb21;
351: Object[] content2 = {
352: new LabelItem("Another Message Box",
353: WingSet.imgSad, LEFT, LEFT),
354: cb21 = new WingCombo() };
355: TablePanel.fillCombo(cb21, 1);
356: int ic21 = cb21.getItemCount();
357: for (int j = 0; j < 2; j++)
358: for (int i = 0, k = 20 + j * 80; i < k; i++) {
359: Color col = Color.getHSBColor((float) 1.0
360: / k * i, (float) 0.9, (float) 0.8);
361: cb21.addItem(new ColorItem(ComboPanel
362: .colorName(col)
363: + " "
364: + cb21.getItem(
365: cb21.getItemCount() % ic21)
366: .toString(), col));
367: }
368:
369: WingMessageBox m4 = new WingMessageBox(b2
370: .getParentFrame(), "Another Message Box",
371: content2, "Yes", "No", null);
372: m4.showMessage(b2);
373: }
374: });
375: b3.addActionListener(new ActionListener() {
376: public void actionPerformed(ActionEvent e) {
377: if (e.getSource() == b3) {
378: WingMenu m5 = MenuPanel.makeSubs(
379: "Wild Submenus", 8);
380: Dimension s = b3.getSize();
381: m5.showPopup(b3, 0, 0, s.width, s.height,
382: HORIZONTAL);
383: }
384: }
385: });
386: m = new WingMessageBox(getParentFrame(),
387: "Complex Message Box - Popup Test", content, "Yes",
388: "No", "Cancel");
389: } else if (src == bCustomStyle) {
390: m = new WingMessageBox(
391: "custom_mbox",
392: getParentFrame(),
393: "Custom Style Message Box",
394: new LabelItem(
395: "Custom Style Message Box\nStyleID: custom_mbox (stylesheet wingsetdemo.ini)",
396: WingSet.imgBigsmileA, LEFT, LEFT), " Yes ",
397: " No ", null, 10, true,
398: GridBagConstraints.HORIZONTAL,
399: GridBagConstraints.BOTH, LEFT);
400: } else {
401: int i;
402: for (i = 0; i < bFile.length; i++) {
403: if (src == bFile[i])
404: break;
405: }
406: if (i < bFile.length) {
407: WingFileDialog d = new WingFileDialog(getParentFrame());
408: d.setPath(tfPath.getText());
409: int type = 0;
410: if (i < 2 || i > 3)
411: type |= WingFileDialog.FILE;
412: if ((i / 2) % 2 == 1)
413: type |= WingFileDialog.DIRECTORY;
414: if (i % 2 == 0)
415: type |= WingFileDialog.EXISTING;
416: Object[][] filters = null;
417: if (i / 2 == 2) {
418: filters = new Object[][] {
419: {
420: "Image File (*.jpeg;*.jpg;*.gif;*.png)",
421: new String[] { ".jpeg", ".jpg",
422: ".gif", ".png" } },
423: { "JPEG Image File (*.jpeg;*.jpg)",
424: new String[] { ".jpeg", ".jpg" } },
425: { "GIF Image File (*.gif)", ".gif" },
426: { "PNG Image File (*.png)", ".png" },
427: { "All files (*.*)", null } };
428: }
429: String open = (i % 2 == 0) ? "Open" : "Save";
430: String s = open
431: + ((i / 2 == 0) ? " File"
432: : (i / 2 == 1) ? " Dir"
433: : (i / 2 == 2) ? " Image"
434: : " File/Dir");
435: dlg = d;
436: boolean r = d.showDialog(this , type, filters,
437: new String[] { s, open });
438: dlg = null;
439:
440: tfResult.setText((r) ? open.toUpperCase() : "CANCEL");
441:
442: if (r) {
443: tfPath.setText(d.getPath());
444: }
445: }
446: }
447:
448: if (m != null) {
449: dlg = m;
450: int r = m.showMessage(this );
451: dlg = null;
452: tfResult.setText((r == WingMessageBox.OKYES) ? "OKYES"
453: : (r == WingMessageBox.NO) ? "NO"
454: : (r == WingMessageBox.CANCEL) ? "CANCEL"
455: : null);
456: }
457: }
458:
459: }
|