Skip to content

Commit f233861

Browse files
committed
URL right-clickable and underlined.
1 parent d60c42e commit f233861

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

app/src/processing/app/Editor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,8 +2743,9 @@ private boolean clickedURL(String line, int offset) {
27432743
String[] parse = SyntaxUtilities.parseCommentUrls(line);
27442744
if (parse==null)
27452745
return false;
2746-
int pos = parse[0].length()+parse[1].length();
2747-
if (offset<pos || offset>pos+2)
2746+
int start = parse[0].length();
2747+
int stop = start + parse[1].length();
2748+
if (offset<start|| offset>stop+2)
27482749
return false;
27492750
clickedURL = parse[1];
27502751
return true;

app/src/processing/app/Preferences.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,9 @@ static public SyntaxStyle getStyle(String what /*, String dflt*/) {
772772
s = st.nextToken();
773773
boolean bold = (s.indexOf("bold") != -1);
774774
boolean italic = (s.indexOf("italic") != -1);
775+
boolean underlined = (s.indexOf("underlined") != -1);
775776
//System.out.println(what + " = " + str + " " + bold + " " + italic);
776777

777-
return new SyntaxStyle(color, italic, bold);
778+
return new SyntaxStyle(color, italic, bold, underlined);
778779
}
779780
}

app/src/processing/app/Theme.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ static public SyntaxStyle getStyle(String what) {
196196
s = st.nextToken();
197197
boolean bold = (s.indexOf("bold") != -1);
198198
boolean italic = (s.indexOf("italic") != -1);
199+
boolean underlined = (s.indexOf("underlined") != -1);
199200

200-
return new SyntaxStyle(color, italic, bold);
201+
return new SyntaxStyle(color, italic, bold, underlined);
201202
}
202203
}

app/src/processing/app/syntax/SyntaxStyle.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
package processing.app.syntax;
1111

1212
import java.awt.*;
13+
import java.awt.font.TextAttribute;
14+
import java.util.Hashtable;
15+
import java.util.Map;
16+
1317
import javax.swing.JComponent;
1418

1519

@@ -27,11 +31,12 @@ public class SyntaxStyle
2731
* @param italic True if the text should be italics
2832
* @param bold True if the text should be bold
2933
*/
30-
public SyntaxStyle(Color color, boolean italic, boolean bold)
34+
public SyntaxStyle(Color color, boolean italic, boolean bold, boolean underlined)
3135
{
3236
this.color = color;
3337
this.italic = italic;
3438
this.bold = bold;
39+
this.underlined = underlined;
3540
}
3641

3742
/**
@@ -47,7 +52,7 @@ public Color getColor()
4752
*/
4853
public boolean isPlain()
4954
{
50-
return !(bold || italic);
55+
return !(bold || italic || underlined);
5156
}
5257

5358
/**
@@ -67,7 +72,14 @@ public boolean isBold()
6772
}
6873

6974
/**
70-
* Returns the specified font, but with the style's bold and
75+
* @return true if underline is enabled for this style.
76+
*/
77+
public boolean isUnderlined() {
78+
return underlined;
79+
}
80+
81+
/**
82+
* Returns the specified font, but with the style's bold, underline and
7183
* italic flags applied.
7284
*/
7385
public Font getStyledFont(Font font)
@@ -78,10 +90,16 @@ public Font getStyledFont(Font font)
7890
if(font.equals(lastFont))
7991
return lastStyledFont;
8092
lastFont = font;
93+
8194
lastStyledFont = new Font(font.getFamily(),
8295
(bold ? Font.BOLD : 0)
8396
| (italic ? Font.ITALIC : 0),
8497
font.getSize());
98+
if (underlined) {
99+
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
100+
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
101+
lastStyledFont = lastStyledFont.deriveFont(attr);
102+
}
85103
return lastStyledFont;
86104
}
87105

@@ -100,6 +118,11 @@ public FontMetrics getFontMetrics(Font font, JComponent comp)
100118
(bold ? Font.BOLD : 0)
101119
| (italic ? Font.ITALIC : 0),
102120
font.getSize());
121+
if (underlined) {
122+
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
123+
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
124+
lastStyledFont = lastStyledFont.deriveFont(attr);
125+
}
103126
//fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(lastStyledFont);
104127
fontMetrics = comp.getFontMetrics(lastStyledFont);
105128
return fontMetrics;
@@ -125,13 +148,16 @@ public String toString()
125148
{
126149
return getClass().getName() + "[color=" + color +
127150
(italic ? ",italic" : "") +
128-
(bold ? ",bold" : "") + "]";
151+
(bold ? ",bold" : "") +
152+
(underlined ? ",underlined" : "") +
153+
"]";
129154
}
130155

131156
// private members
132157
private Color color;
133158
private boolean italic;
134159
private boolean bold;
160+
private boolean underlined;
135161
private Font lastFont;
136162
private Font lastStyledFont;
137163
private FontMetrics fontMetrics;

app/src/processing/app/syntax/SyntaxUtilities.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ public static SyntaxStyle[] getDefaultSyntaxStyles()
9595
{
9696
SyntaxStyle[] styles = new SyntaxStyle[Token.ID_COUNT];
9797

98-
styles[Token.COMMENT1] = new SyntaxStyle(Color.black,true,false);
99-
styles[Token.COMMENT2] = new SyntaxStyle(new Color(0x990033),true,false);
100-
styles[Token.KEYWORD1] = new SyntaxStyle(Color.black,false,true);
101-
styles[Token.KEYWORD2] = new SyntaxStyle(Color.magenta,false,false);
102-
styles[Token.KEYWORD3] = new SyntaxStyle(new Color(0x009600),false,false);
103-
styles[Token.LITERAL1] = new SyntaxStyle(new Color(0x650099),false,false);
104-
styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),false,true);
105-
styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),false,true);
106-
styles[Token.OPERATOR] = new SyntaxStyle(Color.black,false,true);
107-
styles[Token.URL] = new SyntaxStyle(Color.blue,true,false);
108-
styles[Token.INVALID] = new SyntaxStyle(Color.red,false,true);
98+
styles[Token.COMMENT1] = new SyntaxStyle(Color.black,true,false,false);
99+
styles[Token.COMMENT2] = new SyntaxStyle(new Color(0x990033),true,false,false);
100+
styles[Token.KEYWORD1] = new SyntaxStyle(Color.black,false,true,false);
101+
styles[Token.KEYWORD2] = new SyntaxStyle(Color.magenta,false,false,false);
102+
styles[Token.KEYWORD3] = new SyntaxStyle(new Color(0x009600),false,false,false);
103+
styles[Token.LITERAL1] = new SyntaxStyle(new Color(0x650099),false,false,false);
104+
styles[Token.LITERAL2] = new SyntaxStyle(new Color(0x650099),false,true,false);
105+
styles[Token.LABEL] = new SyntaxStyle(new Color(0x990033),false,true,false);
106+
styles[Token.OPERATOR] = new SyntaxStyle(Color.black,false,true,false);
107+
styles[Token.URL] = new SyntaxStyle(Color.blue,true,false,false);
108+
styles[Token.INVALID] = new SyntaxStyle(Color.red,false,true,false);
109109

110110
return styles;
111111
}

build/shared/lib/theme/theme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ editor.literal1.style = #006699,plain
8484
editor.literal2.style = #006699,plain
8585

8686
# http://arduino.cc/
87-
editor.url.style = #0000ff,italic
87+
editor.url.style = #0000ff,underlined
8888

8989
# e.g. + - = /
9090
editor.operator.style = #000000,plain

0 commit comments

Comments
 (0)