MT4j: SwingTextureRenderer
Posted: 13 April 2010 09:43 AM   [ Ignore ]
Avatar
Rank
Joined  2010-02-14
Total Posts:  13
New Member

So, this may be more of a swing question than an MT4j one, but here goes.  My goal is to get a texture composed of rendered html.  I’ve tried code like the following:

JTextPane tp = new JTextPane();
try 
{
    URL url 
= new URL("http://www.google.com");
    
tp.setPage(url);
catch (MalformedURLException e{
    e
.printStackTrace();
catch (IOException e{
    e
.printStackTrace();
}        
SwingTextureRenderer str 
= new SwingTextureRenderer(apptp);
PImage p str.getTextureToRenderTo();
MTImage m = new MTImage(p,app);

This works when I do it in a standalone Swing app.  However, in my MT4j application it’s hanging there somewhere.  I’m pretty sure it’s when the JTextPane is instantiated.  It seems like this should be pretty straightforward and I’m missing something simple.  My Swing-fu is kind of rusty, and poking through JavaDocs hasn’t lead me to anything that works.  Am I going about this the Right™ way?  Any suggestions would be appreciated!

Profile
 
 
Posted: 13 April 2010 11:48 AM   [ Ignore ]   [ # 1 ]
Avatar
RankRankRankRank
Joined  2008-04-30
Total Posts:  612
Elite

Hey,
check out this slightly modified example code which should do what you want.

JTextPane tp = new JTextPane();
        
tp.setSize(800600); //important to set a size
        
try {
            URL url 
= new URL("http://www.google.com");
            
tp.setPage(url);
        
catch (MalformedURLException e{
            e
.printStackTrace();
        
catch (IOException e{
            e
.printStackTrace();
        
}    

        
final SwingTextureRenderer str = new SwingTextureRenderer(mtApplicationtp);
        
MTImage m = new MTImage(str.getTextureToRenderTo(), mtApplication);
        
str.startTimedRefresh(1000); //give the textpane a little time to fetch the data before drawing
        
str.addPaintOcurredListener(new ActionListener() {
            
public void actionPerformed(ActionEvent arg0{
                str
.stopTimedRefresh(); //stop repainting after it was painted once
            
}
        }
);
        
getCanvas().addChild(m);

But the textpane is really only usable for html formatted text. Real webpages will probably not work well. Maybe thats enough for your purposes. If not, try the lobo browser which produces better results.
Btw, be aware that the MTImage has a white border by default. If you dont want that just create a MTRectangle(texture,app);

 Signature 

MT4j - Multi-Touch for Java!

Profile
 
 
Posted: 14 April 2010 07:29 AM   [ Ignore ]   [ # 2 ]
Avatar
RankRank
Joined  2008-10-23
Total Posts:  148
Member

Cool feature!
I checked the hint with the lobo browser and it has much better html layout Rendering, but font quality is still a problem.
I made a sreenshot for comparison: left is the JTexPane, right is the lobo browser.

Is there any solution to get better font rendering ?

Image Attachments
MT4j.Lobo.screenshot.jpg
Profile
 
 
Posted: 14 April 2010 09:31 AM   [ Ignore ]   [ # 3 ]
Avatar
RankRankRankRank
Joined  2008-04-30
Total Posts:  612
Elite
sloopidoopi - 14 April 2010 07:29 AM

Cool feature!
I checked the hint with the lobo browser and it has much better html layout Rendering, but font quality is still a problem.
I made a sreenshot for comparison: left is the JTexPane, right is the lobo browser.

Is there any solution to get better font rendering ?

Yeah, its pretty cool isnt it wink You can render any leightweight swing component to a texture. I already built an experimental mt4j lobo browser this way which also allows interaction. But it has quite a few bugs.

To help the text rendering, in the SwingTextureRenderer class, change the texture’s minification filtering to one of the following:
(in the constructor)

tp.minFilter GLConstants.LINEAR//linear filtering
or
tp.minFilter GLConstants.LINEAR_MIPMAP_LINEAR//creates mip maps, looks best when scaled but needs alittle more memory, time

That could help.

 Signature 

MT4j - Multi-Touch for Java!

Profile
 
 
Posted: 14 April 2010 10:59 AM   [ Ignore ]   [ # 4 ]
Avatar
RankRank
Joined  2008-10-23
Total Posts:  148
Member

Yeah, LINEAR_MIPMAP_LINEAR is a quality boost. smile
(But i would say for clean zoomable text ,Flash is a bit better mad .  Or is there some SVG method with good Layout capabilities?)

Profile
 
 
Posted: 19 April 2010 11:26 PM   [ Ignore ]   [ # 5 ]
Rank
Joined  2010-04-13
Total Posts:  4
New Member

sloopidoopi, How did you get lobo working in mt4j. I tried to follow some of the examples from the lobo website and I keep getting errors.

Profile
 
 
Posted: 20 April 2010 08:58 AM   [ Ignore ]   [ # 6 ]
Avatar
RankRank
Joined  2008-10-23
Total Posts:  148
Member

Look at http://lobobrowser.org/browser/api-info.jsp for code .
You have to download lobo and cobra from http://sourceforge.net/projects/xamj/files/ and make the jar-files in the classpath (Project->Properties->java build path->Libraries-> add external jars ) . (So lobo depends on cobra but you have not import the cobra stuff explicitly)

Profile
 
 
Posted: 20 April 2010 09:41 AM   [ Ignore ]   [ # 7 ]
Rank
Joined  2010-04-13
Total Posts:  4
New Member

yeah, I can get lobo to work as a swing app, but it’s turning it into the mt4j part that isn’t working. It seems like the browser information isn’t loading in time before the swing app converts it to an image. I didn’t know if there was a way to verify the page had loaded first or if you were don’t something different.

Profile
 
 
Posted: 20 April 2010 10:09 AM   [ Ignore ]   [ # 8 ]
Avatar
RankRank
Joined  2008-10-23
Total Posts:  148
Member

As Therion sad above in this Thread you have to make a little timeout for the data fetch into the Browser.
My Code :

FramePanel framePanel = new FramePanel();
        
framePanel.setSize(400300); //important to set a size
        
try {
            
//framePanel.navigate("http://lobobrowser.org/browser/home.jsp");
            
framePanel.navigate("http://mt4j.org/javadocs/latestVersion/org/mt4j/util/TriangleNormalGenerator.html");
        
catch (MalformedURLException e{
            
// TODO Auto-generated catch block
            
e.printStackTrace();
        
}
        
//this.getContentPane().add(framePanel);
        
          
final SwingTextureRenderer str2 = new SwingTextureRenderer(mtApplicationframePanel);
            
MTImage m2 = new MTImage(str2.getTextureToRenderTo(), mtApplication);
            
str2.startTimedRefresh(4000); //give the textpane a little time to fetch the data before drawing
            
str2.addPaintOcurredListener(new ActionListener() {
                
public void actionPerformed(ActionEvent arg0{
                    str2
.stopTimedRefresh(); //stop repainting after it was painted once
                
}
            }
);
            
getCanvas().addChild(m2);

So the code is like Therions, with the JTextPanel only with a FramePanel.(As both a subclasses from Component)

Profile
 
 
Posted: 20 April 2010 10:32 AM   [ Ignore ]   [ # 9 ]
Rank
Joined  2010-04-13
Total Posts:  4
New Member

Changing the time to 4000 did the trick. Thanks.

Profile
 
 
Posted: 12 June 2010 12:40 PM   [ Ignore ]   [ # 10 ]
Rank
Joined  2010-05-30
Total Posts:  15
New Member

2010年6月13日 上午01:36:24 org.lobobrowser.main.PlatformInit getApplicationDirectory
資訊
getApplicationDirectory(): url=file:/C:/Users/Tony/workspace/MT4j/mt4jLibs/lobo.jar,appDir=C:\Users\Tony\workspace\MT4j\mt4jLibs
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\cobra-no-commons.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\javafx-swing.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\javafxc.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\javafxgui.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\javafxrt.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\jlfgr-1_0.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\jmc.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\js.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded extensionExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\jweb-ext.jar,isLibrary=false]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded extensionExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\primary.jar,isLibrary=false]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\Scenario.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager addExtension
資訊
createExtensions(): Loaded library (no lobo-extension.properties): ExtensionInfo[extRoot=C:\Users\Tony\workspace\MT4j\mt4jLibs\ext\websvc.jar,isLibrary=true]
2010年6月13日 上午01
:36:24 org.lobobrowser.main.ExtensionManager createExtensions
資訊
createExtensions(): Creating library class loader with URLs=[[file:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/cobra-no-commons.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/javafx-swing.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/javafxc.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/javafxgui.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/javafxrt.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/jlfgr-1_0.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/jmc.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/js.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/Scenario.jarfile:/C:/Users/Tony/workspace/MT4j/mt4jLibs/ext/websvc.jar]].
2010年6月13日 上午01:36:24 org.lobobrowser.request.RequestEngine processHandler
資訊
run(): ResponseCode=200 for url=http://www.google.com
2010年6月13日 上午01:36:24 org.lobobrowser.request.RequestEngine processHandler
資訊
run(): FROM-HTTPhttp://www.google.com
2010年6月13日 上午01:36:24 org.lobobrowser.request.RequestEngine processHandler
警告
Was unable to handle exception.
java.lang.IllegalStateExceptionNo clientlets found for responseClientletResponseImpl[url=http://www.google.com.hk,method=GET,mimeType=text/html,fromCache=false,requestType=PROGRAMMATIC].
    
at org.lobobrowser.context.ClientletFactory.getClientlet(ClientletFactory.java:76)
    
at org.lobobrowser.request.ClientletRequestHandler.processResponse(ClientletRequestHandler.java:82)
    
at org.lobobrowser.request.RequestEngine.processHandler(RequestEngine.java:856)
    
at org.lobobrowser.request.RequestEngine.access$1(RequestEngine.java:713)
    
at org.lobobrowser.request.RequestEngine$RequestHandlerTask.run(RequestEngine.java:1035)
    
at org.lobobrowser.util.SimpleThreadPool$ThreadRunnable.run(SimpleThreadPool.java:127)
    
at java.lang.Thread.run(Unknown Source)

Hi all, i’m new in MT4J, I would like to insert a browser, so i chose lobo.
But after i add all Jar to the Project, I still get this error… (hv tried to fix it for a few days already.....)
can any one help me =[ thanks!

Profile
 
 
Posted: 13 June 2010 12:53 AM   [ Ignore ]   [ # 11 ]
Rank
Joined  2010-05-30
Total Posts:  15
New Member

I searched in google and found that, it may because it cannot fire the .jar in “ext”.

I put lobo.jar and lobo-pub.jar in ../MT4Jlib and also ../MT4Jlib/ext but the problem still existed....

Any Suggest? thanks!

Profile
 
 
Posted: 15 June 2010 08:44 AM   [ Ignore ]   [ # 12 ]
Avatar
RankRankRankRank
Joined  2008-04-30
Total Posts:  612
Elite

Im not sure whats going wrong here. But you are including too many .jars from the Lobo distribution. In my test project I only included cobra-non-commons.jar, lobo-pub.jar and lobo.jar.

 Signature 

MT4j - Multi-Touch for Java!

Profile
 
 
Posted: 09 December 2015 09:15 PM   [ Ignore ]   [ # 13 ]
Rank
Joined  2015-11-19
Total Posts:  2
New Member
TherioN - 14 April 2010 09:31 AM

sloopidoopi - 14 April 2010 07:29 AM
Cool feature!
I checked the hint with the lobo browser and it has much better html layout Rendering, but font quality is still a problem.
I made a sreenshot for comparison: left is the JTexPane, right is the lobo browser.

Is there any solution to get better font rendering ?

Yeah, its pretty cool isnt it wink You can render any leightweight swing component to a texture. I already built an experimental mt4j lobo browser this way which also allows interaction. But it has quite a few bugs.

To help the text rendering, in the SwingTextureRenderer class, change the texture’s minification js filtering to one of the following:
(in the constructor)

tp.minFilter GLConstants.LINEAR//linear filtering
or
tp.minFilter GLConstants.LINEAR_MIPMAP_LINEAR//creates mip maps, looks best when scaled but needs alittle more memory, time

That could help.

appreciate, useful information.

Profile
 
 
   
 
 
‹‹ MTTextField.setNoStroke?      MTImage problem ››