Example usage for java.awt TexturePaint TexturePaint

List of usage examples for java.awt TexturePaint TexturePaint

Introduction

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

Prototype

public TexturePaint(BufferedImage txtr, Rectangle2D anchor) 

Source Link

Document

Constructs a TexturePaint object.

Usage

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (mTimeFrame == null) {
        renderNoInfoView(g);/* ww  w  .ja v  a2  s  .  co  m*/
    } else {
        updateSize();
        LongRange startRange = mTimeFrame.getStartRange();
        LongRange arriveRange = mTimeFrame.getArriveRange();
        HashMap<LongRange, TimeSpan> startRanges = mTimeFrame
                .startTimespansToRangesMap(AnyTribe.getSingleton());
        HashMap<LongRange, TimeSpan> arriveRanges = mTimeFrame.arriveTimespansToRangesMap(null);
        long minValue = startRange.getMinimumLong();
        long maxValue = arriveRange.getMaximumLong();
        Graphics2D g2d = (Graphics2D) g;
        g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3)));
        g2d.fillRect(0, 0, getWidth(), getHeight());

        //draw frame around the entire range
        renderRange(new LongRange(startRange.getMinimumLong(), arriveRange.getMaximumLong()), startRange,
                arriveRange, false, false, g2d, null, popupInfo);
        g2d.setColor(Constants.DS_BACK);
        popupInfo.clear();
        //fill start range
        renderRange(startRange, startRange, arriveRange, true, false, g2d, null, popupInfo);
        //fill arrive range
        renderRange(arriveRange, startRange, arriveRange, false, true, g2d, null, popupInfo);
        Paint p = g2d.getPaint();
        Iterator<LongRange> rangeKeys = startRanges.keySet().iterator();
        while (rangeKeys.hasNext()) {
            LongRange currentRange = rangeKeys.next();

            TimeSpan spanForRange = startRanges.get(currentRange);
            if (spanForRange != null) {
                if (spanForRange.isValidAtEveryDay()) {
                    g2d.setPaint(new TexturePaint(DAILY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                } else if (spanForRange.isValidAtExactTime()) {
                    g2d.setPaint(new TexturePaint(EXACT_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                } else {
                    g2d.setPaint(new TexturePaint(ONE_DAY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
                }
            }
            renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo);
        }

        Composite c = g2d.getComposite();
        rangeKeys = arriveRanges.keySet().iterator();
        while (rangeKeys.hasNext()) {
            LongRange currentRange = rangeKeys.next();
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
            g2d.setPaint(new TexturePaint(ARRIVE_FRAME_FILL, new Rectangle(0, 0, 3, 3)));
            TimeSpan spanForRange = arriveRanges.get(currentRange);
            renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo);
        }
        g2d.setComposite(c);
        g2d.setPaint(p);
        renderDayMarkers(minValue, maxValue, g2d);
        renderPopup(popupInfo, g2d);
    }
}

From source file:net.sqs2.omr.result.export.chart.ChartImageWriter.java

private void setSectionPaint(DefaultCategoryDataset dataSet, CategoryPlot plot) {

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);/*from  w w  w . j ava  2 s  .c  o m*/
    renderer.setItemLabelAnchorOffset(10);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (this.itemBackgroundImages != null && 0 < this.itemBackgroundImages.length) {
        int index = 0;
        Paint outlinePaint = Color.BLACK;
        Stroke outlineStroke = new BasicStroke(1.0f);
        for (@SuppressWarnings("unused")
        Object key : dataSet.getColumnKeys()) {
            int imageIndex = index % this.itemBackgroundImages.length;
            BufferedImage texture = this.itemBackgroundImages[imageIndex];
            Rectangle2D anchor = new Rectangle2D.Double(0, 0, texture.getWidth(), texture.getHeight());
            TexturePaint fillPaint = new TexturePaint(texture, anchor);
            renderer.setSeriesFillPaint(index, fillPaint);
            renderer.setSeriesPaint(index, fillPaint);
            renderer.setSeriesOutlinePaint(index, outlinePaint);
            renderer.setSeriesOutlineStroke(index, outlineStroke);

            // renderer.setBasePaint(fillPaint);
            // renderer.setBaseOutlineStroke(outlineStroke);
            // renderer.setBaseOutlinePaint(outlinePaint);
        }

    }
}

From source file:TexturedPanel.java

/**
 * Creates a new TexturePaint using the provided colors and texture map.
 *//*from   w  w  w. j  a va  2  s.  co m*/
private void setupTexturePainter(Color foreground, Color background, boolean[][] texture, int scale) {
    if (texture == null || texture.length < 1 || texture[0].length < 1) {
        setupDefaultPainter(foreground, background);
        return;
    }

    else if (foreground == null || background == null) {
        ourPainter = null;
        return;
    }

    scale = Math.max(1, scale);
    int w = texture[0].length;
    int h = texture.length;

    BufferedImage buff = new BufferedImage(w * scale, h * scale, BufferedImage.TYPE_INT_ARGB_PRE);

    Graphics2D g2 = buff.createGraphics();

    g2.setColor(background);
    g2.fillRect(0, 0, w * scale, h * scale);

    g2.setColor(foreground);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            try {
                if (texture[i][j])
                    g2.fillRect(j * scale, i * scale, scale, scale);
            }
            // g2.drawLine(j, i, j, i); }
            catch (ArrayIndexOutOfBoundsException aob) {
            }
        }
    }

    ourPainter = new TexturePaint(buff, new Rectangle(0, 0, w * scale, h * scale));

    g2.dispose();
}

From source file:TexturedPanel.java

/**
 * Creates a new TexturePaint using the provided image.
 *///w  w w  .  j a  va 2 s . c  o m
private void setupImagePainter(Image texture) {
    if (texture == null) {
        ourPainter = null;
        return;
    }

    int w = texture.getWidth(this);
    int h = texture.getHeight(this);

    if (w <= 0 || h <= 0) {
        ourPainter = null;
        return;
    }

    BufferedImage buff = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);

    Graphics2D g2 = buff.createGraphics();
    g2.drawImage(texture, 0, 0, this);
    ourPainter = new TexturePaint(buff, new Rectangle(0, 0, w, h));

    g2.dispose();
}

From source file:net.sqs2.omr.result.export.chart.ChartImageWriter.java

private void setSectionPaint(PieDataset dataSet, PiePlot piePlot) {
    Paint outlinePaint = Color.BLACK;
    Stroke outlineStroke = new BasicStroke(1.0f);

    if (this.itemBackgroundImages != null && 0 < this.itemBackgroundImages.length) {
        int index = 0;
        for (Object key : dataSet.getKeys()) {
            int imageIndex = index % this.itemBackgroundImages.length;
            BufferedImage texture = this.itemBackgroundImages[imageIndex];
            Rectangle2D anchor = new Rectangle2D.Double(0, 0, texture.getWidth(), texture.getHeight());
            TexturePaint fillPaint = new TexturePaint(texture, anchor);
            piePlot.setSectionPaint((Comparable<?>) key, fillPaint);
            piePlot.setSectionOutlinePaint((Comparable<?>) key, outlinePaint);
            piePlot.setSectionOutlineStroke((Comparable<?>) key, outlineStroke);
            index++;//from   w w w.j a  va2 s. co  m
        }
    }
    piePlot.setOutlineVisible(true);
    piePlot.setOutlinePaint(outlinePaint);
    piePlot.setOutlineStroke(outlineStroke);
    piePlot.setSectionOutlinesVisible(true);
    piePlot.setBaseSectionOutlinePaint(outlinePaint);
    piePlot.setBaseSectionOutlineStroke(outlineStroke);
}

From source file:TexturedPanel.java

/**
 * Creates a new TexturePaint using the provided icon.
 *//*from   w  ww  .j  a va 2 s.c o m*/
private void setupIconPainter(Icon texture) {
    if (texture == null) {
        ourPainter = null;
        return;
    }

    int w = texture.getIconWidth();
    int h = texture.getIconHeight();

    if (w <= 0 || h <= 0) {
        ourPainter = null;
        return;
    }

    BufferedImage buff = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);

    Graphics2D g2 = buff.createGraphics();
    texture.paintIcon(this, g2, 0, 0);
    ourPainter = new TexturePaint(buff, new Rectangle(0, 0, w, h));

    g2.dispose();
}

From source file:de.bund.bfr.jung.JungUtils.java

private static Paint mixWith(Paint paint, Color mix) {
    if (paint instanceof Color) {
        Color c = (Color) paint;

        return new Color((c.getRed() + mix.getRed()) / 2, (c.getGreen() + mix.getGreen()) / 2,
                (c.getBlue() + mix.getBlue()) / 2, (c.getAlpha() + mix.getAlpha()) / 2);
    } else if (paint instanceof TexturePaint) {
        BufferedImage texture = ((TexturePaint) paint).getImage();
        BufferedImage mixed = new BufferedImage(texture.getWidth(), texture.getHeight(), texture.getType());

        for (int x = 0; x < texture.getWidth(); x++) {
            for (int y = 0; y < texture.getHeight(); y++) {
                mixed.setRGB(x, y, ((Color) mixWith(new Color(texture.getRGB(x, y)), mix)).getRGB());
            }/*  w  w w .j  a  v a 2  s .  c o m*/
        }

        return new TexturePaint(mixed, new Rectangle(mixed.getWidth(), mixed.getHeight()));
    } else {
        return paint;
    }
}

From source file:com.juanhg.cicloc.cicloCApplet.java

private void initSimulation() {

    Point2D[] nullArray = new Point2D[0];

    //Crear modelo
    model = new cicloCModel(T1, T2, Vmin, Vmax, N, isHot);

    calculateLimits();// ww  w .j  a  v a 2s  . c o m

    // Inicializar charts
    chartPV = new Grafica(nullArray, "", "", "V", "P", false, Color.BLUE, 1f, false);
    chartPV.agregarGrafica(nullArray, "", Color.RED, 1f, false);
    chartPV.setRangeAxis(VLimits, PLimits);

    chartUV = new Grafica(nullArray, "", "", "V", "U", false, Color.BLUE, 1f, false);
    chartUV.agregarGrafica(nullArray, "", Color.RED, 1f, false);
    chartUV.setRangeAxis(VLimits, ULimits);

    chartTV = new Grafica(nullArray, "", "", "V", "T", false, Color.BLUE, 1f, false);
    chartTV.agregarGrafica(nullArray, "", Color.RED, 1f, false);
    chartTV.setRangeAxis(VLimits, TLimits);

    chartPT = new Grafica(nullArray, "", "", "T", "P", false, Color.BLUE, 1f, false);
    chartPT.agregarGrafica(nullArray, "", Color.RED, 1f, false);
    chartPT.setRangeAxis(TLimits, PLimits);

    chartST = new Grafica(nullArray, "", "", "T", "S", false, Color.BLUE, 1f, false);
    chartST.agregarGrafica(nullArray, "", Color.RED, 1f, false);
    chartST.setRangeAxis(TLimits, SLimits);

    chartUT = new Grafica(nullArray, "", "", "T", "U", false, Color.BLUE, 1f, false);
    chartUT.agregarGrafica(nullArray, "", Color.RED, 1f, false);
    chartUT.setRangeAxis(TLimits, ULimits);

    chartPiston = new Grafica(nullArray, "", "", "", "", false, Color.BLUE, 1f, false);
    chartPiston.setRangeAxis(getPistonX0() - 0.5, (getPistonX1() + 0.5), 0, 10);
    chartPiston.fijaFondo(Color.WHITE);
    chartPiston.setAxisVisible(false);

    chartTermo = new Grafica(nullArray, "", "", "", "", false, Color.BLUE, 1f, false);
    chartTermo.setRangeAxis(0, 10, 0, 10);
    chartTermo.fijaFondo(Color.WHITE);
    chartTermo.setAxisVisible(false);

    tBulb = new Time();
    tLED = new Time();

    //Load Images
    waterTextureImage = loadImage(waterTexture);
    texture = new TexturePaint(waterTextureImage, new Rectangle(0, 0, 300, 200));
    termoImage = loadImage(termo);

    //Set Images  
    chartTermo.setImageAtPoint(termoImage, 5, 5);

    tAnnotation = new XYTextAnnotation("-", 5, 5);
    tAnnotation.setPaint(Color.RED);
    tAnnotation.setFont(new Font(null, 10, 40));
    chartTermo.setAnnotation(tAnnotation);

    this.drawPiston();

    //Actualize panels
    updatePanels();
    repaint();
}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

/**Render default view if there is no timeframe yet*/
private void renderNoInfoView(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3)));
    g2d.fillRect(0, 0, getWidth(), getHeight());
    Font f = g2d.getFont().deriveFont(Font.BOLD, 14.0f);
    g2d.setFont(f);/*from   ww  w  .j  ava  2 s .com*/
    Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Kein Zeitfenster aktiv", g);
    int dx = 10;
    if (getWidth() > bounds.getWidth()) {
        dx = (int) Math.rint((getWidth() - bounds.getWidth()) / 2);
    }

    int dy = 10;
    if (getHeight() > bounds.getHeight()) {
        dy = (int) Math.rint((getHeight() - bounds.getHeight()) / 2);
    }
    g2d.setColor(Color.black);
    g2d.drawString("Kein Zeitfenster aktiv", dx, dy);
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static Paint mixColors(Color backgroundColor, List<Color> colors, List<Double> alphas,
        boolean checkedInsteadOfStriped) {
    double rb = backgroundColor.getRed() / 255.0;
    double gb = backgroundColor.getGreen() / 255.0;
    double bb = backgroundColor.getBlue() / 255.0;
    double ab = backgroundColor.getAlpha() / 255.0;
    List<Color> cs = new ArrayList<>();

    for (int i = 0; i < colors.size(); i++) {
        double alpha = alphas.get(i);

        if (alpha > 0.0) {
            double r = colors.get(i).getRed() / 255.0 * alpha + rb * (1 - alpha);
            double g = colors.get(i).getGreen() / 255.0 * alpha + gb * (1 - alpha);
            double b = colors.get(i).getBlue() / 255.0 * alpha + bb * (1 - alpha);
            double a = colors.get(i).getAlpha() / 255.0 * alpha + ab * (1 - alpha);

            cs.add(new Color((float) r, (float) g, (float) b, (float) a));
        }/*  w ww  .  ja va 2 s  .  co m*/
    }

    if (cs.isEmpty()) {
        return backgroundColor;
    } else if (cs.size() == 1) {
        return cs.get(0);
    }

    BufferedImage img;
    int size = cs.size() * (checkedInsteadOfStriped ? EDGE_TEXTURE_SIZE : NODE_TEXTURE_SIZE);

    if (checkedInsteadOfStriped) {
        img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

        for (int x = 0; x < size; x++) {
            for (int y = 0; y < size; y++) {
                img.setRGB(x, y, cs.get((x / EDGE_TEXTURE_SIZE + y / EDGE_TEXTURE_SIZE) % cs.size()).getRGB());
            }
        }
    } else {
        img = new BufferedImage(size, 1, BufferedImage.TYPE_INT_ARGB);

        for (int x = 0; x < size; x++) {
            img.setRGB(x, 0, cs.get(x / NODE_TEXTURE_SIZE).getRGB());
        }
    }

    return new TexturePaint(img, new Rectangle(img.getWidth(), img.getHeight()));
}