Permalink
Browse files

continue refactoring on partition

  • Loading branch information...
1 parent 8c128d0 commit 2ac499b5904f195030110638f33accffb9fd2ef4 geoffroy committed Aug 9, 2011
@@ -100,9 +100,8 @@ public FontData getDefaultFontData() {
}
private static FontData createFontData(int style) {
- FontData fd = new FontData();
- fd.setStyle(style);
- return fd;
+ FontData tmp = new FontData("Monospace", 10, style);
+ return tmp;
}
public RGB getDefaultRGB() {
@@ -4,8 +4,13 @@
import java.util.List;
import opaide.preferences.OpaPreferencesInitializer;
+import opaide.preferences.OpaPreferencesInitializer.SavedTextAttribute;
+import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
public class OpaPartitioner extends RuleBasedPartitionScanner {
public enum OPA_PARTITION {
@@ -20,6 +25,11 @@ public IPredicateRule getPredicateRule() {
public ITokenScanner getTokenScanner(OpaPreferencesInitializer styleProvider) {
return new OpaStringScanner(styleProvider);
}
+
+ @Override
+ public SavedTextAttribute getTextAttribute() {
+ return new SavedTextAttribute(new RGB(64, 144, 225), createDefaultFontData(SWT.ITALIC));
+ }
},
OPA_COMMENT_LINE {
@Override
@@ -32,6 +42,11 @@ public IPredicateRule getPredicateRule() {
public ITokenScanner getTokenScanner(OpaPreferencesInitializer styleProvider) {
return new OpaCommentLineScanner(styleProvider);
}
+
+ @Override
+ public SavedTextAttribute getTextAttribute() {
+ return new SavedTextAttribute(new RGB(171, 74, 0), createDefaultFontData(TextAttribute.STRIKETHROUGH));
+ }
},
OPA_COMMENT_BLOCK {
@Override
@@ -44,6 +59,11 @@ public IPredicateRule getPredicateRule() {
public ITokenScanner getTokenScanner(OpaPreferencesInitializer styleProvider) {
return new OpaCommentBlockScanner(styleProvider);
}
+
+ @Override
+ public SavedTextAttribute getTextAttribute() {
+ return new SavedTextAttribute(new RGB(111, 48, 0), createDefaultFontData(SWT.NORMAL));
+ }
};
@Override
@@ -68,6 +88,11 @@ public String getContentType() {
public abstract IPredicateRule getPredicateRule();
public abstract ITokenScanner getTokenScanner(OpaPreferencesInitializer styleProvider);
+ public abstract SavedTextAttribute getTextAttribute();
+
+ private static FontData createDefaultFontData(int style) {
+ return new FontData("Monospace", 10, style);
+ }
};
@@ -21,17 +21,12 @@
public class OpaPreferencesInitializer extends AbstractPreferenceInitializer {
public static class SavedTextAttribute {
- private int style;
private RGB color;
private FontData fontData;
- public SavedTextAttribute(RGB color, int style, FontData fontData) {
- this.style = style;
+ public SavedTextAttribute(RGB color, FontData fontData) {
this.color = color;
this.fontData = fontData;
}
- public int getStyle() {
- return style;
- }
public RGB getColor() {
return color;
}
@@ -55,17 +50,11 @@ private void setDefaultTextAttribute(String parent, RGB color, FontData font) {
PreferenceConverter.setDefault(store, parent+suffix_font_data, font);
}
- private void storeSavedTextAttribute(String parent, SavedTextAttribute sta) {
- FontData tmp = new FontData("Monospace", 10, sta.getStyle());
-
- setDefaultTextAttribute(parent, sta.getColor(), tmp);
- };
-
private SavedTextAttribute readSavedTextAttribute(String parent) {
RGB c = PreferenceConverter.getColor(store, parent+suffix_color);
FontData fd = PreferenceConverter.getFontData(store, parent+suffix_font_data);
/*System.out.println("PreferencesInitializer.readSavedTextAttribute()" + " reading style=" + fd.getStyle() + " for " + parent);*/
- return new SavedTextAttribute(c, fd.getStyle(), fd);
+ return new SavedTextAttribute(c, fd);
}
private static IPreferenceStore store;
@@ -86,17 +75,7 @@ public void initializeDefaultPreferences() {
store.setDefault(OpaPreferencesConstants.P_OPA_COMPILER_PATH, "/usr/bin/opa");
for (OPA_PARTITION p : OPA_PARTITION.values()) {
- switch (p) {
- case OPA_STRING:
- storeSavedTextAttribute(p.toString(), new SavedTextAttribute(new RGB(64, 144, 225), SWT.ITALIC, new FontData()));
- break;
- case OPA_COMMENT_LINE:
- storeSavedTextAttribute(p.toString(), new SavedTextAttribute(new RGB(171, 74, 0), TextAttribute.STRIKETHROUGH, new FontData()));
- break;
- case OPA_COMMENT_BLOCK:
- storeSavedTextAttribute(p.toString(), new SavedTextAttribute(new RGB(111, 48, 0), SWT.NORMAL, new FontData()));
- break;
- }
+ setDefaultTextAttribute(p.toString(), p.getTextAttribute().getColor(), p.getTextAttribute().getFontData());
}
for (CODE c : CODE.values()) {

0 comments on commit 2ac499b

Please sign in to comment.