PageRenderTime 52ms CodeModel.GetById 44ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/xml/indent/PreserveWhitespaceOptionsPane.java

#
Java | 119 lines | 79 code | 21 blank | 19 comment | 12 complexity | 3c50c8af7da15d970e262a9400b5e293 MD5 | raw file
  1/*
  2 * PreserveWhitespaceOptionsPane.java
  3 *
  4 * Copyright (c) 2003 Robert McKinnon
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License
  8 * as published by the Free Software Foundation; either version 2
  9 * of the License, or any later version.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License
 17 * along with this program; if not, write to the Free Software
 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 19 */
 20package xml.indent;
 21
 22import javax.swing.border.EmptyBorder;
 23import javax.swing.event.*;
 24import javax.swing.*;
 25import java.awt.event.*;
 26import java.awt.*;
 27
 28import org.gjt.sp.jedit.gui.*;
 29import org.gjt.sp.jedit.*;
 30
 31public class PreserveWhitespaceOptionsPane extends AbstractOptionPane {
 32
 33  private JList elementList;
 34  private DefaultListModel elementListModel;
 35  private JButton add;
 36  private JButton remove;
 37
 38  public PreserveWhitespaceOptionsPane() {
 39    super("xmlindenter");
 40  }
 41
 42  protected void _init() {
 43    setLayout(new BorderLayout());
 44
 45    JLabel label = new JLabel(jEdit.getProperty("options.xmlindenter.caption"));
 46    label.setBorder(new EmptyBorder(0, 0, 6, 0));
 47    add(BorderLayout.NORTH, label);
 48
 49    elementListModel = new DefaultListModel();
 50    int i = 0;
 51    String element;
 52    while((element = jEdit.getProperty("xmlindenter.preserve-whitespace-element." + i)) != null) {
 53      elementListModel.addElement(element);
 54      i++;
 55    }
 56
 57    elementList = new JList(elementListModel);
 58    add(BorderLayout.CENTER, new JScrollPane(elementList));
 59    elementList.addListSelectionListener(new ListHandler());
 60
 61    JPanel buttons = new JPanel();
 62    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
 63    buttons.setBorder(new EmptyBorder(6, 0, 0, 0));
 64
 65    add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
 66    add.setToolTipText(jEdit.getProperty("options.xmlindenter.add"));
 67    add.addActionListener(new ActionHandler());
 68    buttons.add(add);
 69    remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
 70    remove.setToolTipText(jEdit.getProperty("options.xmlindenter.remove"));
 71    remove.addActionListener(new ActionHandler());
 72    buttons.add(remove);
 73    buttons.add(Box.createGlue());
 74
 75    add(BorderLayout.SOUTH, buttons);
 76
 77    updateEnabled();
 78  }
 79
 80  protected void _save() {
 81    int i;
 82    for (i = 0; i < elementListModel.getSize(); i++) {
 83      String element = (String)elementListModel.getElementAt(i);
 84      jEdit.setProperty("xmlindenter.preserve-whitespace-element." + i, element);
 85    }
 86
 87    jEdit.unsetProperty("xmlindenter.preserve-whitespace-element." + i);
 88    jEdit.setProperty("xmlindenter.preserve-whitespace-element.modified", "true");
 89  }
 90
 91  private void updateEnabled() {
 92    boolean selected = (elementList.getSelectedValue() != null);
 93    remove.setEnabled(selected);
 94  }
 95
 96  class ActionHandler implements ActionListener {
 97    public void actionPerformed(ActionEvent event) {
 98      if (event.getSource() == add) {
 99        String property = "options.xmlindenter.dialog";
100        String name = GUIUtilities.input(PreserveWhitespaceOptionsPane.this, property, "");
101
102        if(name == null || name.length() == 0)
103          return;
104
105        elementListModel.addElement(name);
106
107      } else if (event.getSource() == remove) {
108        elementListModel.removeElementAt(elementList.getSelectedIndex());
109        updateEnabled();
110      }
111    }
112  }
113
114  class ListHandler implements ListSelectionListener {
115    public void valueChanged(ListSelectionEvent evt) {
116      updateEnabled();
117    }
118  }
119}