PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/InfoViewer/infoviewer/BookmarksDialog.java

#
Java | 169 lines | 126 code | 25 blank | 18 comment | 33 complexity | d2659ba068d226b7bede87f7b81dc0ff 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. * BookmarksDialog.java - "Edit Bookmarks" dialog in InfoViewer
  3. * Copyright (C) 1999-2001 Dirk Moebius
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package infoviewer;
  20. import java.awt.BorderLayout;
  21. import java.awt.Frame;
  22. import java.awt.GridLayout;
  23. import java.awt.event.ActionEvent;
  24. import java.awt.event.ActionListener;
  25. import javax.swing.BorderFactory;
  26. import javax.swing.Box;
  27. import javax.swing.JButton;
  28. import javax.swing.JPanel;
  29. import javax.swing.JScrollPane;
  30. import javax.swing.JTable;
  31. import javax.swing.ListSelectionModel;
  32. import javax.swing.UIManager;
  33. import org.gjt.sp.jedit.EditBus;
  34. import org.gjt.sp.jedit.GUIUtilities;
  35. import org.gjt.sp.jedit.jEdit;
  36. import org.gjt.sp.jedit.gui.EnhancedDialog;
  37. import org.gjt.sp.jedit.msg.PropertiesChanged;
  38. public class BookmarksDialog extends EnhancedDialog {
  39. private static final long serialVersionUID = 1504675651662267292L;
  40. private JTable table;
  41. private JButton bOk, bCancel, bAdd, bDelete, bMoveUp, bMoveDown;
  42. private Bookmarks model;
  43. public BookmarksDialog(Frame parent) {
  44. super(parent, jEdit.getProperty("infoviewer.bdialog.title"), true);
  45. model = new Bookmarks();
  46. table = new JTable(model);
  47. table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  48. JScrollPane scroller = new JScrollPane(table);
  49. bOk = new JButton(jEdit.getProperty("infoviewer.bdialog.ok"));
  50. bCancel = new JButton(jEdit.getProperty("infoviewer.bdialog.cancel"));
  51. bAdd = new JButton(jEdit.getProperty("infoviewer.bdialog.add"));
  52. bDelete = new JButton(jEdit.getProperty("infoviewer.bdialog.delete"));
  53. bMoveUp = new JButton(jEdit.getProperty("infoviewer.bdialog.moveup"));
  54. bMoveDown = new JButton(jEdit.getProperty("infoviewer.bdialog.movedown"));
  55. ActionHandler ah = new ActionHandler();
  56. bOk.addActionListener(ah);
  57. bCancel.addActionListener(ah);
  58. bAdd.addActionListener(ah);
  59. bDelete.addActionListener(ah);
  60. bMoveUp.addActionListener(ah);
  61. bMoveDown.addActionListener(ah);
  62. Box south = Box.createHorizontalBox();
  63. south.add(Box.createHorizontalGlue());
  64. south.add(bOk);
  65. south.add(Box.createHorizontalStrut(20));
  66. south.add(bCancel);
  67. south.add(Box.createHorizontalGlue());
  68. JPanel buttons = new JPanel(new GridLayout(0,1,5,5));
  69. buttons.add(bAdd);
  70. buttons.add(bDelete);
  71. buttons.add(Box.createVerticalStrut(10));
  72. buttons.add(bMoveUp);
  73. buttons.add(bMoveDown);
  74. JPanel east = new JPanel();
  75. east.add(buttons, BorderLayout.NORTH);
  76. east.add(new JPanel(), BorderLayout.CENTER); // don't ask
  77. getContentPane().setLayout(new BorderLayout(10,10));
  78. getContentPane().add(scroller, BorderLayout.CENTER);
  79. getContentPane().add(south, BorderLayout.SOUTH);
  80. getContentPane().add(east, BorderLayout.EAST);
  81. getRootPane().setDefaultButton(bOk);
  82. getRootPane().setBorder(BorderFactory.createMatteBorder(10,10,10,10, UIManager.getColor("Panel.background")));
  83. setSize(500,300);
  84. GUIUtilities.loadGeometry(this, "infoviewer.bdialog");
  85. setLocationRelativeTo(parent);
  86. setVisible(true);
  87. }
  88. public void ok() {
  89. model.save();
  90. GUIUtilities.saveGeometry(this, "infoviewer.bdialog");
  91. EditBus.send(new PropertiesChanged(null));
  92. setVisible(false);
  93. }
  94. public void cancel() {
  95. GUIUtilities.saveGeometry(this, "infoviewer.bdialog");
  96. setVisible(false);
  97. }
  98. private class ActionHandler implements ActionListener {
  99. public void actionPerformed(ActionEvent evt) {
  100. JButton button = (JButton) evt.getSource();
  101. if (button == bAdd) {
  102. model.add(new TitledURLEntry("", ""));
  103. }
  104. else if (button == bDelete) {
  105. int rows[] = table.getSelectedRows();
  106. if (rows.length == 0) {
  107. GUIUtilities.error(null, "infoviewer.error.bdialog.noselection", null);
  108. } else {
  109. for (int i = rows.length - 1; i >= 0; i--) {
  110. model.delete(rows[i]);
  111. }
  112. }
  113. }
  114. else if (button == bMoveUp) {
  115. int rows[] = table.getSelectedRows();
  116. if (rows.length == 0) {
  117. GUIUtilities.error(null, "infoviewer.error.bdialog.noselection", null);
  118. } else if (rows.length > 1) {
  119. GUIUtilities.error(null, "infoviewer.error.bdialog.selecttoomuch", null);
  120. } else if (rows[0] > 0) {
  121. model.moveup(rows[0]);
  122. table.setRowSelectionInterval(rows[0]-1, rows[0]-1);
  123. }
  124. }
  125. else if (button == bMoveDown) {
  126. int rows[] = table.getSelectedRows();
  127. if (rows.length == 0) {
  128. GUIUtilities.error(null, "infoviewer.error.bdialog.noselection", null);
  129. } else if (rows.length > 1) {
  130. GUIUtilities.error(null, "infoviewer.error.bdialog.selecttoomuch", null);
  131. } else if (rows[0] < model.getRowCount()-1) {
  132. model.movedown(rows[0]);
  133. table.setRowSelectionInterval(rows[0]+1, rows[0]+1);
  134. }
  135. }
  136. else if (button == bOk) {
  137. ok();
  138. }
  139. else if (button == bCancel) {
  140. cancel();
  141. }
  142. }
  143. } // inner class ActionHandler
  144. }