Example usage for org.eclipse.swt.widgets Composite getBackground

List of usage examples for org.eclipse.swt.widgets Composite getBackground

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Composite getBackground.

Prototype

public Color getBackground() 

Source Link

Document

Returns the receiver's background color.

Usage

From source file:WidgetTest2.java

public static Composite createComposite(Composite parent) {
    /** * Composite ** */
    //       Create new Composite instance
    final Composite composite = new Composite(parent, 0);
    //       Get properties from the containing composite
    composite.setBackground(parent.getBackground());
    composite.setForeground(parent.getForeground());
    composite.setFont(parent.getFont());
    //       Set position and size
    composite.setBounds(X, Y, WIDTH, HEIGHT);
    return composite;
}

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 .  j  a  v a 2  s  .c  o  m*/
 * @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:widgetTest3.java

/** * Images ** */

public static void doubleBuffering(Composite composite) {
    //       Create canvas
    final Canvas canvas = new Canvas(composite, SWT.BORDER);
    //       Get white system color
    Color white = canvas.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    //       Set canvas background to white
    canvas.setBackground(white);//from ww  w .  j  a  v a2 s.co m
    //       Add paint listener
    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Get Display instance from the event object
            Display display = e.display;
            // Get black and red system color - don't dispose these
            Color black = display.getSystemColor(SWT.COLOR_BLACK);
            Color red = display.getSystemColor(SWT.COLOR_RED);
            // Get the graphics context from event object
            GC gc = e.gc;
            // Get the widget that caused the event
            Composite source = (Composite) e.widget;
            // Get the size of this widgets client area
            Rectangle rect = source.getClientArea();
            // Create buffer for double buffering
            Image buffer = new Image(display, rect.width, rect.height);
            // Create graphics context for this buffer
            GC bufferGC = new GC(buffer);
            // perform drawing operations
            bufferGC.setBackground(red);
            bufferGC.fillRectangle(5, 5, rect.width - 10, rect.height - 10);
            bufferGC.setForeground(black);
            bufferGC.drawRectangle(5, 5, rect.width - 10, rect.height - 10);
            bufferGC.setBackground(source.getBackground());
            bufferGC.fillRectangle(10, 10, rect.width - 20, rect.height - 20);
            // Now draw the buffered image to the target drawable
            gc.drawImage(buffer, 0, 0);
            // Dispose of the buffer's graphics context
            bufferGC.dispose();
            // Dispose of the buffer
            buffer.dispose();
        }
    });
}

From source file:gov.redhawk.statistics.ui.views.StatisticsView.java

/**
 * This is a callback that will allow us to create the viewer and initialize it.
 *//*w  w  w. ja va 2 s . c o m*/
@Override
public void createPartControl(Composite comp) {

    parent = comp;
    parent.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(1).create());

    // Custom Action for the View's Menu
    CustomAction customAction = new CustomAction() {

        @Override
        public void run() {
            SettingsDialog dialog = new SettingsDialog(parent.getShell(), datalist.length, curIndex, numBars);
            dialog.create();
            if (dialog.open() == Window.OK) {
                numBars = dialog.getNumBars();
                curIndex = dialog.getSelectedIndex();
                refreshJob.schedule();
            }
        }
    };
    customAction.setText("Settings");
    getViewSite().getActionBars().getMenuManager().add(customAction);

    // creation of chart composite and selection of associated options
    Composite chartComposite = new Composite(parent, SWT.EMBEDDED);
    chartComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    chart = ChartFactory.createXYBarChart(null, null, false, null, dataSet, PlotOrientation.VERTICAL, false,
            true, false);

    org.eclipse.swt.graphics.Color backgroundColor = chartComposite.getBackground();
    chart.setBackgroundPaint(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chart.getXYPlot().setBackgroundPaint(ChartColor.WHITE);

    Frame chartFrame = SWT_AWT.new_Frame(chartComposite);
    chartFrame.setBackground(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chartFrame.setLayout(new GridLayout());

    ChartPanel jFreeChartPanel = new ChartPanel(chart);
    chartFrame.add(jFreeChartPanel);

    ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setMargin(0.05);
    renderer.setShadowVisible(false);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        @Override
        public String generateLabel(XYDataset dataset, int series, int item) {
            return String.valueOf((int) (dataset.getYValue(series, item)));
        }
    });
    renderer.setBasePaint(new Color(139, 0, 0));
    renderer.setLegendItemLabelGenerator(new XYSeriesLabelGenerator() {

        @Override
        public String generateLabel(XYDataset ds, int i) {
            if (ds.getSeriesCount() == 2) {
                if (i == 0) {
                    return "Real";
                } else if (i == 1) {
                    return "Imaginary";
                } else {
                    return "Complex";
                }
            } else if (ds.getSeriesCount() > 1) {
                return "Dimension " + i;
            }

            return null;
        }
    });
    chart.getXYPlot().setRenderer(renderer);

    dataSet.addChangeListener(new DatasetChangeListener() {

        @Override
        public void datasetChanged(DatasetChangeEvent event) {
            chart.getPlot().datasetChanged(event);

        }
    });

    // creation of the statistics composite
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    section = toolkit.createSection(parent, Section.DESCRIPTION | Section.NO_TITLE | Section.CLIENT_INDENT);
    section.setBackground(parent.getBackground());
    section.setDescription("");
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent

    // Composite for storing the data
    Composite composite = toolkit.createComposite(section, SWT.WRAP);
    composite.setBackground(parent.getBackground());
    composite.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(4).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent
    toolkit.paintBordersFor(composite);
    section.setClient(composite);

    for (int j = 0; j < STAT_PROPS.length; j++) {
        Label label = new Label(composite, SWT.None);
        label.setText(STAT_PROPS[j] + ":");
        labels[j] = new Label(composite, SWT.None);
        labels[j].setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    }

}

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

/**
 * This class creates a composite in which the radar char will be
 * implemented/*  ww w.  j  av  a2  s  .c om*/
 * 
 * @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;

}