Example usage for org.eclipse.swt.graphics Color getGreen

List of usage examples for org.eclipse.swt.graphics Color getGreen

Introduction

In this page you can find the example usage for org.eclipse.swt.graphics Color getGreen.

Prototype

public int getGreen() 

Source Link

Usage

From source file:SWTUtils.java

/**
 * Creates an awt color instance to match the rgb values
 * of the specified swt color./* w ww  .  j a  va 2  s  . c  om*/
 *
 * @param color The swt color to match.
 * @return an awt color abject.
 */
public static java.awt.Color toAwtColor(Color color) {
    return new java.awt.Color(color.getRed(), color.getGreen(), color.getBlue());
}

From source file:SWTUtils.java

/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt color. alpha channel is not supported.
 * Note that the dispose method will need to be called on the
 * returned object.//from  ww w.  java2s.c o m
 *
 * @param device The swt device to draw on (display or gc device).
 * @param color The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Color color) {
    return new org.eclipse.swt.graphics.Color(device, color.getRed(), color.getGreen(), color.getBlue());
}

From source file:net.bioclipse.chart.ChartUtils.java

/**
 * Utility method for converting JFreeChart to an image
 * @param parent used for color correction 
 * @param chart the chart to be made into an image
 * @param width image width/*from w ww  . ja  v  a  2s. com*/
 * @param height image height
 * @return SWT Image of the chart 
 */
public static Image createChartImage(Composite parent, JFreeChart chart, int width, int height) {
    // Color adjustment

    Color swtBackground = parent.getBackground();
    java.awt.Color awtBackground = new java.awt.Color(swtBackground.getRed(), swtBackground.getGreen(),
            swtBackground.getRed());
    chart.setBackgroundPaint(awtBackground);

    // Draw the chart in an AWT buffered image
    BufferedImage bufferedImage = chart.createBufferedImage(width, height, null);

    // Get the data buffer of the image
    DataBuffer buffer = bufferedImage.getRaster().getDataBuffer();
    DataBufferInt intBuffer = (DataBufferInt) buffer;

    // Copy the data from the AWT buffer to a SWT buffer
    PaletteData paletteData = new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF);
    ImageData imageData = new ImageData(width, height, 32, paletteData);
    for (int bank = 0; bank < intBuffer.getNumBanks(); bank++) {
        int[] bankData = intBuffer.getData(bank);
        imageData.setPixels(0, bank, bankData.length, bankData, 0);
    }

    // Create an SWT image
    return new Image(parent.getDisplay(), imageData);
}

From source file:SWTUtils.java

/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt paint. For now, this method test
 * if the paint is a color and then return the adequate
 * swt color. Otherwise plain black is assumed.
 *
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.//  w  w w. ja va2s  .c o m
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    } else {
        try {
            throw new Exception(
                    "only color is supported at present... " + "setting paint to uniform black color");
        } catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device, color.getRed(), color.getGreen(), color.getBlue());
}

From source file:org.qsos.radar.GenerateRadar.java

/**
 * This class creates a composite in which the radar char will be
 * implemented//w w  w  .  j  a v a  2s  .  co  m
 * 
 * @param parent
 *             Composite where the chart will be seen
 * @param Categories
 *             String[] that contains the name of the elements [4 min and 7 max] the user has chosen to visualize
 * @param Scores
 *             Double[] that contains the average score of each category
 * @return Control
 * 
 */
public static Control createChart(Composite parent, String[] Categories, double[] Scores) {

    Composite Charcomposite = new Composite(parent, SWT.EMBEDDED);
    Charcomposite.setLayout(new FillLayout());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //
    for (int i = 0; i < CatNumber; i++) {
        dataset.addValue(Scores[i], getTitle(), Categories[i]);
    }

    String BackGroundMire = null;

    //Configuration of the spiderwebplot
    SpiderWebPlot plot = new SpiderWebPlot();
    plot.setDataset(dataset);
    plot.setMaxValue(JQConst.RADAR_MAX_VALUE);
    plot.setSeriesPaint(JQConst.RADAR_SERIES_PAINT);
    plot.setAxisLabelGap(JQConst.RADAR_AXIS_LABEL_GAP);
    plot.setHeadPercent(JQConst.RADAR_HEAD_PERCENT);
    plot.setInteriorGap(JQConst.RADAR_INTERIOR_GAP);
    plot.setWebFilled(true);

    //The backgroundpicture used as a spiderweb is chosen according to the 
    //number of categories selected
    switch (CatNumber) {
    case 4:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_4;
        break;
    case 5:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_5;
        break;
    case 6:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_6;
        break;
    case 7:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_7;
        break;
    }
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(BackGroundMire);
    plot.setBackgroundImage(icon.getImage());

    //chart creation
    JFreeChart chart = new JFreeChart(plot);

    //Here the background color from the shell is taken in order to match AWT and SWT backgrounds
    Color backgroundColor = parent.getBackground();

    //JFreechart doesn't support SWT so we create an AWT Frame that will depend on Charcomposite
    java.awt.Frame chartPanel = SWT_AWT.new_Frame(Charcomposite);
    chartPanel.setLayout(new java.awt.GridLayout());
    ChartPanel jfreeChartPanel = new ChartPanel(chart);

    chartPanel.setBackground(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    chartPanel.add(jfreeChartPanel);
    chartPanel.pack();

    return parent;

}

From source file:org.eclipse.swt.examples.controlexample.ColorTab.java

String getRGBcolor(int id) {
    Color color = display.getSystemColor(id);
    return String.format("(%d,%d,%d,%d)", color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

private ChartComposite createCPUChart(InstanceVisualizationData instanceVisualizationData,
        Color backgroundColor) {

    final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]", "CPU",
            instanceVisualizationData.getCpuDataSet(), PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    xyPlot.getRangeAxis().setAutoRange(false);
    xyPlot.getRangeAxis().setRange(0, 100);

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

private ChartComposite createMemoryChart(InstanceVisualizationData instanceVisualizationData,
        Color backgroundColor) {

    final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]", "Memory",
            instanceVisualizationData.getMemoryDataSet(), PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    xyPlot.getRangeAxis().setAutoRange(false);
    xyPlot.getRangeAxis().setRange(0, instanceVisualizationData.getUpperBoundForMemoryChart());

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

private ChartComposite createNetworkChart(InstanceVisualizationData instanceVisualizationData,
        Color backgroundColor) {

    final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]", "Network",
            instanceVisualizationData.getNetworkDataSet(), PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    // TODO: Repair auto range for range axis
    xyPlot.getRangeAxis().setAutoRange(false);
    xyPlot.getRangeAxis().setRange(0, 4096);

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}

From source file:eu.stratosphere.addons.visualization.swt.SWTVertexToolTip.java

private ChartComposite createThreadChart(VertexVisualizationData visualizationData, Color backgroundColor) {

    final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]",
            "Thread Utilization [%]", visualizationData.getThreadDataSet(), PlotOrientation.VERTICAL, true,
            true, false);//from   w  w  w  .j a  v a 2 s  .  co m

    chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    // Set axis properly
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setAutoRange(true);
    xyPlot.getDomainAxis().setAutoRangeMinimumSize(60);

    // xyPlot.getRangeAxis().setAutoRange(true);
    xyPlot.getRangeAxis().setRange(0, 100);

    return new ChartComposite(getShell(), SWT.NONE, chart, true);
}