List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment
public static GraphicsEnvironment getLocalGraphicsEnvironment()
From source file:literarytermsquestionbank.AChristmasCarol.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_acc.png"))); // Set custom fonts try {//w w w. ja v a 2 s . c om GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // Load Gill Sans from resources Font gillSansFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/GILLSANS.TTF")); ge.registerFont(gillSansFontFace); tabbedPane.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); questionLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); checkButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); youAreViewingLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); quoteIndexTextField.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 24f)); totalNumberLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 36f)); goButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f)); randomButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f)); backButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); clueLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); passageLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); exampleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); commentsLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); realAnswerLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f)); realAnswerTitleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f)); // Load the FreeStyle Script font from resources Font freeStyleFontFace = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Resources/Fonts/FREESCPT.TTF")); ge.registerFont(freeStyleFontFace); salutationLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f)); signatureLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f)); } 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("A Christmas Carol"); 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.yccheok.jstock.gui.Utils.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }// w w w . j a v a 2s.com // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels; for this method's // implementation, see e661 Determining If an Image Has Transparent Pixels boolean hasAlpha = hasAlpha(image); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { // Determine the type of transparency of the new buffered image int transparency = Transparency.OPAQUE; if (hasAlpha) { transparency = Transparency.BITMASK; } // Create the buffered image 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; if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; } 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:self.philbrown.javaQuery.$.java
/** * Interprets the CSS-style String and sets the value * @param view the view that will change. * @param key the name of the attribute//from w w w. j a v a2s.c om * @param _value the end animation value * @return the computed value */ private Object getAnimationValue(Component view, String key, String _value) { Object value = null; String[] split = (_value).split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)"); if (split.length == 1) { if (split[0].contains(".")) { value = Float.valueOf(split[0]); } else { value = Integer.valueOf(split[0]); } } else { if (split.length > 2) { Log.w("javaQuery", "parsererror for key " + key); return null; } if (split[1].equalsIgnoreCase("px")) { //this is the default. Just determine if float or int if (split[0].contains(".")) { value = Float.valueOf(split[0]); } else { value = Integer.valueOf(split[0]); } } else if (split[1].equalsIgnoreCase("dip") || split[1].equalsIgnoreCase("dp") || split[1].equalsIgnoreCase("sp")) { Log.w("$", "Dimension not supported"); if (split[0].contains(".")) { value = Float.valueOf(split[0]); } else { value = Integer.valueOf(split[0]); } } else if (split[1].equalsIgnoreCase("in")) { float pt = view(0).getGraphics().getFontMetrics().getFont().deriveFont(1).getSize2D() / 72; if (split[0].contains(".")) { value = Float.parseFloat(split[0]) * pt; } else { value = Integer.parseInt(split[0]) * pt; } } else if (split[1].equalsIgnoreCase("mm")) { float pt = view(0).getGraphics().getFontMetrics().getFont().deriveFont(1).getSize2D() / 72; if (split[0].contains(".")) { value = Float.parseFloat(split[0]) * pt / 25.4; } else { value = Integer.parseInt(split[0]) * pt / 25.4; } } else if (split[1].equalsIgnoreCase("pt")) { if (split[0].contains(".")) { value = view(0).getGraphics().getFontMetrics().getFont().deriveFont(Float.parseFloat(split[0])) .getSize2D(); } else { value = view(0).getGraphics().getFontMetrics().getFont().deriveFont(Integer.parseInt(split[0])) .getSize2D(); } } else if (split[1].equals("%")) { Rectangle windowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); Component parent = view.getParent(); float pixels = 0; if (parent == null) { pixels = windowBounds.width; //use best guess for width or height dpi if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top") || split[0].equalsIgnoreCase("bottom")) { pixels = windowBounds.height; } } else { pixels = parent.getWidth(); if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top") || split[0].equalsIgnoreCase("bottom")) { pixels = parent.getHeight(); } } float percent = 0; if (pixels != 0) percent = Float.valueOf(split[0]) / 100 * pixels; if (split[0].contains(".")) { value = percent; } else { value = (int) percent; } } else { Log.w("javaQuery", "invalid units for Object with key " + key); return null; } } return value; }
From source file:processing.app.Base.java
protected int[] defaultEditorLocation() { int defaultWidth = PreferencesData.getInteger("editor.window.width.default"); int defaultHeight = PreferencesData.getInteger("editor.window.height.default"); Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); return new int[] { (screen.width - defaultWidth) / 2, (screen.height - defaultHeight) / 2, defaultWidth, defaultHeight, 0 };//from ww w . java 2 s. c om }
From source file:forseti.JUtil.java
public static synchronized Image generarImagenMensaje(String mensaje, String nombreFuente, int tamanioFuente) { Frame f = new Frame(); f.addNotify();//from ww w.j av a 2 s .co m GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); env.getAvailableFontFamilyNames(); Font fuente = new Font(nombreFuente, Font.PLAIN, tamanioFuente); FontMetrics medidas = f.getFontMetrics(fuente); int anchoMensaje = medidas.stringWidth(mensaje); int lineaBaseX = anchoMensaje / 10; int ancho = anchoMensaje + 2 * (lineaBaseX + tamanioFuente); int alto = tamanioFuente * 7 / 2; int lineaBaseY = alto * 8 / 10; Image imagenMensaje = f.createImage(ancho, alto); Graphics2D g2d = (Graphics2D) imagenMensaje.getGraphics(); g2d.setFont(fuente); g2d.translate(lineaBaseX, lineaBaseY); g2d.setPaint(Color.lightGray); AffineTransform origTransform = g2d.getTransform(); g2d.shear(-0.95, 0); g2d.scale(1, 3); g2d.drawString(mensaje, 0, 0); g2d.setTransform(origTransform); g2d.setPaint(Color.black); g2d.drawString(mensaje, 0, 0); return (imagenMensaje); }
From source file:org.argouml.application.Main.java
/** * Do a part of the initialization that is very much GUI-stuff. * * @param splash the splash screeen//from ww w. j a v a2 s .c o m */ private static ProjectBrowser initializeGUI(SplashScreen splash) { // make the projectbrowser JPanel todoPane = new ToDoPane(); ProjectBrowser pb = ProjectBrowser.makeInstance(splash, true, todoPane); JOptionPane.setRootFrame(pb); pb.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Set the screen layout to what the user left it before, or // to reasonable defaults. Rectangle scrSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); int configFrameWidth = Configuration.getInteger(Argo.KEY_SCREEN_WIDTH, scrSize.width); int w = Math.min(configFrameWidth, scrSize.width); if (w == 0) { w = 600; } int configFrameHeight = Configuration.getInteger(Argo.KEY_SCREEN_HEIGHT, scrSize.height); int h = Math.min(configFrameHeight, scrSize.height); if (h == 0) { h = 400; } int x = Configuration.getInteger(Argo.KEY_SCREEN_LEFT_X, 0); int y = Configuration.getInteger(Argo.KEY_SCREEN_TOP_Y, 0); pb.setLocation(x, y); pb.setSize(w, h); pb.setExtendedState( Configuration.getBoolean(Argo.KEY_SCREEN_MAXIMIZED, false) ? Frame.MAXIMIZED_BOTH : Frame.NORMAL); UIManager.put("Button.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "ENTER", "pressed", "released ENTER", "released", "SPACE", "pressed", "released SPACE", "released" })); return pb; }
From source file:dylemator.DylematorUI.java
public void setFullscreen(boolean fullscreen) { //get a reference to the device. GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); DisplayMode dispMode = device.getDisplayMode(); //save the old display mode before changing it. dispModeOld = device.getDisplayMode(); if (this.fullscreen != fullscreen) { //are we actually changing modes. //change modes. this.fullscreen = fullscreen; // toggle fullscreen mode if (!fullscreen) { //change to windowed mode. //set the display mode back to the what it was when //the program was launched. device.setDisplayMode(dispModeOld); //hide the frame so we can change it. setVisible(false);/* w w w .j a va 2 s . c o m*/ //remove the frame from being displayable. dispose(); //put the borders back on the frame. setUndecorated(false); //needed to unset this window as the fullscreen window. device.setFullScreenWindow(null); //recenter window setLocationRelativeTo(null); setResizable(true); //reset the display mode to what it was before //we changed it. setVisible(true); } else { //change to fullscreen. //hide everything setVisible(false); //remove the frame from being displayable. dispose(); //remove borders around the frame setUndecorated(true); //make the window fullscreen. device.setFullScreenWindow(this); //attempt to change the screen resolution. device.setDisplayMode(dispMode); setResizable(false); setAlwaysOnTop(false); //show the frame setVisible(true); } //make sure that the screen is refreshed. repaint(); } this.requestFocus(); }
From source file:net.sf.jabref.gui.JabRefFrame.java
private void init() { tabbedPane = new DragDropPopupPane(tabPopupMenu()); MyGlassPane glassPane = new MyGlassPane(); setGlassPane(glassPane);/*from w w w . jav a 2s.c o m*/ setTitle(FRAME_TITLE); setIconImage(new ImageIcon(IconTheme.getIconUrl("jabrefIcon48")).getImage()); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (OS.OS_X) { JabRefFrame.this.setVisible(false); } else { new CloseAction().actionPerformed(null); } } }); initSidePane(); initLayout(); initActions(); // Show the toolbar if it was visible at last shutdown: tlb.setVisible(Globals.prefs.getBoolean(JabRefPreferences.TOOLBAR_VISIBLE)); setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); pw = new PositionWindow(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, JabRefPreferences.SIZE_Y); positionWindowOnScreen(); tabbedPane.setBorder(null); tabbedPane.setForeground(GUIGlobals.INACTIVE_TABBED_COLOR); /* * The following state listener makes sure focus is registered with the * correct database when the user switches tabs. Without this, * cut/paste/copy operations would some times occur in the wrong tab. */ tabbedPane.addChangeListener(e -> { markActiveBasePanel(); BasePanel bp = getCurrentBasePanel(); if (bp == null) { return; } groupToggle.setSelected(sidePaneManager.isComponentVisible("groups")); previewToggle.setSelected(Globals.prefs.getBoolean(JabRefPreferences.PREVIEW_ENABLED)); fetcherToggle.setSelected(sidePaneManager.isComponentVisible(generalFetcher.getTitle())); Globals.getFocusListener().setFocused(bp.getMainTable()); setWindowTitle(); editModeAction.initName(); // Update search autocompleter with information for the correct database: bp.updateSearchManager(); // Set correct enabled state for Back and Forward actions: bp.setBackAndForwardEnabledState(); new FocusRequester(bp.getMainTable()); }); //Note: The registration of Apple event is at the end of initialization, because //if the events happen too early (ie when the window is not initialized yet), the //opened (double-clicked) documents are not displayed. if (OS.OS_X) { try { new MacAdapter().registerMacEvents(this); } catch (Exception e) { LOGGER.fatal("Could not interface with Mac OS X methods.", e); } } }
From source file:org.colombbus.tangara.EditorFrame.java
/** * This method initializes the design of the frame. * *//* ww w . java2 s .co m*/ private void initialize() { GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = graphicsEnvironment.getMaximumWindowBounds(); setPreferredSize(bounds.getSize()); this.setJMenuBar(getBanner()); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Sets the main menu (the one separated by jsplitPane1) this.setContentPane(getBasePanel()); this.setTitle(Messages.getString("EditorFrame.application.title")); //$NON-NLS-1$ addWindowListener(this.windowListener); try { // Associates the icon (frame.icon = icon_tangara.png) to Tangara URL url = EditorFrame.class.getResource(ICON_PATH); MediaTracker attenteChargement = new MediaTracker(this); Image image = Toolkit.getDefaultToolkit().getImage(url); attenteChargement.addImage(image, 0); attenteChargement.waitForAll(); setIconImage(image); } catch (InterruptedException e) { LOG.warn("Error while loading icon"); //$NON-NLS-1$ } // fileChooser allows to easily choose a file // when you open (FILE->OPEN...) you have the choice between .txt or // .tgr fileChooser = new JFileChooser(Program.instance().getCurrentDirectory()); // for TangaraFile ".tgr" fileChooser.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) return true; return FileUtils.isTangaraFile(f); } @Override public String getDescription() { return Messages.getString("EditorFrame.file.programFilesDescription"); //$NON-NLS-1$ } }); fileChooserWithoutFilter = new JFileChooser(Program.instance().getCurrentDirectory()); pack(); setVisible(true); setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); }
From source file:org.rdv.ui.MainPanel.java
private boolean enterFullScreenMode() { 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) { log.info("Switching to full screen mode."); frame.setVisible(false);//from w w w. java 2 s. c o m try { device.setFullScreenWindow(frame); } catch (InternalError e) { log.error("Failed to switch to full screen exclusive mode."); e.printStackTrace(); frame.setVisible(true); return false; } frame.dispose(); frame.setUndecorated(true); frame.setVisible(true); frame.requestFocusInWindow(); return true; } } log.warn("No screens available or full screen exclusive mode is unsupported on your platform."); postError("Full screen mode is not supported on your platform."); return false; }