List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment
public static GraphicsEnvironment getLocalGraphicsEnvironment()
From source file:edu.ku.brc.specify.config.init.PrintTableHelper.java
/** * @param model//w ww . j a v a 2s .c om * @return * @throws Exception */ public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception { // Find a Sans Serif Font on the System String fontName = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (java.awt.Font font : ge.getAllFonts()) { String fName = font.getFamily().toLowerCase(); if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial") || StringUtils.contains(fName, "verdana")) { fontName = font.getFamily(); break; } } if (fontName == null) { fontName = Font._FONT_TIMES_NEW_ROMAN; } /** * Creates the DynamicReportBuilder and sets the basic options for the report */ FastReportBuilder drb = new FastReportBuilder(); Style columDetail = new Style(); //columDetail.setBorder(Border.THIN); Style columDetailWhite = new Style(); //columDetailWhite.setBorder(Border.THIN); columDetailWhite.setBackgroundColor(Color.WHITE); columDetailWhite.setFont(new Font(10, fontName, false)); columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER); columDetailWhite.setBlankWhenNull(true); Style columDetailWhiteBold = new Style(); //columDetailWhiteBold.setBorder(Border.THIN); columDetailWhiteBold.setBackgroundColor(Color.WHITE); Style titleStyle = new Style(); titleStyle.setFont(new Font(12, fontName, true)); // Odd Row Style Style oddRowStyle = new Style(); //oddRowStyle.setBorder(Border.NO_BORDER); oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER); Color veryLightGrey = new Color(240, 240, 240); oddRowStyle.setBackgroundColor(veryLightGrey); oddRowStyle.setTransparency(Transparency.OPAQUE); // Create Column Headers for the Report for (int i = 0; i < model.getColumnCount(); i++) { String colName = model.getColumnName(i); Class<?> dataClass = model.getColumnClass(i); if (dataClass == Object.class) { if (model.getRowCount() > 0) { Object data = model.getValueAt(0, i); if (data != null) { dataClass = data.getClass(); } else { // Column in first row was null so search down the rows // for a non-empty cell for (int j = 1; j < model.getRowCount(); j++) { data = model.getValueAt(j, i); if (dataClass != null) { dataClass = data.getClass(); break; } } if (dataClass == null) { dataClass = String.class; } } } } ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName()); int bracketInx = colName.indexOf('['); if (bracketInx > -1) { colName = colName.substring(0, bracketInx - 1); } colBldr.setTitle(colName); colBldr.setStyle(columDetailWhite); AbstractColumn column = colBldr.build(); drb.addColumn(column); Style headerStyle = new Style(); headerStyle.setFont(new Font(11, fontName, true)); //headerStyle.setBorder(Border.THIN); headerStyle.setHorizontalAlign(HorizontalAlign.CENTER); headerStyle.setVerticalAlign(VerticalAlign.MIDDLE); headerStyle.setBackgroundColor(new Color(80, 80, 80)); headerStyle.setTransparency(Transparency.OPAQUE); headerStyle.setTextColor(new Color(255, 255, 255)); column.setHeaderStyle(headerStyle); } drb.setTitle(pageSetupDlg.getPageTitle()); drb.setTitleStyle(titleStyle); drb.setLeftMargin(20); drb.setRightMargin(20); drb.setTopMargin(10); drb.setBottomMargin(10); drb.setPrintBackgroundOnOddRows(true); drb.setOddRowBackgroundStyle(oddRowStyle); drb.setColumnsPerPage(new Integer(1)); drb.setUseFullPageWidth(true); drb.setColumnSpace(new Integer(5)); // This next line causes an exception // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3 //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER); Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(), Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(), Page.Page_A4_Landscape() }; int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3); drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]); DynamicReport dr = drb.build(); return dr; }
From source file:ja.lingo.application.gui.main.settings.appearance.AppearanceGui.java
public AppearanceGui(Model model) { model.addApplicationModelListener(new ModelAdapter() { public void settingsUpdated(Preferences preferences) { setSelectedFontSize(preferences.getFontSize()); setSelectedFontFace(preferences.getFontFace()); dropZoneCheckBox.setSelected(preferences.isDropZoneVisible()); memoryBarCheckBox.setSelected(preferences.isMemoryBarVisible()); }//from w ww .j a v a 2 s . c om }); dropZoneCheckBox = new JCheckBox(resources.text("showDropZone")); fontSizeComboBox = new JComboBox(new Integer[] { 12, 13, DEFAULT_FONT_SIZE, 15, 16, 17 }); memoryBarCheckBox = new JCheckBox(resources.text("showMemoryBar")); JPanel fontSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Gaps.GAP5, 0)); fontSizePanel.add(resources.label("fontSize")); fontSizePanel.add(fontSizeComboBox); fontSizePanel.add(resources.label("requiresRestart")); gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED }, { TableLayout.PREFERRED, // 0: font face Gaps.GAP5, TableLayout.PREFERRED, // 2: font size Gaps.GAP5, TableLayout.PREFERRED, // 4: drop-zone Gaps.GAP5, TableLayout.PREFERRED, // 6: memory bar } })); JPanel fontFacePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Gaps.GAP5, 0)); fontFacePanel.add(resources.label("fontFace")); GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontFaceComboBox = new JComboBox(gEnv.getAvailableFontFamilyNames()); fontFaceComboBox.setMaximumRowCount(10); fontFacePanel.add(fontFaceComboBox); fontFacePanel.add(resources.label("requiresRestart")); gui.add(fontFacePanel, "0, 0"); gui.add(fontSizePanel, "0, 2"); gui.add(dropZoneCheckBox, "0, 4"); gui.add(memoryBarCheckBox, "0, 6"); Gaps.applyBorder5(gui); ActionBinder.bind(this); }
From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java
/** * Creates new form ResultsWindows//w ww .java 2s.co m */ public ResultsWindows() { super(); System.setProperty("apple.awt.application.name", "ResultWindow"); //get a reference to the device. GraphicsDevice[] ScreenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); this.device = ScreenDevices[ScreenDevices.length - 1]; //save the old display mode before changing it. dispModeOld = device.getDisplayMode(); initComponents(); try { Class util = Class.forName("com.apple.eawt.FullScreenUtilities"); Class params[] = new Class[] { Window.class, Boolean.TYPE }; Method method = util.getMethod("setWindowCanFullScreen", params); method.invoke(util, this, true); } catch (Exception e) { //System.out.println("OS X Fullscreen FAIL" + e.toString()); jCheckBoxMenuItem1.setEnabled(true); } if (!jCheckBoxMenuItem1.isEnabled()) { jMenuBar1.remove(jCheckBoxMenuItem1); } initCustumComponents(); initClock(); setSerieResults(); startChromeCast(); }
From source file:org.yccheok.jstock.gui.news.StockNewsJFrame.java
public StockNewsJFrame(java.awt.Frame parent, StockInfo stockInfo, String title) { super(title); this.parent = parent; this.parent.addWindowListener(this); this.setIconImage(parent.getIconImage()); this.stockInfo = stockInfo; final Country country = org.yccheok.jstock.engine.Utils.toCountry(this.stockInfo.code); this.newsServers = NewsServerFactory.getNewsServers(country); fullSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); sceneWidth = fullSize.width / 2;/*from w w w . j a v a 2 s . c o m*/ sceneHeight = fullSize.height; this.setSize((int) sceneWidth, (int) sceneHeight); initComponents(); }
From source file:NwFontChooserS.java
private void addLists() { FontList = new NwList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); StyleList = new NwList(styleList); SizeList = new NwList(sizeList); FontList.setBounds(10, 10, 260, 295); StyleList.setBounds(280, 10, 80, 295); SizeList.setBounds(370, 10, 40, 295); getContentPane().add(FontList);//from w w w .java 2s. c o m getContentPane().add(StyleList); getContentPane().add(SizeList); }
From source file:io.github.moosbusch.lumpi.util.LumpiUtil.java
public static BufferedImage createCompatibleImage(int width, int height) { GraphicsEnvironment gd = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration conf = gd.getDefaultScreenDevice().getDefaultConfiguration(); return conf.createCompatibleImage(width, height); }
From source file:J3dSwingFrame.java
/** * Construct the test frame with a menubar and 3D canvas *//*from w w w . j av a 2 s . c o m*/ public J3dSwingFrame() { super("Java3D Tester"); // Disable lightweight menus JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menubar = new JMenuBar(); // File menu JMenu file_menu = new JMenu("File"); menubar.add(file_menu); close_menu = new JMenuItem("Exit"); close_menu.addActionListener(this); file_menu.add(close_menu); setJMenuBar(menubar); GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getBestConfiguration(template); canvas = new Canvas3D(config); // add the canvas to this frame. Since this is the only thing added to // the main frame we don't care about layout managers etc. getContentPane().add(canvas, "Center"); constructWorld(); setSize(600, 600); }
From source file:MixedTest.java
protected Canvas3D createCanvas3D() { // overidden this method to create a custom // Canvas3D that will implement the Immediate Mode rendering GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D(); gc3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED); GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); ImmediateCanvas3D c3d = new ImmediateCanvas3D(gd[0].getBestConfiguration(gc3D)); c3d.setSize(getCanvas3dWidth(c3d), getCanvas3dHeight(c3d)); return (Canvas3D) c3d; }
From source file:util.ui.UiUtilities.java
/** * Centers a window to its parent frame and shows it. * <p>/*w w w . j a v a 2 s . c o m*/ * If the window has no parent frame it will be centered to the screen. * * @param win * The window to center and show. */ public static void centerAndShow(Window win) { Dimension wD = win.getSize(); Dimension frameD; Point framePos; Frame frame = JOptionPane.getFrameForComponent(win); // Should this window be centered to its parent frame? boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing(); // Center to parent frame or to screen if (centerToParentFrame) { frameD = frame.getSize(); framePos = frame.getLocation(); } else { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // dual head, use first screen if (ge.getScreenDevices().length > 1) { try { GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration config = gd.getConfigurations()[0]; frameD = config.getBounds().getSize(); framePos = config.getBounds().getLocation(); } catch (RuntimeException e) { frameD = Toolkit.getDefaultToolkit().getScreenSize(); framePos = new Point(0, 0); } } // single screen only else { frameD = Toolkit.getDefaultToolkit().getScreenSize(); framePos = new Point(0, 0); } } Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2, framePos.y + (frameD.height - wD.height) / 2); wPos.x = Math.max(0, wPos.x); // Make x > 0 wPos.y = Math.max(0, wPos.y); // Make y > 0 win.setLocation(wPos); win.setVisible(true); }
From source file:components.ListDialogRunner.java
/** * Finds a cursive font to use, or falls back to using * an italic serif font./*from w w w . j av a2 s. c o m*/ */ protected static Font getAFont() { //initial strings of desired fonts String[] desiredFonts = { "French Script", "FrenchScript", "Script" }; String[] existingFamilyNames = null; //installed fonts String fontName = null; //font we'll use //Search for all installed font families. The first //call may take a while on some systems with hundreds of //installed fonts, so if possible execute it in idle time, //and certainly not in a place that delays painting of //the UI (for example, when bringing up a menu). // //In systems with malformed fonts, this code might cause //serious problems; use the latest JRE in this case. (You'll //see the same problems if you use Swing's HTML support or //anything else that searches for all fonts.) If this call //causes problems for you under the latest JRE, please let //us know. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (ge != null) { existingFamilyNames = ge.getAvailableFontFamilyNames(); } //See if there's one we like. if ((existingFamilyNames != null) && (desiredFonts != null)) { int i = 0; while ((fontName == null) && (i < desiredFonts.length)) { //Look for a font whose name starts with desiredFonts[i]. int j = 0; while ((fontName == null) && (j < existingFamilyNames.length)) { if (existingFamilyNames[j].startsWith(desiredFonts[i])) { //We've found a match. Test whether it can display //the Latin character 'A'. (You might test for //a different character if you're using a different //language.) Font f = new Font(existingFamilyNames[j], Font.PLAIN, 1); if (f.canDisplay('A')) { fontName = existingFamilyNames[j]; System.out.println("Using font: " + fontName); } } j++; //Look at next existing font name. } i++; //Look for next desired font. } } //Return a valid Font. if (fontName != null) { return new Font(fontName, Font.PLAIN, 36); } else { return new Font("Serif", Font.ITALIC, 36); } }