oprava názvu balíčku v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 11 Dec 2023 00:28:30 +0100
branchv_0
changeset 28c2ffda907125
parent 27 dc5786f3482b
child 29 8d42303538ed
oprava názvu balíčku
java/rozsirene-atributy/nbproject/project.properties
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady.properties
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_cs.properties
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_en.properties
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.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.form
java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java
java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Atribut.java
java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady.properties
java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_cs.properties
java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_en.properties
java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Startér.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.form
java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Panel.java
     1.1 --- a/java/rozsirene-atributy/nbproject/project.properties	Mon Dec 11 00:10:33 2023 +0100
     1.2 +++ b/java/rozsirene-atributy/nbproject/project.properties	Mon Dec 11 00:28:30 2023 +0100
     1.3 @@ -28,7 +28,7 @@
     1.4  jar.archive.disabled=${jnlp.enabled}
     1.5  javadoc.author=false
     1.6  endorsed.classpath=
     1.7 -main.class=cz.frantovo.rozsireneAtributy.Start\u00E9r
     1.8 +main.class=cz.frantovo.rozsireneatributy.Start\u00e9r
     1.9  junit.selected.version=4
    1.10  source.encoding=UTF-8
    1.11  javac.source=1.7
     2.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java	Mon Dec 11 00:10:33 2023 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,94 +0,0 @@
     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.
    2.11 - * 
    2.12 - * This program is distributed in the hope that it will be useful,
    2.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 - * GNU General Public License for more details.
    2.16 - * 
    2.17 - * You should have received a copy of the GNU General Public License
    2.18 - * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2.19 - */
    2.20 -package cz.frantovo.rozsireneAtributy;
    2.21 -
    2.22 -import java.nio.ByteBuffer;
    2.23 -import java.nio.charset.Charset;
    2.24 -
    2.25 -public class Atribut {
    2.26 -
    2.27 -	private String klíč;
    2.28 -	private String hodnota;
    2.29 -
    2.30 -	public Atribut(String klíč, String hodnota) {
    2.31 -		this.klíč = klíč;
    2.32 -		this.hodnota = hodnota;
    2.33 -	}
    2.34 -
    2.35 -	public Atribut(String klíč, ByteBuffer hodnota) {
    2.36 -		this.klíč = klíč;
    2.37 -		setHodnota(hodnota);
    2.38 -	}
    2.39 -
    2.40 -	public Atribut() {
    2.41 -	}
    2.42 -
    2.43 -	public String getKlíč() {
    2.44 -		return klíč;
    2.45 -	}
    2.46 -
    2.47 -	public void setKlíč(String klíč) {
    2.48 -		this.klíč = klíč;
    2.49 -	}
    2.50 -
    2.51 -	/**
    2.52 -	 * Název atributu musí být nenulový a mít nějakou délku, aby šel uložit
    2.53 -	 * TODO: další kontroly?
    2.54 -	 * @return jestli je platný
    2.55 -	 */
    2.56 -	public boolean isPlatnýKlíč() {
    2.57 -		return klíč != null && klíč.length() > 0;
    2.58 -	}
    2.59 -
    2.60 -	/**
    2.61 -	 * nulová hodnota → smazání atributu
    2.62 -	 * (ale může být prázdný řetězec)
    2.63 -	 * @return jestli je platná
    2.64 -	 */
    2.65 -	public boolean isPlatnáHodnota() {
    2.66 -		return hodnota != null;
    2.67 -	}
    2.68 -
    2.69 -	public String getHodnota() {
    2.70 -		return hodnota;
    2.71 -	}
    2.72 -
    2.73 -	public final ByteBuffer getHodnotaBajty() {
    2.74 -		return zakóduj(getHodnota());
    2.75 -	}
    2.76 -
    2.77 -	public void setHodnota(String hodnota) {
    2.78 -		this.hodnota = hodnota;
    2.79 -	}
    2.80 -
    2.81 -	public final void setHodnota(ByteBuffer hodnota) {
    2.82 -		setHodnota(dekóduj(hodnota));
    2.83 -	}
    2.84 -
    2.85 -	private static String dekóduj(ByteBuffer bajty) {
    2.86 -		bajty.flip();
    2.87 -		return Charset.defaultCharset().decode(bajty).toString();
    2.88 -	}
    2.89 -
    2.90 -	private static ByteBuffer zakóduj(String text) {
    2.91 -		if (text == null) {
    2.92 -			return null;
    2.93 -		} else {
    2.94 -			return Charset.defaultCharset().encode(text);
    2.95 -		}
    2.96 -	}
    2.97 -}
     3.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady.properties	Mon Dec 11 00:10:33 2023 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,1 +0,0 @@
     3.4 -Překlady_cs.properties
     3.5 \ No newline at end of file
     4.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_cs.properties	Mon Dec 11 00:10:33 2023 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,14 +0,0 @@
     4.4 -titulek=Roz\u0161\u00ed\u0159en\u00e9 stributy souboru: {0}
     4.5 -
     4.6 -chyba.titulek=Chyba
     4.7 -chyba.souborNeexistuje=Soubor neexistuje: {0}
     4.8 -chyba.chyb\u00edParametr=O\u010dek\u00e1v\u00e1m pr\u00e1v\u011b jeden parametr \u2013 n\u00e1zev souboru.
     4.9 -chyba.nepoda\u0159iloSeSmazat=Nepoda\u0159ilo se smazat atribut.
    4.10 -chyba.nepoda\u0159iloSeNa\u010d\u00edst=Nepoda\u0159ilo se na\u010d\u00edst atributy.
    4.11 -
    4.12 -tabulka.n\u00e1zev=N\u00e1zev
    4.13 -tabulka.hodnota=Hodnota
    4.14 -
    4.15 -p\u0159idatAtribut=P\u0159idat atribut
    4.16 -smazatAtribut=Smazat atribut
    4.17 -znovuNa\u010d\u00edst=Znovu na\u010d\u00edst
     5.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_en.properties	Mon Dec 11 00:10:33 2023 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,14 +0,0 @@
     5.4 -titulek=Extended Attributes of file: {0}
     5.5 -
     5.6 -chyba.titulek=Error
     5.7 -chyba.souborNeexistuje=File does not exist: {0}
     5.8 -chyba.chyb\u00edParametr=Expecting one parameter \u2013 file name.
     5.9 -chyba.nepoda\u0159iloSeSmazat=Failed to delete the attribute.
    5.10 -chyba.nepoda\u0159iloSeNa\u010d\u00edst=Failed to load attributes.
    5.11 -
    5.12 -tabulka.n\u00e1zev=Name
    5.13 -tabulka.hodnota=Value
    5.14 -
    5.15 -p\u0159idatAtribut=Add attribute
    5.16 -smazatAtribut=Delete attribute
    5.17 -znovuNa\u010d\u00edst=Reload all
     6.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.java	Mon Dec 11 00:10:33 2023 +0100
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,100 +0,0 @@
     6.4 -/**
     6.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
     6.6 - * Copyright © 2012 František Kučera (frantovo.cz)
     6.7 - * 
     6.8 - * This program is free software: you can redistribute it and/or modify
     6.9 - * it under the terms of the GNU General Public License as published by
    6.10 - * the Free Software Foundation, either version 3 of the License.
    6.11 - * 
    6.12 - * This program is distributed in the hope that it will be useful,
    6.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 - * GNU General Public License for more details.
    6.16 - * 
    6.17 - * You should have received a copy of the GNU General Public License
    6.18 - * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    6.19 - */
    6.20 -package cz.frantovo.rozsireneAtributy;
    6.21 -
    6.22 -import cz.frantovo.rozsireneAtributy.gui.Model;
    6.23 -import cz.frantovo.rozsireneAtributy.gui.Panel;
    6.24 -import java.awt.BorderLayout;
    6.25 -import java.awt.event.ActionEvent;
    6.26 -import java.awt.event.ActionListener;
    6.27 -import java.awt.event.KeyEvent;
    6.28 -import java.io.File;
    6.29 -import java.io.IOException;
    6.30 -import java.text.MessageFormat;
    6.31 -import java.util.ResourceBundle;
    6.32 -import java.util.logging.Level;
    6.33 -import java.util.logging.Logger;
    6.34 -import javax.swing.JComponent;
    6.35 -import javax.swing.JFrame;
    6.36 -import javax.swing.JOptionPane;
    6.37 -import javax.swing.KeyStroke;
    6.38 -
    6.39 -/**
    6.40 - * Spouštěč programu
    6.41 - *
    6.42 - * http://freedesktop.org/wiki/CommonExtendedAttributes
    6.43 - * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
    6.44 - * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really
    6.45 - *
    6.46 - * $ setfattr -n "user.fiki.pozdrav" -v 'Dobrý den!' pokus.txt
    6.47 - * (v javě pak pracujeme s klíči bez předpony „user.“)
    6.48 - *
    6.49 - * @author fiki
    6.50 - */
    6.51 -public class Startér {
    6.52 -
    6.53 -	private static final Logger log = Logger.getLogger(Startér.class.getSimpleName());
    6.54 -	private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
    6.55 -
    6.56 -	/**
    6.57 -	 * @param args název souboru
    6.58 -	 * @throws IOException TODO: ošetřit výjimku
    6.59 -	 */
    6.60 -	public static void main(String[] args) throws IOException {
    6.61 -
    6.62 -
    6.63 -		if (args.length == 1 && args[0].length() > 0) {
    6.64 -			File soubor = new File(args[0]);
    6.65 -
    6.66 -			if (soubor.exists()) {
    6.67 -				log.log(Level.INFO, "Pracuji se souborem: {0}", soubor);
    6.68 -
    6.69 -				Model model = new Model(soubor);
    6.70 -
    6.71 -				final JFrame f = new JFrame();
    6.72 -				Panel p = new Panel(model);
    6.73 -
    6.74 -				f.setLayout(new BorderLayout());
    6.75 -				f.add(p, BorderLayout.CENTER);
    6.76 -
    6.77 -				/** Ukončení programu klávesou Escape */
    6.78 -				f.getRootPane().registerKeyboardAction(new ActionListener() {
    6.79 -
    6.80 -					public void actionPerformed(ActionEvent ae) {
    6.81 -						f.dispose();
    6.82 -					}
    6.83 -				}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    6.84 -
    6.85 -				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    6.86 -				f.setTitle(MessageFormat.format(překlady.getString("titulek"), soubor));
    6.87 -				f.setSize(640, 240);
    6.88 -				f.setLocationRelativeTo(null);
    6.89 -				f.setVisible(true);
    6.90 -			} else {
    6.91 -				ukončiChybou(MessageFormat.format(překlady.getString("chyba.souborNeexistuje"), soubor));
    6.92 -			}
    6.93 -		} else {
    6.94 -			ukončiChybou(překlady.getString("chyba.chybíParametr"));
    6.95 -		}
    6.96 -	}
    6.97 -
    6.98 -	private static void ukončiChybou(String hláška) {
    6.99 -		log.log(Level.SEVERE, hláška);
   6.100 -		JOptionPane.showMessageDialog(null, hláška, překlady.getString("chyba.titulek"), JOptionPane.ERROR_MESSAGE);
   6.101 -		System.exit(1);
   6.102 -	}
   6.103 -}
     7.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java	Mon Dec 11 00:10:33 2023 +0100
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,173 +0,0 @@
     7.4 -/**
     7.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
     7.6 - * Copyright © 2012 František Kučera (frantovo.cz)
     7.7 - *
     7.8 - * This program is free software: you can redistribute it and/or modify
     7.9 - * it under the terms of the GNU General Public License as published by
    7.10 - * the Free Software Foundation, either version 3 of the License.
    7.11 - *
    7.12 - * This program is distributed in the hope that it will be useful,
    7.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    7.15 - * GNU General Public License for more details.
    7.16 - *
    7.17 - * You should have received a copy of the GNU General Public License
    7.18 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    7.19 - */
    7.20 -package cz.frantovo.rozsireneAtributy.gui;
    7.21 -
    7.22 -import java.awt.Component;
    7.23 -import java.awt.event.ActionEvent;
    7.24 -import java.awt.event.ActionListener;
    7.25 -import java.util.EventObject;
    7.26 -import javax.swing.JComboBox;
    7.27 -import javax.swing.JTable;
    7.28 -import javax.swing.event.CellEditorListener;
    7.29 -import javax.swing.event.ChangeEvent;
    7.30 -import javax.swing.event.EventListenerList;
    7.31 -import javax.swing.table.TableCellEditor;
    7.32 -
    7.33 -/**
    7.34 - * Umožňuje výběr názvu atributu z předvoleného seznamu (standardizované atributy).
    7.35 - *
    7.36 - * @author Ing. František Kučera (frantovo.cz)
    7.37 - */
    7.38 -public class EditorNázvůAtributů extends JComboBox<String> implements TableCellEditor {
    7.39 -
    7.40 -	protected EventListenerList posluchače = new EventListenerList();
    7.41 -	protected ChangeEvent událost = new ChangeEvent(this);
    7.42 -
    7.43 -	public EditorNázvůAtributů() {
    7.44 -		super();
    7.45 -		setEditable(true);
    7.46 -		addActionListener(new ActionListener() {
    7.47 -
    7.48 -			@Override
    7.49 -			public void actionPerformed(ActionEvent e) {
    7.50 -				fireEditiaceSkončila();
    7.51 -			}
    7.52 -		});
    7.53 -	}
    7.54 -
    7.55 -	protected void fireEditiaceSkončila() {
    7.56 -		for (Object posluchač : posluchače.getListenerList()) {
    7.57 -			if (posluchač instanceof CellEditorListener) {
    7.58 -				((CellEditorListener) posluchač).editingStopped(událost);
    7.59 -			}
    7.60 -		}
    7.61 -	}
    7.62 -
    7.63 -	protected void fireEditiaceZrušena() {
    7.64 -		for (Object posluchač : posluchače.getListenerList()) {
    7.65 -			if (posluchač instanceof CellEditorListener) {
    7.66 -				((CellEditorListener) posluchač).editingCanceled(událost);
    7.67 -			}
    7.68 -		}
    7.69 -	}
    7.70 -
    7.71 -	/**
    7.72 -	 * TODO:
    7.73 -	 * - další standardní atributy
    7.74 -	 * - konfigurovatelnost
    7.75 -	 *
    7.76 -	 * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
    7.77 -	 */
    7.78 -	private void obnovHodnoty(Object názevAtributu) {
    7.79 -		removeAllItems();
    7.80 -
    7.81 -		if (názevAtributu == null) {
    7.82 -			názevAtributu = "";
    7.83 -		} else if (!(názevAtributu instanceof String)) {
    7.84 -			názevAtributu = String.valueOf(názevAtributu);
    7.85 -		}
    7.86 -		addItem((String) názevAtributu);
    7.87 -		setSelectedItem(názevAtributu);
    7.88 -
    7.89 -
    7.90 -		// General attributes in current use
    7.91 -		addItem("mime_type");
    7.92 -		addItem("charset");
    7.93 -		addItem("creator");
    7.94 -
    7.95 -		// Proposed metadata attributes
    7.96 -		addItem("xdg.comment");
    7.97 -		addItem("xdg.origin.url");
    7.98 -		addItem("xdg.origin.email.subject");
    7.99 -		addItem("xdg.origin.email.from");
   7.100 -		addItem("xdg.origin.email.message-id");
   7.101 -		addItem("xdg.language");
   7.102 -		addItem("xdg.creator");
   7.103 -		addItem("xdg.publisher");
   7.104 -
   7.105 -		// Proposed control attributes
   7.106 -		addItem("xdg.robots.index");
   7.107 -		addItem("xdg.robots.backup");
   7.108 -
   7.109 -		// Dublin Core
   7.110 -		addItem("dublincore.title");
   7.111 -		addItem("dublincore.creator");
   7.112 -		addItem("dublincore.subject");
   7.113 -		addItem("dublincore.description");
   7.114 -		addItem("dublincore.publisher");
   7.115 -		addItem("dublincore.contributor");
   7.116 -		addItem("dublincore.date");
   7.117 -		addItem("dublincore.type");
   7.118 -		addItem("dublincore.format");
   7.119 -		addItem("dublincore.identifier");
   7.120 -		addItem("dublincore.source");
   7.121 -		addItem("dublincore.language");
   7.122 -		addItem("dublincore.relation");
   7.123 -		addItem("dublincore.coverage");
   7.124 -		addItem("dublincore.rights");
   7.125 -
   7.126 -		// Application-specific attributes in current use
   7.127 -		addItem("mime_encoding");
   7.128 -		addItem("apache_handler");
   7.129 -		addItem("Beagle.AttrTime");
   7.130 -		addItem("Beagle.Fingerprint");
   7.131 -		addItem("Beagle.MTime");
   7.132 -		addItem("Beagle.Uid");
   7.133 -	}
   7.134 -
   7.135 -	@Override
   7.136 -	public Component getTableCellEditorComponent(JTable tabulka, Object hodnota, boolean vybraná, int řádek, int sloupec) {
   7.137 -		obnovHodnoty(hodnota);
   7.138 -		return this;
   7.139 -	}
   7.140 -
   7.141 -	@Override
   7.142 -	public Object getCellEditorValue() {
   7.143 -		return getSelectedItem();
   7.144 -	}
   7.145 -
   7.146 -	@Override
   7.147 -	public boolean isCellEditable(EventObject anEvent) {
   7.148 -		return true;
   7.149 -	}
   7.150 -
   7.151 -	@Override
   7.152 -	public boolean shouldSelectCell(EventObject anEvent) {
   7.153 -		return true;
   7.154 -	}
   7.155 -
   7.156 -	@Override
   7.157 -	public boolean stopCellEditing() {
   7.158 -		fireEditiaceSkončila();
   7.159 -		return true;
   7.160 -	}
   7.161 -
   7.162 -	@Override
   7.163 -	public void cancelCellEditing() {
   7.164 -		fireEditiaceZrušena();
   7.165 -	}
   7.166 -
   7.167 -	@Override
   7.168 -	public void addCellEditorListener(CellEditorListener l) {
   7.169 -		posluchače.add(CellEditorListener.class, l);
   7.170 -	}
   7.171 -
   7.172 -	@Override
   7.173 -	public void removeCellEditorListener(CellEditorListener l) {
   7.174 -		posluchače.remove(CellEditorListener.class, l);
   7.175 -	}
   7.176 -}
     8.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java	Mon Dec 11 00:10:33 2023 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,168 +0,0 @@
     8.4 -/**
     8.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
     8.6 - * Copyright © 2012 František Kučera (frantovo.cz)
     8.7 - * 
     8.8 - * This program is free software: you can redistribute it and/or modify
     8.9 - * it under the terms of the GNU General Public License as published by
    8.10 - * the Free Software Foundation, either version 3 of the License.
    8.11 - * 
    8.12 - * This program is distributed in the hope that it will be useful,
    8.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 - * GNU General Public License for more details.
    8.16 - * 
    8.17 - * You should have received a copy of the GNU General Public License
    8.18 - * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    8.19 - */
    8.20 -package cz.frantovo.rozsireneAtributy.gui;
    8.21 -
    8.22 -import cz.frantovo.rozsireneAtributy.Atribut;
    8.23 -import java.io.File;
    8.24 -import java.io.IOException;
    8.25 -import java.nio.ByteBuffer;
    8.26 -import java.nio.file.Path;
    8.27 -import java.nio.file.attribute.UserDefinedFileAttributeView;
    8.28 -import java.nio.file.spi.FileSystemProvider;
    8.29 -import java.util.ArrayList;
    8.30 -import java.util.HashSet;
    8.31 -import java.util.List;
    8.32 -import java.util.ResourceBundle;
    8.33 -import java.util.Set;
    8.34 -import java.util.logging.Level;
    8.35 -import java.util.logging.Logger;
    8.36 -import javax.swing.event.TableModelEvent;
    8.37 -import javax.swing.event.TableModelListener;
    8.38 -import javax.swing.table.TableModel;
    8.39 -
    8.40 -/**
    8.41 - *
    8.42 - * @author fiki
    8.43 - */
    8.44 -public class Model implements TableModel {
    8.45 -
    8.46 -	private static final Logger log = Logger.getLogger(Model.class.getSimpleName());
    8.47 -	private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
    8.48 -	private String[] sloupečky = {překlady.getString("tabulka.název"), překlady.getString("tabulka.hodnota")};
    8.49 -	private Set<TableModelListener> posluchače = new HashSet<>();
    8.50 -	private UserDefinedFileAttributeView souborovýSystém;
    8.51 -	private List<Atribut> atributy = new ArrayList<>();
    8.52 -
    8.53 -	public Model(File soubor) throws IOException {
    8.54 -		Path cesta = soubor.toPath();
    8.55 -		FileSystemProvider posyktovatelFS = cesta.getFileSystem().provider();
    8.56 -		souborovýSystém = posyktovatelFS.getFileAttributeView(cesta, UserDefinedFileAttributeView.class);
    8.57 -		načtiAtributy();
    8.58 -	}
    8.59 -
    8.60 -	@Override
    8.61 -	public int getRowCount() {
    8.62 -		return atributy.size();
    8.63 -	}
    8.64 -
    8.65 -	@Override
    8.66 -	public int getColumnCount() {
    8.67 -		return sloupečky.length;
    8.68 -	}
    8.69 -
    8.70 -	@Override
    8.71 -	public String getColumnName(int n) {
    8.72 -		return sloupečky[n];
    8.73 -	}
    8.74 -
    8.75 -	@Override
    8.76 -	public Class<?> getColumnClass(int n) {
    8.77 -		return String.class;
    8.78 -	}
    8.79 -
    8.80 -	@Override
    8.81 -	public boolean isCellEditable(int m, int n) {
    8.82 -		return true;
    8.83 -	}
    8.84 -
    8.85 -	@Override
    8.86 -	public Object getValueAt(int m, int n) {
    8.87 -		if (n == 0) {
    8.88 -			return atributy.get(m).getKlíč();
    8.89 -		} else if (n == 1) {
    8.90 -			return atributy.get(m).getHodnota();
    8.91 -		} else {
    8.92 -			return null;
    8.93 -		}
    8.94 -	}
    8.95 -
    8.96 -	@Override
    8.97 -	public void setValueAt(Object hodnota, int m, int n) {
    8.98 -		Atribut a = atributy.get(m);
    8.99 -		try {
   8.100 -			if (n == 0) {
   8.101 -				/** Měníme klíč – název atributu */
   8.102 -				String novýKlíč = String.valueOf(hodnota);
   8.103 -				if (!novýKlíč.equals(a.getKlíč())) {
   8.104 -					if (a.isPlatnýKlíč()) {
   8.105 -						souborovýSystém.delete(a.getKlíč());
   8.106 -					}
   8.107 -					a.setKlíč(novýKlíč);
   8.108 -					if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) {
   8.109 -						souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty());
   8.110 -					}
   8.111 -				}
   8.112 -			} else if (n == 1) {
   8.113 -				/** Měníme hodnotu atributu */
   8.114 -				a.setHodnota(String.valueOf(hodnota));
   8.115 -				if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) {
   8.116 -					souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty());
   8.117 -				}
   8.118 -			}
   8.119 -		} catch (IOException e) {
   8.120 -			log.log(Level.SEVERE, "Selhalo ukládání atributu na souborový systém", e);
   8.121 -		}
   8.122 -	}
   8.123 -
   8.124 -	@Override
   8.125 -	public void addTableModelListener(TableModelListener l) {
   8.126 -		posluchače.add(l);
   8.127 -	}
   8.128 -
   8.129 -	@Override
   8.130 -	public void removeTableModelListener(TableModelListener l) {
   8.131 -		posluchače.remove(l);
   8.132 -	}
   8.133 -
   8.134 -	/**
   8.135 -	 * @param m číslo řádku
   8.136 -	 * @return atribut, který se na něm nachází
   8.137 -	 */
   8.138 -	public Atribut getAtribut(int m) {
   8.139 -		return atributy.get(m);
   8.140 -	}
   8.141 -
   8.142 -	public void přidejAtribut(Atribut a) {
   8.143 -		atributy.add(a);
   8.144 -		upozorniPosluchače();
   8.145 -	}
   8.146 -
   8.147 -	public void odeberAtribut(Atribut a) throws IOException {
   8.148 -		atributy.remove(a);
   8.149 -		if (a.isPlatnýKlíč()) {
   8.150 -			souborovýSystém.delete(a.getKlíč());
   8.151 -		}
   8.152 -		upozorniPosluchače();
   8.153 -	}
   8.154 -
   8.155 -	public final void načtiAtributy() throws IOException {
   8.156 -		List<String> jménaAtributů = souborovýSystém.list();
   8.157 -		atributy.clear();
   8.158 -		for (String jménoAtributu : jménaAtributů) {
   8.159 -			ByteBuffer hodnotaAtributu = ByteBuffer.allocate(souborovýSystém.size(jménoAtributu));
   8.160 -			souborovýSystém.read(jménoAtributu, hodnotaAtributu);
   8.161 -			atributy.add(new Atribut(jménoAtributu, hodnotaAtributu));
   8.162 -		}
   8.163 -		upozorniPosluchače();
   8.164 -	}
   8.165 -
   8.166 -	private void upozorniPosluchače() {
   8.167 -		for (TableModelListener p : posluchače) {
   8.168 -			p.tableChanged(new TableModelEvent(this));
   8.169 -		}
   8.170 -	}
   8.171 -}
     9.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.form	Mon Dec 11 00:10:33 2023 +0100
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,86 +0,0 @@
     9.4 -<?xml version="1.0" encoding="UTF-8" ?>
     9.5 -
     9.6 -<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
     9.7 -  <AuxValues>
     9.8 -    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
     9.9 -    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
    9.10 -    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
    9.11 -    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
    9.12 -    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
    9.13 -    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
    9.14 -    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
    9.15 -    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
    9.16 -    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
    9.17 -  </AuxValues>
    9.18 -
    9.19 -  <Layout>
    9.20 -    <DimensionLayout dim="0">
    9.21 -      <Group type="103" groupAlignment="0" attributes="0">
    9.22 -          <Group type="102" alignment="0" attributes="0">
    9.23 -              <EmptySpace max="-2" attributes="0"/>
    9.24 -              <Component id="tlačítkoPřidat" min="-2" max="-2" attributes="0"/>
    9.25 -              <EmptySpace max="-2" attributes="0"/>
    9.26 -              <Component id="tlačítkoSmazat" min="-2" max="-2" attributes="0"/>
    9.27 -              <EmptySpace max="-2" attributes="0"/>
    9.28 -              <Component id="tlačítkoZnovuNačíst" min="-2" max="-2" attributes="0"/>
    9.29 -              <EmptySpace pref="186" max="32767" attributes="0"/>
    9.30 -          </Group>
    9.31 -          <Component id="posuvnýPanel" alignment="0" pref="543" max="32767" attributes="0"/>
    9.32 -      </Group>
    9.33 -    </DimensionLayout>
    9.34 -    <DimensionLayout dim="1">
    9.35 -      <Group type="103" groupAlignment="0" attributes="0">
    9.36 -          <Group type="102" alignment="1" attributes="0">
    9.37 -              <Component id="posuvnýPanel" pref="277" max="32767" attributes="0"/>
    9.38 -              <EmptySpace max="-2" attributes="0"/>
    9.39 -              <Group type="103" groupAlignment="3" attributes="0">
    9.40 -                  <Component id="tlačítkoPřidat" alignment="3" min="-2" max="-2" attributes="0"/>
    9.41 -                  <Component id="tlačítkoSmazat" alignment="3" min="-2" max="-2" attributes="0"/>
    9.42 -                  <Component id="tlačítkoZnovuNačíst" alignment="3" min="-2" max="-2" attributes="0"/>
    9.43 -              </Group>
    9.44 -              <EmptySpace max="-2" attributes="0"/>
    9.45 -          </Group>
    9.46 -      </Group>
    9.47 -    </DimensionLayout>
    9.48 -  </Layout>
    9.49 -  <SubComponents>
    9.50 -    <Container class="javax.swing.JScrollPane" name="posuvn&#xfd;Panel">
    9.51 -
    9.52 -      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
    9.53 -    </Container>
    9.54 -    <Component class="javax.swing.JButton" name="tla&#x10d;&#xed;tkoP&#x159;idat">
    9.55 -      <Properties>
    9.56 -        <Property name="mnemonic" type="int" value="112"/>
    9.57 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
    9.58 -          <ResourceString bundle="cz/frantovo/rozsireneAtributy/P&#x159;eklady.properties" key="p&#x159;idatAtribut" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
    9.59 -        </Property>
    9.60 -      </Properties>
    9.61 -      <Events>
    9.62 -        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tla&#x10d;&#xed;tkoP&#x159;idatActionPerformed"/>
    9.63 -      </Events>
    9.64 -    </Component>
    9.65 -    <Component class="javax.swing.JButton" name="tla&#x10d;&#xed;tkoSmazat">
    9.66 -      <Properties>
    9.67 -        <Property name="mnemonic" type="int" value="115"/>
    9.68 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
    9.69 -          <ResourceString bundle="cz/frantovo/rozsireneAtributy/P&#x159;eklady.properties" key="smazatAtribut" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
    9.70 -        </Property>
    9.71 -        <Property name="enabled" type="boolean" value="false"/>
    9.72 -      </Properties>
    9.73 -      <Events>
    9.74 -        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tla&#x10d;&#xed;tkoSmazatActionPerformed"/>
    9.75 -      </Events>
    9.76 -    </Component>
    9.77 -    <Component class="javax.swing.JButton" name="tla&#x10d;&#xed;tkoZnovuNa&#x10d;&#xed;st">
    9.78 -      <Properties>
    9.79 -        <Property name="mnemonic" type="int" value="122"/>
    9.80 -        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
    9.81 -          <ResourceString bundle="cz/frantovo/rozsireneAtributy/P&#x159;eklady.properties" key="znovuNa&#x10d;&#xed;st" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
    9.82 -        </Property>
    9.83 -      </Properties>
    9.84 -      <Events>
    9.85 -        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tla&#x10d;&#xed;tkoZnovuNa&#x10d;&#xed;stActionPerformed"/>
    9.86 -      </Events>
    9.87 -    </Component>
    9.88 -  </SubComponents>
    9.89 -</Form>
    10.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java	Mon Dec 11 00:10:33 2023 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,175 +0,0 @@
    10.4 -/**
    10.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
    10.6 - * Copyright © 2012 František Kučera (frantovo.cz)
    10.7 - *
    10.8 - * This program is free software: you can redistribute it and/or modify
    10.9 - * it under the terms of the GNU General Public License as published by
   10.10 - * the Free Software Foundation, either version 3 of the License.
   10.11 - *
   10.12 - * This program is distributed in the hope that it will be useful,
   10.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   10.15 - * GNU General Public License for more details.
   10.16 - *
   10.17 - * You should have received a copy of the GNU General Public License
   10.18 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
   10.19 - */
   10.20 -package cz.frantovo.rozsireneAtributy.gui;
   10.21 -
   10.22 -import cz.frantovo.rozsireneAtributy.Atribut;
   10.23 -import java.io.IOException;
   10.24 -import java.util.ResourceBundle;
   10.25 -import java.util.logging.Level;
   10.26 -import java.util.logging.Logger;
   10.27 -import javax.swing.JOptionPane;
   10.28 -import javax.swing.JTable;
   10.29 -import javax.swing.ListSelectionModel;
   10.30 -import javax.swing.event.ListSelectionEvent;
   10.31 -import javax.swing.event.ListSelectionListener;
   10.32 -
   10.33 -/**
   10.34 - *
   10.35 - * @author fiki
   10.36 - */
   10.37 -public class Panel extends javax.swing.JPanel {
   10.38 -
   10.39 -	private static final int SLOUPEC_NÁZVU = 0;
   10.40 -	private static final Logger log = Logger.getLogger(Panel.class.getSimpleName());
   10.41 -	private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
   10.42 -	private Model model;
   10.43 -	private Atribut vybranýAtribut;
   10.44 -	private JTable tabulka;
   10.45 -
   10.46 -	public Panel(Model model) {
   10.47 -		this.model = model;
   10.48 -		initComponents();
   10.49 -
   10.50 -		tabulka = new JTable(model);
   10.51 -		nastavEditor();
   10.52 -		tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   10.53 -		posuvnýPanel.setViewportView(tabulka);
   10.54 -
   10.55 -		/** Výběr aktuálního atributu v tabulce */
   10.56 -		tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
   10.57 -
   10.58 -			@Override
   10.59 -			public void valueChanged(ListSelectionEvent e) {
   10.60 -				int řádek = tabulka.getSelectedRow();
   10.61 -				if (řádek < 0) {
   10.62 -					vybranýAtribut = null;
   10.63 -					tlačítkoSmazat.setEnabled(false);
   10.64 -				} else {
   10.65 -					vybranýAtribut = getModel().getAtribut(řádek);
   10.66 -					tlačítkoSmazat.setEnabled(true);
   10.67 -				}
   10.68 -			}
   10.69 -		});
   10.70 -	}
   10.71 -
   10.72 -	private void nastavEditor() {
   10.73 -		tabulka.getColumnModel().getColumn(SLOUPEC_NÁZVU).setCellEditor(new EditorNázvůAtributů());
   10.74 -	}
   10.75 -
   10.76 -	private Model getModel() {
   10.77 -		return model;
   10.78 -	}
   10.79 -
   10.80 -	public void setModel(Model model) {
   10.81 -		this.model = model;
   10.82 -		tabulka.setModel(model);
   10.83 -		nastavEditor();
   10.84 -	}
   10.85 -
   10.86 -	private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
   10.87 -		JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
   10.88 -		log.log(Level.WARNING, hláška, chyba);
   10.89 -	}
   10.90 -
   10.91 -	@SuppressWarnings("unchecked")
   10.92 -    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   10.93 -    private void initComponents() {
   10.94 -
   10.95 -        posuvnýPanel = new javax.swing.JScrollPane();
   10.96 -        tlačítkoPřidat = new javax.swing.JButton();
   10.97 -        tlačítkoSmazat = new javax.swing.JButton();
   10.98 -        tlačítkoZnovuNačíst = new javax.swing.JButton();
   10.99 -
  10.100 -        tlačítkoPřidat.setMnemonic('p');
  10.101 -        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneAtributy/Překlady"); // NOI18N
  10.102 -        tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
  10.103 -        tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
  10.104 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  10.105 -                tlačítkoPřidatActionPerformed(evt);
  10.106 -            }
  10.107 -        });
  10.108 -
  10.109 -        tlačítkoSmazat.setMnemonic('s');
  10.110 -        tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
  10.111 -        tlačítkoSmazat.setEnabled(false);
  10.112 -        tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
  10.113 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  10.114 -                tlačítkoSmazatActionPerformed(evt);
  10.115 -            }
  10.116 -        });
  10.117 -
  10.118 -        tlačítkoZnovuNačíst.setMnemonic('z');
  10.119 -        tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
  10.120 -        tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
  10.121 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
  10.122 -                tlačítkoZnovuNačístActionPerformed(evt);
  10.123 -            }
  10.124 -        });
  10.125 -
  10.126 -        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  10.127 -        this.setLayout(layout);
  10.128 -        layout.setHorizontalGroup(
  10.129 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  10.130 -            .addGroup(layout.createSequentialGroup()
  10.131 -                .addContainerGap()
  10.132 -                .addComponent(tlačítkoPřidat)
  10.133 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  10.134 -                .addComponent(tlačítkoSmazat)
  10.135 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  10.136 -                .addComponent(tlačítkoZnovuNačíst)
  10.137 -                .addContainerGap(186, Short.MAX_VALUE))
  10.138 -            .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
  10.139 -        );
  10.140 -        layout.setVerticalGroup(
  10.141 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  10.142 -            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  10.143 -                .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
  10.144 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  10.145 -                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  10.146 -                    .addComponent(tlačítkoPřidat)
  10.147 -                    .addComponent(tlačítkoSmazat)
  10.148 -                    .addComponent(tlačítkoZnovuNačíst))
  10.149 -                .addContainerGap())
  10.150 -        );
  10.151 -    }// </editor-fold>//GEN-END:initComponents
  10.152 -
  10.153 -	private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
  10.154 -		model.přidejAtribut(new Atribut());
  10.155 -	}//GEN-LAST:event_tlačítkoPřidatActionPerformed
  10.156 -
  10.157 -	private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
  10.158 -		try {
  10.159 -			model.odeberAtribut(vybranýAtribut);
  10.160 -		} catch (IOException e) {
  10.161 -			zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
  10.162 -		}
  10.163 -	}//GEN-LAST:event_tlačítkoSmazatActionPerformed
  10.164 -
  10.165 -	private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
  10.166 -		try {
  10.167 -			model.načtiAtributy();
  10.168 -		} catch (IOException e) {
  10.169 -			zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
  10.170 -		}
  10.171 -	}//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
  10.172 -    // Variables declaration - do not modify//GEN-BEGIN:variables
  10.173 -    private javax.swing.JScrollPane posuvnýPanel;
  10.174 -    private javax.swing.JButton tlačítkoPřidat;
  10.175 -    private javax.swing.JButton tlačítkoSmazat;
  10.176 -    private javax.swing.JButton tlačítkoZnovuNačíst;
  10.177 -    // End of variables declaration//GEN-END:variables
  10.178 -}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Atribut.java	Mon Dec 11 00:28:30 2023 +0100
    11.3 @@ -0,0 +1,94 @@
    11.4 +/**
    11.5 + * Rozšířené atributy – program na správu rozšířených atributů souborů
    11.6 + * Copyright © 2012 František Kučera (frantovo.cz)
    11.7 + * 
    11.8 + * This program is free software: you can redistribute it and/or modify
    11.9 + * it under the terms of the GNU General Public License as published by
   11.10 + * the Free Software Foundation, either version 3 of the License.
   11.11 + * 
   11.12 + * This program is distributed in the hope that it will be useful,
   11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 + * GNU General Public License for more details.
   11.16 + * 
   11.17 + * You should have received a copy of the GNU General Public License
   11.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   11.19 + */
   11.20 +package cz.frantovo.rozsireneatributy;
   11.21 +
   11.22 +import java.nio.ByteBuffer;
   11.23 +import java.nio.charset.Charset;
   11.24 +
   11.25 +public class Atribut {
   11.26 +
   11.27 +	private String klíč;
   11.28 +	private String hodnota;
   11.29 +
   11.30 +	public Atribut(String klíč, String hodnota) {
   11.31 +		this.klíč = klíč;
   11.32 +		this.hodnota = hodnota;
   11.33 +	}
   11.34 +
   11.35 +	public Atribut(String klíč, ByteBuffer hodnota) {
   11.36 +		this.klíč = klíč;
   11.37 +		setHodnota(hodnota);
   11.38 +	}
   11.39 +
   11.40 +	public Atribut() {
   11.41 +	}
   11.42 +
   11.43 +	public String getKlíč() {
   11.44 +		return klíč;
   11.45 +	}
   11.46 +
   11.47 +	public void setKlíč(String klíč) {
   11.48 +		this.klíč = klíč;
   11.49 +	}
   11.50 +
   11.51 +	/**
   11.52 +	 * Název atributu musí být nenulový a mít nějakou délku, aby šel uložit
   11.53 +	 * TODO: další kontroly?
   11.54 +	 * @return jestli je platný
   11.55 +	 */
   11.56 +	public boolean isPlatnýKlíč() {
   11.57 +		return klíč != null && klíč.length() > 0;
   11.58 +	}
   11.59 +
   11.60 +	/**
   11.61 +	 * nulová hodnota → smazání atributu
   11.62 +	 * (ale může být prázdný řetězec)
   11.63 +	 * @return jestli je platná
   11.64 +	 */
   11.65 +	public boolean isPlatnáHodnota() {
   11.66 +		return hodnota != null;
   11.67 +	}
   11.68 +
   11.69 +	public String getHodnota() {
   11.70 +		return hodnota;
   11.71 +	}
   11.72 +
   11.73 +	public final ByteBuffer getHodnotaBajty() {
   11.74 +		return zakóduj(getHodnota());
   11.75 +	}
   11.76 +
   11.77 +	public void setHodnota(String hodnota) {
   11.78 +		this.hodnota = hodnota;
   11.79 +	}
   11.80 +
   11.81 +	public final void setHodnota(ByteBuffer hodnota) {
   11.82 +		setHodnota(dekóduj(hodnota));
   11.83 +	}
   11.84 +
   11.85 +	private static String dekóduj(ByteBuffer bajty) {
   11.86 +		bajty.flip();
   11.87 +		return Charset.defaultCharset().decode(bajty).toString();
   11.88 +	}
   11.89 +
   11.90 +	private static ByteBuffer zakóduj(String text) {
   11.91 +		if (text == null) {
   11.92 +			return null;
   11.93 +		} else {
   11.94 +			return Charset.defaultCharset().encode(text);
   11.95 +		}
   11.96 +	}
   11.97 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady.properties	Mon Dec 11 00:28:30 2023 +0100
    12.3 @@ -0,0 +1,1 @@
    12.4 +Překlady_cs.properties
    12.5 \ No newline at end of file
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_cs.properties	Mon Dec 11 00:28:30 2023 +0100
    13.3 @@ -0,0 +1,14 @@
    13.4 +titulek=Roz\u0161\u00ed\u0159en\u00e9 stributy souboru: {0}
    13.5 +
    13.6 +chyba.titulek=Chyba
    13.7 +chyba.souborNeexistuje=Soubor neexistuje: {0}
    13.8 +chyba.chyb\u00edParametr=O\u010dek\u00e1v\u00e1m pr\u00e1v\u011b jeden parametr \u2013 n\u00e1zev souboru.
    13.9 +chyba.nepoda\u0159iloSeSmazat=Nepoda\u0159ilo se smazat atribut.
   13.10 +chyba.nepoda\u0159iloSeNa\u010d\u00edst=Nepoda\u0159ilo se na\u010d\u00edst atributy.
   13.11 +
   13.12 +tabulka.n\u00e1zev=N\u00e1zev
   13.13 +tabulka.hodnota=Hodnota
   13.14 +
   13.15 +p\u0159idatAtribut=P\u0159idat atribut
   13.16 +smazatAtribut=Smazat atribut
   13.17 +znovuNa\u010d\u00edst=Znovu na\u010d\u00edst
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_en.properties	Mon Dec 11 00:28:30 2023 +0100
    14.3 @@ -0,0 +1,14 @@
    14.4 +titulek=Extended Attributes of file: {0}
    14.5 +
    14.6 +chyba.titulek=Error
    14.7 +chyba.souborNeexistuje=File does not exist: {0}
    14.8 +chyba.chyb\u00edParametr=Expecting one parameter \u2013 file name.
    14.9 +chyba.nepoda\u0159iloSeSmazat=Failed to delete the attribute.
   14.10 +chyba.nepoda\u0159iloSeNa\u010d\u00edst=Failed to load attributes.
   14.11 +
   14.12 +tabulka.n\u00e1zev=Name
   14.13 +tabulka.hodnota=Value
   14.14 +
   14.15 +p\u0159idatAtribut=Add attribute
   14.16 +smazatAtribut=Delete attribute
   14.17 +znovuNa\u010d\u00edst=Reload all
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Startér.java	Mon Dec 11 00:28:30 2023 +0100
    15.3 @@ -0,0 +1,100 @@
    15.4 +/**
    15.5 + * Rozšířené atributy – program na správu rozšířených atributů souborů
    15.6 + * Copyright © 2012 František Kučera (frantovo.cz)
    15.7 + *
    15.8 + * This program is free software: you can redistribute it and/or modify
    15.9 + * it under the terms of the GNU General Public License as published by
   15.10 + * the Free Software Foundation, either version 3 of the License.
   15.11 + *
   15.12 + * This program is distributed in the hope that it will be useful,
   15.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.15 + * GNU General Public License for more details.
   15.16 + *
   15.17 + * You should have received a copy of the GNU General Public License
   15.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   15.19 + */
   15.20 +package cz.frantovo.rozsireneatributy;
   15.21 +
   15.22 +import cz.frantovo.rozsireneatributy.gui.Model;
   15.23 +import cz.frantovo.rozsireneatributy.gui.Panel;
   15.24 +import java.awt.BorderLayout;
   15.25 +import java.awt.event.ActionEvent;
   15.26 +import java.awt.event.ActionListener;
   15.27 +import java.awt.event.KeyEvent;
   15.28 +import java.io.File;
   15.29 +import java.io.IOException;
   15.30 +import java.text.MessageFormat;
   15.31 +import java.util.ResourceBundle;
   15.32 +import java.util.logging.Level;
   15.33 +import java.util.logging.Logger;
   15.34 +import javax.swing.JComponent;
   15.35 +import javax.swing.JFrame;
   15.36 +import javax.swing.JOptionPane;
   15.37 +import javax.swing.KeyStroke;
   15.38 +
   15.39 +/**
   15.40 + * Spouštěč programu
   15.41 + *
   15.42 + * http://freedesktop.org/wiki/CommonExtendedAttributes
   15.43 + * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
   15.44 + * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really
   15.45 + *
   15.46 + * $ setfattr -n "user.fiki.pozdrav" -v 'Dobrý den!' pokus.txt
   15.47 + * (v javě pak pracujeme s klíči bez předpony „user.“)
   15.48 + *
   15.49 + * @author fiki
   15.50 + */
   15.51 +public class Startér {
   15.52 +
   15.53 +	private static final Logger log = Logger.getLogger(Startér.class.getSimpleName());
   15.54 +	private static final ResourceBundle překlady = ResourceBundle.getBundle(Atribut.class.getPackageName() + ".Překlady");
   15.55 +
   15.56 +	/**
   15.57 +	 * @param args název souboru
   15.58 +	 * @throws IOException TODO: ošetřit výjimku
   15.59 +	 */
   15.60 +	public static void main(String[] args) throws IOException {
   15.61 +
   15.62 +
   15.63 +		if (args.length == 1 && args[0].length() > 0) {
   15.64 +			File soubor = new File(args[0]);
   15.65 +
   15.66 +			if (soubor.exists()) {
   15.67 +				log.log(Level.INFO, "Pracuji se souborem: {0}", soubor);
   15.68 +
   15.69 +				Model model = new Model(soubor);
   15.70 +
   15.71 +				final JFrame f = new JFrame();
   15.72 +				Panel p = new Panel(model);
   15.73 +
   15.74 +				f.setLayout(new BorderLayout());
   15.75 +				f.add(p, BorderLayout.CENTER);
   15.76 +
   15.77 +				/** Ukončení programu klávesou Escape */
   15.78 +				f.getRootPane().registerKeyboardAction(new ActionListener() {
   15.79 +
   15.80 +					public void actionPerformed(ActionEvent ae) {
   15.81 +						f.dispose();
   15.82 +					}
   15.83 +				}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
   15.84 +
   15.85 +				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   15.86 +				f.setTitle(MessageFormat.format(překlady.getString("titulek"), soubor));
   15.87 +				f.setSize(640, 240);
   15.88 +				f.setLocationRelativeTo(null);
   15.89 +				f.setVisible(true);
   15.90 +			} else {
   15.91 +				ukončiChybou(MessageFormat.format(překlady.getString("chyba.souborNeexistuje"), soubor));
   15.92 +			}
   15.93 +		} else {
   15.94 +			ukončiChybou(překlady.getString("chyba.chybíParametr"));
   15.95 +		}
   15.96 +	}
   15.97 +
   15.98 +	private static void ukončiChybou(String hláška) {
   15.99 +		log.log(Level.SEVERE, hláška);
  15.100 +		JOptionPane.showMessageDialog(null, hláška, překlady.getString("chyba.titulek"), JOptionPane.ERROR_MESSAGE);
  15.101 +		System.exit(1);
  15.102 +	}
  15.103 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorNázvůAtributů.java	Mon Dec 11 00:28:30 2023 +0100
    16.3 @@ -0,0 +1,173 @@
    16.4 +/**
    16.5 + * Rozšířené atributy – program na správu rozšířených atributů souborů
    16.6 + * Copyright © 2012 František Kučera (frantovo.cz)
    16.7 + *
    16.8 + * This program is free software: you can redistribute it and/or modify
    16.9 + * it under the terms of the GNU General Public License as published by
   16.10 + * the Free Software Foundation, either version 3 of the License.
   16.11 + *
   16.12 + * This program is distributed in the hope that it will be useful,
   16.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   16.15 + * GNU General Public License for more details.
   16.16 + *
   16.17 + * You should have received a copy of the GNU General Public License
   16.18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
   16.19 + */
   16.20 +package cz.frantovo.rozsireneatributy.gui;
   16.21 +
   16.22 +import java.awt.Component;
   16.23 +import java.awt.event.ActionEvent;
   16.24 +import java.awt.event.ActionListener;
   16.25 +import java.util.EventObject;
   16.26 +import javax.swing.JComboBox;
   16.27 +import javax.swing.JTable;
   16.28 +import javax.swing.event.CellEditorListener;
   16.29 +import javax.swing.event.ChangeEvent;
   16.30 +import javax.swing.event.EventListenerList;
   16.31 +import javax.swing.table.TableCellEditor;
   16.32 +
   16.33 +/**
   16.34 + * Umožňuje výběr názvu atributu z předvoleného seznamu (standardizované atributy).
   16.35 + *
   16.36 + * @author Ing. František Kučera (frantovo.cz)
   16.37 + */
   16.38 +public class EditorNázvůAtributů extends JComboBox<String> implements TableCellEditor {
   16.39 +
   16.40 +	protected EventListenerList posluchače = new EventListenerList();
   16.41 +	protected ChangeEvent událost = new ChangeEvent(this);
   16.42 +
   16.43 +	public EditorNázvůAtributů() {
   16.44 +		super();
   16.45 +		setEditable(true);
   16.46 +		addActionListener(new ActionListener() {
   16.47 +
   16.48 +			@Override
   16.49 +			public void actionPerformed(ActionEvent e) {
   16.50 +				fireEditiaceSkončila();
   16.51 +			}
   16.52 +		});
   16.53 +	}
   16.54 +
   16.55 +	protected void fireEditiaceSkončila() {
   16.56 +		for (Object posluchač : posluchače.getListenerList()) {
   16.57 +			if (posluchač instanceof CellEditorListener) {
   16.58 +				((CellEditorListener) posluchač).editingStopped(událost);
   16.59 +			}
   16.60 +		}
   16.61 +	}
   16.62 +
   16.63 +	protected void fireEditiaceZrušena() {
   16.64 +		for (Object posluchač : posluchače.getListenerList()) {
   16.65 +			if (posluchač instanceof CellEditorListener) {
   16.66 +				((CellEditorListener) posluchač).editingCanceled(událost);
   16.67 +			}
   16.68 +		}
   16.69 +	}
   16.70 +
   16.71 +	/**
   16.72 +	 * TODO:
   16.73 +	 * - další standardní atributy
   16.74 +	 * - konfigurovatelnost
   16.75 +	 *
   16.76 +	 * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes
   16.77 +	 */
   16.78 +	private void obnovHodnoty(Object názevAtributu) {
   16.79 +		removeAllItems();
   16.80 +
   16.81 +		if (názevAtributu == null) {
   16.82 +			názevAtributu = "";
   16.83 +		} else if (!(názevAtributu instanceof String)) {
   16.84 +			názevAtributu = String.valueOf(názevAtributu);
   16.85 +		}
   16.86 +		addItem((String) názevAtributu);
   16.87 +		setSelectedItem(názevAtributu);
   16.88 +
   16.89 +
   16.90 +		// General attributes in current use
   16.91 +		addItem("mime_type");
   16.92 +		addItem("charset");
   16.93 +		addItem("creator");
   16.94 +
   16.95 +		// Proposed metadata attributes
   16.96 +		addItem("xdg.comment");
   16.97 +		addItem("xdg.origin.url");
   16.98 +		addItem("xdg.origin.email.subject");
   16.99 +		addItem("xdg.origin.email.from");
  16.100 +		addItem("xdg.origin.email.message-id");
  16.101 +		addItem("xdg.language");
  16.102 +		addItem("xdg.creator");
  16.103 +		addItem("xdg.publisher");
  16.104 +
  16.105 +		// Proposed control attributes
  16.106 +		addItem("xdg.robots.index");
  16.107 +		addItem("xdg.robots.backup");
  16.108 +
  16.109 +		// Dublin Core
  16.110 +		addItem("dublincore.title");
  16.111 +		addItem("dublincore.creator");
  16.112 +		addItem("dublincore.subject");
  16.113 +		addItem("dublincore.description");
  16.114 +		addItem("dublincore.publisher");
  16.115 +		addItem("dublincore.contributor");
  16.116 +		addItem("dublincore.date");
  16.117 +		addItem("dublincore.type");
  16.118 +		addItem("dublincore.format");
  16.119 +		addItem("dublincore.identifier");
  16.120 +		addItem("dublincore.source");
  16.121 +		addItem("dublincore.language");
  16.122 +		addItem("dublincore.relation");
  16.123 +		addItem("dublincore.coverage");
  16.124 +		addItem("dublincore.rights");
  16.125 +
  16.126 +		// Application-specific attributes in current use
  16.127 +		addItem("mime_encoding");
  16.128 +		addItem("apache_handler");
  16.129 +		addItem("Beagle.AttrTime");
  16.130 +		addItem("Beagle.Fingerprint");
  16.131 +		addItem("Beagle.MTime");
  16.132 +		addItem("Beagle.Uid");
  16.133 +	}
  16.134 +
  16.135 +	@Override
  16.136 +	public Component getTableCellEditorComponent(JTable tabulka, Object hodnota, boolean vybraná, int řádek, int sloupec) {
  16.137 +		obnovHodnoty(hodnota);
  16.138 +		return this;
  16.139 +	}
  16.140 +
  16.141 +	@Override
  16.142 +	public Object getCellEditorValue() {
  16.143 +		return getSelectedItem();
  16.144 +	}
  16.145 +
  16.146 +	@Override
  16.147 +	public boolean isCellEditable(EventObject anEvent) {
  16.148 +		return true;
  16.149 +	}
  16.150 +
  16.151 +	@Override
  16.152 +	public boolean shouldSelectCell(EventObject anEvent) {
  16.153 +		return true;
  16.154 +	}
  16.155 +
  16.156 +	@Override
  16.157 +	public boolean stopCellEditing() {
  16.158 +		fireEditiaceSkončila();
  16.159 +		return true;
  16.160 +	}
  16.161 +
  16.162 +	@Override
  16.163 +	public void cancelCellEditing() {
  16.164 +		fireEditiaceZrušena();
  16.165 +	}
  16.166 +
  16.167 +	@Override
  16.168 +	public void addCellEditorListener(CellEditorListener l) {
  16.169 +		posluchače.add(CellEditorListener.class, l);
  16.170 +	}
  16.171 +
  16.172 +	@Override
  16.173 +	public void removeCellEditorListener(CellEditorListener l) {
  16.174 +		posluchače.remove(CellEditorListener.class, l);
  16.175 +	}
  16.176 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java	Mon Dec 11 00:28:30 2023 +0100
    17.3 @@ -0,0 +1,168 @@
    17.4 +/**
    17.5 + * Rozšířené atributy – program na správu rozšířených atributů souborů
    17.6 + * Copyright © 2012 František Kučera (frantovo.cz)
    17.7 + * 
    17.8 + * This program is free software: you can redistribute it and/or modify
    17.9 + * it under the terms of the GNU General Public License as published by
   17.10 + * the Free Software Foundation, either version 3 of the License.
   17.11 + * 
   17.12 + * This program is distributed in the hope that it will be useful,
   17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.15 + * GNU General Public License for more details.
   17.16 + * 
   17.17 + * You should have received a copy of the GNU General Public License
   17.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17.19 + */
   17.20 +package cz.frantovo.rozsireneatributy.gui;
   17.21 +
   17.22 +import cz.frantovo.rozsireneatributy.Atribut;
   17.23 +import java.io.File;
   17.24 +import java.io.IOException;
   17.25 +import java.nio.ByteBuffer;
   17.26 +import java.nio.file.Path;
   17.27 +import java.nio.file.attribute.UserDefinedFileAttributeView;
   17.28 +import java.nio.file.spi.FileSystemProvider;
   17.29 +import java.util.ArrayList;
   17.30 +import java.util.HashSet;
   17.31 +import java.util.List;
   17.32 +import java.util.ResourceBundle;
   17.33 +import java.util.Set;
   17.34 +import java.util.logging.Level;
   17.35 +import java.util.logging.Logger;
   17.36 +import javax.swing.event.TableModelEvent;
   17.37 +import javax.swing.event.TableModelListener;
   17.38 +import javax.swing.table.TableModel;
   17.39 +
   17.40 +/**
   17.41 + *
   17.42 + * @author fiki
   17.43 + */
   17.44 +public class Model implements TableModel {
   17.45 +
   17.46 +	private static final Logger log = Logger.getLogger(Model.class.getSimpleName());
   17.47 +	private static final ResourceBundle překlady = ResourceBundle.getBundle(Atribut.class.getPackageName() + ".Překlady");
   17.48 +	private String[] sloupečky = {překlady.getString("tabulka.název"), překlady.getString("tabulka.hodnota")};
   17.49 +	private Set<TableModelListener> posluchače = new HashSet<>();
   17.50 +	private UserDefinedFileAttributeView souborovýSystém;
   17.51 +	private List<Atribut> atributy = new ArrayList<>();
   17.52 +
   17.53 +	public Model(File soubor) throws IOException {
   17.54 +		Path cesta = soubor.toPath();
   17.55 +		FileSystemProvider posyktovatelFS = cesta.getFileSystem().provider();
   17.56 +		souborovýSystém = posyktovatelFS.getFileAttributeView(cesta, UserDefinedFileAttributeView.class);
   17.57 +		načtiAtributy();
   17.58 +	}
   17.59 +
   17.60 +	@Override
   17.61 +	public int getRowCount() {
   17.62 +		return atributy.size();
   17.63 +	}
   17.64 +
   17.65 +	@Override
   17.66 +	public int getColumnCount() {
   17.67 +		return sloupečky.length;
   17.68 +	}
   17.69 +
   17.70 +	@Override
   17.71 +	public String getColumnName(int n) {
   17.72 +		return sloupečky[n];
   17.73 +	}
   17.74 +
   17.75 +	@Override
   17.76 +	public Class<?> getColumnClass(int n) {
   17.77 +		return String.class;
   17.78 +	}
   17.79 +
   17.80 +	@Override
   17.81 +	public boolean isCellEditable(int m, int n) {
   17.82 +		return true;
   17.83 +	}
   17.84 +
   17.85 +	@Override
   17.86 +	public Object getValueAt(int m, int n) {
   17.87 +		if (n == 0) {
   17.88 +			return atributy.get(m).getKlíč();
   17.89 +		} else if (n == 1) {
   17.90 +			return atributy.get(m).getHodnota();
   17.91 +		} else {
   17.92 +			return null;
   17.93 +		}
   17.94 +	}
   17.95 +
   17.96 +	@Override
   17.97 +	public void setValueAt(Object hodnota, int m, int n) {
   17.98 +		Atribut a = atributy.get(m);
   17.99 +		try {
  17.100 +			if (n == 0) {
  17.101 +				/** Měníme klíč – název atributu */
  17.102 +				String novýKlíč = String.valueOf(hodnota);
  17.103 +				if (!novýKlíč.equals(a.getKlíč())) {
  17.104 +					if (a.isPlatnýKlíč()) {
  17.105 +						souborovýSystém.delete(a.getKlíč());
  17.106 +					}
  17.107 +					a.setKlíč(novýKlíč);
  17.108 +					if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) {
  17.109 +						souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty());
  17.110 +					}
  17.111 +				}
  17.112 +			} else if (n == 1) {
  17.113 +				/** Měníme hodnotu atributu */
  17.114 +				a.setHodnota(String.valueOf(hodnota));
  17.115 +				if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) {
  17.116 +					souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty());
  17.117 +				}
  17.118 +			}
  17.119 +		} catch (IOException e) {
  17.120 +			log.log(Level.SEVERE, "Selhalo ukládání atributu na souborový systém", e);
  17.121 +		}
  17.122 +	}
  17.123 +
  17.124 +	@Override
  17.125 +	public void addTableModelListener(TableModelListener l) {
  17.126 +		posluchače.add(l);
  17.127 +	}
  17.128 +
  17.129 +	@Override
  17.130 +	public void removeTableModelListener(TableModelListener l) {
  17.131 +		posluchače.remove(l);
  17.132 +	}
  17.133 +
  17.134 +	/**
  17.135 +	 * @param m číslo řádku
  17.136 +	 * @return atribut, který se na něm nachází
  17.137 +	 */
  17.138 +	public Atribut getAtribut(int m) {
  17.139 +		return atributy.get(m);
  17.140 +	}
  17.141 +
  17.142 +	public void přidejAtribut(Atribut a) {
  17.143 +		atributy.add(a);
  17.144 +		upozorniPosluchače();
  17.145 +	}
  17.146 +
  17.147 +	public void odeberAtribut(Atribut a) throws IOException {
  17.148 +		atributy.remove(a);
  17.149 +		if (a.isPlatnýKlíč()) {
  17.150 +			souborovýSystém.delete(a.getKlíč());
  17.151 +		}
  17.152 +		upozorniPosluchače();
  17.153 +	}
  17.154 +
  17.155 +	public final void načtiAtributy() throws IOException {
  17.156 +		List<String> jménaAtributů = souborovýSystém.list();
  17.157 +		atributy.clear();
  17.158 +		for (String jménoAtributu : jménaAtributů) {
  17.159 +			ByteBuffer hodnotaAtributu = ByteBuffer.allocate(souborovýSystém.size(jménoAtributu));
  17.160 +			souborovýSystém.read(jménoAtributu, hodnotaAtributu);
  17.161 +			atributy.add(new Atribut(jménoAtributu, hodnotaAtributu));
  17.162 +		}
  17.163 +		upozorniPosluchače();
  17.164 +	}
  17.165 +
  17.166 +	private void upozorniPosluchače() {
  17.167 +		for (TableModelListener p : posluchače) {
  17.168 +			p.tableChanged(new TableModelEvent(this));
  17.169 +		}
  17.170 +	}
  17.171 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Panel.form	Mon Dec 11 00:28:30 2023 +0100
    18.3 @@ -0,0 +1,86 @@
    18.4 +<?xml version="1.0" encoding="UTF-8" ?>
    18.5 +
    18.6 +<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
    18.7 +  <AuxValues>
    18.8 +    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
    18.9 +    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
   18.10 +    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
   18.11 +    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
   18.12 +    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
   18.13 +    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
   18.14 +    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
   18.15 +    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
   18.16 +    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
   18.17 +  </AuxValues>
   18.18 +
   18.19 +  <Layout>
   18.20 +    <DimensionLayout dim="0">
   18.21 +      <Group type="103" groupAlignment="0" attributes="0">
   18.22 +          <Group type="102" alignment="0" attributes="0">
   18.23 +              <EmptySpace max="-2" attributes="0"/>
   18.24 +              <Component id="tlačítkoPřidat" min="-2" max="-2" attributes="0"/>
   18.25 +              <EmptySpace max="-2" attributes="0"/>
   18.26 +              <Component id="tlačítkoSmazat" min="-2" max="-2" attributes="0"/>
   18.27 +              <EmptySpace max="-2" attributes="0"/>
   18.28 +              <Component id="tlačítkoZnovuNačíst" min="-2" max="-2" attributes="0"/>
   18.29 +              <EmptySpace pref="222" max="32767" attributes="0"/>
   18.30 +          </Group>
   18.31 +          <Component id="posuvnýPanel" alignment="0" pref="543" max="32767" attributes="0"/>
   18.32 +      </Group>
   18.33 +    </DimensionLayout>
   18.34 +    <DimensionLayout dim="1">
   18.35 +      <Group type="103" groupAlignment="0" attributes="0">
   18.36 +          <Group type="102" alignment="1" attributes="0">
   18.37 +              <Component id="posuvnýPanel" pref="277" max="32767" attributes="0"/>
   18.38 +              <EmptySpace max="-2" attributes="0"/>
   18.39 +              <Group type="103" groupAlignment="3" attributes="0">
   18.40 +                  <Component id="tlačítkoPřidat" alignment="3" min="-2" max="-2" attributes="0"/>
   18.41 +                  <Component id="tlačítkoSmazat" alignment="3" min="-2" max="-2" attributes="0"/>
   18.42 +                  <Component id="tlačítkoZnovuNačíst" alignment="3" min="-2" max="-2" attributes="0"/>
   18.43 +              </Group>
   18.44 +              <EmptySpace max="-2" attributes="0"/>
   18.45 +          </Group>
   18.46 +      </Group>
   18.47 +    </DimensionLayout>
   18.48 +  </Layout>
   18.49 +  <SubComponents>
   18.50 +    <Container class="javax.swing.JScrollPane" name="posuvn&#xfd;Panel">
   18.51 +
   18.52 +      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
   18.53 +    </Container>
   18.54 +    <Component class="javax.swing.JButton" name="tla&#x10d;&#xed;tkoP&#x159;idat">
   18.55 +      <Properties>
   18.56 +        <Property name="mnemonic" type="int" value="112"/>
   18.57 +        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   18.58 +          <ResourceString bundle="cz/frantovo/rozsireneatributy/P&#x159;eklady.properties" key="p&#x159;idatAtribut" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
   18.59 +        </Property>
   18.60 +      </Properties>
   18.61 +      <Events>
   18.62 +        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tla&#x10d;&#xed;tkoP&#x159;idatActionPerformed"/>
   18.63 +      </Events>
   18.64 +    </Component>
   18.65 +    <Component class="javax.swing.JButton" name="tla&#x10d;&#xed;tkoSmazat">
   18.66 +      <Properties>
   18.67 +        <Property name="mnemonic" type="int" value="115"/>
   18.68 +        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   18.69 +          <ResourceString bundle="cz/frantovo/rozsireneatributy/P&#x159;eklady.properties" key="smazatAtribut" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
   18.70 +        </Property>
   18.71 +        <Property name="enabled" type="boolean" value="false"/>
   18.72 +      </Properties>
   18.73 +      <Events>
   18.74 +        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tla&#x10d;&#xed;tkoSmazatActionPerformed"/>
   18.75 +      </Events>
   18.76 +    </Component>
   18.77 +    <Component class="javax.swing.JButton" name="tla&#x10d;&#xed;tkoZnovuNa&#x10d;&#xed;st">
   18.78 +      <Properties>
   18.79 +        <Property name="mnemonic" type="int" value="122"/>
   18.80 +        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
   18.81 +          <ResourceString bundle="cz/frantovo/rozsireneatributy/P&#x159;eklady.properties" key="znovuNa&#x10d;&#xed;st" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
   18.82 +        </Property>
   18.83 +      </Properties>
   18.84 +      <Events>
   18.85 +        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tla&#x10d;&#xed;tkoZnovuNa&#x10d;&#xed;stActionPerformed"/>
   18.86 +      </Events>
   18.87 +    </Component>
   18.88 +  </SubComponents>
   18.89 +</Form>
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Panel.java	Mon Dec 11 00:28:30 2023 +0100
    19.3 @@ -0,0 +1,175 @@
    19.4 +/**
    19.5 + * Rozšířené atributy – program na správu rozšířených atributů souborů
    19.6 + * Copyright © 2012 František Kučera (frantovo.cz)
    19.7 + *
    19.8 + * This program is free software: you can redistribute it and/or modify
    19.9 + * it under the terms of the GNU General Public License as published by
   19.10 + * the Free Software Foundation, either version 3 of the License.
   19.11 + *
   19.12 + * This program is distributed in the hope that it will be useful,
   19.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   19.15 + * GNU General Public License for more details.
   19.16 + *
   19.17 + * You should have received a copy of the GNU General Public License
   19.18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
   19.19 + */
   19.20 +package cz.frantovo.rozsireneatributy.gui;
   19.21 +
   19.22 +import cz.frantovo.rozsireneatributy.Atribut;
   19.23 +import java.io.IOException;
   19.24 +import java.util.ResourceBundle;
   19.25 +import java.util.logging.Level;
   19.26 +import java.util.logging.Logger;
   19.27 +import javax.swing.JOptionPane;
   19.28 +import javax.swing.JTable;
   19.29 +import javax.swing.ListSelectionModel;
   19.30 +import javax.swing.event.ListSelectionEvent;
   19.31 +import javax.swing.event.ListSelectionListener;
   19.32 +
   19.33 +/**
   19.34 + *
   19.35 + * @author fiki
   19.36 + */
   19.37 +public class Panel extends javax.swing.JPanel {
   19.38 +
   19.39 +	private static final int SLOUPEC_NÁZVU = 0;
   19.40 +	private static final Logger log = Logger.getLogger(Panel.class.getSimpleName());
   19.41 +	private static final ResourceBundle překlady =  ResourceBundle.getBundle(Atribut.class.getPackageName() + ".Překlady");
   19.42 +	private Model model;
   19.43 +	private Atribut vybranýAtribut;
   19.44 +	private JTable tabulka;
   19.45 +
   19.46 +	public Panel(Model model) {
   19.47 +		this.model = model;
   19.48 +		initComponents();
   19.49 +
   19.50 +		tabulka = new JTable(model);
   19.51 +		nastavEditor();
   19.52 +		tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   19.53 +		posuvnýPanel.setViewportView(tabulka);
   19.54 +
   19.55 +		/** Výběr aktuálního atributu v tabulce */
   19.56 +		tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
   19.57 +
   19.58 +			@Override
   19.59 +			public void valueChanged(ListSelectionEvent e) {
   19.60 +				int řádek = tabulka.getSelectedRow();
   19.61 +				if (řádek < 0) {
   19.62 +					vybranýAtribut = null;
   19.63 +					tlačítkoSmazat.setEnabled(false);
   19.64 +				} else {
   19.65 +					vybranýAtribut = getModel().getAtribut(řádek);
   19.66 +					tlačítkoSmazat.setEnabled(true);
   19.67 +				}
   19.68 +			}
   19.69 +		});
   19.70 +	}
   19.71 +
   19.72 +	private void nastavEditor() {
   19.73 +		tabulka.getColumnModel().getColumn(SLOUPEC_NÁZVU).setCellEditor(new EditorNázvůAtributů());
   19.74 +	}
   19.75 +
   19.76 +	private Model getModel() {
   19.77 +		return model;
   19.78 +	}
   19.79 +
   19.80 +	public void setModel(Model model) {
   19.81 +		this.model = model;
   19.82 +		tabulka.setModel(model);
   19.83 +		nastavEditor();
   19.84 +	}
   19.85 +
   19.86 +	private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
   19.87 +		JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
   19.88 +		log.log(Level.WARNING, hláška, chyba);
   19.89 +	}
   19.90 +
   19.91 +	@SuppressWarnings("unchecked")
   19.92 +    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   19.93 +    private void initComponents() {
   19.94 +
   19.95 +        posuvnýPanel = new javax.swing.JScrollPane();
   19.96 +        tlačítkoPřidat = new javax.swing.JButton();
   19.97 +        tlačítkoSmazat = new javax.swing.JButton();
   19.98 +        tlačítkoZnovuNačíst = new javax.swing.JButton();
   19.99 +
  19.100 +        tlačítkoPřidat.setMnemonic('p');
  19.101 +        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneatributy/Překlady"); // NOI18N
  19.102 +        tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
  19.103 +        tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
  19.104 +            public void actionPerformed(java.awt.event.ActionEvent evt) {
  19.105 +                tlačítkoPřidatActionPerformed(evt);
  19.106 +            }
  19.107 +        });
  19.108 +
  19.109 +        tlačítkoSmazat.setMnemonic('s');
  19.110 +        tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
  19.111 +        tlačítkoSmazat.setEnabled(false);
  19.112 +        tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
  19.113 +            public void actionPerformed(java.awt.event.ActionEvent evt) {
  19.114 +                tlačítkoSmazatActionPerformed(evt);
  19.115 +            }
  19.116 +        });
  19.117 +
  19.118 +        tlačítkoZnovuNačíst.setMnemonic('z');
  19.119 +        tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
  19.120 +        tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
  19.121 +            public void actionPerformed(java.awt.event.ActionEvent evt) {
  19.122 +                tlačítkoZnovuNačístActionPerformed(evt);
  19.123 +            }
  19.124 +        });
  19.125 +
  19.126 +        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  19.127 +        this.setLayout(layout);
  19.128 +        layout.setHorizontalGroup(
  19.129 +            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  19.130 +            .addGroup(layout.createSequentialGroup()
  19.131 +                .addContainerGap()
  19.132 +                .addComponent(tlačítkoPřidat)
  19.133 +                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  19.134 +                .addComponent(tlačítkoSmazat)
  19.135 +                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  19.136 +                .addComponent(tlačítkoZnovuNačíst)
  19.137 +                .addContainerGap(222, Short.MAX_VALUE))
  19.138 +            .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
  19.139 +        );
  19.140 +        layout.setVerticalGroup(
  19.141 +            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  19.142 +            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  19.143 +                .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
  19.144 +                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  19.145 +                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  19.146 +                    .addComponent(tlačítkoPřidat)
  19.147 +                    .addComponent(tlačítkoSmazat)
  19.148 +                    .addComponent(tlačítkoZnovuNačíst))
  19.149 +                .addContainerGap())
  19.150 +        );
  19.151 +    }// </editor-fold>//GEN-END:initComponents
  19.152 +
  19.153 +	private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
  19.154 +		model.přidejAtribut(new Atribut());
  19.155 +	}//GEN-LAST:event_tlačítkoPřidatActionPerformed
  19.156 +
  19.157 +	private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
  19.158 +		try {
  19.159 +			model.odeberAtribut(vybranýAtribut);
  19.160 +		} catch (IOException e) {
  19.161 +			zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
  19.162 +		}
  19.163 +	}//GEN-LAST:event_tlačítkoSmazatActionPerformed
  19.164 +
  19.165 +	private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
  19.166 +		try {
  19.167 +			model.načtiAtributy();
  19.168 +		} catch (IOException e) {
  19.169 +			zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
  19.170 +		}
  19.171 +	}//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
  19.172 +    // Variables declaration - do not modify//GEN-BEGIN:variables
  19.173 +    private javax.swing.JScrollPane posuvnýPanel;
  19.174 +    private javax.swing.JButton tlačítkoPřidat;
  19.175 +    private javax.swing.JButton tlačítkoSmazat;
  19.176 +    private javax.swing.JButton tlačítkoZnovuNačíst;
  19.177 +    // End of variables declaration//GEN-END:variables
  19.178 +}