List of usage examples for java.awt GraphicsEnvironment getDefaultScreenDevice
public abstract GraphicsDevice getDefaultScreenDevice() throws HeadlessException;
From source file:io.github.moosbusch.lumpi.util.LumpiUtil.java
public static BufferedImage createCompatibleImage(int width, int height) { GraphicsEnvironment gd = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration conf = gd.getDefaultScreenDevice().getDefaultConfiguration(); return conf.createCompatibleImage(width, height); }
From source file:Main.java
public static void showOnSameScreenAsMouseCenter(Container frame) { Point mouseLocation = MouseInfo.getPointerInfo().getLocation(); GraphicsDevice device;// w w w . j av a 2 s . c om GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice lstGDs[] = ge.getScreenDevices(); ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length); for (GraphicsDevice gd : lstGDs) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screenBounds = gc.getBounds(); if (screenBounds.contains(mouseLocation)) { lstDevices.add(gd); } } if (lstDevices.size() > 0) { device = lstDevices.get(0); } else { device = ge.getDefaultScreenDevice(); } Rectangle bounds = device.getDefaultConfiguration().getBounds(); frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2, bounds.y + bounds.height / 2 - frame.getHeight() / 2); }
From source file:eu.novait.imagerenamer.model.ImageFile.java
private BufferedImage getCompatibleImage(int w, int h) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(w, h); return image; }
From source file:com.mightypocket.ashot.AndroDemon.java
public AndroDemon(final Mediator mediator) { super(mediator.getApplication()); this.mediator = mediator; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); gc = gd.getDefaultConfiguration();/*from w w w .ja v a 2 s.c o m*/ }
From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java
/** * Creates a buffered image from an image * @param image the image/*from ww w. ja va2s. c o m*/ * @return the buffered image */ public static BufferedImage getBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; } // 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:J3dSwingFrame.java
/** * Construct the test frame with a menubar and 3D canvas *///from w ww . java 2 s . co m public J3dSwingFrame() { super("Java3D Tester"); // Disable lightweight menus JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menubar = new JMenuBar(); // File menu JMenu file_menu = new JMenu("File"); menubar.add(file_menu); close_menu = new JMenuItem("Exit"); close_menu.addActionListener(this); file_menu.add(close_menu); setJMenuBar(menubar); GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getBestConfiguration(template); canvas = new Canvas3D(config); // add the canvas to this frame. Since this is the only thing added to // the main frame we don't care about layout managers etc. getContentPane().add(canvas, "Center"); constructWorld(); setSize(600, 600); }
From source file:misc.ModalityDemo.java
/** * Create the GUI and show it. For thread safety, * this method is invoked from the// w w w . java2s. com * 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:com.aurel.track.attachment.AttachBL.java
private static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }/* w w w . ja va2s . c o 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:lucee.runtime.img.Image.java
public static BufferedImage toBufferedImage(java.awt.Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }//from w ww . jav a 2s. c om // 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; }