franta-hg@22
|
1 |
/**
|
franta-hg@22
|
2 |
* Rozšířené atributy – program na správu rozšířených atributů souborů
|
franta-hg@22
|
3 |
* Copyright © 2012 František Kučera (frantovo.cz)
|
franta-hg@22
|
4 |
*
|
franta-hg@22
|
5 |
* This program is free software: you can redistribute it and/or modify
|
franta-hg@22
|
6 |
* it under the terms of the GNU General Public License as published by
|
franta-hg@22
|
7 |
* the Free Software Foundation, either version 3 of the License, or
|
franta-hg@22
|
8 |
* (at your option) any later version.
|
franta-hg@22
|
9 |
*
|
franta-hg@22
|
10 |
* This program is distributed in the hope that it will be useful,
|
franta-hg@22
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
franta-hg@22
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
franta-hg@22
|
13 |
* GNU General Public License for more details.
|
franta-hg@22
|
14 |
*
|
franta-hg@22
|
15 |
* You should have received a copy of the GNU General Public License
|
franta-hg@22
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
franta-hg@22
|
17 |
*/
|
franta-hg@22
|
18 |
package cz.frantovo.rozsireneAtributy.gui;
|
franta-hg@22
|
19 |
|
franta-hg@22
|
20 |
import java.awt.Component;
|
franta-hg@22
|
21 |
import java.awt.event.ActionEvent;
|
franta-hg@22
|
22 |
import java.awt.event.ActionListener;
|
franta-hg@22
|
23 |
import java.util.EventObject;
|
franta-hg@22
|
24 |
import javax.swing.JComboBox;
|
franta-hg@22
|
25 |
import javax.swing.JTable;
|
franta-hg@22
|
26 |
import javax.swing.event.CellEditorListener;
|
franta-hg@22
|
27 |
import javax.swing.event.ChangeEvent;
|
franta-hg@22
|
28 |
import javax.swing.event.EventListenerList;
|
franta-hg@22
|
29 |
import javax.swing.table.TableCellEditor;
|
franta-hg@22
|
30 |
|
franta-hg@22
|
31 |
/**
|
franta-hg@22
|
32 |
* Umožňuje výběr názvu atributu z předvoleného seznamu (standardizované atributy).
|
franta-hg@22
|
33 |
*
|
franta-hg@22
|
34 |
* @author Ing. František Kučera (frantovo.cz)
|
franta-hg@22
|
35 |
*/
|
franta-hg@22
|
36 |
public class EditorNázvůAtributů extends JComboBox<String> implements TableCellEditor {
|
franta-hg@22
|
37 |
|
franta-hg@22
|
38 |
protected EventListenerList posluchače = new EventListenerList();
|
franta-hg@22
|
39 |
protected ChangeEvent událost = new ChangeEvent(this);
|
franta-hg@22
|
40 |
|
franta-hg@22
|
41 |
public EditorNázvůAtributů() {
|
franta-hg@22
|
42 |
super();
|
franta-hg@22
|
43 |
setEditable(true);
|
franta-hg@22
|
44 |
addActionListener(new ActionListener() {
|
franta-hg@22
|
45 |
|
franta-hg@22
|
46 |
@Override
|
franta-hg@22
|
47 |
public void actionPerformed(ActionEvent e) {
|
franta-hg@22
|
48 |
fireEditiaceSkončila();
|
franta-hg@22
|
49 |
}
|
franta-hg@22
|
50 |
});
|
franta-hg@22
|
51 |
}
|
franta-hg@22
|
52 |
|
franta-hg@22
|
53 |
protected void fireEditiaceSkončila() {
|
franta-hg@22
|
54 |
for (Object posluchač : posluchače.getListenerList()) {
|
franta-hg@22
|
55 |
if (posluchač instanceof CellEditorListener) {
|
franta-hg@22
|
56 |
((CellEditorListener) posluchač).editingStopped(událost);
|
franta-hg@22
|
57 |
}
|
franta-hg@22
|
58 |
}
|
franta-hg@22
|
59 |
}
|
franta-hg@22
|
60 |
|
franta-hg@22
|
61 |
protected void fireEditiaceZrušena() {
|
franta-hg@22
|
62 |
for (Object posluchač : posluchače.getListenerList()) {
|
franta-hg@22
|
63 |
if (posluchač instanceof CellEditorListener) {
|
franta-hg@22
|
64 |
((CellEditorListener) posluchač).editingCanceled(událost);
|
franta-hg@22
|
65 |
}
|
franta-hg@22
|
66 |
}
|
franta-hg@22
|
67 |
}
|
franta-hg@22
|
68 |
|
franta-hg@22
|
69 |
/**
|
franta-hg@22
|
70 |
* TODO:
|
franta-hg@22
|
71 |
* - další standardní atributy
|
franta-hg@22
|
72 |
* - konfigurovatelnost
|
franta-hg@22
|
73 |
*
|
franta-hg@22
|
74 |
* @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
|
franta-hg@22
|
75 |
*/
|
franta-hg@22
|
76 |
private void obnovHodnoty(Object názevAtributu) {
|
franta-hg@22
|
77 |
removeAllItems();
|
franta-hg@22
|
78 |
|
franta-hg@22
|
79 |
if (názevAtributu == null) {
|
franta-hg@22
|
80 |
názevAtributu = "";
|
franta-hg@22
|
81 |
} else if (!(názevAtributu instanceof String)) {
|
franta-hg@22
|
82 |
názevAtributu = String.valueOf(názevAtributu);
|
franta-hg@22
|
83 |
}
|
franta-hg@22
|
84 |
addItem((String) názevAtributu);
|
franta-hg@22
|
85 |
setSelectedItem(názevAtributu);
|
franta-hg@22
|
86 |
|
franta-hg@22
|
87 |
|
franta-hg@22
|
88 |
// General attributes in current use
|
franta-hg@22
|
89 |
addItem("mime_type");
|
franta-hg@22
|
90 |
addItem("charset");
|
franta-hg@22
|
91 |
addItem("creator");
|
franta-hg@22
|
92 |
|
franta-hg@22
|
93 |
// Proposed metadata attributes
|
franta-hg@22
|
94 |
addItem("xdg.comment");
|
franta-hg@22
|
95 |
addItem("xdg.origin.url");
|
franta-hg@22
|
96 |
addItem("xdg.origin.email.subject");
|
franta-hg@22
|
97 |
addItem("xdg.origin.email.from");
|
franta-hg@22
|
98 |
addItem("xdg.origin.email.message-id");
|
franta-hg@22
|
99 |
addItem("xdg.language");
|
franta-hg@22
|
100 |
addItem("xdg.creator");
|
franta-hg@22
|
101 |
addItem("xdg.publisher");
|
franta-hg@22
|
102 |
|
franta-hg@22
|
103 |
// Proposed control attributes
|
franta-hg@22
|
104 |
addItem("xdg.robots.index");
|
franta-hg@22
|
105 |
addItem("xdg.robots.backup");
|
franta-hg@22
|
106 |
|
franta-hg@22
|
107 |
// Dublin Core
|
franta-hg@22
|
108 |
addItem("dublincore.title");
|
franta-hg@22
|
109 |
addItem("dublincore.creator");
|
franta-hg@22
|
110 |
addItem("dublincore.subject");
|
franta-hg@22
|
111 |
addItem("dublincore.description");
|
franta-hg@22
|
112 |
addItem("dublincore.publisher");
|
franta-hg@22
|
113 |
addItem("dublincore.contributor");
|
franta-hg@22
|
114 |
addItem("dublincore.date");
|
franta-hg@22
|
115 |
addItem("dublincore.type");
|
franta-hg@22
|
116 |
addItem("dublincore.format");
|
franta-hg@22
|
117 |
addItem("dublincore.identifier");
|
franta-hg@22
|
118 |
addItem("dublincore.source");
|
franta-hg@22
|
119 |
addItem("dublincore.language");
|
franta-hg@22
|
120 |
addItem("dublincore.relation");
|
franta-hg@22
|
121 |
addItem("dublincore.coverage");
|
franta-hg@22
|
122 |
addItem("dublincore.rights");
|
franta-hg@22
|
123 |
|
franta-hg@22
|
124 |
// Application-specific attributes in current use
|
franta-hg@22
|
125 |
addItem("mime_encoding");
|
franta-hg@22
|
126 |
addItem("apache_handler");
|
franta-hg@22
|
127 |
addItem("Beagle.AttrTime");
|
franta-hg@22
|
128 |
addItem("Beagle.Fingerprint");
|
franta-hg@22
|
129 |
addItem("Beagle.MTime");
|
franta-hg@22
|
130 |
addItem("Beagle.Uid");
|
franta-hg@22
|
131 |
}
|
franta-hg@22
|
132 |
|
franta-hg@22
|
133 |
@Override
|
franta-hg@22
|
134 |
public Component getTableCellEditorComponent(JTable tabulka, Object hodnota, boolean vybraná, int řádek, int sloupec) {
|
franta-hg@22
|
135 |
obnovHodnoty(hodnota);
|
franta-hg@22
|
136 |
return this;
|
franta-hg@22
|
137 |
}
|
franta-hg@22
|
138 |
|
franta-hg@22
|
139 |
@Override
|
franta-hg@22
|
140 |
public Object getCellEditorValue() {
|
franta-hg@22
|
141 |
return getSelectedItem();
|
franta-hg@22
|
142 |
}
|
franta-hg@22
|
143 |
|
franta-hg@22
|
144 |
@Override
|
franta-hg@22
|
145 |
public boolean isCellEditable(EventObject anEvent) {
|
franta-hg@22
|
146 |
return true;
|
franta-hg@22
|
147 |
}
|
franta-hg@22
|
148 |
|
franta-hg@22
|
149 |
@Override
|
franta-hg@22
|
150 |
public boolean shouldSelectCell(EventObject anEvent) {
|
franta-hg@22
|
151 |
return true;
|
franta-hg@22
|
152 |
}
|
franta-hg@22
|
153 |
|
franta-hg@22
|
154 |
@Override
|
franta-hg@22
|
155 |
public boolean stopCellEditing() {
|
franta-hg@22
|
156 |
fireEditiaceSkončila();
|
franta-hg@22
|
157 |
return true;
|
franta-hg@22
|
158 |
}
|
franta-hg@22
|
159 |
|
franta-hg@22
|
160 |
@Override
|
franta-hg@22
|
161 |
public void cancelCellEditing() {
|
franta-hg@22
|
162 |
fireEditiaceZrušena();
|
franta-hg@22
|
163 |
}
|
franta-hg@22
|
164 |
|
franta-hg@22
|
165 |
@Override
|
franta-hg@22
|
166 |
public void addCellEditorListener(CellEditorListener l) {
|
franta-hg@22
|
167 |
posluchače.add(CellEditorListener.class, l);
|
franta-hg@22
|
168 |
}
|
franta-hg@22
|
169 |
|
franta-hg@22
|
170 |
@Override
|
franta-hg@22
|
171 |
public void removeCellEditorListener(CellEditorListener l) {
|
franta-hg@22
|
172 |
posluchače.remove(CellEditorListener.class, l);
|
franta-hg@22
|
173 |
}
|
franta-hg@22
|
174 |
}
|