📄 tableelement.java
字号:
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
//
float colWidth = ((Float)m_columnWidths.get(col)).floatValue(); // includes 2*Gaps+Line
float netWidth = colWidth - (2*H_GAP) - m_tFormat.getVLineStroke().floatValue();
if (leftVline)
netWidth -= m_tFormat.getVLineStroke().floatValue();
int rowHeight = m_headerHeight;
float netHeight = rowHeight - (4*m_tFormat.getLineStroke().floatValue()) + (2*V_GAP);
if (DEBUG_PRINT)
log.finer("#" + 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()) // -> | (left)
g2D.drawLine(origX, (int)(origY+m_tFormat.getLineStroke().floatValue()),
origX, (int)(origY+rowHeight-(4*m_tFormat.getLineStroke().floatValue())));
curX += m_tFormat.getVLineStroke().floatValue();
}
// X - start line
if (m_tFormat.isPaintHeaderLines())
{
g2D.setPaint(m_tFormat.getHeaderLine_Color());
g2D.setStroke(m_tFormat.getHeader_Stroke());
g2D.drawLine(origX, origY, // -> - (top)
(int)(origX+colWidth-m_tFormat.getVLineStroke().floatValue()), origY);
}
curY += (2 * m_tFormat.getLineStroke().floatValue()); // thick
// Background
Color bg = getBackground(HEADER_ROW, col);
if (!bg.equals(Color.white))
{
g2D.setPaint(bg);
g2D.fillRect(curX,
(int)(curY-m_tFormat.getLineStroke().floatValue()),
(int)(colWidth-m_tFormat.getVLineStroke().floatValue()),
(int)(rowHeight-(4*m_tFormat.getLineStroke().floatValue())));
}
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());
aString.addAttribute(TextAttribute.FONT, getFont(HEADER_ROW, col));
aString.addAttribute(TextAttribute.FOREGROUND, getColor(HEADER_ROW, col));
//
boolean fastDraw = LayoutEngine.s_FASTDRAW;
if (fastDraw && !isView && !Util.is8Bit(m_columnHeader[col].toString()))
fastDraw = false;
iter = aString.getIterator();
measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
while (measurer.getPosition() < iter.getEndIndex()) // print header
{
TextLayout layout = measurer.nextLayout(netWidth + 2);
if (iter.getEndIndex() != measurer.getPosition())
fastDraw = false;
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (m_columnMaxHeight[col] <= 0 // -1 = FirstLineOnly
|| (usedHeight + lineHeight) <= m_columnMaxHeight[col])
{
if (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Block))
{
layout = layout.getJustifiedLayout(netWidth + 2);
fastDraw = false;
}
curY += layout.getAscent();
float penX = curX;
if (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Center))
penX += (netWidth-layout.getAdvance())/2;
else if ((alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight) && layout.isLeftToRight())
|| (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft) && !layout.isLeftToRight()))
penX += netWidth-layout.getAdvance();
//
if (fastDraw)
{ // Bug - set Font/Color explicitly
g2D.setFont(getFont(HEADER_ROW, col));
g2D.setColor(getColor(HEADER_ROW, col));
g2D.drawString(iter, penX, curY);
}
else
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()) // -> | (right)
g2D.drawLine(curX, (int)(origY+m_tFormat.getLineStroke().floatValue()),
curX, (int)(origY+rowHeight-(4*m_tFormat.getLineStroke().floatValue())));
curX += m_tFormat.getVLineStroke().floatValue();
// X end line
if (m_tFormat.isPaintHeaderLines())
{
g2D.setPaint(m_tFormat.getHeaderLine_Color());
g2D.setStroke(m_tFormat.getHeader_Stroke());
g2D.drawLine(origX, curY, // -> - (button)
(int)(origX+colWidth-m_tFormat.getVLineStroke().floatValue()), curY);
}
curY += (2 * m_tFormat.getLineStroke().floatValue()); // 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) - m_tFormat.getLineStroke().floatValue();
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, // -> | (left)
curX, (int)(rowYstart+rowHeight-m_tFormat.getLineStroke().floatValue()));
curX += m_tFormat.getVLineStroke().floatValue();
}
// Background
bg = getBackground(row, col);
if (!bg.equals(Color.white))
{
g2D.setPaint(bg);
g2D.fillRect(curX, curY,
(int)(colWidth-m_tFormat.getVLineStroke().floatValue()),
(int)(rowHeight-m_tFormat.getLineStroke().floatValue()) );
}
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 ImageElement)
{
g2D.drawImage(((ImageElement)printItems[index]).getImage(),
curX, (int)penY, this);
}
else if (printItems[index] instanceof Boolean)
{
int penX = curX + (int)((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 if (printItems[index] instanceof HTMLRenderer)
{
HTMLRenderer renderer = (HTMLRenderer)printItems[index];
Rectangle allocation = new Rectangle((int)colWidth, (int)netHeight);
// log.finest( "printColumn HTML - " + allocation);
g2D.translate(curX, penY);
renderer.paint(g2D, allocation);
g2D.translate(-curX, -penY);
penY += allocation.getHeight();
}
else
{
String str = printItems[index].toString();
if (DEBUG_PRINT)
log.fine("row=" + row + ",col=" + col + " - " + str + " 8Bit=" + Util.is8Bit(str));
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();
boolean fastDraw = LayoutEngine.s_FASTDRAW;
if (fastDraw && !isView && !Util.is8Bit(lines[lineNo]))
fastDraw = false;
measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
while (measurer.getPosition() < iter.getEndIndex()) // print element
{
TextLayout layout = measurer.nextLayout(netWidth + 2);
if (iter.getEndIndex() != measurer.getPosition())
fastDraw = false;
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.FIELDALIGNMENTTYPE_Block) && measurer.getPosition() < iter.getEndIndex())
{
layout = layout.getJustifiedLayout(netWidth + 2);
fastDraw = false;
}
penY += layout.getAscent();
float penX = curX;
if (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Center))
penX += (netWidth-layout.getAdvance())/2;
else if ((alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight) && layout.isLeftToRight())
|| (alignment.equals(MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft) && !layout.isLeftToRight()))
penX += netWidth-layout.getAdvance();
//
if (fastDraw)
{ // Bug - set Font/Color explicitly
g2D.setFont(getFont(row, col));
if (isView && printItems[index] instanceof NamePair) // ID
{
g2D.setColor(LINK_COLOR);
// TextAttribute.UNDERLINE
}
else
g2D.setColor(getColor(row, col));
g2D.drawString(iter, penX, penY);
}
else
layout.draw(g2D, penX, penY); // -> text
if (DEBUG_PRINT)
log.fine("row=" + row + ",col=" + col + " - " + str + " - x=" + penX + ",y=" + penY);
penY += layout.getDescent() + layout.getLeading();
usedHeight += lineHeight;
//
if (m_columnMaxHeight[col] == -1) // FirstLineOny
break;
}
} // 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, // -> | (right)
curX, (int)(rowYstart+rowHeight-m_tFormat.getLineStroke().floatValue()));
curX += m_tFormat.getVLineStroke().floatValue();
// X end line
if (row == m_data.length-1) // last Line
{
g2D.setPaint(m_tFormat.getHeaderLine_Color());
g2D.setStroke(m_tFormat.getHeader_Stroke());
g2D.drawLine(origX, curY, // -> - (last line)
(int)(origX+colWidth-m_tFormat.getVLineStroke().floatValue()), curY);
curY += (2 * m_tFormat.getLineStroke().floatValue()); // thick
}
else
{
// next line is a funcion column -> underline this
boolean nextIsFunction = m_functionRows.contains(new Integer(row+1));
if (nextIsFunction && m_functionRows.contains(new Integer(row)))
nextIsFunction = false; // this is a function line too
if (nextIsFunction)
{
g2D.setPaint(m_tFormat.getFunctFG_Color());
g2D.setStroke(m_tFormat.getHLine_Stroke());
g2D.drawLine(origX, curY, // -> - (bottom)
(int)(origX+colWidth-m_tFormat.getVLineStroke().floatValue()), curY);
}
else if (m_tFormat.isPaintHLines())
{
g2D.setPaint(m_tFormat.getHLine_Color());
g2D.setStroke(m_tFormat.getHLine_Stroke());
g2D.drawLine(origX, curY, // -> - (bottom)
(int)(origX+colWidth-m_tFormat.getVLineStroke().floatValue()), curY);
}
curY += m_tFormat.getLineStroke().floatValue();
}
} // 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<Object> list = (ArrayList<Object>)m_additionalLineData.get(key);
if (list == null)
list = new ArrayList<Object>();
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<Object> list = (ArrayList<Object>)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<Object> retList = new ArrayList<Object>();
retList.add(m_data[row][col]);
retList.addAll(list);
return retList.toArray();
} // getPrintItems
} // TableElement
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -