java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorNázvůAtributů.java
branchv_0
changeset 39 ec0e970e0830
parent 38 41e91ea94acb
child 40 1978eaf429de
     1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorNázvůAtributů.java	Sat Dec 16 19:09:35 2023 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,190 +0,0 @@
     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.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.19 - */
    1.20 -package cz.frantovo.rozsireneatributy.gui;
    1.21 -
    1.22 -import cz.frantovo.rozsireneatributy.Konfigurace;
    1.23 -import cz.frantovo.rozsireneatributy.Konfigurace.DefiniceAtributu;
    1.24 -import java.awt.Component;
    1.25 -import java.awt.event.ActionEvent;
    1.26 -import java.awt.event.ActionListener;
    1.27 -import java.util.EventObject;
    1.28 -import javax.swing.JComboBox;
    1.29 -import javax.swing.JTable;
    1.30 -import javax.swing.event.CellEditorListener;
    1.31 -import javax.swing.event.ChangeEvent;
    1.32 -import javax.swing.event.EventListenerList;
    1.33 -import javax.swing.table.TableCellEditor;
    1.34 -
    1.35 -/**
    1.36 - * Umožňuje výběr názvu atributu z předvoleného seznamu
    1.37 - * (standardizované atributy).
    1.38 - *
    1.39 - * @author Ing. František Kučera (frantovo.cz)
    1.40 - */
    1.41 -public class EditorNázvůAtributů
    1.42 -	extends JComboBox<String>
    1.43 -	implements TableCellEditor {
    1.44 -
    1.45 -	private final Konfigurace konfigurace;
    1.46 -	protected EventListenerList posluchače = new EventListenerList();
    1.47 -	protected ChangeEvent událost = new ChangeEvent(this);
    1.48 -
    1.49 -	public EditorNázvůAtributů(Konfigurace konfigurace) {
    1.50 -		super();
    1.51 -		this.konfigurace = konfigurace;
    1.52 -		setEditable(true);
    1.53 -		addActionListener(new ActionListener() {
    1.54 -
    1.55 -			@Override
    1.56 -			public void actionPerformed(ActionEvent e) {
    1.57 -				fireEditiaceSkončila();
    1.58 -			}
    1.59 -		});
    1.60 -	}
    1.61 -
    1.62 -	protected void fireEditiaceSkončila() {
    1.63 -		for (Object posluchač : posluchače.getListenerList()) {
    1.64 -			if (posluchač instanceof CellEditorListener) {
    1.65 -				((CellEditorListener) posluchač).editingStopped(událost);
    1.66 -			}
    1.67 -		}
    1.68 -	}
    1.69 -
    1.70 -	protected void fireEditiaceZrušena() {
    1.71 -		for (Object posluchač : posluchače.getListenerList()) {
    1.72 -			if (posluchač instanceof CellEditorListener) {
    1.73 -				((CellEditorListener) posluchač).editingCanceled(událost);
    1.74 -			}
    1.75 -		}
    1.76 -	}
    1.77 -
    1.78 -	/**
    1.79 -	 * TODO:
    1.80 -	 * - další standardní atributy
    1.81 -	 * - načítat z XML souboru
    1.82 -	 *
    1.83 -	 * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
    1.84 -	 */
    1.85 -	private void obnovHodnoty(Object názevAtributu) {
    1.86 -		removeAllItems();
    1.87 -
    1.88 -		if (názevAtributu == null) {
    1.89 -			názevAtributu = "";
    1.90 -		} else if (!(názevAtributu instanceof String)) {
    1.91 -			názevAtributu = String.valueOf(názevAtributu);
    1.92 -		}
    1.93 -		addItem((String) názevAtributu);
    1.94 -		setSelectedItem(názevAtributu);
    1.95 -		
    1.96 -		for (DefiniceAtributu da : konfigurace.getAtributy()) {
    1.97 -			addItem(da.getNázev());
    1.98 -		}
    1.99 -		
   1.100 -		if (!konfigurace.getAtributy().isEmpty()) return;
   1.101 -
   1.102 -		// General attributes in current use
   1.103 -		addItem("mime_type");
   1.104 -		addItem("charset");
   1.105 -		addItem("creator");
   1.106 -
   1.107 -		// Proposed metadata attributes
   1.108 -		addItem("xdg.comment");
   1.109 -		addItem("xdg.origin.url");
   1.110 -		addItem("xdg.origin.email.subject");
   1.111 -		addItem("xdg.origin.email.from");
   1.112 -		addItem("xdg.origin.email.message-id");
   1.113 -		addItem("xdg.language");
   1.114 -		addItem("xdg.creator");
   1.115 -		addItem("xdg.publisher");
   1.116 -
   1.117 -		// Proposed control attributes
   1.118 -		addItem("xdg.robots.index");
   1.119 -		addItem("xdg.robots.backup");
   1.120 -
   1.121 -		// Dublin Core
   1.122 -		addItem("dublincore.title");
   1.123 -		addItem("dublincore.creator");
   1.124 -		addItem("dublincore.subject");
   1.125 -		addItem("dublincore.description");
   1.126 -		addItem("dublincore.publisher");
   1.127 -		addItem("dublincore.contributor");
   1.128 -		addItem("dublincore.date");
   1.129 -		addItem("dublincore.type");
   1.130 -		addItem("dublincore.format");
   1.131 -		addItem("dublincore.identifier");
   1.132 -		addItem("dublincore.source");
   1.133 -		addItem("dublincore.language");
   1.134 -		addItem("dublincore.relation");
   1.135 -		addItem("dublincore.coverage");
   1.136 -		addItem("dublincore.rights");
   1.137 -
   1.138 -		// Application-specific attributes in current use
   1.139 -		addItem("mime_encoding");
   1.140 -		addItem("apache_handler");
   1.141 -		addItem("Beagle.AttrTime");
   1.142 -		addItem("Beagle.Fingerprint");
   1.143 -		addItem("Beagle.MTime");
   1.144 -		addItem("Beagle.Uid");
   1.145 -	}
   1.146 -
   1.147 -	@Override
   1.148 -	public Component getTableCellEditorComponent(
   1.149 -		JTable tabulka,
   1.150 -		Object hodnota,
   1.151 -		boolean vybraná,
   1.152 -		int řádek,
   1.153 -		int sloupec) {
   1.154 -		obnovHodnoty(hodnota);
   1.155 -		return this;
   1.156 -	}
   1.157 -
   1.158 -	@Override
   1.159 -	public Object getCellEditorValue() {
   1.160 -		return getSelectedItem();
   1.161 -	}
   1.162 -
   1.163 -	@Override
   1.164 -	public boolean isCellEditable(EventObject anEvent) {
   1.165 -		return true;
   1.166 -	}
   1.167 -
   1.168 -	@Override
   1.169 -	public boolean shouldSelectCell(EventObject anEvent) {
   1.170 -		return true;
   1.171 -	}
   1.172 -
   1.173 -	@Override
   1.174 -	public boolean stopCellEditing() {
   1.175 -		fireEditiaceSkončila();
   1.176 -		return true;
   1.177 -	}
   1.178 -
   1.179 -	@Override
   1.180 -	public void cancelCellEditing() {
   1.181 -		fireEditiaceZrušena();
   1.182 -	}
   1.183 -
   1.184 -	@Override
   1.185 -	public void addCellEditorListener(CellEditorListener l) {
   1.186 -		posluchače.add(CellEditorListener.class, l);
   1.187 -	}
   1.188 -
   1.189 -	@Override
   1.190 -	public void removeCellEditorListener(CellEditorListener l) {
   1.191 -		posluchače.remove(CellEditorListener.class, l);
   1.192 -	}
   1.193 -}