Example usage for java.awt Graphics getColor

List of usage examples for java.awt Graphics getColor

Introduction

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

Prototype

public abstract Color getColor();

Source Link

Document

Gets this graphics context's current color.

Usage

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private void fillBackground(Graphics g) {
    final Rectangle clip = g.getClipBounds();
    final Color col = g.getColor();
    g.setColor(getBackground());//from  w w  w .  j  a va  2s .co m
    g.fillRect(clip.x, clip.y, clip.width, clip.height);
    g.setColor(col);
}

From source file:edu.umn.cs.spatialHadoop.core.OGCJTSShape.java

@Override
public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) {
    Geometry geom = this.geom;
    Color shape_color = g.getColor();

    drawJTSShape(g, geom, fileMBR, imageWidth, imageHeight, scale, shape_color);
}

From source file:edu.umn.cs.spatialHadoop.osm.OSMEdge.java

@Override
public void draw(Graphics g, double xscale, double yscale) {
    int x1 = (int) Math.round(this.lon1 * xscale);
    int y1 = (int) Math.round(this.lat1 * yscale);
    int x2 = (int) Math.round(this.lon2 * xscale);
    int y2 = (int) Math.round(this.lat2 * yscale);
    Color shape_color = g.getColor();
    // Compute alpha to use based on edge length and image scale
    double geom_alpha = this.getLength() * (xscale + yscale) / 2.0;
    int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255);
    if (color_alpha == 0)
        return;/*www.j a v a  2 s  .c  om*/

    g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
    g.drawLine(x1, y1, x2, y2);
}

From source file:Main.java

public void paintStrikeLine(Graphics g, Shape a) {
    Color c = (Color) getElement().getAttributes().getAttribute("strike-color");
    if (c != null) {
        int y = a.getBounds().y + a.getBounds().height - (int) getGlyphPainter().getDescent(this);
        y = y - (int) (getGlyphPainter().getAscent(this) * 0.3f);
        int x1 = (int) a.getBounds().getX();
        int x2 = (int) (a.getBounds().getX() + a.getBounds().getWidth());

        Color old = g.getColor();
        g.setColor(c);/*from w  w w.  j  a v  a 2 s . c  o m*/
        g.drawLine(x1, y, x2, y);
        g.setColor(old);
    }
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.temsys.ShowEditWindDataWidget.java

private final void paintWindDataTooltip(final Graphics g, final Point p) {
    if (m_widgetFace.isAnimating()) {

        return;//  w w  w .jav  a 2 s  .com
    }
    final Color color = g.getColor();
    g.setColor(Color.BLACK);
    try {
        if (p == null)
            return;

        final IMapPanel mapPanel = m_dataModel.getMapPanel();
        if (mapPanel == null || mapPanel.getProjection() == null)
            return;

        final GM_Point nodePoint = MapUtilities.transform(mapPanel, p);

        final StringBuffer tooltipText = new StringBuffer();

        final IWindDataProvider windProvider = m_dataModel.getWindDataModel();
        if (windProvider != null && nodePoint != null) {
            final Pair<Double, Double> wind1 = windProvider.getWindAsVector(nodePoint);

            final Pair<Double, Double> wind = NativeWindDataModelHelper
                    .convertVectorWindToSpeedAndDirection(wind1);
            if (wind != null && !Double.isNaN(wind.first) && !Double.isNaN(wind.second)) {
                tooltipText.append(Messages
                        .getString("org.kalypso.kalypsomodel1d2d.ui.map.temsys.ShowEditWindDataWidget.3")); //$NON-NLS-1$
                tooltipText.append(String.format(": %.3f m/s %.3f deg ", wind.first, wind.second)); //$NON-NLS-1$
                tooltipText.append(String.format("; %.3f U %.3f V ", wind1.first, wind1.second)); //$NON-NLS-1$
            } else
                tooltipText.append(Messages
                        .getString("org.kalypso.kalypsomodel1d2d.ui.map.temsys.ShowEditWindDataWidget.4")); //$NON-NLS-1$
        } else
            tooltipText.append(
                    Messages.getString("org.kalypso.kalypsomodel1d2d.ui.map.temsys.ShowEditWindDataWidget.4")); //$NON-NLS-1$

        m_toolTipRenderer.setTooltip(tooltipText.toString());
        m_toolTipRenderer.paintToolTip(p, g, getMapPanel().getScreenBounds());

        return;
    } catch (final RuntimeException e) {
        e.printStackTrace();
    } finally {
        g.setColor(color);
    }
}

From source file:edu.umn.cs.spatialHadoop.osm.OSMEdge.java

@Override
public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) {
    int x1 = (int) ((this.lon1 - fileMBR.x1) * imageWidth / fileMBR.getWidth());
    int y1 = (int) ((this.lat1 - fileMBR.y1) * imageHeight / fileMBR.getHeight());
    int x2 = (int) ((this.lon2 - fileMBR.x1) * imageWidth / fileMBR.getWidth());
    int y2 = (int) ((this.lat2 - fileMBR.y1) * imageHeight / fileMBR.getHeight());
    Color shape_color = g.getColor();

    // Compute alpha to use based on edge length and image scale
    double geom_alpha = this.getLength() * scale;
    int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255);
    if (color_alpha == 0)
        return;//from  ww  w. ja  va2s .  c o m

    g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
    g.drawLine(x1, y1, x2, y2);
}

From source file:edu.clemson.cs.nestbed.client.gui.MoteManagementPanel.java

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

    if (moteDepConfig == null) {
        paintDisabledPattern(g);/*from  w ww  .j a v a 2  s .c  o m*/
    } else if (drawBorder) {
        Color oldColor = g.getColor();
        Color newColor = (installedSuccessfully || (installAnimationThread != null)) ? Color.green : Color.red;
        int arcSize = 4;

        g.setColor(newColor);
        g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arcSize, arcSize);
        g.setColor(oldColor);
    }
}

From source file:ExtendedParagraphExample.java

public void paint(Graphics g, Shape a) {
    Container comp = getContainer();
    Rectangle alloc = new Rectangle(a.getBounds());

    alloc.x += paraInsets.left;//  ww w  . j  ava2 s.  c om
    alloc.y += paraInsets.top;
    alloc.width -= paraInsets.left + paraInsets.right;
    alloc.height -= paraInsets.top + paraInsets.bottom;

    if (bgColor != null) {
        Color origColor = g.getColor();
        g.setColor(bgColor);
        g.fillRect(alloc.x, alloc.y, alloc.width, alloc.height);
        g.setColor(origColor);
    }

    if (border != null) {
        // Paint the border
        border.paintBorder(comp, g, alloc.x, alloc.y, alloc.width, alloc.height);
    }
    super.paint(g, a); // Note: pass ORIGINAL allocation
}

From source file:BeanContainer.java

public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Color colorRetainer = g.getColor();

        g.setColor(getBackground());/* w  w  w  . ja v a 2s .  c  o m*/
        g.fillRect(0, 0, getWidth(), getHeight());
        getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

        m_calendar.setTime(new Date()); // get current time
        int hrs = m_calendar.get(Calendar.HOUR_OF_DAY);
        int min = m_calendar.get(Calendar.MINUTE);

        g.setColor(getForeground());
        if (m_digital) {
            String time = "" + hrs + ":" + min;
            g.setFont(getFont());
            FontMetrics fm = g.getFontMetrics();
            int y = (getHeight() + fm.getAscent()) / 2;
            int x = (getWidth() - fm.stringWidth(time)) / 2;
            g.drawString(time, x, y);
        } else {
            int x = getWidth() / 2;
            int y = getHeight() / 2;
            int rh = getHeight() / 4;
            int rm = getHeight() / 3;

            double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI;
            double am = min / 30.0 * Math.PI;

            g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah)));
            g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am)));
        }

        g.setColor(colorRetainer);
    }

From source file:ubic.basecode.graphics.MatrixDisplay.java

/**
 * Draws row names (horizontally)//from www  .  ja  v  a2 s .  c  om
 * 
 * @param g Graphics
 * @param showScalebar
 */
protected void drawRowNames(Graphics g, boolean showScalebar) {

    if (colorMatrix == null)
        return;

    Color oldColor = g.getColor();

    g.setColor(Color.white);
    g.fillRect(colorMatrix.getColumnCount() * m_cellSize.width, 0,
            colorMatrix.getColumnCount() * m_cellSize.width, this.getHeight());

    int rowCount = colorMatrix.getRowCount();
    int xLabelStartPosition = colorMatrix.getColumnCount() * m_cellSize.width + m_labelGutter;
    g.setColor(Color.black);
    g.setFont(m_labelFont);

    for (int i = 0; i < rowCount; i++) {
        int y = i * m_cellSize.height + m_columnLabelHeight + m_labelGutter;
        int yLabelPosition = y + m_cellSize.height - m_fontGutter;
        if (showScalebar) {
            yLabelPosition += SCALE_BAR_ROOM;
        }

        Object rowName = colorMatrix.getRowName(i);
        if (null == rowName) {
            rowName = "Undefined";
        }

        g.drawString(rowName.toString(), xLabelStartPosition, yLabelPosition);

    } // end drawing row names
    g.setColor(oldColor);
}