diff options
author | aclement <aclement> | 2011-08-12 17:40:35 +0000 |
---|---|---|
committer | aclement <aclement> | 2011-08-12 17:40:35 +0000 |
commit | c6dbe6d1c446b40fc063e0587f0f3c2e7ac34237 (patch) | |
tree | 5c644cfba4e67b450108189b0cb5d998767a56ef | |
parent | 22b6f012cb3c2b03b77d043a6234583bf2a417a2 (diff) | |
download | aspectj-c6dbe6d1c446b40fc063e0587f0f3c2e7ac34237.tar.gz aspectj-c6dbe6d1c446b40fc063e0587f0f3c2e7ac34237.zip |
generics refactoring
-rw-r--r-- | ajbrowser/src/org/aspectj/tools/ajbrowser/ui/EditorManager.java | 267 |
1 files changed, 133 insertions, 134 deletions
diff --git a/ajbrowser/src/org/aspectj/tools/ajbrowser/ui/EditorManager.java b/ajbrowser/src/org/aspectj/tools/ajbrowser/ui/EditorManager.java index 682a5e95d..8a717a860 100644 --- a/ajbrowser/src/org/aspectj/tools/ajbrowser/ui/EditorManager.java +++ b/ajbrowser/src/org/aspectj/tools/ajbrowser/ui/EditorManager.java @@ -11,158 +11,157 @@ * Xerox/PARC initial implementation * ******************************************************************/ - package org.aspectj.tools.ajbrowser.ui; import java.awt.BorderLayout; import java.awt.event.KeyEvent; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Vector; -import javax.swing.*; +import javax.swing.Box; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; -import org.aspectj.ajde.*; +import org.aspectj.ajde.EditorAdapter; +import org.aspectj.ajde.EditorListener; import org.aspectj.bridge.ISourceLocation; import org.aspectj.tools.ajbrowser.core.BrowserErrorHandler; /** * Responsible for controlling the editor. - * - * @todo remove coupling to <CODE>BasicEditor</CODE> - * @author Mik Kersten + * + * @todo remove coupling to <CODE>BasicEditor</CODE> + * @author Mik Kersten */ public class EditorManager { - /** @return true if input modifiers have shift down */ - public static boolean isShiftDown(int modifiers) { - return (0 != (modifiers & KeyEvent.SHIFT_MASK)); - } - - private EditorAdapter editor = null; - private BasicEditor basicEditor = null; - private ArrayList editorListeners = new ArrayList(); - private Vector editors = new Vector(); - private JPanel editor_panel = null; - private Box editors_box = Box.createVerticalBox(); - - public EditorManager(EditorAdapter ajdeEditor) { - if (ajdeEditor instanceof BasicEditor) { - this.basicEditor = (BasicEditor)ajdeEditor; - editors.add(basicEditor); - editors_box.add(basicEditor.getPanel()); - editor_panel = new JPanel(new BorderLayout()); - editor_panel.add(editors_box, BorderLayout.CENTER); - } else { - editors.add(ajdeEditor); - this.editor = ajdeEditor; - } - } - - public void addListener(EditorListener editorListener) { - editorListeners.add(editorListener); - } - - public void removeListener(EditorListener editorListener) { - editorListeners.remove(editorListener); - } - - public void notifyCurrentFileChanged(String filePath) { - for (Iterator it = editorListeners.iterator(); it.hasNext(); ) { - ((EditorListener)it.next()).currentFileChanged(filePath); - } - } - - public void addViewForSourceLine(final String filePath, final int lineNumber) { - if (basicEditor == null) return; - editors_box.remove(basicEditor.getPanel()); - final BasicEditor newEditor = new BasicEditor(); - editors.add(newEditor); - - Runnable update = new Runnable() { - public void run() { - editors_box.add(newEditor.getPanel()); - newEditor.showSourceLine(filePath, lineNumber, true); - //AjdeUIManager.getDefault().getIdeUIAdapter().resetGUI(); - } - }; - - if (SwingUtilities.isEventDispatchThread()) { - update.run(); - } else { - try { - SwingUtilities.invokeAndWait(update); - } catch (Exception e) { - BrowserErrorHandler.handleError("Could not add view for source line.", e); - } - } - } - - public String getCurrFile() { - if (basicEditor != null) { - return basicEditor.getCurrFile(); - } else { - return editor.getCurrFile(); - } - } - - + /** @return true if input modifiers have shift down */ + public static boolean isShiftDown(int modifiers) { + return (0 != (modifiers & KeyEvent.SHIFT_MASK)); + } + + private EditorAdapter editor = null; + private BasicEditor basicEditor = null; + private ArrayList<EditorListener> editorListeners = new ArrayList<EditorListener>(); + private Vector<EditorAdapter> editors = new Vector<EditorAdapter>(); + private JPanel editor_panel = null; + private Box editors_box = Box.createVerticalBox(); + + public EditorManager(EditorAdapter ajdeEditor) { + if (ajdeEditor instanceof BasicEditor) { + this.basicEditor = (BasicEditor) ajdeEditor; + editors.add(basicEditor); + editors_box.add(basicEditor.getPanel()); + editor_panel = new JPanel(new BorderLayout()); + editor_panel.add(editors_box, BorderLayout.CENTER); + } else { + editors.add(ajdeEditor); + this.editor = ajdeEditor; + } + } + + public void addListener(EditorListener editorListener) { + editorListeners.add(editorListener); + } + + public void removeListener(EditorListener editorListener) { + editorListeners.remove(editorListener); + } + + public void notifyCurrentFileChanged(String filePath) { + for (Iterator it = editorListeners.iterator(); it.hasNext();) { + ((EditorListener) it.next()).currentFileChanged(filePath); + } + } + + public void addViewForSourceLine(final String filePath, final int lineNumber) { + if (basicEditor == null) + return; + editors_box.remove(basicEditor.getPanel()); + final BasicEditor newEditor = new BasicEditor(); + editors.add(newEditor); + + Runnable update = new Runnable() { + public void run() { + editors_box.add(newEditor.getPanel()); + newEditor.showSourceLine(filePath, lineNumber, true); + // AjdeUIManager.getDefault().getIdeUIAdapter().resetGUI(); + } + }; + + if (SwingUtilities.isEventDispatchThread()) { + update.run(); + } else { + try { + SwingUtilities.invokeAndWait(update); + } catch (Exception e) { + BrowserErrorHandler.handleError("Could not add view for source line.", e); + } + } + } + + public String getCurrFile() { + if (basicEditor != null) { + return basicEditor.getCurrFile(); + } else { + return editor.getCurrFile(); + } + } + public void showSourceLine(ISourceLocation sourceLocation, boolean highlight) { if (sourceLocation != null) { - showSourceLine( - sourceLocation.getSourceFile().getAbsolutePath(), - sourceLocation.getLine(), - highlight); - } + showSourceLine(sourceLocation.getSourceFile().getAbsolutePath(), sourceLocation.getLine(), highlight); + } } - /** - * @todo remove "instanceof AjdeManager" hack - */ - public void showSourceLine(String filePath, int lineNumber, boolean highlight) { - if (editors.size() > 1) { - editors_box.removeAll(); - editors_box.add(basicEditor.getPanel()); - //AjdeUIManager.getDefault().getIdeUIAdapter().resetGUI(); - editors.removeAllElements(); - editors.add(basicEditor); - } - - if (basicEditor != null) { - basicEditor.showSourceLine(filePath, lineNumber, highlight); - } else { - editor.showSourceLine(filePath, lineNumber, highlight); - } - } - - public void pasteToCaretPos(String text) { - if (basicEditor != null) { - basicEditor.pasteToCaretPos(text); - } else { - editor.pasteToCaretPos(text); - } - } - - public void showSourcelineAnnotation(String filePath, int lineNumber, java.util.List items) { - editor.showSourcelineAnnotation(filePath, lineNumber, items); - } - - public void saveContents() { - try { - for (Iterator it = editors.iterator(); it.hasNext(); ) { - ((EditorAdapter)it.next()).saveContents(); - } - } catch (IOException ioe) { - BrowserErrorHandler.handleError("Editor could not save the current file.", ioe); - } - } - - public JPanel getEditorPanel() { - if (editor_panel != null) { - return editor_panel; - } else { - return basicEditor.getPanel(); - } - } -} + /** + * @todo remove "instanceof AjdeManager" hack + */ + public void showSourceLine(String filePath, int lineNumber, boolean highlight) { + if (editors.size() > 1) { + editors_box.removeAll(); + editors_box.add(basicEditor.getPanel()); + // AjdeUIManager.getDefault().getIdeUIAdapter().resetGUI(); + editors.removeAllElements(); + editors.add(basicEditor); + } + + if (basicEditor != null) { + basicEditor.showSourceLine(filePath, lineNumber, highlight); + } else { + editor.showSourceLine(filePath, lineNumber, highlight); + } + } + + public void pasteToCaretPos(String text) { + if (basicEditor != null) { + basicEditor.pasteToCaretPos(text); + } else { + editor.pasteToCaretPos(text); + } + } + + public void showSourcelineAnnotation(String filePath, int lineNumber, java.util.List items) { + editor.showSourcelineAnnotation(filePath, lineNumber, items); + } + public void saveContents() { + try { + for (Iterator it = editors.iterator(); it.hasNext();) { + ((EditorAdapter) it.next()).saveContents(); + } + } catch (IOException ioe) { + BrowserErrorHandler.handleError("Editor could not save the current file.", ioe); + } + } + public JPanel getEditorPanel() { + if (editor_panel != null) { + return editor_panel; + } else { + return basicEditor.getPanel(); + } + } +} |