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:org.kalypso.kalypsomodel1d2d.ui.map.temsys.ShowEditWindDataWidget.java

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

        return;// ww w .j ava  2 s. c  o m
    }
    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:com.openkm.servlet.admin.StampServlet.java

/**
 * View text color//from   w w  w .ja  v  a  2 s .  c  o m
 */
private void textColor(Session session, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("textColor({}, {}, {})", new Object[] { session, request, response });
    int stId = WebUtils.getInt(request, "st_id");
    StampText st = StampTextDAO.findByPk(stId);
    BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    g.setColor(Color.decode(st.getColor()));
    g.fillRect(0, 0, 16, 16);
    response.setContentType("image/jpeg");
    ImageIO.write(bi, "jpg", response.getOutputStream());
    log.debug("textColor: void");
}

From source file:de.tor.tribes.ui.views.DSWorkbenchRankFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    RankTableTab activeTab = getActiveTab();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("Find")) {
            BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT);
            Graphics g = back.getGraphics();
            g.setColor(new Color(120, 120, 120, 120));
            g.fillRect(0, 0, back.getWidth(), back.getHeight());
            g.setColor(new Color(120, 120, 120));
            g.drawLine(0, 0, 3, 3);// w w w .j  a  va  2  s. com
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            DefaultListModel model = new DefaultListModel();

            for (int i = 0; i < activeTab.getRankTable().getColumnCount(); i++) {
                TableColumnExt col = activeTab.getRankTable().getColumnExt(i);
                if (col.isVisible()) {
                    if (col.getTitle().equals("Name") || col.getTitle().equals("Tag")
                            || col.getTitle().equals("Stamm")) {
                        model.addElement(col.getTitle());
                    }

                }
            }
            jXColumnList.setModel(model);
            jXColumnList.setSelectedIndex(0);
            jxSearchPane.setVisible(true);
        }
    }

}

From source file:Main.java

public void paint(Graphics g) {

    int fontSize = 20;

    g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize));

    FontMetrics fm = g.getFontMetrics();

    String s = "www.java2s.com";

    int stringWidth = fm.stringWidth(s);

    int w = 200;//from   ww  w.j  a  v a2s .c  o  m
    int h = 200;

    int x = (w - stringWidth) / 2;
    int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2;
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDecent();
    int fontHeight = fm.getMaxAscent() + fm.getMaxDecent();

    g.setColor(Color.white);
    g.fillRect(x, baseline - ascent, stringWidth, fontHeight);

    g.setColor(Color.gray);
    g.drawLine(x, baseline, x + stringWidth, baseline);

    g.setColor(Color.red);
    g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent);

    g.setColor(Color.blue);
    g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent);
    g.setColor(Color.black);
    g.drawString(s, x, baseline);

}

From source file:MainClass.java

public void paint(Graphics g) {
    int fontSize = 20;

    g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize));

    FontMetrics fm = g.getFontMetrics();

    String s = "www.java2s.com";

    int stringWidth = fm.stringWidth(s);

    int w = 200;//from   w  w w.  j a  v a2s  .  com
    int h = 200;

    int x = (w - stringWidth) / 2;
    int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2;
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDecent();
    int fontHeight = fm.getMaxAscent() + fm.getMaxDecent();

    g.setColor(Color.white);
    g.fillRect(x, baseline - ascent, stringWidth, fontHeight);

    g.setColor(Color.gray);
    g.drawLine(x, baseline, x + stringWidth, baseline);

    g.setColor(Color.red);
    g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent);

    g.setColor(Color.blue);
    g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent);
    g.setColor(Color.black);
    g.drawString(s, x, baseline);
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java

/**
 * Draws the hotspot where the user can join the node to a source node
 *
 * @param g   The Java2D Graphics//from w  w  w .j  av  a 2s. c  om
 * @param col The color to draw
 */
public void drawHeadHotspot(final Graphics g, final Color col) {
    final Point p = displayPosition;
    g.setColor(col);
    g.drawOval(p.x - halfHotSpotSize, p.y + hotSpotOffset, hotSpotSize, hotSpotSize);
}

From source file:oct.analysis.application.OCTSelection.java

public void drawSelection(Graphics g, int imageOffsetX, int imageOffsetY) {
    if (highlighted) {
        g.setColor(Color.pink);
    } else {//from  ww w  .  j  a v a  2 s.  com
        g.setColor(Color.green);
    }
    //draw lines arround the area that is the selection
    int leftEdge = getSelectionLeftEdgeCoordinate();
    int rightEdge = getSelectionRightEdgeCoordinate();
    //        g.drawRect(imageOffsetX + leftEdge - 1, imageOffsetY + yPositionOnOct - 1, width + 2, height + 2);
    //draw left line
    g.drawLine(imageOffsetX + leftEdge - 1, imageOffsetY + yPositionOnOct, imageOffsetX + leftEdge - 1,
            imageOffsetY + yPositionOnOct + height - 1);
    //draw right line
    g.drawLine(imageOffsetX + rightEdge + 1, imageOffsetY + yPositionOnOct, imageOffsetX + rightEdge + 1,
            imageOffsetY + yPositionOnOct + height - 1);
    //draw top line
    g.drawLine(imageOffsetX + leftEdge, imageOffsetY + yPositionOnOct, imageOffsetX + rightEdge,
            imageOffsetY + yPositionOnOct);
    //draw bottom line
    g.drawLine(imageOffsetX + leftEdge, imageOffsetY + yPositionOnOct + height, imageOffsetX + rightEdge,
            imageOffsetY + yPositionOnOct + height);
    //draw button for interacting with the selection
    drawSelectButton(g, imageOffsetX, imageOffsetY);
    drawn = true;
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java

/**
 * Draws the hotspot where the user can join the node to a source node
 *
 * @param g   The Java2D Graphics//ww w.java 2  s .  co m
 * @param col The color to draw
 */
public void drawTailHotspot(final Graphics g, final Color col) {
    final Point p = displayPosition;
    g.setColor(col);

    final int x = p.x + nodeWidth;
    final int y = p.y + halfNodeHeight;
    final int[] xpoints = { x, x + hotSpotOffset, x, x };
    final int[] ypoints = { y - halfHotSpotSize, y, y + halfHotSpotSize, y - halfHotSpotSize };
    g.fillPolygon(xpoints, ypoints, xpoints.length);
}

From source file:FormattedTextFieldExample.java

protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
    g.setColor(unselected);
    workBuff.array = contentBuff.array;/*from  w  w w .j a  va  2 s.co  m*/
    workBuff.offset = p0;
    workBuff.count = p1 - p0;
    return Utilities.drawTabbedText(workBuff, x, y, g, this, p0);
}

From source file:AlphaTest.java

/**
 * Draws vertical lines and labels to denote the various phases of the Alpha
 * function.//w w  w .  j a v  a 2s .co  m
 */
protected void drawPhases(Graphics g, long lMaxTime) {
    int nLoop = 1;

    if (m_Alpha.getLoopCount() > 0)
        nLoop = m_Alpha.getLoopCount();

    double curTime = 0;

    g.setColor(Color.darkGray);

    curTime += m_Alpha.getTriggerTime();
    drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

    curTime += m_Alpha.getPhaseDelayDuration();
    drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

    double startPhaseTime = 0;

    for (int nIteration = 0; nIteration < nLoop; nIteration++) {
        startPhaseTime = curTime;

        g.setColor(Color.black);
        drawGraphString(g, -1, "" + curTime, curTime * m_ScaleX, -20);
        g.setColor(Color.darkGray);

        if ((m_Alpha.getMode() & Alpha.INCREASING_ENABLE) != 0) {
            curTime += m_Alpha.getIncreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getIncreasingAlphaDuration()
                    - m_Alpha.getIncreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getIncreasingAlphaDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime += m_Alpha.getAlphaAtOneDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);
        }

        startPhaseTime = curTime;

        if ((m_Alpha.getMode() & Alpha.DECREASING_ENABLE) != 0) {
            curTime += m_Alpha.getDecreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getDecreasingAlphaDuration()
                    - m_Alpha.getDecreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getDecreasingAlphaDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime += m_Alpha.getAlphaAtZeroDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);
        }
    }

    g.setColor(Color.black);
}