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