# HG changeset patch # User František Kučera # Date 1702250910 -3600 # Node ID 1957b59c93494d69f89f137453bf237a5c1df619 # Parent 36cee2c8f5f82b6a72dc161979e0ee270aa77458 oprava názvu balíčku diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/nbproject/project.properties --- a/java/rozsirene-atributy/nbproject/project.properties Mon Dec 11 00:10:33 2023 +0100 +++ b/java/rozsirene-atributy/nbproject/project.properties Mon Dec 11 00:28:30 2023 +0100 @@ -28,7 +28,7 @@ jar.archive.disabled=${jnlp.enabled} javadoc.author=false endorsed.classpath= -main.class=cz.frantovo.rozsireneAtributy.Start\u00E9r +main.class=cz.frantovo.rozsireneatributy.Start\u00e9r junit.selected.version=4 source.encoding=UTF-8 javac.source=1.7 diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/** - * Rozšířené atributy – program na správu rozšířených atributů souborů - * Copyright © 2012 František Kučera (frantovo.cz) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package cz.frantovo.rozsireneAtributy; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; - -public class Atribut { - - private String klíč; - private String hodnota; - - public Atribut(String klíč, String hodnota) { - this.klíč = klíč; - this.hodnota = hodnota; - } - - public Atribut(String klíč, ByteBuffer hodnota) { - this.klíč = klíč; - setHodnota(hodnota); - } - - public Atribut() { - } - - public String getKlíč() { - return klíč; - } - - public void setKlíč(String klíč) { - this.klíč = klíč; - } - - /** - * Název atributu musí být nenulový a mít nějakou délku, aby šel uložit - * TODO: další kontroly? - * @return jestli je platný - */ - public boolean isPlatnýKlíč() { - return klíč != null && klíč.length() > 0; - } - - /** - * nulová hodnota → smazání atributu - * (ale může být prázdný řetězec) - * @return jestli je platná - */ - public boolean isPlatnáHodnota() { - return hodnota != null; - } - - public String getHodnota() { - return hodnota; - } - - public final ByteBuffer getHodnotaBajty() { - return zakóduj(getHodnota()); - } - - public void setHodnota(String hodnota) { - this.hodnota = hodnota; - } - - public final void setHodnota(ByteBuffer hodnota) { - setHodnota(dekóduj(hodnota)); - } - - private static String dekóduj(ByteBuffer bajty) { - bajty.flip(); - return Charset.defaultCharset().decode(bajty).toString(); - } - - private static ByteBuffer zakóduj(String text) { - if (text == null) { - return null; - } else { - return Charset.defaultCharset().encode(text); - } - } -} diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady.properties --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady.properties Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -Překlady_cs.properties \ No newline at end of file diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_cs.properties --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_cs.properties Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -titulek=Roz\u0161\u00ed\u0159en\u00e9 stributy souboru: {0} - -chyba.titulek=Chyba -chyba.souborNeexistuje=Soubor neexistuje: {0} -chyba.chyb\u00edParametr=O\u010dek\u00e1v\u00e1m pr\u00e1v\u011b jeden parametr \u2013 n\u00e1zev souboru. -chyba.nepoda\u0159iloSeSmazat=Nepoda\u0159ilo se smazat atribut. -chyba.nepoda\u0159iloSeNa\u010d\u00edst=Nepoda\u0159ilo se na\u010d\u00edst atributy. - -tabulka.n\u00e1zev=N\u00e1zev -tabulka.hodnota=Hodnota - -p\u0159idatAtribut=P\u0159idat atribut -smazatAtribut=Smazat atribut -znovuNa\u010d\u00edst=Znovu na\u010d\u00edst diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_en.properties --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Překlady_en.properties Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -titulek=Extended Attributes of file: {0} - -chyba.titulek=Error -chyba.souborNeexistuje=File does not exist: {0} -chyba.chyb\u00edParametr=Expecting one parameter \u2013 file name. -chyba.nepoda\u0159iloSeSmazat=Failed to delete the attribute. -chyba.nepoda\u0159iloSeNa\u010d\u00edst=Failed to load attributes. - -tabulka.n\u00e1zev=Name -tabulka.hodnota=Value - -p\u0159idatAtribut=Add attribute -smazatAtribut=Delete attribute -znovuNa\u010d\u00edst=Reload all diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.java Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/** - * Rozšířené atributy – program na správu rozšířených atributů souborů - * Copyright © 2012 František Kučera (frantovo.cz) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package cz.frantovo.rozsireneAtributy; - -import cz.frantovo.rozsireneAtributy.gui.Model; -import cz.frantovo.rozsireneAtributy.gui.Panel; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.io.File; -import java.io.IOException; -import java.text.MessageFormat; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; - -/** - * Spouštěč programu - * - * http://freedesktop.org/wiki/CommonExtendedAttributes - * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user - * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really - * - * $ setfattr -n "user.fiki.pozdrav" -v 'Dobrý den!' pokus.txt - * (v javě pak pracujeme s klíči bez předpony „user.“) - * - * @author fiki - */ -public class Startér { - - private static final Logger log = Logger.getLogger(Startér.class.getSimpleName()); - private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady"); - - /** - * @param args název souboru - * @throws IOException TODO: ošetřit výjimku - */ - public static void main(String[] args) throws IOException { - - - if (args.length == 1 && args[0].length() > 0) { - File soubor = new File(args[0]); - - if (soubor.exists()) { - log.log(Level.INFO, "Pracuji se souborem: {0}", soubor); - - Model model = new Model(soubor); - - final JFrame f = new JFrame(); - Panel p = new Panel(model); - - f.setLayout(new BorderLayout()); - f.add(p, BorderLayout.CENTER); - - /** Ukončení programu klávesou Escape */ - f.getRootPane().registerKeyboardAction(new ActionListener() { - - public void actionPerformed(ActionEvent ae) { - f.dispose(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); - - f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - f.setTitle(MessageFormat.format(překlady.getString("titulek"), soubor)); - f.setSize(640, 240); - f.setLocationRelativeTo(null); - f.setVisible(true); - } else { - ukončiChybou(MessageFormat.format(překlady.getString("chyba.souborNeexistuje"), soubor)); - } - } else { - ukončiChybou(překlady.getString("chyba.chybíParametr")); - } - } - - private static void ukončiChybou(String hláška) { - log.log(Level.SEVERE, hláška); - JOptionPane.showMessageDialog(null, hláška, překlady.getString("chyba.titulek"), JOptionPane.ERROR_MESSAGE); - System.exit(1); - } -} diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/EditorNázvůAtributů.java Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -/** - * Rozšířené atributy – program na správu rozšířených atributů souborů - * Copyright © 2012 František Kučera (frantovo.cz) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package cz.frantovo.rozsireneAtributy.gui; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.EventObject; -import javax.swing.JComboBox; -import javax.swing.JTable; -import javax.swing.event.CellEditorListener; -import javax.swing.event.ChangeEvent; -import javax.swing.event.EventListenerList; -import javax.swing.table.TableCellEditor; - -/** - * Umožňuje výběr názvu atributu z předvoleného seznamu (standardizované atributy). - * - * @author Ing. František Kučera (frantovo.cz) - */ -public class EditorNázvůAtributů extends JComboBox implements TableCellEditor { - - protected EventListenerList posluchače = new EventListenerList(); - protected ChangeEvent událost = new ChangeEvent(this); - - public EditorNázvůAtributů() { - super(); - setEditable(true); - addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - fireEditiaceSkončila(); - } - }); - } - - protected void fireEditiaceSkončila() { - for (Object posluchač : posluchače.getListenerList()) { - if (posluchač instanceof CellEditorListener) { - ((CellEditorListener) posluchač).editingStopped(událost); - } - } - } - - protected void fireEditiaceZrušena() { - for (Object posluchač : posluchače.getListenerList()) { - if (posluchač instanceof CellEditorListener) { - ((CellEditorListener) posluchač).editingCanceled(událost); - } - } - } - - /** - * TODO: - * - další standardní atributy - * - konfigurovatelnost - * - * @see http://www.freedesktop.org/wiki/CommonExtendedAttributes - */ - private void obnovHodnoty(Object názevAtributu) { - removeAllItems(); - - if (názevAtributu == null) { - názevAtributu = ""; - } else if (!(názevAtributu instanceof String)) { - názevAtributu = String.valueOf(názevAtributu); - } - addItem((String) názevAtributu); - setSelectedItem(názevAtributu); - - - // General attributes in current use - addItem("mime_type"); - addItem("charset"); - addItem("creator"); - - // Proposed metadata attributes - addItem("xdg.comment"); - addItem("xdg.origin.url"); - addItem("xdg.origin.email.subject"); - addItem("xdg.origin.email.from"); - addItem("xdg.origin.email.message-id"); - addItem("xdg.language"); - addItem("xdg.creator"); - addItem("xdg.publisher"); - - // Proposed control attributes - addItem("xdg.robots.index"); - addItem("xdg.robots.backup"); - - // Dublin Core - addItem("dublincore.title"); - addItem("dublincore.creator"); - addItem("dublincore.subject"); - addItem("dublincore.description"); - addItem("dublincore.publisher"); - addItem("dublincore.contributor"); - addItem("dublincore.date"); - addItem("dublincore.type"); - addItem("dublincore.format"); - addItem("dublincore.identifier"); - addItem("dublincore.source"); - addItem("dublincore.language"); - addItem("dublincore.relation"); - addItem("dublincore.coverage"); - addItem("dublincore.rights"); - - // Application-specific attributes in current use - addItem("mime_encoding"); - addItem("apache_handler"); - addItem("Beagle.AttrTime"); - addItem("Beagle.Fingerprint"); - addItem("Beagle.MTime"); - addItem("Beagle.Uid"); - } - - @Override - public Component getTableCellEditorComponent(JTable tabulka, Object hodnota, boolean vybraná, int řádek, int sloupec) { - obnovHodnoty(hodnota); - return this; - } - - @Override - public Object getCellEditorValue() { - return getSelectedItem(); - } - - @Override - public boolean isCellEditable(EventObject anEvent) { - return true; - } - - @Override - public boolean shouldSelectCell(EventObject anEvent) { - return true; - } - - @Override - public boolean stopCellEditing() { - fireEditiaceSkončila(); - return true; - } - - @Override - public void cancelCellEditing() { - fireEditiaceZrušena(); - } - - @Override - public void addCellEditorListener(CellEditorListener l) { - posluchače.add(CellEditorListener.class, l); - } - - @Override - public void removeCellEditorListener(CellEditorListener l) { - posluchače.remove(CellEditorListener.class, l); - } -} diff -r 36cee2c8f5f8 -r 1957b59c9349 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -/** - * Rozšířené atributy – program na správu rozšířených atributů souborů - * Copyright © 2012 František Kučera (frantovo.cz) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package cz.frantovo.rozsireneAtributy.gui; - -import cz.frantovo.rozsireneAtributy.Atribut; -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.file.Path; -import java.nio.file.attribute.UserDefinedFileAttributeView; -import java.nio.file.spi.FileSystemProvider; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.ResourceBundle; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.table.TableModel; - -/** - * - * @author fiki - */ -public class Model implements TableModel { - - private static final Logger log = Logger.getLogger(Model.class.getSimpleName()); - private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady"); - private String[] sloupečky = {překlady.getString("tabulka.název"), překlady.getString("tabulka.hodnota")}; - private Set posluchače = new HashSet<>(); - private UserDefinedFileAttributeView souborovýSystém; - private List atributy = new ArrayList<>(); - - public Model(File soubor) throws IOException { - Path cesta = soubor.toPath(); - FileSystemProvider posyktovatelFS = cesta.getFileSystem().provider(); - souborovýSystém = posyktovatelFS.getFileAttributeView(cesta, UserDefinedFileAttributeView.class); - načtiAtributy(); - } - - @Override - public int getRowCount() { - return atributy.size(); - } - - @Override - public int getColumnCount() { - return sloupečky.length; - } - - @Override - public String getColumnName(int n) { - return sloupečky[n]; - } - - @Override - public Class getColumnClass(int n) { - return String.class; - } - - @Override - public boolean isCellEditable(int m, int n) { - return true; - } - - @Override - public Object getValueAt(int m, int n) { - if (n == 0) { - return atributy.get(m).getKlíč(); - } else if (n == 1) { - return atributy.get(m).getHodnota();