1 package org.jedit.syntax; 2 3 11 12 import java.awt.*; 13 import java.util.StringTokenizer ; 14 15 21 public class SyntaxStyle 22 { 23 29 public SyntaxStyle(Color color, boolean italic, boolean bold) 30 { 31 this.color = color; 32 this.italic = italic; 33 this.bold = bold; 34 } 35 36 39 public Color getColor() 40 { 41 return color; 42 } 43 44 47 public boolean isPlain() 48 { 49 return !(bold || italic); 50 } 51 52 55 public boolean isItalic() 56 { 57 return italic; 58 } 59 60 63 public boolean isBold() 64 { 65 return bold; 66 } 67 68 72 public Font getStyledFont(Font font) 73 { 74 if(font == null) 75 throw new NullPointerException ("font param must not" 76 + " be null"); 77 if(font.equals(lastFont)) 78 return lastStyledFont; 79 lastFont = font; 80 lastStyledFont = new Font(font.getFamily(), 81 (bold ? Font.BOLD : 0) 82 | (italic ? Font.ITALIC : 0), 83 font.getSize()); 84 return lastStyledFont; 85 } 86 87 90 public FontMetrics getFontMetrics(Font font) 91 { 92 if(font == null) 93 throw new NullPointerException ("font param must not" 94 + " be null"); 95 if(font.equals(lastFont) && fontMetrics != null) 96 return fontMetrics; 97 lastFont = font; 98 lastStyledFont = new Font(font.getFamily(), 99 (bold ? Font.BOLD : 0) 100 | (italic ? Font.ITALIC : 0), 101 font.getSize()); 102 fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics( 103 lastStyledFont); 104 return fontMetrics; 105 } 106 107 113 public void setGraphicsFlags(Graphics gfx, Font font) 114 { 115 Font _font = getStyledFont(font); 116 gfx.setFont(_font); 117 gfx.setColor(color); 118 } 119 120 123 public String toString() 124 { 125 return getClass().getName() + "[color=" + color + 126 (italic ? ",italic" : "") + 127 (bold ? ",bold" : "") + "]"; 128 } 129 130 private Color color; 132 private boolean italic; 133 private boolean bold; 134 private Font lastFont; 135 private Font lastStyledFont; 136 private FontMetrics fontMetrics; 137 } 138 | Popular Tags |