📄 repositorytab.java
字号:
/* Sesame - Storage and Querying architecture for RDF and RDF Schema * Copyright (C) 2001-2005 Aduna * * Contact: * Aduna * Prinses Julianaplein 14 b * 3817 CS Amersfoort * The Netherlands * tel. +33 (0)33 465 99 87 * fax. +33 (0)33 465 99 87 * * http://aduna.biz/ * http://www.openrdf.org/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package org.openrdf.sesame.config.ui;import java.awt.Color;import java.awt.Dimension;import java.awt.Frame;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.net.URL;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JViewport;import javax.swing.border.EmptyBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import org.openrdf.sesame.config.SystemConfig;import org.openrdf.sesame.config.ui.util.GridBagUtil;import org.openrdf.sesame.config.ui.util.Util;/** * Repository JPanel of ConfigureSesameFrame * * @author Peter van 't Hof * @author Arjohn Kampman * @version $Revision: 1.4 $ */public class RepositoryTab extends JPanel implements ActionListener, ListSelectionListener {/*----------+| Variables |+----------*/ /** SystemConfig */ protected SystemConfig _config; /** RepositoryTable */ protected RepositoryTable _table; protected JButton _detailsButton; protected JButton _addButton; protected JButton _cloneButton; protected JButton _removeButton;/*-------------+| Constructors |+-------------*/ /** * Creates a new RepositoryTab with the supplied SystemConfig * * @param config SystemConfig */ public RepositoryTab(SystemConfig config) { _config = config; setLayout(new GridBagLayout()); // Add an empty border of 8 pixels. setBorder(new EmptyBorder(8, 8, 8, 8)); // Icon URL url = getClass().getResource("icons/repository.png"); JLabel icon = new JLabel(new ImageIcon(url)); GridBagUtil.constrain(this, icon, 0, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER, 0, 0, 0, 0, 4, 4); // Explanation JTextArea explanation = Util.createReadOnlyTextArea( "Use the list below to add repositories to, or remove repositories from Sesame,\n" + "and to change their access control list, sail stack and other settings.", getBackground()); GridBagUtil.constrain(this, explanation, 1, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST, 0, 0, 0, 4, 4, 0); // Table title JTextArea title = Util.createTitle("Repositories for Sesame:", getBackground()); GridBagUtil.constrain(this, title, 0, 1, 2, 1, GridBagConstraints.NONE, GridBagConstraints.WEST, 0, 0, 4, 0, 4, 0); // Repository table GridBagUtil.constrain(this, _createList(), 0, 2, 2, 1, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1, 1, 4, 0, 4, 0); // Buttons GridBagUtil.constrain(this, _createButtons(), 0, 3, 2, 1, GridBagConstraints.NONE, GridBagConstraints.EAST, 1, 0, 4, 0, 0, 0); _table.getSelectionModel().addListSelectionListener(this); _enableDisableComponents(); } protected JScrollPane _createList() { JScrollPane list = new JScrollPane(); _table = new RepositoryTable(_config); JViewport viewport = list.getViewport(); viewport.add(_table); viewport.setBackground(Color.white); viewport.setPreferredSize(new Dimension(450, 200)); list.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); return list; } protected JPanel _createButtons() { // Use a GridLayout to ensure the buttons get equal sizes: JPanel buttonPanel = new JPanel(new GridLayout(1, 3, 4, 0)); // Details button URL url = getClass().getResource("icons/details-repository.png"); _detailsButton = new JButton(new ImageIcon(url)); _detailsButton.setToolTipText("Show details for selected repository"); buttonPanel.add(_detailsButton); _detailsButton.addActionListener(this); // Add button url = getClass().getResource("icons/add-repository.png"); _addButton = new JButton(new ImageIcon(url)); _addButton.setToolTipText("Add new repository to list"); buttonPanel.add(_addButton); _addButton.addActionListener(this); // Add button url = getClass().getResource("icons/clone-repository.png"); _cloneButton = new JButton(new ImageIcon(url)); _cloneButton.setToolTipText("Clone selected repository"); buttonPanel.add(_cloneButton); _cloneButton.addActionListener(this); // Remove button url = getClass().getResource("icons/remove-repository.png"); _removeButton = new JButton(new ImageIcon(url)); _removeButton.setToolTipText("Remove selected repository from list"); buttonPanel.add(_removeButton); _removeButton.addActionListener(this); return buttonPanel; }/*--------+| Methods |+--------*/ public void valueChanged(ListSelectionEvent e) { _enableDisableComponents(); } /** * Enables/disables components according to the * selections in the user table. **/ protected void _enableDisableComponents() { boolean rowSelected = _table.getSelectedRow() != -1; _detailsButton.setEnabled(rowSelected); _removeButton.setEnabled(rowSelected); _cloneButton.setEnabled(rowSelected); } /** * Focusses on table if it is being edited * * @see javax.swing.JPanel#requestFocus */ public void requestFocus() { if (_table.isEditing()) { _table.requestFocus(); } else { super.requestFocus(); } } protected void _showAdvancedDialog() { Window owner = Util.getOwner(this); if (!_config.hasARepository()) { Util.showWarningDialog (owner, "No repository selected.", "Advanced Settings"); } else { String id = _table.getIdentifierForSelectedRow(); if (id == null) { Util.showWarningDialog (owner, "No repository selected.", "Advanced Settings"); } else { AdvancedDialog dialog = new AdvancedDialog((Frame)owner, id, _config); dialog.show(); } } }/*--------------------------------------+| Methods from interface ActionListener |+--------------------------------------*/ public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if (_table.stopCellEditing()) { if (source == _addButton) { _table.addNewRow(); } if (source == _cloneButton) { _table.cloneRow(); } else if (source == _removeButton) { _table.removeRow(); } else if (source == _detailsButton) { _showAdvancedDialog(); } } requestFocus(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -