01: package net.xoetrope.builder.editor.dialog;
02:
03: import net.xoetrope.awt.XButton;
04: import net.xoetrope.awt.XDialog;
05: import net.xoetrope.awt.XEdit;
06: import net.xoetrope.xui.helper.BuddyHelper;
07: import net.xoetrope.xui.style.XStyleFactory;
08: import net.xoetrope.xui.XPage;
09:
10: /**
11: * A dialog for capturing page size information
12: * <p>Copyright: Copyright (c) Xoetrope Ltd., 2002-2003</p>
13: * @version $Revision: 1.6 $
14: */
15:
16: public class XPageSizeDialog extends XDialog {
17: protected XEdit wField, hField;
18: protected XButton okBtn, cancelBtn;
19: protected boolean okStatus = false;
20:
21: public XPageSizeDialog(int w, int h) {
22: super (true, 2);
23:
24: setSize(240, 120);
25:
26: okBtn = (XButton) componentFactory.addComponent(XPage.BUTTON,
27: 20, 90, 100, 20, "Ok", "XButton");
28: cancelBtn = (XButton) componentFactory.addComponent(
29: XPage.BUTTON, 130, 90, 100, 20, "Cancel", "XButton");
30:
31: BuddyHelper buddy = new BuddyHelper(
32: (XStyleFactory) componentFactory);
33: wField = (XEdit) buddy.addComponent(XPage.EDIT, 10, 100, 20,
34: 210, 20, "Width:", "240", null);
35: hField = (XEdit) buddy.addComponent(XPage.EDIT, 10, 100, 50,
36: 210, 20, "Height:", "320", null);
37: wField.setText(new Integer(w).toString());
38: hField.setText(new Integer(h).toString());
39:
40: addMouseHandler(okBtn, "okClicked");
41: addMouseHandler(cancelBtn, "cancelClicked");
42: }
43:
44: /**
45: * Dismiss the dialog and mark the input as OK
46: */
47: public void okClicked() {
48: if (wasMouseClicked()) {
49: setVisible(false);
50: okStatus = true;
51: }
52: }
53:
54: /**
55: * Dismiss the dialog and clear the input
56: */
57: public void cancelClicked() {
58: if (wasMouseClicked()) {
59: wField.setText("");
60: hField.setText("");
61: setVisible(false);
62: }
63: }
64:
65: /**
66: * Get the content of the width input field.
67: * @return the width
68: */
69: public int getPageWidth() {
70: return Math.max(10, new Integer(wField.getText()).intValue());
71: }
72:
73: /**
74: * Get the content of the height input field.
75: * @return the page height
76: */
77: public int getPageHeight() {
78: return Math.max(10, new Integer(hField.getText()).intValue());
79: }
80:
81: /**
82: * Check if the dialog's OK button was clicked
83: * @return true if OK was clicked or otherwise false
84: */
85: public boolean isOk() {
86: return okStatus;
87: }
88: }
|