Skip to content

Instantly share code, notes, and snippets.

@ulmangt
Last active December 26, 2015 11:59
Show Gist options
  • Save ulmangt/7148138 to your computer and use it in GitHub Desktop.
Save ulmangt/7148138 to your computer and use it in GitHub Desktop.
Example demonstrating adding a persistent tooltip to a timeline plot.
import com.metsci.glimpse.event.mouse.GlimpseMouseAdapter;
import com.metsci.glimpse.event.mouse.GlimpseMouseEvent;
import com.metsci.glimpse.examples.Example;
import com.metsci.glimpse.painter.info.TooltipPainter;
import com.metsci.glimpse.plot.timeline.StackedTimePlot2D;
import com.metsci.glimpse.support.settings.OceanLookAndFeel;
public class StickyTooltipExample extends CollapsibleTimelinePlotExample
{
public static void main( String[] args ) throws Exception
{
Example example = Example.showWithSwing( new StickyTooltipExample( ) );
// use the ocean look and feel
example.getCanvas( ).setLookAndFeel( new OceanLookAndFeel( ) );
}
@Override
public StackedTimePlot2D getLayout( )
{
StackedTimePlot2D plot = super.getLayout( );
// crete a tooltip painter using the same texture atlas as the plot
// (so we can use the same icon set already loaded for the events)
final TooltipPainter painter = new TooltipPainter( plot.getTextureAtlas( ) );
// add some text to the tooltip (multiple lines allowed)
painter.setText( "Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit.\nDuis eu porta nibh,\nfeugiat pulvinar libero." );
// make the tooltip start hidden
painter.setVisible( false );
// use the alarm clock icon in the tooltip
painter.setIcon( "alarm-clock" );
// add the tooltip painter to the GlimpseLayout covering the whole StackedTimePlot2D
plot.getFullOverlayLayout( ).addPainter( painter );
// add a mouse listener which repositions the tooltip whenever the mouse is clicked
plot.getFullOverlayLayout( ).addGlimpseMouseListener( new GlimpseMouseAdapter( )
{
@Override
public void mousePressed( GlimpseMouseEvent event )
{
painter.setVisible( true );
painter.setLocation( event.getX( ), event.getY( ) );
}
} );
return plot;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment