Example usage for java.awt Graphics2D drawLine

List of usage examples for java.awt Graphics2D drawLine

Introduction

In this page you can find the example usage for java.awt Graphics2D drawLine.

Prototype

public abstract void drawLine(int x1, int y1, int x2, int y2);

Source Link

Document

Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

Usage

From source file:org.uva.itast.blended.omr.OMRUtils.java

public static void logFrame(PageImage pageImage, PagePoint topleft, PagePoint topright, PagePoint bottomleft,
        PagePoint bottomright, Color color, String label) {
    if (topleft == null || topright == null || bottomleft == null || bottomright == null)
        return;//from w  w w.j  a v  a  2s  .  c o m

    Graphics2D g = pageImage.getReportingGraphics();
    AffineTransform t = g.getTransform();
    g.setColor(color);
    g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
            new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0));

    // Point framePxUL=pageImage.toPixels(topleft.getX(), topleft.getY());
    // Point framePxUR=pageImage.toPixels(topright.getX(), topright.getY());
    // Point framePxBL=pageImage.toPixels(bottomleft.getX(),
    // bottomleft.getY());
    // Point framePxBR=pageImage.toPixels(bottomright.getX(),
    // bottomright.getY());

    g.drawLine(topleft.getXpx(), topleft.getYpx(), topright.getXpx(), topright.getYpx());
    g.drawLine(topleft.getXpx(), topleft.getYpx(), bottomleft.getXpx(), bottomleft.getYpx());
    g.drawLine(topright.getXpx(), topright.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    g.drawLine(bottomleft.getXpx(), bottomleft.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    if (label != null) {
        g.drawString(label, topleft.getXpx(), topleft.getYpx());
    }
}

From source file:br.ufrgs.enq.jcosmo.ui.SigmaProfileAreaPanel.java

public void addProfile(String label, double[] sigma, double[] area, int rgb) {
    int n = sigma.length;
    XYSeries comp = new XYSeries(label, false, false);

    // charges represent the center of the segments
    comp.add(sigma[0], area[0]);// www . java 2 s .  c o m
    for (int j = 1; j < n; ++j) {
        double dsigma = (sigma[j] - sigma[j - 1]) / 2;
        comp.add(sigma[j] - dsigma, area[j]);
        comp.add(sigma[j] + dsigma + 1e-6, area[j]);
    }
    dataset.addSeries(comp);
    int series = dataset.getSeriesCount() - 1;

    int patternSize = 6;
    BufferedImage bi = new BufferedImage(patternSize, patternSize, BufferedImage.TYPE_INT_RGB);
    Rectangle r = new Rectangle(0, 0, patternSize, patternSize);
    Graphics2D big = bi.createGraphics();
    big.setColor(new Color(rgb, rgb, rgb));
    big.fillRect(0, 0, patternSize, patternSize);

    int pattern = series % 4;
    if (pattern == 1 || pattern == 3) {
        big.setColor(Color.WHITE);
        big.drawLine(0, patternSize / 2, patternSize, patternSize / 2);
    }
    if (pattern == 2 || pattern == 3) {
        big.setColor(Color.WHITE);
        big.drawLine(patternSize / 2, 0, patternSize / 2, patternSize);
    }

    TexturePaint paint = new TexturePaint(bi, r);
    sigmaProfilePlot.getRenderer().setSeriesPaint(series, paint); // new Color(rgb, rgb, rgb));
}

From source file:TexturedPanel.java

/**
 * Creates a new TexturePaint using the provided colors.
 *//*from   ww w .  j  av  a  2 s. c  om*/
private void setupDefaultPainter(Color foreground, Color background) {
    if (foreground == null || background == null) {
        ourPainter = null;
        return;
    }

    BufferedImage buff = new BufferedImage(6, 6, BufferedImage.TYPE_INT_ARGB_PRE);

    Graphics2D g2 = buff.createGraphics();

    g2.setColor(background);
    g2.fillRect(0, 0, 6, 6);

    g2.setColor(foreground);
    g2.drawLine(0, 2, 6, 2);
    g2.drawLine(0, 5, 6, 5);

    ourPainter = new TexturePaint(buff, new Rectangle(0, 0, 6, 6));

    g2.dispose();
}

From source file:edu.umd.cfar.lamp.chronicle.ChronicleRuler.java

private void drawLine(int x1, int y1, int x2, int y2, Paint p, Stroke stroke, PPaintContext paintContext) {
    Graphics2D g2 = paintContext.getGraphics();
    Paint old = g2.getPaint();//  w w w . ja v a  2  s .c  o  m
    Stroke oldS = g2.getStroke();
    g2.setPaint(p);
    g2.setStroke(stroke);
    g2.drawLine(x1, y1, x2, y2);
    g2.setPaint(old);
    g2.setStroke(oldS);
}

From source file:org.tsho.dmc2.core.chart.TrajectoryRenderer.java

private void drawItem(Graphics2D g2, int item, int x, int y) {

    if (connectWithLines) {
        if (item > 0) {
            g2.drawLine(x, y, prevX, prevY);
        }//w  ww.jav  a  2s .co m
        prevX = x;
        prevY = y;
    }

    if (bigDots) {
        g2.fillRect(x - 1, y - 1, 3, 3);
    } else {
        g2.fillRect(x, y, 1, 1);
    }
}

From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java

/**
 * Note:  assumption is that featureList is sorted by pStart position.
 *
 * @param featureList//from  w  w w. j av a 2s  . c  o m
 * @param context
 * @param trackRectangle
 * @param track
 */
@Override
public void render(List<IGVFeature> featureList, RenderContext context, Rectangle trackRectangle, Track track) {

    double origin = context.getOrigin();
    double locScale = context.getScale();

    // TODO -- use enum instead of string "Color"
    if ((featureList != null) && !featureList.isEmpty()) {

        // Create a graphics object to draw font names.  Graphics are not cached
        // by font, only by color, so its neccessary to create a new one to prevent
        // affecting other tracks.
        Font font = FontManager.getFont(track.getFontSize());
        Graphics2D fontGraphics = (Graphics2D) context.getGraphic2DForColor(Color.BLACK).create();

        if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) {
            fontGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        }
        fontGraphics.setFont(font);

        //determine whether to show flanking regions
        PreferenceManager prefs = PreferenceManager.getInstance();
        boolean shouldShowFlankingRegions = prefs
                .getAsBoolean(PreferenceManager.SAM_SHOW_JUNCTION_FLANKINGREGIONS);

        // Track coordinates
        double trackRectangleX = trackRectangle.getX();
        double trackRectangleMaxX = trackRectangle.getMaxX();

        SpliceJunctionFeature selectedFeature = (SpliceJunctionFeature) ((FeatureTrack) track)
                .getSelectedFeature();

        // Start of Roche-Tessella modification
        if (track.getAutoScale()) {
            Frequency f = new Frequency();
            List<Integer> scores = new ArrayList<Integer>();

            for (IGVFeature feature : featureList) {
                SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
                f.addValue(junctionFeature.getScore());
                scores.add((int) junctionFeature.getScore());
            }

            Collections.sort(scores);
            Collections.reverse(scores);
            for (int s : scores) {
                if (f.getCumPct(s) < 0.99) {
                    maxDepth = s;
                    break;
                }
            }

        }
        // End of Roche-Tessella modification

        for (IGVFeature feature : featureList) {
            SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
            //if same junction as selected feature, highlight
            boolean shouldHighlight = false;
            if (selectedFeature != null && selectedFeature.isSameJunction(junctionFeature)) {
                setHighlightFeature(junctionFeature);
                shouldHighlight = true;
            }

            // Get the pStart and pEnd of the entire feature.  at extreme zoom levels the
            // virtual pixel value can be too large for an int, so the computation is
            // done in double precision and cast to an int only when its confirmed its
            // within the field of view.
            int flankingStart = junctionFeature.getStart();
            int flankingEnd = junctionFeature.getEnd();

            int junctionStart = junctionFeature.getJunctionStart();
            int junctionEnd = junctionFeature.getJunctionEnd();

            double virtualPixelStart = Math.round((flankingStart - origin) / locScale);
            double virtualPixelEnd = Math.round((flankingEnd - origin) / locScale);

            double virtualPixelJunctionStart = Math.round((junctionStart - origin) / locScale);
            double virtualPixelJunctionEnd = Math.round((junctionEnd - origin) / locScale);

            // If the any part of the feature fits in the
            // Track rectangle draw it
            if ((virtualPixelEnd >= trackRectangleX) && (virtualPixelStart <= trackRectangleMaxX)) {

                //
                int displayPixelEnd = (int) Math.min(trackRectangleMaxX, virtualPixelEnd);
                int displayPixelStart = (int) Math.max(trackRectangleX, virtualPixelStart);

                float depth = junctionFeature.getJunctionDepth();
                Color color = feature.getColor();

                drawFeature((int) virtualPixelStart, (int) virtualPixelEnd, (int) virtualPixelJunctionStart,
                        (int) virtualPixelJunctionEnd, depth, trackRectangle, context, feature.getStrand(),
                        junctionFeature, shouldHighlight, color, shouldShowFlankingRegions);
            }
        }

        //draw a central horizontal line
        Graphics2D g2D = context.getGraphic2DForColor(COLOR_CENTERLINE);
        g2D.drawLine((int) trackRectangleX, (int) trackRectangle.getCenterY(), (int) trackRectangleMaxX,
                (int) trackRectangle.getCenterY());

    }
}

From source file:krasa.cpu.CpuUsagePanel.java

/**
 * it will probably be better synchronized, not sure
 *//*from  w ww  .  java2  s .  c  o  m*/
private synchronized void draw(Graphics g, Image bufferedImage) {
    UIUtil.drawImage(g, bufferedImage, 0, 0, null);
    if (UIUtil.isJreHiDPI((Graphics2D) g) && !UIUtil.isUnderDarcula()) {
        Graphics2D g2 = (Graphics2D) g.create(0, 0, getWidth(), getHeight());
        float s = JBUI.sysScale(g2);
        g2.scale(1 / s, 1 / s);
        g2.setColor(UIUtil.isUnderIntelliJLaF() ? Gray.xC9 : Gray.x91);
        g2.drawLine(0, 0, (int) (s * getWidth()), 0);
        g2.scale(1, 1);
        g2.dispose();
    }
}

From source file:de.dakror.villagedefense.game.entity.Entity.java

public void drawBump(Graphics2D g, boolean above) {
    if (bump == null || (!hovered && !clicked))
        return;// w w w .j  a  va  2  s.  c om

    Color oldColor = g.getColor();
    g.setColor(clicked ? Color.black : Color.darkGray);
    if (above) {
        g.drawLine((int) x + bump.x, (int) y + bump.y, (int) x + bump.x, (int) y + bump.y + bump.height); // left
        g.drawLine((int) x + bump.x, (int) y + bump.y + bump.height, (int) x + bump.x + bump.width,
                (int) y + bump.y + bump.height); // bottom
        g.drawLine((int) x + bump.x + bump.width, (int) y + bump.y, (int) x + bump.x + bump.width,
                (int) y + bump.y + bump.height); // right
    } else {
        g.drawLine((int) x + bump.x, (int) y + bump.y, (int) x + bump.x + bump.width, (int) y + bump.y); // top
    }
    g.setColor(oldColor);
}

From source file:IconDemoApp.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();

    g2d.setColor(Color.WHITE);//from   w w  w.j a  v a 2 s .  co m
    g2d.fillRect(x + 1, y + 1, width - 2, height - 2);

    g2d.setColor(Color.BLACK);
    g2d.drawRect(x + 1, y + 1, width - 2, height - 2);

    g2d.setColor(Color.RED);

    g2d.setStroke(stroke);
    g2d.drawLine(x + 10, y + 10, x + width - 10, y + height - 10);
    g2d.drawLine(x + 10, y + height - 10, x + width - 10, y + 10);

    g2d.dispose();
}

From source file:FieldValidator.java

@Override
public void paint(Graphics g, JComponent c) {
    super.paint(g, c);

    JLayer jlayer = (JLayer) c;
    JFormattedTextField ftf = (JFormattedTextField) jlayer.getView();
    if (!ftf.isEditValid()) {
        Graphics2D g2 = (Graphics2D) g.create();

        // Paint the red X.
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        int w = c.getWidth();
        int h = c.getHeight();
        int s = 8;
        int pad = 4;
        int x = w - pad - s;
        int y = (h - s) / 2;
        g2.setPaint(Color.red);//from   www.j a v  a 2 s .  c  o  m
        g2.fillRect(x, y, s + 1, s + 1);
        g2.setPaint(Color.white);
        g2.drawLine(x, y, x + s, y + s);
        g2.drawLine(x, y + s, x + s, y);

        g2.dispose();
    }
}