本文整理汇总了Java中org.jfree.text.G2TextMeasurer类的典型用法代码示例。如果您正苦于以下问题:Java G2TextMeasurer类的具体用法?Java G2TextMeasurer怎么用?Java G2TextMeasurer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
G2TextMeasurer类属于org.jfree.text包,在下文中一共展示了G2TextMeasurer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPreferredWidth
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Returns the preferred width of the title. This will only be called when the title
* is being drawn at the left or right of a chart.
*
* @param g2 the graphics device.
* @param height the height.
*
* @return The preferred width of the title.
*/
public float getPreferredWidth(Graphics2D g2, float height) {
float result = 0.0f;
if (this.text != null && !this.text.equals("")) {
g2.setFont(this.font);
TextBlock title = TextUtilities.createTextBlock(
this.text, this.font, this.paint, height, new G2TextMeasurer(g2)
);
Size2D d = title.calculateDimensions(g2);
result = (float) getSpacer().getAdjustedWidth(d.getHeight());
// use height here because the title
// is displayed rotated
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Title preferred width = " + result);
}
return result;
}
示例2: getPreferredHeight
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Returns the preferred height of the title.
*
* @param g2 the graphics device.
* @param width the width.
*
* @return The preferred height of the title.
*/
public float getPreferredHeight(Graphics2D g2, float width) {
float result = 0.0f;
if (this.text != null && !this.text.equals("")) {
g2.setFont(this.font);
float textWidth = (float) getSpacer().trimWidth(width);
TextBlock title = TextUtilities.createTextBlock(
this.text, this.font, this.paint, textWidth, new G2TextMeasurer(g2)
);
Size2D d = title.calculateDimensions(g2);
result = (float) getSpacer().getAdjustedHeight(d.getHeight());
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Title preferred height = " + result);
}
return result;
}
示例3: drawNoDataMessage
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws a message to state that there is no data to plot.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
Shape savedClip = g2.getClip();
g2.clip(area);
String message = this.noDataMessage;
if (message != null) {
g2.setFont(this.noDataMessageFont);
g2.setPaint(this.noDataMessagePaint);
// FontMetrics fm = g2.getFontMetrics(this.noDataMessageFont);
// Rectangle2D bounds = TextUtilities.getTextBounds(message, g2, fm);
// float x = (float) (area.getX() + area.getWidth() / 2 - bounds.getWidth() / 2);
// float y = (float) (area.getMinY() + (area.getHeight() / 2) - (bounds.getHeight() / 2));
// g2.drawString(message, x, y);
TextBlock block = TextUtilities.createTextBlock(
this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint,
0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)
);
block.draw(
g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER
);
}
g2.setClip(savedClip);
}
示例4: drawNoDataMessage
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws a message to state that there is no data to plot.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
Shape savedClip = g2.getClip();
g2.clip(area);
String message = this.noDataMessage;
if (message != null) {
g2.setFont(this.noDataMessageFont);
g2.setPaint(this.noDataMessagePaint);
TextBlock block = TextUtilities.createTextBlock(
this.noDataMessage, this.noDataMessageFont,
this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
new G2TextMeasurer(g2));
block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(),
TextBlockAnchor.CENTER);
}
g2.setClip(savedClip);
}
示例5: drawNoDataMessage
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws a message to state that there is no data to plot.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
Shape savedClip = g2.getClip();
g2.clip(area);
String message = this.noDataMessage;
if (message != null) {
g2.setFont(this.noDataMessageFont);
g2.setPaint(this.noDataMessagePaint);
TextBlock block = TextUtilities.createTextBlock(
this.noDataMessage, this.noDataMessageFont,
this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
new G2TextMeasurer(g2));
block.draw(g2, (float) area.getCenterX(),
(float) area.getCenterY(), TextBlockAnchor.CENTER);
}
g2.setClip(savedClip);
}
示例6: paintComponent
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Paints the panel.
*
* @param g the graphics device.
*/
public void paintComponent(final Graphics g) {
super.paintComponent(g);
final Graphics2D g2 = (Graphics2D) g;
final Dimension size = getSize();
final Insets insets = getInsets();
final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
size.getWidth() - insets.left - insets.right,
size.getHeight() - insets.top - insets.bottom);
final double x = available.getX();
final double y = available.getY();
final float width = (float) available.getWidth();
final TextBlock block = TextUtilities.createTextBlock(
this.text, this.font, Color.black, width, new G2TextMeasurer(g2)
);
g2.setPaint(Color.black);
block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0);
}
示例7: drawLeftLabels
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws the left labels.
*
* @param leftKeys the keys.
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param linkArea the link area.
* @param maxLabelWidth the maximum label width.
* @param state the state.
*/
protected void drawLeftLabels(KeyedValues leftKeys, Graphics2D g2,
Rectangle2D plotArea, Rectangle2D linkArea,
float maxLabelWidth, PiePlotState state) {
PieLabelDistributor distributor1 = new PieLabelDistributor(
leftKeys.getItemCount()
);
double lGap = plotArea.getWidth() * this.labelGap;
double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
for (int i = 0; i < leftKeys.getItemCount(); i++) {
String label = this.labelGenerator.generateSectionLabel(
this.dataset, leftKeys.getKey(i));
if (label != null) {
TextBlock block = TextUtilities.createTextBlock(label,
this.labelFont, this.labelPaint, maxLabelWidth,
new G2TextMeasurer(g2));
TextBox labelBox = new TextBox(block);
labelBox.setBackgroundPaint(this.labelBackgroundPaint);
labelBox.setOutlinePaint(this.labelOutlinePaint);
labelBox.setOutlineStroke(this.labelOutlineStroke);
labelBox.setShadowPaint(this.labelShadowPaint);
double theta = Math.toRadians(
leftKeys.getValue(i).doubleValue());
double baseY = state.getPieCenterY() - Math.sin(theta)
* verticalLinkRadius;
double hh = labelBox.getHeight(g2);
distributor1.addPieLabelRecord(new PieLabelRecord(
leftKeys.getKey(i), theta, baseY, labelBox, hh,
lGap / 2.0 + lGap / 2.0 * -Math.cos(theta), 0.9
+ getExplodePercent(this.dataset.getIndex(
leftKeys.getKey(i)))));
}
}
distributor1.distributeLabels(plotArea.getMinY(), plotArea.getHeight());
for (int i = 0; i < distributor1.getItemCount(); i++) {
drawLeftLabel(g2, state, distributor1.getPieLabelRecord(i));
}
}
示例8: drawHorizontal
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws a the title horizontally within the specified area. This method will be called
* from the {@link #draw(Graphics2D, Rectangle2D) draw} method.
*
* @param g2 the graphics device.
* @param area the area for the title.
*/
protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
Rectangle2D titleArea = (Rectangle2D) area.clone();
getSpacer().trim(titleArea);
g2.setFont(this.font);
g2.setPaint(this.paint);
TextBlock title = TextUtilities.createTextBlock(
this.text, this.font, this.paint, (float) titleArea.getWidth(), new G2TextMeasurer(g2)
);
TextBlockAnchor anchor = null;
float x = 0.0f;
HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
x = (float) titleArea.getX();
anchor = TextBlockAnchor.TOP_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
x = (float) titleArea.getMaxX();
anchor = TextBlockAnchor.TOP_RIGHT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
x = (float) titleArea.getCenterX();
anchor = TextBlockAnchor.TOP_CENTER;
}
float y = 0.0f;
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP) {
y = (float) titleArea.getY();
}
else if (position == RectangleEdge.BOTTOM) {
y = (float) titleArea.getMaxY();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
anchor = TextBlockAnchor.BOTTOM_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
anchor = TextBlockAnchor.BOTTOM_CENTER;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
anchor = TextBlockAnchor.BOTTOM_RIGHT;
}
}
title.draw(g2, x, y, anchor);
}
示例9: drawVertical
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws a the title vertically within the specified area. This method will be called
* from the {@link #draw(Graphics2D, Rectangle2D) draw} method.
*
* @param g2 the graphics device.
* @param area the area for the title.
*/
protected void drawVertical(Graphics2D g2, Rectangle2D area) {
Rectangle2D titleArea = (Rectangle2D) area.clone();
getSpacer().trim(titleArea);
g2.setFont(this.font);
g2.setPaint(this.paint);
TextBlock title = TextUtilities.createTextBlock(
this.text, this.font, this.paint, (float) titleArea.getHeight(), new G2TextMeasurer(g2)
);
TextBlockAnchor anchor = null;
float y = 0.0f;
VerticalAlignment verticalAlignment = getVerticalAlignment();
if (verticalAlignment == VerticalAlignment.TOP) {
y = (float) titleArea.getY();
anchor = TextBlockAnchor.TOP_RIGHT;
}
else if (verticalAlignment == VerticalAlignment.BOTTOM) {
y = (float) titleArea.getMaxY();
anchor = TextBlockAnchor.TOP_LEFT;
}
else if (verticalAlignment == VerticalAlignment.CENTER) {
y = (float) titleArea.getCenterY();
anchor = TextBlockAnchor.TOP_CENTER;
}
float x = 0.0f;
RectangleEdge position = getPosition();
if (position == RectangleEdge.LEFT) {
x = (float) titleArea.getX();
}
else if (position == RectangleEdge.RIGHT) {
x = (float) titleArea.getMaxX();
if (verticalAlignment == VerticalAlignment.TOP) {
anchor = TextBlockAnchor.BOTTOM_RIGHT;
}
else if (verticalAlignment == VerticalAlignment.CENTER) {
anchor = TextBlockAnchor.BOTTOM_CENTER;
}
else if (verticalAlignment == VerticalAlignment.BOTTOM) {
anchor = TextBlockAnchor.BOTTOM_LEFT;
}
}
title.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
}
示例10: drawLeftLabels
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws the left labels.
*
* @param leftKeys the keys.
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param linkArea the link area.
* @param maxLabelWidth the maximum label width.
* @param state the state.
*/
protected void drawLeftLabels(KeyedValues leftKeys, Graphics2D g2,
Rectangle2D plotArea, Rectangle2D linkArea,
float maxLabelWidth, PiePlotState state) {
PieLabelDistributor distributor1 = new PieLabelDistributor(leftKeys.getItemCount());
double lGap = plotArea.getWidth() * this.labelGap;
double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
for (int i = 0; i < leftKeys.getItemCount(); i++) {
String label = this.labelGenerator.generateSectionLabel(
this.dataset, leftKeys.getKey(i)
);
if (label != null) {
TextBlock block = TextUtilities.createTextBlock(
label,
this.labelFont, this.labelPaint, maxLabelWidth, new G2TextMeasurer(g2)
);
TextBox labelBox = new TextBox(block);
labelBox.setBackgroundPaint(this.labelBackgroundPaint);
labelBox.setOutlinePaint(this.labelOutlinePaint);
labelBox.setOutlineStroke(this.labelOutlineStroke);
labelBox.setShadowPaint(this.labelShadowPaint);
double theta = Math.toRadians(leftKeys.getValue(i).doubleValue());
double baseY = state.getPieCenterY() - Math.sin(theta) * verticalLinkRadius;
double hh = labelBox.getHeight(g2);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Label height = " + hh);
}
distributor1.addPieLabelRecord(
new PieLabelRecord(
leftKeys.getKey(i), theta, baseY, labelBox, hh,
lGap / 2.0 + lGap / 2.0 * -Math.cos(theta),
0.9 + getExplodePercent(this.dataset.getIndex(leftKeys.getKey(i)))
)
);
}
}
distributor1.distributeLabels(plotArea.getMinY(), plotArea.getHeight());
for (int i = 0; i < distributor1.getItemCount(); i++) {
drawLeftLabel(g2, state, distributor1.getPieLabelRecord(i));
}
}
示例11: drawRightLabels
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws the right labels.
*
* @param keys the keys.
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param linkArea the link area.
* @param maxLabelWidth the maximum label width.
* @param state the state.
*/
protected void drawRightLabels(KeyedValues keys, Graphics2D g2,
Rectangle2D plotArea, Rectangle2D linkArea,
float maxLabelWidth, PiePlotState state) {
// draw the right labels...
PieLabelDistributor distributor2 = new PieLabelDistributor(keys.getItemCount());
double lGap = plotArea.getWidth() * this.labelGap;
double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
for (int i = 0; i < keys.getItemCount(); i++) {
String label = this.labelGenerator.generateSectionLabel(
this.dataset, keys.getKey(i)
);
if (label != null) {
TextBlock block = TextUtilities.createTextBlock(
label, this.labelFont, this.labelPaint,
maxLabelWidth, new G2TextMeasurer(g2)
);
TextBox labelBox = new TextBox(block);
labelBox.setBackgroundPaint(this.labelBackgroundPaint);
labelBox.setOutlinePaint(this.labelOutlinePaint);
labelBox.setOutlineStroke(this.labelOutlineStroke);
labelBox.setShadowPaint(this.labelShadowPaint);
double theta = Math.toRadians(keys.getValue(i).doubleValue());
double baseY = state.getPieCenterY()
- Math.sin(theta) * verticalLinkRadius;
double hh = labelBox.getHeight(g2);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Label height = " + hh);
}
distributor2.addPieLabelRecord(
new PieLabelRecord(
keys.getKey(i), theta, baseY, labelBox, hh,
lGap / 2.0 + lGap / 2.0 * Math.cos(theta),
0.9 + getExplodePercent(this.dataset.getIndex(keys.getKey(i)))
)
);
}
}
distributor2.distributeLabels(linkArea.getMinY(), linkArea.getHeight());
for (int i = 0; i < distributor2.getItemCount(); i++) {
drawRightLabel(g2, state, distributor2.getPieLabelRecord(i));
}
}
示例12: drawRightLabels
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Draws the right labels.
*
* @param keys the keys.
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param linkArea the link area.
* @param maxLabelWidth the maximum label width.
* @param state the state.
*/
protected void drawRightLabels(KeyedValues keys, Graphics2D g2,
Rectangle2D plotArea, Rectangle2D linkArea,
float maxLabelWidth, PiePlotState state) {
// draw the right labels...
PieLabelDistributor distributor2
= new PieLabelDistributor(keys.getItemCount());
double lGap = plotArea.getWidth() * this.labelGap;
double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
for (int i = 0; i < keys.getItemCount(); i++) {
String label = this.labelGenerator.generateSectionLabel(
this.dataset, keys.getKey(i));
if (label != null) {
TextBlock block = TextUtilities.createTextBlock(label,
this.labelFont, this.labelPaint, maxLabelWidth,
new G2TextMeasurer(g2));
TextBox labelBox = new TextBox(block);
labelBox.setBackgroundPaint(this.labelBackgroundPaint);
labelBox.setOutlinePaint(this.labelOutlinePaint);
labelBox.setOutlineStroke(this.labelOutlineStroke);
labelBox.setShadowPaint(this.labelShadowPaint);
double theta = Math.toRadians(keys.getValue(i).doubleValue());
double baseY = state.getPieCenterY()
- Math.sin(theta) * verticalLinkRadius;
double hh = labelBox.getHeight(g2);
distributor2.addPieLabelRecord(new PieLabelRecord(
keys.getKey(i), theta, baseY, labelBox, hh,
lGap / 2.0 + lGap / 2.0 * Math.cos(theta),
0.9 + getExplodePercent(this.dataset.getIndex(
keys.getKey(i)))));
}
}
distributor2.distributeLabels(plotArea.getMinY(), plotArea.getHeight());
for (int i = 0; i < distributor2.getItemCount(); i++) {
drawRightLabel(g2, state, distributor2.getPieLabelRecord(i));
}
}
示例13: createLabel
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Creates a label.
*
* @param category the category.
* @param width the available width.
* @param edge the edge on which the axis appears.
* @param g2 the graphics device.
*
* @return a label.
*/
protected TextBlock createLabel(Comparable category, float width,
RectangleEdge edge, Graphics2D g2) {
TextBlock label = TextUtilities.createTextBlock(
category.toString(), getTickLabelFont(), getTickLabelPaint(),
width, this.maxCategoryLabelLines, new G2TextMeasurer(g2)
);
return label;
}
示例14: createLabel
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Creates a label.
*
* @param category the category.
* @param width the available width.
* @param edge the edge on which the axis appears.
* @param g2 the graphics device.
*
* @return A label.
*/
protected TextBlock createLabel(Comparable category, float width,
RectangleEdge edge, Graphics2D g2) {
TextBlock label = TextUtilities.createTextBlock(category.toString(),
getTickLabelFont(category), getTickLabelPaint(category), width,
this.maximumCategoryLabelLines, new G2TextMeasurer(g2));
return label;
}
示例15: createLabel
import org.jfree.text.G2TextMeasurer; //导入依赖的package包/类
/**
* Creates a label.
*
* @param category the category.
* @param width the available width.
* @param edge the edge on which the axis appears.
* @param g2 the graphics device.
*
* @return A label.
*/
protected TextBlock createLabel(Comparable category, float width,
RectangleEdge edge, Graphics2D g2) {
TextBlock label = TextUtilities.createTextBlock(category.toString(),
getTickLabelFont(category), getTickLabelPaint(category), width,
this.maximumCategoryLabelLines, new G2TextMeasurer(g2));
return label;
}