Skip to content

Instantly share code, notes, and snippets.

@ulmangt
Created November 5, 2013 05:12
Show Gist options
  • Save ulmangt/7314218 to your computer and use it in GitHub Desktop.
Save ulmangt/7314218 to your computer and use it in GitHub Desktop.
Example demonstrating placing a Glimpse StackedTimePlot2D inside an AWT ScrollPane
import static com.metsci.glimpse.gl.util.GLPBufferUtils.createPixelBuffer;
import java.awt.ScrollPane;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLOffscreenAutoDrawable;
import javax.media.opengl.GLProfile;
import javax.swing.JFrame;
import com.metsci.glimpse.canvas.NewtSwingGlimpseCanvas;
import com.metsci.glimpse.layout.GlimpseLayout;
import com.metsci.glimpse.support.repaint.NEWTRepaintManager;
import com.metsci.glimpse.support.settings.OceanLookAndFeel;
import com.metsci.glimpse.support.settings.SwingLookAndFeel;
public class ScrollPaneExample extends HorizontalTimelinePlotExample
{
public static void main( String[] args ) throws Exception
{
// Normal boilerplate stuff to create gl context, canvas, etc...
ScrollPaneExample layoutProvider = new ScrollPaneExample( );
final GLOffscreenAutoDrawable pBuffer = createPixelBuffer( 1, 1 );
final GLContext context = pBuffer.getContext( );
final NewtSwingGlimpseCanvas canvas = new NewtSwingGlimpseCanvas( GLProfile.GL2GL3, context );
GlimpseLayout layout = layoutProvider.getLayout( );
canvas.addLayout( layout );
canvas.setLookAndFeel( new SwingLookAndFeel( ) );
NEWTRepaintManager.newRepaintManager( canvas );
final JFrame frame = new JFrame( "Glimpse Example" );
canvas.addDisposeListener( frame, pBuffer );
// Here's where it's different
// DONT add the canvas to the frame
//frame.add( canvas );
// INSTEAD create an AWT ScrollPane (NOT a Swing JScrollPane)
ScrollPane scrollPane = new ScrollPane( );
scrollPane.setSize( 800, 2000 );
// ADD the heavyweight NewtCanvasAWT to the ScrollPane
// NOT the lightweight Swing NewtSwingGlimpseCanvas
scrollPane.add( canvas.getCanvas( ) );
frame.add( scrollPane );
// make the frame visible
frame.pack( );
frame.setSize( 800, 800 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
// use the ocean look and feel
canvas.setLookAndFeel( new OceanLookAndFeel( ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment