B4J Question Custom View Spectrogram - Working with TabPanes

rgarnett1955

Active Member
Licensed User
Longtime User
Hi

I am designing a custom view using Hansolo heat maps. I can get it to work on the main layout, but not on Tabs.

I have attached a zip of the project including the charts-11.8.jar file to go in additional libs.


Main App File:
#Region Project Attributes
    #MainFormWidth: 1300
    #MainFormHeight: 950
    #AdditionalJar: charts-11.8
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Private Spectrogram1 As Spectrogram
    Private tabPane1Obj As TabPage

    Private SpectrogramTab As Spectrogram
    Private TabPane1 As TabPane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Spectrogram1.plotSpectrogram
    
    Try
        SpectrogramTab.plotSpectrogram
    Catch
        Log("tab Spect error 1")
    End Try

    Try
        tabPane1Obj = TabPane1.LoadLayout("tabPane1", "Spectrograph")
    Catch
        Log("tab Spect error 2")
    End Try   
End Sub

The custom view code is:

Custom View: Spectrogram:
#DesignerProperty: Key: BooleanExample, DisplayName: Show Seconds, FieldType: Boolean, DefaultValue: True
#DesignerProperty: Key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Text color

Sub Class_Globals
#If B4J   
    Private fx As JFX
#End If   
    Private xui As XUI 'ignore
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Public mBase As B4XView
    Public Tag As Object
    
    Private mParent As B4XView
    
    Dim chart As JavaObject

    Private mLeft, mTop, mWidth, mHeight As Int
    Private pnlSpectrogram As Pane
End Sub


Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
End Sub


'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    Private mDummy As B4XView
    pnlSpectrogram.Initialize("pnlSpectEvent")
    
    mDummy = Base
    mLeft = mDummy.Left
    mTop = mDummy.Top
    mWidth = mDummy.Width
    mHeight = mDummy.Height
    Tag = mDummy.Tag
    
    'we create a new mBase object to get the Touch event
    mBase = xui.CreatePanel("eventSpect")
    mParent = mDummy.Parent
    mParent.AddView(mBase, mLeft, mTop, mWidth, mHeight)
    mParent.AddView(pnlSpectrogram, mLeft, mTop, mWidth, mHeight)
    mBase.Tag = Me
    
    Tag = mBase.Tag
    mBase.Tag = Me
    mDummy.RemoveViewFromParent
    

    InitClass
End Sub


Private Sub InitClass

End Sub

Private Sub Base_Resize (Width As Double, Height As Double)
 
End Sub

Private Sub imgLegend_MouseClicked (EventData As MouseEvent)
    
End Sub

Private Sub timeSlider_ValueChange (Value As Double)
    
End Sub


Private Sub AreaHeatMapBuilderFcn(dataPointList)
    Dim AreaHeatMapBuilder As JavaObject
    Dim width As Double  = 1001.0
    Dim height As Double = 601.0
    Dim colorMapping As JavaObject
    colorMapping.InitializeStatic("eu.hansolo.fx.charts.tools.ColorMapping")
    
    Dim color As JavaObject = colorMapping.GetField("BLUE_CYAN_GREEN_YELLOW_RED")
    
    Dim qual As JavaObject
    qual.InitializeStatic("eu.hansolo.fx.charts.areaheatmap.AreaHeatMap.Quality")
    Dim quality As JavaObject = qual.GetField("FINE")
        
    AreaHeatMapBuilder.InitializeStatic("eu.hansolo.fx.charts.areaheatmap.AreaHeatMapBuilder")
    chart = AreaHeatMapBuilder.RunMethodJO("create", Null) _
                              .RunMethodJO("prefSize", Array(width, height)) _
                              .RunMethodJO("colorMapping", Array(color)) _
                              .RunMethodJO("dataPoints", Array(dataPointList)) _
                              .RunMethodJO("heatMapOpacity", Array(0.9)) _
                              .RunMethodJO("useColorMapping", Array(True)) _
                              .RunMethodJO("dataPointsVisible", Array(False)) _
                              .RunMethodJO("noOfCloserInfluentPoints", Array(1)) _
                              .RunMethodJO("quality", Array(quality)) _
                              .RunMethodJO("build", Null)

    'add the chart to pnlSpChart
    pnlSpectrogram.AddNode(chart, pnlSpectrogram.Width*0.025, pnlSpectrogram.Height*0.025, pnlSpectrogram.Width*0.95, pnlSpectrogram.Height*0.95)
    
End Sub


public Sub plotSpectrogram(freqX As List,  values As List, noSamples)
    Dim dataPoints As JavaObject
    Dim dataPointList As List
    Dim val1, val2, val3 As Double
    dataPointList.Initialize

val2 = 0
    val1 = 0
    
    val3 = 130
    dataPointList.add(dataPoints.InitializeNewInstance("eu.hansolo.fx.charts.data.DataPoint", Array(val1, val2, val3)))
    
    val2 = 130
    val1 = 0
    
    val3 = 450
    dataPointList.add(dataPoints.InitializeNewInstance("eu.hansolo.fx.charts.data.DataPoint", Array(val1, val2, val3)))
    
    val2 = 0
    val1 = 900
    
    val3 = 50
    dataPointList.add(dataPoints.InitializeNewInstance("eu.hansolo.fx.charts.data.DataPoint", Array(val1, val2, val3)))
    
    val2 = 130
    val1 = 900
    
    val3 = 60
    dataPointList.add(dataPoints.InitializeNewInstance("eu.hansolo.fx.charts.data.DataPoint", Array(val1, val2, val3)))
    
    'Ínitialise and plot
    Dim areaHeatMapBuilder As JavaObject
    Dim width As Double  = mWidth
    Dim height As Double = mHeight
    Dim colorMapping As JavaObject
    colorMapping.InitializeStatic("eu.hansolo.fx.charts.tools.ColorMapping")
    
    Dim color As JavaObject = colorMapping.GetField("BLUE_CYAN_GREEN_YELLOW_RED")
    
    Dim qual As JavaObject
    qual.InitializeStatic("eu.hansolo.fx.charts.areaheatmap.AreaHeatMap.Quality")
    Dim quality As JavaObject = qual.GetField("FINE")
        
    areaHeatMapBuilder.InitializeStatic("eu.hansolo.fx.charts.areaheatmap.AreaHeatMapBuilder")
    chart = areaHeatMapBuilder.RunMethodJO("create", Null) _
                              .RunMethodJO("prefSize", Array(width, height)) _
                              .RunMethodJO("colorMapping", Array(color)) _
                              .RunMethodJO("dataPoints", Array(dataPointList)) _
                              .RunMethodJO("heatMapOpacity", Array(0.99)) _
                              .RunMethodJO("useColorMapping", Array(True)) _
                              .RunMethodJO("dataPointsVisible", Array(False)) _
                              .RunMethodJO("noOfCloserInfluentPoints", Array(1)) _
                              .RunMethodJO("quality", Array(quality)) _
                              .RunMethodJO("build", Null)

    'add the chart to pnlSpectrogram
    pnlSpectrogram.AddNode(chart,pnlSpectrogram.Width*0.025,pnlSpectrogram.Height*0.025,pnlSpectrogram.Width*0.95,pnlSpectrogram.Height*0.95)
End Sub

I suspect the problem is with the designer create view which I lifted form the Custom View booklet, but I'm afraid I don't really understand what it does.

Can some one help me.

If I can get it working I will publish it on the forum so others can use it. The heat map does a good job although it's a bit slow.

Regards
Rob
 

rgarnett1955

Active Member
Licensed User
Longtime User
Sorry,

Gave the tab pages the incorrect name. Fixed it, but it still does not work for the tab spectrum view.

I can't upload the charts-11.8.jar it's too big
 

Attachments

  • Spectrogram.zip
    6.9 KB · Views: 132
Upvote 0
Top