PageRenderTime 78ms CodeModel.GetById 69ms app.highlight 7ms 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
  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
 20package infoviewer;
 21
 22import java.awt.BorderLayout;
 23import java.awt.Frame;
 24import java.awt.GridLayout;
 25import java.awt.event.ActionEvent;
 26import java.awt.event.ActionListener;
 27
 28import javax.swing.BorderFactory;
 29import javax.swing.Box;
 30import javax.swing.JButton;
 31import javax.swing.JPanel;
 32import javax.swing.JScrollPane;
 33import javax.swing.JTable;
 34import javax.swing.ListSelectionModel;
 35import javax.swing.UIManager;
 36
 37import org.gjt.sp.jedit.EditBus;
 38import org.gjt.sp.jedit.GUIUtilities;
 39import org.gjt.sp.jedit.jEdit;
 40import org.gjt.sp.jedit.gui.EnhancedDialog;
 41import org.gjt.sp.jedit.msg.PropertiesChanged;
 42
 43
 44public class BookmarksDialog extends EnhancedDialog {
 45
 46	private static final long serialVersionUID = 1504675651662267292L;
 47	private JTable table;
 48    private JButton bOk, bCancel, bAdd, bDelete, bMoveUp, bMoveDown;
 49    private Bookmarks model;
 50
 51    public BookmarksDialog(Frame parent) {
 52        super(parent, jEdit.getProperty("infoviewer.bdialog.title"), true);
 53
 54        model = new Bookmarks();
 55        table = new JTable(model);
 56        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 57        JScrollPane scroller = new JScrollPane(table);
 58
 59        bOk       = new JButton(jEdit.getProperty("infoviewer.bdialog.ok"));
 60        bCancel   = new JButton(jEdit.getProperty("infoviewer.bdialog.cancel"));
 61        bAdd      = new JButton(jEdit.getProperty("infoviewer.bdialog.add"));
 62        bDelete   = new JButton(jEdit.getProperty("infoviewer.bdialog.delete"));
 63        bMoveUp   = new JButton(jEdit.getProperty("infoviewer.bdialog.moveup"));
 64        bMoveDown = new JButton(jEdit.getProperty("infoviewer.bdialog.movedown"));
 65
 66        ActionHandler ah = new ActionHandler();
 67        bOk.addActionListener(ah);
 68        bCancel.addActionListener(ah);
 69        bAdd.addActionListener(ah);
 70        bDelete.addActionListener(ah);
 71        bMoveUp.addActionListener(ah);
 72        bMoveDown.addActionListener(ah);
 73
 74        Box south = Box.createHorizontalBox();
 75        south.add(Box.createHorizontalGlue());
 76        south.add(bOk);
 77        south.add(Box.createHorizontalStrut(20));
 78        south.add(bCancel);
 79        south.add(Box.createHorizontalGlue());
 80
 81        JPanel buttons = new JPanel(new GridLayout(0,1,5,5));
 82        buttons.add(bAdd);
 83        buttons.add(bDelete);
 84        buttons.add(Box.createVerticalStrut(10));
 85        buttons.add(bMoveUp);
 86        buttons.add(bMoveDown);
 87
 88        JPanel east = new JPanel();
 89        east.add(buttons, BorderLayout.NORTH);
 90        east.add(new JPanel(), BorderLayout.CENTER); // don't ask
 91
 92        getContentPane().setLayout(new BorderLayout(10,10));
 93        getContentPane().add(scroller, BorderLayout.CENTER);
 94        getContentPane().add(south, BorderLayout.SOUTH);
 95        getContentPane().add(east, BorderLayout.EAST);
 96
 97        getRootPane().setDefaultButton(bOk);
 98        getRootPane().setBorder(BorderFactory.createMatteBorder(10,10,10,10, UIManager.getColor("Panel.background")));
 99
100        setSize(500,300);
101        GUIUtilities.loadGeometry(this, "infoviewer.bdialog");
102        setLocationRelativeTo(parent);
103        setVisible(true);
104    }
105
106
107    public void ok() {
108        model.save();
109        GUIUtilities.saveGeometry(this, "infoviewer.bdialog");
110        EditBus.send(new PropertiesChanged(null));
111        setVisible(false);
112    }
113
114
115    public void cancel() {
116        GUIUtilities.saveGeometry(this, "infoviewer.bdialog");
117        setVisible(false);
118    }
119
120
121    private class ActionHandler implements ActionListener {
122        public void actionPerformed(ActionEvent evt) {
123            JButton button = (JButton) evt.getSource();
124            if (button == bAdd) {
125                model.add(new TitledURLEntry("", ""));
126            }
127            else if (button == bDelete) {
128                int rows[] = table.getSelectedRows();
129                if (rows.length == 0) {
130                    GUIUtilities.error(null, "infoviewer.error.bdialog.noselection", null);
131                } else {
132                    for (int i = rows.length - 1; i >= 0; i--) {
133                        model.delete(rows[i]);
134                    }
135                }
136            }
137            else if (button == bMoveUp) {
138                int rows[] = table.getSelectedRows();
139                if (rows.length == 0) {
140                    GUIUtilities.error(null, "infoviewer.error.bdialog.noselection", null);
141                } else if (rows.length > 1) {
142                    GUIUtilities.error(null, "infoviewer.error.bdialog.selecttoomuch", null);
143                } else if (rows[0] > 0) {
144                    model.moveup(rows[0]);
145                    table.setRowSelectionInterval(rows[0]-1, rows[0]-1);
146                }
147            }
148            else if (button == bMoveDown) {
149                int rows[] = table.getSelectedRows();
150                if (rows.length == 0) {
151                    GUIUtilities.error(null, "infoviewer.error.bdialog.noselection", null);
152                } else if (rows.length > 1) {
153                    GUIUtilities.error(null, "infoviewer.error.bdialog.selecttoomuch", null);
154                } else if (rows[0] < model.getRowCount()-1) {
155                    model.movedown(rows[0]);
156                    table.setRowSelectionInterval(rows[0]+1, rows[0]+1);
157                }
158            }
159            else if (button == bOk) {
160                ok();
161            }
162            else if (button == bCancel) {
163                cancel();
164            }
165        }
166    } // inner class ActionHandler
167
168}
169