1 31 32 package org.antlr.works.menu; 33 34 import org.antlr.works.ate.syntax.misc.ATELine; 35 import org.antlr.works.ate.syntax.misc.ATEToken; 36 import org.antlr.works.components.grammar.CEditorGrammar; 37 import org.antlr.works.stats.StatisticsAW; 38 import org.antlr.works.syntax.element.ElementReference; 39 40 import javax.swing.*; 41 import java.util.Set ; 42 43 public class MenuGoTo extends MenuAbstract { 44 45 public MenuGoTo(CEditorGrammar editor) { 46 super(editor); 47 } 48 49 public void goToRule() { 50 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_RULE); 51 editor.goToRule.display(); 52 } 53 54 public void goToDeclaration() { 55 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_DECLARATION); 56 57 ElementReference ref = editor.getCurrentReference(); 58 if(ref == null) return; 59 60 for(ATEToken decl : editor.parserEngine.getDecls()) { 61 if(decl.getAttribute().equals(ref.token.getAttribute())) { 62 editor.goToHistoryRememberCurrentPosition(); 63 setCaretPosition(decl.start); 64 break; 65 } 66 } 67 } 68 69 public void goToBreakpoint(int direction) { 70 if(direction == -1) 71 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_PREV_BRKPT); 72 else 73 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_NEXT_BRKPT); 74 75 Set <Integer > breakpoints = editor.breakpointManager.getBreakpoints(); 76 int line = editor.getTextEditor().getLineIndexAtTextPosition(getCaretPosition()); 77 if(line == -1) return; 78 79 while(true) { 80 line += direction; 81 if(line < 0 || line > editor.parserEngine.getMaxLines()-1) 82 break; 83 84 if(breakpoints.contains(Integer.valueOf(line))) { 85 moveCursorToLine(line); 86 break; 87 } 88 } 89 } 90 91 public void goToLine() { 92 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_LINE); 93 String s = (String )JOptionPane.showInputDialog(editor.getJavaContainer(), "Line number:", "Go To Line", 94 JOptionPane.QUESTION_MESSAGE, null, null, null); 95 if(s != null) { 96 moveCursorToLine(Integer.parseInt(s)-1); 97 } 98 } 99 100 public void goToCharacter() { 101 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_CHAR); 102 String s = (String )JOptionPane.showInputDialog(editor.getJavaContainer(), "Character number:", "Go To Character", 103 JOptionPane.QUESTION_MESSAGE, null, null, null); 104 if(s != null) { 105 int character = Integer.parseInt(s); 106 if(character < 0 || character > getTextPane().getDocument().getLength()-1) 107 return; 108 109 editor.goToHistoryRememberCurrentPosition(); 110 111 setCaretPosition(character); 112 } 113 } 114 115 public void goToBackward() { 116 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_BACK); 117 118 if(editor.goToHistory.canGoBack()) { 119 setCaretPosition(editor.goToHistory.getBackPosition(getCaretPosition())); 120 editor.refreshMainMenuBar(); 121 } 122 } 123 124 public void goToForward() { 125 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_GOTO_FORWARD); 126 127 if(editor.goToHistory.canGoForward()) { 128 setCaretPosition(editor.goToHistory.getForwardPosition()); 129 editor.refreshMainMenuBar(); 130 } 131 } 132 133 public void moveCursorToLine(int lineIndex) { 134 if(lineIndex < 0 || lineIndex > editor.getLines().size()-1) 135 return; 136 137 ATELine line = editor.getLines().get(lineIndex); 138 editor.goToHistoryRememberCurrentPosition(); 139 setCaretPosition(line.position); 140 } 141 142 } 143 | Popular Tags |