mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Code cleanup
This commit is contained in:
parent
ffff480e9b
commit
6848614ce2
@ -86,7 +86,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
installFeatures();
|
installFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void installFeatures() throws IOException {
|
private void installFeatures() throws IOException {
|
||||||
setTheme(PreferencesData.get("editor.syntax_theme", "default"));
|
setTheme(PreferencesData.get("editor.syntax_theme", "default"));
|
||||||
|
|
||||||
setLinkGenerator(new DocLinkGenerator(pdeKeywords));
|
setLinkGenerator(new DocLinkGenerator(pdeKeywords));
|
||||||
@ -96,7 +96,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
setSyntaxEditingStyle(SYNTAX_STYLE_CPLUSPLUS);
|
setSyntaxEditingStyle(SYNTAX_STYLE_CPLUSPLUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTheme(String name) throws IOException {
|
private void setTheme(String name) throws IOException {
|
||||||
FileInputStream defaultXmlInputStream = null;
|
FileInputStream defaultXmlInputStream = null;
|
||||||
try {
|
try {
|
||||||
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/" + name + ".xml"));
|
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/" + name + ".xml"));
|
||||||
@ -143,7 +143,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
|
|
||||||
// Removing the default focus traversal keys
|
// Removing the default focus traversal keys
|
||||||
// This is because the DefaultKeyboardFocusManager handles the keypress and consumes the event
|
// This is because the DefaultKeyboardFocusManager handles the keypress and consumes the event
|
||||||
protected void fixControlTab() {
|
private void fixControlTab() {
|
||||||
removeCTRLTabFromFocusTraversal();
|
removeCTRLTabFromFocusTraversal();
|
||||||
|
|
||||||
removeCTRLSHIFTTabFromFocusTraversal();
|
removeCTRLSHIFTTabFromFocusTraversal();
|
||||||
@ -151,23 +151,18 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
|
|
||||||
private void removeCTRLSHIFTTabFromFocusTraversal() {
|
private void removeCTRLSHIFTTabFromFocusTraversal() {
|
||||||
KeyStroke ctrlShiftTab = KeyStroke.getKeyStroke("ctrl shift TAB");
|
KeyStroke ctrlShiftTab = KeyStroke.getKeyStroke("ctrl shift TAB");
|
||||||
Set<AWTKeyStroke> backwardKeys = new HashSet<AWTKeyStroke>(this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
|
Set<AWTKeyStroke> backwardKeys = new HashSet<>(this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
|
||||||
backwardKeys.remove(ctrlShiftTab);
|
backwardKeys.remove(ctrlShiftTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeCTRLTabFromFocusTraversal() {
|
private void removeCTRLTabFromFocusTraversal() {
|
||||||
KeyStroke ctrlTab = KeyStroke.getKeyStroke("ctrl TAB");
|
KeyStroke ctrlTab = KeyStroke.getKeyStroke("ctrl TAB");
|
||||||
Set<AWTKeyStroke> forwardKeys = new HashSet<AWTKeyStroke>(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
|
Set<AWTKeyStroke> forwardKeys = new HashSet<>(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
|
||||||
forwardKeys.remove(ctrlTab);
|
forwardKeys.remove(ctrlTab);
|
||||||
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
|
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void select(int selectionStart, int selectionEnd) {
|
|
||||||
super.select(selectionStart, selectionEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSelectionActive() {
|
public boolean isSelectionActive() {
|
||||||
return this.getSelectedText() != null;
|
return this.getSelectedText() != null;
|
||||||
}
|
}
|
||||||
@ -221,17 +216,6 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JPopupMenu createPopupMenu() {
|
|
||||||
JPopupMenu menu = super.createPopupMenu();
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configurePopupMenu(JPopupMenu popupMenu) {
|
|
||||||
super.configurePopupMenu(popupMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RTAMouseListener createMouseListener() {
|
protected RTAMouseListener createMouseListener() {
|
||||||
return new SketchTextAreaMouseListener(this);
|
return new SketchTextAreaMouseListener(this);
|
||||||
@ -242,7 +226,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
int offset = getLineStartOffset(line);
|
int offset = getLineStartOffset(line);
|
||||||
int end = getLineEndOffset(line);
|
int end = getLineEndOffset(line);
|
||||||
getDocument().getText(offset, end - offset, segment);
|
getDocument().getText(offset, end - offset, segment);
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,16 +255,16 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkGeneratorResult isLinkAtOffset(RSyntaxTextArea textArea, final int offs) {
|
public LinkGeneratorResult isLinkAtOffset(RSyntaxTextArea textArea, final int offs) {
|
||||||
|
Token token = textArea.modelToToken(offs);
|
||||||
|
if (token == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
final Token token = textArea.modelToToken(offs);
|
String reference = pdeKeywords.getReference(token.getLexeme());
|
||||||
|
|
||||||
final String reference = pdeKeywords.getReference(token.getLexeme());
|
if (reference != null || (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION)) {
|
||||||
|
|
||||||
// LOG.fine("reference: " + reference + ", match: " + (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION));
|
return new LinkGeneratorResult() {
|
||||||
|
|
||||||
if (token != null && (reference != null || (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION))) {
|
|
||||||
|
|
||||||
LinkGeneratorResult generatorResult = new LinkGeneratorResult() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSourceOffset() {
|
public int getSourceOffset() {
|
||||||
@ -297,8 +281,6 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return generatorResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -316,7 +298,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
private boolean isScanningForLinks;
|
private boolean isScanningForLinks;
|
||||||
private int hoveredOverLinkOffset = -1;
|
private int hoveredOverLinkOffset = -1;
|
||||||
|
|
||||||
protected SketchTextAreaMouseListener(RTextArea textArea) {
|
SketchTextAreaMouseListener(RTextArea textArea) {
|
||||||
super(textArea);
|
super(textArea);
|
||||||
insets = new Insets(0, 0, 0, 0);
|
insets = new Insets(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@ -458,7 +440,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
|||||||
if (isScanningForLinks) {
|
if (isScanningForLinks) {
|
||||||
Cursor c = getCursor();
|
Cursor c = getCursor();
|
||||||
isScanningForLinks = false;
|
isScanningForLinks = false;
|
||||||
if (c != null && c.getType() == Cursor.HAND_CURSOR) {
|
if (c.getType() == Cursor.HAND_CURSOR) {
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||||
repaint(); // TODO: Repaint just the affected line.
|
repaint(); // TODO: Repaint just the affected line.
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user