PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. */
  20. package xml.indent;
  21. import javax.swing.border.EmptyBorder;
  22. import javax.swing.event.*;
  23. import javax.swing.*;
  24. import java.awt.event.*;
  25. import java.awt.*;
  26. import org.gjt.sp.jedit.gui.*;
  27. import org.gjt.sp.jedit.*;
  28. public class PreserveWhitespaceOptionsPane extends AbstractOptionPane {
  29. private JList elementList;
  30. private DefaultListModel elementListModel;
  31. private JButton add;
  32. private JButton remove;
  33. public PreserveWhitespaceOptionsPane() {
  34. super("xmlindenter");
  35. }
  36. protected void _init() {
  37. setLayout(new BorderLayout());
  38. JLabel label = new JLabel(jEdit.getProperty("options.xmlindenter.caption"));
  39. label.setBorder(new EmptyBorder(0, 0, 6, 0));
  40. add(BorderLayout.NORTH, label);
  41. elementListModel = new DefaultListModel();
  42. int i = 0;
  43. String element;
  44. while((element = jEdit.getProperty("xmlindenter.preserve-whitespace-element." + i)) != null) {
  45. elementListModel.addElement(element);
  46. i++;
  47. }
  48. elementList = new JList(elementListModel);
  49. add(BorderLayout.CENTER, new JScrollPane(elementList));
  50. elementList.addListSelectionListener(new ListHandler());
  51. JPanel buttons = new JPanel();
  52. buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
  53. buttons.setBorder(new EmptyBorder(6, 0, 0, 0));
  54. add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
  55. add.setToolTipText(jEdit.getProperty("options.xmlindenter.add"));
  56. add.addActionListener(new ActionHandler());
  57. buttons.add(add);
  58. remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
  59. remove.setToolTipText(jEdit.getProperty("options.xmlindenter.remove"));
  60. remove.addActionListener(new ActionHandler());
  61. buttons.add(remove);
  62. buttons.add(Box.createGlue());
  63. add(BorderLayout.SOUTH, buttons);
  64. updateEnabled();
  65. }
  66. protected void _save() {
  67. int i;
  68. for (i = 0; i < elementListModel.getSize(); i++) {
  69. String element = (String)elementListModel.getElementAt(i);
  70. jEdit.setProperty("xmlindenter.preserve-whitespace-element." + i, element);
  71. }
  72. jEdit.unsetProperty("xmlindenter.preserve-whitespace-element." + i);
  73. jEdit.setProperty("xmlindenter.preserve-whitespace-element.modified", "true");
  74. }
  75. private void updateEnabled() {
  76. boolean selected = (elementList.getSelectedValue() != null);
  77. remove.setEnabled(selected);
  78. }
  79. class ActionHandler implements ActionListener {
  80. public void actionPerformed(ActionEvent event) {
  81. if (event.getSource() == add) {
  82. String property = "options.xmlindenter.dialog";
  83. String name = GUIUtilities.input(PreserveWhitespaceOptionsPane.this, property, "");
  84. if(name == null || name.length() == 0)
  85. return;
  86. elementListModel.addElement(name);
  87. } else if (event.getSource() == remove) {
  88. elementListModel.removeElementAt(elementList.getSelectedIndex());
  89. updateEnabled();
  90. }
  91. }
  92. }
  93. class ListHandler implements ListSelectionListener {
  94. public void valueChanged(ListSelectionEvent evt) {
  95. updateEnabled();
  96. }
  97. }
  98. }