Java Code Examples for java.awt.Graphics#getClipBounds()
The following examples show how to use
java.awt.Graphics#getClipBounds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SliderUI.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public void paint(Graphics g, JComponent c) { recalculateIfInsetsChanged(); recalculateIfOrientationChanged(); Rectangle clip = g.getClipBounds(); if (!clip.intersects(trackRect) && slider.getPaintTrack()) { calculateGeometry(); } if (slider.getPaintTrack() && clip.intersects(trackRect)) { paintTrack(g); } if (slider.hasFocus() && clip.intersects(focusRect)) { paintFocus(g); } // the ticks are now inside the track so they have to be painted each thumb movement paintTicks(g); // thumb is always painted due to value below thumb paintThumb(g); }
Example 2
Source File: TimelineDepthPanel.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
@Override protected void paintComponent(Graphics g) { Rectangle clip = g.getClipBounds(); int yofs = TimelinePanel.FRAME_HEIGHT - (scrollOffset % TimelinePanel.FRAME_HEIGHT); int start_d = (scrollOffset + clip.y) / TimelinePanel.FRAME_HEIGHT; int end_d = (scrollOffset + clip.y + clip.height) / TimelinePanel.FRAME_HEIGHT; int d_count = end_d - start_d; g.setColor(TimelinePanel.getBackgroundColor()); g.fillRect(0, 0, getWidth(), getHeight()); for (int d = 0; d < d_count; d++) { g.setColor(borderColor); g.drawLine(0, yofs + d * TimelinePanel.FRAME_HEIGHT + 1, getWidth(), yofs + d * TimelinePanel.FRAME_HEIGHT + 1); int curr_d = start_d + d; g.setColor(fontColor); g.drawString(start_d + d == 0 ? "a" : Integer.toString(curr_d), padding, yofs + d * TimelinePanel.FRAME_HEIGHT - padding); } }
Example 3
Source File: JLayeredPane.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Paints this JLayeredPane within the specified graphics context. * * @param g the Graphics context within which to paint */ public void paint(Graphics g) { if(isOpaque()) { Rectangle r = g.getClipBounds(); Color c = getBackground(); if(c == null) c = Color.lightGray; g.setColor(c); if (r != null) { g.fillRect(r.x, r.y, r.width, r.height); } else { g.fillRect(0, 0, getWidth(), getHeight()); } } super.paint(g); }
Example 4
Source File: JLayeredPane.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Paints this JLayeredPane within the specified graphics context. * * @param g the Graphics context within which to paint */ public void paint(Graphics g) { if(isOpaque()) { Rectangle r = g.getClipBounds(); Color c = getBackground(); if(c == null) c = Color.lightGray; g.setColor(c); if (r != null) { g.fillRect(r.x, r.y, r.width, r.height); } else { g.fillRect(0, 0, getWidth(), getHeight()); } } super.paint(g); }
Example 5
Source File: JLayeredPane.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Paints this JLayeredPane within the specified graphics context. * * @param g the Graphics context within which to paint */ public void paint(Graphics g) { if(isOpaque()) { Rectangle r = g.getClipBounds(); Color c = getBackground(); if(c == null) c = Color.lightGray; g.setColor(c); if (r != null) { g.fillRect(r.x, r.y, r.width, r.height); } else { g.fillRect(0, 0, getWidth(), getHeight()); } } super.paint(g); }
Example 6
Source File: JXLabel.java From pgptool with GNU General Public License v3.0 | 6 votes |
/** * Renders the view. * * @param g * the graphics context * @param allocation * the region to render into */ @Override public void paint(Graphics g, Shape allocation) { Rectangle alloc = allocation.getBounds(); // log.fine("aloc:" + alloc + "::" + host.getVisibleRect() + "::" + // host.getBounds()); // view.setSize(alloc.width, alloc.height); // this.width = alloc.width; // this.height = alloc.height; if (g.getClipBounds() == null) { g.setClip(alloc); view.paint(g, allocation); g.setClip(null); } else { // g.translate(alloc.x, alloc.y); view.paint(g, allocation); // g.translate(-alloc.x, -alloc.y); } }
Example 7
Source File: TreeUI.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
protected void paintHorizontalSeparators(Graphics g, JComponent c) { Rectangle clipBounds = g.getClipBounds(); int beginRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y)); int endRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y + clipBounds.height - 1)); if ((beginRow <= -1) || (endRow <= -1)) { return; } for (int i = beginRow; i <= endRow; ++i) { TreePath path = getPathForRow(this.tree, i); if ((path != null) && (path.getPathCount() == 2)) { Rectangle rowBounds = getPathBounds(this.tree, getPathForRow(this.tree, i)); // Draw a line at the top if (rowBounds != null) { g.drawLine(clipBounds.x, rowBounds.y, clipBounds.x + clipBounds.width, rowBounds.y); } } } }
Example 8
Source File: mxUtils.java From blog-codes with Apache License 2.0 | 6 votes |
/** * */ public static void fillClippedRect(Graphics g, int x, int y, int width, int height) { Rectangle bg = new Rectangle(x, y, width, height); try { if (g.getClipBounds() != null) { bg = bg.intersection(g.getClipBounds()); } } catch (Exception e) { log.log(Level.SEVERE, "Failed to compute intersection", e); // FIXME: Getting clipbounds sometimes throws an NPE } g.fillRect(bg.x, bg.y, bg.width, bg.height); }
Example 9
Source File: JLayeredPane.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Paints this JLayeredPane within the specified graphics context. * * @param g the Graphics context within which to paint */ public void paint(Graphics g) { if(isOpaque()) { Rectangle r = g.getClipBounds(); Color c = getBackground(); if(c == null) c = Color.lightGray; g.setColor(c); if (r != null) { g.fillRect(r.x, r.y, r.width, r.height); } else { g.fillRect(0, 0, getWidth(), getHeight()); } } super.paint(g); }
Example 10
Source File: ReflectionPanel.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void paintContent(Graphics g) { if (contentBuffer == null || contentBuffer.getWidth() != contentPane.getWidth() || contentBuffer.getHeight() != contentPane.getHeight()) { if (contentBuffer != null) { contentBuffer.flush(); contentGraphics.dispose(); } contentBuffer = GraphicsUtilities.createCompatibleTranslucentImage( contentPane.getWidth(), contentPane.getHeight()); contentGraphics = contentBuffer.createGraphics(); } Graphics2D g2 = contentGraphics; g2.clipRect(contentPane.getX(), contentPane.getY(), contentPane.getWidth(), contentPane.getHeight()); g2.setComposite(AlphaComposite.Clear); Rectangle clip = g.getClipBounds(); g2.fillRect(clip.x, clip.y, clip.width, clip.height); g2.setComposite(AlphaComposite.SrcOver); g2.setColor(g.getColor()); g2.setFont(g.getFont()); super.paint(g2); g.drawImage(contentBuffer, 0, 0, null); }
Example 11
Source File: RepaintManagerDemo.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(new GradientPaint(0.0f, getHeight() * 0.22f, new Color(0x202737), 0.0f, getHeight() * 0.7f, Color.BLACK, true)); Rectangle clip = g.getClipBounds(); g2.fillRect(clip.x, clip.y, clip.width, clip.height); g2.dispose(); }
Example 12
Source File: SigPainter.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a new {@code SigPainter} object. * * @param g Graphic context * @param scale the global scale */ public SigPainter (Graphics g, Scale scale) { this.g = (Graphics2D) g; this.clip = g.getClipBounds(); // Determine proper music fonts if (scale == null) { musicFontLarge = musicFontSmall = null; musicHeadFontLarge = musicHeadFontSmall = null; } else { // Standard size final int large = scale.getInterline(); musicFontLarge = MusicFont.getBaseFont(large); musicHeadFontLarge = MusicFont.getHeadFont(scale, large); // Smaller size final Integer small = scale.getSmallInterline(); musicFontSmall = (small != null) ? MusicFont.getBaseFont(small) : null; musicHeadFontSmall = (small != null) ? MusicFont.getHeadFont(scale, small) : null; } // Determine lines parameters lineStroke = new BasicStroke( (scale != null) ? scale.getFore() : 2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); stemStroke = new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); ledgerStroke = new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); }
Example 13
Source File: SynthTableUI.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Paints the specified component. * * @param context context for the component being painted * @param g the {@code Graphics} object used for painting * @see #update(Graphics,JComponent) */ protected void paint(SynthContext context, Graphics g) { Rectangle clip = g.getClipBounds(); Rectangle bounds = table.getBounds(); // account for the fact that the graphics has already been translated // into the table's bounds bounds.x = bounds.y = 0; if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 || // this check prevents us from painting the entire table // when the clip doesn't intersect our bounds at all !bounds.intersects(clip)) { paintDropLines(context, g); return; } boolean ltr = table.getComponentOrientation().isLeftToRight(); Point upperLeft = clip.getLocation(); Point lowerRight = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1); int rMin = table.rowAtPoint(upperLeft); int rMax = table.rowAtPoint(lowerRight); // This should never happen (as long as our bounds intersect the clip, // which is why we bail above if that is the case). if (rMin == -1) { rMin = 0; } // If the table does not have enough rows to fill the view we'll get -1. // (We could also get -1 if our bounds don't intersect the clip, // which is why we bail above if that is the case). // Replace this with the index of the last row. if (rMax == -1) { rMax = table.getRowCount()-1; } int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight); int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft); // This should never happen. if (cMin == -1) { cMin = 0; } // If the table does not have enough columns to fill the view we'll get -1. // Replace this with the index of the last column. if (cMax == -1) { cMax = table.getColumnCount()-1; } // Paint the cells. paintCells(context, g, rMin, rMax, cMin, cMax); // Paint the grid. // it is important to paint the grid after the cells, otherwise the grid will be overpainted // because in Synth cell renderers are likely to be opaque paintGrid(context, g, rMin, rMax, cMin, cMax); paintDropLines(context, g); }
Example 14
Source File: NavigatorWindow.java From mars-sim with GNU General Public License v3.0 | 4 votes |
public void paintComponent(Graphics g) { g.setColor(getBackground()); Rectangle r = g.getClipBounds(); g.fillRect(r.x, r.y, r.width, r.height); super.paintComponent(g); }
Example 15
Source File: SwingTerminal.java From jexer with MIT License | 4 votes |
/** * Paint redraws the whole screen. * * @param gr the Swing Graphics context */ public void paint(final Graphics gr) { if (gotFontDimensions == false) { // Lazy-load the text width/height getFontDimensions(gr); /* System.err.println("textWidth " + textWidth + " textHeight " + textHeight); System.err.println("FONT: " + swing.getFont() + " font " + font); */ } if ((swing.getFrame() != null) && (swing.getBufferStrategy() != null) && (SwingUtilities.isEventDispatchThread()) ) { // System.err.println("paint(), skip first paint on swing thread"); return; } int xCellMin = 0; int xCellMax = width; int yCellMin = 0; int yCellMax = height; Rectangle bounds = gr.getClipBounds(); if (bounds != null) { // Only update what is in the bounds xCellMin = textColumn(bounds.x); xCellMax = textColumn(bounds.x + bounds.width); if (xCellMax > width) { xCellMax = width; } if (xCellMin >= xCellMax) { xCellMin = xCellMax - 2; } if (xCellMin < 0) { xCellMin = 0; } yCellMin = textRow(bounds.y); yCellMax = textRow(bounds.y + bounds.height); if (yCellMax > height) { yCellMax = height; } if (yCellMin >= yCellMax) { yCellMin = yCellMax - 2; } if (yCellMin < 0) { yCellMin = 0; } } else { // We need a total repaint reallyCleared = true; } // Prevent updates to the screen's data from the TApplication // threads. synchronized (this) { /* System.err.printf("bounds %s X %d %d Y %d %d\n", bounds, xCellMin, xCellMax, yCellMin, yCellMax); */ for (int y = yCellMin; y < yCellMax; y++) { for (int x = xCellMin; x < xCellMax; x++) { int xPixel = x * textWidth + left; int yPixel = y * textHeight + top; Cell lCell = logical[x][y]; Cell pCell = physical[x][y]; if (!lCell.equals(pCell) || lCell.isBlink() || reallyCleared || (swing.getFrame() == null)) { drawGlyph(gr, lCell, xPixel, yPixel); // Physical is always updated physical[x][y].setTo(lCell); } } } drawCursor(gr); reallyCleared = false; } // synchronized (this) }
Example 16
Source File: SynthTableUI.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Paints the specified component. * * @param context context for the component being painted * @param g the {@code Graphics} object used for painting * @see #update(Graphics,JComponent) */ protected void paint(SynthContext context, Graphics g) { Rectangle clip = g.getClipBounds(); Rectangle bounds = table.getBounds(); // account for the fact that the graphics has already been translated // into the table's bounds bounds.x = bounds.y = 0; if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 || // this check prevents us from painting the entire table // when the clip doesn't intersect our bounds at all !bounds.intersects(clip)) { paintDropLines(context, g); return; } boolean ltr = table.getComponentOrientation().isLeftToRight(); Point upperLeft = clip.getLocation(); Point lowerRight = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1); int rMin = table.rowAtPoint(upperLeft); int rMax = table.rowAtPoint(lowerRight); // This should never happen (as long as our bounds intersect the clip, // which is why we bail above if that is the case). if (rMin == -1) { rMin = 0; } // If the table does not have enough rows to fill the view we'll get -1. // (We could also get -1 if our bounds don't intersect the clip, // which is why we bail above if that is the case). // Replace this with the index of the last row. if (rMax == -1) { rMax = table.getRowCount()-1; } int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight); int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft); // This should never happen. if (cMin == -1) { cMin = 0; } // If the table does not have enough columns to fill the view we'll get -1. // Replace this with the index of the last column. if (cMax == -1) { cMax = table.getColumnCount()-1; } // Paint the cells. paintCells(context, g, rMin, rMax, cMin, cMax); // Paint the grid. // it is important to paint the grid after the cells, otherwise the grid will be overpainted // because in Synth cell renderers are likely to be opaque paintGrid(context, g, rMin, rMax, cMin, cMax); paintDropLines(context, g); }
Example 17
Source File: SeaGlassSliderUI.java From seaglass with Apache License 2.0 | 4 votes |
public void paint(SeaGlassContext context, Graphics g) { recalculateIfInsetsChanged(); recalculateIfOrientationChanged(); Rectangle clip = g.getClipBounds(); if (lastSize == null || !lastSize.equals(slider.getSize())) { calculateGeometry(); } if (paintValue) { FontMetrics fm = SwingUtilities2.getFontMetrics(slider, g); int labelWidth = context.getStyle().getGraphicsUtils(context).computeStringWidth(context, g.getFont(), fm, "" + slider.getValue()); valueRect.x = thumbRect.x + (thumbRect.width - labelWidth) / 2; // For horizontal sliders, make sure value is not painted // outside slider bounds. if (slider.getOrientation() == JSlider.HORIZONTAL) { if (valueRect.x + labelWidth > contentDim.width) { valueRect.x = contentDim.width - labelWidth; } valueRect.x = Math.max(valueRect.x, 0); } g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND)); context.getStyle().getGraphicsUtils(context).paintText(context, g, "" + slider.getValue(), valueRect.x, valueRect.y, -1); } SeaGlassContext subcontext = getContext(slider, Region.SLIDER_TRACK); paintTrack(subcontext, g, trackRect); subcontext.dispose(); subcontext = getContext(slider, Region.SLIDER_THUMB); paintThumb(subcontext, g, thumbRect); subcontext.dispose(); if (slider.getPaintTicks() && clip.intersects(tickRect)) { paintTicks(g); } if (slider.getPaintLabels() && clip.intersects(labelRect)) { paintLabels(g); } }
Example 18
Source File: TaskListTableUI.java From netbeans with Apache License 2.0 | 4 votes |
/** Paint a representation of the <code>table</code> instance * that was set in installUI(). * * (copy & paste from BasicTableUI) */ public void paint(Graphics g, JComponent c) { Rectangle clip = g.getClipBounds(); Rectangle bounds = table.getBounds(); // account for the fact that the graphics has already been translated // into the table's bounds bounds.x = bounds.y = 0; if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 || // this check prevents us from painting the entire table // when the clip doesn't intersect our bounds at all !bounds.intersects(clip)) { return; } Point upperLeft = clip.getLocation(); Point lowerRight = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1); int rMin = table.rowAtPoint(upperLeft); int rMax = table.rowAtPoint(lowerRight); // This should never happen (as long as our bounds intersect the clip, // which is why we bail above if that is the case). if (rMin == -1) { rMin = 0; } // If the table does not have enough rows to fill the view we'll get -1. // (We could also get -1 if our bounds don't intersect the clip, // which is why we bail above if that is the case). // Replace this with the index of the last row. if (rMax == -1) { rMax = table.getRowCount()-1; } boolean ltr = table.getComponentOrientation().isLeftToRight(); int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight); int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft); // This should never happen. if (cMin == -1) { cMin = 0; } // If the table does not have enough columns to fill the view we'll get -1. // Replace this with the index of the last column. if (cMax == -1) { cMax = table.getColumnCount()-1; } // Paint the grid. paintGrid(g, rMin, rMax, cMin, cMax); // Paint the cells. paintCells(g, rMin, rMax, cMin, cMax); }
Example 19
Source File: DisplayCanvas.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
@Override public void paint(final Graphics g) { if (null == g) return; try { synchronized (lock_paint) { lock_paint.lock(); } // ensure proper positioning g.translate(0, 0); // ints! final Rectangle clipRect = g.getClipBounds(); final Displayable active = display.getActive(); final int c_alphas = display.getDisplayChannelAlphas(); final Layer active_layer = display.getLayer(); final List<Layer> layers = active_layer.getParent().getColorCueLayerRange(active_layer); final Graphics2D g2d = (Graphics2D)g; // prepare the canvas for the srcRect and magnification final AffineTransform at_original = g2d.getTransform(); atc.setToIdentity(); atc.scale(magnification, magnification); atc.translate(-srcRect.x, -srcRect.y); at_original.preConcatenate(atc); if (null != offscreen && dragging) invalidateVolatile(); // to update the active at least render(g, active, active_layer, layers, c_alphas, at_original, clipRect); g2d.setTransform(at_original); g2d.setStroke(this.stroke); // debug buckets //if (null != display.getLayer().root) display.getLayer().root.paint(g2d, srcRect, magnification, Color.red); //if (null != display.getLayer().getParent().lbucks.get(display.getLayer()).root) display.getLayer().getParent().lbucks.get(display.getLayer()).root.paint(g2d, srcRect, magnification, Color.blue); // reset to identity g2d.setTransform(new AffineTransform()); // reset to 1.0 thickness g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); // paint brush outline for AreaList, or fast-marching area if (mouse_in && null != active && AreaContainer.class.isInstance(active)) { switch (ProjectToolbar.getToolId()) { case ProjectToolbar.BRUSH: final int brushSize = ProjectToolbar.getBrushSize(); g.setColor(active.getColor()); g.drawOval((int)((xMouse -srcRect.x -brushSize/2)*magnification), (int)((yMouse - srcRect.y -brushSize/2)*magnification), (int)(brushSize * magnification), (int)(brushSize * magnification)); break; case ProjectToolbar.PENCIL: case ProjectToolbar.WAND: final Composite co = g2d.getComposite(); if (IJ.isWindows()) g2d.setColor(Color.yellow); else g2d.setXORMode(Color.yellow); // XOR on yellow for best contrast g2d.drawRect((int)((xMouse -srcRect.x -Segmentation.fmp.width/2) * magnification), (int)((yMouse -srcRect.y -Segmentation.fmp.height/2) * magnification), (int)(Segmentation.fmp.width * magnification), (int)(Segmentation.fmp.height * magnification)); g2d.setComposite(co); // undo XOR mode break; } } final Roi roi = imp.getRoi(); if (null != roi) { roi.draw(g); } // Mathias code: if (null != freehandProfile) { freehandProfile.paint(g, magnification, srcRect, true); if(noCursor == null) noCursor = Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(1,1,BufferedImage.TYPE_BYTE_BINARY), new Point(0,0), "noCursor"); } } catch (final Exception e) { Utils.log2("DisplayCanvas.paint(Graphics) Error: " + e); IJError.print(e); } finally { synchronized (lock_paint) { lock_paint.unlock(); } } }
Example 20
Source File: Ruler.java From openAGV with Apache License 2.0 | 4 votes |
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Rectangle drawHere = g.getClipBounds(); // Point translation = (Point) drawingView.getTranslation().clone(); Point translation = new Point((int) -drawingView.getDrawingToViewTransform().getTranslateX(), (int) -drawingView.getDrawingToViewTransform().getTranslateY()); // if we scroll right the translation isn't incremented by default // we use the translation of the visible rect instead int visibleRectX = drawingView.getVisibleRect().x + STANDARD_TRANSLATION; if (STANDARD_TRANSLATION == translation.x) { translation.x = visibleRectX; } Graphics2D g2d = (Graphics2D) g; g2d.setFont(new Font("Arial", Font.PLAIN, 10)); // i translated int translated; // i normalized to decimal int draw; int drawOld = 0; // draw translated int drawTranslated; String translatedAsString; String lastIndex; // base line g2d.drawLine(0, SIZE - 1, getWidth(), SIZE - 1); for (int i = drawHere.x; i < getWidth(); i += 10) { translated = translateValue(i, translation); translatedAsString = Integer.toString(translated); lastIndex = translatedAsString.substring(translatedAsString.length() - 1); int decimal = Integer.parseInt(lastIndex); { // These steps are neccessary to guarantee lines are drawn // at every pixel. It always rounds i to a decimal, so the modulo // operators work draw = i; if (translated < 0) { draw += decimal; } else { draw -= decimal; } drawTranslated = translateValue(draw, translation); // draw has to be incremented by 1, otherwise the drawn lines // are wrong by 1 pixel draw++; } if (drawTranslated % (10 * scaleFactor) == 0) { g2d.drawLine(draw, SIZE - 1, draw, SIZE - 4); } if (drawTranslated % (50 * scaleFactor) == 0) { g2d.drawLine(draw, SIZE - 1, draw, SIZE - 7); } if (drawTranslated % (100 * scaleFactor) == 0) { g2d.drawLine(draw, SIZE - 1, draw, SIZE - 11); int value = (int) (drawTranslated / scaleFactor) * (int) horizontalRulerScale; String textValue = Integer.toString(value); if (scaleFactor < 0.06) { if (value % 5000 == 0) { g2d.drawString(textValue, value == 0 ? draw - 2 : draw - 8, 9); } } else if ((draw - drawOld) < 31) { if (value % 500 == 0) { g2d.drawString(textValue, value == 0 ? draw - 2 : draw - 8, 9); } } else { g2d.drawString(textValue, value == 0 ? draw - 2 : draw - 8, 9); } drawOld = draw; } } }