Example usage for com.google.gwt.widgetideas.graphics.client GWTCanvas setFillStyle

List of usage examples for com.google.gwt.widgetideas.graphics.client GWTCanvas setFillStyle

Introduction

In this page you can find the example usage for com.google.gwt.widgetideas.graphics.client GWTCanvas setFillStyle.

Prototype

public void setFillStyle(Color color) 

Source Link

Document

Set the current Fill Style to the specified color.

Usage

From source file:com.google.caliper.cloud.client.BoxPlot.java

License:Apache License

public Widget create(int style, double max, MeasurementSet measurementSet, boolean useNanos) {
    /*//from  w w  w.  j  a va  2  s .  co  m
     * Compute the five displayed values of the box plot from the measurements.
     *
     * a = minimum
     * b = lower quartile
     * c = median
     * d = upper quartile
     * e = maximum
     */
    List<Double> measurements = useNanos ? measurementSet.getMeasurementsRaw()
            : measurementSet.getMeasurementUnits();
    Collections.sort(measurements);
    int numMeasurements = measurements.size();
    double unitsPerPixel = max / maxWidth;
    int quartile = numMeasurements / 4;
    double a = measurements.get(0) / unitsPerPixel;
    double b = measurements.get(quartile) / unitsPerPixel;
    double c = measurements.get(numMeasurements / 2) / unitsPerPixel;
    double d = measurements.get(numMeasurements - (quartile > 0 ? quartile : 1)) / unitsPerPixel;
    double e = measurements.get(numMeasurements - 1) / unitsPerPixel;

    Color[] colors = Colors.forStyle(style);
    Color dark = colors[0];
    Color medium = colors[1];
    Color light = colors[2];

    GWTCanvas canvas = new GWTCanvas(maxWidth, maxHeight);
    if (numMeasurements > 3) {
        canvas.setFillStyle(dark);
        canvas.fillRect(0, 0, b, maxHeight);

        canvas.setFillStyle(medium);
        canvas.fillRect(b, 0, (c - b), maxHeight);

        canvas.setFillStyle(light);
        canvas.fillRect(c, 0, (d - c), maxHeight);

    } else {
        canvas.setFillStyle(dark);
        canvas.fillRect(0, 0, c, maxHeight);
    }

    if (numMeasurements > 1) {
        int quarterHeight = maxHeight / 4;
        int halfHeight = maxHeight / 2;

        canvas.setStrokeStyle(light);
        canvas.setLineWidth(1);

        // the |-- of the |--[ | ]---|
        if ((int) (a - b) != 0) {
            canvas.beginPath();
            canvas.moveTo(a, quarterHeight);
            canvas.lineTo(a, maxHeight - quarterHeight);
            canvas.stroke();
            canvas.beginPath();
            canvas.moveTo(a, halfHeight);
            canvas.lineTo(b, halfHeight);
            canvas.stroke();
        }

        // the ---| of the |--[ | ]---|
        if ((int) (e - d) != 0) {
            canvas.setStrokeStyle(dark);
            canvas.beginPath();
            canvas.moveTo(d, halfHeight);
            canvas.lineTo(e, halfHeight);
            canvas.stroke();
            canvas.beginPath();
            canvas.moveTo(e, quarterHeight);
            canvas.lineTo(e, maxHeight - quarterHeight);
            canvas.stroke();
        }
    }

    return canvas;
}

From source file:org.utgenome.gwt.ribbon.client.ui.WeaverCanvas.java

License:Apache License

public WeaverCanvas() {

    int width = 800;
    int height = 500;
    mainPanel = new AbsolutePanel();
    mainPanel.setPixelSize(width, height);
    canvas1 = new GWTCanvas(width, height);
    canvas2 = new GWTCanvas(width, height);

    //      CanvasGradient gr = canvas1.createRadialGradient(45, 45, 10, 52, 50, 30);
    //      gr.addColorStop(0, new Color(0xA7, 0XD3, 0x0C));
    //      gr.addColorStop(0.9f, new Color(0x01, 0x9F, 0x62, 0f));
    //      gr.addColorStop(1, new Color("rgba(1,159,98,0)"));
    //canvas1.setFillStyle(gr);
    canvas1.setFillStyle(new Color(200, 0, 0, 0.7f));
    canvas1.fillRect(0, 0, 150, 150);/*ww w.j a  v a 2  s.  co m*/

    canvas2.setFillStyle(new Color(100, 200, 250));
    canvas2.fillRect(30, 20, 200, 150);
    canvas2.setFillStyle(new Color(200, 50, 240, 0.4f));
    canvas2.fillRect(130, 40, 150, 40);

    mainPanel.add(canvas2, 0, 0);
    mainPanel.add(canvas1, 0, 0);

    TabPanel tabPanel = new TabPanel();

    RoundCornerFrame tab1 = new RoundCornerFrame("336699", 0.8f, 4);
    RoundCornerFrame tab2 = new RoundCornerFrame("336699", 0.8f, 4);
    tab2.setFrameColor("336699", 0.3f);

    Label tl = new Label("Track Groups");
    Style.fontColor(tl, "white");
    Style.bold(tl);
    Style.nowrap(tl);
    Label tl2 = new Label("Tracks");
    Style.fontColor(tl2, "white");
    Style.bold(tl2);
    Style.nowrap(tl2);

    tab1.setWidget(tl);
    tab2.setWidget(tl2);
    tabPanel.add(new SimplePanel(), tab1);
    tabPanel.add(new SimplePanel(), tab2);

    mainPanel.add(tabPanel, 100, 100);

    final RoundCornerFrame f = new RoundCornerFrame("3E5A77", 0.8f, 4);
    final FixedWidthLabel l = new FixedWidthLabel("Hello World. Nice to meet you. Welcome to UTGB Toolkit",
            200);
    Style.fontSize(l, 12);
    Style.fontColor(l, "white");
    //Style.semiTransparentBackground(l, "3E5A77", 0.8f);
    f.setWidget(l);

    //      l.setPixelSize(200, 19);
    //      //l.setStyleName("label");
    //      DOM.setStyleAttribute(l.getElement(), "backgroundImage", "url(utgb-core/transparent?color=3E5A77&opacity=0.7)");
    //      DOM.setStyleAttribute(l.getElement(), "textOverflow", "ellipsis");
    //      DOM.setStyleAttribute(l.getElement(), "overflow", "hidden");
    //      DOM.setStyleAttribute(l.getElement(), "whiteSpace", "nowrap");
    //      DOM.setStyleAttribute(l.getElement(), "display", "block");
    //DOM.setStyleAttribute(l.getElement(), "color", "white");

    mainPanel.add(f, 10, 10);

    final GWTCanvas canvas = new GWTCanvas(100, 100);
    canvas.setFillStyle(new Color("rgba(100, 100, 255, 0.5)"));
    canvas.fillRect(10, 20, 50, 30);

    mainPanel.add(canvas, 40, 40);

    Button scale = new Button("scale");
    scale.addClickHandler(new ClickHandler() {

        boolean on = false;

        public void onClick(ClickEvent event) {
            Style.scaleXwithAnimation(canvas, on ? 5 : 1.5, 0.5);
            on = !on;
        }
    });

    mainPanel.add(scale, 100, 300);

    initWidget(mainPanel);
}