diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 31aa16ea2..9cc1a151a 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -169,7 +169,7 @@ public class JavaEditor extends Editor { // add our hacked version back to the editor box.add(textAndError); - getJavaTextArea().setECSandThemeforTextArea(errorCheckerService, jmode); + getJavaTextArea().setMode(jmode); // ensure completion is hidden when editor loses focus addWindowFocusListener(new WindowFocusListener() { @@ -221,7 +221,7 @@ public class JavaEditor extends Editor { // Adding Error Table in a scroll pane errorTableScrollPane = new JScrollPane(); - errorTable = new XQErrorTable(errorCheckerService); + errorTable = new XQErrorTable(this); // errorTableScrollPane.setBorder(new EmptyBorder(2, 2, 2, 2)); // errorTableScrollPane.setBorder(new EtchedBorder()); errorTableScrollPane.setBorder(BorderFactory.createEmptyBorder()); @@ -1913,6 +1913,11 @@ public class JavaEditor extends Editor { } + public ErrorCheckerService getErrorChecker() { + return errorCheckerService; + } + + /** * Grab current contents of the sketch window, advance the console, stop any * other running sketches, auto-save the user's code... not in that order. diff --git a/java/src/processing/mode/java/pdex/CompletionPanel.java b/java/src/processing/mode/java/pdex/CompletionPanel.java index 70c2ea5ec..fff845507 100644 --- a/java/src/processing/mode/java/pdex/CompletionPanel.java +++ b/java/src/processing/mode/java/pdex/CompletionPanel.java @@ -104,9 +104,9 @@ public class CompletionPanel { * @param dedit */ public CompletionPanel(final JEditTextArea textarea, int position, String subWord, - DefaultListModel items, final Point location, JavaEditor dedit) { + DefaultListModel items, final Point location, JavaEditor editor) { this.textarea = (JavaTextArea) textarea; - editor = dedit; + this.editor = editor; this.insertionPosition = position; if (subWord.indexOf('.') != -1) this.subWord = subWord.substring(subWord.lastIndexOf('.') + 1); @@ -121,7 +121,7 @@ public class CompletionPanel { scrollPane.setViewportView(completionList = createSuggestionList(position, items)); popupMenu.add(scrollPane, BorderLayout.CENTER); popupMenu.setPopupSize(calcWidth(), calcHeight(items.getSize())); //TODO: Eradicate this evil - this.textarea.errorCheckerService.getASTGenerator().updateJavaDoc(completionList.getSelectedValue()); + editor.getErrorChecker().getASTGenerator().updateJavaDoc(completionList.getSelectedValue()); textarea.requestFocusInWindow(); popupMenu.show(textarea, location.x, textarea.getBaseline(0, 0) + location.y); //log("Suggestion shown: " + System.currentTimeMillis()); @@ -487,7 +487,7 @@ public class CompletionPanel { .getVerticalScrollBar() .getValue() - step); - textarea.errorCheckerService.getASTGenerator().updateJavaDoc(completionList.getSelectedValue()); + editor.getErrorChecker().getASTGenerator().updateJavaDoc(completionList.getSelectedValue()); } } @@ -504,7 +504,7 @@ public class CompletionPanel { int index = Math.min(completionList.getSelectedIndex() + 1, completionList.getModel().getSize() - 1); selectIndex(index); - textarea.errorCheckerService.getASTGenerator().updateJavaDoc(completionList.getSelectedValue()); + editor.getErrorChecker().getASTGenerator().updateJavaDoc(completionList.getSelectedValue()); int step = scrollPane.getVerticalScrollBar().getMaximum() / completionList.getModel().getSize(); scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getValue() + step); } diff --git a/java/src/processing/mode/java/pdex/ErrorCheckerService.java b/java/src/processing/mode/java/pdex/ErrorCheckerService.java index fdf9ed36c..3c053fca1 100644 --- a/java/src/processing/mode/java/pdex/ErrorCheckerService.java +++ b/java/src/processing/mode/java/pdex/ErrorCheckerService.java @@ -111,7 +111,7 @@ public class ErrorCheckerService implements Runnable { /** * Stores all Problems in the sketch */ - public ArrayList problemsList; + public List problemsList; /** * How many lines are present till the initial class declaration? In static diff --git a/java/src/processing/mode/java/pdex/ErrorWindow.java b/java/src/processing/mode/java/pdex/ErrorWindow.java index d381ac6f4..a7656e1b6 100644 --- a/java/src/processing/mode/java/pdex/ErrorWindow.java +++ b/java/src/processing/mode/java/pdex/ErrorWindow.java @@ -22,7 +22,6 @@ package processing.mode.java.pdex; import java.awt.BorderLayout; import java.awt.Frame; -import java.awt.Point; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.WindowAdapter; @@ -35,16 +34,16 @@ import javax.swing.WindowConstants; import javax.swing.border.EmptyBorder; import javax.swing.table.TableModel; -import processing.app.Editor; import processing.app.Toolkit; import processing.mode.java.JavaEditor; + /** * Error Window that displays a tablular list of errors. Clicking on an error * scrolls to its location in the code. - * + * * @author Manindra Moharana <me@mkmoharana.com> - * + * */ public class ErrorWindow extends JFrame { @@ -58,9 +57,10 @@ public class ErrorWindow extends JFrame { */ protected JScrollPane scrollPane; - protected JavaEditor thisEditor; + //protected JavaEditor thisEditor; + protected JavaEditor editor; private JFrame thisErrorWindow; - + /** * Handles the sticky Problem window */ @@ -70,7 +70,7 @@ public class ErrorWindow extends JFrame { /** * Preps up ErrorWindow - * + * * @param editor * - Editor * @param ecs - ErrorCheckerService @@ -78,11 +78,12 @@ public class ErrorWindow extends JFrame { public ErrorWindow(JavaEditor editor, ErrorCheckerService ecs) { thisErrorWindow = this; errorCheckerService = ecs; - thisEditor = editor; + this.editor = editor; setTitle("Problems"); prepareFrame(); } + /** * Sets up ErrorWindow */ @@ -100,7 +101,7 @@ public class ErrorWindow extends JFrame { scrollPane = new JScrollPane(); contentPane.add(scrollPane); - errorTable = new XQErrorTable(errorCheckerService); + errorTable = new XQErrorTable(editor); scrollPane.setViewportView(errorTable); try { @@ -111,17 +112,17 @@ public class ErrorWindow extends JFrame { e.printStackTrace(); } - if (thisEditor != null) { - setLocation(new Point(thisEditor.getLocation().x - + thisEditor.getWidth(), thisEditor.getLocation().y)); + if (editor != null) { + setLocation(editor.getLocation().x + editor.getWidth(), + editor.getLocation().y); } - } + /** * Updates the error table with new data(Table Model). Called from Error * Checker Service. - * + * * @param tableModel * - Table Model * @return True - If error table was updated successfully. @@ -173,12 +174,12 @@ public class ErrorWindow extends JFrame { @Override public void windowDeiconified(WindowEvent e) { - thisEditor.setExtendedState(Frame.NORMAL); + editor.setExtendedState(Frame.NORMAL); } }); - if (thisEditor == null) { + if (editor == null) { System.out.println("Editor null"); return; } @@ -209,7 +210,7 @@ public class ErrorWindow extends JFrame { });*/ - thisEditor.addComponentListener(new ComponentListener() { + editor.addComponentListener(new ComponentListener() { @Override public void componentShown(ComponentEvent e) { @@ -249,10 +250,10 @@ public class ErrorWindow extends JFrame { * Implements the docking feature of the tool - The frame sticks to the * editor and once docked, moves along with it as the editor is resized, * moved, or closed. - * + * * This class has been borrowed from Tab Manager tool by Thomas Diewald. It * has been slightly modified and used here. - * + * * @author Thomas Diewald , http://thomasdiewald.com */ private class DockTool2Base { @@ -285,9 +286,7 @@ public class ErrorWindow extends JFrame { // public void tryDocking() { - if (thisEditor == null) - return; - Editor editor = thisEditor; + if (editor == null) return; Frame frame = thisErrorWindow; int ex = editor.getX(); @@ -330,9 +329,7 @@ public class ErrorWindow extends JFrame { } public void dock() { - if (thisEditor == null) - return; - Editor editor = thisEditor; + if (editor == null) return; Frame frame = thisErrorWindow; int ex = editor.getX(); @@ -369,6 +366,5 @@ public class ErrorWindow extends JFrame { } frame.setLocation(x, y); } - } } diff --git a/java/src/processing/mode/java/pdex/JavaTextArea.java b/java/src/processing/mode/java/pdex/JavaTextArea.java index b01c10b62..f0d68c256 100644 --- a/java/src/processing/mode/java/pdex/JavaTextArea.java +++ b/java/src/processing/mode/java/pdex/JavaTextArea.java @@ -82,7 +82,7 @@ public class JavaTextArea extends JEditTextArea { /// maps line index to gutter text color protected Map gutterTextColors = new HashMap(); - protected ErrorCheckerService errorCheckerService; +// protected ErrorCheckerService errorCheckerService; private CompletionPanel suggestion; @@ -159,10 +159,9 @@ public class JavaTextArea extends JEditTextArea { * @param ecs * @param mode */ - public void setECSandThemeforTextArea(ErrorCheckerService ecs, - JavaMode mode) { - errorCheckerService = ecs; - getCustomPainter().setECSandTheme(ecs, mode); + public void setMode(JavaMode mode) { +// errorCheckerService = ecs; + getCustomPainter().setMode(mode); } @@ -383,7 +382,7 @@ public class JavaTextArea extends JEditTextArea { return null; } Base.log("Mouse click, word: " + word.trim()); - errorCheckerService.getASTGenerator().setLastClickedWord(line, word, xLS); + editor.getErrorChecker().getASTGenerator().setLastClickedWord(line, word, xLS); return word.trim(); } } @@ -443,8 +442,7 @@ public class JavaTextArea extends JEditTextArea { if (word.endsWith(".")) word = word.substring(0, word.length() - 1); - errorCheckerService.getASTGenerator().preparePredictions(word, line - + errorCheckerService.mainClassOffset,0); + editor.getErrorChecker().getASTGenerator().preparePredictions(word, line + editor.getErrorChecker().mainClassOffset,0); return word; } @@ -506,8 +504,8 @@ public class JavaTextArea extends JEditTextArea { // word = word.substring(0, word.length() - 1); int lineStartNonWSOffset = 0; if (word.length() >= JavaMode.codeCompletionTriggerLength) { - errorCheckerService.getASTGenerator() - .preparePredictions(word, line + errorCheckerService.mainClassOffset, + editor.getErrorChecker().getASTGenerator() + .preparePredictions(word, line + editor.getErrorChecker().mainClassOffset, lineStartNonWSOffset); } return word; diff --git a/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java b/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java index a6604f6ab..962ddad83 100644 --- a/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java +++ b/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java @@ -66,7 +66,7 @@ public class JavaTextAreaPainter extends TextAreaPainter implements MouseListener, MouseMotionListener { // protected JavaTextArea ta; // we need the subclassed textarea - protected ErrorCheckerService errorCheckerService; +// protected ErrorCheckerService errorCheckerService; public Color errorColor; // = new Color(0xED2630); public Color warningColor; // = new Color(0xFFC30E); @@ -188,8 +188,8 @@ public class JavaTextAreaPainter extends TextAreaPainter if (Character.isDigit(word.charAt(0))) return; - Base.log(errorCheckerService.mainClassOffset + line + "|" + line + "| offset " + xLS + word + " <= \n"); - errorCheckerService.getASTGenerator().scrollToDeclaration(line, word, xLS); + Base.log(getEditor().getErrorChecker().mainClassOffset + line + "|" + line + "| offset " + xLS + word + " <= \n"); + getEditor().getErrorChecker().getASTGenerator().scrollToDeclaration(line, word, xLS); } } @@ -398,11 +398,8 @@ public class JavaTextAreaPainter extends TextAreaPainter * @param x */ protected void paintErrorLine(Graphics gfx, int line, int x) { - if (errorCheckerService == null) { - return; - } - - if (errorCheckerService.problemsList == null) { + ErrorCheckerService ecs = getEditor().getErrorChecker(); + if (ecs == null || ecs.problemsList == null) { return; } @@ -413,7 +410,7 @@ public class JavaTextAreaPainter extends TextAreaPainter errorLineCoords.clear(); // Check if current line contains an error. If it does, find if it's an // error or warning - for (ErrorMarker emarker : errorCheckerService.getEditor().getErrorPoints()) { + for (ErrorMarker emarker : getEditor().getErrorPoints()) { if (emarker.getProblem().getLineNumber() == line) { notFound = false; if (emarker.getType() == ErrorMarker.Warning) { @@ -529,8 +526,8 @@ public class JavaTextAreaPainter extends TextAreaPainter * @param ecs * @param mode */ - public void setECSandTheme(ErrorCheckerService ecs, JavaMode mode) { - this.errorCheckerService = ecs; + public void setMode(JavaMode mode) { + //this.errorCheckerService = ecs; //loadTheme(mode); errorColor = mode.getColor("editor.errorcolor"); //, errorColor); @@ -543,6 +540,7 @@ public class JavaTextAreaPainter extends TextAreaPainter gutterLineHighlightColor = mode.getColor("editor.gutter.linehighlight.color"); } + @Override public String getToolTipText(MouseEvent event) { if (!getEditor().hasJavaTabs()) { @@ -614,7 +612,7 @@ public class JavaTextAreaPainter extends TextAreaPainter setToolTipText(null); return super.getToolTipText(event); } - String tooltipText = errorCheckerService.getASTGenerator() + String tooltipText = getEditor().getErrorChecker().getASTGenerator() .getLabelForASTNode(line, word, xLS); // log(errorCheckerService.mainClassOffset + " MCO " diff --git a/java/src/processing/mode/java/pdex/XQErrorTable.java b/java/src/processing/mode/java/pdex/XQErrorTable.java index 39ff51eae..7ecc204df 100644 --- a/java/src/processing/mode/java/pdex/XQErrorTable.java +++ b/java/src/processing/mode/java/pdex/XQErrorTable.java @@ -23,6 +23,7 @@ package processing.mode.java.pdex; import java.awt.Color; import java.awt.FontMetrics; import java.awt.event.*; +import java.util.List; import javax.swing.*; import javax.swing.event.ListSelectionEvent; @@ -41,12 +42,13 @@ import processing.mode.java.JavaEditor; * @author Manindra Moharana <me@mkmoharana.com> */ public class XQErrorTable extends JTable { + JavaEditor editor; /** Column Names of JTable */ - public static final String[] columnNames = { - Language.text("editor.footer.errors.problem"), - Language.text("editor.footer.errors.tab"), - Language.text("editor.footer.errors.line") + public static final String[] columnNames = { + Language.text("editor.footer.errors.problem"), + Language.text("editor.footer.errors.tab"), + Language.text("editor.footer.errors.line") }; /** Column Widths of JTable. */ @@ -56,11 +58,13 @@ public class XQErrorTable extends JTable { private boolean columnResizing = false; /** ErrorCheckerService instance */ - protected ErrorCheckerService errorCheckerService; +// protected ErrorCheckerService errorCheckerService; - - public XQErrorTable(final ErrorCheckerService errorCheckerService) { - this.errorCheckerService = errorCheckerService; + +// public XQErrorTable(final ErrorCheckerService errorCheckerService) { +// this.errorCheckerService = errorCheckerService; + public XQErrorTable(final JavaEditor editor) { + this.editor = editor; for (int i = 0; i < this.getColumnModel().getColumnCount(); i++) { getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]); } @@ -72,28 +76,30 @@ public class XQErrorTable extends JTable { synchronized public void mouseClicked(MouseEvent e) { try { int row = ((XQErrorTable) e.getSource()).getSelectedRow(); - errorCheckerService.scrollToErrorLine(row); + editor.getErrorChecker().scrollToErrorLine(row); } catch (Exception e1) { Base.log("Exception XQErrorTable mouseReleased " + e); } - } + } }); - - final XQErrorTable thisTable = this; - + +// final XQErrorTable thisTable = this; + this.addMouseMotionListener(new MouseMotionAdapter() { - + @Override public void mouseMoved(MouseEvent evt) { int rowIndex = rowAtPoint(evt.getPoint()); - synchronized (errorCheckerService.problemsList) { - if (rowIndex < errorCheckerService.problemsList.size()) { - - Problem p = errorCheckerService.problemsList.get(rowIndex); + + List problemsList = editor.getErrorChecker().problemsList; + synchronized (problemsList) { + if (rowIndex < problemsList.size()) { + + Problem p = problemsList.get(rowIndex); if (p.getImportSuggestions() != null && p.getImportSuggestions().length > 0) { String t = p.getMessage() + "(Import Suggestions available)"; - FontMetrics fm = thisTable.getFontMetrics(thisTable.getFont()); + FontMetrics fm = getFontMetrics(getFont()); int x1 = fm.stringWidth(p.getMessage()); int x2 = fm.stringWidth(t); if (evt.getX() > x1 && evt.getX() < x2) { @@ -103,7 +109,7 @@ public class XQErrorTable extends JTable { for (int i = 0; i < list.length; i++) { temp[i] = "Import '" + className + "' (" + list[i] + ")"; } - showImportSuggestion(temp, evt.getXOnScreen(), evt.getYOnScreen() - 3 * thisTable.getFont().getSize()); + showImportSuggestion(temp, evt.getXOnScreen(), evt.getYOnScreen() - 3 * getFont().getSize()); } } } @@ -116,7 +122,7 @@ public class XQErrorTable extends JTable { // widths,and resume updating. Updating is disabled as long as // columnResizing is true this.getTableHeader().addMouseListener(new MouseAdapter() { - + @Override public void mousePressed(MouseEvent e) { columnResizing = true; @@ -131,11 +137,11 @@ public class XQErrorTable extends JTable { } } }); - + ToolTipManager.sharedInstance().registerComponent(this); } - - + + @Override public boolean isCellEditable(int rowIndex, int colIndex) { return false; // Disallow the editing of any cell @@ -163,7 +169,7 @@ public class XQErrorTable extends JTable { protected void done() { try { setModel(tableModel); - + // Set column widths to user defined widths for (int i = 0; i < getColumnModel().getColumnCount(); i++) { getColumnModel().getColumn(i).setPreferredWidth( @@ -190,10 +196,10 @@ public class XQErrorTable extends JTable { } return true; } - - + + JFrame frmImportSuggest; - + private void showImportSuggestion(String list[], int x, int y){ if (frmImportSuggest != null) { // frmImportSuggest.setVisible(false); @@ -203,7 +209,7 @@ public class XQErrorTable extends JTable { final JList classList = new JList(list); classList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); frmImportSuggest = new JFrame(); - + frmImportSuggest.setUndecorated(true); frmImportSuggest.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel panel = new JPanel(); @@ -218,8 +224,7 @@ public class XQErrorTable extends JTable { panel.validate(); frmImportSuggest.getContentPane().add(panel); frmImportSuggest.pack(); - - final JavaEditor editor = errorCheckerService.getEditor(); + classList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (classList.getSelectedValue() != null) { @@ -242,9 +247,9 @@ public class XQErrorTable extends JTable { frmImportSuggest = null; } }); - + frmImportSuggest.addWindowFocusListener(new WindowFocusListener() { - + @Override public void windowLostFocus(WindowEvent e) { if (frmImportSuggest != null) { @@ -252,10 +257,10 @@ public class XQErrorTable extends JTable { frmImportSuggest = null; } } - + @Override public void windowGainedFocus(WindowEvent e) { - + } });