Example usage for java.awt Graphics2D fillRect

List of usage examples for java.awt Graphics2D fillRect

Introduction

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

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

From source file:ClipBetweenRectangleEllipse2D.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;

    Graphics2D g2 = (Graphics2D) g;

    int w = getSize().width;
    int h = getSize().height;
    Ellipse2D e = new Ellipse2D.Float(w / 4.0f, h / 4.0f, w / 2.0f, h / 2.0f);
    g2.setClip(e);/*from ww w .  jav a2s .  co m*/

    g2.setColor(Color.red);
    g2.fillRect(0, 0, w, h);

    Rectangle r = new Rectangle(w / 2, h / 2, w / 2, h / 2);
    g2.clip(r);

    g2.setColor(Color.green);
    g2.fillRect(0, 0, w, h);

}

From source file:picocash.components.mode.ModePanel.java

@Override
public void paint(Graphics2D g, Object object, int width, int height) {
    g.setColor(PANEL_BACKGROUND_COLOR);//w  w  w. j a v a  2 s. c o  m
    g.fillRect(0, 0, width, height);

    g.setColor(borderColor);
    g.drawRect(0, 0, width - 1, height - 1);
}

From source file:costumetrade.common.verify.ImageVerification.java

public Pair<String, BufferedImage> create() {
    int x = 0, fontHeight = 0, codeY = 0;
    int red = 0, green = 0, blue = 0;

    x = width / (codeCount + 2);//?
    fontHeight = height - 2;//
    codeY = height - 4;/*from   w  w w .  java 2 s  . c o  m*/

    // ?buffer
    BufferedImage buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = buffImg.createGraphics();
    // ?
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, width, height);
    // 
    g.setFont(new Font("Arial", Font.PLAIN, fontHeight));

    for (int i = 0; i < lineCount; i++) {

        int xs = RandomUtils.nextInt(0, width);
        int ys = RandomUtils.nextInt(0, height);
        int xe = xs + RandomUtils.nextInt(0, width / 8);
        int ye = ys + RandomUtils.nextInt(0, height / 8);
        red = RandomUtils.nextInt(0, 255);
        green = RandomUtils.nextInt(0, 255);
        blue = RandomUtils.nextInt(0, 255);
        g.setColor(new Color(red, green, blue));
        g.drawLine(xs, ys, xe, ye);
    }

    // randomCode???
    StringBuilder randomCode = new StringBuilder();
    // ?codeCount??
    for (int i = 0; i < codeCount; i++) {
        String strRand = String.valueOf(codeSequence[RandomUtils.nextInt(0, codeSequence.length)]);
        // ????
        red = RandomUtils.nextInt(0, 255);
        green = RandomUtils.nextInt(0, 255);
        blue = RandomUtils.nextInt(0, 255);
        g.setColor(new Color(red, green, blue));
        g.drawString(strRand, (i + 1) * x, codeY);
        // ??
        randomCode.append(strRand);
    }
    // ????Session
    return new Pair<String, BufferedImage>(randomCode.toString(), buffImg);
}

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]);/*from  w w w. j  ava  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:Main.java

public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();

    // Create the gradient paint
    GradientPaint paint = new GradientPaint(0, 0, start, width, height, end, true);

    // we need to cast to Graphics2D for this operation
    Graphics2D g2d = (Graphics2D) g;

    // save the old paint
    Paint oldPaint = g2d.getPaint();

    // set the paint to use for this operation
    g2d.setPaint(paint);/* w w  w.j  a  va  2 s .  c o m*/

    // fill the background using the paint
    g2d.fillRect(0, 0, width, height);

    // restore the original paint
    g2d.setPaint(oldPaint);

    super.paint(g);
}

From source file:org.gitools.ui.app.actions.file.ExportScaleImageAction.java

@Override
public void actionPerformed(ActionEvent e) {

    Heatmap hm = getHeatmap();/*  w w w  .j  a va2 s. c o m*/
    final HeatmapLayer layer = hm.getLayers().getTopLayer();
    Decorator cd = layer.getDecorator();

    final ITextFormatter textFormatter = layer.getShortFormatter();
    final INumericColorScale scale = cd != null ? cd.getScale() : null;

    if (scale == null) {
        return;
    }

    final ScaleExportWizard wz = new ScaleExportWizard();
    wz.setTitle("Export scale to image ...");
    wz.getSavePage()
            .setFileNameWithoutExtension(FilenameUtils.getName(getSelectedEditor().getName()) + "-scale");
    wz.getSavePage().setFolder(Settings.get().getLastExportPath());
    wz.getSavePage().setFormats(new FileFormat[] { FileFormats.PNG, FileFormats.JPG });
    wz.setScale(scale);

    WizardDialog dlg = new WizardDialog(Application.get(), wz);
    dlg.open();
    if (dlg.isCancelled()) {
        return;
    }

    Settings.get().setLastExportPath(wz.getSavePage().getFolder());

    final File file = wz.getSavePage().getPathAsFile();
    if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
    }

    final String formatExtension = wz.getSavePage().getFormat().getExtension();

    JobThread.execute(Application.get(), new JobRunnable() {
        @Override
        public void run(IProgressMonitor monitor) {
            try {
                monitor.begin("Exporting scale to image ...", 1);
                monitor.info("File: " + file.getName());

                ColorScaleDrawer drawer = new ColorScaleDrawer(scale, textFormatter);

                Dimension size = drawer.getSize();
                size.width = wz.getScaleSize();

                BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);

                Graphics2D g = bi.createGraphics();
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, size.width, size.height);

                drawer.draw(g, new Rectangle(new Point(), size), new Rectangle(new Point(), size),
                        layer.getName());

                ImageIO.write(bi, formatExtension, file);

            } catch (Exception ex) {
                monitor.exception(ex);
            }
        }
    });

    Application.get().showNotification("Image created.", 2000);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

private static Paint createTransparentCheckeredPaint(Color color, int checkerSize) {
    int s = checkerSize;
    BufferedImage bufferedImage = new BufferedImage(2 * s, 2 * s, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = bufferedImage.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
            RenderingHints.VALUE_ANTIALIAS_ON);

    Color c1 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .8));
    Color c2 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .2));
    g2.setStroke(new BasicStroke(0));
    g2.setPaint(c2);/* w ww  . ja v  a 2  s  . c o  m*/
    g2.setColor(c2);
    g2.fillRect(0, 0, s, s);
    g2.fillRect(s, s, s, s);
    g2.setPaint(c1);
    g2.setColor(c1);
    g2.fillRect(0, s, s, s);
    g2.fillRect(s, 0, s, s);

    // paint with the texturing brush
    Rectangle2D rect = new Rectangle2D.Double(0, 0, 2 * s, 2 * s);
    return new TexturePaint(bufferedImage, rect);
}

From source file:org.n52.server.io.DiagramGenerator.java

/**
 * Creates a time series chart diagram and writes it to the OutputStream.
 *//*  w  w w.  ja  v a 2s .  c  o  m*/
public void producePresentation(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options,
        FileOutputStream out, boolean compress) throws OXFException, IOException {

    // render features:
    int width = options.getWidth();
    int height = options.getHeight();
    Calendar begin = Calendar.getInstance();
    begin.setTimeInMillis(options.getBegin());
    Calendar end = Calendar.getInstance();
    end.setTimeInMillis(options.getEnd());

    DiagramRenderer renderer = new DiagramRenderer(false);

    JFreeChart diagramChart = renderer.renderChart(entireCollMap, options, begin, end, compress);
    diagramChart.removeLegend();

    // draw chart into image:
    BufferedImage diagramImage = new BufferedImage(width, height, TYPE_INT_RGB);
    Graphics2D chartGraphics = diagramImage.createGraphics();
    chartGraphics.setColor(Color.white);
    chartGraphics.fillRect(0, 0, width, height);

    diagramChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height));

    JPEGImageWriteParam p = new JPEGImageWriteParam(null);
    p.setCompressionMode(JPEGImageWriteParam.MODE_DEFAULT);
    write(diagramImage, FORMAT, out);
}

From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer.java

/**
 * The resulting IVisualization shows a chart which consists a TimeSeries for each FeatureOfInterest
 * contained in the observationCollection.
 *///from  www  . ja  v a 2s.c om
public IVisualization renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon,
        int width, int height) {
    JFreeChart chart = renderChart(observationCollection, paramCon);

    Plot plot = chart.getPlot();

    // draw plot into image:

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    Graphics2D g = image.createGraphics();

    g.setColor(Color.white);
    g.fillRect(0, 0, width, height);

    plot.draw(g, new Rectangle2D.Float(0, 0, width, height), null, null, null);

    return new StaticVisualization(image);
}