source: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/ui/PluginsPanel.java @ 1001

Revision 1001, 5.3 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #552 - Inclusão do projeto Java referente ao applet do módulo.

Line 
1/*
2 *      Jeti, a Java Jabber client, Copyright (C) 2002 E.S. de Boer 
3 *
4 *  This program is free software; you can redistribute it and/or modify
5 *  it under the terms of the GNU General Public License as published by
6 *  the Free Software Foundation; either version 2 of the License, or
7 *  (at your option) any later version.
8 *
9 *  This program is distributed in the hope that it will be useful,
10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *      GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with this program; if not, write to the Free Software
16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 *      For questions, comments etc,
19 *      use the website at http://jeti.jabberstudio.org
20 *  or mail me at eric@jeti.tk
21 */
22
23
24package nu.fw.jeti.ui;
25
26import java.awt.BorderLayout;
27import java.awt.Component;
28import java.awt.event.ActionEvent;
29import java.io.File;
30import java.text.MessageFormat;
31import java.util.List;
32
33import javax.swing.JButton;
34import javax.swing.JScrollPane;
35import javax.swing.JTable;
36import javax.swing.table.DefaultTableCellRenderer;
37
38import nu.fw.jeti.backend.Start;
39import nu.fw.jeti.plugins.PluginData;
40import nu.fw.jeti.plugins.PluginsInfo;
41import nu.fw.jeti.plugins.PreferencesPanel;
42import nu.fw.jeti.ui.models.ListTableModel;
43import nu.fw.jeti.util.I18N;
44import nu.fw.jeti.util.Preferences;
45import nu.fw.jeti.util.TableSorter;
46
47/**
48 * @author E.S. de Boer
49 * @version 1.0
50 */
51public class PluginsPanel extends PreferencesPanel
52{//change to jtreetable http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html
53    private JScrollPane jScrollPane1 = new JScrollPane();
54    private JTable jTable1;
55    private JButton jButton1 = new JButton();
56        private OptionsWindow prefWindow;
57    private List plugins;
58    private ListTableModel dataModel;
59
60    public PluginsPanel(OptionsWindow pref)
61    {
62                prefWindow = pref;
63               
64        plugins = Preferences.getTranslatedPlugins();
65        dataModel = new ListTableModel(
66            new String[]{
67                I18N.gettext("main.options.Name"),
68                I18N.gettext("main.options.Enabled"),
69                I18N.gettext("main.options.Description")},
70            plugins);
71        TableSorter sorter = new TableSorter(dataModel);
72        jTable1 = new JTable(sorter);
73        sorter.setTableHeader(jTable1.getTableHeader());
74        sorter.setSortingStatus(0, TableSorter.ASCENDING);
75        jTable1.setDefaultRenderer(String.class, new PluginRenderer());
76                jTable1.setRowSelectionAllowed(false);
77        jTable1.getColumnModel().getColumn(0).setPreferredWidth(60);
78        jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
79        jTable1.getColumnModel().getColumn(2).setPreferredWidth(180);
80       
81                setLayout(new BorderLayout());
82                if (!Start.applet && new File(Start.path + "plugins").exists())
83                {       
84                jButton1.setText(I18N.gettext("main.options.Scan_plugins"));
85                jButton1.addActionListener(new java.awt.event.ActionListener()
86                {
87                    public void actionPerformed(ActionEvent e)
88                    {
89                        jButton1_actionPerformed(e);
90                    }
91                });
92                add(jButton1, BorderLayout.SOUTH);
93                }
94        add(jScrollPane1, BorderLayout.CENTER);
95        jScrollPane1.getViewport().add(jTable1);
96    }
97
98    void jButton1_actionPerformed(ActionEvent e)
99    {
100                new PluginData().scanPlugins();
101                dataModel.reload(Preferences.getTranslatedPlugins());
102                       
103    }
104
105        public void savePreferences()
106        {
107                List oldStatus = nu.fw.jeti.util.Preferences.getPlugins();
108                List newStatus =dataModel.getPlugins();
109                for(int i=0;i<newStatus.size();i++)
110                {
111                        Object[] newS =(Object[]) newStatus.get(i);
112                        Object[] oldS =(Object[]) oldStatus.get(i);
113                        if(!newS[1].equals(oldS[1]))
114                        {
115                                oldS[1] = newS[1];
116                                String name =(String)oldS[0];
117                                if(((Boolean)oldS[1]).booleanValue())
118                                {//load
119                                        PluginsInfo.loadPlugin(name);
120                                        prefWindow.addPanel(name);
121                                }
122                                else
123                                {//unload
124                                        PluginsInfo.unloadPlugin(name);
125                                        prefWindow.removePanel(name);
126                                }
127                        }
128                }
129        }
130       
131          class PluginRenderer extends DefaultTableCellRenderer {
132        String format;
133       
134        public PluginRenderer() {
135            super();
136            format = I18N.gettext("main.options.Version_{0}_(Jeti_{1})");
137        }
138
139        public Component getTableCellRendererComponent(JTable table,
140                                                       Object value,
141                                                       boolean isSelected,
142                                                       boolean hasFocus,
143                                                       int row,
144                                                       int column) {
145                if(row<plugins.size())
146                {
147                    String pluginVersion = (String)((Object[])plugins.get(row))[3];
148                    String jetiVersion = (String)((Object[])plugins.get(row))[4];
149               
150                    setToolTipText(
151                                MessageFormat.format(
152                                        format, new Object[]{pluginVersion, jetiVersion}));
153                }
154            return super.getTableCellRendererComponent(
155                table, value, isSelected, hasFocus, row, column);
156        }
157    }
158
159}
160/*
161 * Overrides for emacs
162 * Local variables:
163 * tab-width: 4
164 * End:
165 */
Note: See TracBrowser for help on using the repository browser.