List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment
public static GraphicsEnvironment getLocalGraphicsEnvironment()
From source file:SpinnerTest.java
public SpinnerFrame() { setTitle("SpinnerTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton);//from w ww. jav a2s . c om 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:Main.java
/** * Computes the center point of the current screen device. If this method is called on JDK 1.4, Xinerama-aware * results are returned. (See Sun-Bug-ID 4463949 for details). * * @return the center point of the current screen. *//*from www. j a v a 2 s . co m*/ public static Point getCenterPoint() { final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { final Method method = GraphicsEnvironment.class.getMethod("getCenterPoint", (Class[]) null); return (Point) method.invoke(localGraphicsEnvironment, (Object[]) null); } catch (Exception e) { // ignore ... will fail if this is not a JDK 1.4 .. } final Dimension s = Toolkit.getDefaultToolkit().getScreenSize(); return new Point(s.width / 2, s.height / 2); }
From source file:org.apache.fop.render.java2d.InstalledFontCollection.java
/** * {@inheritDoc}//w w w . j a va 2s .c o m */ public int setup(int start, FontInfo fontInfo) { int num = start; GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); java.awt.Font[] fonts = env.getAllFonts(); for (int i = 0; i < fonts.length; i++) { java.awt.Font f = fonts[i]; if (HARDCODED_FONT_NAMES.contains(f.getName())) { continue; //skip } if (log.isTraceEnabled()) { log.trace("AWT Font: " + f.getFontName() + ", family: " + f.getFamily() + ", PS: " + f.getPSName() + ", Name: " + f.getName() + ", Angle: " + f.getItalicAngle() + ", Style: " + f.getStyle()); } String searchName = FontUtil.stripWhiteSpace(f.getName()).toLowerCase(); String guessedStyle = FontUtil.guessStyle(searchName); int guessedWeight = FontUtil.guessWeight(searchName); num++; String fontKey = "F" + num; int style = convertToAWTFontStyle(guessedStyle, guessedWeight); addFontMetricsMapper(fontInfo, f.getName(), fontKey, java2DFontMetrics, style); //Register appropriate font triplets matching the font. Two different strategies: //Example: "Arial Bold", normal, normal addFontTriplet(fontInfo, f.getName(), Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, fontKey); if (!f.getName().equals(f.getFamily())) { //Example: "Arial", bold, normal addFontTriplet(fontInfo, f.getFamily(), guessedStyle, guessedWeight, fontKey); } } return num; }
From source file:eu.irreality.age.SwingAetheriaGameLoaderInterface.java
public static void loadFont() { //cargar configuracin del ini String fontName = "Courier New"; int fontSize = 12; try {/*w w w. j ava2 s . c o m*/ BufferedReader iniReader = new BufferedReader( Utility.getBestInputStreamReader(new FileInputStream("age.cfg"))); String linea; for (int line = 1; line < 100; line++) { linea = iniReader.readLine(); if (linea != null) { //System.out.println("Linea " + linea ); String codigo = StringMethods.getTok(linea, 1, '=').trim().toLowerCase(); if (codigo.equals("font name")) { //System.out.println("Nombre: " + StringMethods.getTok(linea,2,'=').trim() ); fontName = StringMethods.getTok(linea, 2, '=').trim(); } else if (codigo.equals("font size")) { fontSize = Integer.parseInt(StringMethods.getTok(linea, 2, '=').trim()); } } } } //las excepciones nos la sudan porque hay valores por defecto catch (FileNotFoundException fnfe) { ; } catch (NumberFormatException nfe) { ; } catch (IOException ioe) { ; } catch (SecurityException se) //applet mode { ; } Font[] fuentes = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); Font fuenteElegida; for (int f = 0; f < fuentes.length; f++) { if (fuentes[f].getFontName().equalsIgnoreCase(fontName)) { SwingAetheriaGameLoaderInterface.font = fuentes[f].deriveFont((float) fontSize); break; } //System.out.println("Fuente: " + fuentes[f]); } //System.err.println("He seleccionado mi fuente, y es: " + SwingAetheriaGameLoaderInterface.font ); //font not selected? be less picky if (SwingAetheriaGameLoaderInterface.font == null) { String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); Arrays.sort(fonts); if (Arrays.binarySearch(fonts, "Courier New") >= 0) { SwingAetheriaGameLoaderInterface.font = new Font("Courier New", Font.PLAIN, 12); } else if (Arrays.binarySearch(fonts, "Courier") >= 0) { SwingAetheriaGameLoaderInterface.font = new Font("Courier", Font.PLAIN, 12); } else if (Arrays.binarySearch(fonts, "Monospaced") >= 0) { SwingAetheriaGameLoaderInterface.font = new Font("Monospaced", Font.PLAIN, 13); } } //still not selected? well, in that case just default to font 0 if (SwingAetheriaGameLoaderInterface.font == null) SwingAetheriaGameLoaderInterface.font = fuentes[0].deriveFont((float) fontSize); }
From source file:musiccrawler.App.java
private void configPositionApp() { Dimension windowSize = getSize(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Point centerPoint = ge.getCenterPoint(); int dx = centerPoint.x - windowSize.width / 2; int dy = centerPoint.y - windowSize.height / 2; setLocation(dx, dy);/*from ww w.j a v a 2 s. c om*/ }
From source file:com.seleniumtests.driver.screenshots.VideoRecorder.java
/** * //from w w w . j ava 2 s . c om * @param folderPath * @param fileName * @param localRecording if true, we will capture something locally. Else grid mode is used */ public VideoRecorder(File folderPath, String fileName, boolean localRecording) { //Create a instance of ScreenRecorder with the required configurations if (localRecording) { //Create a instance of GraphicsConfiguration to get the Graphics configuration //of the Screen. This is needed for ScreenRecorder class. GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); try { screenRecorder = new ScreenRecorder(gc, null, new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI), new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, (int) 24, FrameRateKey, Rational.valueOf(25), QualityKey, 1.0f, KeyFrameIntervalKey, (int) (15 * 60)), null, null, folderPath); } catch (Exception e) { logger.error("Error while creating video recording", e); } } this.fileName = fileName; this.folderPath = folderPath; }
From source file:eu.novait.imagerenamer.model.ImageFile.java
private BufferedImage getCompatibleImage(int w, int h) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(w, h); return image; }
From source file:FontDemo.java
/** * Construct a FontDemo -- Sets title and gets array of fonts on the system *//*www . j a v a2s . com*/ public FontDemo() { Toolkit toolkit = Toolkit.getDefaultToolkit(); // For JDK 1.1: returns about 10 names (Serif, SansSerif, etc.) // fontNames = toolkit.getFontList(); // For JDK 1.2: a much longer list; most of the names that come // with your OS (e.g., Arial, Lucida, Lucida Bright, Lucida Sans...) fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); fonts = new Font[fontNames.length]; }
From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.layouts.internalframe.InternalFrameDemoFrame.java
/** * Computes the maximum bounds of the current screen device. If this method is called on JDK 1.4, Xinerama-aware * results are returned. (See Sun-Bug-ID 4463949 for details). * * @return the maximum bounds of the current screen. *//*from ww w . ja va2s . com*/ private static Rectangle getMaximumWindowBounds() { try { final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); return localGraphicsEnvironment.getMaximumWindowBounds(); } catch (Exception e) { // ignore ... will fail if this is not a JDK 1.4 .. } final Dimension s = Toolkit.getDefaultToolkit().getScreenSize(); return new Rectangle(0, 0, s.width, s.height); }
From source file:net.technicpack.ui.lang.ResourceLoader.java
public Font getFontByName(String fontName) { Font font;// w w w . j av a2 s . c o m if (fontCache.containsKey(fontName)) return fontCache.get(fontName); if (launcherAssets == null) return fallbackFont; InputStream fontStream = null; try { String fullName = getString(fontName); fontStream = FileUtils.openInputStream(new File(launcherAssets, fullName)); if (fontStream == null) return fallbackFont; font = Font.createFont(Font.TRUETYPE_FONT, fontStream); GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); genv.registerFont(font); } catch (Exception e) { e.printStackTrace(); // Fallback return fallbackFont; } finally { if (fontStream != null) IOUtils.closeQuietly(fontStream); } fontCache.put(fontName, font); if (font == null) return fallbackFont; return font; }