franta-hg@22: /** franta-hg@22: * Rozšířené atributy – program na správu rozšířených atributů souborů franta-hg@22: * Copyright © 2012 František Kučera (frantovo.cz) franta-hg@22: * franta-hg@22: * This program is free software: you can redistribute it and/or modify franta-hg@22: * it under the terms of the GNU General Public License as published by franta-hg@27: * the Free Software Foundation, either version 3 of the License. franta-hg@22: * franta-hg@22: * This program is distributed in the hope that it will be useful, franta-hg@22: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@22: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@22: * GNU General Public License for more details. franta-hg@22: * franta-hg@22: * You should have received a copy of the GNU General Public License franta-hg@22: * along with this program. If not, see . franta-hg@22: */ franta-hg@28: package cz.frantovo.rozsireneatributy.gui; franta-hg@22: franta-hg@31: import cz.frantovo.rozsireneatributy.Konfigurace; franta-hg@31: import cz.frantovo.rozsireneatributy.Konfigurace.DefiniceAtributu; franta-hg@22: import java.awt.Component; franta-hg@22: import java.awt.event.ActionEvent; franta-hg@22: import java.awt.event.ActionListener; franta-hg@22: import java.util.EventObject; franta-hg@22: import javax.swing.JComboBox; franta-hg@22: import javax.swing.JTable; franta-hg@22: import javax.swing.event.CellEditorListener; franta-hg@22: import javax.swing.event.ChangeEvent; franta-hg@22: import javax.swing.event.EventListenerList; franta-hg@22: import javax.swing.table.TableCellEditor; franta-hg@22: franta-hg@22: /** franta-hg@29: * Umožňuje výběr názvu atributu z předvoleného seznamu franta-hg@29: * (standardizované atributy). franta-hg@22: * franta-hg@22: * @author Ing. František Kučera (frantovo.cz) franta-hg@22: */ franta-hg@29: public class EditorNázvůAtributů franta-hg@29: extends JComboBox franta-hg@29: implements TableCellEditor { franta-hg@22: franta-hg@31: private final Konfigurace konfigurace; franta-hg@22: protected EventListenerList posluchače = new EventListenerList(); franta-hg@22: protected ChangeEvent událost = new ChangeEvent(this); franta-hg@22: franta-hg@31: public EditorNázvůAtributů(Konfigurace konfigurace) { franta-hg@22: super(); franta-hg@31: this.konfigurace = konfigurace; franta-hg@22: setEditable(true); franta-hg@22: addActionListener(new ActionListener() { franta-hg@22: franta-hg@22: @Override franta-hg@22: public void actionPerformed(ActionEvent e) { franta-hg@22: fireEditiaceSkončila(); franta-hg@22: } franta-hg@22: }); franta-hg@22: } franta-hg@22: franta-hg@22: protected void fireEditiaceSkončila() { franta-hg@22: for (Object posluchač : posluchače.getListenerList()) { franta-hg@22: if (posluchač instanceof CellEditorListener) { franta-hg@22: ((CellEditorListener) posluchač).editingStopped(událost); franta-hg@22: } franta-hg@22: } franta-hg@22: } franta-hg@22: franta-hg@22: protected void fireEditiaceZrušena() { franta-hg@22: for (Object posluchač : posluchače.getListenerList()) { franta-hg@22: if (posluchač instanceof CellEditorListener) { franta-hg@22: ((CellEditorListener) posluchač).editingCanceled(událost); franta-hg@22: } franta-hg@22: } franta-hg@22: } franta-hg@22: franta-hg@22: /** franta-hg@22: * TODO: franta-hg@22: * - další standardní atributy franta-hg@31: * - načítat z XML souboru franta-hg@22: * franta-hg@22: * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes franta-hg@22: */ franta-hg@22: private void obnovHodnoty(Object názevAtributu) { franta-hg@22: removeAllItems(); franta-hg@22: franta-hg@22: if (názevAtributu == null) { franta-hg@22: názevAtributu = ""; franta-hg@22: } else if (!(názevAtributu instanceof String)) { franta-hg@22: názevAtributu = String.valueOf(názevAtributu); franta-hg@22: } franta-hg@22: addItem((String) názevAtributu); franta-hg@22: setSelectedItem(názevAtributu); franta-hg@31: franta-hg@31: for (DefiniceAtributu da : konfigurace.getAtributy()) { franta-hg@31: addItem(da.getNázev()); franta-hg@31: } franta-hg@31: franta-hg@31: if (!konfigurace.getAtributy().isEmpty()) return; franta-hg@22: franta-hg@22: // General attributes in current use franta-hg@22: addItem("mime_type"); franta-hg@22: addItem("charset"); franta-hg@22: addItem("creator"); franta-hg@22: franta-hg@22: // Proposed metadata attributes franta-hg@22: addItem("xdg.comment"); franta-hg@22: addItem("xdg.origin.url"); franta-hg@22: addItem("xdg.origin.email.subject"); franta-hg@22: addItem("xdg.origin.email.from"); franta-hg@22: addItem("xdg.origin.email.message-id"); franta-hg@22: addItem("xdg.language"); franta-hg@22: addItem("xdg.creator"); franta-hg@22: addItem("xdg.publisher"); franta-hg@22: franta-hg@22: // Proposed control attributes franta-hg@22: addItem("xdg.robots.index"); franta-hg@22: addItem("xdg.robots.backup"); franta-hg@22: franta-hg@22: // Dublin Core franta-hg@22: addItem("dublincore.title"); franta-hg@22: addItem("dublincore.creator"); franta-hg@22: addItem("dublincore.subject"); franta-hg@22: addItem("dublincore.description"); franta-hg@22: addItem("dublincore.publisher"); franta-hg@22: addItem("dublincore.contributor"); franta-hg@22: addItem("dublincore.date"); franta-hg@22: addItem("dublincore.type"); franta-hg@22: addItem("dublincore.format"); franta-hg@22: addItem("dublincore.identifier"); franta-hg@22: addItem("dublincore.source"); franta-hg@22: addItem("dublincore.language"); franta-hg@22: addItem("dublincore.relation"); franta-hg@22: addItem("dublincore.coverage"); franta-hg@22: addItem("dublincore.rights"); franta-hg@22: franta-hg@22: // Application-specific attributes in current use franta-hg@22: addItem("mime_encoding"); franta-hg@22: addItem("apache_handler"); franta-hg@22: addItem("Beagle.AttrTime"); franta-hg@22: addItem("Beagle.Fingerprint"); franta-hg@22: addItem("Beagle.MTime"); franta-hg@22: addItem("Beagle.Uid"); franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@29: public Component getTableCellEditorComponent( franta-hg@29: JTable tabulka, franta-hg@29: Object hodnota, franta-hg@29: boolean vybraná, franta-hg@29: int řádek, franta-hg@29: int sloupec) { franta-hg@22: obnovHodnoty(hodnota); franta-hg@22: return this; franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@22: public Object getCellEditorValue() { franta-hg@22: return getSelectedItem(); franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@22: public boolean isCellEditable(EventObject anEvent) { franta-hg@22: return true; franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@22: public boolean shouldSelectCell(EventObject anEvent) { franta-hg@22: return true; franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@22: public boolean stopCellEditing() { franta-hg@22: fireEditiaceSkončila(); franta-hg@22: return true; franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@22: public void cancelCellEditing() { franta-hg@22: fireEditiaceZrušena(); franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@22: public void addCellEditorListener(CellEditorListener l) { franta-hg@22: posluchače.add(CellEditorListener.class, l); franta-hg@22: } franta-hg@22: franta-hg@22: @Override franta-hg@22: public void removeCellEditorListener(CellEditorListener l) { franta-hg@22: posluchače.remove(CellEditorListener.class, l); franta-hg@22: } franta-hg@22: }