为自定义驱动程序创建GraphicsDevice [英] Create GraphicsDevice for custom driver

查看:153
本文介绍了为自定义驱动程序创建GraphicsDevice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个在嵌入式系统中使用Java的项目中工作.我有用于屏幕和触摸输入的驱动程序,以及用于文本输入的虚拟键盘.我的屏幕驱动程序有一个Graphics2D对象,您可以将其拖入其中,以及一个repaint(Rectangle)方法进行更新.同样,触摸驱动程序能够为听众生成MouseEvents.

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.

现在,我正在直接将图形绘制到屏幕上.很好,但是我真正想要的是允许我的库用户创建一个JFrame并使用常规的Swing元素.但是,默认的GraphicsEnvironment是无头的,因为Java没有看到我的EInkDriver类或我的TouchDriver类.

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.

我知道有很多方法可以调用组件的paint方法来获取图像;但是,在绘制Container时这会出现问题,我还想向用户展示GraphicsConfiguration,以便他们可以编写类似JFrame frame = new JFrame(getEInkGraphicsConfiguration());的内容并像编写台式机Swing应用程序一样继续进行.

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.

鉴于我已经拥有的这些功能,我将如何创建允许我在项目中使用Swing的GraphicsDeviceGraphicsEnvironment?

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

GraphicsEnvironment中的以下代码显示:

The following code from GraphicsEnvironment shows:

  1. 是否用于无头的系统属性(可以设置).
  2. 环境设置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));
                        }

这篇关于为自定义驱动程序创建GraphicsDevice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆