org.fife.rtext.plugins.tasks.TasksOptionPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rtext Show documentation
Show all versions of rtext Show documentation
RText is a powerful, cross-platform programmer's text editor written in Java. It is designed
to be easy to use, highly customizable and flexible. Part of RText's design is for the source code
to be simple, easy to understand, and well documented, so that other programmers can look into its
inner-workings and figure out how RText ticks with ease. A good place to start (besides the source
code) is the Javadoc for all classes used in the project.
/* * 02/06/2010 * * TasksOptionPanel.java - Option panel for the Tasks plugin. * Copyright (C) 2010 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.awt.ComponentOrientation; import java.awt.Frame; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ResourceBundle; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.table.DefaultTableModel; import javax.swing.text.PlainDocument; import org.fife.rtext.RText; import org.fife.ui.EscapableDialog; import org.fife.ui.PickyDocumentFilter; import org.fife.ui.RButton; import org.fife.ui.ResizableFrameContentPane; import org.fife.ui.SelectableLabel; import org.fife.ui.UIUtil; import org.fife.ui.app.PluginOptionsDialogPanel; import org.fife.ui.modifiabletable.ModifiableTable; import org.fife.ui.modifiabletable.ModifiableTableChangeEvent; import org.fife.ui.modifiabletable.ModifiableTableListener; import org.fife.ui.modifiabletable.RowHandler; /** * Options panel used to specify tasks options. * * @author Robert Futrell * @version 1.0 */ class TasksOptionPanel extends PluginOptionsDialogPanel implements ActionListener, ItemListener, ModifiableTableListener { private TasksPlugin plugin; private JCheckBox visibleCB; private JComboBox locationCombo; private DefaultTableModel model; private ModifiableTable table; private static final String PROPERTY = "Property"; /** * Constructor. * * @param rtext The parent application. * @param plugin The tasks plugin. */ public TasksOptionPanel(RText rtext, TasksPlugin plugin) { super(plugin.getPluginName(), plugin); ResourceBundle gpb = ResourceBundle.getBundle( "org.fife.ui.app.GUIPlugin"); setIcon(plugin.getPluginIcon()); this.plugin = plugin; ComponentOrientation o = ComponentOrientation.getOrientation(getLocale()); setLayout(new BorderLayout()); setBorder(UIUtil.getEmpty5Border()); // A panel to contain everything that will go into our "top" area. Box topPanel = Box.createVerticalBox(); topPanel.setBorder(new OptionPanelBorder( plugin.getString("Options.TaskWindow"))); // A check box toggling the plugin's visibility. JPanel temp = new JPanel(new BorderLayout()); visibleCB = new JCheckBox(gpb.getString("Visible")); visibleCB.addActionListener(this); temp.add(visibleCB, BorderLayout.LINE_START); topPanel.add(temp); topPanel.add(Box.createVerticalStrut(10)); // A combo in which to select the dockable window's placement. JPanel locationPanel = new JPanel(); locationPanel.setLayout(new BoxLayout(locationPanel, BoxLayout.LINE_AXIS)); locationCombo = new JComboBox(); UIUtil.fixComboOrientation(locationCombo); locationCombo.addItem(gpb.getString("Location.top")); locationCombo.addItem(gpb.getString("Location.left")); locationCombo.addItem(gpb.getString("Location.bottom")); locationCombo.addItem(gpb.getString("Location.right")); locationCombo.addItem(gpb.getString("Location.floating")); locationCombo.addItemListener(this); JLabel locLabel = new JLabel(gpb.getString("Location.title")); locLabel.setLabelFor(locationCombo); locationPanel.add(locLabel); locationPanel.add(Box.createHorizontalStrut(5)); locationPanel.add(locationCombo); locationPanel.add(Box.createHorizontalGlue()); topPanel.add(locationPanel); topPanel.add(Box.createVerticalStrut(5)); add(topPanel, BorderLayout.NORTH); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setBorder(new OptionPanelBorder( plugin.getString("Options.TaskIdentifiers"))); add(contentPane); model = new DefaultTableModel(0, 1); table = new ModifiableTable(model); table.addModifiableTableListener(this); table.getTable().setTableHeader(null); table.setRowHandler(new IdRowHandler()); contentPane.add(table); RButton defaultsButton = new RButton( plugin.getString("Options.RestoreDefaults")); defaultsButton.setActionCommand("RestoreDefaults"); defaultsButton.addActionListener(this); temp = new JPanel(new BorderLayout()); temp.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); temp.add(defaultsButton, BorderLayout.LINE_START); add(temp, BorderLayout.SOUTH); applyComponentOrientation(o); } /** * Called when an event occurs in this panel. * * @param e The event. */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (visibleCB==e.getSource()) { hasUnsavedChanges = true; firePropertyChange(PROPERTY, null, null); } else if ("RestoreDefaults".equals(command)) { String taskIds = plugin.getTaskIdentifiers(); if (!visibleCB.isSelected() || locationCombo.getSelectedIndex()!=2 || !taskIds.equals(TasksPrefs.DEFAULT_TASK_IDS)) { visibleCB.setSelected(true); locationCombo.setSelectedIndex(2); setDisplayedTaskIds(TasksPrefs.DEFAULT_TASK_IDS); hasUnsavedChanges = true; firePropertyChange(PROPERTY, null, null); } } } /** * {@inheritDoc} */ protected void doApplyImpl(Frame owner) { plugin.setTaskWindowVisible(visibleCB.isSelected()); plugin.setTaskWindowPosition(locationCombo.getSelectedIndex()); StringBuffer sb = new StringBuffer(); for (int i=0; i
. */ private void setDisplayedTaskIds(String identifiers) { model.setRowCount(0); if (identifiers!=null && identifiers.length()>0) { String[] ids = identifiers.split("\\|"); for (int i=0; inull