📄 stringelement.java
字号:
{
AttributedCharacterIterator iter = m_string_paper[i].getIterator();
if (iter.getBeginIndex() == iter.getEndIndex())
continue;
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, frc);
// System.out.println("StringLength=" + m_originalString.length() + " MaxWidth=" + p_maxWidth + " MaxHeight=" + p_maxHeight);
while (measurer.getPosition() < iter.getEndIndex())
{
// no need to expand tab space for limited space
layout = measurer.nextLayout(p_maxWidth);
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
// System.out.println(" LineWidth=" + layout.getAdvance() + " LineHeight=" + lineHeight);
if (p_maxHeight == -1f && i == 0) // one line only
p_maxHeight = lineHeight;
if (p_maxHeight == 0f || (p_height + lineHeight) <= p_maxHeight)
p_height += lineHeight;
}
} // for all strings
// Add CheckBox Size
if (m_check != null)
{
// p_width += LayoutEngine.IMAGE_SIZE.width;
if (p_height < LayoutEngine.IMAGE_SIZE.height)
p_height = LayoutEngine.IMAGE_SIZE.height;
}
// System.out.println(" Width=" + p_width + " Height=" + p_height);
}
// System.out.println("StringElement.calculate size - Width="
// + p_width + "(" + p_maxWidth + ") - Height=" + p_height + "(" + p_maxHeight + ")");
// Enlarge Size when aligned and max size is given
if (p_FieldAlignmentType != null)
{
boolean changed = false;
if (p_height < p_maxHeight)
{
p_height = p_maxHeight;
changed = true;
}
if (p_width < p_maxWidth)
{
p_width = p_maxWidth;
changed = true;
}
// if (changed)
// System.out.println("StringElement.calculate size - Width="
// + p_width + "(" + p_maxWidth + ") - Height=" + p_height + "(" + p_maxHeight + ")");
}
return true;
} // calculateSize
/*************************************************************************/
/**
* Get Drill Down value
* @param relativePoint relative Point
* @param pageNo page number (ignored)
* @return if found query or null
*/
public MQuery getDrillDown (Point relativePoint, int pageNo)
{
if (m_ID != null && getBounds().contains(relativePoint))
{
Log.trace(Log.l5_DData, "StringElement.getDrillDown", toString());
String columnName = m_ID.getName();
String tableName = columnName;
int index = tableName.lastIndexOf("_ID");
if (index != -1)
tableName = tableName.substring(0, index);
Object code = m_ID.getID();
if (m_ID instanceof KeyNamePair)
code = new Integer(((KeyNamePair)m_ID).getKey());
//
MQuery query = new MQuery(tableName);
query.addRestriction(columnName, MQuery.EQUAL, code);
return query;
}
return null;
} // getDrillDown
/**
* Get Drill Across value
* @param relativePoint relative Point
* @param pageNo page number (ignored)
* @return null - not implemented
*/
public MQuery getDrillAcross (Point relativePoint, int pageNo)
{
// Log.trace(Log.l5_DData, "StringElement.getDrillAcross");
// if (getBounds().contains(relativePoint));
return null;
} // getDrillAcross
/*************************************************************************/
/**
* Paint/Print.
* Calculate actual Size.
* The text is printed in the topmost left position - i.e. the leading is below the line
* @param g2D Graphics
* @param pageStart top left Location of page
* @param pageNo page number for multi page support (0 = header/footer) - ignored
* @param ctx print context
* @param isView true if online view (IDs are links)
*/
public void paint (Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView)
{
// Log.trace(8, "StringElement.paint", "<" + m_originalString + "> " + p_pageLocation.x + "/" + p_pageLocation.y
// + ", Clip=" + g2D.getClip()
// + ", Translate=" + g2D.getTransform().getTranslateX() + "/" + g2D.getTransform().getTranslateY()
// + ", Scale=" + g2D.getTransform().getScaleX() + "/" + g2D.getTransform().getScaleY()
// + ", Shear=" + g2D.getTransform().getShearX() + "/" + g2D.getTransform().getShearY());
Point2D.Double location = getAbsoluteLocation(pageStart);
//
if (m_originalString != null)
translate(ctx);
AttributedCharacterIterator iter = null;
float xPos = (float)location.x;
float yPos = (float)location.y;
float yPen = 0f;
float height = 0f;
float width = 0f;
// for all strings
for (int i = 0; i < m_string_paper.length; i++)
{
// Get Text
if (isView)
iter = m_string_view[i].getIterator();
else
iter = m_string_paper[i].getIterator();
if (iter.getBeginIndex() == iter.getEndIndex())
continue;
// Check for Tab (just first)
int tabPos = -1;
for (char c = iter.first(); c != iter.DONE && tabPos == -1; c = iter.next())
{
if (c == '\t')
tabPos = iter.getIndex();
}
TextLayout layout = null;
float xPen = xPos;
// No Limit
if (p_maxWidth == 0f)
{
if (tabPos == -1)
{
layout = new TextLayout (iter, g2D.getFontRenderContext());
yPen = yPos + layout.getAscent();
layout.draw(g2D, xPen, yPen);
yPos += layout.getAscent() + layout.getDescent() + layout.getLeading();
if (width < layout.getAdvance())
width = layout.getAdvance();
}
else
{
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
layout = measurer.nextLayout(9999, tabPos, false);
float lineHeight1 = layout.getAscent() + layout.getDescent() + layout.getLeading();
yPen = yPos + layout.getAscent();
layout.draw(g2D, xPen, yPen); // first part
xPen = getTabPos (xPos, layout.getAdvance());
float lineWidth = xPen - xPos;
layout = measurer.nextLayout(9999, iter.getEndIndex(), true);
float lineHeight2 = layout.getAscent() + layout.getDescent() + layout.getLeading();
layout.draw(g2D, xPen, yPen);
yPos += Math.max(lineHeight1, lineHeight2);
lineWidth += layout.getAdvance();
if (width < lineWidth)
width = lineWidth;
}
// Log.trace(9, "StringElement.paint - No Limit - " + location.x + "/" + yPos
// + " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Bounds=" + layout.getBounds());
}
// Size Limits
else
{
LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
while (measurer.getPosition() < iter.getEndIndex())
{
if (tabPos == -1)
layout = measurer.nextLayout(p_maxWidth);
else
layout = measurer.nextLayout(p_maxWidth, tabPos, false);
// Line Height
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (p_maxHeight == -1f && i == 0) // one line only
p_maxHeight = lineHeight;
// If we have hight left over
if (p_maxHeight == 0f || (height + lineHeight) <= p_maxHeight)
{
yPen = (float)location.y + height + layout.getAscent();
// Tab in Text
if (tabPos != -1)
{
layout.draw(g2D, xPen, yPen); // first part
xPen = getTabPos (xPos, layout.getAdvance());
layout = measurer.nextLayout(p_width, iter.getEndIndex(), true);
tabPos = -1; // reset (just one tab)
}
else if ((MPrintFormatItem.FIELD_ALIGN_TRAILING.equals(p_FieldAlignmentType) && layout.isLeftToRight())
|| (MPrintFormatItem.FIELD_ALIGN_LEADING.equals(p_FieldAlignmentType) && !layout.isLeftToRight()))
xPen += p_maxWidth - layout.getAdvance();
else if (MPrintFormatItem.FIELD_ALIGN_CENTER.equals(p_FieldAlignmentType))
xPen += (p_maxWidth - layout.getAdvance()) / 2;
else if (MPrintFormatItem.FIELD_ALIGN_BLOCK.equals(p_FieldAlignmentType) && measurer.getPosition() < iter.getEndIndex())
layout = layout.getJustifiedLayout(p_maxWidth);
layout.draw(g2D, xPen, yPen);
height += lineHeight;
// Log.trace(9, "StringElement.paint - Limit - " + xPen + "/" + yPen
// + " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Align=" + p_FieldAlignmentType + ", Max w=" + p_maxWidth + ",h=" + p_maxHeight + ", Bounds=" + layout.getBounds());
}
}
width = p_maxWidth;
} // size limits
} // for all strings
if (m_check != null)
{
int x = (int)(location.x + width + 1);
int y = (int)(location.y);
g2D.drawImage(m_check.booleanValue() ? LayoutEngine.IMAGE_TRUE : LayoutEngine.IMAGE_FALSE, x, y, this);
}
} // paint
/**
* Get Tab Position.
* The Tab position is relative to the string itself, not the absolute
* position; i.e. to have the same tab position on a page, strings need
* to start at the same position.
* The Tab is rounded up to the next 30 dividable position.
* @param xPos starting x position
* @param length length of segment
* @return new x Position (xPos + length + tabSpace)
*/
private float getTabPos (float xPos, float length)
{
float retValue = xPos + length;
int iLength = (int)Math.ceil(length);
int tabSpace = iLength % 30;
retValue += (30 - tabSpace);
return retValue;
} // getTabPos
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("StringElement[");
sb.append("Bounds=").append(getBounds())
.append(",Height=").append(p_height).append("(").append(p_maxHeight)
.append("),Width=").append(p_width).append("(").append(p_maxHeight)
.append("),PageLocation=").append(p_pageLocation).append(" - ");
for (int i = 0; i < m_string_paper.length; i++)
{
if (m_string_paper.length > 1)
sb.append(Env.NL).append(i).append(":");
AttributedCharacterIterator iter = m_string_paper[i].getIterator();
for (char c = iter.first(); c != iter.DONE; c = iter.next())
sb.append(c);
}
if (m_ID != null)
sb.append(",ID=(").append(m_ID.toStringX()).append(")");
sb.append("]");
return sb.toString();
} // toString
} // StringElement
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -