2 * Rozšířené atributy – program na správu rozšířených atributů souborů
3 * Copyright © 2012 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package cz.frantovo.rozsireneatributy.gui;
19 import cz.frantovo.rozsireneatributy.Konfigurace;
20 import cz.frantovo.rozsireneatributy.Konfigurace.DefiniceAtributu;
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.EventObject;
25 import javax.swing.JComboBox;
26 import javax.swing.JTable;
27 import javax.swing.event.CellEditorListener;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.EventListenerList;
30 import javax.swing.table.TableCellEditor;
33 * Umožňuje výběr názvu atributu z předvoleného seznamu
34 * (standardizované atributy).
36 * @author Ing. František Kučera (frantovo.cz)
38 public class EditorNázvůAtributů
39 extends JComboBox<String>
40 implements TableCellEditor {
42 private final Konfigurace konfigurace;
43 protected EventListenerList posluchače = new EventListenerList();
44 protected ChangeEvent událost = new ChangeEvent(this);
46 public EditorNázvůAtributů(Konfigurace konfigurace) {
48 this.konfigurace = konfigurace;
50 addActionListener(new ActionListener() {
53 public void actionPerformed(ActionEvent e) {
54 fireEditiaceSkončila();
59 protected void fireEditiaceSkončila() {
60 for (Object posluchač : posluchače.getListenerList()) {
61 if (posluchač instanceof CellEditorListener) {
62 ((CellEditorListener) posluchač).editingStopped(událost);
67 protected void fireEditiaceZrušena() {
68 for (Object posluchač : posluchače.getListenerList()) {
69 if (posluchač instanceof CellEditorListener) {
70 ((CellEditorListener) posluchač).editingCanceled(událost);
77 * - další standardní atributy
78 * - načítat z XML souboru
80 * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
82 private void obnovHodnoty(Object názevAtributu) {
85 if (názevAtributu == null) {
87 } else if (!(názevAtributu instanceof String)) {
88 názevAtributu = String.valueOf(názevAtributu);
90 addItem((String) názevAtributu);
91 setSelectedItem(názevAtributu);
93 for (DefiniceAtributu da : konfigurace.getAtributy()) {
94 addItem(da.getNázev());
97 if (!konfigurace.getAtributy().isEmpty()) return;
99 // General attributes in current use
100 addItem("mime_type");
104 // Proposed metadata attributes
105 addItem("xdg.comment");
106 addItem("xdg.origin.url");
107 addItem("xdg.origin.email.subject");
108 addItem("xdg.origin.email.from");
109 addItem("xdg.origin.email.message-id");
110 addItem("xdg.language");
111 addItem("xdg.creator");
112 addItem("xdg.publisher");
114 // Proposed control attributes
115 addItem("xdg.robots.index");
116 addItem("xdg.robots.backup");
119 addItem("dublincore.title");
120 addItem("dublincore.creator");
121 addItem("dublincore.subject");
122 addItem("dublincore.description");
123 addItem("dublincore.publisher");
124 addItem("dublincore.contributor");
125 addItem("dublincore.date");
126 addItem("dublincore.type");
127 addItem("dublincore.format");
128 addItem("dublincore.identifier");
129 addItem("dublincore.source");
130 addItem("dublincore.language");
131 addItem("dublincore.relation");
132 addItem("dublincore.coverage");
133 addItem("dublincore.rights");
135 // Application-specific attributes in current use
136 addItem("mime_encoding");
137 addItem("apache_handler");
138 addItem("Beagle.AttrTime");
139 addItem("Beagle.Fingerprint");
140 addItem("Beagle.MTime");
141 addItem("Beagle.Uid");
145 public Component getTableCellEditorComponent(
151 obnovHodnoty(hodnota);
156 public Object getCellEditorValue() {
157 return getSelectedItem();
161 public boolean isCellEditable(EventObject anEvent) {
166 public boolean shouldSelectCell(EventObject anEvent) {
171 public boolean stopCellEditing() {
172 fireEditiaceSkončila();
177 public void cancelCellEditing() {
178 fireEditiaceZrušena();
182 public void addCellEditorListener(CellEditorListener l) {
183 posluchače.add(CellEditorListener.class, l);
187 public void removeCellEditorListener(CellEditorListener l) {
188 posluchače.remove(CellEditorListener.class, l);