« January 2009 | Main | March 2009 »

February 21, 2009

Hybrid tutorial - Taskbar icon, messages and menus

About
Taskbar icon, messages and menus.

Dependencies
You must create an ext/ folder and add bsf.jar, js.jar and commons-logging.jar into this folder. Add Substance 5 (substance.jar) in the same folder for EDT checking. The application and taskbar icon is defined in the application XML file.

taskbar.js
importPackage(Packages.java.awt)
importPackage(Packages.java.awt.event)
importPackage(Packages.javax.swing)
importPackage(Packages.com.teppefall.hybrid)

context.info("I am " + context.getApplication().getApplicationName())
app = context.getApplication()

awtMenu = new MenuItem("Hello")
awtMenu.addActionListener(function(e) {
JOptionPane.showMessageDialog(app.getApplicationFrame(), "Hello taskbar !")
})
app.getTrayMenu().insertSeparator(0)
app.getTrayMenu().insert(awtMenu, 0)
app.displayTrayMessage("Added a menu item to the taskbar icon popup", JApplication.INFORMATION)

Read more about JApplication here

run.cmd
java -cp teppefall-runtime.jar com.teppefall.hybrid.app.JJHMain taskbar.xml

WindowClipping (13).png

February 17, 2009

Hybrid tutorial - Using SharedVM with JJHMain

Before doing anything it is important that the developer understands the limitations of SharedVM. The SharedVM system uses the same class loader as the parent caller and the same event system. So one crashing application or blocking dialog box will affect all running applications. Also, the shutdown system is different and might cause problems with shutdown hooks.

Starting one Hybrid application within another Hybrid application can be done in one line of Javascript code. Just point JJHMain to the Adobe AIR descriptor file.

new SharedVM("com.teppefall.hybrid.app.JJHMain", ["../other/stuff.xml"]).start()

Hybrid documentation

Component context:
AssemblyContext.

Browser plugin:
JJHPlugin

Desktop runtime:
JJHMain

Teppefall JJHMain uses the Adobe AIR application property format:
Setting AIR application properties (Adobe website).

February 15, 2009

Hybrid tutorial - Teppefall Frame Extensions and the JJHMain parameter -XrunScriptOnOwnThread

About
This showcases Teppefall Frame Extensions and the JJHMain parameter -XrunScriptOnOwnThread.

Dependencies
You must create an ext/ folder and add bsf.jar, js.jar and commons-logging.jar into this folder. Add Substance 5 (substance.jar) in the same folder for EDT checking.

frames.js
importPackage(Packages.java.awt.event)
importPackage(Packages.javax.swing)
importPackage(Packages.java.awt)
importPackage(Packages.com.teppefall.ds)
importPackage(Packages.com.teppefall.ds.console)

context.info("I am " + context.getApplication().getApplicationName())
frame = context.getApplication().getApplicationFrame()

var r = {
run : function() {
new FrameExtension(frame, new JLabel("inside top right"), FrameMovementTracker.INSIDE_TOP_RIGHT)
new FrameExtension(frame, new JLabel("bottom"), FrameMovementTracker.BOTTOM)
new FrameExtension(frame, new JLabel("left"), FrameMovementTracker.LEFT)
new FrameExtension(frame, new JLabel("inside left"), FrameMovementTracker.INSIDE_LEFT)
}
}

if(EventQueue.isDispatchThread()) {
Console.info(this, "Running on EDT") // You can change this with -XrunScriptOnOwnThread - Default is to run on the EDT
r.run()
}
else {
Console.info(this, "Not running on EDT, developer must do the work")
EventQueue.invokeLater(new Runnable(r))
}

run.cmd
java -cp teppefall-runtime.jar com.teppefall.hybrid.app.JJHMain frames.xml

WindowClipping (12).png

February 12, 2009

Hybrid tutorial - The anti-social image viewer

About
This application displays one image from your own desktop. It is cutting edge anti-social-ware.

Dependencies
You must create an ext/ folder and add bsf.jar, js.jar and commons-logging.jar into this folder.

antisocial.xml
<application script="antisocial.js">
<id>com.teppefall.example</id>
<name>The Anti-Social Image Viewer</name>
<version>1.0</version>
<initialWindow>
<title>The Anti-Social Image Viewer</title>
<content>anti_social_gui.jxml</content>
<systemChrome>normal</systemChrome>
</initialWindow>

<icon>
<image64x64>teppefall-stort-ikon.png</image64x64>
</icon>
</application>

anti_social_gui.jfc (Warning: dropping a Effects2D script into the Effects2D panel runs the code without a security sandbox!)
<component class="com.teppefall.ds.render2d.Effects2D" id="effects">
<property name="foreground" type="color" value="#ffffff"/>
<property name="background" type="color" value="#0000ff"/>
<property name="opaque" type="boolean" value="true"/>
</component>

antisocial.js
importPackage(Packages.java.lang)
importPackage(Packages.java.awt.event)
importPackage(Packages.java.io)
importPackage(Packages.java.awt)
importPackage(Packages.java.awt.image)
importPackage(Packages.javax.imageio)
importPackage(Packages.com.teppefall.ds.render2d)
importPackage(Packages.com.teppefall.ds.render2d.compositing)

context.info("I am " + context.getApplication().getApplicationName())
effects = context.getApplication().getAssembly().getComponentById("effects")
context.info(effects)

var ds, img, bg, desktop, file, files, cachedFilename, cachedFileSize, cachedDate
var transHeight = 40
var r = {
destroy : function() {
shutdown = true
},
initialize : function(ds, fgColor, bgColor) {
bg = ColorLogic.deriveTransparent(Color.BLACK, 200)
desktop = new File(System.getProperty("user.home") + "/Desktop")
context.info(desktop)
if(desktop != null && desktop.isDirectory()) {
context.info("find files")
files = desktop.listFiles(new FileFilter({
accept: function (file) {
if(file.getName().endsWith(".jpg") || file.getName().endsWith(".png"))
return true
return false
}
}))
if(files.length != 0) {
index = Math.floor(Math.random()*files.length)
context.info("index=" + index)
file = files[index]
context.info("file=" + file)
}
}
else {
file = new File("teppefall-stort-ikon.png")
}
if(file != null) {
img = ImageIO.read(file)
cachedFilename = file.getName()
cachedFileSize = Math.round(file.length() / 1024) + "KB"
cachedDate = new Date(file.lastModified())
}
logo = ImageIO.read(new File("teppefall-stort-ikon.png"))
},
render : function(g, size) {
g.setColor(Color.WHITE)
g.fillRect(0, 0, size.width, size.height)
g.setColor(Color.WHITE)
g.setClip(0,0,size.width, size.height)
if(img != null) {
g.drawImage(
img,
size.width/2-img.getWidth()/2,
size.height/2-img.getHeight()/2,
img.getWidth(), img.getHeight(), null
)
g.setColor(bg)
g.fillRect(
0,
size.height - transHeight,
size.width+1, // huh?
transHeight+1 // huh?
)
g.setColor(Color.WHITE)
g.drawString(
"Filename: " + cachedFilename +" Size: "+ cachedFileSize +" Modified: "+ cachedDate +" Pixel size: "+ img.getWidth() +"x"+ img.getHeight(),
20,
size.height - (transHeight/2) + (g.getFont().getSize() /2)
);
}
else {
g.setColor(Color.BLACK)
g.drawString("No picture", 20, 40);
}
}
}

effects.setRenderer(new D2DRenderer(r))

run.cmd
java -cp teppefall-runtime.jar com.teppefall.hybrid.app.JJHMain antisocial.xml

The Anti-Social Image Viewer (3).png

February 10, 2009

Hybrid tutorial - Writing a desktop application in Javascript

About
Teppefall Hybrid makes it possible to write Java desktop applications in just Javascript and XML. You simply add an attribute to the application.xml file.

Dependencies
You must create an ext/ folder and add bsf.jar, js.jar and commons-logging.jar into this folder.

hello.xml
<application script="sample.js">
<!-- Configuration code here-->
</application>

hello.jfc (notice the ID attribute)
<component class="javax.swing.JLabel" id="hello" text="Hello World !"/>

sample.js
context.info("Hallo verden !" + context.getApplication().getApplicationName())
context.info(context.getApplication().getAssembly().getComponentById("hello"))

run.cmd
java -cp teppefall-runtime.jar com.teppefall.hybrid.app.JJHMain hello.xml

CWindowssystem32cmd.exe.png

Hello World !.png

February 05, 2009

Hybrid tutorial - Hello world!

About
This tutorial shows you how to create a desktop application in Teppefall Hybrid.

Dependencies
You need the teppefall-runtime.jar file from the Teppefall SDK and the Teppefall Layout application.

hello.xml
<application>

<id>com.teppefall.example</id>
<name>Hello World</name>
<version>1.0</version>

<initialWindow>
<title>Hello World !</title>
<content>hello.jxml</content>
<systemChrome>none</systemChrome>
</initialWindow>

<icon>
<image32x32>icon.png</image32x32>
</icon>

</application>

hello.jfc (open this in Teppefall Layout)
<component class="javax.swing.JLabel" text="Hello World !"/>


hello.jxml (created by Teppefall Layout 4)
<?xml version="1.0" encoding="utf-8"?>
<!--Teppefall Layout 4.0-->
<java version="1.4.2" class="java.beans.XMLDecoder">
<object id="self" class="com.teppefall.ds.layout.jxml.jfc.JFCAssembly">
<void method="add">
<object class="javax.swing.JLabel">
<void property="text">
<string><![CDATA[Hello World !]]></string>
</void>
</object>
</void>
</object>
</java>

run.cmd
java -cp ../teppefall-runtime.jar com.teppefall.hybrid.app.JJHMain hello.xml

This website is all about alpha and beta software

Download non-beta software here