source: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/images/IconPrefPanel.java @ 1014

Revision 1014, 5.4 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) 2001 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 *  30-12-2004
23 */
24
25package nu.fw.jeti.images;
26
27import java.awt.BorderLayout;
28import java.awt.event.ActionEvent;
29import java.io.File;
30import java.security.AccessControlException;
31import java.util.List;
32
33import javax.swing.*;
34
35import nu.fw.jeti.backend.Start;
36import nu.fw.jeti.plugins.PreferencesPanel;
37import nu.fw.jeti.ui.models.ListTableModel;
38import nu.fw.jeti.util.I18N;
39import nu.fw.jeti.util.Preferences;
40import nu.fw.jeti.util.TableSorter;
41
42/**
43 * @author E.S. de Boer
44 * @version 1.0
45 */
46
47public class IconPrefPanel extends PreferencesPanel
48{
49        private BorderLayout borderLayout1 = new BorderLayout();
50        private JScrollPane jScrollPane1 = new JScrollPane();
51        private JTable jTable1;
52        private JButton jButton1 = new JButton();
53    protected ListTableModel dataModel;
54    private String iconType;
55
56        public IconPrefPanel(String type)
57        {
58                iconType = type;
59                dataModel = new ListTableModel(
60            new String[] {
61                I18N.gettext("emoticons.Name"),
62                I18N.gettext("emoticons.Enabled"),
63                I18N.gettext("emoticons.Description"),
64                I18N.gettext("emoticons.Type") },
65            Preferences.getPlugableCopy(iconType));
66
67        TableSorter sorter = new TableSorter(dataModel);
68        jTable1 = new JTable(sorter);
69        sorter.setTableHeader(jTable1.getTableHeader());
70        sorter.setSortingStatus(0, TableSorter.ASCENDING);
71        //jTable1.setDefaultRenderer(String.class, new IconRenderer());
72                jTable1.setRowSelectionAllowed(false);
73
74        jTable1.getColumnModel().getColumn(0).setPreferredWidth(60);
75        jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
76        jTable1.getColumnModel().getColumn(2).setPreferredWidth(180);
77        jTable1.getColumnModel().getColumn(3).setPreferredWidth(40);
78       
79        String c[];
80        if(iconType.equals("rostericons"))
81        {
82                c =new String[]{"jabber","msn","icq",
83                        "aim","yahoo","gadu-gadu","sms","smtp","unknown","default"};
84        }
85        else
86        {
87                c =new String[]{"jabber","msn","icq",
88                        "aim","yahoo","gadu-gadu","groupchat","default","unknown"};
89        }
90       
91        JComboBox comboBox =  new JComboBox(c);
92        comboBox.setEditable(true);
93        jTable1.getColumnModel().getColumn(3).
94                                setCellEditor(new DefaultCellEditor(comboBox));
95               
96                this.setLayout(borderLayout1);
97                try {
98                if (new File(Start.path + "plugins" + File.separator + iconType).exists())
99                {       
100                        I18N.setTextAndMnemonic("emoticons.Scan_Emoticons",jButton1);
101                        jButton1.addActionListener(new java.awt.event.ActionListener()
102                        {
103                                public void actionPerformed(ActionEvent e)
104                                {
105                                        jButton1_actionPerformed(e);
106                                }
107                        });
108                        this.add(jButton1, BorderLayout.SOUTH);
109                }
110                }catch(AccessControlException e) {/*security exception so no scan*/}
111                this.add(jScrollPane1, BorderLayout.CENTER);
112                jScrollPane1.getViewport().add(jTable1, null);
113        }
114
115        void jButton1_actionPerformed(ActionEvent e)
116        {
117                new Icons(iconType).scanIcons();
118                dataModel.reload(Preferences.getPlugableCopy(iconType));
119        }
120
121        public void savePreferences()
122        {
123                List oldStatus = Preferences.getPlugable("rostericons");
124                List newStatus = dataModel.getPlugins();
125               
126                StatusIcons plugin = null;
127                boolean reloadNeeded=false;
128                try {
129                        for (int i = 0; i < newStatus.size(); i++)
130                        {
131                                Object[] newS = (Object[]) newStatus.get(i);
132                                Object[] oldS = (Object[]) oldStatus.get(i);
133                                if (!newS[3].equals(oldS[3]))
134                                {
135                                        reloadNeeded = true;
136                                        if (plugin == null) plugin = new StatusIcons();
137                                        plugin.unloadRosterIcon((String) oldS[3]);
138                                        plugin.unloadRosterIcon((String) newS[3]);
139                                        oldS[3]=newS[3];
140                                }
141                                if (!newS[1].equals(oldS[1]))
142                                {
143                                        oldS[1] = newS[1];
144                                        if (((Boolean) oldS[1]).booleanValue())
145                                        {
146                                                if(!reloadNeeded)
147                                                {
148                                                        //load
149                                                        if (plugin == null)     plugin = new StatusIcons();
150                                                        plugin.loadRosterIcon((String) oldS[4],(String)oldS[3]);
151                                                }
152                                        }
153                                        else
154                                        {
155                                                //unload
156                                                if (plugin == null) plugin = new StatusIcons();
157                                                plugin.unloadRosterIcon((String) oldS[3]);
158                                        }
159                                }
160                        }
161                        if(reloadNeeded)
162                        {
163                                for (int i = 0; i < newStatus.size(); i++)
164                                {
165                                        Object[] oldS = (Object[]) oldStatus.get(i);
166                                        if (((Boolean) oldS[1]).booleanValue())
167                                        {
168                                                if (plugin == null)     plugin = new StatusIcons();
169                                                plugin.reloadRosterIcon((String) oldS[4],(String)oldS[3]);
170                                        }
171                                }
172                        }
173                }
174                catch (Exception e)
175                {//FIXME quick hack to solve icon preferences saving on applet
176                        e.printStackTrace();
177                }
178               
179        }
180}
181/*
182 * Overrides for emacs
183 * Local variables:
184 * tab-width: 4
185 * End:
186 */
Note: See TracBrowser for help on using the repository browser.