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