001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.gsfret.navigation.base;
043:
044: import java.awt.*;
045:
046: /**
047: * This file is originally from Retouche, the Java Support
048: * infrastructure in NetBeans. I have modified the file as little
049: * as possible to make merging Retouche fixes back as simple as
050: * possible.
051: * <p>
052: * Trivial layout manager class used by the panels for selecting look and filter. Simply uses the preferred size of the
053: * first compnent and fills the rest of the space with the second, to the height of the tallest.
054: *
055: * @author Tim Boudreau
056: */
057: final class TrivialLayout implements LayoutManager {
058: public void addLayoutComponent(String name, Component comp) {
059: //do nothing
060: }
061:
062: public void removeLayoutComponent(Component comp) {
063: //do nothing
064: }
065:
066: public void layoutContainer(Container parent) {
067: if (parent instanceof TapPanel) {
068: layoutTapPanel((TapPanel) parent);
069: } else {
070: layoutComp(parent);
071: }
072: }
073:
074: /**
075: * Standard layout for any container
076: */
077: private void layoutComp(Container parent) {
078: Component[] c = parent.getComponents();
079: if (c.length > 1) {
080: Dimension d1 = c[0].getPreferredSize();
081: Dimension d2 = c[1].getPreferredSize();
082: int labely = 0;
083: d1.width += 10; //Aqua displays elipsis
084: if (d2.height > d1.height) {
085: labely = (d2.height / 2) - (d1.height / 2);
086: }
087: if (parent.getWidth() - d1.width < d2.width) {
088: c[0].setBounds(0, 0, 0, 0);
089: c[1].setBounds(0, 0, parent.getWidth(), parent
090: .getHeight());
091: } else {
092: c[0].setBounds(0, labely, d1.width, d1.height);
093: c[1].setBounds(d1.width + 1, 0, parent.getWidth()
094: - d1.width, Math.min(parent.getHeight(),
095: d2.height));
096: }
097: }
098: }
099:
100: /**
101: * Layout for TapPanel, taking into account its minimumHeight
102: */
103: private void layoutTapPanel(TapPanel tp) {
104: Component[] c = tp.getComponents();
105: if (c.length > 1) {
106: Dimension d1 = c[0].getPreferredSize();
107: Dimension d2 = c[1].getPreferredSize();
108: int labely = 0;
109: if (d2.height > d1.height) {
110: labely = ((d2.height / 2) - (d1.height / 2)) + 2; //+2 fudge factor for font baseline
111: }
112:
113: if (tp.isExpanded()) {
114: int top = tp.getOrientation() == tp.UP ? 0 : tp
115: .getMinimumHeight();
116: int height = Math.min(tp.getHeight()
117: - tp.getMinimumHeight(), d2.height);
118: if (tp.getWidth() - d1.width < d2.width) {
119: c[0].setBounds(0, 0, 0, 0);
120: c[1].setBounds(0, top, tp.getWidth(), height);
121: } else {
122: c[0]
123: .setBounds(0, top + labely, d1.width,
124: d1.height);
125: c[1].setBounds(d1.width + 1, top, tp.getWidth()
126: - d1.width, height);
127: }
128: } else {
129: c[0].setBounds(0, 0, 0, 0);
130: c[1].setBounds(0, 0, 0, 0);
131: }
132: }
133: }
134:
135: public Dimension minimumLayoutSize(Container parent) {
136: Dimension result = new Dimension(20, 10);
137: Component[] c = parent.getComponents();
138: TapPanel tp = (TapPanel) parent;
139: if (c.length > 1) {
140: Dimension d1 = c[0].getPreferredSize();
141: Dimension d2 = c[1].getPreferredSize();
142: result.width = d1.width + d2.width;
143: result.height = tp.isExpanded() ? Math.max(d1.height,
144: d2.height)
145: + tp.getMinimumHeight() : tp.getMinimumHeight();
146: }
147: return result;
148: }
149:
150: public Dimension preferredLayoutSize(Container parent) {
151: return minimumLayoutSize(parent);
152: }
153: }
|