diff -r 000000000000 -r bf06eb899671 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java Sun Oct 07 15:11:42 2012 +0200 @@ -0,0 +1,174 @@ +/** + * 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, or + * (at your option) any later version. + * + * 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 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 { + + protected EventListenerList posluchače = new EventListenerList(); + protected ChangeEvent událost = new ChangeEvent(this); + + public EditorNázvůAtributů() { + super(); + 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 + * - konfigurovatelnost + * + * @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); + + + // 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); + } +}