/* * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. */ package com.fr.grid; import java.awt.Dimension; import com.fr.base.GraphHelper; import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; /** * GridRow used to paint and edit grid row. * * @editor zhou * @since 2012-3-22下午6:12:03 */ public class GridRow extends GridHeader { private static final int MAX = 4; private int adsorbHeight; private GridRowMouseHandler gridRowMouseHandler; public GridRow(int resolution) { this(resolution, 0); } public GridRow(int resolution, int adsorbHeight) { super(resolution); this.adsorbHeight = adsorbHeight; } @Override protected void initByConstructor() { this.updateUI(); } @Override public Integer getDisplay(int index) { return new Integer(index + 1); } @Override public void updateUI() { this.removeMouseListener(gridRowMouseHandler); this.removeMouseMotionListener(gridRowMouseHandler); gridRowMouseHandler = new GridRowMouseHandler(this, adsorbHeight); this.addMouseListener(gridRowMouseHandler); this.addMouseMotionListener(gridRowMouseHandler); this.setUI(new GridRowUI(resolution)); } /** * Gets the preferred size. */ @Override public Dimension getPreferredSize() { ElementCasePane reportPane = this.getElementCasePane(); float time = (float) reportPane.getResolution() / DesignerUIModeConfig.getInstance().getScreenResolution(); if (!(reportPane.isRowHeaderVisible())) { return new Dimension(0, 0); } int maxCharNumber = this.caculateMaxCharNumber(reportPane); return new Dimension((int) (maxCharNumber * GraphHelper.getFontMetrics(this.getFont()).charWidth('M') * time), super.getPreferredSize().height); } /** * Calculates max char number. */ private int caculateMaxCharNumber(ElementCasePane reportPane) { int maxCharNumber = MAX; maxCharNumber = Math.max(maxCharNumber, ("" + (reportPane.getGrid().getVerticalValue() + reportPane.getGrid().getVerticalExtent())).length() + 1); return maxCharNumber; } }