java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java Sun Oct 07 15:11:42 2012 +0200
1.3 @@ -0,0 +1,174 @@
1.4 +/**
1.5 + * Rozšířené atributy – program na správu rozšířených atributů souborů
1.6 + * Copyright © 2012 František Kučera (frantovo.cz)
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation, either version 3 of the License, or
1.11 + * (at your option) any later version.
1.12 + *
1.13 + * This program is distributed in the hope that it will be useful,
1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.16 + * GNU General Public License for more details.
1.17 + *
1.18 + * You should have received a copy of the GNU General Public License
1.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.20 + */
1.21 +package cz.frantovo.rozsireneAtributy.gui;
1.22 +
1.23 +import java.awt.Component;
1.24 +import java.awt.event.ActionEvent;
1.25 +import java.awt.event.ActionListener;
1.26 +import java.util.EventObject;
1.27 +import javax.swing.JComboBox;
1.28 +import javax.swing.JTable;
1.29 +import javax.swing.event.CellEditorListener;
1.30 +import javax.swing.event.ChangeEvent;
1.31 +import javax.swing.event.EventListenerList;
1.32 +import javax.swing.table.TableCellEditor;
1.33 +
1.34 +/**
1.35 + * Umožňuje výběr názvu atributu z předvoleného seznamu (standardizované atributy).
1.36 + *
1.37 + * @author Ing. František Kučera (frantovo.cz)
1.38 + */
1.39 +public class EditorNázvůAtributů extends JComboBox<String> implements TableCellEditor {
1.40 +
1.41 + protected EventListenerList posluchače = new EventListenerList();
1.42 + protected ChangeEvent událost = new ChangeEvent(this);
1.43 +
1.44 + public EditorNázvůAtributů() {
1.45 + super();
1.46 + setEditable(true);
1.47 + addActionListener(new ActionListener() {
1.48 +
1.49 + @Override
1.50 + public void actionPerformed(ActionEvent e) {
1.51 + fireEditiaceSkončila();
1.52 + }
1.53 + });
1.54 + }
1.55 +
1.56 + protected void fireEditiaceSkončila() {
1.57 + for (Object posluchač : posluchače.getListenerList()) {
1.58 + if (posluchač instanceof CellEditorListener) {
1.59 + ((CellEditorListener) posluchač).editingStopped(událost);
1.60 + }
1.61 + }
1.62 + }
1.63 +
1.64 + protected void fireEditiaceZrušena() {
1.65 + for (Object posluchač : posluchače.getListenerList()) {
1.66 + if (posluchač instanceof CellEditorListener) {
1.67 + ((CellEditorListener) posluchač).editingCanceled(událost);
1.68 + }
1.69 + }
1.70 + }
1.71 +
1.72 + /**
1.73 + * TODO:
1.74 + * - další standardní atributy
1.75 + * - konfigurovatelnost
1.76 + *
1.77 + * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
1.78 + */
1.79 + private void obnovHodnoty(Object názevAtributu) {
1.80 + removeAllItems();
1.81 +
1.82 + if (názevAtributu == null) {
1.83 + názevAtributu = "";
1.84 + } else if (!(názevAtributu instanceof String)) {
1.85 + názevAtributu = String.valueOf(názevAtributu);
1.86 + }
1.87 + addItem((String) názevAtributu);
1.88 + setSelectedItem(názevAtributu);
1.89 +
1.90 +
1.91 + // General attributes in current use
1.92 + addItem("mime_type");
1.93 + addItem("charset");
1.94 + addItem("creator");
1.95 +
1.96 + // Proposed metadata attributes
1.97 + addItem("xdg.comment");
1.98 + addItem("xdg.origin.url");
1.99 + addItem("xdg.origin.email.subject");
1.100 + addItem("xdg.origin.email.from");
1.101 + addItem("xdg.origin.email.message-id");
1.102 + addItem("xdg.language");
1.103 + addItem("xdg.creator");
1.104 + addItem("xdg.publisher");
1.105 +
1.106 + // Proposed control attributes
1.107 + addItem("xdg.robots.index");
1.108 + addItem("xdg.robots.backup");
1.109 +
1.110 + // Dublin Core
1.111 + addItem("dublincore.title");
1.112 + addItem("dublincore.creator");
1.113 + addItem("dublincore.subject");
1.114 + addItem("dublincore.description");
1.115 + addItem("dublincore.publisher");
1.116 + addItem("dublincore.contributor");
1.117 + addItem("dublincore.date");
1.118 + addItem("dublincore.type");
1.119 + addItem("dublincore.format");
1.120 + addItem("dublincore.identifier");
1.121 + addItem("dublincore.source");
1.122 + addItem("dublincore.language");
1.123 + addItem("dublincore.relation");
1.124 + addItem("dublincore.coverage");
1.125 + addItem("dublincore.rights");
1.126 +
1.127 + // Application-specific attributes in current use
1.128 + addItem("mime_encoding");
1.129 + addItem("apache_handler");
1.130 + addItem("Beagle.AttrTime");
1.131 + addItem("Beagle.Fingerprint");
1.132 + addItem("Beagle.MTime");
1.133 + addItem("Beagle.Uid");
1.134 + }
1.135 +
1.136 + @Override
1.137 + public Component getTableCellEditorComponent(JTable tabulka, Object hodnota, boolean vybraná, int řádek, int sloupec) {
1.138 + obnovHodnoty(hodnota);
1.139 + return this;
1.140 + }
1.141 +
1.142 + @Override
1.143 + public Object getCellEditorValue() {
1.144 + return getSelectedItem();
1.145 + }
1.146 +
1.147 + @Override
1.148 + public boolean isCellEditable(EventObject anEvent) {
1.149 + return true;
1.150 + }
1.151 +
1.152 + @Override
1.153 + public boolean shouldSelectCell(EventObject anEvent) {
1.154 + return true;
1.155 + }
1.156 +
1.157 + @Override
1.158 + public boolean stopCellEditing() {
1.159 + fireEditiaceSkončila();
1.160 + return true;
1.161 + }
1.162 +
1.163 + @Override
1.164 + public void cancelCellEditing() {
1.165 + fireEditiaceZrušena();
1.166 + }
1.167 +
1.168 + @Override
1.169 + public void addCellEditorListener(CellEditorListener l) {
1.170 + posluchače.add(CellEditorListener.class, l);
1.171 + }
1.172 +
1.173 + @Override
1.174 + public void removeCellEditorListener(CellEditorListener l) {
1.175 + posluchače.remove(CellEditorListener.class, l);
1.176 + }
1.177 +}