Skip to content

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffroy committed Aug 9, 2011
1 parent a58aa1f commit e18854a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
40 changes: 40 additions & 0 deletions src/opaide/editors/opasrc/OpaCodeScanner.java
Expand Up @@ -10,6 +10,8 @@

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 OpaCodeScanner extends RuleBasedScanner {
Expand All @@ -24,6 +26,14 @@ public IWordDetector getWordDetector() {
public ITextualRep[] getTextualReps() {
return OPAKEYWORDS.values();
}
@Override
public FontData getDefaultFontData() {
return createFontData(SWT.BOLD);
}
@Override
public RGB getDefaultRGB() {
return new RGB(0, 255, 255);
}
},
SEPARATOR {
@Override
Expand All @@ -34,6 +44,14 @@ public IWordDetector getWordDetector() {
public ITextualRep[] getTextualReps() {
return OPASEPARATORS.values();
}
@Override
public FontData getDefaultFontData() {
return createFontData(SWT.BOLD);
}
@Override
public RGB getDefaultRGB() {
return new RGB(124, 62, 71);
}
},
GENERIC_WORD {
@Override
Expand All @@ -53,6 +71,14 @@ public boolean isWordPart(char c) {
public ITextualRep[] getTextualReps() {
return new ITextualRep[]{};
}
@Override
public FontData getDefaultFontData() {
return createFontData(SWT.NORMAL);
}
@Override
public RGB getDefaultRGB() {
return new RGB(20, 20, 20);
}
};

@Override
Expand All @@ -63,6 +89,20 @@ public String toString() {
public abstract IWordDetector getWordDetector();
public abstract ITextualRep[] getTextualReps();

public FontData getDefaultFontData() {
return createFontData(SWT.NORMAL);
}

private static FontData createFontData(int style) {
FontData fd = new FontData();
fd.setStyle(style);
return fd;
}

public RGB getDefaultRGB() {
return new RGB(20, 20, 20);
}

}


Expand Down
13 changes: 2 additions & 11 deletions src/opaide/preferences/OpaPreferencesInitializer.java
Expand Up @@ -83,18 +83,9 @@ public void initializeDefaultPreferences() {
}

for (CODE c : CODE.values()) {
switch (c) {
case KEYWORD:
storeSavedTextAttribute(c.toString(), new SavedTextAttribute(new RGB(0, 255, 255), SWT.BOLD));
break;
case SEPARATOR:
storeSavedTextAttribute(c.toString(), new SavedTextAttribute(new RGB(124, 62, 71), SWT.BOLD));
break;
case GENERIC_WORD:
storeSavedTextAttribute(c.toString(), new SavedTextAttribute(new RGB(20, 20, 20), SWT.NORMAL));
break;
}
storeSavedTextAttribute(c.toString(), new SavedTextAttribute(c.getDefaultRGB(), c.getDefaultFontData().getStyle()));
}

}

public SavedTextAttribute getSavedTextAttribute(OPA_PARTITION p) {
Expand Down

0 comments on commit e18854a

Please sign in to comment.