org.fife.rtext.plugins.tasks.TaskWindow Maven / Gradle / Ivy
Show all versions of rtext Show documentation
/* * 10/17/2009 * * TaskWindow.java - A dockable window that lists tasks (todo's, fixme's, etc.) * in open files. * Copyright (C) 2009 Robert Futrell * robert_futrell at users.sourceforge.net * http://rtext.fifesoft.com * * This file is a part of RText. * * RText is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * RText is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.fife.rtext.plugins.tasks; import java.awt.BorderLayout; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.net.URL; import java.util.Iterator; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JTable; import org.fife.rtext.AbstractMainView; import org.fife.rtext.AbstractParserNoticeWindow; import org.fife.rtext.RText; import org.fife.rtext.RTextEditorPane; import org.fife.ui.RScrollPane; import org.fife.ui.dockablewindows.DockableWindowScrollPane; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.parser.Parser; import org.fife.ui.rsyntaxtextarea.parser.ParserNotice; import org.fife.ui.rsyntaxtextarea.parser.TaskTagParser; /** * A window that displays text flagged in source code comments that have * been designated as "tasks." Tasks are identified by configurable * identifiers, such as "
' * character. * @return Whether the task pattern was actually modified. This will be *FIXME
", "TODO
" and * "HACK
".* * Parsing for tasks is only done if the tasks window is visible. * * @author Robert Futrell * @version 1.0 */ class TaskWindow extends AbstractParserNoticeWindow implements PropertyChangeListener { private JTable table; private TaskNoticeTableModel model; private TaskTagParser taskParser; private boolean installed; public TaskWindow(RText rtext, String taskIdentifiers) { super(rtext); installed = false; model = new TaskNoticeTableModel(rtext.getString("TaskList.Task")); table = createTable(model); RScrollPane sp = new DockableWindowScrollPane(table); setLayout(new BorderLayout()); add(sp); // active and position are set by caller, from TasksPrefs setDockableWindowName(rtext.getString("TaskList.Tasks")); URL url = getClass().getResource("page_white_edit.png"); setIcon(new ImageIcon(url)); taskParser = new TaskTagParser(); setTaskIdentifiers(taskIdentifiers); applyComponentOrientation(rtext.getComponentOrientation()); } /** * Adds listeners to start parsing a text area for tasks. * * @param textArea The text area to start parsing for tasks. * @see #removeTaskParser(RTextEditorPane) */ private void addTaskParser(RTextEditorPane textArea) { textArea.addPropertyChangeListener( RSyntaxTextArea.PARSER_NOTICES_PROPERTY, this); textArea.addParser(taskParser); } /** * Returns the identifiers scanned for to identify "tasks" (e.g. * "
TODO
", "FIXME
", "IDEA
", etc.). * * @return The identifiers. This will always return a value, even it task * parsing is disabled. If there are no identifiers, an empty * string is returned. * @see #setTaskIdentifiers(String) */ public String getTaskIdentifiers() { String pattern = taskParser.getTaskPattern(); if (pattern!=null) { pattern = pattern.replaceAll("\\\\\\?", "?"); } else { pattern = ""; } return pattern; } /** * @see #uninstallParser() */ private void installParser() { if (!installed) { RText rtext = getRText(); AbstractMainView mainView = rtext.getMainView(); mainView.addPropertyChangeListener(AbstractMainView.TEXT_AREA_ADDED_PROPERTY, this); mainView.addPropertyChangeListener(AbstractMainView.TEXT_AREA_REMOVED_PROPERTY, this); for (int i=0; i| false
ifidentifiers
is the same as * the current value. * @see #getTaskIdentifiers() */ public boolean setTaskIdentifiers(String identifiers) { if (!identifiers.equals(getTaskIdentifiers())) { identifiers = identifiers.replaceAll("\\?", "\\\\\\?"); taskParser.setTaskPattern(identifiers); return true; } return false; } /** * @see #installParser() */ private void uninstallParser() { if (installed) { RText rtext = getRText(); AbstractMainView mainView = rtext.getMainView(); mainView.removePropertyChangeListener(AbstractMainView.TEXT_AREA_ADDED_PROPERTY, this); mainView.removePropertyChangeListener(AbstractMainView.TEXT_AREA_REMOVED_PROPERTY, this); for (int i=0; i