diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index e34bb4a87..0b25324a1 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2743,8 +2743,9 @@ public class Editor extends JFrame implements RunnerListener { String[] parse = SyntaxUtilities.parseCommentUrls(line); if (parse==null) return false; - int pos = parse[0].length()+parse[1].length(); - if (offsetpos+2) + int start = parse[0].length(); + int stop = start + parse[1].length(); + if (offsetstop+2) return false; clickedURL = parse[1]; return true; diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 4dd15c041..315620033 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -772,8 +772,9 @@ public class Preferences { s = st.nextToken(); boolean bold = (s.indexOf("bold") != -1); boolean italic = (s.indexOf("italic") != -1); + boolean underlined = (s.indexOf("underlined") != -1); //System.out.println(what + " = " + str + " " + bold + " " + italic); - return new SyntaxStyle(color, italic, bold); + return new SyntaxStyle(color, italic, bold, underlined); } } diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java index 8b68f4f45..373b56835 100644 --- a/app/src/processing/app/Theme.java +++ b/app/src/processing/app/Theme.java @@ -196,7 +196,8 @@ public class Theme { s = st.nextToken(); boolean bold = (s.indexOf("bold") != -1); boolean italic = (s.indexOf("italic") != -1); + boolean underlined = (s.indexOf("underlined") != -1); - return new SyntaxStyle(color, italic, bold); + return new SyntaxStyle(color, italic, bold, underlined); } } \ No newline at end of file diff --git a/app/src/processing/app/syntax/SyntaxStyle.java b/app/src/processing/app/syntax/SyntaxStyle.java index 56323c3cc..ac3dd797d 100644 --- a/app/src/processing/app/syntax/SyntaxStyle.java +++ b/app/src/processing/app/syntax/SyntaxStyle.java @@ -10,6 +10,10 @@ package processing.app.syntax; import java.awt.*; +import java.awt.font.TextAttribute; +import java.util.Hashtable; +import java.util.Map; + import javax.swing.JComponent; @@ -27,11 +31,12 @@ public class SyntaxStyle * @param italic True if the text should be italics * @param bold True if the text should be bold */ - public SyntaxStyle(Color color, boolean italic, boolean bold) + public SyntaxStyle(Color color, boolean italic, boolean bold, boolean underlined) { this.color = color; this.italic = italic; this.bold = bold; + this.underlined = underlined; } /** @@ -47,7 +52,7 @@ public class SyntaxStyle */ public boolean isPlain() { - return !(bold || italic); + return !(bold || italic || underlined); } /** @@ -67,7 +72,14 @@ public class SyntaxStyle } /** - * Returns the specified font, but with the style's bold and + * @return true if underline is enabled for this style. + */ + public boolean isUnderlined() { + return underlined; + } + + /** + * Returns the specified font, but with the style's bold, underline and * italic flags applied. */ public Font getStyledFont(Font font) @@ -78,10 +90,16 @@ public class SyntaxStyle if(font.equals(lastFont)) return lastStyledFont; lastFont = font; + lastStyledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize()); + if (underlined) { + Map attr = new Hashtable(); + attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + lastStyledFont = lastStyledFont.deriveFont(attr); + } return lastStyledFont; } @@ -100,6 +118,11 @@ public class SyntaxStyle (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize()); + if (underlined) { + Map attr = new Hashtable(); + attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + lastStyledFont = lastStyledFont.deriveFont(attr); + } //fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(lastStyledFont); fontMetrics = comp.getFontMetrics(lastStyledFont); return fontMetrics; @@ -125,13 +148,16 @@ public class SyntaxStyle { return getClass().getName() + "[color=" + color + (italic ? ",italic" : "") + - (bold ? ",bold" : "") + "]"; + (bold ? ",bold" : "") + + (underlined ? ",underlined" : "") + + "]"; } // private members private Color color; private boolean italic; private boolean bold; + private boolean underlined; private Font lastFont; private Font lastStyledFont; private FontMetrics fontMetrics; diff --git a/app/src/processing/app/syntax/SyntaxUtilities.java b/app/src/processing/app/syntax/SyntaxUtilities.java index 54443c805..d4df8da90 100644 --- a/app/src/processing/app/syntax/SyntaxUtilities.java +++ b/app/src/processing/app/syntax/SyntaxUtilities.java @@ -95,17 +95,17 @@ public class SyntaxUtilities { SyntaxStyle[] styles = new SyntaxStyle[Token.ID_COUNT]; - styles[Token.COMMENT1] = new SyntaxStyle(Color.black,true,false); - styles[Token.COMMENT2] = new SyntaxStyle(new Color(0x990033),true,false); - styles[Token.KEYWORD1] = new SyntaxStyle(Color.black,false,true); - styles[Token.KEYWORD2] = new SyntaxStyle(Color.magenta,false,false); - styles[Token.KEYWORD3] = new SyntaxStyle(new Color(0x009600),false,false); - styles[Token.LITERAL1] = new SyntaxStyle(new Color(0x650099),false,false); - styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),false,true); - styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),false,true); - styles[Token.OPERATOR] = new SyntaxStyle(Color.black,false,true); - styles[Token.URL] = new SyntaxStyle(Color.blue,true,false); - styles[Token.INVALID] = new SyntaxStyle(Color.red,false,true); + styles[Token.COMMENT1] = new SyntaxStyle(Color.black,true,false,false); + styles[Token.COMMENT2] = new SyntaxStyle(new Color(0x990033),true,false,false); + styles[Token.KEYWORD1] = new SyntaxStyle(Color.black,false,true,false); + styles[Token.KEYWORD2] = new SyntaxStyle(Color.magenta,false,false,false); + styles[Token.KEYWORD3] = new SyntaxStyle(new Color(0x009600),false,false,false); + styles[Token.LITERAL1] = new SyntaxStyle(new Color(0x650099),false,false,false); + styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),false,true,false); + styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),false,true,false); + styles[Token.OPERATOR] = new SyntaxStyle(Color.black,false,true,false); + styles[Token.URL] = new SyntaxStyle(Color.blue,true,false,false); + styles[Token.INVALID] = new SyntaxStyle(Color.red,false,true,false); return styles; } diff --git a/build/shared/lib/theme/theme.txt b/build/shared/lib/theme/theme.txt index c488d20ab..d8f5b7aa4 100644 --- a/build/shared/lib/theme/theme.txt +++ b/build/shared/lib/theme/theme.txt @@ -84,7 +84,7 @@ editor.literal1.style = #006699,plain editor.literal2.style = #006699,plain # http://arduino.cc/ -editor.url.style = #0000ff,italic +editor.url.style = #0000ff,underlined # e.g. + - = / editor.operator.style = #000000,plain