Example usage for java.awt GraphicsEnvironment getLocalGraphicsEnvironment

List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getLocalGraphicsEnvironment.

Prototype

public static GraphicsEnvironment getLocalGraphicsEnvironment() 

Source Link

Document

Returns the local GraphicsEnvironment .

Usage

From source file:Demo3D.java

/**
 * Constructor that allows to specify the desired initial instances.
 *///from   ww w .j av a 2  s.c o m
public Demo3D() {
    // Set the best GraphicsConfiguration
    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();

    GraphicsConfiguration graphConf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getBestConfiguration(template);

    canvas3D = new Canvas3D(graphConf); // The used Canvas3D

    // Construction of the main frame.
    setTitle("Demo");

    JPanel jMainPanel = new JPanel(true);
    jMainPanel.setLayout(new BorderLayout(0, 5)); // hor_gap and ver_gap

    JPanel jFpsPanel = new JPanel(true);
    jFpsPanel.setBackground(Color.white);

    jLabel = new JLabel("");
    jLabel.setText("Wait for informations");
    jFpsPanel.add(jLabel);

    jMainPanel.add(canvas3D, BorderLayout.CENTER);

    /*
     * // For the stereo-mode with an "Head Monted Display" (HMD). JPanel
     * jScene_Stereo_Panel = new JPanel(true);
     * jScene_Stereo_Panel.setLayout(new GridLayout(1, 2, 0, 0)); // rows,
     * col, hor_gap and ver_gap jScene_Stereo_Panel.add(canvas3D);
     * jScene_Stereo_Panel.add(canvas3D);
     * jMainPanel.add(jScene_Stereo_Panel, BorderLayout.CENTER);
     */

    jMainPanel.add(jFpsPanel, BorderLayout.SOUTH);

    setContentPane(jMainPanel);

    // The ViewBranch class creates the instances of ViewPlatform, View,
    // etc.
    viewBr = new ViewBranch(canvas3D);

    fpsThread = new Thread(this);

    myScene();
}

From source file:org.squidy.nodes.plugin.PatternPlugin.java

@Plugin.Interface
public PNode getInterface() {

    PropertiesTable table = new PropertiesTable();

    TextFieldControl control = new TextFieldControl(remoteAddress);
    control.addPropertyUpdateListener(new PropertyUpdateListener<String>() {
        public void propertyUpdate(String value) {
            remoteAddress = value;//w  w w.ja v  a 2s . c o  m
            disposeControlClient();
        }
    });
    TableEntry<TextFieldControl> entry = new TableEntry<TextFieldControl>("Remote IP", "Description", control,
            "", "");
    table.addEntry(entry);

    control = new TextFieldControl(String.valueOf(remotePort));
    control.addPropertyUpdateListener(new PropertyUpdateListener<String>() {
        public void propertyUpdate(String value) {
            remotePort = Integer.parseInt(value);
            disposeControlClient();
        }
    });
    entry = new TableEntry<TextFieldControl>("Remote Port", "Description", control, "", "");
    table.addEntry(entry);

    control = new TextFieldControl(String.valueOf(patternWidth));
    control.addPropertyUpdateListener(new PropertyUpdateListener<String>() {
        public void propertyUpdate(String value) {
            patternWidth = Integer.parseInt(value);
        }
    });
    entry = new TableEntry<TextFieldControl>("Pattern Width", "Description", control, "", "");
    table.addEntry(entry);

    control = new TextFieldControl(String.valueOf(patternHeight));
    control.addPropertyUpdateListener(new PropertyUpdateListener<String>() {
        public void propertyUpdate(String value) {
            patternHeight = Integer.parseInt(value);
        }
    });
    entry = new TableEntry<TextFieldControl>("Pattern Height", "Description", control, "", "");
    table.addEntry(entry);

    control = new TextFieldControl(String.valueOf(patternColumns));
    control.addPropertyUpdateListener(new PropertyUpdateListener<String>() {
        public void propertyUpdate(String value) {
            patternColumns = Integer.parseInt(value);
        }
    });
    entry = new TableEntry<TextFieldControl>("Pattern Columns", "Description", control, "", "");
    table.addEntry(entry);

    control = new TextFieldControl(String.valueOf(patternRows));
    control.addPropertyUpdateListener(new PropertyUpdateListener<String>() {
        public void propertyUpdate(String value) {
            patternRows = Integer.parseInt(value);
        }
    });
    entry = new TableEntry<TextFieldControl>("Pattern Rows", "Description", control, "", "");
    table.addEntry(entry);

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (final GraphicsDevice device : graphicsEnvironment.getScreenDevices()) {

        CheckBoxControl control2 = new CheckBoxControl(false);
        control2.addPropertyUpdateListener(new PropertyUpdateListener<Boolean>() {

            /**
             * @param value
             */
            public void propertyUpdate(Boolean value) {

                InetAddress address = null;
                try {
                    address = InetAddress.getByName(remoteAddress);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                try {
                    if (client == null) {
                        client = new ControlClient(address, remotePort);
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                SwitchableCommand command = new PatternScreen(device.getIDstring(), patternWidth, patternHeight,
                        patternColumns - 1, patternRows - 1);
                command.setState(value ? Switch.ON : Switch.OFF);
                client.send(command);

                Designer.getInstance().requestFocus();
            }
        });
        TableEntry<CheckBoxControl> entry2 = new TableEntry<CheckBoxControl>("Device " + device.getIDstring(),
                "Description", control2, "", "");
        table.addEntry(entry2);
    }

    CheckBoxControl loadImageControl = new CheckBoxControl(false);
    TableEntry<CheckBoxControl> loadImage = new TableEntry<CheckBoxControl>("Load Camera Image", "Description",
            loadImageControl, "", "");
    table.addEntry(loadImage);

    //   panelControl.setImage("C:\\projects\\Squidy\\squidy-2.0.0\\bayer.PNG");

    return table;

}

From source file:org.alex73.skarynka.scan.ui.scan.ScanDialogController.java

private ScanDialogController(PanelEditController panelController) {
    this.panelController = panelController;
    this.book = panelController.getBook();
    int currentZoom = DataStorage.device.getZoom();

    Dimension[] deviceImageSizes = DataStorage.device.getImageSize();
    Dimension imageSize = deviceImageSizes[0];
    for (int i = 1; i < deviceImageSizes.length; i++) {
        if (!imageSize.equals(deviceImageSizes[i])) {
            JOptionPane.showMessageDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_NOTEQUALSSIZE"), Messages.getString("ERROR_TITLE"),
                    JOptionPane.ERROR_MESSAGE);
            return;
        }/*from www.j ava 2 s  .  co m*/
    }

    int pagesCount = book.getPagesCount();
    if (pagesCount > 0) {
        int bookZoom = book.zoom;

        if (bookZoom != currentZoom) {
            if (JOptionPane.showConfirmDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_ZOOM", pagesCount, bookZoom, currentZoom),
                    Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }
        }
        if (imageSize.width != book.imageSizeX || imageSize.height != book.imageSizeY) {
            if (JOptionPane.showConfirmDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_IMAGESIZE", pagesCount,
                            s(new Dimension(book.imageSizeX, book.imageSizeY)), s(imageSize)),
                    Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }
            for (String page : book.listPages()) {
                Book2.PageInfo pi = book.getPageInfo(page);
                pi.cropPosX = Integer.MIN_VALUE;
                pi.cropPosY = Integer.MIN_VALUE;
            }
        }
    }

    book.zoom = currentZoom;
    book.imageSizeX = imageSize.width;
    book.imageSizeY = imageSize.height;
    String dpi = Context.getSettings().get("dpi." + book.zoom);
    if (dpi != null) {
        book.dpi = Integer.parseInt(dpi);
    } else {
        book.dpi = 300;
    }

    dialog = new ScanDialog(DataStorage.mainFrame, true);
    dialog.btnClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            DataStorage.device.setPreviewPanels();
            panelController.show();
        }
    });

    init(dialog.controlLeft, dialog.liveLeft);
    init(dialog.controlRight, dialog.liveRight);

    checkNumbers();
    showStatus();

    boolean[] visible = DataStorage.device.setPreviewPanels(dialog.liveLeft, dialog.liveRight);
    dialog.controlLeft.setVisible(visible[0]);
    dialog.controlRight.setVisible(visible[1]);
    dialog.liveLeft.setVisible(visible[0]);
    dialog.liveRight.setVisible(visible[1]);

    int[] rotations = DataStorage.device.getRotations();
    dialog.liveLeft.setRotation(rotations[0]);
    dialog.liveRight.setRotation(rotations[1]);

    dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
    dialog.validate();
    dialog.controlLeft.txtNumber.setVisible(false);
    dialog.controlLeft.txtNumber.setVisible(false);

    int keyCode = HIDScanController.getKeyCode(Context.getSettings().get("hidscan-keys"));
    if (keyCode != 0) {
        addAction(keyCode, actionScan);
    }
    if (keyCode != KeyEvent.VK_F1) {
        addAction(KeyEvent.VK_F1, actionScan);
    }
    dialog.btnScan.addActionListener(actionScan);
    addAction(KeyEvent.VK_F2, actionRescan);
    dialog.btnRescan.addActionListener(actionRescan);

    dialog.setVisible(true);
}

From source file:com.googlecode.gmail4j.util.LoginDialog.java

/**
 * Centers the frame on screen/*from w w  w .j a  v a  2s  .co  m*/
 * 
 * @param frame Target frame
 */
private void center(final JFrame frame) {
    final Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().getBounds();
    frame.setLocation(screen.width / 2 - dialog.getSize().width / 2,
            screen.height / 2 - dialog.getSize().height / 2);
}

From source file:com.willwinder.universalgcodesender.uielements.panels.MachineStatusPanel.java

private void applyFont() {
    String fontPath = "/resources/";
    String fontName = "LED.ttf";
    InputStream is = getClass().getResourceAsStream(fontPath + fontName);
    Font font;/*from  w w  w.j  av  a  2  s  . c om*/
    Font big, small;

    try {
        font = Font.createFont(Font.TRUETYPE_FONT, is);
        big = font.deriveFont(Font.PLAIN, 30);
        small = font.deriveFont(Font.PLAIN, 18);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println(fontName + " not loaded.  Using serif font.");
        big = new Font("serif", Font.PLAIN, 24);
        small = new Font("serif", Font.PLAIN, 17);
    }

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.registerFont(big);
    ge.registerFont(small);

    this.machinePositionXValue.setFont(small);
    this.machinePositionXValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.machinePositionYValue.setFont(small);
    this.machinePositionYValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.machinePositionZValue.setFont(small);
    this.machinePositionZValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

    this.workPositionXValue.setFont(big);
    this.workPositionXValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.workPositionYValue.setFont(big);
    this.workPositionYValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    this.workPositionZValue.setFont(big);
    this.workPositionZValue.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
}

From source file:com.sshtools.sshterm.SshTermFullScreenWindowContainer.java

public void setContainerVisible(boolean visible) {
    if (visible && !isContainerVisible()) {
        try {/*  w w  w.ja v a 2s.c om*/
            setVisible(true);
            GraphicsDevice device = panel.getGraphicsConfiguration().getDevice();
            Method m = device.getClass().getMethod("setFullScreenWindow", new Class[] { Window.class });
            m.invoke(device, new Object[] { this });
            log.debug("Full screen container made visible");
            ((SshTerminalPanel) panel).setAutoHideTools(true);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }
    } else if (!visible && isContainerVisible()) {
        try {
            GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
            Method m = device.getClass().getMethod("setFullScreenWindow", new Class[] { Window.class });
            m.invoke(device, new Object[] { null });
            setVisible(false);
            log.debug("Full screen container made invisible");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }
    }
}

From source file:pcgen.gui2.tools.Utility.java

/**
 * Update the size of the dialog to ensure it will fit on the screen.
 *
 * @param dialog The dialog to be resized.
 *///w w  w.  ja va  2 s .  co m
public static void resizeComponentToScreen(Component dialog) {
    // Get the maximum window size to account for taskbars etc
    Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

    final Dimension dialogSize = dialog.getSize();

    if (dialogSize.height > screenBounds.height) {
        dialogSize.height = screenBounds.height;
    }

    if (dialogSize.width > screenBounds.width) {
        dialogSize.width = screenBounds.width;
    }
    dialog.setSize(dialogSize);
}

From source file:es.mityc.firmaJava.libreria.pkcs7.ValidaTarjeta.java

/**
 * This method initializes this//from w ww.  j  a va2  s.c o  m
 * 
 */
private void initialize() {
    this.setSize(new Dimension(534, 264));
    this.setResizable(false);
    this.setModal(true);
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setContentPane(getJPanel());
    this.setTitle(I18n.getResource(LIBRERIAXADES_VALIDARTARJETA_TEXTO_5));

    // Centramos la ventana del applet
    //  Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();

    int screenWidth = 0;
    int screenHeight = 0;
    int longitud = gs.length;
    for (int i = 0; i < longitud; i++) {
        DisplayMode dm = gs[i].getDisplayMode();
        screenWidth = dm.getWidth();
        screenHeight = dm.getHeight();
    }

    this.setLocation((int) (screenWidth / 2) - (int) (539 / 2), (int) (screenHeight / 2) - (int) (497 / 2));
}

From source file:com.flexive.shared.media.impl.FxMediaNativeEngine.java

public static BufferedImage scale(BufferedImage bi, int width, int height) {
    BufferedImage bi2;/*from  ww  w  .j av  a  2s .  com*/
    int scaleWidth = bi.getWidth(null);
    int scaleHeight = bi.getHeight(null);
    double scaleX = (double) width / scaleWidth;
    double scaleY = (double) height / scaleHeight;
    double scale = Math.min(scaleX, scaleY);
    scaleWidth = (int) ((double) scaleWidth * scale);
    scaleHeight = (int) ((double) scaleHeight * scale);
    Image scaledImage;
    if (HEADLESS) {
        // create a new buffered image, don't rely on a local graphics system (headless mode)
        final int type;
        if (bi.getType() != BufferedImage.TYPE_CUSTOM) {
            type = bi.getType();
        } else if (bi.getAlphaRaster() != null) {
            // alpha channel available
            type = BufferedImage.TYPE_INT_ARGB;
        } else {
            type = BufferedImage.TYPE_INT_RGB;
        }
        bi2 = new BufferedImage(scaleWidth, scaleHeight, type);
    } else {
        GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration();
        bi2 = gc.createCompatibleImage(scaleWidth, scaleHeight, bi.getTransparency());
    }
    Graphics2D g = bi2.createGraphics();
    if (scale < 0.3 && Math.max(scaleWidth, scaleHeight) < 500) {
        scaledImage = bi.getScaledInstance(scaleWidth, scaleHeight, Image.SCALE_SMOOTH);
        new ImageIcon(scaledImage).getImage();
        g.drawImage(scaledImage, 0, 0, scaleWidth, scaleHeight, null);
    } else {
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.drawImage(bi, 0, 0, scaleWidth, scaleHeight, null);
    }
    g.dispose();
    return bi2;
}