Example usage for java.awt Graphics setColor

List of usage examples for java.awt Graphics setColor

Introduction

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

Prototype

public abstract void setColor(Color c);

Source Link

Document

Sets this graphics context's current color to the specified color.

Usage

From source file:com.jcraft.weirdx.XPixmap.java

Graphics getGraphics(GC gc, int mask) {
    Graphics graphics = imgg;
    if (gc == currentGC && gc.time == gctime && (mask & ~gmask) == 0) {
        return graphics;
    }/* w w  w  .  ja  v a2s.c om*/
    gctime = gc.time;
    currentGC = gc;
    gmask = mask;
    if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) {
        java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask());
        if (rec == null) {
            return graphics;
        }
        graphics.setClip(rec.x, rec.y, rec.width, rec.height);
    }
    if ((mask & GC.GCFunction) != 0) {
        Color color = getColormap().getColor(gc.fgPixel);
        if (gc.function == GC.GXxor) {
            gmask &= ~GC.GCFunction;
            graphics.setXORMode(new Color((color.getRGB() ^ graphics.getColor().getRGB()) & 0xffffff));
        } else if (gc.function == GC.GXinvert) {
            //System.out.println("Pimxpa: GXinvert");
        } else {
            graphics.setColor(color);
        }
    }
    if ((mask & GC.GCFont) != 0) {
        XFont font = gc.font;
        graphics.setFont(font.getFont());
    }
    if ((mask & GC.GCLineWidth) != 0 || (mask & GC.GCLineStyle) != 0 || (mask & GC.GCCapStyle) != 0
            || (mask & GC.GCJoinStyle) != 0) {
    }
    return graphics;
}

From source file:com.cburch.logisim.gui.start.AboutCredits.java

@Override
protected void paintComponent(Graphics g) {
    FontMetrics[] fms = new FontMetrics[font.length];
    for (int i = 0; i < fms.length; i++) {
        fms[i] = g.getFontMetrics(font[i]);
    }/*www  .j  av a 2s .co m*/
    if (linesHeight == 0) {
        int y = 0;
        int index = -1;
        for (CreditsLine line : lines) {
            index++;
            if (index == initialLines)
                initialHeight = y;
            if (line.type == 0)
                y += 10;
            FontMetrics fm = fms[line.type];
            line.y = y + fm.getAscent();
            y += fm.getHeight();
        }
        linesHeight = y;
    }

    Paint[] paint = paintSteady;
    int yPos = 0;
    int height = getHeight();
    int initY = Math.min(0, initialHeight - height + About.IMAGE_BORDER);
    int maxY = linesHeight - height - initY;
    int totalMillis = 2 * MILLIS_FREEZE + (linesHeight + height) * MILLIS_PER_PIXEL;
    int offs = scroll % totalMillis;
    if (offs >= 0 && offs < MILLIS_FREEZE) {
        // frozen before starting the credits scroll
        int a = 255 * (MILLIS_FREEZE - offs) / MILLIS_FREEZE;
        if (a > 245) {
            paint = null;
        } else if (a < 15) {
            paint = paintSteady;
        } else {
            paint = new Paint[colorBase.length];
            for (int i = 0; i < paint.length; i++) {
                Color hue = colorBase[i];
                paint[i] = new GradientPaint(0.0f, 0.0f, derive(hue, a), 0.0f, fadeStop, hue);
            }
        }
        yPos = initY;
    } else if (offs < MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) {
        // scrolling through credits
        yPos = initY + (offs - MILLIS_FREEZE) / MILLIS_PER_PIXEL;
    } else if (offs < 2 * MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) {
        // freezing at bottom of scroll
        yPos = initY + maxY;
    } else if (offs < 2 * MILLIS_FREEZE + (linesHeight - initY) * MILLIS_PER_PIXEL) {
        // scrolling bottom off screen
        yPos = initY + (offs - 2 * MILLIS_FREEZE) / MILLIS_PER_PIXEL;
    } else {
        // scrolling next credits onto screen
        int millis = offs - 2 * MILLIS_FREEZE - (linesHeight - initY) * MILLIS_PER_PIXEL;
        paint = null;
        yPos = -height + millis / MILLIS_PER_PIXEL;
    }

    int width = getWidth();
    int centerX = width / 2;
    maxY = getHeight();
    for (CreditsLine line : lines) {
        int y = line.y - yPos;
        if (y < -100 || y > maxY + 50)
            continue;

        int type = line.type;
        if (paint == null) {
            g.setColor(colorBase[type]);
        } else {
            ((Graphics2D) g).setPaint(paint[type]);
        }
        g.setFont(font[type]);
        int textWidth = fms[type].stringWidth(line.text);
        g.drawString(line.text, centerX - textWidth / 2, line.y - yPos);

        Image img = line.img;
        if (img != null) {
            int x = width - line.imgWidth - About.IMAGE_BORDER;
            int top = y - fms[type].getAscent();
            g.drawImage(img, x, top, this);
        }
    }
}

From source file:edu.ku.brc.services.mapping.LocalityMapper.java

/**
 * Grabs a new map from the web service and appropriately adorns it
 * with labels and markers./*  w ww. j a va  2 s.  co m*/
 *
 * @return a map image as an icon
 * @throws HttpException a network error occurred while grabbing the map from the service
 * @throws IOException a network error occurred while grabbing the map from the service
 */
protected Icon grabNewMap() throws HttpException, IOException {
    recalculateBoundingBox();

    if (!cacheValid) {
        //            Image mapImage = getMapFromService("mapus.jpl.nasa.gov",
        //                    "/wms.cgi?request=GetMap&srs=EPSG:4326&format=image/png&styles=visual",
        //                    "global_mosaic",
        //                    mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);
        //
        //            Image overlayImage = getMapFromService("129.237.201.132",
        //                    "/cgi-bin/mapserv?map=/var/www/maps/specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&format=image/png&transparent=true",
        //                    "states,rivers",
        //                    mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);

        Image mapImage = getMapFromService("lifemapper.org", //$NON-NLS-1$
                "/ogc?map=specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&STYLES=&format=image/png&transparent=TRUE", //$NON-NLS-1$
                "global_mosaic,states,rivers", //$NON-NLS-1$
                mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);

        mapIcon = new ImageIcon(mapImage);
        //            overlayIcon = new ImageIcon(overlayImage);
        cacheValid = true;

        mapWidth = mapIcon.getIconWidth();
        mapHeight = mapIcon.getIconHeight();

        if (mapWidth < 0 || mapHeight < 0) {
            throw new IOException("Request for map failed.  Received map has negative width or height."); //$NON-NLS-1$
        }

        mapLatRange = mapMaxLat - mapMinLat;
        mapLongRange = mapMaxLong - mapMinLong;

        pixelPerLatRatio = mapHeight / mapLatRange;
        pixelPerLongRatio = mapWidth / mapLongRange;

        for (int i = 0; i < mapLocations.size(); ++i) {
            MapLocationIFace loc = mapLocations.get(i);
            Point iconLoc = determinePixelCoordsOfMapLocationIFace(loc);
            markerLocations.set(i, iconLoc);
        }

        cacheValid = true;
    }

    Icon icon = new Icon() {
        public void paintIcon(Component c, Graphics g, int x, int y) {
            // this helps keep the labels inside the map
            g.setClip(x, y, mapWidth, mapHeight);
            // log the x and y for the MouseMotionListener
            mostRecentPaintedX = x;
            mostRecentPaintedY = y;
            Point currentLocPoint = null;
            if (currentLoc != null) {
                currentLocPoint = determinePixelCoordsOfMapLocationIFace(currentLoc);
            }

            mapIcon.paintIcon(c, g, x, y);
            //                overlayIcon.paintIcon(c, g, x, y);

            Point lastLoc = null;
            for (int i = 0; i < mapLocations.size(); ++i) {
                Point markerLoc = markerLocations.get(i);
                String label = labels.get(i);
                boolean current = (currentLoc != null) && markerLoc.equals(currentLocPoint);

                if (markerLoc == null) {
                    log.error("A marker location is null"); //$NON-NLS-1$
                    continue;
                }
                if (!pointIsOnMapIcon(x + markerLoc.x, y + markerLoc.y)) {
                    log.error("A marker location is off the map"); //$NON-NLS-1$
                    continue;
                }
                if (showArrows && lastLoc != null) {
                    int x1 = x + lastLoc.x;
                    int y1 = y + lastLoc.y;
                    int x2 = x + markerLoc.x;
                    int y2 = y + markerLoc.y;
                    Color origColor = g.getColor();
                    if (current && !animationInProgress) {
                        g.setColor(getCurrentLocColor());
                    } else {
                        g.setColor(arrowColor);
                    }
                    GraphicsUtils.drawArrow(g, x1, y1, x2, y2, 2, 2);
                    g.setColor(origColor);
                }
                if (current) {
                    currentLocMarker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y);
                } else {
                    marker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y);
                }
                if (label != null) {
                    Color origColor = g.getColor();
                    FontMetrics fm = g.getFontMetrics();
                    int length = fm.stringWidth(label);
                    g.setColor(Color.WHITE);
                    g.fillRect(markerLoc.x + x - (length / 2), markerLoc.y + y - (fm.getHeight() / 2), length,
                            fm.getHeight());
                    g.setColor(labelColor);
                    GraphicsUtils.drawCenteredString(label, g, markerLoc.x + x, markerLoc.y + y);
                    g.setColor(origColor);
                }

                lastLoc = markerLoc;
            }
            if (showArrowAnimations && animationInProgress) {
                int startIndex = mapLocations.indexOf(animStartLoc);
                int endIndex = mapLocations.indexOf(animEndLoc);
                if (startIndex != -1 && endIndex != -1) {
                    Point startPoint = markerLocations.get(startIndex);
                    Point endPoint = markerLocations.get(endIndex);
                    Point arrowEnd = GraphicsUtils.getPointAlongLine(startPoint, endPoint, percent);
                    Color orig = g.getColor();
                    g.setColor(getCurrentLocColor());
                    GraphicsUtils.drawArrow(g, startPoint.x + x, startPoint.y + y, arrowEnd.x + x,
                            arrowEnd.y + y, 5, 3);
                    g.setColor(orig);
                }
            }
        }

        public int getIconWidth() {
            return mapWidth;
        }

        public int getIconHeight() {
            return mapHeight;
        }
    };

    return icon;
}

From source file:es.emergya.ui.gis.layers.MapViewerLayer.java

@Override
public void paint(Graphics g, MapView mv) {
    parent = (CustomMapView) mv;//from   ww w  .j  a  va  2  s  .  c  om

    int iMove = 0;

    zoom = mv.zoom();
    LatLon cen = Main.proj.eastNorth2latlon(mv.getCenter());

    center = new Point(OsmMercator.LonToX(cen.getX(), zoom), OsmMercator.LatToY(cen.getY(), zoom));

    int tilex = center.x / Tile.SIZE;
    int tiley = center.y / Tile.SIZE;
    int off_x = (center.x % Tile.SIZE);
    int off_y = (center.y % Tile.SIZE);

    int w2 = mv.getWidth() / 2;
    int h2 = mv.getHeight() / 2;
    int posx = w2 - off_x;
    int posy = h2 - off_y;

    int diff_left = off_x;
    int diff_right = Tile.SIZE - off_x;
    int diff_top = off_y;
    int diff_bottom = Tile.SIZE - off_y;

    boolean start_left = diff_left < diff_right;
    boolean start_top = diff_top < diff_bottom;

    if (start_top) {
        if (start_left) {
            iMove = 2;
        } else {
            iMove = 3;
        }
    } else {
        if (start_left) {
            iMove = 1;
        } else {
            iMove = 0;
        }
    } // calculate the visibility borders
    int x_min = -Tile.SIZE;
    int y_min = -Tile.SIZE;
    int x_max = mv.getWidth();
    int y_max = mv.getHeight();

    // paint the tiles in a spiral, starting from center of the map
    boolean painted = true;
    int x = 0;
    while (painted) {
        painted = false;
        for (int i = 0; i < 4; i++) {
            if (i % 2 == 0) {
                x++;
            }
            for (int j = 0; j < x; j++) {
                if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) {
                    // tile is visible
                    Tile tile = getTile(tilex, tiley, zoom);
                    if (tile != null) {
                        painted = true;
                        tile.paint(g, posx, posy);
                        if (tileGridVisible) {
                            g.drawString(tile.getXtile() + ", " + tile.getYtile(), posx, posy + 12);
                            g.drawRect(posx, posy, Tile.SIZE, Tile.SIZE);
                        }
                    }
                }
                Point p = move[iMove];
                posx += p.x * Tile.SIZE;
                posy += p.y * Tile.SIZE;
                tilex += p.x;
                tiley += p.y;
            }
            iMove = (iMove + 1) % move.length;
        }
    }
    // outer border of the map
    int mapSize = Tile.SIZE << zoom;
    g.drawRect(w2 - center.x, h2 - center.y, mapSize, mapSize);

    if (LOG.isDebugEnabled()) {
        g.setColor(Color.LIGHT_GRAY);
        g.drawString("Tiles in cache: " + tileCache.getTileCount(), 50, 15);
    }

    // g.fillRect(0, 100, 300, 55);
    // g.setColor(Color.BLACK);
    // g.drawString("center: " + center.x + ", " + center.y, 5, 120);
    // g.drawString("zoom: " + zoom + " for scale:" + mv.getScale(), 5,
    // 150);
}

From source file:forge.toolbox.FSkin.java

public static void setGraphicsColor(final Graphics g, final SkinColor skinColor) {
    g.setColor(skinColor.color);
}

From source file:stainingestimation.StainingEstimation.java

/**
 * Performs nucleus finding on the given color chanel image imp (heatmap) with the given parameters. Nuclei are drawn on the image.
 * @param imp The gray scaled color channel image after color deconvolution. It is altered by the method.
 * @param blur The blur parameter before nucleus detection.
 * @param tolerance The tolerance parameter of the local maximum method.
 * @param t The minimum value of a local maximum.
 *//*from  w  w  w  .  j  ava2s .co  m*/
void calculateNucleiPreview(ImagePlus imp, double blur, int tolerance, int t) {
    List<TMApoint> tps = StainingEstimation.find_nucleus_lm(null, imp.duplicate(), 0, 0, blur, tolerance, t,
            TMALabel.STAINING_0, true);
    new ImageConverter(imp).convertToRGB();
    Graphics g = imp.getImage().getGraphics();
    g.setColor(Color.RED);
    for (TMApoint tp : tps) {
        g.drawRect(tp.x - 1, tp.y - 1, 3, 3);
    }
}

From source file:stainingestimation.StainingEstimation.java

/**
 * Performs nucleus finding on the given color chanel image imp (heatmap) with the given parameters. Nuclei are drawn on the image.
 * @param imp The gray scaled color channel image after color deconvolution. It is altered by the method.
 * @param blur The blur parameter before nucleus detection.
 * @param tolerance The tolerance parameter of the local maximum method.
 * @param tmap The grayscaled image (same size as imp). Each pixel give a minimum value of a local maximum at this point.
 *///from w  ww .  ja va2 s  .  co m
void calculateNucleiPreview(ImagePlus imp, double blur, int tolerance, ImagePlus tmap) {
    List<TMApoint> tps = StainingEstimation.find_nucleus_lm(null, imp.duplicate(), 0, 0, blur, tolerance, tmap,
            TMALabel.STAINING_0, true);
    new ImageConverter(imp).convertToRGB();
    Graphics g = imp.getImage().getGraphics();
    g.setColor(Color.RED);
    for (TMApoint tp : tps) {
        g.drawRect(tp.x - 1, tp.y - 1, 3, 3);
    }
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_//from  w w w . ja  va2s.  co  m
 *
 * @param g _more_
 * @param comp _more_
 */
public void paintDashboardBackground(Graphics g, JComponent comp) {
    Graphics2D g2 = (Graphics2D) g;
    Rectangle b = dashboardLbl.getBounds();
    g.setColor(Color.white);
    g.fillRect(0, 0, b.width, b.height);

    if (showDecoration) {
        boolean callRepaint = false;
        for (FlythroughDecorator decorator : decorators) {
            if (!decorator.getShown()) {
                continue;
            }
            if (decorator.paintDashboard(g2, comp)) {
                callRepaint = true;
            }
        }
        if (callRepaint) {
            synchronized (REPAINT_MUTEX) {
                repaintCnt++;
                Misc.runInABit(500, this, "doRepaint", comp);
            }
        }

    }

}

From source file:com.actelion.research.table.view.JVisualization.java

protected void drawSelectionOutline(Graphics g) {
    g.setColor(VisualizationColor.cSelectedColor);
    if (mRectangleSelecting)
        g.drawRect((mMouseX1 < mMouseX2) ? mMouseX1 : mMouseX2, (mMouseY1 < mMouseY2) ? mMouseY1 : mMouseY2,
                Math.abs(mMouseX2 - mMouseX1), Math.abs(mMouseY2 - mMouseY1));

    if (mLassoSelecting)
        g.drawPolygon(mLassoRegion);/*from   w w w  . j  a  v a  2s .  c om*/
}