#!/usr/bin/env jython
# VisAD Tutorial
# Copyright (C) 2000 Ugo Taddei
#
# Jython translation
# Copyright (C) 2002 Frank Gibbons.

try:
    import java
    from javax.swing import *
    from visad import *
    from visad.python.JPythonMethods import *
    from visad.java2d import DisplayImplJ2D
except:
    pass

false = 0
true = not false

#  Enhanced version of program P2_01.
#  Scale y-axis and use a Linear1DSet for time.


class p2_02:

  def __init__(self):
      """The conctructor for our example class."""
      # Create the quantities to be displayed in x- and y-axes
      # time and height are measured in SI seconds and SI meters, respectively
      # Use RealType(String name, Unit u,  Set set), set is null
      time = getRealType("time")
      height = getRealType("height")
      
      # Create a FunctionType, that is the class which represents the function
      # y = f(x), that is the MathType ( time -> height )
      # Use FunctionType(MathType domain, MathType range)
      func_t_h = FunctionType(time, height)
      
      # Those are our actual data values
      # Our Data values for time are represented by the set
      # Create the time_set, with 5 values, but this time using a Linear1DSet
      # Linear1DSet(MathType type, double first, double last, int length)
      time_set = Linear1DSet(time, -3.0, 3.0, 5)
      
      # ...the height values
      h_vals = [[0.0, 33.75, 45.0, 33.75, 0.0]]
      
      # The Data class FlatField, which will hold time and height data.
      # time data are implicitely given by the Set time_set
      # Create a FlatField, that is the class for the samples
      # Use FlatField(FunctionType type, Set domain_set)
      h_vals_ff = FlatField( func_t_h, time_set)
      
      # and put the y values above in it
      h_vals_ff.setSamples( h_vals )
      
      # Create Display and its maps
      # A 2D display
      display = DisplayImplJ2D("display1")
      
      # Get display's graphics mode control and draw scales
      dispGMC = display.getGraphicsModeControl()
      dispGMC.setScaleEnable(true)
      
      # Create the ScalarMaps: quantity time is to be displayed along XAxis
      # and height along YAxis
      # Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
      timeMap = ScalarMap( time, Display.XAxis )
      heightMap = ScalarMap( height, Display.YAxis )
      
      # Add maps to display
      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 0.0 to 50.0
      heightMap.setRange( 0.0, 50.0)
      
      # Create a data reference and set the FlatField as our data
      data_ref = DataReferenceImpl("data_ref")
      data_ref.setData( h_vals_ff )
      
      # Add reference to display
      display.addReference( data_ref )
      
      # Create application window, put display into it
      jframe = JFrame("Visad Tutorial example 2_02")
      jframe.getContentPane().add(display.getComponent())
      
      # Set window size and make it visible
      jframe.setSize(300, 300)
      jframe.setVisible(true)
      


p2_02()
