Search in sources :

Example 26 with GraphicsConfiguration

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;
    }
}
Also used : PageFormat(java.awt.print.PageFormat) HeadlessException(java.awt.HeadlessException) GraphicsConfiguration(java.awt.GraphicsConfiguration) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService) DialogTypeSelection(javax.print.attribute.standard.DialogTypeSelection)

Example 27 with GraphicsConfiguration

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);
}
Also used : Container(java.awt.Container) GraphicsDevice(java.awt.GraphicsDevice) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 28 with GraphicsConfiguration

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;
}
Also used : Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 29 with GraphicsConfiguration

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);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 30 with GraphicsConfiguration

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;
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)136 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)44 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)34 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)30 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)17 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6