From: Stefan F. <ste...@us...> - 2010-06-22 18:10:22
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv16308/rails/ui/swing Modified Files: GameUIManager.java Log Message: Added selection of font type and scaling (see feature request 2982270) Still requires some changes to adapt window sizes etc. Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** GameUIManager.java 9 Apr 2010 07:20:27 -0000 1.46 --- GameUIManager.java 22 Jun 2010 18:10:14 -0000 1.47 *************** *** 1,4 **** --- 1,5 ---- package rails.ui.swing; + import java.awt.Font; import java.io.File; import java.text.SimpleDateFormat; *************** *** 6,9 **** --- 7,11 ---- import javax.swing.*; + import javax.swing.plaf.FontUIResource; import org.apache.log4j.Logger; *************** *** 107,113 **** --- 109,144 ---- configuredStockChartVisibility = "yes".equalsIgnoreCase(Config.get("stockchart.window.open")); + // font settings + String fontType = Config.get("font.global.name"); + Font font = null; + if (Util.hasValue(fontType)) { + boolean boldStyle = true; + String fontStyle = Config.get("font.global.style"); + if (Util.hasValue(fontStyle)) { + if (fontStyle.equalsIgnoreCase("plain")) { + boldStyle = false; + } + } + if (boldStyle) { + font = new Font(fontType, Font.BOLD, 12); + } else { + font = new Font(fontType, Font.PLAIN, 12); + } + if (font != null) log.debug("Change text fonts globally to " + font.getName() + " / " + (boldStyle ? "Bold" : "Plain")); + } + + String fontScale = Config.get("font.global.scale"); + if (Util.hasValue(fontScale)) { + try { + changeGlobalFont(font, Double.parseDouble(fontScale)); + log.debug("Change text fonts to relative scale " + fontScale); + } catch (NumberFormatException e) { + // do nothing + } + } } public void gameUIInit() { + imageLoader = new ImageLoader(); stockChart = new StockChart(this); *************** *** 115,119 **** orWindow = new ORWindow(this); orUIManager = orWindow.getORUIManager(); ! String statusWindowClassName = getClassName(GuiDef.ClassName.STATUS_WINDOW); try { --- 146,150 ---- orWindow = new ORWindow(this); orUIManager = orWindow.getORUIManager(); ! String statusWindowClassName = getClassName(GuiDef.ClassName.STATUS_WINDOW); try { *************** *** 603,606 **** --- 634,664 ---- } + /** + * Change global font size + * @param scale + */ + public void changeGlobalFont(Font replaceFont, double scale) { + UIDefaults defaults = UIManager.getDefaults(); + Enumeration<Object> keys = defaults.keys(); + while(keys.hasMoreElements()) { + Object key = keys.nextElement(); + Object value = defaults.get(key); + if(value != null && value instanceof Font) { + UIManager.put(key, null); + Font font; + if (replaceFont != null) { + font = replaceFont; + } else { + font = UIManager.getFont(key); + } + if(font != null) { + float newSize = font.getSize2D() * (float)scale; + UIManager.put(key, new FontUIResource(font.deriveFont(newSize))); + } + } + } + } + + public void exportGame(GameAction exportAction) { JFileChooser jfc = new JFileChooser(); |