use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class RasterPrinterJob method pageDialog.
/**
* Display a dialog to the user allowing the modification of a
* PageFormat instance.
* The <code>page</code> argument is used to initialize controls
* in the page setup dialog.
* If the user cancels the dialog, then the method returns the
* original <code>page</code> object unmodified.
* If the user okays the dialog then the method returns a new
* PageFormat object with the indicated changes.
* In either case the original <code>page</code> object will
* not be modified.
* @param page the default PageFormat presented to the user
* for modification
* @return the original <code>page</code> object if the dialog
* is cancelled, or a new PageFormat object containing
* the format indicated by the user if the dialog is
* acknowledged
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.2
*/
public PageFormat pageDialog(PageFormat page) throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
PrintService service = (PrintService) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
PrintService service = getPrintService();
if (service == null) {
ServiceDialog.showNoPrintService(gc);
return null;
}
return service;
}
});
if (service == null) {
return page;
}
updatePageAttributes(service, page);
PageFormat newPage = null;
DialogTypeSelection dts = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
if (dts == DialogTypeSelection.NATIVE) {
// Remove DialogTypeSelection.NATIVE to prevent infinite loop in
// RasterPrinterJob.
attributes.remove(DialogTypeSelection.class);
newPage = pageDialog(attributes);
// restore attribute
attributes.add(DialogTypeSelection.NATIVE);
} else {
newPage = pageDialog(attributes);
}
if (newPage == null) {
return page;
} else {
return newPage;
}
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class JMenu method getPopupMenuOrigin.
/**
* Computes the origin for the <code>JMenu</code>'s popup menu.
* This method uses Look and Feel properties named
* <code>Menu.menuPopupOffsetX</code>,
* <code>Menu.menuPopupOffsetY</code>,
* <code>Menu.submenuPopupOffsetX</code>, and
* <code>Menu.submenuPopupOffsetY</code>
* to adjust the exact location of popup.
*
* @return a <code>Point</code> in the coordinate space of the
* menu which should be used as the origin
* of the <code>JMenu</code>'s popup menu
*
* @since 1.3
*/
protected Point getPopupMenuOrigin() {
int x;
int y;
JPopupMenu pm = getPopupMenu();
// Figure out the sizes needed to caclulate the menu position
Dimension s = getSize();
Dimension pmSize = pm.getSize();
// the size has not yet been initiated
if (pmSize.width == 0) {
pmSize = pm.getPreferredSize();
}
Point position = getLocationOnScreen();
Toolkit toolkit = Toolkit.getDefaultToolkit();
GraphicsConfiguration gc = getGraphicsConfiguration();
Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
for (int i = 0; i < gd.length; i++) {
if (gd[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
GraphicsConfiguration dgc = gd[i].getDefaultConfiguration();
if (dgc.getBounds().contains(position)) {
gc = dgc;
break;
}
}
}
if (gc != null) {
screenBounds = gc.getBounds();
// take screen insets (e.g. taskbar) into account
Insets screenInsets = toolkit.getScreenInsets(gc);
screenBounds.width -= Math.abs(screenInsets.left + screenInsets.right);
screenBounds.height -= Math.abs(screenInsets.top + screenInsets.bottom);
position.x -= Math.abs(screenInsets.left);
position.y -= Math.abs(screenInsets.top);
}
Container parent = getParent();
if (parent instanceof JPopupMenu) {
// We are a submenu (pull-right)
int xOffset = UIManager.getInt("Menu.submenuPopupOffsetX");
int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
if (SwingUtilities.isLeftToRight(this)) {
// First determine x:
// Prefer placement to the right
x = s.width + xOffset;
if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && // popup doesn't fit - place it wherever there's more room
screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
x = 0 - xOffset - pmSize.width;
}
} else {
// First determine x:
// Prefer placement to the left
x = 0 - xOffset - pmSize.width;
if (position.x + x < screenBounds.x && // popup doesn't fit - place it wherever there's more room
screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
x = s.width + xOffset;
}
}
// Then the y:
// Prefer dropping down
y = yOffset;
if (position.y + y + pmSize.height >= screenBounds.height + screenBounds.y && // popup doesn't fit - place it wherever there's more room
screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
y = s.height - yOffset - pmSize.height;
}
} else {
// We are a toplevel menu (pull-down)
int xOffset = UIManager.getInt("Menu.menuPopupOffsetX");
int yOffset = UIManager.getInt("Menu.menuPopupOffsetY");
if (SwingUtilities.isLeftToRight(this)) {
// First determine the x:
// Extend to the right
x = xOffset;
if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && // popup doesn't fit - place it wherever there's more room
screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
x = s.width - xOffset - pmSize.width;
}
} else {
// First determine the x:
// Extend to the left
x = s.width - xOffset - pmSize.width;
if (position.x + x < screenBounds.x && // popup doesn't fit - place it wherever there's more room
screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
x = xOffset;
}
}
// Then the y:
// Prefer dropping down
y = s.height + yOffset;
if (position.y + y + pmSize.height >= screenBounds.height + screenBounds.y && // popup doesn't fit - place it wherever there's more room
screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
// Otherwise drop 'up'
y = 0 - yOffset - pmSize.height;
}
}
return new Point(x, y);
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class SunGraphicsEnvironment method getUsableBounds.
/**
* 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;
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class UnmanagedDrawImagePerformance method makeVI.
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);
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class IncorrectDestinationOffset method main.
public static void main(final String[] args) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE);
BufferedImage bi = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
for (double scale : SCALES) {
while (true) {
// initialize Volatile Image
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.green);
g2d.fillRect(0, 0, SIZE, SIZE);
g2d.dispose();
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
// Draw the VolatileImage to BI with scale and offsets
Graphics2D g = bi.createGraphics();
g.setComposite(AlphaComposite.Src);
g.setColor(Color.RED);
g.fillRect(0, 0, SIZE / 2, SIZE / 2);
g.setColor(Color.BLUE);
g.fillRect(SIZE / 2, 0, SIZE / 2, SIZE / 2);
g.setColor(Color.ORANGE);
g.fillRect(0, SIZE / 2, SIZE / 2, SIZE / 2);
g.setColor(Color.MAGENTA);
g.fillRect(SIZE / 2, SIZE / 2, SIZE / 2, SIZE / 2);
int point2draw = (int) (100 * scale);
int size2draw = (int) (SIZE * scale);
g.drawImage(vi, point2draw, point2draw, size2draw, size2draw, null);
g.dispose();
if (vi.contentsLost()) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
validate(bi, point2draw, size2draw);
break;
}
}
}
Aggregations