mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-19 13:54:23 +01:00
URL right-clickable and underlined.
This commit is contained in:
parent
d60c42e5ed
commit
f233861a4c
@ -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 (offset<pos || offset>pos+2)
|
||||
int start = parse[0].length();
|
||||
int stop = start + parse[1].length();
|
||||
if (offset<start|| offset>stop+2)
|
||||
return false;
|
||||
clickedURL = parse[1];
|
||||
return true;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
|
||||
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<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
|
||||
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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user