001: /*
002: * @(#)QtPanelPeer.java 1.13 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027: package sun.awt.qt;
028:
029: import sun.awt.peer.*;
030: import java.awt.*;
031:
032: /**
033: * QtContainerPeer.java
034: *
035: * @author Nicholas Allen
036: */
037:
038: class QtPanelPeer extends QtContainerPeer implements PanelPeer {
039: private int numChildren = 0;
040:
041: QtPanelPeer(QtToolkit toolkit, Container target) {
042: super (toolkit, target);
043: }
044:
045: protected native void create(QtComponentPeer parentPeer);
046:
047: /*
048: * Fix for Bug ID 4778521, frame borders not repainting. See
049: * the native implementation for a lengthy explanatory comment.
050: */
051: public native void endValidate();
052:
053: final void add(QtComponentPeer peer) {
054: // If the component whose peer is being created is a direct
055: // child of this container (i.e., it is not a heavyweight
056: // inside a lightweight) then we need to determine the
057: // position to insert at.
058:
059: if (peer.target.getParent() == target) {
060: // Determine the Z order position of the component being added.
061:
062: Container container = (Container) target;
063: int numComponents = container.getComponentCount();
064:
065: for (int i = 0; i < numComponents; i++) {
066: Component component = container.getComponent(i);
067:
068: if (component == peer.target) {
069: insert(peer, i);
070: numChildren++;
071: return;
072: }
073: }
074: }
075:
076: // The peer is not a direct child so it must be in a
077: // lightweight hierarchy. We add the peer to the end of the
078: // list.
079:
080: else {
081: insert(peer, -1);
082: }
083: }
084:
085: final void remove(QtComponentPeer peer) {
086: if (peer.target.getParent() == target) {
087: numChildren--;
088: }
089: }
090:
091: /** Inserts the component's peer into this container at the
092: specified index. If the index is negative then the component
093: will be added at the end of the list. */
094:
095: private native void insert(QtComponentPeer peer, int index);
096:
097: protected boolean canHavePixmapBackground() {
098: return false;
099: }
100:
101: protected boolean shouldFocusOnClick() {
102: return ((Container) target).getComponentCount() == 0;
103: }
104:
105: }
|