diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 1ed649ceb..b1bedbe09 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -129,6 +129,16 @@ public class DebugEditor extends JavaEditor implements ActionListener { */ protected boolean compilationCheckEnabled = true; + /** + * Show warnings menu item + */ + protected JCheckBoxMenuItem showWarnings; + + /** + * Check box menu item for show/hide Problem Window + */ + public JCheckBoxMenuItem problemWindowMenuCB; + public DebugEditor(Base base, String path, EditorState state, Mode mode) { super(base, path, state, mode); @@ -383,8 +393,9 @@ public class DebugEditor extends JavaEditor implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - if (errorCheckerService.errorWindow == null) + if (errorCheckerService.errorWindow == null) { return; + } errorCheckerService.errorWindow .setVisible(((JCheckBoxMenuItem) e.getSource()) .isSelected()); @@ -410,102 +421,6 @@ public class DebugEditor extends JavaEditor implements ActionListener { return debugMenu; } - /** - * Show warnings menu item - */ - protected JCheckBoxMenuItem showWarnings; - - /** - * Check box menu item for show/hide Problem Window - */ - public JCheckBoxMenuItem problemWindowMenuCB; - - - public JMenu buildXQModeMenu() { - - // Enable Error Checker - CB - // Show/Hide Problem Window - CB - // Show Warnings - CB - JMenu menu = new JMenu("XQMode"); - JCheckBoxMenuItem item; - final DebugEditor thisEditor = this; - item = new JCheckBoxMenuItem("Error Checker Enabled"); - item.setSelected(true); - item.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - - if (!((JCheckBoxMenuItem) e.getSource()).isSelected()) { - // unticked Menu Item - errorCheckerService.pauseThread(); - System.out.println(thisEditor.getSketch().getName() - + " - Error Checker paused."); - errorBar.errorPoints.clear(); - errorCheckerService.problemsList.clear(); - errorCheckerService.updateErrorTable(); - errorCheckerService.updateEditorStatus(); - getTextArea().repaint(); - } else { - errorCheckerService.resumeThread(); - System.out.println(thisEditor.getSketch().getName() - + " - Error Checker resumed."); - } - } - }); - menu.add(item); - - problemWindowMenuCB = new JCheckBoxMenuItem("Show Problem Window"); - // problemWindowMenuCB.setSelected(true); - problemWindowMenuCB.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - if (errorCheckerService.errorWindow == null) - return; - errorCheckerService.errorWindow - .setVisible(((JCheckBoxMenuItem) e.getSource()) - .isSelected()); - // switch to console, now that Error Window is open - toggleView(XQConsoleToggle.text[0]); - } - }); - menu.add(problemWindowMenuCB); - - showWarnings = new JCheckBoxMenuItem("Warnings Enabled"); - showWarnings.setSelected(true); - showWarnings.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - errorCheckerService.warningsEnabled = ((JCheckBoxMenuItem) e - .getSource()).isSelected(); - } - }); - menu.add(showWarnings); - - menu.addSeparator(); - - JMenuItem item2 = new JMenuItem("XQMode Wiki"); - item2.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Base.openURL("https://github.com/Manindra29/XQMode/wiki"); - } - }); - menu.add(item2); - - item2 = new JMenuItem("XQMode on Github"); - item2.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Base.openURL("https://github.com/Manindra29/XQMode"); - } - }); - menu.add(item2); - return menu; - } - @Override public JMenu buildModeMenu() { return buildDebugMenu(); @@ -1176,6 +1091,10 @@ public class DebugEditor extends JavaEditor implements ActionListener { } + /** + * Updates the error bar + * @param problems + */ public void updateErrorBar(ArrayList problems) { errorBar.updateErrorPoints(problems); } @@ -1191,6 +1110,11 @@ public class DebugEditor extends JavaEditor implements ActionListener { cl.show(consoleProblemsPane, buttonName); } + /** + * Updates the error table + * @param tableModel + * @return + */ synchronized public boolean updateTable(final TableModel tableModel) { return errorTable.updateTable(tableModel); } diff --git a/pdex/src/processing/mode/experimental/ErrorBar.java b/pdex/src/processing/mode/experimental/ErrorBar.java index 4934ebc70..b66c34543 100755 --- a/pdex/src/processing/mode/experimental/ErrorBar.java +++ b/pdex/src/processing/mode/experimental/ErrorBar.java @@ -1,11 +1,11 @@ /* Part of the XQMode project - https://github.com/Manindra29/XQMode - + Under Google Summer of Code 2012 - http://www.google-melange.com/gsoc/homepage/google/gsoc2012 - + Copyright (C) 2012 Manindra Moharana - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. @@ -81,8 +81,14 @@ public class ErrorBar extends JPanel { */ public Color backgroundColor = new Color(0x2C343D); + /** + * DebugEditor instance + */ protected DebugEditor editor; + /** + * ErrorCheckerService instance + */ protected ErrorCheckerService errorCheckerService; /** @@ -90,6 +96,9 @@ public class ErrorBar extends JPanel { */ protected ArrayList errorPoints = new ArrayList(); + /** + * Stores previous list of error markers. + */ protected ArrayList errorPointsOld = new ArrayList(); public void paintComponent(Graphics g) { @@ -102,8 +111,7 @@ public class ErrorBar extends JPanel { for (ErrorMarker emarker : errorPoints) { if (emarker.type == ErrorMarker.Error) { g.setColor(errorColor); - } - else { + } else { g.setColor(warningColor); } g.fillRect(2, emarker.y, (getWidth() - 3), errorMarkerHeight); @@ -123,8 +131,8 @@ public class ErrorBar extends JPanel { this.preferredHeight = height; this.errorCheckerService = editor.errorCheckerService; errorColor = mode.getThemeColor("errorbar.errorcolor", errorColor); - warningColor = mode.getThemeColor("errorbar.warningcolor", - warningColor); + warningColor = mode + .getThemeColor("errorbar.warningcolor", warningColor); backgroundColor = mode.getThemeColor("errorbar.backgroundcolor", backgroundColor); addListeners(); @@ -140,69 +148,73 @@ public class ErrorBar extends JPanel { // NOTE TO SELF: ErrorMarkers are calculated for the present tab only // Error Marker index in the arraylist is LOCALIZED for current tab. - - final int fheight = this.getHeight(); - SwingWorker worker = new SwingWorker() { - - protected Object doInBackground() throws Exception { - return null; - } + // Also, need to do the update in the UI thread to prevent concurrency issues. + final int fheight = this.getHeight(); + SwingWorker worker = new SwingWorker() { - protected void done() { - int bigCount = 0; - int totalLines = 0; - int currentTab = 0; - for (SketchCode sc : editor.getSketch().getCode()) { - if (sc.isExtension("pde")) { - sc.setPreprocOffset(bigCount); + protected Object doInBackground() throws Exception { + return null; + } - try { - if (editor.getSketch().getCurrentCode().equals(sc)) { - // Adding + 1 to len because \n gets appended for each - // sketchcode extracted during processPDECode() - totalLines = Base.countLines(sc.getDocument().getText( - 0, sc.getDocument().getLength())) + 1; - break; - } - } catch (Exception e) { - e.printStackTrace(); - } - } - currentTab++; - } - // System.out.println("Total lines: " + totalLines); + protected void done() { + int bigCount = 0; + int totalLines = 0; + int currentTab = 0; + for (SketchCode sc : editor.getSketch().getCode()) { + if (sc.isExtension("pde")) { + sc.setPreprocOffset(bigCount); - errorPointsOld.clear(); - for (ErrorMarker marker : errorPoints) { - errorPointsOld.add(marker); - } - errorPoints.clear(); + try { + if (editor.getSketch().getCurrentCode().equals(sc)) { + // Adding + 1 to len because \n gets appended + // for each + // sketchcode extracted during processPDECode() + totalLines = Base.countLines(sc.getDocument() + .getText(0, + sc.getDocument().getLength())) + 1; + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + currentTab++; + } + // System.out.println("Total lines: " + totalLines); - // Each problem.getSourceLine() will have an extra line added because of - // class declaration in the beginning - for (Problem problem : problems) { - if (problem.tabIndex == currentTab) { - // Ratio of error line to total lines - float y = problem.lineNumber / ((float) totalLines); - // Ratio multiplied by height of the error bar - y *= fheight - 15; // -15 is just a vertical offset - errorPoints.add(new ErrorMarker(problem, (int) y, problem - .isError() ? ErrorMarker.Error : ErrorMarker.Warning)); - // System.out.println("Y: " + y); - } - } + errorPointsOld.clear(); + for (ErrorMarker marker : errorPoints) { + errorPointsOld.add(marker); + } + errorPoints.clear(); - repaint(); - } - }; + // Each problem.getSourceLine() will have an extra line added + // because of + // class declaration in the beginning + for (Problem problem : problems) { + if (problem.tabIndex == currentTab) { + // Ratio of error line to total lines + float y = problem.lineNumber / ((float) totalLines); + // Ratio multiplied by height of the error bar + y *= fheight - 15; // -15 is just a vertical offset + errorPoints.add(new ErrorMarker(problem, (int) y, + problem.isError() ? ErrorMarker.Error + : ErrorMarker.Warning)); + // System.out.println("Y: " + y); + } + } - try { - worker.execute(); // I eat concurrency bugs for breakfast. - } catch (Exception exp) { - System.out.println("Errorbar update markers is slacking." - + exp.getMessage()); - // e.printStackTrace(); - } + repaint(); + } + }; + + try { + worker.execute(); // I eat concurrency bugs for breakfast. + } catch (Exception exp) { + System.out.println("Errorbar update markers is slacking." + + exp.getMessage()); + // e.printStackTrace(); + } } /** @@ -270,10 +282,12 @@ public class ErrorBar extends JPanel { .size(); i++) { Problem p = errorCheckerService.problemsList .get(i); - if (p.tabIndex < currentTab) + if (p.tabIndex < currentTab) { totalErrorIndex++; - if (p.tabIndex == currentTab) + } + if (p.tabIndex == currentTab) { break; + } } errorCheckerService .scrollToErrorLine(totalErrorIndex); @@ -364,7 +378,7 @@ public class ErrorBar extends JPanel { @Override public void mouseDragged(MouseEvent arg0) { - + } }); diff --git a/pdex/src/processing/mode/experimental/ErrorCheckerService.java b/pdex/src/processing/mode/experimental/ErrorCheckerService.java index 850613095..97730a271 100755 --- a/pdex/src/processing/mode/experimental/ErrorCheckerService.java +++ b/pdex/src/processing/mode/experimental/ErrorCheckerService.java @@ -52,7 +52,7 @@ public class ErrorCheckerService implements Runnable{ private boolean pauseThread = false; protected ErrorWindow errorWindow; -// protected ErrorBar errorBar; + /** * IProblem[] returned by parser stored in here */ @@ -256,15 +256,16 @@ public class ErrorCheckerService implements Runnable{ syntaxCheck(); // No syntax errors, proceed for compilation check, Stage 2. - if (problems.length == 0 && editor.compilationCheckEnabled) { //TODO: && editor.compilationCheckEnabled condition + if (problems.length == 0 && editor.compilationCheckEnabled) { sourceCode = xqpreproc.doYourThing(sourceCode, programImports); prepareCompilerClasspath(); mainClassOffset = xqpreproc.mainClassOffset; // tiny, but // significant - if (staticMode) - mainClassOffset++; // Extra line for setup() decl. -// System.out.println(sourceCode); -// System.out.println("--------------------------"); + if (staticMode) { + mainClassOffset++; // Extra line for setup() decl. + } + // System.out.println(sourceCode); + // System.out.println("--------------------------"); compileCheck(); } @@ -303,7 +304,7 @@ public class ErrorCheckerService implements Runnable{ int a[] = calculateTabIndexAndLineNumber(problems[i]); Problem p = new Problem(problems[i], a[0], a[1]); problemsList.add(p); -// System.out.println(p.toString()); + // System.out.println(p.toString()); } } @@ -329,17 +330,18 @@ public class ErrorCheckerService implements Runnable{ File f = new File("modes" + File.separator - + "java2" + + "experimental" + File.separator + "mode"); FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return (file.getName().endsWith(".jar") && !file - .getName().startsWith("XQMode")); + .getName().startsWith("experimental")); } }; File[] jarFiles = f.listFiles(fileFilter); + // System.out.println( "Jar files found? " + (jarFiles != null)); for (File jarFile : jarFiles) { classpathJars.add(jarFile.toURI().toURL()); } @@ -444,8 +446,10 @@ public class ErrorCheckerService implements Runnable{ * */ private void prepareCompilerClasspath() { - if (!loadCompClass) + if (!loadCompClass) { return; + } + // System.out.println("1.."); classpathJars = new ArrayList(); String entry = ""; @@ -648,6 +652,7 @@ public class ErrorCheckerService implements Runnable{ * Repaints the textarea if required */ public void updateTextAreaPainter() { + // TODO: Make this fucntion of some use editor.getTextArea().repaint(); currentTab = editor.getSketch().getCodeIndex( editor.getSketch().getCurrentCode()); @@ -658,9 +663,6 @@ public class ErrorCheckerService implements Runnable{ return; } -// TODO: if (errorBar.errorPointsChanged()) -// editor.getTextArea().repaint(); - } /** @@ -920,8 +922,10 @@ public class ErrorCheckerService implements Runnable{ * - index of error */ public void scrollToErrorLine(int errorIndex) { - if (editor == null) + if (editor == null) { return; + } + if (errorIndex < problemsList.size() && errorIndex >= 0) { Problem p = problemsList.get(errorIndex); try { @@ -1073,8 +1077,6 @@ public class ErrorCheckerService implements Runnable{ */ public void stopThread() { stopThread = true; -// System.out.println(editor.getSketch().getName() -// + " - Error Checker stopped."); } /** diff --git a/pdex/src/processing/mode/experimental/ImportStatement.java b/pdex/src/processing/mode/experimental/ImportStatement.java index 6e28490ef..26d2db7d1 100755 --- a/pdex/src/processing/mode/experimental/ImportStatement.java +++ b/pdex/src/processing/mode/experimental/ImportStatement.java @@ -29,23 +29,29 @@ package processing.mode.experimental; * */ public class ImportStatement { - /** - * Ex: processing.opengl.*, java.util.* - */ - String importName; - /** - * Which tab does it belong to? - */ - int tab; - - /** - * Line number(pde code) of the import - */ - int lineNumber; + /** + * Ex: processing.opengl.*, java.util.* + */ + String importName; + /** + * Which tab does it belong to? + */ + int tab; - public ImportStatement(String importName, int tab, int lineNumber) { - this.importName = importName; - this.tab = tab; - this.lineNumber = lineNumber; - } - } \ No newline at end of file + /** + * Line number(pde code) of the import + */ + int lineNumber; + + /** + * + * @param importName - Ex: processing.opengl.*, java.util.* + * @param tab - Which tab does it belong to? + * @param lineNumber - Line number(pde code) of the import + */ + public ImportStatement(String importName, int tab, int lineNumber) { + this.importName = importName; + this.tab = tab; + this.lineNumber = lineNumber; + } +} \ No newline at end of file diff --git a/pdex/src/processing/mode/experimental/Problem.java b/pdex/src/processing/mode/experimental/Problem.java index f7348b71c..6b5b95ff4 100755 --- a/pdex/src/processing/mode/experimental/Problem.java +++ b/pdex/src/processing/mode/experimental/Problem.java @@ -55,10 +55,19 @@ public class Problem { */ public String message; + /** + * The type of error - WARNING or ERROR. + */ public int type; public static final int ERROR = 1, WARNING = 2; + /** + * + * @param iProblem - The IProblem which is being wrapped + * @param tabIndex - The tab number to which the error belongs to + * @param lineNumber - Line number(pde code) of the error + */ public Problem(IProblem iProblem, int tabIndex, int lineNumber) { this.iProblem = iProblem; if(iProblem.isError()) { @@ -101,10 +110,10 @@ public class Problem { else throw new IllegalArgumentException("Illegal Problem type passed to Problem.setType(int)"); } - static Pattern pattern; - static Matcher matcher; + private static Pattern pattern; + private static Matcher matcher; - static final String tokenRegExp = "\\b token\\b"; + private static final String tokenRegExp = "\\b token\\b"; public static String process(IProblem problem) { return process(problem.getMessage()); @@ -126,21 +135,12 @@ public class Problem { matcher = pattern.matcher(message); message = matcher.replaceAll(""); - // Split camel case words into separate words. - // "VaraibleDeclaration" becomes "Variable Declaration" - // But sadly "PApplet" become "P Applet" and so on. - - // StringTokenizer st = new StringTokenizer(message); - // String newMessage = ""; - // while (st.hasMoreTokens()) { - // String word = st.nextToken(); - // newMessage += splitCamelCaseWord(word) + " "; - // } - // message = new String(newMessage); - return message; } + // Split camel case words into separate words. + // "VaraibleDeclaration" becomes "Variable Declaration" + // But sadly "PApplet" become "P Applet" and so on. public static String splitCamelCaseWord(String word) { String newWord = ""; for (int i = 1; i < word.length(); i++) { diff --git a/pdex/src/processing/mode/experimental/TextArea.java b/pdex/src/processing/mode/experimental/TextArea.java index 08a6b88e4..e8bb82991 100755 --- a/pdex/src/processing/mode/experimental/TextArea.java +++ b/pdex/src/processing/mode/experimental/TextArea.java @@ -92,6 +92,11 @@ public class TextArea extends JEditTextArea { currentLineMarker = theme.loadThemeString("currentline.marker", currentLineMarker); } + /** + * Sets ErrorCheckerService and loads theme for TextArea(XQMode) + * @param ecs + * @param mode + */ public void setECSandThemeforTextArea(ErrorCheckerService ecs, ExperimentalMode mode) { customPainter.setECSandTheme(ecs, mode); diff --git a/pdex/src/processing/mode/experimental/TextAreaPainter.java b/pdex/src/processing/mode/experimental/TextAreaPainter.java index c2c0ae48b..8c93978f2 100755 --- a/pdex/src/processing/mode/experimental/TextAreaPainter.java +++ b/pdex/src/processing/mode/experimental/TextAreaPainter.java @@ -193,7 +193,7 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter { * 0-based line number: NOTE * @param x */ - private void paintErrorLine(Graphics gfx, int line, int x) { + protected void paintErrorLine(Graphics gfx, int line, int x) { if (errorCheckerService == null) { return; @@ -306,6 +306,11 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter { return newString; } + /** + * Sets ErrorCheckerService and loads theme for TextAreaPainter(XQMode) + * @param ecs + * @param mode + */ public void setECSandTheme(ErrorCheckerService ecs, ExperimentalMode mode){ this.errorCheckerService = ecs; loadTheme(mode); diff --git a/pdex/src/processing/mode/experimental/XQErrorTable.java b/pdex/src/processing/mode/experimental/XQErrorTable.java index 9bf36afc0..e64cf2c4b 100755 --- a/pdex/src/processing/mode/experimental/XQErrorTable.java +++ b/pdex/src/processing/mode/experimental/XQErrorTable.java @@ -53,6 +53,9 @@ public class XQErrorTable extends JTable { */ private boolean columnResizing = false; + /** + * ErrorCheckerService instance + */ protected ErrorCheckerService errorCheckerService; @Override @@ -118,8 +121,9 @@ public class XQErrorTable extends JTable { synchronized public boolean updateTable(final TableModel tableModel) { // If problems list is not visible, no need to update - if (!this.isVisible()) + if (!this.isVisible()) { return false; + } SwingWorker worker = new SwingWorker() { @@ -148,8 +152,9 @@ public class XQErrorTable extends JTable { }; try { - if (!columnResizing) + if (!columnResizing) { worker.execute(); + } } catch (Exception e) { System.out.println("ErrorTable updateTable Worker's slacking." + e.getMessage()); diff --git a/pdex/src/processing/mode/experimental/XQPreprocessor.java b/pdex/src/processing/mode/experimental/XQPreprocessor.java index 9cf3e8c2f..7835c7c02 100755 --- a/pdex/src/processing/mode/experimental/XQPreprocessor.java +++ b/pdex/src/processing/mode/experimental/XQPreprocessor.java @@ -43,6 +43,7 @@ import org.eclipse.text.edits.TextEdit; import processing.app.Preferences; import processing.core.PApplet; +import processing.mode.java.preproc.PdePreprocessor; /** * My implementation of P5 preprocessor. Uses Eclipse JDT features instead of @@ -57,8 +58,16 @@ public class XQPreprocessor { private ASTRewrite rewrite = null; public int mainClassOffset = 0; - ArrayList imports; - ArrayList extraImports; + private ArrayList imports; + private ArrayList extraImports; + + private String[] coreImports, defaultImports; + + public XQPreprocessor() { + PdePreprocessor p = new PdePreprocessor(null); + defaultImports = p.getDefaultImports(); + coreImports = p.getCoreImports(); + } /** * The main method that performs preprocessing. Converts code into compilable java. @@ -104,8 +113,9 @@ public class XQPreprocessor { int position = doc.get().indexOf("{") + 1; int lines = 0; for (int i = 0; i < position; i++) { - if (doc.get().charAt(i) == '\n') + if (doc.get().charAt(i) == '\n') { lines++; + } } lines += 2; // System.out.println("Lines: " + lines); @@ -117,7 +127,7 @@ public class XQPreprocessor { /** * Returns all import statements as lines of code * - * @return String - All import statements combined + * @return String - All import statements combined. Each import in a separate line. */ public String prepareImports() { imports = new ArrayList(); @@ -125,11 +135,11 @@ public class XQPreprocessor { imports.add(new String(extraImports.get(i).importName)); } imports.add(new String("// Default Imports")); - for (int i = 0; i < getCoreImports().length; i++) { - imports.add(new String("import " + getCoreImports()[i] + ";")); + for (int i = 0; i < coreImports.length; i++) { + imports.add(new String("import " + coreImports[i] + ";")); } - for (int i = 0; i < getDefaultImports().length; i++) { - imports.add(new String("import " + getDefaultImports()[i] + ";")); + for (int i = 0; i < defaultImports.length; i++) { + imports.add(new String("import " + defaultImports[i] + ";")); } String totalImports = ""; for (int i = 0; i < imports.size(); i++) { @@ -139,17 +149,6 @@ public class XQPreprocessor { return totalImports; } - public String[] getCoreImports() { - return new String[] { "processing.core.*", "processing.data.*", - "processing.opengl.*" }; - } - - public String[] getDefaultImports() { - // These may change in-between (if the prefs panel adds this option) - String prefsLine = Preferences.get("preproc.imports.list"); - return PApplet.splitTokens(prefsLine, ", "); - } - /** * Visitor implementation that does all the substitution dirty work.
*
  • Any function not specified as being protected or private will be made