nabídka standardizovaných atributů
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun Oct 07 15:11:42 2012 +0200 (2012-10-07)
changeset 22bf06eb899671
parent 21 c0e70d138e42
child 23 69f49b79342e
nabídka standardizovaných atributů
http://www.freedesktop.org/wiki/CommonExtendedAttributes
java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java
     1.1 --- a/java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java	Sun Oct 07 15:10:42 2012 +0200
     1.2 +++ b/java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java	Sun Oct 07 15:11:42 2012 +0200
     1.3 @@ -100,6 +100,7 @@
     1.4  				add(p, BorderLayout.CENTER);
     1.5  			} else {
     1.6  				// TODO: zobrazit chybu
     1.7 +				log.log(Level.WARNING, "Soubor neexistuje nebo nemáme práva na čtení: {0}", s);
     1.8  			}
     1.9  		} catch (IOException e) {
    1.10  			log.log(Level.WARNING, "Chyba při změně souboru.", e);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java	Sun Oct 07 15:11:42 2012 +0200
     2.3 @@ -0,0 +1,174 @@
     2.4 +/**
     2.5 + * Rozšířené atributy – program na správu rozšířených atributů souborů
     2.6 + * Copyright © 2012 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21 +package cz.frantovo.rozsireneAtributy.gui;
    2.22 +
    2.23 +import java.awt.Component;
    2.24 +import java.awt.event.ActionEvent;
    2.25 +import java.awt.event.ActionListener;
    2.26 +import java.util.EventObject;
    2.27 +import javax.swing.JComboBox;
    2.28 +import javax.swing.JTable;
    2.29 +import javax.swing.event.CellEditorListener;
    2.30 +import javax.swing.event.ChangeEvent;
    2.31 +import javax.swing.event.EventListenerList;
    2.32 +import javax.swing.table.TableCellEditor;
    2.33 +
    2.34 +/**
    2.35 + * Umožňuje výběr názvu atributu z předvoleného seznamu (standardizované atributy).
    2.36 + *
    2.37 + * @author Ing. František Kučera (frantovo.cz)
    2.38 + */
    2.39 +public class EditorNázvůAtributů extends JComboBox<String> implements TableCellEditor {
    2.40 +
    2.41 +	protected EventListenerList posluchače = new EventListenerList();
    2.42 +	protected ChangeEvent událost = new ChangeEvent(this);
    2.43 +
    2.44 +	public EditorNázvůAtributů() {
    2.45 +		super();
    2.46 +		setEditable(true);
    2.47 +		addActionListener(new ActionListener() {
    2.48 +
    2.49 +			@Override
    2.50 +			public void actionPerformed(ActionEvent e) {
    2.51 +				fireEditiaceSkončila();
    2.52 +			}
    2.53 +		});
    2.54 +	}
    2.55 +
    2.56 +	protected void fireEditiaceSkončila() {
    2.57 +		for (Object posluchač : posluchače.getListenerList()) {
    2.58 +			if (posluchač instanceof CellEditorListener) {
    2.59 +				((CellEditorListener) posluchač).editingStopped(událost);
    2.60 +			}
    2.61 +		}
    2.62 +	}
    2.63 +
    2.64 +	protected void fireEditiaceZrušena() {
    2.65 +		for (Object posluchač : posluchače.getListenerList()) {
    2.66 +			if (posluchač instanceof CellEditorListener) {
    2.67 +				((CellEditorListener) posluchač).editingCanceled(událost);
    2.68 +			}
    2.69 +		}
    2.70 +	}
    2.71 +
    2.72 +	/**
    2.73 +	 * TODO:
    2.74 +	 * - další standardní atributy
    2.75 +	 * - konfigurovatelnost
    2.76 +	 *
    2.77 +	 * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
    2.78 +	 */
    2.79 +	private void obnovHodnoty(Object názevAtributu) {
    2.80 +		removeAllItems();
    2.81 +
    2.82 +		if (názevAtributu == null) {
    2.83 +			názevAtributu = "";
    2.84 +		} else if (!(názevAtributu instanceof String)) {
    2.85 +			názevAtributu = String.valueOf(názevAtributu);
    2.86 +		}
    2.87 +		addItem((String) názevAtributu);
    2.88 +		setSelectedItem(názevAtributu);
    2.89 +
    2.90 +
    2.91 +		// General attributes in current use
    2.92 +		addItem("mime_type");
    2.93 +		addItem("charset");
    2.94 +		addItem("creator");
    2.95 +
    2.96 +		// Proposed metadata attributes
    2.97 +		addItem("xdg.comment");
    2.98 +		addItem("xdg.origin.url");
    2.99 +		addItem("xdg.origin.email.subject");
   2.100 +		addItem("xdg.origin.email.from");
   2.101 +		addItem("xdg.origin.email.message-id");
   2.102 +		addItem("xdg.language");
   2.103 +		addItem("xdg.creator");
   2.104 +		addItem("xdg.publisher");
   2.105 +
   2.106 +		// Proposed control attributes
   2.107 +		addItem("xdg.robots.index");
   2.108 +		addItem("xdg.robots.backup");
   2.109 +
   2.110 +		// Dublin Core
   2.111 +		addItem("dublincore.title");
   2.112 +		addItem("dublincore.creator");
   2.113 +		addItem("dublincore.subject");
   2.114 +		addItem("dublincore.description");
   2.115 +		addItem("dublincore.publisher");
   2.116 +		addItem("dublincore.contributor");
   2.117 +		addItem("dublincore.date");
   2.118 +		addItem("dublincore.type");
   2.119 +		addItem("dublincore.format");
   2.120 +		addItem("dublincore.identifier");
   2.121 +		addItem("dublincore.source");
   2.122 +		addItem("dublincore.language");
   2.123 +		addItem("dublincore.relation");
   2.124 +		addItem("dublincore.coverage");
   2.125 +		addItem("dublincore.rights");
   2.126 +
   2.127 +		// Application-specific attributes in current use
   2.128 +		addItem("mime_encoding");
   2.129 +		addItem("apache_handler");
   2.130 +		addItem("Beagle.AttrTime");
   2.131 +		addItem("Beagle.Fingerprint");
   2.132 +		addItem("Beagle.MTime");
   2.133 +		addItem("Beagle.Uid");
   2.134 +	}
   2.135 +
   2.136 +	@Override
   2.137 +	public Component getTableCellEditorComponent(JTable tabulka, Object hodnota, boolean vybraná, int řádek, int sloupec) {
   2.138 +		obnovHodnoty(hodnota);
   2.139 +		return this;
   2.140 +	}
   2.141 +
   2.142 +	@Override
   2.143 +	public Object getCellEditorValue() {
   2.144 +		return getSelectedItem();
   2.145 +	}
   2.146 +
   2.147 +	@Override
   2.148 +	public boolean isCellEditable(EventObject anEvent) {
   2.149 +		return true;
   2.150 +	}
   2.151 +
   2.152 +	@Override
   2.153 +	public boolean shouldSelectCell(EventObject anEvent) {
   2.154 +		return true;
   2.155 +	}
   2.156 +
   2.157 +	@Override
   2.158 +	public boolean stopCellEditing() {
   2.159 +		fireEditiaceSkončila();
   2.160 +		return true;
   2.161 +	}
   2.162 +
   2.163 +	@Override
   2.164 +	public void cancelCellEditing() {
   2.165 +		fireEditiaceZrušena();
   2.166 +	}
   2.167 +
   2.168 +	@Override
   2.169 +	public void addCellEditorListener(CellEditorListener l) {
   2.170 +		posluchače.add(CellEditorListener.class, l);
   2.171 +	}
   2.172 +
   2.173 +	@Override
   2.174 +	public void removeCellEditorListener(CellEditorListener l) {
   2.175 +		posluchače.remove(CellEditorListener.class, l);
   2.176 +	}
   2.177 +}
     3.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java	Sun Oct 07 15:10:42 2012 +0200
     3.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java	Sun Oct 07 15:11:42 2012 +0200
     3.3 @@ -28,6 +28,7 @@
     3.4  import java.util.HashSet;
     3.5  import java.util.List;
     3.6  import java.util.ResourceBundle;
     3.7 +import java.util.Set;
     3.8  import java.util.logging.Level;
     3.9  import java.util.logging.Logger;
    3.10  import javax.swing.event.TableModelEvent;
    3.11 @@ -43,9 +44,9 @@
    3.12  	private static final Logger log = Logger.getLogger(Model.class.getSimpleName());
    3.13  	private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
    3.14  	private String[] sloupečky = {překlady.getString("tabulka.název"), překlady.getString("tabulka.hodnota")};
    3.15 -	private HashSet<TableModelListener> posluchače = new HashSet<TableModelListener>();
    3.16 +	private Set<TableModelListener> posluchače = new HashSet<>();
    3.17  	private UserDefinedFileAttributeView souborovýSystém;
    3.18 -	private ArrayList<Atribut> atributy = new ArrayList<Atribut>();
    3.19 +	private List<Atribut> atributy = new ArrayList<>();
    3.20  
    3.21  	public Model(File soubor) throws IOException {
    3.22  		Path cesta = soubor.toPath();
    3.23 @@ -54,26 +55,32 @@
    3.24  		načtiAtributy();
    3.25  	}
    3.26  
    3.27 +	@Override
    3.28  	public int getRowCount() {
    3.29  		return atributy.size();
    3.30  	}
    3.31  
    3.32 +	@Override
    3.33  	public int getColumnCount() {
    3.34  		return sloupečky.length;
    3.35  	}
    3.36  
    3.37 +	@Override
    3.38  	public String getColumnName(int n) {
    3.39  		return sloupečky[n];
    3.40  	}
    3.41  
    3.42 +	@Override
    3.43  	public Class<?> getColumnClass(int n) {
    3.44  		return String.class;
    3.45  	}
    3.46  
    3.47 +	@Override
    3.48  	public boolean isCellEditable(int m, int n) {
    3.49  		return true;
    3.50  	}
    3.51  
    3.52 +	@Override
    3.53  	public Object getValueAt(int m, int n) {
    3.54  		if (n == 0) {
    3.55  			return atributy.get(m).getKlíč();
    3.56 @@ -84,6 +91,7 @@
    3.57  		}
    3.58  	}
    3.59  
    3.60 +	@Override
    3.61  	public void setValueAt(Object hodnota, int m, int n) {
    3.62  		Atribut a = atributy.get(m);
    3.63  		try {
    3.64 @@ -111,10 +119,12 @@
    3.65  		}
    3.66  	}
    3.67  
    3.68 +	@Override
    3.69  	public void addTableModelListener(TableModelListener l) {
    3.70  		posluchače.add(l);
    3.71  	}
    3.72  
    3.73 +	@Override
    3.74  	public void removeTableModelListener(TableModelListener l) {
    3.75  		posluchače.remove(l);
    3.76  	}
     4.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java	Sun Oct 07 15:10:42 2012 +0200
     4.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java	Sun Oct 07 15:11:42 2012 +0200
     4.3 @@ -1,19 +1,19 @@
     4.4  /**
     4.5   * Rozšířené atributy – program na správu rozšířených atributů souborů
     4.6   * Copyright © 2012 František Kučera (frantovo.cz)
     4.7 - * 
     4.8 + *
     4.9   * This program is free software: you can redistribute it and/or modify
    4.10   * it under the terms of the GNU General Public License as published by
    4.11   * the Free Software Foundation, either version 3 of the License, or
    4.12   * (at your option) any later version.
    4.13 - * 
    4.14 + *
    4.15   * This program is distributed in the hope that it will be useful,
    4.16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    4.19   * GNU General Public License for more details.
    4.20 - * 
    4.21 + *
    4.22   * You should have received a copy of the GNU General Public License
    4.23 - * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    4.24 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    4.25   */
    4.26  package cz.frantovo.rozsireneAtributy.gui;
    4.27  
    4.28 @@ -45,12 +45,14 @@
    4.29  		initComponents();
    4.30  
    4.31  		tabulka = new JTable(model);
    4.32 +		tabulka.getColumnModel().getColumn(0).setCellEditor(new EditorNázvůAtributů());
    4.33  		tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    4.34  		posuvnýPanel.setViewportView(tabulka);
    4.35  
    4.36  		/** Výběr aktuálního atributu v tabulce */
    4.37  		tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    4.38  
    4.39 +			@Override
    4.40  			public void valueChanged(ListSelectionEvent e) {
    4.41  				int řádek = tabulka.getSelectedRow();
    4.42  				if (řádek < 0) {