OTrunkStep: getReportForLearner() implementation

1 view
Skip to first unread message

Geoffrey Kwan

unread,
Jan 22, 2008, 1:05:18 PM1/22/08
to otrun...@googlegroups.com
Hi,

I am trying to implement the getReportForLearner() function in OTrunkStep.

We found where it creates the xhtml in OTMLToXHTMLConverter.java. The bodyText contains the xhtml in the code below.

            OTJComponentView objView = getOTJComponentView(topLevelOTObject, mode);

            OTXHTMLView xhtmlView = null;
            String bodyText = "";
            if(objView instanceof OTXHTMLView) {
                xhtmlView = (OTXHTMLView) objView;
                bodyText = xhtmlView.getXHTMLText(topLevelOTObject);
            }
            //System.out.println(bodyText);

We are wondering how to obtain the OTJComponentView from within an OTrunkStep.

We are also wondering how to obtain topLevelOTObject which is a DefaultOTObject from within an OTrunkStep. Is it possible to obtain a DefaultOTObject from the getComponent() method within OTrunkStep?

Does any of the code below relate to how we could obtain the DefaultOTObject? (this code is from within getComponent())

            OTViewContainerPanel otPanel = viewerHelper.createViewContainerPanel();
            panel.setLayout(new BorderLayout());

            panel.add(otPanel, BorderLayout.CENTER);

            OTObject root = viewerHelper.getRootObject();


Thanks,
Geoff

Scott Cytacki

unread,
Jan 23, 2008, 2:31:19 PM1/23/08
to otrun...@googlegroups.com
Hi Geoff, thanks for joining the list.

To start off with a page that everyone might find useful is this one:
http://confluence.concord.org/display/CSP/OTrunk+HowTo
Any general info about OTrunk that other developers might find useful
should go here.

You can also create individual pages for more lengthy pieces of info,
for example:
http://confluence.concord.org/display/CSP/OTrunk+Script+Example

At some point the HowTo page will be reorganized, so it isn't one giant
page.

I answered your specific questions below.

Geoffrey Kwan wrote:
> Hi,
>
> I am trying to implement the getReportForLearner() function in OTrunkStep.
>
> We found where it creates the xhtml in OTMLToXHTMLConverter.java. The
> bodyText contains the xhtml in the code below.
>
> OTJComponentView objView =
> getOTJComponentView(topLevelOTObject, mode);
>
> OTXHTMLView xhtmlView = null;
> String bodyText = "";
> if(objView instanceof OTXHTMLView) {
> xhtmlView = (OTXHTMLView) objView;
> bodyText = xhtmlView.getXHTMLText(topLevelOTObject);
> }
> //System.out.println(bodyText);
>
> We are wondering how to obtain the OTJComponentView from within an
> OTrunkStep.

I think you should be able to use the OTMLToXHTMLConverter to do the
work. So you don't need to worry about getting the OTJComponentView
yourself. If not then we/you should fix it so you can use it. All you
have to worry about (I think) is calling the correct constructor for
OTMLToXHTMLConverter, calling setXHTMLParams, and then calling the run
method.

I think the right constructor is probably:
public OTMLToXHTMLConverter(OTViewFactory viewFactory, OTObject otObject)

you should be able to get the correct viewFactory and root object, out
of the viewerHelper used by OTrunkStep.


>
> We are also wondering how to obtain topLevelOTObject which is a
> DefaultOTObject from within an OTrunkStep. Is it possible to obtain a
> DefaultOTObject from the getComponent() method within OTrunkStep?
>
> Does any of the code below relate to how we could obtain the
> DefaultOTObject? (this code is from within getComponent())
>
> OTViewContainerPanel otPanel =
> viewerHelper.createViewContainerPanel();
> panel.setLayout(new BorderLayout());
>
> panel.add(otPanel, BorderLayout.CENTER);
>
> OTObject root = viewerHelper.getRootObject();

This shouldn't be necessary if you follow the approach above.

The OTMLToXHTMLConvert code has a few bugs that are mentioned here:
http://jira.concord.org/browse/ALL-38

Hopefully you won't run into these problems with the draw tool.


Scott

Geoffrey Kwan

unread,
Feb 7, 2008, 8:47:46 PM2/7/08
to otrun...@googlegroups.com
I am trying to invoke the constructor

public OTMLToXHTMLConverter(OTViewFactory viewFactory, DefaultOTObject otObject)

from within OTrunkStep.java


Is there a way to obtain a DefaultOTObject from within the OTrunkStep. I can only obtain an OTObject from viewerHelper.getRootObject() but need a DefaultOTObject. I have tried casting the viewerHelper.getRootObject() to a DefaultOTObject but I receive a ClassCastException.

Thanks,
Geoff

Scott Cytacki

unread,
Feb 8, 2008, 11:23:40 AM2/8/08
to otrun...@googlegroups.com
I just checked in some changes to OTMLToXHTMLConverter which make it
work with most OTObject.

Sam, can you verify that these changes don't break how you are using it
in UDL?
If they do break it can you send me instructions how I should test it,
so I can do that as I make changes?

Geoff, if you are using this with the OTrunkStep you are probably
getting the classes from a otrunk jar in your local maven repository.
If you want to test you code with these latest changes you'll need to
add the otrunk project to your launcher classpath infront of the maven
dependencies. Once this OTMLToXHTMLConverter code is stabilized you can
probably go back to using the otrunk jar in your local maven repository.

Scott

Geoffrey Kwan wrote:
> I am trying to invoke the constructor
>
> public OTMLToXHTMLConverter(OTViewFactory viewFactory, DefaultOTObject
> otObject)
>
> from within OTrunkStep.java
>
>
> Is there a way to obtain a DefaultOTObject from within the OTrunkStep.
> I can only obtain an OTObject from viewerHelper.getRootObject() but
> need a DefaultOTObject. I have tried casting the
> viewerHelper.getRootObject() to a DefaultOTObject but I receive a
> ClassCastException.
>
> Thanks,
> Geoff
>
> On Jan 23, 2008 11:31 AM, Scott Cytacki <scyt...@fastmail.fm

Geoffrey Kwan

unread,
Feb 11, 2008, 8:47:37 PM2/11/08
to otrun...@googlegroups.com
When I try to call oTMLToXHTMLConverter.run(); I receive an exception. Is there any way to resolve this?

Here's my code below

        OTMLToXHTMLConverter oTMLToXHTMLConverter = null;
        File outputFile = new File("output.txt");
        OTObject otObject = null;
        try {
            otObject = viewerHelper.getRootObject();
            oTMLToXHTMLConverter = new OTMLToXHTMLConverter(viewerHelper.getViewFactory(), otObject);
            oTMLToXHTMLConverter.setXHTMLParams(outputFile, 200, 200);
            oTMLToXHTMLConverter.run();
        } catch(Exception e) {
            System.out.println("Exception: " + e);
        }

Here is the exception

Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
    at java.awt.EventQueue.invokeAndWait(EventQueue.java:834)
    at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1257)
    at org.concord.otrunk.OTMLToXHTMLConverter.embedComponent(OTMLToXHTMLConverter.java:252)
    at org.concord.otrunk.OTMLToXHTMLConverter.embedOTObject(OTMLToXHTMLConverter.java:322)
    at org.concord.otrunk.OTMLToXHTMLConverter.run(OTMLToXHTMLConverter.java:195)
    at org.telscenter.pas.otrunk.OTrunkStep.getReportForLearner(OTrunkStep.java:357)
    at org.telscenter.pas.steps.ShowAllWorkStep.traverseActivities(ShowAllWorkStep.java:247)
    at org.telscenter.pas.steps.ShowAllWorkStep.getComponent(ShowAllWorkStep.java:129)
    at org.telscenter.pas.navigation.PasProjectNavigationTaskPanel$6.actionPerformed(PasProjectNavigationTaskPanel.java:1081)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
    at java.awt.Component.processMouseEvent(Component.java:5488)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
    at java.awt.Component.processEvent(Component.java:5253)
    at java.awt.Container.processEvent(Container.java:1966)
    at java.awt.Component.dispatchEventImpl(Component.java:3955)
    at java.awt.Container.dispatchEventImpl(Container.java:2024)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.java:2010)
    at java.awt.Window.dispatchEventImpl(Window.java:1774)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


Thanks,
Geoff

Scott Cytacki

unread,
Feb 11, 2008, 10:35:16 PM2/11/08
to otrun...@googlegroups.com
It isn't clear from the code, but instead of calling run() you should
call start().

The OTMLToXHTMLConverter extends the Thread class. With the Thread
class if you call the start method it creates a new thread of execution
and then calls the run method in this new thread.

Scott

Geoffrey Kwan wrote:
> When I try to call oTMLToXHTMLConverter.run(); I receive an exception.
> Is there any way to resolve this?
>
> Here's my code below
>
> OTMLToXHTMLConverter oTMLToXHTMLConverter = null;
> File outputFile = new File("output.txt");
> OTObject otObject = null;
> try {
> otObject = viewerHelper.getRootObject();
> oTMLToXHTMLConverter = new
> OTMLToXHTMLConverter(viewerHelper.getViewFactory(), otObject);
> oTMLToXHTMLConverter.setXHTMLParams(outputFile, 200, 200);

> *oTMLToXHTMLConverter.run();*

Geoffrey Kwan

unread,
Feb 12, 2008, 8:41:52 PM2/12/08
to otrun...@googlegroups.com
When I try to save an OT Drawing I click "Save" and then it says "Your data has been saved" but sometimes it doesn't save the drawing if I leave and come back to the step. If I try to Show All Work, I then receive this output in the console in Eclipse

Loaded objects in: jar:podar:dddddddd-0002-0002-0000-000982454303!/drawing.otml
error reading property "template-id" it is not defined for type: org.concord.graph.util.state.OTDrawingTool
Loaded objects in: unknown_name

and the image is blank in Show All Work.

Do you guys know why it doesn't save all the time when the "Save" button is clicked?


Another issue is that the dimension of the image that is captured has a max of width = 550, and height = 225 which is set in the OTDrawingToolView.java in the function getPrintDimention(int containerDisplayWidth, int containerDisplayHeight). This may cause the drawing to be cropped since some students may have their VLE window set to a larger size. Are the dimensions set to 550, and 225 for a reason or can I increase it in OTDrawingToolView.java?


Thanks for all your help Scott,
Geoff

Scott Cytacki

unread,
Feb 13, 2008, 9:52:26 AM2/13/08
to otrun...@googlegroups.com
Geoffrey Kwan wrote:
> When I try to save an OT Drawing I click "Save" and then it says "Your
> data has been saved" but sometimes it doesn't save the drawing if I
> leave and come back to the step.
It should only be saving the drawing if you have changed it. If you
have changed it, and you leave the step it should be automatically
saved. Are you testing this using a pas-builder to create simple curnit?

Have you tried debugging it? I find debugging something is good way to
learn how it works. If you find some code that you can't figure out let
us know and we can help. We could talk about this more at our meeting
today.

> If I try to Show All Work, I then receive this output in the console
> in Eclipse
>
> Loaded objects in:
> jar:podar:dddddddd-0002-0002-0000-000982454303!/drawing.otml
> error reading property "template-id" it is not defined for type:
> org.concord.graph.util.state.OTDrawingTool
> Loaded objects in: unknown_name
>
> and the image is blank in Show All Work.

the template-id error is not a problem. I think the "unknown_name" is
not a problem either. Usually that would be the url for the file the
students work is loaded from, but since it is coming from a sockEntry it
has an "unknown_name".

>
> Do you guys know why it doesn't save all the time when the "Save"
> button is clicked?

It will only save if it thinks the drawing has been changed. When you
say it doesn't save is that because you are debugging it and can tell
the data isn't going into a sock entry? Or is it that you are not
seeing your drawing?


>
> Another issue is that the dimension of the image that is captured has
> a max of width = 550, and height = 225 which is set in the
> OTDrawingToolView.java in the function getPrintDimention(int
> containerDisplayWidth, int containerDisplayHeight). This may cause the
> drawing to be cropped since some students may have their VLE window
> set to a larger size. Are the dimensions set to 550, and 225 for a
> reason or can I increase it in OTDrawingToolView.java?

Yeah that is a problem. OTDrawingToolView should calculate the best
dimension in the getPrintDimension method. The best solution would be this:

First it looks at the width of the background image, and it then looks
at the bounding box of all the objects that drawn. It should take the
larger of the two in each direction. Just that would get us pretty far.

Second it should compare this to the containerDisplay* params. If its
calculate size is larger then it needs to store some scale factor, and
when the getComponent method is called this scale factored should be
used to shrink the drawing down to size.

Can you try adding the first part of the calculation to OTDrawingToolView?


>
>
> Thanks for all your help Scott,

No problem, keep it coming. :)

Scott

Geoffrey Kwan

unread,
Jul 21, 2008, 9:23:23 PM7/21/08
to otrun...@googlegroups.com
Is there an easy way to determine the bounding box of all the objects drawn? or will I have to iterate through all the drawing objects and figure out the farthest points from the center of the drawing?

I believe the the screenshot of the drawing is taken from the center of the drawing step. Therefore just obtaining the size of the background image or the size of an object and taking a screenshot with those dimensions might not capture all the student's drawing if they drew their picture off to the side or top, etc. The background image actually seems to be added to the very left of the drawing screen and not centered either. It looks like I'll need to find the farthest points away from the center and determine the screenshot size that will capture all of the student's drawing unless there is a simpler way of doing it?

Thanks,
Geoff

Geoffrey Kwan

unread,
Jul 22, 2008, 9:19:24 PM7/22/08
to otrun...@googlegroups.com
So far I have implemented the iteration through the shapes and pencil drawings and determining the necessary dimensions that will capture all the drawing objects. I have access to the drawing objects because I pass the OTDrawingTool to OTDrawingToolView.getPrintDimension(). The OTDrawingToolView does have an OTDrawingTool drawingTool member variable but I found that to be null when getPrintDimension() was called. I haven't figured out how to get the OTDrawingTool drawingTool member variable set before getPrintDimension() is called yet.

In OTDrawingToolView.java I need access to these two classes

import org.concord.data.state.OTDataStore;
import org.concord.datagraph.state.OTDataGraphable;

and was wondering how we can get those two classes accessible within the graphutil project? I tried adding datagraph to the classpath but that resulted in a cyclical dependency. Right now just to get it working on my computer, I have added the datagraph-0.1.0-SNAPSHOT.jar and the data project to the classpath.

I have attached OTDrawingToolView.java so you can see what and how I have implemented this so far. Feel free to tell me if I'm doing any no, no's.

Thanks,
Geoff
OTDrawingToolView.java

Sam Fentress

unread,
Jul 23, 2008, 9:15:15 AM7/23/08
to otrun...@googlegroups.com
In OTDrawingToolView.java I need access to these two classes

import org.concord.data.state.OTDataStore;
import org.concord.datagraph.state.OTDataGraphable;

and was wondering how we can get those two classes accessible within the graphutil project? I tried adding datagraph to the classpath but that resulted in a cyclical dependency. Right now just to get it working on my computer, I have added the datagraph-0.1.0-SNAPSHOT.jar and the data project to the classpath.
I have attached OTDrawingToolView.java so you can see what and how I have implemented this so far. Feel free to tell me if I'm doing any no, no's.


Hi Geoff,

I didn't get the attachment, so I can't see quite what you're doing, but I don't believe that you need the OTDataStores or the OTDataGraphables. Since the draw tool has access to the shapes, it must know the bounds of those shapes, I would think.

It looks like the draw tool has an objList, which contains a set of DrawingObjects (see the addDrawingObject method). DrawingObjects include DrawingShapes, lines and stamps. The DrawingObject interface extends BoundingBoxProvider, which returns a bounding box. So each drawing object inside the draw tool should provide a bounding box. I haven't tried this myself, so I'm not certain what coordinate system the bounding box is, but I would assume that you could use it to get the over-all bounding box needed.

Sam

Geoffrey Kwan

unread,
Jul 24, 2008, 7:30:15 PM7/24/08
to otrun...@googlegroups.com
It doesn't seem as if objList in DrawingGraph is being populated with the objects that I try to draw. When I debug through the OTrunkStep.getComponent() and try to see what is in my DrawingGraph objList, there is nothing in it even after I have drawn several objects. Perhaps the OTDrawingToolView isn't properly updating the objList because some parameters aren't set up correctly? Or perhaps the OTDrawingView is just storing the draw objects somewhere else because they are persisted even after I navigate away from the step and come back.

Thanks,
Geoff

Geoffrey Kwan

unread,
Jul 24, 2008, 8:41:49 PM7/24/08
to otrun...@googlegroups.com
After trying to look at this more, I've noticed that during the process of interacting with the draw step, i.e. drawing and getting the report for learner, that multiple instances of OTDrawingToolView(DrawingGraph) are created. One of the instances always has an empty objList while the other one is the one that actually stores all the drawing objects. The problem is that when I try to access the OTDrawingToolView, I receive the OTDrawingToolView that always has the empty objList.

The first OTDrawingToolView is created in OTrunkStep.getComponent(boolean). This is the one that always has the empty objList.

The second OTDrawingToolView is created from some thread that calls OTViewContainerPanel.createJComponent() that eventually creates an OTDrawingToolView but I'm not sure where that thread is started from. This is the one that has the populated objList.

How can I access the OTDrawingToolView that has its objList populated?

Thanks,
Geoff
Reply all
Reply to author
Forward
0 new messages