本文整理匯總了Java中java.awt.GraphicsDevice.getDefaultConfiguration方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsDevice.getDefaultConfiguration方法的具體用法?Java GraphicsDevice.getDefaultConfiguration怎麽用?Java GraphicsDevice.getDefaultConfiguration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.GraphicsDevice
的用法示例。
在下文中一共展示了GraphicsDevice.getDefaultConfiguration方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: show
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public void show(Point location) {
Rectangle screenBounds = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
for (GraphicsDevice device : gds) {
GraphicsConfiguration gc = device.getDefaultConfiguration();
screenBounds = gc.getBounds();
if (screenBounds.contains(location)) {
break;
}
}
// showing the popup tooltip
cp = new TooltipContentPanel(master.getTextComponent());
Window w = SwingUtilities.windowForComponent(master.getTextComponent());
contentWindow = new JWindow(w);
contentWindow.add(cp);
contentWindow.pack();
Dimension dim = contentWindow.getSize();
if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
}
if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
}
contentWindow.setSize(dim);
contentWindow.setLocation(location.x, location.y - 1); // slight visual adjustment
contentWindow.setVisible(true);
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
w.addWindowFocusListener(this);
contentWindow.addWindowFocusListener(this);
}
示例2: main
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getScreenDevices();
for (final GraphicsDevice gd : sds) {
fail = true;
Robot robot = new Robot(gd);
robot.setAutoDelay(100);
robot.setAutoWaitForIdle(true);
Frame frame = new Frame(gd.getDefaultConfiguration());
frame.setUndecorated(true);
frame.setSize(400, 400);
frame.setVisible(true);
robot.waitForIdle();
frame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("e = " + e);
fail = false;
}
});
Rectangle bounds = frame.getBounds();
robot.mouseMove(bounds.x + bounds.width / 2,
bounds.y + bounds.height / 2);
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
frame.dispose();
if (fail) {
System.err.println("Frame bounds = " + bounds);
throw new RuntimeException("Click in the wrong location");
}
}
}
示例3: getGC
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static X11GraphicsConfig getGC(X11ComponentPeer peer) {
if (peer != null) {
return (X11GraphicsConfig) peer.getGraphicsConfiguration();
} else {
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (X11GraphicsConfig)gd.getDefaultConfiguration();
}
}
示例4: makeVI
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
private static VolatileImage makeVI(final int type) {
final GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
final GraphicsDevice gd = ge.getDefaultScreenDevice();
final GraphicsConfiguration gc = gd.getDefaultConfiguration();
return gc.createCompatibleVolatileImage(SIZE, SIZE, type);
}
示例5: main
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static void main(String[] args) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
testGC(gc);
if (failed) {
throw new RuntimeException("Test FAILED. See err output for more");
}
System.out.println("Test PASSED.");
}
示例6: main
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static void main(final String[] args) {
final GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice gd = ge.getDefaultScreenDevice();
final GraphicsConfiguration gc = gd.getDefaultConfiguration();
final VolatileImage vi =
gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
final int expected = bi.getRGB(2, 2);
int attempt = 0;
BufferedImage snapshot;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
vi.validate(gc);
final Graphics2D g2d = vi.createGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.scale(2, 2);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.drawImage(bi, 0, 0, null);
g2d.dispose();
snapshot = vi.getSnapshot();
if (vi.contentsLost()) {
continue;
}
break;
}
final int actual = snapshot.getRGB(2, 2);
if (actual != expected) {
System.err.println("Actual: " + Integer.toHexString(actual));
System.err.println("Expected: " + Integer.toHexString(expected));
throw new RuntimeException("Test failed");
}
}
示例7: getGC
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static CGLGraphicsConfig getGC(CPlatformView pView) {
if (pView != null) {
return (CGLGraphicsConfig)pView.getGraphicsConfiguration();
} else {
// REMIND: this should rarely (never?) happen, but what if
// default config is not CGL?
GraphicsEnvironment env = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (CGLGraphicsConfig) gd.getDefaultConfiguration();
}
}
示例8: getScreenBounds
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
private Rectangle[] getScreenBounds() {
GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
List<Rectangle> rects = new ArrayList<Rectangle>(gds.length);
for (GraphicsDevice gd : gds) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
rects.add(Utilities.getUsableScreenBounds(gc));
}
return rects.toArray(new Rectangle[rects.size()]);
}
示例9: show
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
void show(Point location) {
Rectangle screenBounds = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
for (GraphicsDevice device : gds) {
GraphicsConfiguration gc = device.getDefaultConfiguration();
screenBounds = gc.getBounds();
if (screenBounds.contains(location)) {
break;
}
}
// showing the popup tooltip
cp = new TooltipContentPanel();
Window w = SwingUtilities.windowForComponent(parent);
contentWindow = new JWindow(w);
contentWindow.add(cp);
contentWindow.pack();
Dimension dim = contentWindow.getSize();
if (screenBounds.width + screenBounds.x - location.x < cp.longestLine) {
// the whole window does fully not fit to the right
// the x position where the window has to start to fully fit to the right
int left = screenBounds.width + screenBounds.x - cp.longestLine;
// the window should have x pos minimally at the screen's start
location.x = Math.max(screenBounds.x, left);
}
if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
}
if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
}
contentWindow.setSize(dim);
contentWindow.setLocation(location.x, location.y + 1); // slight visual adjustment
contentWindow.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
cp.scrollRectToVisible(new Rectangle(1, 1));
}
});
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
w.addWindowFocusListener(this);
contentWindow.addWindowFocusListener(this);
contentWindow.addKeyListener(this);
w.addKeyListener(this);
}
示例10: setScreenAndDimensions
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
private void setScreenAndDimensions(JFrame frame) {
// check multiple displays
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String display = Config.instance().to().getString(Config.Entry.SCREEN.key(), "-");
GraphicsDevice[] screens = ge.getScreenDevices();
if (screens.length == 1) {
setDimensions(frame,
Config.instance().to().getInt(Config.Entry.POS_X.key(), -1),
Config.instance().to().getInt(Config.Entry.POS_Y.key(), -1),
Config.instance().to().getInt(Config.Entry.POS_WIDTH.key(), -1),
Config.instance().to().getInt(Config.Entry.POS_HEIGHT.key(), -1));
} else {
for (GraphicsDevice screen : screens) { // if multiple screens available then try to open on saved display
if (screen.getIDstring().contentEquals(display)) {
JFrame dummy = new JFrame(screen.getDefaultConfiguration());
frame.setLocationRelativeTo(dummy);
dummy.dispose();
Rectangle screenBounds = screen.getDefaultConfiguration().getBounds();
Point pos = new Point(Config.instance().to().getInt(Config.Entry.SCREEN_POS_X.key(), -1),
Config.instance().to().getInt(Config.Entry.SCREEN_POS_Y.key(), -1));
if (pos.x >= 0 && pos.y >= 0) {
pos.x += screenBounds.x;
pos.y += screenBounds.y;
logger.info(" new pos {} {} ", pos.x, pos.y);
}
setDimensions(frame,
pos.x,
pos.y,
Config.instance().to().getInt(Config.Entry.SCREEN_POS_WIDTH.key(), -1),
Config.instance().to().getInt(Config.Entry.SCREEN_POS_HEIGHT.key(), -1));
break;
}
}
}
}
示例11: getGC
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static WGLGraphicsConfig getGC(WComponentPeer peer) {
if (peer != null) {
return (WGLGraphicsConfig)peer.getGraphicsConfiguration();
} else {
// REMIND: this should rarely (never?) happen, but what if
// default config is not WGL?
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (WGLGraphicsConfig)gd.getDefaultConfiguration();
}
}
示例12: getGC
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static GLXGraphicsConfig getGC(X11ComponentPeer peer) {
if (peer != null) {
return (GLXGraphicsConfig)peer.getGraphicsConfiguration();
} else {
// REMIND: this should rarely (never?) happen, but what if
// default config is not GLX?
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (GLXGraphicsConfig)gd.getDefaultConfiguration();
}
}
示例13: getUsableBounds
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
/**
* Return the bounds of a GraphicsDevice, less its screen insets.
* See also java.awt.GraphicsEnvironment.getUsableBounds();
*/
public static Rectangle getUsableBounds(GraphicsDevice gd) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
Rectangle usableBounds = gc.getBounds();
usableBounds.x += insets.left;
usableBounds.y += insets.top;
usableBounds.width -= (insets.left + insets.right);
usableBounds.height -= (insets.top + insets.bottom);
return usableBounds;
}
示例14: main
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static void main(String[] args) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
vi.validate(gc);
VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);
vi1.validate(gc);
if (!(vi instanceof DestSurfaceProvider)) {
System.out.println("Test considered PASSED: no HW acceleration");
return;
}
DestSurfaceProvider p = (DestSurfaceProvider)vi;
Surface s = p.getDestSurface();
if (!(s instanceof AccelSurface)) {
System.out.println("Test considered PASSED: no HW acceleration");
return;
}
AccelSurface dst = (AccelSurface)s;
Graphics g = vi.createGraphics();
g.drawImage(vi1, 95, 95, null);
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.black);
g.fillRect(0, 0, 100, 100);
// after this the validated context color is black
RenderQueue rq = dst.getContext().getRenderQueue();
rq.lock();
try {
dst.getContext().saveState();
dst.getContext().restoreState();
} finally {
rq.unlock();
}
// this will cause ResetPaint (it will set color to extended EA=ff,
// which is ffffffff==Color.white)
g.drawImage(vi1, 95, 95, null);
// now try filling with black again, but it will come up as white
// because this fill rect won't validate the color properly
g.setColor(Color.black);
g.fillRect(0, 0, 100, 100);
BufferedImage bi = vi.getSnapshot();
if (bi.getRGB(50, 50) != Color.black.getRGB()) {
throw new RuntimeException("Test FAILED: found color="+
Integer.toHexString(bi.getRGB(50, 50))+" instead of "+
Integer.toHexString(Color.black.getRGB()));
}
System.out.println("Test PASSED.");
}
示例15: main
import java.awt.GraphicsDevice; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
OSInfo.OSType type = OSInfo.getOSType();
if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {
System.out.println("This test is for Solaris and Linux only..." +
"skipping!");
return;
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multi-screen test... skipping!");
return;
}
for (int screen = 0; screen < gds.length; ++screen) {
GraphicsDevice gd = gds[screen];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
Frame frame = new Frame(gc);
frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,
bounds.y + (bounds.height - SIZE) / 2);
frame.setSize(SIZE, SIZE);
frame.setUndecorated(true);
frame.setVisible(true);
// Maximize Frame to reach the struts
frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
Thread.sleep(2000);
Rectangle frameBounds = frame.getBounds();
frame.dispose();
if (bounds.x + insets.left != frameBounds.x
|| bounds.y + insets.top != frameBounds.y
|| bounds.width - insets.right - insets.left != frameBounds.width
|| bounds.height - insets.bottom - insets.top != frameBounds.height) {
throw new RuntimeException("Test FAILED! Wrong screen #" +
screen + " insets: " + insets);
}
}
System.out.println("Test PASSED!");
}