Example usage for java.awt GraphicsDevice getDisplayMode

List of usage examples for java.awt GraphicsDevice getDisplayMode

Introduction

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

Prototype

public DisplayMode getDisplayMode() 

Source Link

Document

Returns the current display mode of this GraphicsDevice .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();

    boolean canChg = gs.isDisplayChangeSupported();
    if (canChg) {
        DisplayMode displayMode = gs.getDisplayMode();
        int screenWidth = 640;
        int screenHeight = 480;
        int bitDepth = 8;
        displayMode = new DisplayMode(screenWidth, screenHeight, bitDepth, displayMode.getRefreshRate());
        try {/*  w w  w . ja  v  a2  s .  co  m*/
            gs.setDisplayMode(displayMode);
        } catch (Throwable e) {
            gs.setFullScreenWindow(null);
        }
    }
}

From source file:io.lonelyrobot.empires.client.core.MainClientLauncher.java

public static void main(String[] args) {
    LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
    cfg.title = Values.SUPERTITLE + " - " + Values.VERSION_NUMBER;

    final Options gameOptions = new Options();
    // gameOptions.addOption("fullscreen", false, "Launch as fullscreen");

    if (gameOptions.hasOption("fullscreen")) {
        System.out.println("Attempting to launch as fullscreen Application. This is experimental as of 1.3+");
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

        cfg.width = gd.getDisplayMode().getWidth();
        cfg.height = gd.getDisplayMode().getHeight();
        cfg.fullscreen = true;//from w ww .  j  a  v a 2s. c om

        Values.NEW_WIDTH = cfg.width;
        Values.NEW_HEIGHT = cfg.height;
    } else {
        cfg.fullscreen = false;
        cfg.width = Values.OLD_WIDTH;
        cfg.height = Values.OLD_HEIGHT;
    }

    cfg.useGL30 = true;
    cfg.resizable = false;
    cfg.initialBackgroundColor = Color.BLACK;

    new LwjglApplication(GameCore.getInstance(), cfg);
}

From source file:FullScreen.java

public static void main(String args[]) {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
    DisplayMode originalDisplayMode = graphicsDevice.getDisplayMode();

    try {/*from  ww w.j av a  2  s.c  o  m*/
        Frame frame = new Frame();
        frame.setUndecorated(true);
        frame.setIgnoreRepaint(true);
        graphicsDevice.setFullScreenWindow(frame);
        if (graphicsDevice.isDisplayChangeSupported()) {
            graphicsDevice.setDisplayMode(getBestDisplayMode(graphicsDevice));
        }
        frame.createBufferStrategy(2); // 2 buffers
        Rectangle bounds = frame.getBounds();
        BufferStrategy bufferStrategy = frame.getBufferStrategy();
        while (!done()) {
            Graphics g = null;
            try {
                g = bufferStrategy.getDrawGraphics();
                if ((counter <= 2)) { // 2 buffers
                    g.setColor(Color.CYAN);
                    g.fillRect(0, 0, bounds.width, bounds.height);
                }
                g.setColor(Color.RED);
                // redraw prior line, too, since 2 buffers
                if (counter != 1) {
                    g.drawLine(counter - 1, (counter - 1) * 5, bounds.width, bounds.height);
                }
                g.drawLine(counter, counter * 5, bounds.width, bounds.height);
                bufferStrategy.show();
            } finally {
                if (g != null) {
                    g.dispose();
                }
            }
            try {
                Thread.sleep(250);
            } catch (InterruptedException ignored) {
            }
        }
    } finally {
        graphicsDevice.setDisplayMode(originalDisplayMode);
        graphicsDevice.setFullScreenWindow(null);
    }
    System.exit(0);
}

From source file:Main.java

/**
 * Gets the screen resolution in an integer array.
 * /* w  ww  .  j  av a  2 s  . c  om*/
 * @return an int array containing two entries, the width and the height in
 *         pixels.
 */
public static int[] getScreenResolution() {
    final int[] result = new int[2];
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    result[0] = gd.getDisplayMode().getWidth();
    result[1] = gd.getDisplayMode().getHeight();
    return result;
}

From source file:Main.java

/**
 * Returns current screen size of the display. In case of multi-display system it returns the
 * screen size for default one.//w w  w. j  a  va2  s.c  om
 * @return
 */
public static Dimension getEffectiveScreenSize() {
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    int width = gd.getDisplayMode().getWidth();
    int height = gd.getDisplayMode().getHeight();
    return new Dimension(width, height);
}

From source file:wsattacker.sso.openid.attacker.evaluation.SeleniumBrowser.java

public static WebDriver getWebDriver() {

    if (INSTANCE == null || hasQuit(INSTANCE) || INSTANCE.getWindowHandles().isEmpty()) {
        // create chrome profile
        //ChromeOptions options = new ChromeOptions();
        //options.addExtensions(new File("adblock.crx"));

        FirefoxProfile profile = new FirefoxProfile();

        // install adblock plus
        File tmpFile = new File("adblock.xpi");
        try {/*  w w  w . j  a  v a2s.c o  m*/
            InputStream inputStream = SeleniumBrowser.class.getResourceAsStream("/adblock_firefox.xpi");
            FileUtils.copyInputStreamToFile(inputStream, tmpFile);
            profile.addExtension(tmpFile);
        } catch (IOException ex) {
            Logger.getLogger(EvaluationGui.class.getName()).log(Level.SEVERE, null, ex);
        }

        // disable local and session storage
        // some websites (e.g. stackoverflow) use those storages in addition
        // to session cookies
        profile.setPreference("dom.storage.enabled", false);

        // start new Firefox instance
        INSTANCE = new FirefoxDriver(profile);

        // screen size
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int width = gd.getDisplayMode().getWidth();
        int height = gd.getDisplayMode().getHeight();

        width = width > 1440 ? 1440 : width;
        height = height > 900 ? 900 : height;

        INSTANCE.manage().window().setPosition(new Point(0, 0));
        INSTANCE.manage().window().setSize(new Dimension(width, height));

        tmpFile.delete();
    }

    return INSTANCE;
}

From source file:DisplayModeModel.java

public DisplayModeTest(GraphicsDevice device) {
    super(device.getDefaultConfiguration());
    this.device = device;
    setTitle("Display Mode Test");
    originalDM = device.getDisplayMode();
    setDMLabel(originalDM);//from w w  w  . java2 s .c o  m
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    // Make sure a DM is always selected in the list
    exit.addActionListener(this);
    changeDM.addActionListener(this);
    changeDM.setEnabled(device.isDisplayChangeSupported());
}

From source file:GeMSE.Visualization.ElbowPlot.java

public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) {
    double maxY = 0;

    float[] secYColor = new float[3];
    Color.RGBtoHSB(153, 245, 255, secYColor);

    float[] priYColor = new float[3];
    Color.RGBtoHSB(255, 255, 255, priYColor);

    float[] cutColor = new float[3];
    Color.RGBtoHSB(255, 255, 0, cutColor);

    //create the series - add some dummy data
    XYSeries pvSeries = new XYSeries("Percentage of variance        ");
    for (int i = 1; i < pvData.size(); i++) {
        pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]);
        maxY = Math.max(maxY, pvData.get(i)[1]);
    }// w  w  w.  jav a 2s  .co m

    XYSeries dSeries = new XYSeries("Percentage of differences between slopes        ");
    for (int i = 0; i < dData.size(); i++)
        dSeries.add(dData.get(i)[0], dData.get(i)[1]);

    XYSeries cutSeries = new XYSeries("Cut        ");
    cutSeries.add(cut, 0.0);
    cutSeries.add(cut, maxY);

    //create the datasets
    XYSeriesCollection pvDataSeries = new XYSeriesCollection();
    pvDataSeries.addSeries(pvSeries);

    XYSeriesCollection cutDataSeries = new XYSeriesCollection();
    cutDataSeries.addSeries(cutSeries);

    XYSeriesCollection dDataSeries = new XYSeriesCollection();
    dDataSeries.addSeries(dSeries);

    //construct the plot
    XYPlot plot = new XYPlot();
    plot.setDataset(0, pvDataSeries);
    plot.setDataset(1, cutDataSeries);
    plot.setDataset(2, dDataSeries);

    // use XYSplineRenderer if you want to smooth the lines.
    XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer();
    pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));

    BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 1.0f, 10.0f }, 0.0f);
    XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer();
    dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    dRenderer.setSeriesStroke(0, dstroke);

    BasicStroke cutStoke = new BasicStroke(4);
    // use XYSplineRenderer if you want to smooth the lines.
    //XYSplineRenderer cutRenderer = new XYSplineRenderer();
    XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer();
    cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2]));
    cutRenderer.setSeriesStroke(0, cutStoke);

    plot.setRenderer(0, pvRenderer);
    plot.setRenderer(1, cutRenderer);
    plot.setRenderer(2, dRenderer);

    plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance"));
    plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes"));
    plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n"));

    //Map the data to the appropriate axis
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 0);
    plot.mapDatasetToRangeAxis(2, 1);

    float[] hsbValues = new float[3];
    Color.RGBtoHSB(16, 23, 67, hsbValues);
    plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2]));

    Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14);
    Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12);
    Font legendFont = new Font("Dialog", Font.PLAIN, 14);

    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(axisLabelFont);
    plot.getDomainAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelFont(axisLabelFont);
    plot.getRangeAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelFont(axisLabelFont);
    plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont);

    //generate the chart
    JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(),
            plot, true);

    chart.getTitle().setPaint(Color.white);
    chart.getLegend().setBackgroundPaint(Color.black);
    chart.getLegend().setItemPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    chart.getLegend().setItemFont(legendFont);

    float[] hsbValues2 = new float[3];
    Color.RGBtoHSB(36, 43, 87, hsbValues2);
    chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2]));
    JPanel chartPanel = new ChartPanel(chart);

    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    chartPanel.setPreferredSize(
            new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0),
                    (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0)));

    setContentPane(chartPanel);
}

From source file:com.grillecube.editor.ModelEditor.java

private JSONObject createDefaultJSON() {
    JSONObject json = new JSONObject();

    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    int width = gd.getDisplayMode().getWidth();

    width = width / 2;//from w  w w .  ja  v a  2 s  . co m
    json.put(ModelEditor.Config.MODEL_WINDOW_WIDTH, width);
    json.put(ModelEditor.Config.MODEL_WINDOW_HEIGHT, width / 1.6f);
    json.put(ModelEditor.Config.VSYNC, 1);
    json.put(ModelEditor.Config.SOUND, 1);

    return (json);
}

From source file:de.ifsr.adam.ImageGenerator.java

/**
 * Main method for generating an Preview out of a report with it results.
 *
 * @param resultReport The report with it results
 * @return returns true if the generation and saving of the image was successful, false
 * otherwise//from  www . j ava2s .  c o m
 */
public Scene generatePreview(JSONArray resultReport) {
    log.info("Preview generation has started");
    VBox vbox = generateImageVBox(resultReport);

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
    scrollPane.setContent(vbox);

    //Gets the screen resulution for scaling.
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    int width = gd.getDisplayMode().getWidth();
    int height = gd.getDisplayMode().getHeight();

    scrollPane.setVmax(100.0);
    scrollPane.setPrefSize(width * 0.65, height * 0.8); //TODO Can I do this better?

    ((Group) scene.getRoot()).getChildren().add(scrollPane);
    scene.getStylesheets().add(this.stylesheetURI.toString());

    //The Observer for resizing the scrollpane when the window changes.
    scene.widthProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth,
                Number newSceneWidth) {
            scrollPane.setPrefWidth(newSceneWidth.doubleValue());
        }
    });

    //The Observer for resizing the scrollpane when the window changes.
    scene.heightProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight,
                Number newSceneHeight) {
            scrollPane.setPrefHeight(newSceneHeight.doubleValue());
        }
    });

    log.info("End of Preview generation");
    return scene;
}