Search in sources :

Example 96 with BasicStroke

use of java.awt.BasicStroke in project deltahex-java by exbin.

the class DefaultCodeAreaPainter method paintCursor.

@Override
public void paintCursor(@Nonnull Graphics g) {
    if (!worker.getCodeArea().hasFocus()) {
        return;
    }
    DefaultCodeAreaCaret caret = (DefaultCodeAreaCaret) ((CaretCapable) worker).getCaret();
    Rectangle cursorRect = getPositionRect(caret.getDataPosition(), caret.getCodeOffset(), caret.getSection());
    if (cursorRect == null) {
        return;
    }
    Rectangle clipBounds = g.getClipBounds();
    Rectangle mainAreaRect = getMainAreaRect();
    Rectangle intersection = mainAreaRect.intersection(cursorRect);
    boolean cursorVisible = caret.isCursorVisible() && !intersection.isEmpty();
    if (cursorVisible) {
        g.setClip(intersection);
        DefaultCodeAreaCaret.CursorRenderingMode renderingMode = caret.getRenderingMode();
        g.setColor(colors.cursor);
        switch(renderingMode) {
            case PAINT:
                {
                    g.fillRect(intersection.x, intersection.y, intersection.width, intersection.height);
                    break;
                }
            case XOR:
                {
                    g.setXORMode(colors.background);
                    g.fillRect(intersection.x, intersection.y, intersection.width, intersection.height);
                    g.setPaintMode();
                    break;
                }
            case NEGATIVE:
                {
                    g.fillRect(cursorRect.x, cursorRect.y, cursorRect.width, cursorRect.height);
                    g.setColor(colors.negativeCursor);
                    BinaryData codeAreaData = worker.getCodeArea().getData();
                    int row = (cursorRect.y + scrollPosition.getScrollRowOffset() - dataViewY) / rowHeight;
                    int scrolledX = cursorRect.x + scrollPosition.getScrollCharPosition() * characterWidth + scrollPosition.getScrollCharOffset();
                    int posY = dataViewY + (row + 1) * rowHeight - subFontSpace - scrollPosition.getScrollRowOffset();
                    long dataPosition = caret.getDataPosition();
                    if (viewMode != CodeAreaViewMode.CODE_MATRIX && caret.getSection() == BasicCodeAreaSection.TEXT_PREVIEW.getSection()) {
                        int charPos = (scrolledX - previewRelativeX) / characterWidth;
                        if (dataPosition >= dataSize) {
                            break;
                        }
                        char[] previewChars = new char[1];
                        byte[] data = new byte[maxCharLength];
                        if (maxCharLength > 1) {
                            int charDataLength = maxCharLength;
                            if (dataPosition + maxCharLength > dataSize) {
                                charDataLength = (int) (dataSize - dataPosition);
                            }
                            if (codeAreaData == null) {
                                previewChars[0] = ' ';
                            } else {
                                codeAreaData.copyToArray(dataPosition, data, 0, charDataLength);
                                String displayString = new String(data, 0, charDataLength, charset);
                                if (!displayString.isEmpty()) {
                                    previewChars[0] = displayString.charAt(0);
                                }
                            }
                        } else {
                            if (charMappingCharset == null || charMappingCharset != charset) {
                                buildCharMapping(charset);
                            }
                            if (codeAreaData == null) {
                                previewChars[0] = ' ';
                            } else {
                                previewChars[0] = charMapping[codeAreaData.getByte(dataPosition) & 0xFF];
                            }
                        }
                        int posX = previewRelativeX + charPos * characterWidth - scrollPosition.getScrollCharPosition() * characterWidth - scrollPosition.getScrollCharOffset();
                        // if (characterRenderingMode == CharacterRenderingMode.LINE_AT_ONCE) {
                        // g.drawChars(previewChars, 0, 1, posX, posY);
                        // } else {
                        drawCenteredChar(g, previewChars, 0, characterWidth, posX, posY);
                    // }
                    } else {
                        int charPos = (scrolledX - dataViewX) / characterWidth;
                        int byteOffset = computePositionByte(charPos);
                        int codeCharPos = computeFirstCodeCharacterPos(byteOffset);
                        char[] rowChars = new char[codeType.getMaxDigitsForByte()];
                        if (codeAreaData != null && dataPosition < dataSize) {
                            byte dataByte = codeAreaData.getByte(dataPosition);
                            CodeAreaUtils.byteToCharsCode(dataByte, codeType, rowChars, 0, hexCharactersCase);
                        } else {
                            Arrays.fill(rowChars, ' ');
                        }
                        int posX = dataViewX + codeCharPos * characterWidth - scrollPosition.getScrollCharPosition() * characterWidth - scrollPosition.getScrollCharOffset();
                        int charsOffset = charPos - codeCharPos;
                        // if (characterRenderingMode == CharacterRenderingMode.LINE_AT_ONCE) {
                        // g.drawChars(lineChars, charsOffset, 1, posX + (charsOffset * characterWidth), posY);
                        // } else {
                        drawCenteredChar(g, rowChars, charsOffset, characterWidth, posX + (charsOffset * characterWidth), posY);
                    // }
                    }
                    break;
                }
            default:
                throw new IllegalStateException("Unexpected rendering mode " + renderingMode.name());
        }
    }
    // Paint mirror cursor
    if (viewMode == CodeAreaViewMode.DUAL && showMirrorCursor) {
        Rectangle mirrorCursorRect = getMirrorCursorRect(caret.getDataPosition(), caret.getSection());
        if (mirrorCursorRect != null) {
            intersection = mainAreaRect.intersection(mirrorCursorRect);
            boolean mirrorCursorVisible = !intersection.isEmpty();
            if (mirrorCursorVisible) {
                g.setClip(intersection);
                g.setColor(colors.cursor);
                Graphics2D g2d = (Graphics2D) g.create();
                Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 2 }, 0);
                g2d.setStroke(dashed);
                g2d.drawRect(mirrorCursorRect.x, mirrorCursorRect.y, mirrorCursorRect.width - 1, mirrorCursorRect.height - 1);
            }
        }
    }
    g.setClip(clipBounds);
}
Also used : BasicStroke(java.awt.BasicStroke) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Rectangle(java.awt.Rectangle) BinaryData(org.exbin.utils.binary_data.BinaryData) Graphics2D(java.awt.Graphics2D)

Example 97 with BasicStroke

use of java.awt.BasicStroke in project beast2 by CompEvol.

the class Arrow method draw.

@Override
public void draw(Graphics2D g, JPanel panel) {
    g.setStroke(new BasicStroke(m_nPenWidth));
    g.setColor(m_pencolor);
    g.setColor(Color.gray);
    GeneralPath path = new GeneralPath();
    path.moveTo(m_x, m_y);
    path.curveTo(m_x + 20, m_y, m_x + m_w - 40, m_y + m_h, m_x + m_w, m_y + m_h);
    g.draw(path);
    drawLabel(g);
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath)

Example 98 with BasicStroke

use of java.awt.BasicStroke in project h2database by h2database.

the class RailroadImages method setStroke.

private static void setStroke(Graphics2D g, int i) {
    if (i == 0) {
        g.setColor(Color.WHITE);
        g.setStroke(new BasicStroke(STROKE * 3));
    } else {
        g.setColor(Color.BLACK);
        g.setStroke(new BasicStroke(STROKE));
    }
}
Also used : BasicStroke(java.awt.BasicStroke)

Example 99 with BasicStroke

use of java.awt.BasicStroke in project com.revolsys.open by revolsys.

the class TriangulationVisualization method displayTin.

public static void displayTin(final TriangulatedIrregularNetwork tin) {
    BoundingBox boundingBox = tin.getBoundingBox();
    double mapWidth = boundingBox.getWidth() + 4;
    double mapHeight = boundingBox.getHeight() + 4;
    if (mapHeight > mapWidth) {
        boundingBox = boundingBox.expand((mapHeight - mapWidth) / 2, 0);
        mapWidth = boundingBox.getWidth();
    } else if (mapHeight < mapWidth) {
        boundingBox = boundingBox.expand(0, (mapWidth - mapHeight) / 2);
        mapHeight = boundingBox.getHeight();
    }
    final AffineTransform transform = new AffineTransform();
    final double pixelsPerXUnit = 800 / mapWidth;
    final double pixelsPerYUnit = -800 / mapHeight;
    final double originX = boundingBox.getMinX() - 2;
    final double originY = boundingBox.getMaxY() + 2;
    transform.concatenate(AffineTransform.getScaleInstance(pixelsPerXUnit, pixelsPerYUnit));
    transform.concatenate(AffineTransform.getTranslateInstance(-originX, -originY));
    SwingUtilities.invokeLater(() -> {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(850, 850);
        frame.setVisible(true);
        frame.setLayout(new BorderLayout());
        frame.add(new JPanel() {

            /**
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void paint(final Graphics graphics) {
                final Graphics2D g2 = (Graphics2D) graphics;
                g2.setPaint(WebColors.White);
                g2.fillRect(0, 0, 800, 800);
                final AffineTransform oldTransform = g2.getTransform();
                g2.transform(transform);
                synchronized (tin) {
                    g2.setStroke(new BasicStroke((float) (1 / pixelsPerXUnit)));
                    tin.forEachTriangle((triangle) -> {
                        g2.setPaint(WebColors.newAlpha(WebColors.Aqua, 25));
                        g2.fill(triangle);
                        g2.setColor(WebColors.Black);
                        g2.draw(triangle);
                    });
                    if (showCircumcircle) {
                        tin.forEachTriangle((triangle) -> {
                            final double x1 = triangle.getX(1);
                            final double x2 = triangle.getY(1);
                            final double[] centre = Triangle.getCircumcentreCoordinates(triangle.getX(0), triangle.getY(0), x1, x2, triangle.getX(2), triangle.getY(2));
                            final double centreX = centre[0];
                            final double centreY = centre[1];
                            final double size = 7;
                            final double half = size / 2;
                            final Ellipse2D.Double shape = new Ellipse2D.Double(centreX - half / pixelsPerXUnit, centreY - half / pixelsPerXUnit, size / pixelsPerXUnit, size / pixelsPerXUnit);
                            g2.setPaint(WebColors.Yellow);
                            g2.fill(shape);
                            g2.setColor(WebColors.Black);
                            g2.draw(shape);
                        });
                        tin.forEachTriangle((triangle) -> {
                            final double x1 = triangle.getX(1);
                            final double x2 = triangle.getY(1);
                            final double[] centre = Triangle.getCircumcentreCoordinates(triangle.getX(0), triangle.getY(0), x1, x2, triangle.getX(2), triangle.getY(2));
                            final Circle circle = triangle.getCircumcircle();
                            final double centreX = centre[0];
                            final double centreY = centre[1];
                            final double radius = circle.getRadius();
                            final Ellipse2D ellipse = new Ellipse2D.Double(centreX - radius, centreY - radius, radius * 2, radius * 2);
                            g2.setColor(WebColors.Red);
                            g2.draw(ellipse);
                        });
                    }
                // for (int vertexIndex = 0; vertexIndex < tin.getVertexCount(); vertexIndex++) {
                // final Point point = tin.getVertex(vertexIndex);
                // final double x = point.getX();
                // final double y = point.getY();
                // final double size = 7;
                // final double half = size / 2;
                // final Ellipse2D.Double shape = new Ellipse2D.Double(x - half / pixelsPerXUnit,
                // y - half / pixelsPerXUnit, size / pixelsPerXUnit, size / pixelsPerXUnit);
                // g2.setPaint(WebColors.Yellow);
                // g2.fill(shape);
                // g2.setColor(WebColors.Black);
                // g2.draw(shape);
                // }
                // {
                // final Point point = pointHolder.getValue();
                // if (point != null) {
                // g2.setPaint(WebColors.Red);
                // final double x = point.getX();
                // final double y = point.getY();
                // final double size = 9;
                // final double half = size / 2;
                // g2.fill(new Ellipse2D.Double(x - half / pixelsPerXUnit, y - half / pixelsPerXUnit,
                // size / pixelsPerXUnit, size / pixelsPerXUnit));
                // }
                // }
                // g2.setTransform(oldTransform);
                // g2.translate(0, 800);
                // g2.setPaint(WebColors.Green);
                // for (int vertexIndex = 0; vertexIndex < tin.getVertexCount(); vertexIndex++) {
                // final Point point = tin.getVertex(vertexIndex);
                // final double x = point.getX();
                // final double y = point.getY();
                // final int screenX = (int)((x + 2) * pixelsPerXUnit);
                // final int screenY = (int)((y + 2) * pixelsPerYUnit);
                // g2.drawString(Integer.toString(vertexIndex), screenX + 5, screenY);
                // }
                }
            }
        }, BorderLayout.CENTER);
    });
}
Also used : BasicStroke(java.awt.BasicStroke) LasPointCloud(com.revolsys.elevation.cloud.las.LasPointCloud) PathResource(com.revolsys.spring.resource.PathResource) AffineTransform(java.awt.geom.AffineTransform) ArrayList(java.util.ArrayList) WebColors(com.revolsys.awt.WebColors) List(java.util.List) SwingUtilities(javax.swing.SwingUtilities) TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) Ellipse2D(java.awt.geom.Ellipse2D) Triangle(com.revolsys.geometry.model.Triangle) Graphics2D(java.awt.Graphics2D) PointCloud(com.revolsys.elevation.cloud.PointCloud) Circle(com.revolsys.geometry.model.impl.Circle) Graphics(java.awt.Graphics) QuadEdgeDelaunayTinBuilder(com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder) BasicStroke(java.awt.BasicStroke) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JPanel(javax.swing.JPanel) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) JPanel(javax.swing.JPanel) Circle(com.revolsys.geometry.model.impl.Circle) Ellipse2D(java.awt.geom.Ellipse2D) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BoundingBox(com.revolsys.geometry.model.BoundingBox) AffineTransform(java.awt.geom.AffineTransform)

Example 100 with BasicStroke

use of java.awt.BasicStroke in project com.revolsys.open by revolsys.

the class TabClosableTitle method paintComponent.

@Override
protected void paintComponent(final Graphics graphics) {
    super.paintComponent(graphics);
    final Graphics2D graphics2d = (Graphics2D) graphics;
    graphics2d.setStroke(new BasicStroke(2));
    graphics2d.setColor(Color.BLACK);
    final int x1 = getWidth() - getInsets().right - 9;
    final int y1 = getInsets().top + 4;
    final int x2 = x1 + 7;
    final int y2 = y1 + 7;
    graphics2d.drawLine(x1, y1, x2, y2);
    graphics2d.drawLine(x1, y2, x2, y1);
}
Also used : BasicStroke(java.awt.BasicStroke) Graphics2D(java.awt.Graphics2D)

Aggregations

BasicStroke (java.awt.BasicStroke)571 Graphics2D (java.awt.Graphics2D)179 Color (java.awt.Color)164 Stroke (java.awt.Stroke)141 GradientPaint (java.awt.GradientPaint)96 Test (org.junit.Test)93 Rectangle2D (java.awt.geom.Rectangle2D)71 Paint (java.awt.Paint)64 Font (java.awt.Font)61 Point (java.awt.Point)47 Line2D (java.awt.geom.Line2D)47 BufferedImage (java.awt.image.BufferedImage)43 Shape (java.awt.Shape)39 Point2D (java.awt.geom.Point2D)38 AffineTransform (java.awt.geom.AffineTransform)34 JFreeChart (org.jfree.chart.JFreeChart)34 Rectangle (java.awt.Rectangle)27 Ellipse2D (java.awt.geom.Ellipse2D)27 RectangleInsets (org.jfree.ui.RectangleInsets)27 NumberAxis (org.jfree.chart.axis.NumberAxis)25