📄 managepanel.java
字号:
/* * ManagePanel.java - Manages plugins * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2002 Kris Kopicki * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package org.gjt.sp.jedit.pluginmgr;//{{{ Importsimport javax.swing.border.*;import javax.swing.event.*;import javax.swing.table.*;import javax.swing.*;import java.awt.event.*;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.io.File;import java.net.URL;import java.util.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.help.*;import org.gjt.sp.jedit.*;import org.gjt.sp.util.Log;//}}}public class ManagePanel extends JPanel{ //{{{ ManagePanel constructor public ManagePanel(PluginManager window) { super(new BorderLayout(12,12)); this.window = window; setBorder(new EmptyBorder(12,12,12,12)); Box topBox = new Box(BoxLayout.X_AXIS); topBox.add(hideLibraries = new HideLibrariesButton()); add(BorderLayout.NORTH,topBox); /* Create the plugin table */ table = new JTable(pluginModel = new PluginTableModel()); table.setShowGrid(false); table.setIntercellSpacing(new Dimension(0,0)); table.setRowHeight(table.getRowHeight() + 2); table.setPreferredScrollableViewportSize(new Dimension(500,300)); table.setRequestFocusEnabled(false); table.setDefaultRenderer(Object.class, new TextRenderer( (DefaultTableCellRenderer)table.getDefaultRenderer(Object.class))); TableColumn col1 = table.getColumnModel().getColumn(0); TableColumn col2 = table.getColumnModel().getColumn(1); TableColumn col3 = table.getColumnModel().getColumn(2); TableColumn col4 = table.getColumnModel().getColumn(3); col1.setPreferredWidth(30); col1.setMinWidth(30); col1.setMaxWidth(30); col1.setResizable(false); col2.setPreferredWidth(300); col3.setPreferredWidth(100); col4.setPreferredWidth(100); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); header.addMouseListener(new HeaderMouseHandler()); JScrollPane scrollpane = new JScrollPane(table); scrollpane.getViewport().setBackground(table.getBackground()); add(BorderLayout.CENTER,scrollpane); /* Create button panel */ Box buttons = new Box(BoxLayout.X_AXIS); buttons.add(new RemoveButton()); buttons.add(Box.createGlue()); buttons.add(new HelpButton()); add(BorderLayout.SOUTH,buttons); } //}}} //{{{ update() method public void update() { pluginModel.update(); } //}}} //{{{ Private members private JCheckBox hideLibraries; private JTable table; private PluginTableModel pluginModel; private JButton remove; private JButton help; private PluginManager window; //{{{ showListConfirm() method private int showListConfirm(String name, String[] args, Vector listModel) { JList list = new JList(listModel); list.setVisibleRowCount(8); Object[] message = { jEdit.getProperty(name + ".message",args), new JScrollPane(list) }; return JOptionPane.showConfirmDialog(window, message, jEdit.getProperty(name + ".title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } //}}} //}}} //{{{ Inner classes //{{{ Entry class class Entry { static final String ERROR = "error"; static final String LOADED = "loaded"; static final String NOT_LOADED = "not-loaded"; String status; String jar; String clazz, name, version, author, docs; List jars; Entry(String jar) { jars = new LinkedList(); this.jar = jar; jars.add(this.jar); status = NOT_LOADED; } Entry(PluginJAR jar) { jars = new LinkedList(); this.jar = jar.getPath(); jars.add(this.jar); EditPlugin plugin = jar.getPlugin(); if(plugin != null) { status = (plugin instanceof EditPlugin.Broken ? ERROR : LOADED); clazz = plugin.getClassName(); name = jEdit.getProperty("plugin."+clazz+".name"); version = jEdit.getProperty("plugin."+clazz+".version"); author = jEdit.getProperty("plugin."+clazz+".author"); docs = jEdit.getProperty("plugin."+clazz+".docs"); String jarsProp = jEdit.getProperty("plugin."+clazz+".jars"); if(jarsProp != null) { String directory = MiscUtilities.getParentOfPath(this.jar); StringTokenizer st = new StringTokenizer(jarsProp); while(st.hasMoreElements()) { jars.add(MiscUtilities.constructPath( directory,st.nextToken())); } } } else status = LOADED; } } //}}} //{{{ PluginTableModel class class PluginTableModel extends AbstractTableModel { private List entries; private int sortType = EntryCompare.NAME; //{{{ Constructor public PluginTableModel() { entries = new ArrayList(); update(); } //}}} //{{{ getColumnCount() method public int getColumnCount() { return 4; } //}}} //{{{ getColumnClass() method public Class getColumnClass(int columnIndex) { switch (columnIndex) { case 0: return Boolean.class; default: return Object.class; } } //}}} //{{{ getColumnName() method public String getColumnName(int column) { switch (column) { case 0: return " "; case 1: return jEdit.getProperty("manage-plugins.info.name"); case 2: return jEdit.getProperty("manage-plugins.info.version"); case 3: return jEdit.getProperty("manage-plugins.info.status"); default: throw new Error("Column out of range"); } } //}}} //{{{ getEntry() method public Entry getEntry(int rowIndex) { return (Entry)entries.get(rowIndex); } //}}} //{{{ getRowCount() method public int getRowCount() { return entries.size(); } //}}} //{{{ getValueAt() method public Object getValueAt(int rowIndex,int columnIndex) { Entry entry = (Entry)entries.get(rowIndex); switch (columnIndex) { case 0: return new Boolean( !entry.status.equals( Entry.NOT_LOADED)); case 1: if(entry.name == null) { return MiscUtilities.getFileName(entry.jar); } else return entry.name; case 2: return entry.version; case 3: return jEdit.getProperty("plugin-manager.status." + entry.status); default: throw new Error("Column out of range"); } } //}}} //{{{ isCellEditable() method public boolean isCellEditable(int rowIndex, int columnIndex) { return columnIndex == 0; } //}}} //{{{ setValueAt() method public void setValueAt(Object value, int rowIndex, int columnIndex) { Entry entry = (Entry)entries.get(rowIndex); if(columnIndex == 0) { PluginJAR jar = jEdit.getPluginJAR(entry.jar); if(jar == null) { if(value.equals(Boolean.FALSE)) return; loadPluginJAR(entry.jar); } else { if(value.equals(Boolean.TRUE)) return; unloadPluginJARWithDialog(jar); } } update(); } //}}} //{{{ setSortType() method public void setSortType(int type) { sortType = type; sort(type); } //}}} //{{{ sort() method public void sort(int type) { Collections.sort(entries,new EntryCompare(type)); fireTableChanged(new TableModelEvent(this)); } //}}} //{{{ update() method public void update() { entries.clear(); String systemJarDir = MiscUtilities.constructPath( jEdit.getJEditHome(),"jars"); String userJarDir; if(jEdit.getSettingsDirectory() == null) userJarDir = null; else { userJarDir = MiscUtilities.constructPath(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -