Example usage for java.awt GraphicsDevice getDefaultConfiguration

List of usage examples for java.awt GraphicsDevice getDefaultConfiguration

Introduction

In this page you can find the example usage for java.awt GraphicsDevice getDefaultConfiguration.

Prototype

public abstract GraphicsConfiguration getDefaultConfiguration();

Source Link

Document

Returns the default GraphicsConfiguration associated with this GraphicsDevice .

Usage

From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java

protected Rectangle getDeviceBounds(GraphicsDevice device) {
    GraphicsConfiguration gc = device.getDefaultConfiguration();
    return gc.getBounds();
}

From source file:org.jas.dnd.Jdk6u10TransparencyManager.java

@Override
public GraphicsConfiguration getTranslucencyCapableGC() {
    GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice defaultScreenDevice = localGraphicsEnvironment.getDefaultScreenDevice();
    GraphicsConfiguration translucencyCapableGC = defaultScreenDevice.getDefaultConfiguration();

    if (!isTranslucencyCapable(translucencyCapableGC)) {
        translucencyCapableGC = null;//from w  w  w  . jav  a2 s .c  om

        log.info("Default graphics configuration does not support translucency");

        GraphicsEnvironment env = localGraphicsEnvironment;
        GraphicsDevice[] devices = env.getScreenDevices();

        for (int i = 0; i < devices.length && translucencyCapableGC == null; i++) {
            GraphicsConfiguration[] configs = devices[i].getConfigurations();

            for (int j = 0; j < configs.length && translucencyCapableGC == null; j++) {
                if (isTranslucencyCapable(configs[j])) {
                    translucencyCapableGC = configs[j];
                }
            }
        }
    }

    if (translucencyCapableGC == null) {
        log.warn("Translucency capable graphics configuration not found");
    }
    return translucencyCapableGC;
}

From source file:com.aurel.track.attachment.AttachBL.java

private static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/* www. j  a v a  2 s .  co  m*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}

From source file:Main.java

void initUI() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    int i = 1;//from w w  w.java2 s  .  com
    for (GraphicsDevice gd : ge.getScreenDevices()) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(createLabel(String.valueOf(i)));
        frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
                .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "exit");
        frame.getRootPane().getActionMap().put("exit", new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        frame.setLocation(gd.getDefaultConfiguration().getBounds().getLocation());
        frame.setUndecorated(true);
        frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
        frame.setVisible(true);
        gd.setFullScreenWindow(frame);
        i++;
    }
}

From source file:org.squidy.nodes.MouseIO.java

@Override
public void onStart() {

    // Search minimum/maximum of x/y.
    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    screenBounds = new Rectangle[devices.length];
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        screenBounds[i] = bounds;/*from ww  w  . j  a va 2s  .  c o  m*/

        double x, y;
        x = bounds.getX();
        minX = Math.min(minX, x);
        x += bounds.getWidth();
        maxX = Math.max(maxX, x);
        y = bounds.getY();
        minY = Math.min(minY, y);
        y += bounds.getHeight();
        maxY = Math.max(maxY, y);
    }

    width = Math.abs(minX) + Math.abs(maxX);
    height = Math.abs(minY) + Math.abs(maxY);

    try {
        robot = new Robot();
        robot.setAutoDelay(0);
    } catch (AWTException e) {
        if (LOG.isErrorEnabled())
            LOG.error("Could not initialize Robot.");
        publishFailure(e);
    }

    if (openInputWindow) {
        inputWindow = InputWindow.getInstance();
        inputWindow.registerMouseListener(this);
    }

    if (directInput && isWindows) {
        if (cdim == null) {
            createDirectInputMouse();
            if (cdim != null) {
                if (cdim.Init(0) != 0) {
                    cdim = null;
                    publishFailure(new SquidyException("Could not initialize DirectInput mouse."));
                }
            }
        }
        if (cdim != null) {
            if (cdim.StartCapture() != 0)
                publishFailure(new SquidyException("Could not start DirectInput mouse."));
            else
                new Thread(new Runnable() {
                    public void run() {
                        while (processing) {
                            cdim.WaitForBufferedData();
                            if (processing)
                                processDirectInputMouseBufferedData();
                        }
                    }
                }, getId() + "_DIM").start();
        }
    }
}

From source file:misc.ModalityDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method is invoked from the//from  www . j  a  v a  2  s  . c o  m
 * event-dispatching thread.
 */
private void createAndShowGUI() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(gc);
    int sw = gc.getBounds().width - ins.left - ins.right;
    int sh = gc.getBounds().height - ins.top - ins.bottom;

    // first document

    // frame f1

    f1 = new JFrame("Book 1 (parent frame)");
    f1.setBounds(32, 32, 300, 200);
    f1.addWindowListener(closeWindow);
    // create radio buttons
    rb11 = new JRadioButton("Biography", true);
    rb12 = new JRadioButton("Funny tale", false);
    rb13 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg1 = new ButtonGroup();
    bg1.add(rb11);
    bg1.add(rb12);
    bg1.add(rb13);
    JButton b1 = new JButton("OK");
    b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb11.isSelected()) {
                title = rb11.getText();
            } else if (rb12.isSelected()) {
                title = rb12.getText();
            } else {
                title = rb13.getText();
            }
            // prepend radio button label to dialogs' titles
            d2.setTitle(title + " (modeless dialog)");
            d3.setTitle(title + " (document-modal dialog)");
            d2.setVisible(true);
        }
    });
    Container cp1 = f1.getContentPane();
    // create three containers to improve layouting
    cp1.setLayout(new GridLayout(1, 3));
    // an empty container
    Container cp11 = new Container();
    // a container to layout components
    Container cp12 = new Container();
    // an empty container
    Container cp13 = new Container();
    // add a button into a separate panel
    JPanel p1 = new JPanel();
    p1.setLayout(new FlowLayout());
    p1.add(b1);
    // add radio buttons and the OK button one after another into a single column
    cp12.setLayout(new GridLayout(4, 1));
    cp12.add(rb11);
    cp12.add(rb12);
    cp12.add(rb13);
    cp12.add(p1);
    // add three containers
    cp1.add(cp11);
    cp1.add(cp12);
    cp1.add(cp13);

    // dialog d2

    d2 = new JDialog(f1);
    d2.setBounds(132, 132, 300, 200);
    d2.addWindowListener(closeWindow);
    JLabel l2 = new JLabel("Enter your name: ");
    l2.setHorizontalAlignment(SwingConstants.CENTER);
    tf2 = new JTextField(12);
    JButton b2 = new JButton("OK");
    b2.setHorizontalAlignment(SwingConstants.CENTER);
    b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l3.setText("by " + tf2.getText());
            d3.setVisible(true);
        }
    });
    Container cp2 = d2.getContentPane();
    // add label, text field and button one after another into a single column
    cp2.setLayout(new BorderLayout());
    cp2.add(l2, BorderLayout.NORTH);
    cp2.add(tf2, BorderLayout.CENTER);
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(b2);
    cp2.add(p2, BorderLayout.SOUTH);

    // dialog d3

    d3 = new JDialog(d2, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d3.setBounds(232, 232, 300, 200);
    d3.addWindowListener(closeWindow);
    JTextArea ta3 = new JTextArea();
    l3 = new JLabel();
    l3.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp3 = d3.getContentPane();
    cp3.setLayout(new BorderLayout());
    cp3.add(new JScrollPane(ta3), BorderLayout.CENTER);
    JPanel p3 = new JPanel();
    p3.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p3.add(l3);
    cp3.add(p3, BorderLayout.SOUTH);

    // second document

    // frame f4

    f4 = new JFrame("Book 2 (parent frame)");
    f4.setBounds(sw - 300 - 32, 32, 300, 200);
    f4.addWindowListener(closeWindow);
    // create radio buttons
    rb41 = new JRadioButton("Biography", true);
    rb42 = new JRadioButton("Funny tale", false);
    rb43 = new JRadioButton("Sonnets", false);
    // place radio buttons into a single group
    ButtonGroup bg4 = new ButtonGroup();
    bg4.add(rb41);
    bg4.add(rb42);
    bg4.add(rb43);
    JButton b4 = new JButton("OK");
    b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // get label of selected radiobutton
            String title = null;
            if (rb41.isSelected()) {
                title = rb41.getText();
            } else if (rb42.isSelected()) {
                title = rb42.getText();
            } else {
                title = rb43.getText();
            }
            // prepend radiobutton label to dialogs' titles
            d5.setTitle(title + " (modeless dialog)");
            d6.setTitle(title + " (document-modal dialog)");
            d5.setVisible(true);
        }
    });
    Container cp4 = f4.getContentPane();
    // create three containers to improve layouting
    cp4.setLayout(new GridLayout(1, 3));
    Container cp41 = new Container();
    Container cp42 = new Container();
    Container cp43 = new Container();
    // add the button into a separate panel
    JPanel p4 = new JPanel();
    p4.setLayout(new FlowLayout());
    p4.add(b4);
    // add radiobuttons and the OK button one after another into a single column
    cp42.setLayout(new GridLayout(4, 1));
    cp42.add(rb41);
    cp42.add(rb42);
    cp42.add(rb43);
    cp42.add(p4);
    //add three containers
    cp4.add(cp41);
    cp4.add(cp42);
    cp4.add(cp43);

    // dialog d5

    d5 = new JDialog(f4);
    d5.setBounds(sw - 400 - 32, 132, 300, 200);
    d5.addWindowListener(closeWindow);
    JLabel l5 = new JLabel("Enter your name: ");
    l5.setHorizontalAlignment(SwingConstants.CENTER);
    tf5 = new JTextField(12);
    tf5.setHorizontalAlignment(SwingConstants.CENTER);
    JButton b5 = new JButton("OK");
    b5.setHorizontalAlignment(SwingConstants.CENTER);
    b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //pass a name into the document modal dialog
            l6.setText("by " + tf5.getText());
            d6.setVisible(true);
        }
    });
    Container cp5 = d5.getContentPane();
    // add label, text field and button one after another into a single column
    cp5.setLayout(new BorderLayout());
    cp5.add(l5, BorderLayout.NORTH);
    cp5.add(tf5, BorderLayout.CENTER);
    JPanel p5 = new JPanel();
    p5.setLayout(new FlowLayout());
    p5.add(b5);
    cp5.add(p5, BorderLayout.SOUTH);

    // dialog d6

    d6 = new JDialog(d5, "", Dialog.ModalityType.DOCUMENT_MODAL);
    d6.setBounds(sw - 500 - 32, 232, 300, 200);
    d6.addWindowListener(closeWindow);
    JTextArea ta6 = new JTextArea();
    l6 = new JLabel();
    l6.setHorizontalAlignment(SwingConstants.RIGHT);
    Container cp6 = d6.getContentPane();
    cp6.setLayout(new BorderLayout());
    cp6.add(new JScrollPane(ta6), BorderLayout.CENTER);
    JPanel p6 = new JPanel();
    p6.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p6.add(l6);
    cp6.add(p6, BorderLayout.SOUTH);

    // third document

    // frame f7

    f7 = new JFrame("Classics (excluded frame)");
    f7.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    f7.setBounds(32, sh - 200 - 32, 300, 200);
    f7.addWindowListener(closeWindow);
    JLabel l7 = new JLabel("Famous writers: ");
    l7.setHorizontalAlignment(SwingConstants.CENTER);
    // create radio buttons
    rb71 = new JRadioButton("Burns", true);
    rb72 = new JRadioButton("Dickens", false);
    rb73 = new JRadioButton("Twain", false);
    // place radio buttons into a single group
    ButtonGroup bg7 = new ButtonGroup();
    bg7.add(rb71);
    bg7.add(rb72);
    bg7.add(rb73);
    Container cp7 = f7.getContentPane();
    // create three containers to improve layouting
    cp7.setLayout(new GridLayout(1, 3));
    Container cp71 = new Container();
    Container cp72 = new Container();
    Container cp73 = new Container();
    // add the label into a separate panel
    JPanel p7 = new JPanel();
    p7.setLayout(new FlowLayout());
    p7.add(l7);
    // add a label and radio buttons one after another into a single column
    cp72.setLayout(new GridLayout(4, 1));
    cp72.add(p7);
    cp72.add(rb71);
    cp72.add(rb72);
    cp72.add(rb73);
    // add three containers
    cp7.add(cp71);
    cp7.add(cp72);
    cp7.add(cp73);

    // fourth document

    // frame f8

    f8 = new JFrame("Feedback (parent frame)");
    f8.setBounds(sw - 300 - 32, sh - 200 - 32, 300, 200);
    f8.addWindowListener(closeWindow);
    JButton b8 = new JButton("Rate yourself");
    b8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showConfirmDialog(null, "I really like my book", "Question (application-modal dialog)",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        }
    });
    Container cp8 = f8.getContentPane();
    cp8.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8));
    cp8.add(b8);
}

From source file:com.josue.tileset.editor.Editor.java

private BufferedImage createTileImage() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gs.getDefaultConfiguration();
    BufferedImage tileImage = gc.createCompatibleImage(TILE_SIZE, TILE_SIZE, Transparency.TRANSLUCENT);
    //        return new BufferedImage(Tile.TILE_SIZE, Tile.TILE_SIZE, BufferedImage.TYPE_INT_ARGB);
    return tileImage;
}

From source file:lucee.runtime.img.Image.java

public static BufferedImage toBufferedImage(java.awt.Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*  w w w  . j a v a  2 s .  co  m*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 *
 * @return//  ww w  .  ja va 2 s .  c om
 */
public GraphicsConfiguration getGraphicsConfiguration() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    return gs.getDefaultConfiguration();
}

From source file:pcgen.gui2.PCGenFrame.java

/**
 * This checks to make sure that the given rectangle will be visible
 * on the current graphics environment// w  w  w.  j a va  2 s  . c o m
 */
private boolean checkBounds(Rectangle rect) {
    if (rect.isEmpty()) {
        return false;
    }
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

    for (GraphicsDevice device : env.getScreenDevices()) {
        Rectangle bounds = device.getDefaultConfiguration().getBounds();
        if (bounds.contains(rect) || bounds.intersects(rect)) {
            return true;
        }
    }
    return false;
}