下面列出了java.awt.Graphics2D#getClipBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void renderItems (Graphics2D g)
{
// (Phase #2) Render sections (on top of rendered spots)
super.render(g);
// (Phase #3) Render spots mean line
final Rectangle clip = g.getClipBounds();
final Stroke oldStroke = UIUtil.setAbsoluteStroke(g, 1f);
final Color oldColor = g.getColor();
g.setColor(Color.RED);
for (Glyph spot : spots) {
if ((clip == null) || clip.intersects(spot.getBounds())) {
spot.renderLine(g); // Draw glyph mean line
}
}
g.setColor(oldColor);
g.setStroke(oldStroke);
}
/**
* Draws the given {@link Operator} if inside the graphics clip bounds.
*
* @param op
* the operator to draw. Note that it must have a position attached, see
* {@link GUIProcessXMLFilter}
* @param drawPorts
* if {@true} will also draw operator ports, otherwise will not draw ports
* @param g2
* the graphics context to draw upon
* @param printing
* if {@code true} we are printing instead of drawing to the screen
*
*/
public void drawOperator(final Operator op, final boolean drawPorts, final Graphics2D g2, final boolean printing) {
Rectangle2D frame = model.getOperatorRect(op);
if (frame == null) {
return;
}
// only draw operator if visible
Rectangle2D opBounds = new Rectangle2D.Double(frame.getX() - 10, frame.getY(), frame.getWidth() + 20,
frame.getHeight());
if (g2.getClipBounds() != null && !g2.getClipBounds().intersects(opBounds)) {
return;
}
renderOperator(op, g2);
renderPorts(op.getInputPorts(), g2, op.isEnabled());
renderPorts(op.getOutputPorts(), g2, op.isEnabled());
// let operator decorators draw
drawOperatorDecorators(op, g2, printing);
}
private static void test(final Graphics2D g) {
for (final Shape clip : clips) {
g.setClip(clip);
if (!g.getClip().equals(clip)) {
System.err.println("Expected clip: " + clip);
System.err.println("Actual clip: " + g.getClip());
System.err.println("bounds="+g.getClip().getBounds2D());
System.err.println("bounds="+g.getClip().getBounds());
status = false;
}
final Rectangle bounds = g.getClipBounds();
if (!clip.equals(bounds)) {
System.err.println("Expected getClipBounds(): " + clip);
System.err.println("Actual getClipBounds(): " + bounds);
status = false;
}
g.getClipBounds(bounds);
if (!clip.equals(bounds)) {
System.err.println("Expected getClipBounds(r): " + clip);
System.err.println("Actual getClipBounds(r): " + bounds);
status = false;
}
if (!clip.getBounds2D().isEmpty() && ((SunGraphics2D) g).clipRegion
.isEmpty()) {
System.err.println("clipRegion should not be empty");
status = false;
}
}
}
/**
* Render the provided box area, using inverted color.
*
* @param box the rectangle whose area is to be rendered
* @param g the graphic context
*/
protected void renderBoxArea (Rectangle box,
Graphics2D g)
{
// Check the clipping
Rectangle clip = g.getClipBounds();
if ((box != null) && ((clip == null) || clip.intersects(box))) {
g.drawRect(box.x, box.y, box.width, box.height);
}
}
public void highlight(Graphics2D g) {
Rectangle bounds = g.getClipBounds();
if(startY > bounds.getMaxY() || startY+height <bounds.getMinY()) {
return;
}
int x = line.getX();
int width = line.getWidth();
g.drawRoundRect(x, startY, width, height, ARC_SIZE, ARC_SIZE);
}
/**
* Draws operator backgrounds and then calls all registered {@link ProcessDrawDecorator}s for
* the annotations render phase.
*
* @param process
* the process to draw the operator backgrounds for
* @param g2
* the graphics context to draw upon
* @param printing
* if {@code true} we are printing instead of drawing to the screen
*/
public void drawOperatorBackgrounds(final ExecutionUnit process, final Graphics2D g2, final boolean printing) {
Graphics2D gBG = (Graphics2D) g2.create();
// draw background of operators
for (Operator op : process.getOperators()) {
Rectangle2D frame = model.getOperatorRect(op);
if (frame == null) {
continue;
}
// only draw background if operator is visisble
Rectangle2D opBounds = new Rectangle2D.Double(frame.getX() - 10, frame.getY(), frame.getWidth() + 20,
frame.getHeight());
if (g2.getClipBounds() != null && !g2.getClipBounds().intersects(opBounds)) {
continue;
}
renderOperatorBackground(op, gBG);
}
// draw connections background for all operators
for (Operator operator : process.getOperators()) {
renderConnectionsBackground(operator.getInputPorts(), operator.getOutputPorts(), gBG);
}
// draw connections background for process
renderConnectionsBackground(process.getInnerSinks(), process.getInnerSources(), gBG);
gBG.dispose();
// let decorators draw
drawPhaseDecorators(process, g2, RenderPhase.OPERATOR_BACKGROUND, printing);
}
/**
* Paints the charts.
*
* @param g graphics context in which to paint
*/
private void paintCharts( final Graphics2D g ) {
if ( chartList.isEmpty() )
return;
// Calculate charts sizes
// Use full width
final int chartWidth = getWidth() - INSETS.left - INSETS.right;
// Vertical space available for a chart:
final int chartVSpace = getHeight() / chartList.size(); // Size > 0
final int chartHeight = chartVSpace - INSETS.top - INSETS.bottom;
if ( chartHeight <= 0 )
return;
final Rect visibleRect = new Rect( getVisibleRect() );
final Rectangle oldClipBounds = g.getClipBounds();
int y = 0;
for ( final Chart< ? > chart : chartList ) {
final Rect r = new Rect( INSETS.left, y + INSETS.top, chartWidth, chartHeight );
g.setClip( oldClipBounds );
g.clipRect( r.x1, r.y1, r.width, r.height );
chart.paint( g, r, visibleRect.intersection( r ) );
y += chartVSpace;
}
g.setClip( oldClipBounds );
}
private JComponent buildBlackPanel() {
return new JPanel(new BorderLayout()) {
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
Rectangle clip = g2.getClipBounds();
g2.setPaint(new GradientPaint(0.0f, 0.0f, new Color(0x666f7f).darker(),
0.0f, getHeight(), new Color(0x262d3d).darker()));
g2.fillRect(clip.x, clip.y, clip.width, clip.height);
}
};
}
/**
* Creates a new PagePainter object.
*
* @param graphics Graphic context
* @param color the default color
* @param coloredVoices true for voices with different colors
* @param linePainting true for painting staff lines
* @param annotated true if annotations are to be drawn
*/
public PagePainter (Graphics graphics,
Color color,
boolean coloredVoices,
boolean linePainting,
boolean annotated)
{
g = (Graphics2D) graphics.create();
oldClip = g.getClipBounds();
this.defaultColor = color;
this.coloredVoices = coloredVoices;
this.linePainting = linePainting;
this.annotated = annotated;
// Use a specific color for all score entities
g.setColor(color);
// Anti-aliasing
g.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// Default font for annotations
g.setFont(basicFont);
}
public void setImage(PlanarImage img) {
image = new DisplayImage(img, true, true);
JLabel imageLabel = new JLabel(image) {
protected void paintChildren(Graphics graphics) {
super.paintChildren(graphics);
if (!(graphics instanceof Graphics2D)) {
throw new RuntimeException("DisplayImagePanel requires Graphics2D.");
}
Graphics2D g2d = (Graphics2D) graphics;
Rectangle clipBounds = g2d.getClipBounds();
if (layers != null) {
ListIterator layerIter = layers.listIterator();
while (layerIter.hasNext()) {
DisplayImageLayer layer = (DisplayImageLayer) layerIter.next();
layer.paintLayer(g2d, clipBounds);
}
}
}
};
imageLabel.setHorizontalAlignment(SwingConstants.LEFT);
imageLabel.setVerticalAlignment(SwingConstants.TOP);
setViewportView(imageLabel);
}
private static void test(final Graphics2D g) {
for (final Shape clip : clips) {
g.setClip(clip);
if (!g.getClip().equals(clip)) {
System.err.println("Expected clip: " + clip);
System.err.println("Actual clip: " + g.getClip());
System.err.println("bounds="+g.getClip().getBounds2D());
System.err.println("bounds="+g.getClip().getBounds());
status = false;
}
final Rectangle bounds = g.getClipBounds();
if (!clip.equals(bounds)) {
System.err.println("Expected getClipBounds(): " + clip);
System.err.println("Actual getClipBounds(): " + bounds);
status = false;
}
g.getClipBounds(bounds);
if (!clip.equals(bounds)) {
System.err.println("Expected getClipBounds(r): " + clip);
System.err.println("Actual getClipBounds(r): " + bounds);
status = false;
}
if (!clip.getBounds2D().isEmpty() && ((SunGraphics2D) g).clipRegion
.isEmpty()) {
System.err.println("clipRegion should not be empty");
status = false;
}
}
}
/**
*
*/
public void paintShape(mxGraphics2DCanvas canvas, String text,
mxCellState state, Map<String, Object> style)
{
mxLightweightLabel textRenderer = mxLightweightLabel
.getSharedInstance();
CellRendererPane rendererPane = canvas.getRendererPane();
Rectangle rect = state.getLabelBounds().getRectangle();
Graphics2D g = canvas.getGraphics();
if (textRenderer != null
&& rendererPane != null
&& (g.getClipBounds() == null || g.getClipBounds().intersects(
rect)))
{
double scale = canvas.getScale();
int x = rect.x;
int y = rect.y;
int w = rect.width;
int h = rect.height;
if (!mxUtils.isTrue(style, mxConstants.STYLE_HORIZONTAL, true))
{
g.rotate(-Math.PI / 2, x + w / 2, y + h / 2);
g.translate(w / 2 - h / 2, h / 2 - w / 2);
int tmp = w;
w = h;
h = tmp;
}
// Replaces the linefeeds with BR tags
if (isReplaceHtmlLinefeeds())
{
text = text.replaceAll("\n", "<br>");
}
// Renders the scaled text
textRenderer.setText(createHtmlDocument(style, text,
(int) Math.round(w / state.getView().getScale()),
(int) Math.round(h / state.getView().getScale())));
textRenderer.setFont(mxUtils.getFont(style, canvas.getScale()));
g.scale(scale, scale);
rendererPane.paintComponent(g, textRenderer, rendererPane,
(int) (x / scale) + mxConstants.LABEL_INSET,
(int) (y / scale) + mxConstants.LABEL_INSET,
(int) (w / scale), (int) (h / scale), true);
}
}
@Override
protected void paintBase(Graphics2D g) {
Rectangle r = this.getBounds();
int esq = (int) (r.width * Criador.getDivisor());
setArea(new Rectangle(esq -2, 0, 4, r.height - 1));
//int dir = r.width - esq;
if (!isSelecionado()) {
g.setColor(Color.GRAY);
g.drawRoundRect(0, 0, r.width - 1, r.height - 1, 10, 10);
g.drawLine(esq, 0, esq, r.height - 1);
g.setColor(Color.BLACK);
getCorParaTexto(g);
Rectangle bkp = g.getClipBounds();
g.clipRect(0, 0, esq - 1, r.height);
g.drawString(getTexto(), (Criador.espaco * 2) + 1, (int) (r.height * 0.72));
g.setClip(bkp);
int re = esq + r.height -5;
g.setColor(CanEdit() ? Color.BLACK : Color.LIGHT_GRAY);
g.fillRect(esq + 4, 4, r.height - 9, r.height - 9);
try {
Color c = util.Utilidades.StringToColor(getTransValor());//new Color(Integer.parseInt(getTransValor()));
g.setColor(c);
} catch (Exception e) {
}
Color tmpc = g.getColor();
String bonito = Integer.toString(tmpc.getRed()) + ", " + Integer.toString(tmpc.getGreen()) + ", " +Integer.toString(tmpc.getBlue())+ ", " +Integer.toString(tmpc.getAlpha());
if (CanEdit()) {
g.fillRect(esq + 5, 5, r.height - 10, r.height -10);
}
// g.setColor(CanEdit() ? Color.BLACK : Color.LIGHT_GRAY);
// g.drawRect(tmp + 4, 4, r.height - 9, r.height -9);
g.clipRect(re, 0, esq - 1, r.height);
getCorParaTexto(g);
g.drawString(bonito, re + (Criador.espaco * 2) + 1, (int) (r.height * 0.72));
g.setClip(bkp);
} else {
super.paintBase(g);
}
}
/**
* Draw arrow polyline
*
* @param points The points
* @param alb The arrow line break
* @param g Graphics2D
*/
public static void drawArrowLine(PointF[] points, ArrowLineBreak alb, Graphics2D g) {
int n = points.length;
PointF aPoint = points[n - 2];
PointF bPoint = points[n - 1];
double U = bPoint.X - aPoint.X;
double V = bPoint.Y - aPoint.Y;
double radian = Math.atan(V / U);
double angle = radian * 180 / Math.PI;
angle = angle + 90;
if (U < 0) {
angle = angle + 180;
}
if (angle >= 360) {
angle = angle - 360;
}
double dx = alb.getArrowHeadLength() * Math.cos(radian) * (1 - alb.getArrowOverhang());
double dy = alb.getArrowHeadLength() * Math.sin(radian) * (1 - alb.getArrowOverhang());
if (angle > 180) {
dx = -dx;
dy = -dy;
}
points[n - 1] = new PointF(bPoint.X - (float) dx, bPoint.Y - (float) dy);
g.setColor(alb.getColor());
float[] dashPattern = getDashPattern(alb.getStyle());
g.setStroke(new BasicStroke(alb.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
drawPolyline(points, g);
//Draw symbol
if (alb.getDrawSymbol()) {
Object rend = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Rectangle clip = g.getClipBounds();
PointF p;
if (clip != null) {
g.setClip(null);
for (int i = 0; i < points.length; i++) {
p = new PointF(points[i].X, points[i].Y);
if (p.X >= clip.x && p.X <= clip.x + clip.width && p.Y >= clip.y && p.Y <= clip.y + clip.height) {
if (i % alb.getSymbolInterval() == 0) {
drawPoint(alb.getSymbolStyle(), p, alb.getSymbolFillColor(), alb.getSymbolColor(),
alb.getSymbolSize(), true, alb.isFillSymbol(), g);
}
}
}
g.setClip(clip);
} else {
for (int i = 0; i < points.length; i++) {
if (i % alb.getSymbolInterval() == 0) {
p = new PointF(points[i].X, points[i].Y);
drawPoint(alb.getSymbolStyle(), p, alb.getSymbolFillColor(), alb.getSymbolColor(),
alb.getSymbolSize(), true, alb.isFillSymbol(), g);
}
}
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend);
}
//Draw arrow
Draw.drawArraw(g, bPoint, angle, alb.getArrowHeadLength(), alb.getArrowHeadWidth(),
alb.getArrowOverhang(), alb.getArrowFillColor(), alb.getArrowOutlineColor());
}
@Override
public Dimension render(Graphics2D graphics)
{
final List<WidgetItem> itemWidgets = overlayManager.getItemWidgets();
final Rectangle originalClipBounds = graphics.getClipBounds();
Widget curClipParent = null;
for (WidgetItem widgetItem : itemWidgets)
{
Widget widget = widgetItem.getWidget();
int interfaceGroup = TO_GROUP(widget.getId());
// Don't draw if this widget isn't one of the allowed nor in tag tab/item tab
if (!interfaceGroups.contains(interfaceGroup) ||
(interfaceGroup == BANK_GROUP_ID
&& (widget.getParentId() == BANK_CONTENT_CONTAINER.getId() || widget.getParentId() == BANK_TAB_CONTAINER.getId())))
{
continue;
}
Widget parent = widget.getParent();
Rectangle parentBounds = parent.getBounds();
Rectangle itemCanvasBounds = widgetItem.getCanvasBounds();
boolean dragging = widgetItem.getDraggingCanvasBounds() != null;
boolean shouldClip;
if (dragging)
{
// If dragging, clip if the dragged item is outside of the parent bounds
shouldClip = itemCanvasBounds.x < parentBounds.x;
shouldClip |= itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x + parentBounds.width;
shouldClip |= itemCanvasBounds.y < parentBounds.y;
shouldClip |= itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y + parentBounds.height;
}
else
{
// Otherwise, we only need to clip the overlay if it intersects the parent bounds,
// since items completely outside of the parent bounds are not drawn
shouldClip = itemCanvasBounds.y < parentBounds.y && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y;
shouldClip |= itemCanvasBounds.y < parentBounds.y + parentBounds.height && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y + parentBounds.height;
shouldClip |= itemCanvasBounds.x < parentBounds.x && itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x;
shouldClip |= itemCanvasBounds.x < parentBounds.x + parentBounds.width && itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x + parentBounds.width;
}
if (shouldClip)
{
if (curClipParent != parent)
{
graphics.setClip(parentBounds);
curClipParent = parent;
}
}
else if (curClipParent != null && curClipParent != parent)
{
graphics.setClip(originalClipBounds);
curClipParent = null;
}
renderItemOverlay(graphics, widgetItem.getId(), widgetItem);
}
return null;
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (splashImg != null) {
int x, y, imgW, imgH;
g2.setColor(BG_COLOR);
g2.fill(g2.getClip());
imgW = splashImg.getWidth(this);
imgH = splashImg.getHeight(this);
x = (getBounds().width - imgW) / 2;
y = (getBounds().height - imgH) / 2;
g2.drawImage(splashImg, x, y, this);
return;
}
Rectangle rBounds = new Rectangle(0, 0, getWidth(), getHeight());
if (actPanel == null || actPanel.getActivity().bgGradient == null
|| actPanel.getActivity().bgGradient.hasTransparency())
super.paintComponent(g);
if (actPanel != null && (actPanel.getActivity().bgGradient != null || actPanel.bgImage != null)) {
RenderingHints rh = g2.getRenderingHints();
g2.setRenderingHints(DEFAULT_RENDERING_HINTS);
if (actPanel.getActivity().bgGradient != null)
actPanel.getActivity().bgGradient.paint(g2, rBounds);
if (actPanel.bgImage != null) {
Rectangle r = new Rectangle(0, 0, actPanel.bgImage.getWidth(this), actPanel.bgImage.getHeight(this));
Rectangle gBounds = g2.getClipBounds();
if (!actPanel.getActivity().tiledBgImg) {
r.setLocation(bgImageOrigin);
if (r.intersects(gBounds)) {
g2.drawImage(actPanel.bgImage, bgImageOrigin.x, bgImageOrigin.y, this);
}
} else {
Utils.tileImage(g2, actPanel.bgImage, rBounds, r, this);
}
}
g2.setRenderingHints(rh);
}
}
private boolean printView(Graphics2D graphics2D, Shape allocation,
View view) {
boolean pageExists = false;
Rectangle clipRectangle = graphics2D.getClipBounds();
Shape childAllocation;
View childView;
if (view.getViewCount() > 0) {
for (int i = 0; i < view.getViewCount(); i++) {
childAllocation = view.getChildAllocation(i, allocation);
if (childAllocation != null) {
childView = view.getView(i);
if (printView(graphics2D, childAllocation, childView)) {
pageExists = true;
}
}
}
}
else {
// I
if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
pageExists = true;
// II
if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) &&
(allocation.intersects(clipRectangle))) {
view.paint(graphics2D, allocation);
}
else {
// III
if (allocation.getBounds().getY() >= clipRectangle.getY()) {
if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) {
view.paint(graphics2D, allocation);
}
else {
// IV
if (allocation.getBounds().getY() < pageEndY) {
pageEndY = allocation.getBounds().getY();
}
}
}
}
}
}
return pageExists;
}
@Override
public void render (Graphics2D g)
{
PaintingParameters painting = PaintingParameters.getInstance();
// Render the picture image
if (painting.isInputPainting()) {
sheet.getPicture()
.render(g);
} else {
// Use a white background
Color oldColor = g.getColor();
g.setColor(Color.WHITE);
Rectangle rect = g.getClipBounds();
g.fill(rect);
g.setColor(oldColor);
}
// Render the recognized score entities?
if (painting.isOutputPainting()) {
if (sheet.getTargetBuilder() != null) {
sheet.getTargetBuilder()
.renderSystems(g); // TODO: Temporary
}
boolean mixed = painting.isInputPainting();
sheet.getPage()
.accept(
new PagePhysicalPainter(
g,
mixed ? Colors.MUSIC_PICTURE : Colors.MUSIC_ALONE,
mixed ? false : painting.isVoicePainting(),
true,
false));
} else {
if (sheet.getTargetBuilder() != null) {
sheet.getTargetBuilder()
.renderWarpGrid(g, true);
}
}
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Rectangle rBounds = new Rectangle(0, 0, getWidth(), getHeight());
if (bgGradient == null || bgGradient.hasTransparency())
super.paintComponent(g);
if (bgGradient != null || bgImage != null) {
RenderingHints rh = g2.getRenderingHints();
g2.setRenderingHints(edu.xtec.jclic.Constants.DEFAULT_RENDERING_HINTS);
if (bgGradient != null)
bgGradient.paint(g2, rBounds);
if (bgImage != null) {
Rectangle r = new Rectangle(0, 0, bgImage.getWidth(this), bgImage.getHeight(this));
Rectangle gBounds = g2.getClipBounds();
if (!tiledBgImg) {
r.setLocation(bgImageOrigin);
if (r.intersects(gBounds)) {
if (scale == 1.0)
g2.drawImage(bgImage, bgImageOrigin.x, bgImageOrigin.y, this);
else {
int w0 = bgImage.getWidth(this);
int h0 = bgImage.getHeight(this);
int w = (int) (scale * w0);
int h = (int) (scale * h0);
g2.drawImage(bgImage, bgImageOrigin.x, bgImageOrigin.y, bgImageOrigin.x + w, bgImageOrigin.y + h, 0, 0,
w0, h0, this);
}
}
} else {
Utils.tileImage(g2, bgImage, rBounds, r, this);
}
}
g2.setRenderingHints(rh);
}
}
@Override
public void paint(Graphics gr) {
super.paint(gr);
Graphics2D g = (Graphics2D) gr;
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Rectangle rect = g.getClipBounds();
int pageIndex = 0;
int row = 0;
int column = 0;
Dimension size = getSize();
if (width * getZoom() < size.getWidth()) {
g.translate((size.getWidth() - width * getZoom()) / 2, 0);
}
AffineTransform at = g.getTransform();
Font font = new Font("Dialog", Font.BOLD, 12);
for (Page page : pages) {
if (page.contains(rect, row, column)) {
if (pageOf != null) {
String text = MessageFormat.format(
GlobalResourcesManager.getString("PageOf"),
pageIndex + 1, printable.getPageCount());
if (!text.equals(pageOf.getText()))
pageOf.setText(text);
}
g.setTransform(at);
String pageNumber = "- " + (pageIndex + 1) + " -";
g.setFont(font);
Rectangle2D fontRect = g.getFontMetrics().getStringBounds(
pageNumber, g);
double left = (pageWidth - fontRect.getWidth() - W_SPACE / zoom) / 2d;
g.setColor(Color.black);
g.drawString(
pageNumber,
(float) (left * zoom + column
* (pageWidth + W_SPACE / zoom) * zoom) + 5,
(float) ((pageHeight + W_SPACE / zoom) * (row + 1) * zoom) - 22);
g.scale(getZoom(), getZoom());
g.translate(column * (pageWidth + W_SPACE / zoom) + 1, row
* (pageHeight + W_SPACE / zoom));
Rectangle2D r = new Rectangle2D.Double(0, 0, page.width,
page.height);
if (reverce)
g.rotate(Math.PI, r.getCenterX(), r.getCenterY());
g.setColor(Color.white);
g.fill(r);
g.setColor(Color.black);
g.draw(r);
r = new Rectangle2D.Double(page.x, page.y, page.imageableWidth,
page.imageableHeight);
try {
g.translate(1, 1);
printable.print(g, pageIndex);
} catch (PrinterException e) {
e.printStackTrace();
}
}
pageIndex++;
column++;
if (column >= columnCount) {
column = 0;
row++;
}
}
}