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.wings;
022:
023: import java.awt.BorderLayout;
024: import java.awt.Container;
025: import java.awt.Dialog;
026: import java.awt.Dimension;
027: import java.awt.Frame;
028: import java.awt.Graphics;
029: import java.awt.IllegalComponentStateException;
030: import java.awt.Insets;
031: import java.awt.Point;
032: import java.awt.Toolkit;
033:
034: /**
035: * An extended version of <code>java.awt.Dialog</code> that adds support for
036: * the WingS component architecture.
037: * <code>WingDialog</code> contains a
038: * <code>WingRootPane</code> as its only child.<br>
039: * <br>
040: * <b>This class is thread safe.</b>
041: * @see WingRootPane
042: **/
043: public class WingDialog extends Dialog {
044: protected/*final*/WingRootPane root;
045:
046: /**
047: * Constructs an initially invisible, modeless <code>Dialog</code> with
048: * the specified owner <code>Frame</code> and an empty title.
049: *
050: * @param owner the owner of the dialog
051: */
052: public WingDialog(Frame owner) {
053: this (owner, false);
054: }
055:
056: /**
057: * Constructs an initially invisible <code>Dialog</code> with the specified
058: * owner <code>Frame</code> and modality and an empty title.
059: *
060: * @param owner the owner of the dialog or <code>null</code> if
061: * this dialog has no owner
062: * @param modal specifies whether dialog blocks user input to other top-level
063: * windows when shown. If <code>true</code> the dialog is modal
064: */
065: public WingDialog(Frame owner, boolean modal) {
066: super (owner, modal);
067: root = new WingRootPane();
068: this .add(root, BorderLayout.CENTER);
069: }
070:
071: /**
072: * Returns the rootPane object for this dialog.
073: * @see WingRootPane
074: */
075: public WingRootPane getRootPane() {
076: return root;
077: }
078:
079: /**
080: * Sets the contentPane for this dialog.
081: * @see WingRootPane#setContentPane(WingComponent)
082: * @param c the new content pane
083: */
084: public void setContentPane(WingComponent c) {
085: root.setContentPane(c);
086: }
087:
088: /**
089: * Sets the menu bar for this dialog.
090: * @param c the menu bar being placed in the dialog
091: */
092: public void setMenuBar(WingComponent c) {
093: root.setMenuBar(c);
094: }
095:
096: public void update(Graphics g) {
097: paint(g);
098: }
099:
100: public void paint(Graphics g) {
101: Insets insets = getInsets();
102: g.translate(insets.left, insets.top);
103: root.paint(g);
104: }
105:
106: public void packAndCenter(Container origin, int minWidth,
107: int minHeight) {
108: Dimension screenSize = Toolkit.getDefaultToolkit()
109: .getScreenSize();
110: int x = screenSize.width / 2, y = screenSize.height / 2;
111: if (origin != null) {
112: try {
113: Point los = origin.getLocationOnScreen();
114: Dimension osize = origin.getSize();
115: x = los.x + osize.width / 2;
116: y = los.y + osize.height / 2;
117: } catch (IllegalComponentStateException e) {
118: }
119: }
120: this .pack();
121: Dimension size = this .getSize();
122: int width = size.width, height = size.height;
123: if (width < minWidth)
124: width = minWidth;
125: if (height < minHeight)
126: height = minHeight;
127: if (width > screenSize.width)
128: width = screenSize.width;
129: if (height > screenSize.height)
130: height = screenSize.height;
131: x -= width / 2;
132: y -= height / 2;
133: if (x < 0)
134: x = 0;
135: if (y < 0)
136: y = 0;
137: if (x + width > screenSize.width)
138: x = screenSize.width - width;
139: if (y + height > screenSize.height)
140: y = screenSize.height - height;
141: this.setBounds(x, y, width, height);
142: }
143: }
|