Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaMode cleanup #4390

Merged
merged 8 commits into from Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/processing/app/ui/Editor.java
Expand Up @@ -332,6 +332,10 @@ public void windowGainedFocus(WindowEvent e) {
}
});

// TODO: Subclasses can't initialize anything before Doc Open happens since
// super() has to be the first line in subclass constructor; we might
// want to keep constructor light and call methods later [jv 160318]

// Open the document that was passed in
handleOpenInternal(path);

Expand Down
54 changes: 16 additions & 38 deletions java/src/processing/mode/java/JavaEditor.java
Expand Up @@ -49,14 +49,7 @@ public class JavaEditor extends Editor {

// Need to sort through the rest of these additions [fry]

// TODO these are all null, need to remove color support
protected Color breakpointColor;
protected Color currentLineColor;
protected Color breakpointMarkerColor;
protected Color currentLineMarkerColor;

protected List<LineHighlight> breakpointedLines =
new ArrayList<LineHighlight>();
protected final List<LineHighlight> breakpointedLines = new ArrayList<>();
protected LineHighlight currentLine; // where the debugger is suspended
protected final String breakpointMarkerComment = " //<>//";

Expand Down Expand Up @@ -983,7 +976,7 @@ public void propertyChange(PropertyChangeEvent e) {
Object value = optionPane.getValue();
if (value.equals(exportButton)) {
return jmode.handleExportApplication(sketch);
} else if (value.equals(cancelButton) || value.equals(Integer.valueOf(-1))) {
} else if (value.equals(cancelButton) || value.equals(-1)) {
// closed window by hitting Cancel or ESC
statusNotice(Language.text("export.notice.exporting.cancel"));
}
Expand Down Expand Up @@ -1619,7 +1612,7 @@ public void actionPerformed(ActionEvent e) {
item = Toolkit.newJMenuItem(Language.text("menu.debug.show_sketch_outline"), KeyEvent.VK_L);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.log("Show Sketch Outline:");
Messages.log("Show Sketch Outline:");
errorCheckerService.getASTGenerator().showSketchOutline();
}
});
Expand All @@ -1628,7 +1621,7 @@ public void actionPerformed(ActionEvent e) {
item = Toolkit.newJMenuItem(Language.text("menu.debug.show_tabs_list"), KeyEvent.VK_Y);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.log("Show Tab Outline:");
Messages.log("Show Tab Outline:");
errorCheckerService.getASTGenerator().showTabOutline();
}
});
Expand Down Expand Up @@ -1681,7 +1674,7 @@ public JMenu buildModeMenu() {
* removed from.
*/
protected List<LineID> stripBreakpointComments() {
List<LineID> bps = new ArrayList<LineID>();
List<LineID> bps = new ArrayList<>();
// iterate over all tabs
Sketch sketch = getSketch();
for (int i = 0; i < sketch.getCodeCount(); i++) {
Expand Down Expand Up @@ -1757,7 +1750,7 @@ protected void addBreakpointComments(String tabFilename) {
@Override
public boolean handleSave(boolean immediately) {
// note modified tabs
final List<String> modified = new ArrayList<String>();
final List<String> modified = new ArrayList<>();
for (int i = 0; i < getSketch().getCodeCount(); i++) {
SketchCode tab = getSketch().getCode(i);
if (tab.isModified()) {
Expand Down Expand Up @@ -1915,7 +1908,7 @@ protected void downloadImports() {
PApplet.matchAll(tabCode, ErrorCheckerService.IMPORT_REGEX);

if (pieces != null) {
ArrayList<String> importHeaders = new ArrayList<String>();
ArrayList<String> importHeaders = new ArrayList<>();
for (String[] importStatement : pieces) {
importHeaders.add(importStatement[2]);
}
Expand All @@ -1924,7 +1917,7 @@ protected void downloadImports() {
if (!installLibsHeaders.isEmpty()) {
StringBuilder libList = new StringBuilder("Would you like to install them now?");
for (AvailableContribution ac : installLibsHeaders) {
libList.append("\n • " + ac.getName());
libList.append("\n • ").append(ac.getName());
}
int option = Messages.showYesNoQuestion(this,
Language.text("contrib.import.dialog.title"),
Expand All @@ -1950,7 +1943,7 @@ protected void downloadImports() {
private List<AvailableContribution> getNotInstalledAvailableLibs(ArrayList<String> importHeadersList) {
Map<String, Contribution> importMap =
ContributionListing.getInstance().getLibrariesByImportHeader();
List<AvailableContribution> libList = new ArrayList<AvailableContribution>();
List<AvailableContribution> libList = new ArrayList<>();
for (String importHeaders : importHeadersList) {
int dot = importHeaders.lastIndexOf('.');
String entry = (dot == -1) ? importHeaders : importHeaders.substring(0,
Expand Down Expand Up @@ -2148,7 +2141,7 @@ public void toggleDebug() {

for (Component item : debugMenu.getMenuComponents()) {
if (item instanceof JMenuItem && item != debugItem) {
((JMenuItem) item).setEnabled(debugEnabled);
item.setEnabled(debugEnabled);
}
}
}
Expand Down Expand Up @@ -2213,8 +2206,8 @@ public void setCurrentLine(LineID line) {
// scroll to line, by setting the cursor
cursorToLineStart(line.lineIdx());
// highlight line
currentLine = new LineHighlight(line.lineIdx(), currentLineColor, this);
currentLine.setMarker(JavaTextArea.STEP_MARKER, currentLineMarkerColor);
currentLine = new LineHighlight(line.lineIdx(), this);
currentLine.setMarker(JavaTextArea.STEP_MARKER);
currentLine.setPriority(10); // fixes current line being hidden by the breakpoint when moved down
}

Expand Down Expand Up @@ -2242,8 +2235,8 @@ public void clearCurrentLine() {
* @param lineID the line id to highlight as breakpointed
*/
public void addBreakpointedLine(LineID lineID) {
LineHighlight hl = new LineHighlight(lineID, breakpointColor, this);
hl.setMarker(JavaTextArea.BREAK_MARKER, breakpointMarkerColor);
LineHighlight hl = new LineHighlight(lineID, this);
hl.setMarker(JavaTextArea.BREAK_MARKER);
breakpointedLines.add(hl);
// repaint current line if it's on this line
if (currentLine != null && currentLine.getLineID().equals(lineID)) {
Expand All @@ -2252,17 +2245,6 @@ public void addBreakpointedLine(LineID lineID) {
}


/**
* Add highlight for a breakpointed line on the current tab.
* @param lineIdx the line index on the current tab to highlight as
* breakpointed
*/
//TODO: remove and replace by {@link #addBreakpointedLine(LineID lineID)}
public void addBreakpointedLine(int lineIdx) {
addBreakpointedLine(getLineIDInCurrentTab(lineIdx));
}


/**
* Remove a highlight for a breakpointed line. Needs to be on the current tab.
* @param lineIdx the line index on the current tab to remove a breakpoint
Expand Down Expand Up @@ -2299,7 +2281,6 @@ public void clearBreakpointedLines() {
breakpointedLines.clear(); // remove all breakpoints
// fix highlights not being removed when tab names have
// changed due to opening a new sketch in same editor
getJavaTextArea().clearLineBgColors(); // force clear all highlights
getJavaTextArea().clearGutterText();

// repaint current line
Expand Down Expand Up @@ -2364,11 +2345,8 @@ public void setCode(SketchCode code) {
final JavaTextArea ta = getJavaTextArea();
// can be null when setCode is called the first time (in constructor)
if (ta != null) {
// clear all line backgrounds
ta.clearLineBgColors();
// clear all gutter text
ta.clearGutterText();
// load appropriate line backgrounds for tab
// first paint breakpoints
if (breakpointedLines != null) {
for (LineHighlight hl : breakpointedLines) {
Expand Down Expand Up @@ -2618,7 +2596,7 @@ private void showImportSuggestion(String[] list, int x, int y) {
// frmImportSuggest = null;
return;
}
final JList<String> classList = new JList<String>(list);
final JList<String> classList = new JList<>(list);
classList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
frmImportSuggest = new JFrame();

Expand Down Expand Up @@ -2876,7 +2854,7 @@ protected void initBaseCode() {

baseCode = new String[code.length];
for (int i = 0; i < code.length; i++) {
baseCode[i] = new String(code[i].getSavedProgram());
baseCode[i] = code[i].getSavedProgram();
}
}

Expand Down
1 change: 0 additions & 1 deletion java/src/processing/mode/java/MarkerColumn.java
Expand Up @@ -28,7 +28,6 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.JPanel;
Expand Down
50 changes: 8 additions & 42 deletions java/src/processing/mode/java/debug/LineHighlight.java
Expand Up @@ -20,7 +20,6 @@

package processing.mode.java.debug;

import java.awt.Color;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -35,25 +34,21 @@
*/
public class LineHighlight {

protected JavaEditor editor; // the view, used for highlighting lines by setting a background color
protected Color bgColor; // the background color for highlighting lines
protected LineID lineID; // the id of the line
protected final JavaEditor editor; // the view, used for highlighting lines by setting a background color
protected final LineID lineID; // the id of the line
protected String marker; //
protected Color markerColor;
protected int priority = 0;
protected static Set<LineHighlight> allHighlights = new HashSet<LineHighlight>();
protected static final Set<LineHighlight> allHighlights = new HashSet<>();


/**
* Create a {@link LineHighlight}.
*
* @param lineID the line id to highlight
* @param bgColor the background color used for highlighting
* @param editor the {@link JavaEditor}
*/
public LineHighlight(LineID lineID, Color bgColor, JavaEditor editor) {
public LineHighlight(LineID lineID, JavaEditor editor) {
this.lineID = lineID;
this.bgColor = bgColor;
this.editor = editor;
lineID.addListener(this);
lineID.startTracking(editor.getTab(lineID.fileName()).getDocument()); // TODO: overwrite a previous doc?
Expand Down Expand Up @@ -87,12 +82,11 @@ public int priority() {
* Create a {@link LineHighlight} on the current tab.
*
* @param lineIdx the line index on the current tab to highlight
* @param bgColor the background color used for highlighting
* @param editor the {@link JavaEditor}
*/
// TODO: Remove and replace by {@link #LineHighlight(LineID lineID, Color bgColor, JavaEditor editor)}
public LineHighlight(int lineIdx, Color bgColor, JavaEditor editor) {
this(editor.getLineIDInCurrentTab(lineIdx), bgColor, editor);
// TODO: Remove and replace by {@link #LineHighlight(LineID lineID, JavaEditor editor)}
public LineHighlight(int lineIdx, JavaEditor editor) {
this(editor.getLineIDInCurrentTab(lineIdx), editor);
}

/**
Expand All @@ -106,18 +100,6 @@ public void setMarker(String marker) {
paint();
}

/**
* Set a text based marker displayed in the left hand gutter area of this
* highlighted line. Also use a custom text color.
*
* @param marker the marker text
* @param markerColor the text color
*/
public void setMarker(String marker, Color markerColor) {
this.markerColor = markerColor;
setMarker(marker);
}

/**
* Retrieve the line id of this {@link LineHighlight}.
*
Expand All @@ -127,15 +109,6 @@ public LineID getLineID() {
return lineID;
}

/**
* Retrieve the color for highlighting this line.
*
* @return the highlight color.
*/
public Color getColor() {
return bgColor;
}

/**
* Test if this highlight is on a certain line.
*
Expand All @@ -157,7 +130,6 @@ public boolean isOnLine(LineID testLine) {
public void lineChanged(LineID line, int oldLineIdx, int newLineIdx) {
// clear old line
if (editor.isInCurrentTab(new LineID(line.fileName(), oldLineIdx))) {
editor.getJavaTextArea().clearLineBgColor(oldLineIdx);
editor.getJavaTextArea().clearGutterText(oldLineIdx);
}

Expand All @@ -184,13 +156,8 @@ public void dispose() {
*/
public void paint() {
if (editor.isInCurrentTab(lineID)) {
editor.getJavaTextArea().setLineBgColor(lineID.lineIdx(), bgColor);
if (marker != null) {
if (markerColor != null) {
editor.getJavaTextArea().setGutterText(lineID.lineIdx(), marker, markerColor);
} else {
editor.getJavaTextArea().setGutterText(lineID.lineIdx(), marker);
}
editor.getJavaTextArea().setGutterText(lineID.lineIdx(), marker);
}
}
}
Expand All @@ -200,7 +167,6 @@ public void paint() {
*/
public void clear() {
if (editor.isInCurrentTab(lineID)) {
editor.getJavaTextArea().clearLineBgColor(lineID.lineIdx());
editor.getJavaTextArea().clearGutterText(lineID.lineIdx());
}
}
Expand Down