/* * 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.fit.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import com.fr.stable.StableUtils; /** * GridColumn used to paint and edit grid column. * * @editor zhou * @since 2012-3-22下午6:12:40 */ public class GridColumn extends GridHeader { private GridColumnMouseHandler gridColumnMouseHandler; public GridColumn(int resolution) { super(resolution); } @Override protected void initByConstructor() { gridColumnMouseHandler = new GridColumnMouseHandler(this); this.addMouseListener(gridColumnMouseHandler); this.addMouseMotionListener(gridColumnMouseHandler); this.updateUI(); } @Override public String getDisplay(int index) { return StableUtils.convertIntToABC(index + 1); } @Override public void updateUI() { this.removeMouseListener(gridColumnMouseHandler); this.removeMouseMotionListener(gridColumnMouseHandler); gridColumnMouseHandler = new GridColumnMouseHandler(this); this.addMouseListener(gridColumnMouseHandler); this.addMouseMotionListener(gridColumnMouseHandler); this.setUI(new GridColumnUI(resolution)); } /** * Gets the preferred size. */ @Override public Dimension getPreferredSize() { ElementCasePane reportPane = this.getElementCasePane(); float time = (float)reportPane.getResolution()/ DesignerUIModeConfig.getInstance().getScreenResolution(); if (!reportPane.isColumnHeaderVisible()) { return new Dimension(0, 0); } return new Dimension(super.getPreferredSize().width, (int) (GraphHelper.getFontMetrics(this.getFont()).getHeight() * time + SIZE_ADJUST)); } }