Skip to content

Commit 6848614

Browse files
author
Federico Fissore
committed
Code cleanup
1 parent ffff480 commit 6848614

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

app/src/processing/app/syntax/SketchTextArea.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public SketchTextArea(PdeKeywords pdeKeywords) throws IOException {
8686
installFeatures();
8787
}
8888

89-
protected void installFeatures() throws IOException {
89+
private void installFeatures() throws IOException {
9090
setTheme(PreferencesData.get("editor.syntax_theme", "default"));
9191

9292
setLinkGenerator(new DocLinkGenerator(pdeKeywords));
@@ -96,7 +96,7 @@ protected void installFeatures() throws IOException {
9696
setSyntaxEditingStyle(SYNTAX_STYLE_CPLUSPLUS);
9797
}
9898

99-
public void setTheme(String name) throws IOException {
99+
private void setTheme(String name) throws IOException {
100100
FileInputStream defaultXmlInputStream = null;
101101
try {
102102
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/" + name + ".xml"));
@@ -143,31 +143,26 @@ private void setSyntaxTheme(int tokenType, String id) {
143143

144144
// Removing the default focus traversal keys
145145
// This is because the DefaultKeyboardFocusManager handles the keypress and consumes the event
146-
protected void fixControlTab() {
146+
private void fixControlTab() {
147147
removeCTRLTabFromFocusTraversal();
148148

149149
removeCTRLSHIFTTabFromFocusTraversal();
150150
}
151151

152152
private void removeCTRLSHIFTTabFromFocusTraversal() {
153153
KeyStroke ctrlShiftTab = KeyStroke.getKeyStroke("ctrl shift TAB");
154-
Set<AWTKeyStroke> backwardKeys = new HashSet<AWTKeyStroke>(this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
154+
Set<AWTKeyStroke> backwardKeys = new HashSet<>(this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
155155
backwardKeys.remove(ctrlShiftTab);
156156
}
157157

158158
private void removeCTRLTabFromFocusTraversal() {
159159
KeyStroke ctrlTab = KeyStroke.getKeyStroke("ctrl TAB");
160-
Set<AWTKeyStroke> forwardKeys = new HashSet<AWTKeyStroke>(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
160+
Set<AWTKeyStroke> forwardKeys = new HashSet<>(this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
161161
forwardKeys.remove(ctrlTab);
162162
this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
163163
}
164164

165165

166-
@Override
167-
public void select(int selectionStart, int selectionEnd) {
168-
super.select(selectionStart, selectionEnd);
169-
}
170-
171166
public boolean isSelectionActive() {
172167
return this.getSelectedText() != null;
173168
}
@@ -221,17 +216,6 @@ public void switchDocument(Document document, UndoManager newUndo) {
221216

222217
}
223218

224-
@Override
225-
protected JPopupMenu createPopupMenu() {
226-
JPopupMenu menu = super.createPopupMenu();
227-
return menu;
228-
}
229-
230-
@Override
231-
protected void configurePopupMenu(JPopupMenu popupMenu) {
232-
super.configurePopupMenu(popupMenu);
233-
}
234-
235219
@Override
236220
protected RTAMouseListener createMouseListener() {
237221
return new SketchTextAreaMouseListener(this);
@@ -242,7 +226,7 @@ public void getTextLine(int line, Segment segment) {
242226
int offset = getLineStartOffset(line);
243227
int end = getLineEndOffset(line);
244228
getDocument().getText(offset, end - offset, segment);
245-
} catch (BadLocationException e) {
229+
} catch (BadLocationException ignored) {
246230
}
247231
}
248232

@@ -271,16 +255,16 @@ public DocLinkGenerator(PdeKeywords pdeKeywords) {
271255

272256
@Override
273257
public LinkGeneratorResult isLinkAtOffset(RSyntaxTextArea textArea, final int offs) {
258+
Token token = textArea.modelToToken(offs);
259+
if (token == null) {
260+
return null;
261+
}
274262

275-
final Token token = textArea.modelToToken(offs);
276-
277-
final String reference = pdeKeywords.getReference(token.getLexeme());
278-
279-
// LOG.fine("reference: " + reference + ", match: " + (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION));
263+
String reference = pdeKeywords.getReference(token.getLexeme());
280264

281-
if (token != null && (reference != null || (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION))) {
265+
if (reference != null || (token.getType() == TokenTypes.DATA_TYPE || token.getType() == TokenTypes.VARIABLE || token.getType() == TokenTypes.FUNCTION)) {
282266

283-
LinkGeneratorResult generatorResult = new LinkGeneratorResult() {
267+
return new LinkGeneratorResult() {
284268

285269
@Override
286270
public int getSourceOffset() {
@@ -297,8 +281,6 @@ public HyperlinkEvent execute() {
297281
return null;
298282
}
299283
};
300-
301-
return generatorResult;
302284
}
303285

304286
return null;
@@ -316,7 +298,7 @@ private class SketchTextAreaMouseListener extends RTextAreaMutableCaretEvent {
316298
private boolean isScanningForLinks;
317299
private int hoveredOverLinkOffset = -1;
318300

319-
protected SketchTextAreaMouseListener(RTextArea textArea) {
301+
SketchTextAreaMouseListener(RTextArea textArea) {
320302
super(textArea);
321303
insets = new Insets(0, 0, 0, 0);
322304
}
@@ -458,7 +440,7 @@ private void stopScanningForLinks() {
458440
if (isScanningForLinks) {
459441
Cursor c = getCursor();
460442
isScanningForLinks = false;
461-
if (c != null && c.getType() == Cursor.HAND_CURSOR) {
443+
if (c.getType() == Cursor.HAND_CURSOR) {
462444
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
463445
repaint(); // TODO: Repaint just the affected line.
464446
}

0 commit comments

Comments
 (0)