From f6e3f24f908566d56cbbe2d3efeb270cd4666533 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 8 Jan 2005 05:15:35 +0000 Subject: [PATCH] some refactoring --- factor/jedit/FactorPlugin.props | 7 ++- .../{WordPopup.java => TextAreaPopup.java} | 59 +++++++------------ 2 files changed, 28 insertions(+), 38 deletions(-) rename factor/jedit/{WordPopup.java => TextAreaPopup.java} (82%) diff --git a/factor/jedit/FactorPlugin.props b/factor/jedit/FactorPlugin.props index ed79bed93b..0f35839ae2 100644 --- a/factor/jedit/FactorPlugin.props +++ b/factor/jedit/FactorPlugin.props @@ -29,6 +29,9 @@ plugin.factor.jedit.FactorPlugin.menu=factor-listener \ - \ factor-extract-word \ - \ + factor-infer-effect \ + factor-compile \ + - \ factor-infer-effects \ - \ factor-restart @@ -43,7 +46,9 @@ factor-edit.label=Edit word at caret factor-edit-dialog.label=Edit word... factor-usages.label=Word usages at caret factor-extract-word.label=Extract word... -factor-infer-effects.label=Infer word stack effects... +factor-infer-effect.label=Infer word stack effect +factor-compile.label=Compile word at caret +factor-infer-effects.label=Infer word stack effects factor-restart.label=Restart Factor # SideKick stuff diff --git a/factor/jedit/WordPopup.java b/factor/jedit/TextAreaPopup.java similarity index 82% rename from factor/jedit/WordPopup.java rename to factor/jedit/TextAreaPopup.java index 7540359181..94e3e3ad2f 100644 --- a/factor/jedit/WordPopup.java +++ b/factor/jedit/TextAreaPopup.java @@ -38,48 +38,16 @@ import org.gjt.sp.jedit.textarea.JEditTextArea; import org.gjt.sp.jedit.*; import org.gjt.sp.util.Log; -public class WordPopup extends JWindow +public class TextAreaPopup extends JWindow { private View view; private JTextArea preview; - //{{{ showWordPopup() method - public static void showWordPopup(JEditTextArea textArea) + //{{{ TextAreaPopup constructor + public TextAreaPopup(JEditTextArea textArea, String text) { - View view = GUIUtilities.getView(textArea); - String def; - - try - { - def = FactorPlugin.evalInWire( - FactorPlugin.factorWord(view) - + " see").trim(); - } - catch(IOException io) - { - def = io.toString(); - Log.log(Log.ERROR,WordPopup.class,io); - } - - WordPopup popup = new WordPopup(view,def); - - int line = textArea.getCaretLine(); - String lineText = textArea.getLineText(line); - int caret = textArea.getCaretPosition() - - textArea.getLineStartOffset(line); - int start = FactorPlugin.getWordStartOffset(lineText,caret); - Point loc = textArea.offsetToXY(line,start); - loc.y += textArea.getPainter().getFontMetrics().getHeight(); - SwingUtilities.convertPointToScreen(loc,textArea.getPainter()); - popup.setLocation(loc); - popup.show(); - } //}}} - - //{{{ WordPopup constructor - public WordPopup(View view, String text) - { - super(view); - this.view = view; + super(GUIUtilities.getView(textArea)); + this.view = GUIUtilities.getView(textArea); preview = new JTextArea(text); preview.setEditable(false); getContentPane().add(BorderLayout.CENTER,new JScrollPane(preview)); @@ -91,6 +59,23 @@ public class WordPopup extends JWindow view.setKeyEventInterceptor(keyHandler); GUIUtilities.requestFocus(this,preview); + + positionAtCaret(textArea); + setVisible(true); + } //}}} + + //{{{ positionAtCaret() method + private void positionAtCaret(JEditTextArea textArea) + { + int line = textArea.getCaretLine(); + String lineText = textArea.getLineText(line); + int caret = textArea.getCaretPosition() + - textArea.getLineStartOffset(line); + int start = FactorPlugin.getWordStartOffset(lineText,caret); + Point loc = textArea.offsetToXY(line,start); + loc.y += textArea.getPainter().getFontMetrics().getHeight(); + SwingUtilities.convertPointToScreen(loc,textArea.getPainter()); + setLocation(loc); } //}}} //{{{ KeyHandler class