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.applet.Applet;
024: import java.awt.BorderLayout;
025: import java.awt.Component;
026: import java.awt.Frame;
027: import java.awt.Graphics;
028: import java.awt.Insets;
029: import java.awt.event.FocusEvent;
030:
031: /**
032: * An extended version of <code>java.applet.Applet</code> that adds support for
033: * the WingS component architecture.
034: * <code>WingApplet</code> contains a
035: * <code>WingRootPane</code> as its only child.<br>
036: * <br>
037: * <b>This class is thread safe.</b>
038: * @see WingRootPane
039: **/
040: public class WingApplet extends Applet {
041: protected final WingRootPane root;
042:
043: /**
044: * Creates an applet instance.
045: */
046: public WingApplet() {
047: setLayout(new BorderLayout());
048: root = new WingRootPane();
049: removeAll();
050: add(root, BorderLayout.CENTER);
051: }
052:
053: /**
054: * Returns the rootPane object for this applet.
055: * @see WingRootPane
056: */
057: public WingRootPane getRootPane() {
058: return root;
059: }
060:
061: /**
062: * Sets the contentPane for this applet.
063: * @see WingRootPane#setContentPane(WingComponent)
064: * @param c the new content pane
065: */
066: public void setContentPane(WingComponent c) {
067: root.setContentPane(c);
068: }
069:
070: /**
071: * Sets the menu bar for this applet.
072: * @param c the menu bar being placed in the applet
073: */
074: public void setMenuBar(WingComponent c) {
075: root.setMenuBar(c);
076: }
077:
078: public void update(Graphics g) {
079: paint(g);
080: }
081:
082: public void paint(Graphics g) {
083: fixFocus();
084:
085: Insets insets = getInsets();
086: g.translate(insets.left, insets.top);
087: root.paint(g);
088: }
089:
090: /**
091: * fixes unix focus bug
092: */
093: private boolean fixed;
094:
095: private void fixFocus() {
096: if (fixed)
097: return;
098: fixed = true;
099:
100: Component p = getParent();
101: if (p != null) {
102: Component p2 = p.getParent();
103: if (p2 != null
104: && "sun.plugin.viewer.frame.XNetscapeEmbeddedFrame"
105: .equals(p2.getClass().getName())) {
106: System.out.println("unix focus fix");
107:
108: final WingWindow splash = new WingWindow((Frame) p2);
109: WingButton b = new WingButton("Start") {
110: public void processFocusEvent(FocusEvent e) {
111: splash.setVisible(false);
112: splash.dispose();
113: WingApplet.this .requestFocus();
114: }
115: };
116: splash.setContentPane(b);
117: splash.setSize(1, 1);
118: splash.setVisible(true);
119: b.requestFocus();
120: }
121: }
122:
123: }
124:
125: }
|