Skip to content

Instantly share code, notes, and snippets.

@ulmangt
Last active December 26, 2015 01:59
Show Gist options
  • Save ulmangt/7074809 to your computer and use it in GitHub Desktop.
Save ulmangt/7074809 to your computer and use it in GitHub Desktop.
An example demonstrating how to set the background color of a number of areas of the StackedTimePlot2D
import com.metsci.glimpse.examples.Example;
import com.metsci.glimpse.layout.GlimpseLayout;
import com.metsci.glimpse.painter.decoration.BackgroundPainter;
import com.metsci.glimpse.plot.timeline.StackedTimePlot2D;
import com.metsci.glimpse.plot.timeline.layout.TimePlotInfo;
import com.metsci.glimpse.support.color.GlimpseColor;
import com.metsci.glimpse.support.settings.OceanLookAndFeel;
public class TimelineBackgroundColorExample extends CollapsibleTimelinePlotExample
{
public static void main( String[] args ) throws Exception
{
Example example = Example.showWithSwing( new TimelineBackgroundColorExample( ) );
// use the ocean look and feel
example.getCanvas( ).setLookAndFeel( new OceanLookAndFeel( ) );
}
@Override
public StackedTimePlot2D getLayout( )
{
StackedTimePlot2D plot = super.getLayout( );
plot.setBackgroundColor( GlimpseColor.getRed( ) );
// get a reference to one of the plots
TimePlotInfo plotInfo = plot.getTimePlot( "speed-plot-1-id" );
// set the background color of the plot
plotInfo.getBackgroundPainter( ).setColor( GlimpseColor.getBlue( ) );
// set the background color of the plot label
// the API doesn't provide quite as clean a way to do this at the moment, but it is possible
// first get the GlimpseLayout which defines the location of the plot label
GlimpseLayout labelLayout = plotInfo.getLabelLayout( );
// add a new BackgroundPainter (which paints a solid color) to the GlimpseLayout and set
// its ordering value so that it appears behind all other painters
labelLayout.addPainter( new BackgroundPainter( ).setColor( GlimpseColor.getGreen( ) ), Integer.MIN_VALUE );
return plot;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment