jnodegraphicsenvironment.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 142 行
JAVA
142 行
/*
* $Id: JNodeGraphicsEnvironment.java,v 1.1 2003/11/25 11:51:35 epr Exp $
*/
package org.jnode.awt;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
import org.jnode.awt.font.FontManager;
import org.jnode.awt.image.JNodeBufferedImageGraphics;
import org.jnode.driver.Device;
import org.jnode.driver.DeviceUtils;
import org.jnode.driver.video.FrameBufferAPI;
import org.jnode.naming.InitialNaming;
/**
* JNode implementation of GraphicsEnvironment.
*
* @author Ewout Prangsma (epr@users.sourceforge.net)
*/
public class JNodeGraphicsEnvironment extends GraphicsEnvironment {
/** My logger */
private final Logger log = Logger.getLogger(getClass());
private GraphicsDevice[] devices;
private GraphicsDevice defaultDevice;
/**
* @param image
* @see java.awt.GraphicsEnvironment#createGraphics(java.awt.image.BufferedImage)
* @return The graphics
*/
public Graphics2D createGraphics(BufferedImage image) {
return new JNodeBufferedImageGraphics(image);
}
/**
* @see java.awt.GraphicsEnvironment#getAllFonts()
* @return All fonts
*/
public Font[] getAllFonts() {
final FontManager fm = getFontManager();
if (fm != null) {
return fm.getAllFonts();
} else {
return new Font[0];
}
}
/**
* @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
* @return All font family names
*/
public String[] getAvailableFontFamilyNames() {
final Font[] fonts = getAllFonts();
final HashSet names = new HashSet();
for (int i = 0; i < fonts.length; i++) {
names.add(fonts[i].getFamily());
}
return (String[])names.toArray(new String[names.size()]);
}
/**
* @param l
* @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames(java.util.Locale)
* @return All font family names
*/
public String[] getAvailableFontFamilyNames(Locale l) {
final Font[] fonts = getAllFonts();
final HashSet names = new HashSet();
for (int i = 0; i < fonts.length; i++) {
names.add(fonts[i].getFamily(l));
}
return (String[])names.toArray(new String[names.size()]);
}
/**
* @see java.awt.GraphicsEnvironment#getDefaultScreenDevice()
* @return The default screen device
*/
public GraphicsDevice getDefaultScreenDevice() {
final String devId = System.getProperty("jnode.awt.device", "fb0");
if ((defaultDevice == null) || !devId.equals(defaultDevice.getIDstring())){
final GraphicsDevice[] devs = getScreenDevices();
for (int i = 0;(defaultDevice == null) && (i < devs.length); i++) {
if (devs[i].getIDstring().equals(devId)) {
defaultDevice = devs[i];
log.debug("Using ScreenDevice " + defaultDevice.getIDstring());
}
}
}
return defaultDevice;
}
/**
* @param device
* @see java.awt.GraphicsEnvironment#getDefaultScreenDevice()
*/
public void setDefaultScreenDevice(GraphicsDevice device) {
defaultDevice = device;
}
/**
* @see java.awt.GraphicsEnvironment#getScreenDevices()
* @return All screen devices
*/
public GraphicsDevice[] getScreenDevices() {
if (devices == null) {
final Collection devs = DeviceUtils.getDevicesByAPI(FrameBufferAPI.class);
devices = new GraphicsDevice[devs.size()];
int idx = 0;
for (Iterator i = devs.iterator(); i.hasNext(); idx++) {
devices[idx] = new JNodeFrameBufferDevice((Device) i.next());
}
}
return devices;
}
/**
* Gets the font manager, or null if not found.
* @return The font manager
*/
private FontManager getFontManager() {
try {
return (FontManager) InitialNaming.lookup(FontManager.NAME);
} catch (NamingException ex) {
return null;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?