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