键盘上的舞者

像写情书一样Coding...
随笔 - 20, 文章 - 0, 评论 - 15, 引用 - 0
数据加载中……

2011年3月6日

Node的属性改变后通知属性表单(Propertites Sheet)更新

Node API提供了一个方法在Node属性集变化时通知注册在其上的监听器更新。
protected final void firePropertySetsChange(Node.PropertySet[] o, Node.PropertySet[] n)

如图,精灵动画就是一个自定义的Node,当使用鼠标将Node从A点拖拽到B点时,Node坐标已经改变,可以调用Node的firePropertySetsChange()方法通知属性表单(Propertites Sheet)更新显示。


因为firePropertySetsChange()是个受保护(protected)的方法,如果需要在Node的外部调用,还可以包装在自定义的公共(public)方法里。
public void notifySheetChange(){
    firePropertySetsChange(
null, Sheet.createDefault().toArray());
}

posted @ 2011-03-06 22:15 陈维 阅读(1216) | 评论 (1)编辑 收藏

2010年8月7日

使用TopComponent群组

TopComponent群组的作用是在打开一个TopComponent组件的同时,打开其他相关的TopComponent组件。例如,当打开或者激活GUI编辑器的时候,“组件面板”、“属性”窗口和“检查器”窗口都会出现。当需要一个组件同时伴随着很多其他类似于组件面板窗口的时候,利用TopComponent群组可以轻松实现一个组件的激活引发其他组件被打开或者被选中。

定义群组涉及到2XML文件。首先是wsgrp,它代表“窗口系统群组(Window System Group)”。它定义了“窗口系统”的群组,系统根据它的定义查找对应的目录,它也定义了群组是否应该在启动时打开。另一个文件是wstcgrp,它代表“窗口系统TopComponent群组(Window System TopComponent Group)”,这个文件通过ID识别单态的TopComponent组件,同时还定义了一些群组的打开和关闭属性。

TopComponent群组编程实例

首先创建一个模块项目TopComponentGroup然后新建2个窗口组件(TopComponent),命名为EditorTopComponentSatelliteTopComponent,就像窗口的名字所表示的那样,SatelliteTopComponent将会随着EditorTopComponent的打开和关闭一同打开和关闭。

首先新建一个名为EditorGroupWsgrpxml文件,这个文件里定义了名为EditorGroup的编辑器窗口群组。
<group version="2.0">
    
<module name="org.jqueen.nb.topcomponentgroup" spec="1.0" />
    
<name unique="EditorGroup" />
    
<state opened="false" />
</group>

再新建一个名为SatelliteTopComponentWstcgrp的xml文件,在这个文件里可以通过ID识别出SatelliteTopComponent组件
<tc-group version="2.0">
    
<tc-id id="SatelliteTopComponent" />
    
<open-close-behavior open="true" close="true" />
</tc-group>

编辑模块的layer.xml文件,在系统文件系统中的Windows2目录添加一个Group文件夹,将名为"EditorGroup"的群组添加进Group。
<folder name="Groups">
    
<file name="EditorGroup.wsgrp" url="EditorGroupWsgrp.xml"/>
    
<folder name="EditorGroup">
        
<file name="SatelliteTopComponent.wstcgrp" url="SatelliteTopComponentWstcgrp.xml"/>
    
</folder>
</folder>

编辑EditorTopComponent内容,重写TopComponent类的componentOpened()和componentClosed()方法,在EditorTopComponent被打开和关闭时打开和关闭名为"EditorGroup"的群组。
    @Override
    
protected void componentOpened() {
        TopComponentGroup group 
= WindowManager.getDefault().findTopComponentGroup("EditorGroup");
        
if (group != null) {
            group.open();
        }
    }

    @Override
    
public void componentClosed() {
        TopComponentGroup group 
= WindowManager.getDefault().findTopComponentGroup("EditorGroup");
        
if (group != null) {
            group.close();
        }
    }

至此,就完成了一个TopComponent群组的编辑。执行模块项目,当从窗口菜单中打开EditorTopComponent时SatelliteTopComponent会自动打开,EditorTopComponent被关闭时SatelliteTopComponent也会自动关闭。

样例程序下载

posted @ 2010-08-07 22:46 陈维 阅读(1568) | 评论 (0)编辑 收藏

2010年4月25日

JavaFX进行HTTP Basic认证

最近用JavaFX写一个应用调用Internet上的开放API时需要进行HTTP Basic认证,JavaFX提供了一个类HttpRequest用于发送Web服务的请求,类HttpHeader顾名思义就是用来表示HTTP请求的"Header"了。HttpHeader提供了一个很方便的方法用来创建HTTP Basic认证需要的用户名和密码"Header":
public basicAuth(username: java.lang.String, password: java.lang.String) : HttpHeader
下面就看一下如何使用JavaFX编写进行HTTP Basic认证的代码:
// var user = "user";
// var password = "password";
HttpRequest{
    location: 
// url
    headers: HttpHeader.basicAuth(user, password)
    
// 
}.start();

posted @ 2010-04-25 02:49 陈维 阅读(1494) | 评论 (0)编辑 收藏

2010年4月15日

本公司的几个开发类职位的招聘(上海)

有兴趣的朋友可以先给我发简历,谢谢谢谢谢谢谢谢。
chenweionline#hotmail.com

公司基本信息可以访问
www.jaiziworld.com
www.ccjoy.com

51job上的发布链接
http://search.51job.com/list/co,c,2088688,0000,10,1.html

Java/JavaFX富客户端应用开发工程师

岗位职责:
在Java平台上进行网络游戏相关客户端产品的研发。

任职要求:
1.Java SE基础扎实,了解常用设计模式并且能够在开发过程用适当的应用;
2.熟悉AWT/Swing,Java 2D,JavaFX,NetBeans Platform编程技术;
3.诚实守信,具有良好的团队合作精神,具有迎接挑战的信心和对工作的激情。

优先条件:
1.熟悉游戏相关业务或者有相关游戏、编辑器工具开发经验者;
2.熟悉JavaScript,Flash/Flex,Silverlight等其他RIA开发技术;
3.熟悉Java ME,Android,Windows Mobile,Symbian,iPhone等移动技术平台开发。


Java服务器端开发工程师

岗位职责:
1.具备良好的分析解决问题能力,能独立承担任务和有系统进度把控能力;
2.负责网络游戏服务器端应用逻辑的编写,分布式系统的架构设计;
3.编写相关的开发文档;
4.与项目组美术与策划人员深入沟通,准确实现开发需求。

任职要求:
1.熟悉Java语言,熟练掌握J2EE相关技术;
2.熟悉常用设计模式、数据结构、算法;
3.熟练使用:eclipse、PowerDesigner、UML建模、Word、Excel等常用开发工具。

优先条件:
1.熟悉游戏相关业务或者有相关开发经验者。


移动设备应用开发工程师

岗位职责:
1.在主流的移动平台上开发互联网服务产品。

任职要求:
1.可以熟练使用JavaME,Android或iPhone平台编程技术进行开发。

优先条件:
1.2年以上移动平台应用开发经验;
2.具有个人作品者优先。


游戏算法研发工程师

岗位职责:
1.从事网络游戏相关的技术研发和算法优化工作。

任职要求:
1.数学、人工智能或计算机专业硕士以上学历,数学基础扎实;
2.熟悉图像处理、模式识别、计算机视觉等方面的知识;
3.熟练掌握数值计算相关理论和方法,对算法的并行处理和优化有经验的优先;
4.能够编写技术文档。

优先条件:
1.熟悉Java语言优先

posted @ 2010-04-15 15:24 陈维 阅读(238) | 评论 (0)编辑 收藏

2010年4月9日

JavaFX开发模仿Mac OS的MagicalDock(鱼眼效果)

launch
MagicalDock修改了上个版本的设计,目前的思路是使用2个容器类Container和Flow完成布局,Flow为Node提供水平布局,Container是Flow的容器。
当鼠标移动到Node上,Node大小变化时会改变Flow的尺寸范围,这时动态调整Flow在Container中的位置完成水平位移效果并且将锚定Node的底部使一组Node在变化时都能够底线对齐。

posted @ 2010-04-09 17:58 陈维 阅读(1928) | 评论 (2)编辑 收藏

2010年3月12日

SOSHaiti(Preview) - Game In JavaFX

开发中的一个版本,先睹为快,希望有更多的开发者关注JavaFX技术。

2010年3月22日更新:
1.修正游戏结束时不显示得分的BUG
2.增加一个Menu菜单,在游戏进行中可暂停游戏
3.添加物体间的碰撞特性(使用JBox2D)

posted @ 2010-03-12 22:25 陈维 阅读(1909) | 评论 (6)编辑 收藏

2010年2月25日

JavaFX编译器编译重载方法的一处BUG

直接看测试代码吧,一共2个类:BugTest.fx和A.fx,SDK版本是1.2.3。
/*
 * BugTest.fx
 *
 * Created on 2010-2-25, 22:05:11
 
*/
package org.jqueen.fx.bug;

/**
 * 
@author Leon
 
*/
public class BugTest {

// 取消该方法注释编译将抛出异常
//    function test(a: A): Void {
//        test(5);
//    }

    function test(s: String): Void {
        test(
5);
    }

    function test(i: Integer): Void {
    }

}
/*
 * A.fx
 *
 * Created on 2010-2-25, 22:10:45
 
*/

package org.jqueen.fx.bug;

/**
 * 
@author Leon
 
*/

public mixin class A {}
BugTest里实现了3个带输入参数的重载方法,第一个方法的参数是自定义类型A,A被声明为mixin,后2个的参数是原始类型。只有在第一个方法被注释的情况下该类才可以被编译通过,否则编译器会抛出异常:
An exception has occurred in the OpenJavafx compiler. Please file a bug at the Openjfx-compiler issues home (https://openjfx-compiler.dev.java.net/Issues) after checking for duplicates. Include the following diagnostic in your report and, if possible, the source code which triggered this problem.  Thank you.
java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$ClassSymbol
        at com.sun.tools.javafx.code.JavafxTypes.asSuper(JavafxTypes.java:202)
        at com.sun.tools.javac.code.Types.isSubtypeUnchecked(Types.java:305)
        at com.sun.tools.javafx.comp.JavafxResolve.argumentsAcceptable(JavafxResolve.java:421)
        at com.sun.tools.javafx.comp.JavafxResolve.rawInstantiate(JavafxResolve.java:387)
        at com.sun.tools.javafx.comp.JavafxResolve.selectBest(JavafxResolve.java:711)
        at com.sun.tools.javafx.comp.JavafxResolve.findMemberWithoutAccessChecks(JavafxResolve.java:952)
        at com.sun.tools.javafx.comp.JavafxResolve.findMember(JavafxResolve.java:906)
        at com.sun.tools.javafx.comp.JavafxResolve.findMember(JavafxResolve.java:886)
        at com.sun.tools.javafx.comp.JavafxResolve.findVar(JavafxResolve.java:567)
        at com.sun.tools.javafx.comp.JavafxResolve.findIdent(JavafxResolve.java:1228)
        at com.sun.tools.javafx.comp.JavafxResolve.resolveIdent(JavafxResolve.java:1423)
        at com.sun.tools.javafx.comp.JavafxAttr.visitIdent(JavafxAttr.java:506)
        at com.sun.tools.javafx.tree.JFXIdent.accept(JFXIdent.java:52)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribExpr(JavafxAttr.java:311)
        at com.sun.tools.javafx.comp.JavafxAttr.visitFunctionInvocation(JavafxAttr.java:2239)
        at com.sun.tools.javafx.tree.JFXFunctionInvocation.accept(JFXFunctionInvocation.java:53)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribExpr(JavafxAttr.java:303)
        at com.sun.tools.javafx.comp.JavafxAttr.visitBlockExpression(JavafxAttr.java:1373)
        at com.sun.tools.javafx.tree.JFXBlock.accept(JFXBlock.java:83)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribExpr(JavafxAttr.java:311)
        at com.sun.tools.javafx.comp.JavafxAttr.finishFunctionDefinition(JavafxAttr.java:1863)
        at com.sun.tools.javafx.comp.JavafxMemberEnter$SymbolCompleter.complete(JavafxMemberEnter.java:646)
        at com.sun.tools.javac.code.Symbol.complete(Symbol.java:400)
        at com.sun.tools.javafx.comp.JavafxAttr.visitFunctionDefinition(JavafxAttr.java:1658)
        at com.sun.tools.javafx.tree.JFXFunctionDefinition.accept(JFXFunctionDefinition.java:93)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribExpr(JavafxAttr.java:321)
        at com.sun.tools.javafx.comp.JavafxMemberEnter$SymbolCompleter.complete(JavafxMemberEnter.java:643)
        at com.sun.tools.javac.code.Symbol.complete(Symbol.java:400)
        at com.sun.tools.javafx.comp.JavafxResolve.findMemberWithoutAccessChecks(JavafxResolve.java:943)
        at com.sun.tools.javafx.comp.JavafxResolve.findMember(JavafxResolve.java:906)
        at com.sun.tools.javafx.comp.JavafxResolve.findMember(JavafxResolve.java:886)
        at com.sun.tools.javafx.comp.JavafxResolve.findVar(JavafxResolve.java:567)
        at com.sun.tools.javafx.comp.JavafxResolve.findIdent(JavafxResolve.java:1228)
        at com.sun.tools.javafx.comp.JavafxResolve.resolveIdent(JavafxResolve.java:1423)
        at com.sun.tools.javafx.comp.JavafxAttr.visitIdent(JavafxAttr.java:506)
        at com.sun.tools.javafx.tree.JFXIdent.accept(JFXIdent.java:52)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribExpr(JavafxAttr.java:311)
        at com.sun.tools.javafx.comp.JavafxAttr.visitFunctionInvocation(JavafxAttr.java:2239)
        at com.sun.tools.javafx.tree.JFXFunctionInvocation.accept(JFXFunctionInvocation.java:53)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribExpr(JavafxAttr.java:303)
        at com.sun.tools.javafx.comp.JavafxAttr.visitBlockExpression(JavafxAttr.java:1373)
        at com.sun.tools.javafx.tree.JFXBlock.accept(JFXBlock.java:83)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribExpr(JavafxAttr.java:311)
        at com.sun.tools.javafx.comp.JavafxAttr.finishFunctionDefinition(JavafxAttr.java:1863)
        at com.sun.tools.javafx.comp.JavafxMemberEnter$SymbolCompleter.complete(JavafxMemberEnter.java:646)
        at com.sun.tools.javac.code.Symbol.complete(Symbol.java:400)
        at com.sun.tools.javafx.comp.JavafxAttr.visitFunctionDefinition(JavafxAttr.java:1658)
        at com.sun.tools.javafx.tree.JFXFunctionDefinition.accept(JFXFunctionDefinition.java:93)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:280)
        at com.sun.tools.javafx.comp.JavafxAttr.attribTree(JavafxAttr.java:265)
        at com.sun.tools.javafx.comp.JavafxAttr.attribDecl(JavafxAttr.java:334)
        at com.sun.tools.javafx.comp.JavafxAttr.attribClassBody(JavafxAttr.java:3696)
        at com.sun.tools.javafx.comp.JavafxAttr.attribClass(JavafxAttr.java:2808)
        at com.sun.tools.javafx.comp.JavafxAttr.attribClass(JavafxAttr.java:2763)
        at com.sun.tools.javafx.main.JavafxCompiler.attribute(JavafxCompiler.java:936)
        at com.sun.tools.javafx.main.JavafxCompiler.compile2(JavafxCompiler.java:782)
        at com.sun.tools.javafx.main.JavafxCompiler.compile(JavafxCompiler.java:685)
        at com.sun.tools.javafx.main.Main.compile(Main.java:624)
        at com.sun.tools.javafx.main.Main.compile(Main.java:312)
        at com.sun.tools.javafx.Main.compile(Main.java:84)
        at com.sun.tools.javafx.Main.main(Main.java:69)

posted @ 2010-02-25 23:35 陈维 阅读(1535) | 评论 (1)编辑 收藏

2009年12月21日

JavaFX项目发布时虚拟机参数设置方法

我一直是使用NetBeans IDE开发JavaFX项目,JavaFX项目编译后会在项目目录下建立一个dist文件夹,文件夹包含你的程序和另外3个发布文件,发布文件分别是XXX.html、XXX.jnlp和XXX_browser.jnlp,如果需要设置JavaFX程序运行时的虚拟机参数,那么可以根据你的发布方式选择在XXX.jnlp或者XXX_browser.jnlp里做出修改,它们都是标准的Java网络加载协议文件。

例如,我选择把应用发布到浏览器,那么我使用文本编辑器打开文件XXX_browser.jnlp,在<resources>节点下默认有一个节点<j2se version="1.5+"/>用于描述程序运行需要的JRE版本,我们把它修改为<j2se version="1.5+" java-vm-args="-Xmx256m" />,这样,我们的应用在运行时就可以使用最大256m的内存了。同理,可以设置更多的虚拟机参数,就不一一举例了。

posted @ 2009-12-21 17:02 陈维 阅读(1377) | 评论 (0)编辑 收藏

2009年12月19日

JavaFX实现一个简单的模态窗口

JavaFX直到目前最新的1.2.1版本里没有提供模态窗口或着对话框,我在项目里通过扩展Control自己实现了一个简单的模态窗口,控件由2个类Window.fx和WindowSkin.fx组成,在WindowSkin里实现了Skin的抽象方法contains,在模态下始终返回true。

下面是控件的源码和一个演示demo。

Window.fx
package org.jqueen.fx.scene.control;

import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.control.Control;

/**
 * 
@author Leon Chen
 
*/
public class Window extends Control {

    
public var modal: Boolean;
    
public var background: Image;
    
public var content: Node[];

    override 
protected function create(): Node {
        skin 
= WindowSkin {};
        
super.create();
        }
}

WindowSkin.fx
package org.jqueen.fx.scene.control;

import javafx.scene.control.Skin;
import javafx.scene.Group;
import javafx.scene.image.ImageView;

/**
 * 
@author Leon Chen
 
*/
package class WindowSkin extends Skin {

    def windowControl 
= bind control as Window;
    def bounds : Bounds = bind windowControl.boundsInLocal;
    def background 
= ImageView {
                image: bind windowControl.background
            };
    def content 
= bind windowControl.content;
    
    init {
        node 
= Group {
            content: bind[background, content]
        }
    }

    override 
public function intersects(localX: Number, localY: Number, localWidth: Number, localHeight: Number): Boolean {
        
return bounds.intersects(localX, localY, localWidth, localHeight);
    }

    override 
public function contains(localX: Number, localY: Number): Boolean {
        
if (windowControl.modal) {
            
return true;
            } 
else {
            
return bounds.contains(localX, localY);
            }
    }
}



点击图片可运行程序,非模态时背景可以监听到鼠标事件。

posted @ 2009-12-19 02:45 陈维 阅读(1931) | 评论 (0)编辑 收藏

2009年12月11日

与NetBeans6.8无关

今天NetBeans 6.8正式发布,作为粉丝当然第一时间去官网下载。
随手点开了Overview视频,视频随后部分介绍了一些基于NetBeans Platform开发的富客户端应用,在5分53秒突然一张很熟悉的抓图跃入眼帘,那是我在07年在NetBeans 5.5上开发的一个图像处理富客户端应用,兴奋之余又开始习惯性的反省,这2年在Platform开发上没什么成绩,要努力。



posted @ 2009-12-11 21:12 陈维 阅读(213) | 评论 (0)编辑 收藏