001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.lib.client.components.docking;
015:
016: import org.jetbrains.annotations.NotNull;
017:
018: import javax.swing.*;
019: import java.awt.*;
020:
021: /**
022: * User: Martin
023: * Date: 05.11.2004
024: * Time: 13:14:08
025: */
026: public class DockingPaneLayout implements LayoutManager {
027: private int maxX;
028: private int maxY;
029:
030: public DockingPaneLayout() {
031: maxX = 100;
032: maxY = 100;
033: }
034:
035: public void addLayoutComponent(@NotNull
036: String name, @NotNull
037: Component comp) {
038: }
039:
040: public void removeLayoutComponent(@NotNull
041: Component comp) {
042: }
043:
044: @NotNull
045: public Dimension preferredLayoutSize(@NotNull
046: Container parent) {
047: return new Dimension(maxX, maxY);
048: }
049:
050: @NotNull
051: public Dimension minimumLayoutSize(@NotNull
052: Container parent) {
053: return new Dimension(maxX, maxY);
054: }
055:
056: public void layoutContainer(@NotNull
057: Container parent) {
058: synchronized (parent.getTreeLock()) {
059: DockingPane dockingPane = (DockingPane) parent;
060:
061: JPanel[] buttonBorders = dockingPane.getButtonBorders();
062:
063: BorderComponent[] borderComponents = dockingPane
064: .getDockedComponents();
065:
066: int w = dockingPane.getWidth();
067: int h = dockingPane.getHeight();
068:
069: int tBH = buttonBorders[0].getPreferredSize().height;
070: //int tBW = buttonBorders[0].getPreferredSize().width;
071:
072: int bBH = buttonBorders[1].getPreferredSize().height;
073: //int bBW = buttonBorders[1].getPreferredSize().width;
074:
075: //int lBH = buttonBorders[2].getPreferredSize().height;
076: int lBW = buttonBorders[2].getPreferredSize().width;
077:
078: //int rBH = buttonBorders[3].getPreferredSize().height;
079: int rBW = buttonBorders[3].getPreferredSize().width;
080:
081: //int tCW = borderComponents[0].getPreferredSize().width;
082: int tCH = borderComponents[0].getPreferredSize().height;
083:
084: //int bCW = borderComponents[1].getPreferredSize().width;
085: int bCH = borderComponents[1].getPreferredSize().height;
086:
087: int lCW = borderComponents[2].getPreferredSize().width;
088: //int lCH = borderComponents[2].getPreferredSize().height;
089:
090: int rCW = borderComponents[3].getPreferredSize().width;
091: //int rCH = borderComponents[3].getPreferredSize().height;
092:
093: if (tBH + tCH + bBH + bCH > h) {
094: double divideRatio = bCH / (double) (tCH + bCH);
095:
096: int innerHeight = h - (tBH + bBH);
097:
098: int bAllowedH = (int) (innerHeight * divideRatio);//h without border divided proportionally
099: if (bAllowedH < borderComponents[1].getDragPanel()
100: .getHeight()) {
101: bAllowedH = borderComponents[1].getDragPanel()
102: .getHeight();
103: }
104: int tAllowedH = innerHeight - bAllowedH;//buttom gets rest of available space
105: if (tAllowedH < borderComponents[0].getDragPanel()
106: .getHeight()) {
107: tAllowedH = borderComponents[0].getDragPanel()
108: .getHeight();
109: }
110: tCH = tAllowedH;
111: bCH = bAllowedH;
112:
113: borderComponents[0].setToolWindowHeight(tCH);
114: borderComponents[1].setToolWindowHeight(bCH);
115: }
116:
117: if (lBW + lCW + rBW + rCW > w) {
118: double divideRatio = rCW / (double) (lCW + rCW);
119:
120: int innerWidth = w - (lBW + rBW);
121:
122: int bAllowedW = (int) (innerWidth * divideRatio);//h without border divided proportionally
123: if (bAllowedW < borderComponents[3].getDragPanel()
124: .getWidth()) {
125: bAllowedW = borderComponents[3].getDragPanel()
126: .getWidth();
127: }
128: int tAllowedW = innerWidth - bAllowedW;//buttom gets rest of available space
129: if (tAllowedW < borderComponents[2].getDragPanel()
130: .getWidth()) {
131: tAllowedW = borderComponents[2].getDragPanel()
132: .getWidth();
133: }
134: lCW = tAllowedW;
135: rCW = bAllowedW;
136:
137: borderComponents[2].setToolWindowWidth(lCW);
138: borderComponents[3].setToolWindowWidth(rCW);
139: }
140:
141: buttonBorders[0].setBounds(lBW, 0, w - (lBW + rBW), tBH);//top
142: buttonBorders[1].setBounds(lBW, h - bBH, w - (lBW + rBW),
143: bBH);//bottom
144:
145: buttonBorders[2].setBounds(0, tBH + tCH, lBW, h
146: - (tBH + bBH + tCH + bCH));
147: buttonBorders[3].setBounds(w - rBW, tBH + tCH, rBW, h
148: - (tBH + bBH + tCH + bCH));
149:
150: borderComponents[0].setBounds(lBW, tBH, w - (lBW + rBW),
151: tCH);
152: borderComponents[1].setBounds(lBW, h - (bBH + bCH), w
153: - (lBW + rBW), bCH);
154:
155: borderComponents[2].setBounds(lBW, tBH + tCH, lCW, h
156: - (tBH + bBH + tCH + bCH));
157: borderComponents[3].setBounds(w - (rBW + rCW), tBH + tCH,
158: rCW, h - (tBH + bBH + tCH + bCH));
159:
160: dockingPane.getCenterComponent().setBounds(lBW + lCW,
161: tBH + tCH, w - (lBW + lCW + rBW + rCW),
162: h - (tBH + tCH + bBH + bCH));
163: }
164: }
165:
166: }
|