1 30 31 package org.syntax.jedit; 32 33 import java.awt.*; 34 import java.util.StringTokenizer ; 35 36 42 public class SyntaxStyle 43 { 44 50 public SyntaxStyle(Color color, boolean italic, boolean bold) 51 { 52 this.color = color; 53 this.italic = italic; 54 this.bold = bold; 55 } 56 57 60 public Color getColor() 61 { 62 return color; 63 } 64 65 68 public boolean isPlain() 69 { 70 return !(bold || italic); 71 } 72 73 76 public boolean isItalic() 77 { 78 return italic; 79 } 80 81 84 public boolean isBold() 85 { 86 return bold; 87 } 88 89 93 public Font getStyledFont(Font font) 94 { 95 if(font == null) 96 throw new NullPointerException ("font param must not" 97 + " be null"); 98 if(font.equals(lastFont)) 99 return lastStyledFont; 100 lastFont = font; 101 lastStyledFont = new Font(font.getFamily(), 102 (bold ? Font.BOLD : 0) 103 | (italic ? Font.ITALIC : 0), 104 font.getSize()); 105 return lastStyledFont; 106 } 107 108 111 public FontMetrics getFontMetrics(Font font) 112 { 113 if(font == null) 114 throw new NullPointerException ("font param must not" 115 + " be null"); 116 if(font.equals(lastFont) && fontMetrics != null) 117 return fontMetrics; 118 lastFont = font; 119 lastStyledFont = new Font(font.getFamily(), 120 (bold ? Font.BOLD : 0) 121 | (italic ? Font.ITALIC : 0), 122 font.getSize()); 123 fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics( 124 lastStyledFont); 125 return fontMetrics; 126 } 127 128 134 public void setGraphicsFlags(Graphics gfx, Font font) 135 { 136 Font _font = getStyledFont(font); 137 gfx.setFont(_font); 138 gfx.setColor(color); 139 } 140 141 144 public String toString() 145 { 146 return getClass().getName() + "[color=" + color + 147 (italic ? ",italic" : "") + 148 (bold ? ",bold" : "") + "]"; 149 } 150 151 private Color color; 153 private boolean italic; 154 private boolean bold; 155 private Font lastFont; 156 private Font lastStyledFont; 157 private FontMetrics fontMetrics; 158 } 159 | Popular Tags |