⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tableelement.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		for (int col = regularColumnStart; col < nextPageColumn; col++)
		{
			int colWidth = ((Float)m_columnWidths.get(col)).intValue();		//	includes 2*Gaps+Line
			if (xPos >= curX && xPos < (curX + colWidth))
				return col;
			curX += colWidth;
		}	//	for all columns
		//	too right
		return -1;
	}	//	getCol

	/*************************************************************************/

	/**
	 * 	Paint/Print.
	 *
	 * 	@param g2D Graphics
	 *  @param pageNo page number for multi page support (0 = header/footer)
	 *  @param pageStart top left Location of page
	 *  @param ctx context
	 *  @param isView true if online view (IDs are links)
	 */
	public void paint (Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView)
	{
		int pageIndex = getPageIndex(pageNo);
		int pageXindex = getPageXIndex(pageIndex);
		int pageYindex = getPageYIndex(pageIndex);
	//	Log.trace(Log.l6_Database, "TableElement.paint", "Page=" + pageNo
	//		+ " [x=" + pageXindex + ", y=" + pageYindex + "]");
		//
		int firstColumn = ((Integer)m_firstColumnOnPage.get(pageXindex)).intValue();
		int nextPageColumn = m_columnHeader.length;		// no of cols
		if (pageXindex+1 < m_firstColumnOnPage.size())
			nextPageColumn = ((Integer)m_firstColumnOnPage.get(pageXindex+1)).intValue();
		//
		int firstRow = ((Integer)m_firstRowOnPage.get(pageYindex)).intValue();
		int nextPageRow = m_data.length;				//	no of rows
		if (pageYindex+1 < m_firstRowOnPage.size())
			nextPageRow = ((Integer)m_firstRowOnPage.get(pageYindex+1)).intValue();
	//	Log.trace(7, "Col=" + firstColumn + "-" + (nextPageColumn-1),
	//		"Row=" + firstRow + "-" + (nextPageRow-1));

		//	Top Left
		int startX = (int)pageStart.getX();
		int startY = (int)pageStart.getY();
		//	Table Start
		startX += pageXindex == 0 ? m_firstPage.x : m_nextPages.x;
		startY += pageYindex == 0 ? m_firstPage.y : m_nextPages.y;
	//	Log.trace(9, "PageStart=" + pageStart , "StartTable x=" + startX + ", y=" + startY);

		//	paint first fixed volumns
		boolean firstColumnPrint = true;
		int regularColumnStart = firstColumn;
		for (int col = 0; col < m_repeatedColumns; col++)
		{
			int colWidth = ((Float)m_columnWidths.get(col)).intValue();		//	includes 2*Gaps+Line
			if (colWidth != 0)
			{
				printColumn (g2D, col, startX, startY, firstColumnPrint, firstRow, nextPageRow, isView);
				startX += colWidth;
				firstColumnPrint = false;
			}
			if (regularColumnStart == col)
				regularColumnStart++;
		}

		//	paint columns
		for (int col = regularColumnStart; col < nextPageColumn; col++)
		{
			int colWidth = ((Float)m_columnWidths.get(col)).intValue();		//	includes 2*Gaps+Line
			if (colWidth != 0)
			{
				printColumn (g2D, col, startX, startY, firstColumnPrint, firstRow, nextPageRow, isView);
				startX += colWidth;
				firstColumnPrint = false;
			}
		}	//	for all columns

	}	//	paint

	/**
	 * 	Print non zero width Column
	 * 	@param g2D graphics
	 * 	@param col column index
	 * 	@param origX start X
	 * 	@param origY start Y
	 *  @param leftVline if true print left vertical line (for first column)
	 * 	@param firstRow first row index
	 * 	@param nextPageRow row index of next page
	 *  @param isView true if online view (IDs are links)
	 */
	private void printColumn (Graphics2D g2D, int col,
		final int origX, final int origY, boolean leftVline,
		final int firstRow, final int nextPageRow, boolean isView)
	{
		int curX = origX;
		int curY = origY;	//	start from top
		//
		int colWidth = ((Float)m_columnWidths.get(col)).intValue();		//	includes 2*Gaps+Line
		int netWidth = colWidth - (2*H_GAP) - V_LINE;
		if (leftVline)
			netWidth -= V_LINE;
		int rowHeight = m_headerHeight;
		int netHeight = rowHeight - (4*H_LINE) + (2*V_GAP);

	//	Log.trace(9, "TableElement.printColumn = " + col, "x=" + curX + ", y=" + curY
	//		+ ", width=" + colWidth + "/" + netWidth + ", HeaderHeight=" + rowHeight + "/" + netHeight);
		String alignment = m_columnJustification[col];

		//	paint header	**********
		if (leftVline)			//	draw left | line
		{
			g2D.setPaint(m_tFormat.getVLine_Color());
			g2D.setStroke(m_tFormat.getVLine_Stroke());
			if (m_tFormat.isPaintBoundaryLines())
				g2D.drawLine(origX, origY+H_LINE, origX, (origY+rowHeight-(4*H_LINE)));	//	 -> | (left)
			curX += V_LINE;
		}
		//	X - start line
		g2D.setPaint(m_tFormat.getHeaderLine_Color());
		g2D.setStroke(m_tFormat.getHeader_Stroke());
		g2D.drawLine(origX, origY, (origX+colWidth-V_LINE), origY);		//	 -> - (top)
		curY += (2 * H_LINE);	//	thick
		//	Background
		Color bg = getBackground(HEADER_ROW, col);
		if (!bg.equals(Color.white))
		{
			g2D.setPaint(bg);
			g2D.fillRect(curX, curY-H_LINE, colWidth-V_LINE, rowHeight-(4*H_LINE));
		}
		curX += H_GAP;		//	upper left gap
		curY += V_GAP;
		//	Header
		AttributedString aString = null;
		AttributedCharacterIterator iter = null;
		LineBreakMeasurer measurer = null;
		float usedHeight = 0;
		if (m_columnHeader[col].toString().length() > 0)
		{
			aString = new AttributedString(m_columnHeader[col].toString());
			Font font = getFont(HEADER_ROW, col);
			aString.addAttribute(TextAttribute.FONT, font);
			aString.addAttribute(TextAttribute.FOREGROUND, getColor(HEADER_ROW, col));
			iter = aString.getIterator();
			measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
			while (measurer.getPosition() < iter.getEndIndex())		//	print header
			{
				TextLayout layout = measurer.nextLayout(netWidth + 2);
				float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
				if (m_columnMaxHeight[col] == 0 || (usedHeight + lineHeight) <= m_columnMaxHeight[col])
				{
					if (alignment.equals(MPrintFormatItem.FIELD_ALIGN_BLOCK))
						layout = layout.getJustifiedLayout(netWidth + 2);
					curY += layout.getAscent();
					float penX = curX;
					if (alignment.equals(MPrintFormatItem.FIELD_ALIGN_CENTER))
						penX += (netWidth-layout.getAdvance())/2;
					else if ((alignment.equals(MPrintFormatItem.FIELD_ALIGN_TRAILING) && layout.isLeftToRight())
						|| (alignment.equals(MPrintFormatItem.FIELD_ALIGN_LEADING) && !layout.isLeftToRight()))
						penX += netWidth-layout.getAdvance();
					layout.draw(g2D, penX, curY);										//	-> text
					curY += layout.getDescent() + layout.getLeading();
					usedHeight += lineHeight;
				}
				if (!m_multiLineHeader)			//	one line only
					break;
			}
		}	//	length > 0
		curX += netWidth + H_GAP;
		curY += V_GAP;
		//	Y end line
		g2D.setPaint(m_tFormat.getVLine_Color());
		g2D.setStroke(m_tFormat.getVLine_Stroke());
		if (m_tFormat.isPaintVLines())
			g2D.drawLine(curX, origY+H_LINE, curX, (origY+rowHeight-(4*H_LINE)));		//	 -> | (right)
		curX += V_LINE;
		//	X end line
		g2D.setPaint(m_tFormat.getHeaderLine_Color());
		g2D.setStroke(m_tFormat.getHeader_Stroke());
		g2D.drawLine(origX, curY, (origX+colWidth-V_LINE), curY);		//	 -> - (button)
		curY += (2 * H_LINE);	//	thick


		//	paint Data		***********
		for (int row = firstRow; row < nextPageRow; row++)
		{
			rowHeight = ((Float)m_rowHeights.get(row)).intValue();	//	includes 2*Gaps+Line
			netHeight = rowHeight - (2*V_GAP) - H_LINE;
			int rowYstart = curY;

			curX = origX;
			if (leftVline)			//	draw left | line
			{
				g2D.setPaint(m_tFormat.getVLine_Color());
				g2D.setStroke(m_tFormat.getVLine_Stroke());
				if (m_tFormat.isPaintBoundaryLines())
					g2D.drawLine(curX, rowYstart, curX, (rowYstart+rowHeight-H_LINE));		//	 -> | (left)
				curX += V_LINE;
			}
			//	Background
			bg = getBackground(row, col);
			if (!bg.equals(Color.white))
			{
				g2D.setPaint(bg);
				g2D.fillRect(curX, curY, colWidth-V_LINE, rowHeight-H_LINE);
			}
			curX += H_GAP;		//	upper left gap
			curY += V_GAP;

			//	actual data
			Object[] printItems = getPrintItems(row,col);
			float penY = curY;
			for (int index = 0; index < printItems.length; index++)
			{
				if (printItems[index] == null)
					;
				else if (printItems[index] instanceof Boolean)
				{
					int penX = curX + (netWidth-LayoutEngine.IMAGE_SIZE.width)/2;	//	center
					if (((Boolean)printItems[index]).booleanValue())
						g2D.drawImage(LayoutEngine.IMAGE_TRUE, penX, (int)penY, this);
					else
						g2D.drawImage(LayoutEngine.IMAGE_FALSE, penX, (int)penY, this);
					penY += LayoutEngine.IMAGE_SIZE.height;
				}
				else
				{
					String str = printItems[index].toString();
					if (str.length() > 0)
					{
						usedHeight = 0;
						String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(str);
						for (int lineNo = 0; lineNo < lines.length; lineNo++)
						{
							aString = new AttributedString(lines[lineNo]);
							aString.addAttribute(TextAttribute.FONT, getFont(row, col));
							if (isView && printItems[index] instanceof NamePair)	//	ID
							{
								aString.addAttribute(TextAttribute.FOREGROUND, LINK_COLOR);
								aString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL, 0, str.length());
							}
							else
								aString.addAttribute(TextAttribute.FOREGROUND, getColor(row, col));
							iter = aString.getIterator();
							measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
							while (measurer.getPosition() < iter.getEndIndex())		//	print element
							{
								TextLayout layout = measurer.nextLayout(netWidth + 2);
								float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
								if ((m_columnMaxHeight[col] == 0 || (usedHeight + lineHeight) <= m_columnMaxHeight[col])
									&& (usedHeight + lineHeight) <= netHeight)
								{
									if (alignment.equals(MPrintFormatItem.FIELD_ALIGN_BLOCK) && measurer.getPosition() < iter.getEndIndex())
										layout = layout.getJustifiedLayout(netWidth + 2);
									penY += layout.getAscent();
									float penX = curX;
									if (alignment.equals(MPrintFormatItem.FIELD_ALIGN_CENTER))
										penX += (netWidth-layout.getAdvance())/2;
									else if ((alignment.equals(MPrintFormatItem.FIELD_ALIGN_TRAILING) && layout.isLeftToRight())
										|| (alignment.equals(MPrintFormatItem.FIELD_ALIGN_LEADING) && !layout.isLeftToRight()))
										penX += netWidth-layout.getAdvance();
									layout.draw(g2D, penX, penY);										//	-> text
									penY += layout.getDescent() + layout.getLeading();
									usedHeight += lineHeight;
								}
							}	//	print element
						}	//	for all lines
					}	//	length > 0
				}	//	non boolean
			}	//	for all print items

			curY += netHeight + V_GAP;
			curX += netWidth + H_GAP;
			//	Y end line
			g2D.setPaint(m_tFormat.getVLine_Color());
			g2D.setStroke(m_tFormat.getVLine_Stroke());
			if (m_tFormat.isPaintVLines())
				g2D.drawLine(curX, rowYstart, curX, (rowYstart+rowHeight-H_LINE));		//	 -> | (right)
			curX += V_LINE;

			//	X end line
			if (row == m_data.length-1			//	last Line
				|| (row == m_data.length-2 && m_lastLineFunction))
			{
				g2D.setPaint(m_tFormat.getHeaderLine_Color());
				g2D.setStroke(m_tFormat.getHeader_Stroke());
				g2D.drawLine(origX, curY, (origX+colWidth-V_LINE), curY);		//	 -> - (last)
				curY += (2 * H_LINE);	//	thick
			}
			else
			{
				g2D.setPaint(m_tFormat.getHLine_Color());
				g2D.setStroke(m_tFormat.getHLine_Stroke());
				if (m_tFormat.isPaintHLines())
					g2D.drawLine(origX, curY, (origX+colWidth-V_LINE), curY);		//	 -> - (button)
				curY += H_LINE;
			}
		}	// for all rows
	}	//	printColumn

	/**
	 * 	Add Additional Lines to row/col
	 * 	@param row row
	 * 	@param col col
	 * 	@param data data
	 */
	private void addAdditionalLines (int row, int col, Object data)
	{
		Point key = new Point (row,col);
		ArrayList list = (ArrayList)m_additionalLineData.get(key);
		if (list == null)
			list = new ArrayList();
		list.add(data);
		m_additionalLineData.put(key, list);
	}	//	addAdditionalLines

	/**
	 * 	Get Print Data including additional Lines
	 * 	@param row row
	 * 	@param col col
	 * 	@return non null array of print objects (may be empty)
	 */
	private Object[] getPrintItems (int row, int col)
	{
		Point key = new Point (row,col);
		ArrayList list = (ArrayList)m_additionalLineData.get(key);
		if (list == null)
		{
			if (m_data[row][col] != null)
				return new Object[] {m_data[row][col]};
			else
				return new Object[] {};
		}
		//	multiple
		ArrayList retList = new ArrayList();
		retList.add(m_data[row][col]);
		retList.addAll(list);
		return retList.toArray();
	}	//	getPrintItems

}	//	TableElement

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -