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:misc.GradientTranslucentWindowDemo.java

public static void main(String[] args) {
    // Determine what the GraphicsDevice can support.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    boolean isPerPixelTranslucencySupported = gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);

    //If translucent windows aren't supported, exit.
    if (!isPerPixelTranslucencySupported) {
        System.out.println("Per-pixel translucency is not supported");
        System.exit(0);/*from w  w w .j av  a  2  s. c o m*/
    }

    JFrame.setDefaultLookAndFeelDecorated(true);

    // Create the GUI on the event-dispatching thread
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            GradientTranslucentWindowDemo gtw = new GradientTranslucentWindowDemo();

            // Display the window.
            gtw.setVisible(true);
        }
    });
}

From source file:QueryProperties.java

public static void main(String[] args) {
    VirtualUniverse vu = new VirtualUniverse();
    Map vuMap = vu.getProperties();

    System.out.println("version = " + vuMap.get("j3d.version"));
    System.out.println("vendor = " + vuMap.get("j3d.vendor"));
    System.out.println("specification.version = " + vuMap.get("j3d.specification.version"));
    System.out.println("specification.vendor = " + vuMap.get("j3d.specification.vendor"));
    System.out.println("renderer = " + vuMap.get("j3d.renderer") + "\n");

    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();

    /*//from www. j  av a  2s  .  c  o m
     * We need to set this to force choosing a pixel format that support the
     * canvas.
     */
    template.setStereo(template.PREFERRED);
    template.setSceneAntialiasing(template.PREFERRED);

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

    Map c3dMap = new Canvas3D(config).queryProperties();

    System.out.println("Renderer version = " + c3dMap.get("native.version"));
    System.out.println("doubleBufferAvailable = " + c3dMap.get("doubleBufferAvailable"));
    System.out.println("stereoAvailable = " + c3dMap.get("stereoAvailable"));
    System.out.println("sceneAntialiasingAvailable = " + c3dMap.get("sceneAntialiasingAvailable"));
    System.out.println("sceneAntialiasingNumPasses = " + c3dMap.get("sceneAntialiasingNumPasses"));
    System.out.println("textureColorTableSize = " + c3dMap.get("textureColorTableSize"));
    System.out.println("textureEnvCombineAvailable = " + c3dMap.get("textureEnvCombineAvailable"));
    System.out.println("textureCombineDot3Available = " + c3dMap.get("textureCombineDot3Available"));
    System.out.println("textureCombineSubtractAvailable = " + c3dMap.get("textureCombineSubtractAvailable"));
    System.out.println("texture3DAvailable = " + c3dMap.get("texture3DAvailable"));
    System.out.println("textureCubeMapAvailable = " + c3dMap.get("textureCubeMapAvailable"));
    System.out.println("textureSharpenAvailable = " + c3dMap.get("textureSharpenAvailable"));
    System.out.println("textureDetailAvailable = " + c3dMap.get("textureDetailAvailable"));
    System.out.println("textureFilter4Available = " + c3dMap.get("textureFilter4Available"));
    System.out
            .println("textureAnisotropicFilterDegreeMax = " + c3dMap.get("textureAnisotropicFilterDegreeMax"));
    System.out.println("textureBoundaryWidthMax = " + c3dMap.get("textureBoundaryWidthMax"));
    System.out.println("textureWidthMax = " + c3dMap.get("textureWidthMax"));
    System.out.println("textureHeightMax = " + c3dMap.get("textureHeightMax"));
    System.out.println("textureLodOffsetAvailable = " + c3dMap.get("textureLodOffsetAvailable"));
    System.out.println("textureLodRangeAvailable = " + c3dMap.get("textureLodRangeAvailable"));
    System.out.println("textureUnitStateMax = " + c3dMap.get("textureUnitStateMax"));
    System.out.println(
            "compressedGeometry.majorVersionNumber = " + c3dMap.get("compressedGeometry.majorVersionNumber"));
    System.out.println(
            "compressedGeometry.minorVersionNumber = " + c3dMap.get("compressedGeometry.minorVersionNumber"));
    System.out.println("compressedGeometry.minorMinorVersionNumber = "
            + c3dMap.get("compressedGeometry.minorMinorVersionNumber"));

    System.exit(0);
}

From source file:org.lobzik.home_sapiens.pi.BoxRegistrator.java

/**
 * @param args the command line arguments
 *//*w  w w .j  a v a 2  s .co  m*/
public static void main(String[] args) {
    // TODO code application logic here
    try {
        /*
        if (BoxCommonData.BOX_ID > 0) {
        System.err.println("Box registered already, " + BoxCommonData.BOX_ID_FILE + " exists. Exiting.");
        return;
        }
                
        JSONObject boxJson = new JSONObject();
        boxJson.put("ssid", BoxCommonData.SSID);
        boxJson.put("public_key", new String(Files.readAllBytes(Paths.get(BoxCommonData.PUBLIC_KEY_FILE)), "UTF-8"));
        boxJson.put("version", BoxCommonData.BOX_VERSION);
        boxJson.put("wpa_psk", BoxCommonData.WPA_PSK);
                
        JSONObject reqJson = new JSONObject();
        reqJson.put("action", "register_request");
        reqJson.put("box_data", boxJson);
                
        URL url = new URL(BoxCommonData.REGISTER_SERVER_URL);
                
        URLConnection conn = url.openConnection();
        conn.setDoInput(true);
        conn.setDoOutput(true);
        OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
        out.write(reqJson.toString());
        out.close();
                
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String decodedString;
        StringBuffer sb = new StringBuffer();
        while ((decodedString = in.readLine()) != null) {
        sb.append(decodedString);
        }
        in.close();
        JSONObject response = new JSONObject(sb.toString());
        if (response.has("register_result") && response.getString("register_result").equals("success")) {
                
        int id = response.getInt("box_id");
        File boxIdFile = new File(BoxCommonData.BOX_ID_FILE);
        FileOutputStream fos = new FileOutputStream(boxIdFile);
        OutputStreamWriter idFileOs = new OutputStreamWriter(fos);
        idFileOs.write("box_id=" + id + "\n");
        idFileOs.flush();
        idFileOs.close();
        fos.flush();
        fos.close();
        System.out.println("Box registered successfully");
        System.out.println("Box ID: " + id);
        System.out.println("Box SSID: " + BoxCommonData.SSID);
        System.out.println("Box WPA_PSK: " + BoxCommonData.WPA_PSK); //print on a sticker
        System.out.println("Box RSA public key: " + BoxCommonData.PUBLIC_KEY);
        System.out.println("Box registration done");
        } else {
        System.err.println("Error while registering device ");
        System.err.println(sb.toString());
        }
        //boxIdFile.
         */

        GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] fonts = e.getAllFonts(); // Get the fonts
        for (Font f : fonts) {
            System.out.println(f.getFontName());
        }

    } catch (Throwable e) {
        System.err.println("Error while registering device ");
        e.printStackTrace();
    }
}

From source file:core.PlanC.java

/**
 * inicio de aplicacion/*from  ww  w  .  j a va2s.co m*/
 * 
 * @param arg - argumentos de entrada
 */
public static void main(String[] args) {

    // user.name

    /*
     * Properties prp = System.getProperties(); System.out.println(getWmicValue("bios", "SerialNumber"));
     * System.out.println(getWmicValue("cpu", "SystemName"));
     */

    try {
        // log
        // -Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
        // System.setProperty("java.util.logging.SimpleFormatter.format",
        // "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n");
        System.setProperty("java.util.logging.SimpleFormatter.format",
                "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %5$s%6$s%n");

        FileHandler fh = new FileHandler(LOG_FILE);
        fh.setFormatter(new SimpleFormatter());
        fh.setLevel(Level.INFO);
        ConsoleHandler ch = new ConsoleHandler();
        ch.setFormatter(new SimpleFormatter());
        ch.setLevel(Level.INFO);
        logger = Logger.getLogger("");
        Handler[] hs = logger.getHandlers();
        for (int x = 0; x < hs.length; x++) {
            logger.removeHandler(hs[x]);
        }
        logger.addHandler(fh);
        logger.addHandler(ch);
        // point apache log to this log
        System.setProperty("org.apache.commons.logging.Log", Jdk14Logger.class.getName());

        TPreferences.init();
        TStringUtils.init();

        Font fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Light.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Medium.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("AERO_ITALIC.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);

        SwingTimerTimingSource ts = new SwingTimerTimingSource();
        AnimatorBuilder.setDefaultTimingSource(ts);
        ts.init();

        // parse app argument parameters and append to tpreferences to futher uses
        for (String arg : args) {
            String[] kv = arg.split("=");
            TPreferences.setProperty(kv[0], kv[1]);
        }
        RUNNING_MODE = TPreferences.getProperty("runningMode", RM_NORMAL);

        newMsg = Applet.newAudioClip(TResourceUtils.getURL("newMsg.wav"));

    } catch (Exception e) {
        SystemLog.logException1(e, true);
    }

    // pass icon from metal to web look and feel
    Icon i1 = UIManager.getIcon("OptionPane.errorIcon");
    Icon i2 = UIManager.getIcon("OptionPane.informationIcon");
    Icon i3 = UIManager.getIcon("OptionPane.questionIcon");
    Icon i4 = UIManager.getIcon("OptionPane.warningIcon");
    // Object fcui = UIManager.get("FileChooserUI");
    // JFileChooser fc = new JFileChooser();

    WebLookAndFeel.install();
    // WebLookAndFeel.setDecorateFrames(true);
    // WebLookAndFeel.setDecorateDialogs(true);

    UIManager.put("OptionPane.errorIcon", i1);
    UIManager.put("OptionPane.informationIcon", i2);
    UIManager.put("OptionPane.questionIcon", i3);
    UIManager.put("OptionPane.warningIcon", i4);
    // UIManager.put("TFileChooserUI", fcui);

    // warm up the IDW.
    // in my computer, some weird error ocurr if i don't execute this preload.
    new RootWindow(null);

    frame = new TWebFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            Exit.shutdown();
        }
    });

    if (RUNNING_MODE.equals(RM_NORMAL)) {
        initEnviorement();
    }
    if (RUNNING_MODE.equals(RM_CONSOLE)) {
        initConsoleEnviorement();
    }

    if (RUNNING_MODE.equals(ONE_TASK)) {
        String cln = TPreferences.getProperty("taskName", "*TaskNotFound");
        PlanC.logger.log(Level.INFO, "OneTask parameter found in .properties. file Task name = " + cln);
        try {
            Class cls = Class.forName(cln);
            Object dobj = cls.newInstance();
            // new class must be extends form AbstractExternalTask
            TTaskManager.executeTask((Runnable) dobj);
            return;
        } catch (Exception e) {
            PlanC.logger.log(Level.SEVERE, e.getMessage(), e);
            Exit.shutdown();
        }
    }
}

From source file:MultiBufferTest.java

public static void main(String[] args) {
    try {/*from   w  ww  .j a va 2  s. c o m*/
        int numBuffers = 2;
        if (args != null && args.length > 0) {
            numBuffers = Integer.parseInt(args[0]);
            if (numBuffers < 2 || numBuffers > COLORS.length) {
                System.err.println("Must specify between 2 and " + COLORS.length + " buffers");
                System.exit(1);
            }
        }
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice device = env.getDefaultScreenDevice();
        MultiBufferTest test = new MultiBufferTest(numBuffers, device);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.exit(0);
}

From source file:Main.java

public static int getCenterX() {
    return (int) (GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth() / 2);
}

From source file:Main.java

public static void centerFrame(JFrame frame) {
    GraphicsDevice defaultScreen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    Rectangle screenSize = defaultScreen.getDefaultConfiguration().getBounds();

    int midx = screenSize.width / 2;
    int midy = screenSize.height / 2;

    int posx = midx - (frame.getWidth() / 2);
    int posy = midy - (frame.getHeight() / 2);

    frame.setLocation(posx, posy);//from  w ww  .jav  a  2s.  c  o  m
}

From source file:Main.java

public static Image getImage(Component c) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();

    // Create an image that supports transparent pixels
    BufferedImage bImage = gc.createCompatibleImage(c.getWidth(), c.getHeight(), Transparency.BITMASK);

    /*//from ww w  .  jav a  2  s.c o m
     * And now this is how we get an image of the component
     */
    Graphics2D g = bImage.createGraphics();

    // Then use the current component we're in and call paint on this
    // graphics object
    c.paint(g);
    return bImage;
}

From source file:Main.java

public static Dimension getScreenDimension() {
    int width = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode()
            .getWidth();//from   w  w  w.  j a  va  2 s . c o m
    int height = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode()
            .getHeight();

    Dimension d = new Dimension(width, height);
    return d;
}

From source file:de.unidue.inf.is.ezdl.gframedl.EzDL.java

/**
 * Main method of the desktop application.
 * //  w ww  . ja  v a2  s. c o  m
 * @param args
 *            an array of command-line arguments
 */
public static void main(String[] args) {
    GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice().getDefaultConfiguration();

    Application app = new DesktopApplication(graphicsConfiguration);
    EzDL.start(args, app, graphicsConfiguration);
}