From: <iam...@us...> - 2010-03-15 10:52:42
|
Revision: 1303 http://eulergui.svn.sourceforge.net/eulergui/?rev=1303&view=rev Author: iamlolive Date: 2010-03-15 10:52:28 +0000 (Mon, 15 Mar 2010) Log Message: ----------- TextEditor now maps some features from jEdit: caret positioning , tooltip over text. This last feature is not tied to any useful feature at the moment (i.e the tooltip is "toto", but the next step is to add a contextual tooltip). Modified Paths: -------------- trunk/eulergui/src/main/java/eulergui/gui/view/TextEditor.java Modified: trunk/eulergui/src/main/java/eulergui/gui/view/TextEditor.java =================================================================== --- trunk/eulergui/src/main/java/eulergui/gui/view/TextEditor.java 2010-03-14 16:22:16 UTC (rev 1302) +++ trunk/eulergui/src/main/java/eulergui/gui/view/TextEditor.java 2010-03-15 10:52:28 UTC (rev 1303) @@ -1,7 +1,7 @@ package eulergui.gui.view; -import java.awt.HeadlessException; -import java.awt.Window; +import java.awt.*; +import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; @@ -28,6 +28,7 @@ import org.syntax.jedit.JEditTextArea; import org.syntax.jedit.SyntaxDocument; +import org.syntax.jedit.TextAreaPainter; import org.syntax.jedit.tokenmarker.ShellScriptTokenMarker; import org.syntax.jedit.tokenmarker.TokenMarker; import org.syntax.jedit.tokenmarker.XMLTokenMarker; @@ -111,6 +112,56 @@ return jedit; } + public void setCaretPosition(int line, int col){ + if(line>=1) + line--; + if(col>=1) + col--; + + int position = jedit.getLineStartOffset(line) + col; + //TODO the parser erroneously places the end of line errors. They are placed at the beginning of the next line. We correct that behaviour (on purpose?) + if(col==0) + position--; + setCaretPosition(position); + } + + private void setCaretPosition(int position) { + jedit.setCaretVisible(true); + jedit.setCaretPosition(position); + jedit.scrollToCaret(); + } + + + public int getCaretPosition(){ + return jedit.getCaretPosition(); + } + + public void setToolTipText(String text){ + jedit.getPainter().addCustomHighlight(new TextAreaPainter.Highlight(){ + + @Override + public void init(JEditTextArea textArea, TextAreaPainter.Highlight next) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void paintHighlight(Graphics gfx, int line, int y) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String getToolTipText(MouseEvent evt) { + return "toto"; //To change body of implemented methods use File | Settings | File Templates. + } + }); + } + + public String getToolTipText(){ + return jedit.getToolTipText(); + } + + + /** display Editor in a new Window, with save As in File menu */ public void displayEditor( ProjectGUI projectGUI, String toOpen ) { JFrame jf = new JFrame( ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |