Example usage for java.awt GradientPaint GradientPaint

List of usage examples for java.awt GradientPaint GradientPaint

Introduction

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

Prototype

public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2) 

Source Link

Document

Constructs a simple acyclic GradientPaint object.

Usage

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createGanttChart(CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    DateAxis dateAxis = new DateAxis(valueAxisLabel);

    CategoryItemRenderer renderer = new GanttRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(
                new IntervalCategoryToolTipGenerator("{3} - {4}", DateFormat.getDateInstance()));
    }/*from  www  . ja va  2  s  . c o  m*/
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart chart = new JFreeChart("Gantt Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Called to set up this main window frame.
 *///ww  w.  j a va  2  s  . com
public void setupFrame(Client mirthClient) throws ClientException {

    LoginPanel login = LoginPanel.getInstance();

    // Initialize the send message dialog
    editMessageDialog = new EditMessageDialog();

    this.mirthClient = mirthClient;
    login.setStatus("Loading extensions...");
    try {
        loadExtensionMetaData();
    } catch (ClientException e) {
        alertError(this, "Unable to load extensions.");
        throw e;
    }

    // Re-initialize the controller every time the frame is setup
    AuthorizationControllerFactory.getAuthorizationController().initialize();
    channelPanel = new ChannelPanel();
    channelPanel.retrieveGroups();
    channelPanel.retrieveDependencies();
    codeTemplatePanel = new CodeTemplatePanel(this);
    initializeExtensions();

    channelPanel.initPanelPlugins();

    // Load the data type/display name maps now that the extensions have been loaded.
    dataTypeToDisplayName = new LinkedHashMap<String, String>();
    displayNameToDataType = new LinkedHashMap<String, String>();
    for (Entry<String, DataTypeClientPlugin> entry : LoadedExtensions.getInstance().getDataTypePlugins()
            .entrySet()) {
        dataTypeToDisplayName.put(entry.getKey(), entry.getValue().getDisplayName());
        displayNameToDataType.put(entry.getValue().getDisplayName(), entry.getKey());
    }

    setInitialVisibleTasks();
    login.setStatus("Loading preferences...");
    userPreferences = Preferences.userNodeForPackage(Mirth.class);
    userPreferences.put("defaultServer", PlatformUI.SERVER_URL);
    login.setStatus("Loading GUI components...");
    splitPane.setDividerSize(0);
    splitPane.setBorder(BorderFactory.createEmptyBorder());

    contentPanel = (JPanel) getContentPane();
    contentPanel.setLayout(new BorderLayout());
    contentPanel.setBorder(BorderFactory.createEmptyBorder());
    taskPane.setBorder(BorderFactory.createEmptyBorder());

    statusBar = new StatusBar();
    statusBar.setBorder(BorderFactory.createEmptyBorder());
    contentPane.setBorder(BorderFactory.createEmptyBorder());

    buildContentPanel(rightContainer, contentPane, false);

    // Set task pane container background painter
    MattePainter taskPanePainter = new MattePainter(new GradientPaint(0f, 0f,
            UIConstants.JX_CONTAINER_BACKGROUND_COLOR, 0f, 1f, UIConstants.JX_CONTAINER_BACKGROUND_COLOR));
    taskPanePainter.setPaintStretched(true);
    taskPaneContainer.setBackgroundPainter(taskPanePainter);

    // Set main content container title painter
    MattePainter contentTitlePainter = new MattePainter(new GradientPaint(0f, 0f,
            UIConstants.JX_CONTAINER_BACKGROUND_COLOR, 0f, 1f, UIConstants.JX_CONTAINER_BACKGROUND_COLOR));
    contentTitlePainter.setPaintStretched(true);
    rightContainer.setTitlePainter(contentTitlePainter);

    splitPane.add(rightContainer, JSplitPane.RIGHT);
    splitPane.add(taskPane, JSplitPane.LEFT);
    taskPane.setMinimumSize(new Dimension(UIConstants.TASK_PANE_WIDTH, 0));
    splitPane.setDividerLocation(UIConstants.TASK_PANE_WIDTH);

    contentPanel.add(statusBar, BorderLayout.SOUTH);
    contentPanel.add(splitPane, java.awt.BorderLayout.CENTER);

    try {
        PlatformUI.SERVER_ID = mirthClient.getServerId();
        PlatformUI.SERVER_VERSION = mirthClient.getVersion();
        PlatformUI.SERVER_TIMEZONE = mirthClient.getServerTimezone();
        PlatformUI.SERVER_TIME = mirthClient.getServerTime();

        setTitle(getTitle() + " - (" + PlatformUI.SERVER_VERSION + ")");

        PlatformUI.BUILD_DATE = mirthClient.getBuildDate();

        // Initialize ObjectXMLSerializer once we know the server version
        try {
            ObjectXMLSerializer.getInstance().init(PlatformUI.SERVER_VERSION);
        } catch (Exception e) {
        }
    } catch (ClientException e) {
        alertError(this, "Could not get server information.");
    }

    // Display the server timezone information
    statusBar.setTimezoneText(PlatformUI.SERVER_TIMEZONE);
    statusBar.setServerTime(PlatformUI.SERVER_TIME);

    setCurrentTaskPaneContainer(taskPaneContainer);
    login.setStatus("Loading dashboard...");
    doShowDashboard();
    login.setStatus("Loading channel editor...");
    channelEditPanel = new ChannelSetup();
    login.setStatus("Loading alert editor...");
    if (alertEditPanel == null) {
        alertEditPanel = new DefaultAlertEditPanel();
    }
    login.setStatus("Loading message browser...");
    messageBrowser = new MessageBrowser();

    // Refresh code templates after extensions have been loaded
    codeTemplatePanel.doRefreshCodeTemplates(false);

    // Refresh resources
    if (settingsPane == null) {
        settingsPane = new SettingsPane();
    }
    SettingsPanelResources resourcesPanel = (SettingsPanelResources) settingsPane
            .getSettingsPanel(SettingsPanelResources.TAB_NAME);
    if (resourcesPanel != null) {
        resourcesPanel.doRefresh();
    }

    // DEBUGGING THE UIDefaults:

    //         UIDefaults uiDefaults = UIManager.getDefaults(); Enumeration enum1 =
    //         uiDefaults.keys(); while (enum1.hasMoreElements()) { Object key =
    //         enum1.nextElement(); Object val = uiDefaults.get(key);
    ////         if(key.toString().indexOf("ComboBox") != -1)
    //         System.out.println("UIManager.put(\"" + key.toString() + "\",\"" +
    //         (null != val ? val.toString() : "(null)") + "\");"); }

}

From source file:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates and returns a sample time series chart.
 *
 * @return a sample time series chart.//from   w  ww  . jav a2 s  . com
 */
public JFreeChart createTimeSeries2Chart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("timeseries.sample2.title");
    final String subtitleStr = this.resources.getString("timeseries.sample2.subtitle");
    final String domain = this.resources.getString("timeseries.sample2.domain");
    final String range = this.resources.getString("timeseries.sample2.range");
    final XYDataset data = DemoDatasetFactory.createTimeSeriesCollection4();
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, data, true, true, false);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    final XYPlot plot = chart.getXYPlot();
    final LogarithmicAxis rangeAxis = new LogarithmicAxis(range);
    plot.setRangeAxis(rangeAxis);
    return chart;

}

From source file:org.gridchem.client.gui.panels.myccg.resource.HPCChartPanel.java

/**
 * Renders the bar chart.// ww  w.j av a2s. co m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart renderBarChart(JFreeChart chart) {

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperBound(100);

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.black);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.black);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.black);
    final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.orange, 0.0f, 0.0f, Color.black);

    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);

    //        final CategoryAxis domainAxis = plot.getDomainAxis();
    //        domainAxis.setCategoryLabelPositions(
    //            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
    //        );
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:MyJava3D.java

public void setTexture(Object obj) {
    if (obj instanceof GradientPaint) {
        texture = new GradientPaint(0, 0, Color.white, getSize().width * 2, 0, Color.green);
    } else {//from w w w . j av  a  2  s.c o m
        texture = (Paint) obj;
    }
}

From source file:savant.view.swing.GraphPane.java

/**
 * Render the background of this GraphPane
 *
 * @param g The graphics object to use//from www  .ja v  a2 s  .  co  m
 */
private void renderBackground(Graphics2D g2, boolean xGridOn, boolean yGridOn) {
    int h = getHeight();
    int w = getWidth();

    // Paint a gradient from top to bottom
    GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0,
            h, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM));
    g2.setPaint(gp0);
    g2.fillRect(0, 0, w, h);

    // We don't want the axes stomping on our labels, so make sure the clip excludes them.
    Area clipArea = new Area(new Rectangle(0, 0, w, h));
    Color gridColor = ColourSettings.getColor(ColourKey.AXIS_GRID);

    if (yGridOn) {
        // Smallish font for tick labels.
        Font tickFont = g2.getFont().deriveFont(Font.PLAIN, 9);

        int[] yTicks = MiscUtils.getTickPositions(transformYPixel(getHeight()), transformYPixel(0.0));

        g2.setColor(gridColor);
        g2.setFont(tickFont);
        for (int t : yTicks) {
            double y = transformYPos(t);

            // Skip labels at the top or bottom of the window because they look stupid.
            if (y != 0.0 && y != getHeight()) {
                String s = Integer.toString(t);
                Rectangle2D labelRect = tickFont.getStringBounds(s, g2.getFontRenderContext());
                double baseline = y + labelRect.getHeight() * 0.5 - 2.0;
                g2.drawString(s, 4.0F, (float) baseline);
                clipArea.subtract(new Area(new Rectangle2D.Double(3.0, baseline - labelRect.getHeight() - 1.0,
                        labelRect.getWidth() + 2.0, labelRect.getHeight() + 2.0)));
            }
        }
        g2.setClip(clipArea);
        for (int t2 : yTicks) {
            double y = transformYPos(t2);
            g2.draw(new Line2D.Double(0.0, y, w, y));
        }
    }
    if (xGridOn) {
        Range r = LocationController.getInstance().getRange();
        int[] xTicks = MiscUtils.getTickPositions(r);

        g2.setColor(gridColor);
        for (int t : xTicks) {
            double x = transformXPos(t);
            g2.draw(new Line2D.Double(x, 0, x, h));
        }
    }
    g2.setClip(null);
}

From source file:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates and returns a sample time series chart.
 *
 * @return a sample time series chart.//from w  ww . j a  v  a 2 s  .c  om
 */
public JFreeChart createTimeSeriesWithMAChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("timeseries.sample3.title");
    final String domain = this.resources.getString("timeseries.sample3.domain");
    final String range = this.resources.getString("timeseries.sample3.range");
    final String subtitleStr = this.resources.getString("timeseries.sample3.subtitle");
    final TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries();
    final TimeSeries mav = MovingAverage.createMovingAverage(jpy, "30 Day Moving Average", 30, 30);
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(jpy);
    dataset.addSeries(mav);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain, range, dataset, true, true,
            false);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createWaterfallChart(CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);

    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    WaterfallBarRenderer renderer = new WaterfallBarRenderer();
    if (orientation == PlotOrientation.HORIZONTAL) {
        ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
                TextAnchor.CENTER, Math.PI / 2.0);
        renderer.setBasePositiveItemLabelPosition(position);
        renderer.setBaseNegativeItemLabelPosition(position);
    } else if (orientation == PlotOrientation.VERTICAL) {
        ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0);
        renderer.setBasePositiveItemLabelPosition(position);
        renderer.setBaseNegativeItemLabelPosition(position);
    }//  w w w  .  j  a  v a  2 s .c  o  m
    if (tooltips) {
        StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator();
        renderer.setBaseToolTipGenerator(generator);
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.clearRangeMarkers();
    Marker baseline = new ValueMarker(0.0);
    baseline.setPaint(Color.black);
    plot.addRangeMarker(baseline, Layer.FOREGROUND);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart("Waterfall Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    //        GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    //        AbstractRenderer#setSeriesPaint(int, Paint) are ignored;
    //        renderer.setSeriesPaint(0, gp0);
    //        renderer.setSeriesPaint(1, gp1);
    //        renderer.setSeriesPaint(2, gp2);

    //??
    renderer.setFirstBarPaint(gp0);
    renderer.setLastBarPaint(gp2);
    renderer.setPositiveBarPaint(Color.orange);
    renderer.setNegativeBarPaint(Color.cyan);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}

From source file:org.gridchem.client.gui.panels.myccg.resource.HPCChartPanel.java

/**
 * This lays the layers over each other/*from  w  w w .  j  a  va  2s . c o m*/
 * @param chart
 */
private void renderLayeredBarChart(JFreeChart chart) {
    //      get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setRowRenderingOrder(SortOrder.DESCENDING);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperBound(100);

    // disable bar outlines...
    final LayeredBarRenderer renderer = (LayeredBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.black);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.black);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.black);
    final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.orange, 0.0f, 0.0f, Color.black);

    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);

}

From source file:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Displays a vertical bar chart in its own frame.
 *
 * @return a high low chart.// ww w .j a va 2 s . c om
 */
public JFreeChart createHighLowChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("timeseries.highlow.title");
    final String domain = this.resources.getString("timeseries.highlow.domain");
    final String range = this.resources.getString("timeseries.highlow.range");
    final String subtitleStr = this.resources.getString("timeseries.highlow.subtitle");
    final DefaultHighLowDataset data = DemoDatasetFactory.createHighLowDataset();
    final JFreeChart chart = ChartFactory.createHighLowChart(title, domain, range, data, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.magenta));
    return chart;

}