All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scudata.ide.spl.control.ColHeaderPanel Maven / Gradle / Ivy

Go to download

SPL(Structured Process Language) A programming language specially for structured data computing.

There is a newer version: 20241126
Show newest version
package com.scudata.ide.spl.control;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.HashSet;

import javax.swing.JPanel;

import com.scudata.common.StringUtils;
import com.scudata.ide.common.GC;
import com.scudata.ide.spl.GCSpl;

/**
 * ?б?ͷ???
 *
 */
public class ColHeaderPanel extends JPanel {
	private static final long serialVersionUID = 1L;

	/** ????ؼ? */
	protected SplControl control;
	/**
	 * ?Ƿ???Ա༭
	 */
	protected boolean editable = true;
	/**
	 * ?????????
	 */
	protected CellSetParser parser;

	/**
	 * ?б?ͷ??幹?캯??
	 * 
	 * @param control
	 */
	public ColHeaderPanel(SplControl control) {
		this(control, true);
	}

	/**
	 * ?б?ͷ??幹?캯??
	 * 
	 * @param control ?༭?ؼ?
	 */
	public ColHeaderPanel(SplControl control, boolean editable) {
		this.control = control;
		this.editable = editable;
		parser = new CellSetParser(control.cellSet);
		initCoords();
		int h = (int) (GCSpl.DEFAULT_ROW_HEIGHT * control.scale);
		setPreferredSize(new Dimension((int) getPreferredSize().getWidth(),
				h + 1));
	}

	/**
	 * ??ʼ??????
	 */
	protected void initCoords() {
		int cols = control.cellSet.getColCount() + 1;
		if (control.cellX == null || cols != control.cellX.length) {
			control.cellX = new int[cols];
			control.cellW = new int[cols];
		}

		for (int i = 1; i < cols; i++) {
			if (i == 1) {
				control.cellX[i] = 1;
			} else {
				control.cellX[i] = control.cellX[i - 1] + control.cellW[i - 1];
			}
			if (!parser.isColVisible(i)) {
				control.cellW[i] = 0;
			} else {
				control.cellW[i] = parser.getColWidth(i, control.scale);
			}
		}
	}

	/**
	 * ?????б?ͷ
	 * 
	 * @param g ????е?ͼ?ζ???
	 */
	public void paintComponent(Graphics g) {
		ControlUtils.setGraphicsRenderingHints(g);
		int h = (int) (GCSpl.DEFAULT_ROW_HEIGHT * control.scale);
		g.clearRect(0, 0, 999999, h + 1);

		int cols = control.cellSet.getColCount() + 1;
		if (cols != control.cellX.length) {
			control.cellX = new int[cols];
			control.cellW = new int[cols];
		}
		Rectangle r = control.getViewport().getViewRect();
		HashSet selectedCols = ControlUtils.listSelectedCols(control
				.getSelectedAreas());
		for (int i = 1; i < cols; i++) {
			if (i == 1) {
				control.cellX[i] = 1;
			} else {
				control.cellX[i] = control.cellX[i - 1] + control.cellW[i - 1];
			}
			if (!parser.isColVisible(i)) {
				control.cellW[i] = 0;
			} else {
				control.cellW[i] = parser.getColWidth(i, control.scale);
			}
			if (control.cellX[i] + control.cellW[i] <= r.x) {
				continue;
			}
			if (control.cellX[i] >= r.x + r.width) {
				break;
			}

			Color bkColor = Color.lightGray;
			String label = getColLabel(i);
			byte flag = GC.SELECT_STATE_NONE;
			if (selectedCols.contains(new Integer(i))) {
				flag = GC.SELECT_STATE_CELL;
			}
			for (int k = 0; k < control.m_selectedCols.size(); k++) {
				if (i == ((Integer) control.m_selectedCols.get(k)).intValue()) {
					flag = GC.SELECT_STATE_COL;
					break;
				}
			}
			int x = control.cellX[i];
			int w = control.cellW[i];
			if (i > 1) {
				x++;
				w--;
			}
			if (w > 0) {
				ControlUtils.drawHeader(g, x, 0, w, h, label, control.scale,
						bkColor, flag, editable);
			}
		}
		setPreferredSize(new Dimension((int) getPreferredSize().getWidth(),
				h + 1));
		g.dispose();
	}

	protected String getColLabel(int col) {
		return StringUtils.toExcelLabel(col);
	}

	/**
	 * ȡ???ߴ??С
	 */
	public Dimension getPreferredSize() {
		int width = 0;
		for (int col = 1; col <= control.cellSet.getColCount(); col++) {
			if (parser.isColVisible(col)) {
				width += parser.getColWidth(col, control.scale);
			}
		}
		int h = (int) (GCSpl.DEFAULT_ROW_HEIGHT * control.scale);
		return new Dimension(width + 2, h + 1);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy