java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorNázvůAtributů.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 11 Dec 2023 00:28:30 +0100
branchv_0
changeset 28 c2ffda907125
parent 27 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java@dc5786f3482b
child 29 8d42303538ed
permissions -rw-r--r--
oprava názvu balíčku
franta-hg@22
     1
/**
franta-hg@22
     2
 * Rozšířené atributy – program na správu rozšířených atributů souborů
franta-hg@22
     3
 * Copyright © 2012 František Kučera (frantovo.cz)
franta-hg@22
     4
 *
franta-hg@22
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@22
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@27
     7
 * the Free Software Foundation, either version 3 of the License.
franta-hg@22
     8
 *
franta-hg@22
     9
 * This program is distributed in the hope that it will be useful,
franta-hg@22
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@22
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@22
    12
 * GNU General Public License for more details.
franta-hg@22
    13
 *
franta-hg@22
    14
 * You should have received a copy of the GNU General Public License
franta-hg@22
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@22
    16
 */
franta-hg@28
    17
package cz.frantovo.rozsireneatributy.gui;
franta-hg@22
    18
franta-hg@22
    19
import java.awt.Component;
franta-hg@22
    20
import java.awt.event.ActionEvent;
franta-hg@22
    21
import java.awt.event.ActionListener;
franta-hg@22
    22
import java.util.EventObject;
franta-hg@22
    23
import javax.swing.JComboBox;
franta-hg@22
    24
import javax.swing.JTable;
franta-hg@22
    25
import javax.swing.event.CellEditorListener;
franta-hg@22
    26
import javax.swing.event.ChangeEvent;
franta-hg@22
    27
import javax.swing.event.EventListenerList;
franta-hg@22
    28
import javax.swing.table.TableCellEditor;
franta-hg@22
    29
franta-hg@22
    30
/**
franta-hg@22
    31
 * Umožňuje výběr názvu atributu z předvoleného seznamu (standardizované atributy).
franta-hg@22
    32
 *
franta-hg@22
    33
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@22
    34
 */
franta-hg@22
    35
public class EditorNázvůAtributů extends JComboBox<String> implements TableCellEditor {
franta-hg@22
    36
franta-hg@22
    37
	protected EventListenerList posluchače = new EventListenerList();
franta-hg@22
    38
	protected ChangeEvent událost = new ChangeEvent(this);
franta-hg@22
    39
franta-hg@22
    40
	public EditorNázvůAtributů() {
franta-hg@22
    41
		super();
franta-hg@22
    42
		setEditable(true);
franta-hg@22
    43
		addActionListener(new ActionListener() {
franta-hg@22
    44
franta-hg@22
    45
			@Override
franta-hg@22
    46
			public void actionPerformed(ActionEvent e) {
franta-hg@22
    47
				fireEditiaceSkončila();
franta-hg@22
    48
			}
franta-hg@22
    49
		});
franta-hg@22
    50
	}
franta-hg@22
    51
franta-hg@22
    52
	protected void fireEditiaceSkončila() {
franta-hg@22
    53
		for (Object posluchač : posluchače.getListenerList()) {
franta-hg@22
    54
			if (posluchač instanceof CellEditorListener) {
franta-hg@22
    55
				((CellEditorListener) posluchač).editingStopped(událost);
franta-hg@22
    56
			}
franta-hg@22
    57
		}
franta-hg@22
    58
	}
franta-hg@22
    59
franta-hg@22
    60
	protected void fireEditiaceZrušena() {
franta-hg@22
    61
		for (Object posluchač : posluchače.getListenerList()) {
franta-hg@22
    62
			if (posluchač instanceof CellEditorListener) {
franta-hg@22
    63
				((CellEditorListener) posluchač).editingCanceled(událost);
franta-hg@22
    64
			}
franta-hg@22
    65
		}
franta-hg@22
    66
	}
franta-hg@22
    67
franta-hg@22
    68
	/**
franta-hg@22
    69
	 * TODO:
franta-hg@22
    70
	 * - další standardní atributy
franta-hg@22
    71
	 * - konfigurovatelnost
franta-hg@22
    72
	 *
franta-hg@22
    73
	 * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
franta-hg@22
    74
	 */
franta-hg@22
    75
	private void obnovHodnoty(Object názevAtributu) {
franta-hg@22
    76
		removeAllItems();
franta-hg@22
    77
franta-hg@22
    78
		if (názevAtributu == null) {
franta-hg@22
    79
			názevAtributu = "";
franta-hg@22
    80
		} else if (!(názevAtributu instanceof String)) {
franta-hg@22
    81
			názevAtributu = String.valueOf(názevAtributu);
franta-hg@22
    82
		}
franta-hg@22
    83
		addItem((String) názevAtributu);
franta-hg@22
    84
		setSelectedItem(názevAtributu);
franta-hg@22
    85
franta-hg@22
    86
franta-hg@22
    87
		// General attributes in current use
franta-hg@22
    88
		addItem("mime_type");
franta-hg@22
    89
		addItem("charset");
franta-hg@22
    90
		addItem("creator");
franta-hg@22
    91
franta-hg@22
    92
		// Proposed metadata attributes
franta-hg@22
    93
		addItem("xdg.comment");
franta-hg@22
    94
		addItem("xdg.origin.url");
franta-hg@22
    95
		addItem("xdg.origin.email.subject");
franta-hg@22
    96
		addItem("xdg.origin.email.from");
franta-hg@22
    97
		addItem("xdg.origin.email.message-id");
franta-hg@22
    98
		addItem("xdg.language");
franta-hg@22
    99
		addItem("xdg.creator");
franta-hg@22
   100
		addItem("xdg.publisher");
franta-hg@22
   101
franta-hg@22
   102
		// Proposed control attributes
franta-hg@22
   103
		addItem("xdg.robots.index");
franta-hg@22
   104
		addItem("xdg.robots.backup");
franta-hg@22
   105
franta-hg@22
   106
		// Dublin Core
franta-hg@22
   107
		addItem("dublincore.title");
franta-hg@22
   108
		addItem("dublincore.creator");
franta-hg@22
   109
		addItem("dublincore.subject");
franta-hg@22
   110
		addItem("dublincore.description");
franta-hg@22
   111
		addItem("dublincore.publisher");
franta-hg@22
   112
		addItem("dublincore.contributor");
franta-hg@22
   113
		addItem("dublincore.date");
franta-hg@22
   114
		addItem("dublincore.type");
franta-hg@22
   115
		addItem("dublincore.format");
franta-hg@22
   116
		addItem("dublincore.identifier");
franta-hg@22
   117
		addItem("dublincore.source");
franta-hg@22
   118
		addItem("dublincore.language");
franta-hg@22
   119
		addItem("dublincore.relation");
franta-hg@22
   120
		addItem("dublincore.coverage");
franta-hg@22
   121
		addItem("dublincore.rights");
franta-hg@22
   122
franta-hg@22
   123
		// Application-specific attributes in current use
franta-hg@22
   124
		addItem("mime_encoding");
franta-hg@22
   125
		addItem("apache_handler");
franta-hg@22
   126
		addItem("Beagle.AttrTime");
franta-hg@22
   127
		addItem("Beagle.Fingerprint");
franta-hg@22
   128
		addItem("Beagle.MTime");
franta-hg@22
   129
		addItem("Beagle.Uid");
franta-hg@22
   130
	}
franta-hg@22
   131
franta-hg@22
   132
	@Override
franta-hg@22
   133
	public Component getTableCellEditorComponent(JTable tabulka, Object hodnota, boolean vybraná, int řádek, int sloupec) {
franta-hg@22
   134
		obnovHodnoty(hodnota);
franta-hg@22
   135
		return this;
franta-hg@22
   136
	}
franta-hg@22
   137
franta-hg@22
   138
	@Override
franta-hg@22
   139
	public Object getCellEditorValue() {
franta-hg@22
   140
		return getSelectedItem();
franta-hg@22
   141
	}
franta-hg@22
   142
franta-hg@22
   143
	@Override
franta-hg@22
   144
	public boolean isCellEditable(EventObject anEvent) {
franta-hg@22
   145
		return true;
franta-hg@22
   146
	}
franta-hg@22
   147
franta-hg@22
   148
	@Override
franta-hg@22
   149
	public boolean shouldSelectCell(EventObject anEvent) {
franta-hg@22
   150
		return true;
franta-hg@22
   151
	}
franta-hg@22
   152
franta-hg@22
   153
	@Override
franta-hg@22
   154
	public boolean stopCellEditing() {
franta-hg@22
   155
		fireEditiaceSkončila();
franta-hg@22
   156
		return true;
franta-hg@22
   157
	}
franta-hg@22
   158
franta-hg@22
   159
	@Override
franta-hg@22
   160
	public void cancelCellEditing() {
franta-hg@22
   161
		fireEditiaceZrušena();
franta-hg@22
   162
	}
franta-hg@22
   163
franta-hg@22
   164
	@Override
franta-hg@22
   165
	public void addCellEditorListener(CellEditorListener l) {
franta-hg@22
   166
		posluchače.add(CellEditorListener.class, l);
franta-hg@22
   167
	}
franta-hg@22
   168
franta-hg@22
   169
	@Override
franta-hg@22
   170
	public void removeCellEditorListener(CellEditorListener l) {
franta-hg@22
   171
		posluchače.remove(CellEditorListener.class, l);
franta-hg@22
   172
	}
franta-hg@22
   173
}