SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-11-2010, 10:08 PM
chrishallowell chrishallowell is offline
Sage Advanced User
 
Join Date: Jan 2008
Posts: 169
2D table - can't get the data to display

Hi everyone,
I'm trying to fill a simple 2D table using Java. I'm using the Chap 12 example as my template. I get the column headers and row headers displayed fine but I'm having problems with the data cells.

Could you please take a quick look at my attachments and see what I'm doing wrong? It would be much appreciated!

Thanks,
Chris
Reply With Quote
  #2  
Old 08-12-2010, 12:02 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
For a 2D table you don't pass in an array of data values to the Cell component; you perform an indexing calculation to retrieve the element for a specific row and column and pass in that single element. Sage will take care of iterating over the rows and columns to fill in the entire table.

So in your case you'd want some function GetItem(theRowHeader, theColumnHeader) to pick out the element for the given row and column.

I realize this is just a toy example, but your Java code is not doing anything here that couldn't be done much more easily by CreateArray(). However if you do continue to use Java to populate this table, I'd suggest the following changes:

1. Don't reuse the same list for different purposes (row headers, column headers, and cell data) in your class methods. All of those quantities are needed simultaneously to display the table, and you don't want them stepping on each other by overwriting a shared list. Have each method create its own list internally, populate it, and return it.

2. You don't need to generate new data every time the table is displayed (as you're doing now). If the data is relatively static, call your Java methods once at menu load time, save the results in attribute variables, and use those saved variables to feed the table display. If the data changes in response to some user action, then you can call the Java code again to refresh the variables. This will result in better display performance and a lot less object churn in the Java heap.

3. You don't need to say "this" everywhere. Just refer to your member variables by name within your class methods. Qualifying them with "this" all the time (in my opinion) just clutters the code unnecessarily and detracts from readability. The only times you need "this" are when you're trying to access a member variable that's been masked by a method parameter or local variable (itself a questionable practice), or when you need to pass a reference to your object in to a method of some other class.
__________________
-- Greg
Reply With Quote
  #3  
Old 08-12-2010, 06:55 AM
chrishallowell chrishallowell is offline
Sage Advanced User
 
Join Date: Jan 2008
Posts: 169
Thanks Greg for your very helpful response and suggestions. I really appreciate them.

I'll try this tonight.

This statement in the Studio documentation kind of threw me off... (I should have stuck with the info in the Chap 12 examples section.)
Quote:
2-D tables require three TableComponents, one each for Cell, RowHeader, and ColHeader. Place action chains between the Table widget and its TableComponent widgets, with each action chain creating the data array for its child TableComponent.

Last edited by chrishallowell; 08-12-2010 at 07:08 AM.
Reply With Quote
  #4  
Old 08-12-2010, 10:26 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
I agree the wording on that is somewhat confusing, but you really don't want to be instantiating the entire data array on what could potentially be a very large table. All you need are the elements that actually show on screen. (You do need all the row and column headers, though, so Sage knows how big the table actually is for scrolling purposes.)
__________________
-- Greg
Reply With Quote
  #5  
Old 08-12-2010, 09:30 PM
chrishallowell chrishallowell is offline
Sage Advanced User
 
Join Date: Jan 2008
Posts: 169
Ok, I got it working.

Ok, I got it working. I attached the files for reference in case someone else needs an example of how to populate a 2D table using java. Just keep in mind the java code is not a practical example (See Greg's comments).

Thanks again Greg.

Also you can use TableRow and TableCol, like this:

Studio Action: HelloTable_HelloTableClass_getData2(theHelloTable, TableRow, TableCol)
java method:
Quote:
public String getData2(int rw, int col) {
return "D2";
}
Attached Images
File Type: jpg MyHelloTable2D - Java.jpg (123.9 KB, 127 views)
File Type: jpg MyHelloTable2D - SageTV.jpg (75.1 KB, 123 views)
File Type: jpg MyHelloTable2D - Studio Hier.jpg (183.3 KB, 123 views)
File Type: jpg MyHelloTable2D - Studio QualityList2DTable Properties.jpg (36.1 KB, 113 views)
File Type: jpg MyHelloTable2D - Studio theDataCells Properties.jpg (100.3 KB, 131 views)

Last edited by chrishallowell; 08-12-2010 at 10:14 PM.
Reply With Quote
  #6  
Old 08-13-2010, 12:16 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
This is definitely an improvement, but I'd still suggest some further changes.

1. Your theDataCells component is not receiving a unique value for each cell. Rather, all cells are receiving the string value "REM Populate the data". You're displaying a different caption for each cell, but any additional code you might write that would want to refer to the actual cell value (such as calls to SetFocusForVariable and the like) will not work correctly unless you pass in the unique cell value to the Cell component, like so:

Code:
"REM Populate the data"
    HelloTable_HelloTableClass(theHelloTable, theRowHeader, theColumnHeader)
        theDataCells
            ...
Then you can simply refer to theDataCells as a variable within the subsequent code to obtain the cell value without having to recalculate it:

Code:
"REM Show the recording quality's format"
    theDataCells
        (untitled Text widget)
2. Your Java code is still reusing the same List object as the return value for multiple methods. This is bad practice because it assumes that the caller will make a copy of that list before calling another method of your class. If the caller fails to make a copy, the list gets overwritten and the caller gets confused as values change out from under it. A much better practice is for each method to create a new list each time it's called, and return that list to the caller for the caller's exclusive use, retaining no reference to the created list within the class. That way the caller can do what it likes with the list without fear of confusing or being confused by anybody else. So:

Code:
public List<String> getRestColHeaders()
    {
    List<String> l = new List<String>();
    l.add("CH1");
    l.add("CH2");
    return l;
    }
or better yet:

Code:
public List<String> getRestColHeaders()
    {
    return java.util.Arrays.asList("CH1", "CH2");
    }
__________________
-- Greg
Reply With Quote
  #7  
Old 08-13-2010, 09:05 PM
chrishallowell chrishallowell is offline
Sage Advanced User
 
Join Date: Jan 2008
Posts: 169
Ok, another go at it.... (Maybe the last? )
Attached Images
File Type: jpg MyHelloTable2D - SageTV.jpg (97.4 KB, 110 views)
File Type: jpg MyHelloTable2D - Studio Hier.jpg (193.3 KB, 105 views)
File Type: jpg MyHelloTable2D - Java.jpg (115.4 KB, 106 views)
File Type: jpg MyHelloTable2D - Studio Properties.jpg (120.0 KB, 109 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SageTV display cutoff using secondary display chrishallowell SageTV Software 1 02-09-2008 08:44 AM
After Upgrade, Sage Client Will not display CC Data DocLove SageTV Software 5 04-05-2005 08:25 PM
Dual Display & forcing Sage into Other Display PaulG SageTV Software 12 09-27-2004 04:14 PM


All times are GMT -6. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.