From: Benjamin R. <ran...@us...> - 2007-08-02 16:22:25
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26770/src/org/jrobin/graph Modified Files: RrdGraphDef.java Log Message: yay, it works! Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** RrdGraphDef.java 2 Aug 2007 05:21:11 -0000 1.27 --- RrdGraphDef.java 2 Aug 2007 16:22:20 -0000 1.28 *************** *** 30,35 **** --- 30,39 ---- import java.awt.*; + import java.io.File; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; + import java.net.MalformedURLException; + import java.net.URL; import java.util.ArrayList; import java.util.List; *************** *** 116,120 **** int firstDayOfWeek = FIRST_DAY_OF_WEEK; // ok boolean showSignature = true; ! List<Source> sources = new ArrayList<Source>(); List<CommentText> comments = new ArrayList<CommentText>(); --- 120,125 ---- int firstDayOfWeek = FIRST_DAY_OF_WEEK; // ok boolean showSignature = true; ! File fontDir = null; ! List<Source> sources = new ArrayList<Source>(); List<CommentText> comments = new ArrayList<CommentText>(); *************** *** 131,159 **** throw new RuntimeException(e); } ! smallFont = this.getSmallFont(); ! largeFont = this.getLargeFont(); } protected Font getFontFromResourceName(String name) { ! Font font; ! try { ! InputStream fontStream = this.getClass().getResourceAsStream(name); ! font = Font.createFont(Font.TRUETYPE_FONT, fontStream); ! fontStream.close(); ! } catch (Exception e) { ! System.err.println("An error occurred loading the font '" + name + "'. Falling back to the default."); ! // e.printStackTrace(); font = new Font(DEFAULT_FONT_NAME, Font.PLAIN, 10); } return font; } protected Font getSmallFont() { ! return this.getFontFromResourceName(RrdGraphConstants.DEFAULT_SMALL_FONT_FILE).deriveFont(Font.PLAIN).deriveFont(10); } protected Font getLargeFont() { ! return this.getFontFromResourceName(RrdGraphConstants.DEFAULT_LARGE_FONT_FILE).deriveFont(Font.BOLD).deriveFont(12); } --- 136,192 ---- throw new RuntimeException(e); } ! ! String fontdirProperty = System.getProperty("jrobin.fontdir"); ! if (fontdirProperty != null && fontdirProperty.length() != 0) { ! fontDir = new File(fontdirProperty); ! } ! ! smallFont = this.getFontFromResourceName(RrdGraphConstants.DEFAULT_SMALL_FONT_FILE).deriveFont(Font.PLAIN, 10); ! largeFont = this.getFontFromResourceName(RrdGraphConstants.DEFAULT_SMALL_FONT_FILE).deriveFont(Font.BOLD, 12); } protected Font getFontFromResourceName(String name) { ! Font font = null; ! Exception exception = null; ! URL file = null; ! if (fontDir != null) { ! try { ! file = new URL("file://" + new File(fontDir, name).getAbsolutePath()); ! } catch (MalformedURLException e) { ! // fall through to the jar ! exception = e; ! } ! } ! if (file == null) { ! file = this.getClass().getResource(name); ! } ! ! if (file != null) { ! try { ! InputStream fontStream = file.openStream(); ! font = Font.createFont(Font.TRUETYPE_FONT, fontStream); ! fontStream.close(); ! } catch (Exception e) { ! exception = e; ! } ! } else { ! // we can't find our fonts, fall back to the system font ! System.err.println("An error occurred loading the font '" + name + "'. Falling back to the default."); ! if (exception != null) { ! System.err.println(exception.getLocalizedMessage()); ! } font = new Font(DEFAULT_FONT_NAME, Font.PLAIN, 10); } + return font; } protected Font getSmallFont() { ! return this.smallFont; } protected Font getLargeFont() { ! return this.largeFont; } *************** *** 672,676 **** * font is selected. * ! * @param smallFont Default font for graphing. Use only monospaced fonths. */ public void setSmallFont(Font smallFont) { --- 705,709 ---- * font is selected. * ! * @param smallFont Default font for graphing. Use only monospaced fonts. */ public void setSmallFont(Font smallFont) { |