java创建驱动程序,为自定义驱动程序创建GraphicsDevice

I'm working on a project using Java in an embedded system. I have drivers for the screen and touch input, and a virtual keyboard for text input. My screen driver has a Graphics2D object you can draw into and a repaint(Rectangle) method for updating. Similarly, the touch driver is capable of generating MouseEvents for listeners.

Right now I'm working with drawing directly to the screen. This is fine, but what I really want is to allow the user of my library to create a JFrame and use normal Swing elements. However, the default GraphicsEnvironment is headless, since Java doesn't see my EInkDriver class or my TouchDriver class.

I'm aware that there are ways to call a component's paint method to get the image; however this has problems when you're painting a Container, and I'd also like to present the user with a GraphicsConfiguration so they can write something like JFrame frame = new JFrame(getEInkGraphicsConfiguration()); and carry on as if they were writing a desktop Swing app.

Given these capabilities that I already have, how would I go about creating a GraphicsDevice or GraphicsEnvironment that would allow me to use Swing in my project?

解决方案

I took a very short look at the abstract class GraphicsEnvironment, and guess, one may derive ones own class, and use the "java.awt.graphicsenv" key of line 64 to register it.

Fortunately there is an abstract class, and the code is little.

Thereafter

The following code from GraphicsEnvironment shows:

System properties (you may set) that are used for headless or not.

The environment setting DISPLAY.

Maybe you can use this info.

String osName = System.getProperty("os.name");

if (osName.contains("OS X") && "sun.awt.HToolkit".equals(

System.getProperty("awt.toolkit")))

{

headless = defaultHeadless = Boolean.TRUE;

} else {

headless = defaultHeadless =

Boolean.valueOf(("Linux".equals(osName) ||

"SunOS".equals(osName) ||

"FreeBSD".equals(osName) ||

"NetBSD".equals(osName) ||

"OpenBSD".equals(osName)) &&

(System.getenv("DISPLAY") == null));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值