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:com.callidusrobotics.swing.SwingConsole.java

private void initConsole(final Font font, final int rows, final int cols) {
    frame = new JFrame();
    icon = new ImageIcon();
    label = new JLabel(icon);

    // Compute font metrics
    final DisplayMode displayMode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDisplayMode();//from   w w w  .j av  a  2  s  . c  o  m
    frame.setVisible(true);
    imageBuffer = frame.createImage(displayMode.getWidth(), displayMode.getHeight());
    graphicsRenderer = imageBuffer.getGraphics();
    graphicsRenderer.setFont(font);

    final FontMetrics fontMetrics = graphicsRenderer.getFontMetrics(font);

    charHeight = fontMetrics.getHeight();
    charWidth = fontMetrics.getHeight();
    charHOffset = 0;
    charVOffset = fontMetrics.getAscent();

    // Compute console dimensions and initialize graphics renderer
    final int width = charWidth * cols;
    final int height = charHeight * rows;

    imageBuffer = frame.createImage(width, height);
    graphicsRenderer = imageBuffer.getGraphics();
    graphicsRenderer.setFont(font);

    render();

    label.setBackground(TrueColor.MAGENTA);
    label.setBounds(0, 0, width, height);
    label.setVisible(true);

    frame.setBounds(0, 0, width, height);
    frame.setBackground(TrueColor.MAGENTA);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(label);
    frame.setCursor(null);
    frame.pack();

    frame.setLocationRelativeTo(null);
    frame.setResizable(false);

    frame.addKeyListener(this);
}

From source file:zz.pseas.ghost.utils.BrowserUtil.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }//ww  w  .  ja  v a  2s.c  om
    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        int transparency = Transparency.OPAQUE;
        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;
        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

public Main() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);/*from w  ww . j  av a 2s  .  c o  m*/
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JSpinner defaultSpinner = new JSpinner();
    addRow("Default", defaultSpinner);

    JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5));
    addRow("Bounded", boundedSpinner);

    String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts));
    addRow("List", listSpinner);

    JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) {
        public Object getNextValue() {
            return super.getPreviousValue();
        }

        public Object getPreviousValue() {
            return super.getNextValue();
        }
    });
    addRow("Reverse List", reverseListSpinner);

    JSpinner dateSpinner = new JSpinner(new SpinnerDateModel());
    addRow("Date", dateSpinner);

    JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel());
    String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern();
    betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern));
    addRow("Better Date", betterDateSpinner);

    JSpinner timeSpinner = new JSpinner(new SpinnerDateModel());
    pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern();
    timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern));
    addRow("Time", timeSpinner);

    JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat"));
    addRow("Word permutations", permSpinner);
}

From source file:Commander.Main.java

/**
 * Creates new form Main//from w w  w  .  j  av a  2 s .  co  m
 */
public Main(java.awt.Frame parent, boolean modal) {
    super(parent, modal);

    //Set tranparant
    Color transparant = new Color(0, 0, 0, 0);
    setUndecorated(true);
    getRootPane().setOpaque(false);
    getContentPane().setBackground(transparant);
    setBackground(transparant);

    initComponents();

    //Set components transparant
    transparant = new Color(0, 0, 0, 1);
    txtCommand.setBackground(transparant);
    txtCommand.setForeground(Color.GREEN);
    txtCommand.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0, 150)));
    jScrollPane1.getViewport().setBackground(transparant);
    jScrollPane1.getViewport().setOpaque(false);
    txtError.setBackground(transparant);
    txtError.setForeground(Color.RED);
    txtError.setEditable(false);
    txtError.setFocusable(false);
    jScrollPane1.setVisible(false);
    setAlwaysOnTop(true);

    pack();
    Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    int width = getPreferredSize().width;
    int height = getPreferredSize().height;
    setLocation(screen.width - width - 20, screen.height - height - 20);

    txtCommand.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            if (jScrollPane1.isVisible()) {
                jScrollPane1.setVisible(false);
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            if (jScrollPane1.isVisible()) {
                jScrollPane1.setVisible(false);
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            //Not supported
        }

    });

    String home = System.getProperty("user.home");
    defaultLocations[0] = home + "/Documents";
    defaultLocations[1] = home + "/Pictures";
    defaultLocations[2] = home + "/Downloads";
    defaultLocations[3] = home + "/Music";

    //        run("Casino.jar", new ArrayList<>());
}

From source file:com.o2d.pkayjava.editor.Main.java

private void startLoadingEditor() {
    //first, kill off the splash
    if (!(SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_UNIX)) {
        splash.kill();/*from   w w  w .  java 2  s  .  c om*/
    }

    Overlap2D overlap2D = new Overlap2D();
    Rectangle maximumWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    double width = maximumWindowBounds.getWidth();
    double height = maximumWindowBounds.getHeight();

    if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_MAC) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Overlap2D");
        JglfwApplicationConfiguration config = new JglfwApplicationConfiguration();
        config.width = (int) (width);
        config.height = (int) (height - height * .04);
        config.backgroundFPS = 0;
        config.title = "Overlap2D - Public Alpha v" + AppConfig.getInstance().version;
        new JglfwApplication(overlap2D, config);
    } else {
        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        config.title = "Overlap2D - Public Alpha v" + AppConfig.getInstance().version;
        config.fullscreen = true;
        config.resizable = false;
        config.width = (int) (width);
        config.height = (int) (height - height * .04);
        config.backgroundFPS = 0;
        mainFrame = new LwjglFrame(overlap2D, config);
        mainFrame.setExtendedState(mainFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
        toggleVisible();

        // subscribe to file dropping notifications, currently windows only
        DropTarget dropTarget = new DropTarget(mainFrame, new FileDropListener());
    }

    if (!SystemUtils.IS_OS_UNIX) {
        // no aesthetics for linux users I guess..
        setIcon();
    }

}

From source file:cool.pandora.modeller.BaggerLifecycleAdvisor.java

/**
 * Additional window configuration before it is created.
 *///from  w  w  w  . j av  a2  s. c  o m
@Override
public void onPreWindowOpen(final ApplicationWindowConfigurer configurer) {
    super.onPreWindowOpen(configurer);
    // comment out to hide the menubar, or reduce window size...
    // configurer.setShowMenuBar(false);
    final Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    configurer.setInitialSize(new Dimension(rect.width, rect.height));
    //configurer.setInitialSize(new Dimension(1024, 768));
}

From source file:FontDemoLabel.java

public FontDemoLabel() {
    super("Font Demo - Label");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = getContentPane();

    // get font name list
    fl = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    // IGNORE the setLayout and North/South stuff...
    // we will discuss it in a few pages!

    cp.setLayout(new BorderLayout());
    cp.add(BorderLayout.NORTH, new Label("Number of Fonts = " + fl.length, Label.CENTER));
    cp.add(BorderLayout.CENTER, p = new JPanel());
    p.setLayout(new GridLayout(5, 0, 5, 5));

    for (int i = 0; i < fl.length; i++) {
        JLabel lab;/*from   ww  w  . j a  v a 2 s .  c o m*/

        // The crux of the matter: for each font name,
        // create a label using the name as the text,
        // AND set the font to be the named font!
        p.add(lab = new JLabel(fl[i]));
        lab.setFont(new Font(fl[i], Font.ITALIC | Font.BOLD, 14));
    }
    pack();
}

From source file:org.apache.pdfbox.pdmodel.font.FontManager.java

/**
 * Load all available fonts from the environment.
 *//*w ww. j a  v  a  2s .c om*/
private static void loadFonts() {
    for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) {
        String family = normalizeFontname(font.getFamily());
        String psname = normalizeFontname(font.getPSName());
        if (isBoldItalic(font)) {
            envFonts.put(family + "bolditalic", font);
        } else if (isBold(font)) {
            envFonts.put(family + "bold", font);
        } else if (isItalic(font)) {
            envFonts.put(family + "italic", font);
        } else {
            envFonts.put(family, font);
        }
        if (!family.equals(psname)) {
            envFonts.put(normalizeFontname(font.getPSName()), font);
        }
    }
}

From source file:com.ables.pix.utility.PictureOps.java

public static GraphicsConfiguration getDefaultConfiguration() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    return gd.getDefaultConfiguration();

}

From source file:FontChooser.java

private FontChooser(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();/*  w  ww .  ja  va 2s .c om*/
    setListValues(jFontList, GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
    setListValues(jStyleList, styleList);
    setListValues(jSizeList, sizeList);
    setCurrentFont(jSample.getFont());
    pack();
}