#!/usr/bin/env jython

# VisAD Tutorial
# Copyright (C) 2000 Ugo Taddei
#
# Jython translation
# Copyright (C) 2002 Frank Gibbons.

import java
from visad import *
from visad.python.JPythonMethods import *
from visad.java2d import DisplayImplJ2D
import java.rmi.RemoteException
from java.awt import *
from javax.swing import *

# VisAD Tutorial example 2_04
#  Simple extension of example P2_03
#  We link a ConstantMap to our DataReference, in order to
#  get large red points.
#  Data is organized as MathType (  index -> ( time, height ) )

# Create the quantities, x and y are measured in SI meters
# Use RealType(String name, Unit u,  Set set), set is null
time =  getRealType("time")
height =  getRealType("height")
t_h_tuple =  RealTupleType( time, height)
index =  RealType("index")

# Create a FunctionType ( index -> ( time, height) )
# Use FunctionType(MathType domain, MathType range)
func_i_tuple =  FunctionType( index, t_h_tuple)

# Create the x_set, with 5 values, but this time using an
# Integer1DSet(MathType type, int length)
index_set =  Integer1DSet(index, 5)

# These are our actual data values for time and height
# Note that these values correspond to the parabola of the
# previous examples. The y (height) values are the same, but the x (time)
# are now given given.
point_vals =  [ [-3.0, -1.5, 0.0, 1.5, 3.0], 
                [0.0, 33.75, 45.0, 33.75, 0.0] ]

# Create a FlatField, that is the Data class for the samples
# Use FlatField(FunctionType type, Set domain_set)
vals_ff = FlatField(func_i_tuple, index_set)

# and put the height values above in it
vals_ff.setSamples(point_vals)

# Create Display and its maps: A 2D display
display =  DisplayImplJ2D("display1")

# Draw scales
dispGMC = display.getGraphicsModeControl()
dispGMC.setScaleEnable(1)

# Create the ScalarMaps: quantity time is to be displayed along XAxis
# and height along YAxis
timeMap =  ScalarMap( time, Display.XAxis )
heightMap =  ScalarMap( height, Display.YAxis )

display.addMap( timeMap )
display.addMap( heightMap )

# Scale heightMap. This will scale the y-axis, because heightMap has DisplayRealType YAXIS
# We simply choose the range from -4 to 4 for the x-axis
# and -10.0 to 50.0 for
timeMap.setRange( -4.0, 4.0)
heightMap.setRange( -10.0, 50.0)

data_ref =  DataReferenceImpl("data_ref")
data_ref.setData( vals_ff )

# Only change from the previous version
# Define a ConstantMap to draw large red points
pointsCMap = [ ConstantMap( 1.0, Display.Red),
               ConstantMap( 0.0, Display.Green),
               ConstantMap( 0.0, Display.Blue),
               ConstantMap( 3.5, Display.PointSize) ]

# Add reference to display, and link DataReference to ConstantMap
display.addReference( data_ref, pointsCMap )

# Create application window, put display into it
jframe = JFrame("VisAD Tutorial example 2_04")
jframe.getContentPane().add(display.getComponent())
jframe.setSize(300, 300)
jframe.setVisible(1)
