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:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java

/**
 * Add an image with a html code without change its dimension
 * /*from ww w .  ja v  a  2 s .co m*/
 * @param slideToSet slide to set
 * @param html html code
 * @param x horizontal position
 * @param y vertical position
 * @throws IOException if error
 * @throws PPTGeneratorException 
 */
protected void addHtmlPicture(Slide slideToSet, String html, int x, int y)
        throws IOException, PPTGeneratorException {
    try {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        if (!ge.isHeadlessInstance()) {
            LOGGER.warn("Runtime is not configured for supporting graphiv manipulation !");
        }
        JEditorPane editor = new JEditorPane();
        editor.setContentType("text/html");
        editor.setText(html);
        LOGGER.debug("Editor pane is built");
        editor.setSize(editor.getPreferredSize());
        editor.addNotify(); // Serveur X requis
        LOGGER.debug("Panel rendering is done");
        BufferedImage bufferSave = new BufferedImage(editor.getPreferredSize().width,
                editor.getPreferredSize().height, BufferedImage.TYPE_3BYTE_BGR);
        Graphics g = bufferSave.getGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, editor.getPreferredSize().width, editor.getPreferredSize().height);
        editor.paint(g);
        LOGGER.debug("graphics is drawn");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ImageIO.write(bufferSave, "png", out);
        LOGGER.debug("image is written");
        addPicture(slideToSet, out.toByteArray(),
                new Rectangle(x, y, editor.getPreferredSize().width, editor.getPreferredSize().height));
        LOGGER.debug("image is added");
    } catch (HeadlessException e) {
        LOGGER.error("X Server no initialized or -Djava.awt.headless=true not set !");
        throw new PPTGeneratorException("X Server no initialized or -Djava.awt.headless=true not set !");
    }
}

From source file:edu.ku.brc.specify.BackupAndRestoreApp.java

/**
 * Restarts the app with a new or old database and user name and creates the core app UI.
 * @param window the login window/*from www .  j a v a  2s  .  c  o  m*/
 * @param databaseNameArg the database name
 * @param userNameArg the user name
 * @param startOver tells the AppContext to start over
 * @param firstTime indicates this is the first time in the application and it should create all the UI for the core app
 */
public void restartApp(final Window window, final String databaseNameArg, final String userNameArg,
        final boolean startOver, final boolean firstTime) {
    log.debug("restartApp"); //$NON-NLS-1$
    if (dbLoginPanel != null) {
        dbLoginPanel.getStatusBar().setText(getResourceString("Specify.INITIALIZING_APP")); //$NON-NLS-1$
    }

    if (firstTime) {
        GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration();

        initialize(gc);

        topFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        UIRegistry.register(UIRegistry.FRAME, topFrame);

    }

    if (window != null) {
        window.setVisible(false);
    }

    showApp();

    statusField.setText(DBConnection.getInstance().getDatabaseName());

    if (dbLoginPanel != null) {
        dbLoginPanel.getWindow().setVisible(false);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void checkForInitialLoadScreenSizes(final FormControl control, final JSplitPane verticalMain,
        final String verticalMainName, final JSplitPane verticalSub, final String verticalSubName,
        final JSplitPane horizontalMain, final String horizontalMainName, final JSplitPane horizontalSub,
        final String horizontalSubName) {
    if ((control.getWidth() == -1) && (control.getHeight() == -1) && (control.getLeft() == -1)
            && (control.getTop() == -1)) {
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice[] gs = ge.getScreenDevices();
        if (gs.length > 0) {
            final DisplayMode dm = gs[0].getDisplayMode();
            final int screenWidth = dm.getWidth() - 20;
            final int screenHeight = dm.getHeight() - 50;
            // Set form bounds
            control.setTop(10);/* w  w  w . j a v a2  s.  c  o  m*/
            control.setLeft(10);
            control.setWidth(screenWidth);
            control.setHeight(screenHeight);
            control.resizeScreen();
            // Set divider positions
            int dividerPosition = 175;
            verticalMain.setDividerLocation(dividerPosition);
            control.setExtra(verticalMainName, dividerPosition);
            dividerPosition = screenHeight / 3;
            verticalSub.setDividerLocation(dividerPosition);
            control.setExtra(verticalSubName, dividerPosition);
            dividerPosition = screenWidth / 3;
            horizontalMain.setDividerLocation(dividerPosition);
            control.setExtra(horizontalMainName, dividerPosition);
            horizontalSub.setDividerLocation(dividerPosition);
            control.setExtra(horizontalSubName, dividerPosition);
        }
    }

}

From source file:net.sourceforge.dvb.projectx.common.Common.java

public static Object[] getFonts() {
    Object[] fonts = new Object[0];

    try {/*from ww w .ja  v  a  2  s.  c o  m*/
        fonts = (Object[]) GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    } catch (Exception exc) {
        System.out.println(Resource.getString("SubtitlePanel.Font.LoadError") + ": " + exc);

    } catch (Error err) {
        System.out.println(Resource.getString("SubtitlePanel.Font.LoadError") + ": " + err);
    }

    return fonts;
}

From source file:literarytermsquestionbank.RomeoAndJuliet.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    // Set custom  icon
    this.setIconImage(
            Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/Images/book-icon_rj.png")));

    // Set custom fonts
    try {//from  w w  w  . j a  va 2  s. c  o m
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        // Load Old English from resources
        Font englishFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/OLDENGL.TTF"));
        ge.registerFont(englishFontFace);
        actLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 30f));
        sceneLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f));
        lineNumberLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f));

        // Load Matura Script font from resources
        Font maturaFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/MATURASC.TTF"));
        ge.registerFont(maturaFontFace);
        tabbedPane.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        questionLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        checkButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        stuckLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        rescueButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        answerLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        youAreViewingLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        quoteIndexTextField.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f));
        totalNumberLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 36f));
        goButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f));
        randomButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        previousButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        nextButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        backButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));

        // Load Corsova font from resources
        Font corsovaFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/MTCORSVA.TTF"));
        ge.registerFont(corsovaFontFace);
        clueLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        passageLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        examplesLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        commentsLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 14f));

        // Load Imprint font from resources
        Font imprintFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/IMPRISHA.TTF"));
        ge.registerFont(imprintFontFace);
        quoteTopLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
        quoteBottomLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
    } catch (FontFormatException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONParser parser = new JSONParser();

    try {
        // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package.
        Object quoteObj = parser
                .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json")));

        // This casts the object to a JSONObject for future manipulation
        JSONObject jsonObject = (JSONObject) quoteObj;

        // This array holds all the quotes
        JSONArray quotesArray = (JSONArray) jsonObject.get("Romeo and Juliet");
        Iterator<JSONObject> iterator = quotesArray.iterator();

        // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList
        while (iterator.hasNext()) {
            Collections.addAll(quotesList, iterator.next());
            totalNumberOfQuotes++;
        }

        // Init randomizer
        Random rand = new Random();

        // Generate a random integer between 1 and size of the ArrayList
        quoteIndex = rand.nextInt(quotesList.size()) + 1;

        generateQuote(quoteIndex); // This calls a method to generate a quote and display it
    } catch (Exception e) { // This means something went very wrong when starting the program
        System.out.println("Uh oh, something bad happened. Possible database corruption.");
        JOptionPane.showMessageDialog(null,
                "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}

From source file:org.openstreetmap.josm.tools.ImageProvider.java

/**
 * Decorate one icon with an overlay icon.
 *
 * @param ground the base image// w ww.j  a va 2s  .com
 * @param overlay the overlay image (can be smaller than the base image)
 * @param pos position of the overlay image inside the base image (positioned
 * in one of the corners)
 * @return an icon that represent the overlay of the two given icons. The second icon is layed
 * on the first relative to the given position.
 */
public static ImageIcon overlay(Icon ground, Icon overlay, OverlayPosition pos) {
    GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration();
    int w = ground.getIconWidth();
    int h = ground.getIconHeight();
    int wo = overlay.getIconWidth();
    int ho = overlay.getIconHeight();
    BufferedImage img = conf.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    Graphics g = img.createGraphics();
    ground.paintIcon(null, g, 0, 0);
    int x = 0, y = 0;
    switch (pos) {
    case NORTHWEST:
        x = 0;
        y = 0;
        break;
    case NORTHEAST:
        x = w - wo;
        y = 0;
        break;
    case SOUTHWEST:
        x = 0;
        y = h - ho;
        break;
    case SOUTHEAST:
        x = w - wo;
        y = h - ho;
        break;
    }
    overlay.paintIcon(null, g, x, y);
    return new ImageIcon(img);
}

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:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Undock the UI component and display fullscreen.
 * //from w  w  w . j av a2  s .c  o  m
 * @since  1.1
 */
void maximizePanel() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        if (device.isFullScreenSupported() && device.getFullScreenWindow() == null) {
            maximized = true;
            dataPanelContainer.removeDataPanel(component);

            frame = new JFrame(getTitle());
            frame.setUndecorated(true);
            frame.getContentPane().add(component);

            try {
                device.setFullScreenWindow(frame);
            } catch (InternalError e) {
                log.error("Failed to switch to full screen mode: " + e.getMessage() + ".");
                restorePanel(true);
                return;
            }

            frame.setVisible(true);
            frame.requestFocus();

            return;
        }
    }

    log.warn("No screens available or full screen exclusive mode is unsupported on your platform.");
}

From source file:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Leave fullscreen mode and dock the UI component if addToContainer is true.
 * /*  w w w  .jav  a2  s  .c om*/
 * @param addToContainer  whether to dock the UI component
 * @since                 1.1
 */
void restorePanel(boolean addToContainer) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        if (device.isFullScreenSupported() && device.getFullScreenWindow() == frame) {
            if (frame != null) {
                frame.setVisible(false);
                device.setFullScreenWindow(null);
                frame.getContentPane().remove(component);
                frame.dispose();
                frame = null;
            }

            maximized = false;

            if (addToContainer) {
                dataPanelContainer.addDataPanel(component);
            }

            break;
        }
    }
}

From source file:literarytermsquestionbank.ShortStories.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    // Set window icon
    this.setIconImage(
            Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/Images/book-icon_ss.png")));

    // Set custom fonts
    try {/*  ww w . j av  a 2 s  . com*/
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        // Load Great Vibes from resources
        Font bradleyFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/BRADHITC.TTF"));
        ge.registerFont(bradleyFontFace);
        questionLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        checkButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 36f));
        stuckLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f));
        rescueButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        answerLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        youAreViewingLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        quoteIndexTextField.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        totalNumberLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 36f));
        goButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        randomButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        previousButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        nextButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        backButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f));
        clueTitleLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f));
        clueLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        passageLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        examplesLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        commentsLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        storyLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 20f));
        tabbedPane.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        menuTitleLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));

        // Load and set Imprint font face
        Font imprintFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/IMPRISHA.TTF"));
        ge.registerFont(imprintFontFace);
        quoteTopLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
        quoteBottomLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
    } catch (FontFormatException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONParser parser = new JSONParser();
    try {
        // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package.
        Object quoteObj = parser
                .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json")));

        // This casts the object to a JSONObject for future manipulation
        JSONObject jsonObject = (JSONObject) quoteObj;

        // This array holds all the quotes
        JSONArray quotesArray = (JSONArray) jsonObject.get("Short Stories");
        Iterator<JSONObject> iterator = quotesArray.iterator();

        // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList
        while (iterator.hasNext()) {
            Collections.addAll(quotesList, iterator.next());
            totalNumberOfQuotes++;
        }

        // Init randomizer
        Random rand = new Random();

        // Generate a random integer between 1 and size of the ArrayList
        quoteIndex = rand.nextInt(quotesList.size()) + 1;

        generateQuote(quoteIndex); // This calls a method to generate a quote and display it
    } catch (Exception e) { // This means something went very wrong when starting the program
        System.out.println("Uh oh, something bad happened. Possible database corruption.");
        JOptionPane.showMessageDialog(null,
                "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}