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.crm.report;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018:
019: import java.awt.*;
020: import java.util.ArrayList;
021:
022: /**
023: * User: Martin
024: * Date: 25.01.2006
025: * Time: 18:32:17
026: */
027: public class BandsComponentLayoutManager implements LayoutManager2 {
028: @NotNull
029: private BandsComponent bandsComponent;
030:
031: public BandsComponentLayoutManager(@NotNull
032: BandsComponent bandsComponent) {
033: //noinspection ConstantConditions
034: if (bandsComponent == null) {
035: throw new IllegalArgumentException(
036: "bandsComponent must not be null");
037: }
038: this .bandsComponent = bandsComponent;
039: }
040:
041: public void addLayoutComponent(@NotNull
042: Component comp, @Nullable
043: Object constraints) {
044: }
045:
046: @NotNull
047: public Dimension maximumLayoutSize(@NotNull
048: Container target) {
049: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
050: }
051:
052: public float getLayoutAlignmentX(@NotNull
053: Container target) {
054: return 0;
055: }
056:
057: public float getLayoutAlignmentY(@NotNull
058: Container target) {
059: return 0;
060: }
061:
062: public void invalidateLayout(@NotNull
063: Container target) {
064: }
065:
066: public void addLayoutComponent(@NotNull
067: String name, @NotNull
068: Component comp) {
069: }
070:
071: public void removeLayoutComponent(@NotNull
072: Component comp) {
073: }
074:
075: @NotNull
076: public Dimension preferredLayoutSize(@NotNull
077: Container parent) {
078: return calculateSize();
079: }
080:
081: @NotNull
082: public Dimension minimumLayoutSize(@NotNull
083: Container parent) {
084: return calculateSize();
085: }
086:
087: @NotNull
088: private Dimension calculateSize() {
089: Dimension dim = new Dimension(100, 0);
090: ArrayList<ReportBorderPanel> panelInfos = bandsComponent
091: .getReportBorderPanels();
092: for (ReportBorderPanel reportBorderPanel : panelInfos) {
093: dim.width = reportBorderPanel.getPreferredSize().width;
094: double topBorder = reportBorderPanel.isShowTopBorder() ? reportBorderPanel
095: .getReportPanel().getReport().getPageDefinition()
096: .getTopBorder()
097: : 0;
098: dim.height += (int) ((reportBorderPanel.getReportPanel()
099: .getBandToplevelReportElement().getVisualHeight() + topBorder) * reportBorderPanel
100: .getReportPanel().getScaleFactor());
101: }
102:
103: dim.height += 10;
104:
105: return dim;
106: }
107:
108: public void layoutContainer(@NotNull
109: Container parent) {
110: int grabberWidth = 0;
111: int width = parent.getWidth() - grabberWidth;
112:
113: int currentY = 0;
114:
115: ArrayList<ReportBorderPanel> panelInfos = bandsComponent
116: .getReportBorderPanels();
117: for (int i = 0; i < panelInfos.size(); i++) {
118: ReportBorderPanel reportBorderPanel = panelInfos.get(i);
119: double topBorder = reportBorderPanel.isShowTopBorder() ? reportBorderPanel
120: .getReportPanel().getReport().getPageDefinition()
121: .getTopBorder()
122: : 0;
123: reportBorderPanel
124: .setBounds(
125: grabberWidth,
126: currentY,
127: width,
128: (int) ((reportBorderPanel.getReportPanel()
129: .getBandToplevelReportElement()
130: .getVisualHeight() + topBorder) * reportBorderPanel
131: .getReportPanel().getScaleFactor()));
132: currentY += (int) ((reportBorderPanel.getReportPanel()
133: .getBandToplevelReportElement().getVisualHeight() + topBorder) * reportBorderPanel
134: .getReportPanel().getScaleFactor());
135:
136: GrabberComponent grabberComponent = bandsComponent
137: .getGrabberComponents().get(i);
138: grabberComponent
139: .setBounds(0, currentY - 3, grabberWidth, 6);
140: }
141:
142: bandsComponent.getBottomHelperPanel().setBounds(0, currentY,
143: width, parent.getHeight() - currentY);
144: }
145: }
|