Skip to content

Commit

Permalink
Merge pull request #29 from metsci/master
Browse files Browse the repository at this point in the history
2.0.1 Pull Request
  • Loading branch information
ulmangt committed Oct 27, 2013
2 parents e7a7b26 + 4dc8f27 commit 98fc4d1
Show file tree
Hide file tree
Showing 44 changed files with 1,224 additions and 4,005 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
*/
package com.metsci.glimpse.examples.animated;

import it.unimi.dsi.fastutil.ints.IntAVLTreeSet;
import it.unimi.dsi.fastutil.ints.IntBidirectionalIterator;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.metsci.glimpse.axis.Axis1D;
import com.metsci.glimpse.axis.Axis2D;
Expand Down Expand Up @@ -244,15 +244,15 @@ public void axisUpdatedRateLimited( Axis1D axis )
// a custom listener which is notified when the track points inside the plot's selection box change
private static class TrackSelectionListener implements SpatialSelectionListener<Point>
{
private IntAVLTreeSet selectedTrackIds;
private IntAVLTreeSet newSelectedTrackIds;
private Set<Object> selectedTrackIds;
private Set<Object> newSelectedTrackIds;
private TrackPainter trackPainter;
private TrackManager trackManager;

public TrackSelectionListener( TrackManager trackManager, TrackPainter trackPainter )
{
this.selectedTrackIds = new IntAVLTreeSet( );
this.newSelectedTrackIds = new IntAVLTreeSet( );
this.selectedTrackIds = new HashSet<>( );
this.newSelectedTrackIds = new HashSet<>( );

this.trackManager = trackManager;
this.trackPainter = trackPainter;
Expand All @@ -277,10 +277,10 @@ public void selectionChanged( Collection<Point> newSelectedPoints )
}

// change various display characteristics of the selected tracks
IntBidirectionalIterator iter = newSelectedTrackIds.iterator( );
Iterator<Object> iter = newSelectedTrackIds.iterator( );
while ( iter.hasNext( ) )
{
int trackId = iter.nextInt( );
Object trackId = iter.next( );

trackPainter.setPointColor( trackId, 0.0f, 1.0f, 0.0f, 1.0f );
trackPainter.setLineColor( trackId, 0.0f, 1.0f, 0.0f, 1.0f );
Expand All @@ -293,7 +293,7 @@ public void selectionChanged( Collection<Point> newSelectedPoints )
iter = selectedTrackIds.iterator( );
while ( iter.hasNext( ) )
{
int trackId = iter.nextInt( );
Object trackId = iter.next( );

if ( newSelectedTrackIds.contains( trackId ) ) continue;

Expand All @@ -305,7 +305,7 @@ public void selectionChanged( Collection<Point> newSelectedPoints )
}

// swap the sets storing previously selected and newly selected tracks
IntAVLTreeSet temp = selectedTrackIds;
Set<Object> temp = selectedTrackIds;
selectedTrackIds = newSelectedTrackIds;
newSelectedTrackIds = temp;
}
Expand All @@ -315,15 +315,15 @@ public void selectionChanged( Collection<Point> newSelectedPoints )
private static class TrackManager extends Thread
{
private int time = 0;
private Map<Integer, Track> tracks;
private Map<Object, Track> tracks;
private TrackPainter trackPainter;
private int numberOfTracks;

public TrackManager( TrackPainter trackPainter, int numberOfTracks )
{
this.trackPainter = trackPainter;
this.numberOfTracks = numberOfTracks;
this.tracks = Collections.synchronizedMap( new HashMap<Integer, Track>( numberOfTracks ) );
this.tracks = Collections.synchronizedMap( new HashMap<Object, Track>( numberOfTracks ) );
}

@Override
Expand Down Expand Up @@ -382,7 +382,7 @@ public void run( )
}
}

public Track getTrack( int id )
public Track getTrack( Object id )
{
return tracks.get( id );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ protected NumericAxisPainter createAxisPainterZ( AxisLabelHandler tickHandler )
// add a painter to display the x and y position of the cursor
CursorTextPainter cursorPainter = new CursorTextPainter( );
plot.addPainter( cursorPainter );

// don't offset the text by the size of the selection box, since we aren't showing it
cursorPainter.setOffsetBySelectionSize( false );

LineLegendPainter legend = new LineLegendPainter( LegendPlacement.SE );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public void applyConstraint( TaggedAxis1D axis )
CursorTextZPainter cursorPainter = new CursorTextZPainter( );
plot.addPainter( cursorPainter );

cursorPainter.setOffsetBySelectionSize( false );
// offset the text by the size of the selection box
cursorPainter.setOffsetBySelectionSize( true );

// tell the cursor painter what texture to report data values from
cursorPainter.setTexture( texture );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Logger;

import javax.swing.JFrame;
Expand Down Expand Up @@ -63,18 +61,7 @@ public static void main( String[] args ) throws Exception

final JFrame frame = new JFrame( "Glimpse Example (Swing)" );

frame.addWindowListener( new WindowAdapter( )
{
@Override
public void windowClosing( WindowEvent e )
{
// dispose of resources associated with the canvas
canvas.dispose( );

// remove the canvas from the frame
frame.remove( canvas );
}
} );
canvas.addDisposeListener( frame );

frame.add( canvas );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2012, Metron, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Metron, Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL METRON, INC. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.metsci.glimpse.examples.stacked;

import java.util.TimeZone;

import com.metsci.glimpse.examples.Example;
import com.metsci.glimpse.painter.info.SimpleTextPainter.VerticalPosition;
import com.metsci.glimpse.plot.timeline.StackedTimePlot2D;
import com.metsci.glimpse.plot.timeline.layout.TimelineInfo;

public class MultipleTimelineExample extends CollapsibleTimelinePlotExample
{
public static void main( String[] args ) throws Exception
{
Example.showWithSwing( new MultipleTimelineExample( ) );
}

@Override
public StackedTimePlot2D getLayout( )
{
StackedTimePlot2D plot = super.getLayout( );

// set up two timelines, one showing EST and one showing GMT time
TimelineInfo gmtTimeline = plot.getDefaultTimeline( );
gmtTimeline.getTimeZonePainter( ).setVerticalPosition( VerticalPosition.Top );
gmtTimeline.getTimeZonePainter( ).setSizeText( "EST" );
// don't show the date labels for the GMT timeline
gmtTimeline.getAxisPainter( ).setShowDateLabels( false );
gmtTimeline.setSize( 25 );

// set up the additional timeline showing EST
TimelineInfo estTimeline = plot.createTimeline( );
estTimeline.setTimeZone( TimeZone.getTimeZone( "GMT-4:00" ) );
estTimeline.getTimeZonePainter( ).setText( "EST" );
estTimeline.getTimeZonePainter( ).setVerticalPosition( VerticalPosition.Top );
estTimeline.getTimeZonePainter( ).setSizeText( "EST" );
estTimeline.setSize( 35 );

return plot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ public NumericXYAxisPainter( )
{
this( new GridAxisExponentLabelHandler( ), new GridAxisExponentLabelHandler( ) );
}

public void setLabelHandlerX( AxisLabelHandler ticksX )
{
this.ticksX = ticksX;
}

public void setLabelHandlerY( AxisLabelHandler ticksY )
{
this.ticksY = ticksY;
}

public AxisLabelHandler getLabelHandlerX( )
{
return this.ticksX;
}

public AxisLabelHandler getLabelHandlerY( )
{
return this.ticksY;
}

public void setFont( Font font )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public abstract class TimeAxisPainter extends GlimpsePainter1D
protected volatile Font newFont = null;
protected volatile boolean antialias = false;

protected boolean showDateLabels = true;
protected boolean showCurrentTimeLabel = false;
protected float[] currentTimeTextColor;
protected float[] currentTimeTickColor;
Expand All @@ -87,6 +88,16 @@ public TimeAxisPainter( TimeAxisLabelHandler handler )
this.currentTimeLineThickness = 3;
}

public boolean isShowDateLabels( )
{
return this.showDateLabels;
}

public void setShowDateLabels( boolean show )
{
this.showDateLabels = show;
}

public TimeAxisLabelHandler getLabelHandler( )
{
return this.handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,21 @@
* @see TimeAxisPainter
*/
public class TimeXAxisPainter extends TimeAxisPainter
{
{
public TimeXAxisPainter( TimeZone timeZone, Epoch epoch )
{
super( new TimeAxisLabelHandler( timeZone, epoch ) );
}

public TimeXAxisPainter( Epoch epoch )
{
super( new TimeAxisLabelHandler( epoch ) );
}

//@formatter:off
public TimeXAxisPainter( TimeStampFormat minuteSecondFormat,
TimeStampFormat hourMinuteFormat,
TimeStampFormat hourDayMonthFormat,
TimeStampFormat dayMonthYearFormat,
TimeStampFormat dayFormat,
TimeStampFormat dayMonthFormat,
TimeStampFormat monthYearFormat,
TimeStampFormat yearFormat,
TimeZone timeZone, Epoch epoch )
public TimeXAxisPainter( TimeAxisLabelHandler handler )
{
super( new TimeAxisLabelHandler( minuteSecondFormat, hourMinuteFormat, hourDayMonthFormat, dayMonthYearFormat, dayFormat, dayMonthFormat, monthYearFormat, yearFormat, timeZone, epoch ) );
super( handler );
}
//@formatter:on

@Override
public void paintTo( GlimpseContext context, GlimpseBounds bounds, Axis1D axis )
Expand Down Expand Up @@ -121,31 +116,31 @@ public void paintTo( GlimpseContext context, GlimpseBounds bounds, Axis1D axis )
double jTimeText = printTickLabels( tickTimes, axis, handler.getSecondMinuteFormat( ), width, height );

// Date labels
printHoverLabels( tickTimes, axis, handler.getHourDayMonthFormat( ), handler.getHourStructFactory( ), jTimeText, width, height );
if ( isShowDateLabels( ) ) printHoverLabels( tickTimes, axis, handler.getHourDayMonthFormat( ), handler.getHourStructFactory( ), jTimeText, width, height );
}
else if ( tickInterval <= Time.fromHours( 12 ) )
{
// Time labels
double jTimeText = printTickLabels( tickTimes, axis, handler.getHourMinuteFormat( ), width, height );

// Date labels
printHoverLabels( tickTimes, axis, handler.getDayMonthYearFormat( ), handler.getDayStructFactory( ), jTimeText, width, height );
if ( isShowDateLabels( ) ) printHoverLabels( tickTimes, axis, handler.getDayMonthYearFormat( ), handler.getDayStructFactory( ), jTimeText, width, height );
}
else if ( tickInterval <= Time.fromDays( 10 ) )
{
// Date labels
double jTimeText = printTickLabels( tickTimes, axis, handler.getDayFormat( ), width, height );

// Year labels
printHoverLabels( tickTimes, axis, handler.getMonthYearFormat( ), handler.getMonthStructFactory( ), jTimeText, width, height );
if ( isShowDateLabels( ) ) printHoverLabels( tickTimes, axis, handler.getMonthYearFormat( ), handler.getMonthStructFactory( ), jTimeText, width, height );
}
else if ( tickInterval <= Time.fromDays( 60 ) )
{
// Date labels
double jTimeText = printTickLabels( tickTimes, axis, handler.getMonthFormat( ), width, height );

// Year labels
printHoverLabels( tickTimes, axis, handler.getYearFormat( ), handler.getYearStructFactory( ), jTimeText, width, height );
if ( isShowDateLabels( ) ) printHoverLabels( tickTimes, axis, handler.getYearFormat( ), handler.getYearStructFactory( ), jTimeText, width, height );
}
else
{
Expand All @@ -164,7 +159,7 @@ protected TimeStamp getCurrentTime( )
return currentTime( );
}

private void printHoverLabels( List<TimeStamp> tickTimes, Axis1D axis, TimeStampFormat format, TimeStructFactory factory, double jTimeText, int width, int height )
protected void printHoverLabels( List<TimeStamp> tickTimes, Axis1D axis, TimeStampFormat format, TimeStructFactory factory, double jTimeText, int width, int height )
{
// text heights vary slightly, making the labels appear unevenly spaced in height
// just use the height of a fixed sample character
Expand All @@ -191,7 +186,7 @@ private void printHoverLabels( List<TimeStamp> tickTimes, Axis1D axis, TimeStamp
}
}

private double printTickLabels( List<TimeStamp> tickTimes, Axis1D axis, TimeStampFormat format, int width, int height )
protected double printTickLabels( List<TimeStamp> tickTimes, Axis1D axis, TimeStampFormat format, int width, int height )
{
// text heights vary slightly, making the labels appear unevenly spaced in height
// just use the height of a fixed sample character
Expand All @@ -218,28 +213,35 @@ private double printTickLabels( List<TimeStamp> tickTimes, Axis1D axis, TimeStam
return jTimeText;
}

private void drawCurrentTimeTick( GL2 gl, Axis1D axis, int width, int height )
protected void drawCurrentTimeTick( GL2 gl, Axis1D axis, int width, int height )
{
int iTick = axis.valueToScreenPixel( fromTimeStamp( getCurrentTime( ) ) );
TimeStamp currentTime = getCurrentTime( );
double axisTime = fromTimeStamp( currentTime );
int pixelTime = axis.valueToScreenPixel( axisTime );

gl.glColor4fv( currentTimeTickColor, 0 );
gl.glLineWidth( currentTimeLineThickness );
gl.glBegin( GL2.GL_LINES );
gl.glVertex2d( iTick, height );
gl.glVertex2d( iTick, 0 );
gl.glVertex2d( pixelTime, height );
gl.glVertex2d( pixelTime, 0 );
gl.glEnd( );

String text = "NOW";
String text = getCurrentTimeTickText( currentTime );

GlimpseColor.setColor( textRenderer, currentTimeTextColor );
textRenderer.beginRendering( width, height );
try
{
textRenderer.draw( text, iTick + 3, 0 + 3 );
textRenderer.draw( text, pixelTime + 3, 0 + 3 );
}
finally
{
textRenderer.endRendering( );
}
}

protected String getCurrentTimeTickText( TimeStamp currentTime )
{
return "NOW";
}
}
Loading

0 comments on commit 98fc4d1

Please sign in to comment.