From: <k_s...@us...> - 2008-09-27 12:20:43
|
Revision: 13814 http://jedit.svn.sourceforge.net/jedit/?rev=13814&view=rev Author: k_satoda Date: 2008-09-27 12:20:40 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Made addHighlightTo() and removeHighlightFrom() of BackgroundHighlight usable without internal knowledge. Modified Paths: -------------- plugins/Background/trunk/background/BackgroundHighlight.java plugins/Background/trunk/background/BackgroundPlugin.java Modified: plugins/Background/trunk/background/BackgroundHighlight.java =================================================================== --- plugins/Background/trunk/background/BackgroundHighlight.java 2008-09-27 11:42:01 UTC (rev 13813) +++ plugins/Background/trunk/background/BackgroundHighlight.java 2008-09-27 12:20:40 UTC (rev 13814) @@ -194,14 +194,21 @@ public static TextAreaExtension addHighlightTo(EditPane editPane) { - TextAreaExtension textAreaHighlight = new BackgroundHighlight(editPane.getTextArea()); - highlights.put(editPane, textAreaHighlight); - return textAreaHighlight; + JEditTextArea textArea = editPane.getTextArea(); + TextAreaPainter painter = textArea.getPainter(); + BackgroundHighlight highlight = new BackgroundHighlight(textArea); + painter.addExtension(TextAreaPainter.BACKGROUND_LAYER, highlight); + highlights.put(editPane, highlight); + return highlight; } public static void removeHighlightFrom(EditPane editPane) { - highlights.remove(editPane); + BackgroundHighlight highlight = (BackgroundHighlight) highlights.remove(editPane); + + if (highlight == null) { return; } + + editPane.getTextArea().getPainter().removeExtension(highlight); } Modified: plugins/Background/trunk/background/BackgroundPlugin.java =================================================================== --- plugins/Background/trunk/background/BackgroundPlugin.java 2008-09-27 11:42:01 UTC (rev 13813) +++ plugins/Background/trunk/background/BackgroundPlugin.java 2008-09-27 12:20:40 UTC (rev 13814) @@ -23,7 +23,6 @@ import org.gjt.sp.jedit.*; import org.gjt.sp.jedit.msg.EditPaneUpdate; import org.gjt.sp.jedit.msg.PropertiesChanged; -import org.gjt.sp.jedit.textarea.TextAreaPainter; public class BackgroundPlugin extends EBPlugin @@ -33,7 +32,7 @@ while (view != null) { EditPane[] panes = view.getEditPanes(); for (int i = 0; i < panes.length; i++) - initEditPane(panes[i]); + BackgroundHighlight.addHighlightTo(panes[i]); view = view.getNext(); } } @@ -43,7 +42,7 @@ while (view != null) { EditPane[] panes = view.getEditPanes(); for (int i = 0; i < panes.length; i++) - uninitEditPane(panes[i]); + BackgroundHighlight.removeHighlightFrom(panes[i]); view = view.getNext(); } } @@ -54,32 +53,13 @@ EditPane editPane = epu.getEditPane(); if (epu.getWhat() == EditPaneUpdate.CREATED) { - initEditPane(editPane); + BackgroundHighlight.addHighlightTo(editPane); } else if (epu.getWhat() == EditPaneUpdate.DESTROYED) { - uninitEditPane(editPane); + BackgroundHighlight.removeHighlightFrom(editPane); } } else if (message instanceof PropertiesChanged) { BackgroundHighlight.propertiesChanged(); } } - - private static void initEditPane(EditPane editPane) { - TextAreaPainter textAreaPainter = editPane.getTextArea().getPainter(); - - BackgroundHighlight backgroundHighlight = - (BackgroundHighlight) BackgroundHighlight.addHighlightTo(editPane); - - textAreaPainter.addExtension(TextAreaPainter.BACKGROUND_LAYER, backgroundHighlight); - } - - private static void uninitEditPane(EditPane editPane) { - TextAreaPainter textAreaPainter = editPane.getTextArea().getPainter(); - - BackgroundHighlight backgroundHighlight = - BackgroundHighlight.getHighlightFor(editPane); - - textAreaPainter.removeExtension(backgroundHighlight); - BackgroundHighlight.removeHighlightFrom(editPane); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |