# HG changeset patch # User František Kučera # Date 1702250910 -3600 # Node ID c2ffda907125278a2dd77a6b64460fe6e3eb3b83 # Parent dc5786f3482bc2c029ca76371d8752d380995f51 oprava názvu balíčku diff -r dc5786f3482b -r c2ffda907125 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 dc5786f3482b -r c2ffda907125 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 dc5786f3482b -r c2ffda907125 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 dc5786f3482b -r c2ffda907125 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 dc5786f3482b -r c2ffda907125 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 dc5786f3482b -r c2ffda907125 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 dc5786f3482b -r c2ffda907125 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 dc5786f3482b -r c2ffda907125 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(); - } else { - return null; - } - } - - @Override - public void setValueAt(Object hodnota, int m, int n) { - Atribut a = atributy.get(m); - try { - if (n == 0) { - /** Měníme klíč – název atributu */ - String novýKlíč = String.valueOf(hodnota); - if (!novýKlíč.equals(a.getKlíč())) { - if (a.isPlatnýKlíč()) { - souborovýSystém.delete(a.getKlíč()); - } - a.setKlíč(novýKlíč); - if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) { - souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty()); - } - } - } else if (n == 1) { - /** Měníme hodnotu atributu */ - a.setHodnota(String.valueOf(hodnota)); - if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) { - souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty()); - } - } - } catch (IOException e) { - log.log(Level.SEVERE, "Selhalo ukládání atributu na souborový systém", e); - } - } - - @Override - public void addTableModelListener(TableModelListener l) { - posluchače.add(l); - } - - @Override - public void removeTableModelListener(TableModelListener l) { - posluchače.remove(l); - } - - /** - * @param m číslo řádku - * @return atribut, který se na něm nachází - */ - public Atribut getAtribut(int m) { - return atributy.get(m); - } - - public void přidejAtribut(Atribut a) { - atributy.add(a); - upozorniPosluchače(); - } - - public void odeberAtribut(Atribut a) throws IOException { - atributy.remove(a); - if (a.isPlatnýKlíč()) { - souborovýSystém.delete(a.getKlíč()); - } - upozorniPosluchače(); - } - - public final void načtiAtributy() throws IOException { - List jménaAtributů = souborovýSystém.list(); - atributy.clear(); - for (String jménoAtributu : jménaAtributů) { - ByteBuffer hodnotaAtributu = ByteBuffer.allocate(souborovýSystém.size(jménoAtributu)); - souborovýSystém.read(jménoAtributu, hodnotaAtributu); - atributy.add(new Atribut(jménoAtributu, hodnotaAtributu)); - } - upozorniPosluchače(); - } - - private void upozorniPosluchače() { - for (TableModelListener p : posluchače) { - p.tableChanged(new TableModelEvent(this)); - } - } -} diff -r dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.form --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.form Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff -r dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java Mon Dec 11 00:10:33 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +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.IOException; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JOptionPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -/** - * - * @author fiki - */ -public class Panel extends javax.swing.JPanel { - - private static final int SLOUPEC_NÁZVU = 0; - private static final Logger log = Logger.getLogger(Panel.class.getSimpleName()); - private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady"); - private Model model; - private Atribut vybranýAtribut; - private JTable tabulka; - - public Panel(Model model) { - this.model = model; - initComponents(); - - tabulka = new JTable(model); - nastavEditor(); - tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - posuvnýPanel.setViewportView(tabulka); - - /** Výběr aktuálního atributu v tabulce */ - tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - - @Override - public void valueChanged(ListSelectionEvent e) { - int řádek = tabulka.getSelectedRow(); - if (řádek < 0) { - vybranýAtribut = null; - tlačítkoSmazat.setEnabled(false); - } else { - vybranýAtribut = getModel().getAtribut(řádek); - tlačítkoSmazat.setEnabled(true); - } - } - }); - } - - private void nastavEditor() { - tabulka.getColumnModel().getColumn(SLOUPEC_NÁZVU).setCellEditor(new EditorNázvůAtributů()); - } - - private Model getModel() { - return model; - } - - public void setModel(Model model) { - this.model = model; - tabulka.setModel(model); - nastavEditor(); - } - - private void zobrazChybovouHlášku(String hláška, Throwable chyba) { - JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE); - log.log(Level.WARNING, hláška, chyba); - } - - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - posuvnýPanel = new javax.swing.JScrollPane(); - tlačítkoPřidat = new javax.swing.JButton(); - tlačítkoSmazat = new javax.swing.JButton(); - tlačítkoZnovuNačíst = new javax.swing.JButton(); - - tlačítkoPřidat.setMnemonic('p'); - java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneAtributy/Překlady"); // NOI18N - tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N - tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - tlačítkoPřidatActionPerformed(evt); - } - }); - - tlačítkoSmazat.setMnemonic('s'); - tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N - tlačítkoSmazat.setEnabled(false); - tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - tlačítkoSmazatActionPerformed(evt); - } - }); - - tlačítkoZnovuNačíst.setMnemonic('z'); - tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N - tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - tlačítkoZnovuNačístActionPerformed(evt); - } - }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(tlačítkoPřidat) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(tlačítkoSmazat) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(tlačítkoZnovuNačíst) - .addContainerGap(186, Short.MAX_VALUE)) - .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(tlačítkoPřidat) - .addComponent(tlačítkoSmazat) - .addComponent(tlačítkoZnovuNačíst)) - .addContainerGap()) - ); - }// //GEN-END:initComponents - - private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed - model.přidejAtribut(new Atribut()); - }//GEN-LAST:event_tlačítkoPřidatActionPerformed - - private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed - try { - model.odeberAtribut(vybranýAtribut); - } catch (IOException e) { - zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e); - } - }//GEN-LAST:event_tlačítkoSmazatActionPerformed - - private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed - try { - model.načtiAtributy(); - } catch (IOException e) { - zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e); - } - }//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JScrollPane posuvnýPanel; - private javax.swing.JButton tlačítkoPřidat; - private javax.swing.JButton tlačítkoSmazat; - private javax.swing.JButton tlačítkoZnovuNačíst; - // End of variables declaration//GEN-END:variables -} diff -r dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Atribut.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Atribut.java Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,94 @@ +/** + * 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 dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady.properties Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,1 @@ +Překlady_cs.properties \ No newline at end of file diff -r dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_cs.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_cs.properties Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,14 @@ +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 dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_en.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Překlady_en.properties Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,14 @@ +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 dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Startér.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Startér.java Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,100 @@ +/** + * 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(Atribut.class.getPackageName() + ".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 dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorNázvůAtributů.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorNázvůAtributů.java Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,173 @@ +/** + * 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 dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,168 @@ +/** + * 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(Atribut.class.getPackageName() + ".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(); + } else { + return null; + } + } + + @Override + public void setValueAt(Object hodnota, int m, int n) { + Atribut a = atributy.get(m); + try { + if (n == 0) { + /** Měníme klíč – název atributu */ + String novýKlíč = String.valueOf(hodnota); + if (!novýKlíč.equals(a.getKlíč())) { + if (a.isPlatnýKlíč()) { + souborovýSystém.delete(a.getKlíč()); + } + a.setKlíč(novýKlíč); + if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) { + souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty()); + } + } + } else if (n == 1) { + /** Měníme hodnotu atributu */ + a.setHodnota(String.valueOf(hodnota)); + if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) { + souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty()); + } + } + } catch (IOException e) { + log.log(Level.SEVERE, "Selhalo ukládání atributu na souborový systém", e); + } + } + + @Override + public void addTableModelListener(TableModelListener l) { + posluchače.add(l); + } + + @Override + public void removeTableModelListener(TableModelListener l) { + posluchače.remove(l); + } + + /** + * @param m číslo řádku + * @return atribut, který se na něm nachází + */ + public Atribut getAtribut(int m) { + return atributy.get(m); + } + + public void přidejAtribut(Atribut a) { + atributy.add(a); + upozorniPosluchače(); + } + + public void odeberAtribut(Atribut a) throws IOException { + atributy.remove(a); + if (a.isPlatnýKlíč()) { + souborovýSystém.delete(a.getKlíč()); + } + upozorniPosluchače(); + } + + public final void načtiAtributy() throws IOException { + List jménaAtributů = souborovýSystém.list(); + atributy.clear(); + for (String jménoAtributu : jménaAtributů) { + ByteBuffer hodnotaAtributu = ByteBuffer.allocate(souborovýSystém.size(jménoAtributu)); + souborovýSystém.read(jménoAtributu, hodnotaAtributu); + atributy.add(new Atribut(jménoAtributu, hodnotaAtributu)); + } + upozorniPosluchače(); + } + + private void upozorniPosluchače() { + for (TableModelListener p : posluchače) { + p.tableChanged(new TableModelEvent(this)); + } + } +} diff -r dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Panel.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Panel.form Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,86 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r dc5786f3482b -r c2ffda907125 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Panel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Panel.java Mon Dec 11 00:28:30 2023 +0100 @@ -0,0 +1,175 @@ +/** + * 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.IOException; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * + * @author fiki + */ +public class Panel extends javax.swing.JPanel { + + private static final int SLOUPEC_NÁZVU = 0; + private static final Logger log = Logger.getLogger(Panel.class.getSimpleName()); + private static final ResourceBundle překlady = ResourceBundle.getBundle(Atribut.class.getPackageName() + ".Překlady"); + private Model model; + private Atribut vybranýAtribut; + private JTable tabulka; + + public Panel(Model model) { + this.model = model; + initComponents(); + + tabulka = new JTable(model); + nastavEditor(); + tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + posuvnýPanel.setViewportView(tabulka); + + /** Výběr aktuálního atributu v tabulce */ + tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + int řádek = tabulka.getSelectedRow(); + if (řádek < 0) { + vybranýAtribut = null; + tlačítkoSmazat.setEnabled(false); + } else { + vybranýAtribut = getModel().getAtribut(řádek); + tlačítkoSmazat.setEnabled(true); + } + } + }); + } + + private void nastavEditor() { + tabulka.getColumnModel().getColumn(SLOUPEC_NÁZVU).setCellEditor(new EditorNázvůAtributů()); + } + + private Model getModel() { + return model; + } + + public void setModel(Model model) { + this.model = model; + tabulka.setModel(model); + nastavEditor(); + } + + private void zobrazChybovouHlášku(String hláška, Throwable chyba) { + JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE); + log.log(Level.WARNING, hláška, chyba); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + posuvnýPanel = new javax.swing.JScrollPane(); + tlačítkoPřidat = new javax.swing.JButton(); + tlačítkoSmazat = new javax.swing.JButton(); + tlačítkoZnovuNačíst = new javax.swing.JButton(); + + tlačítkoPřidat.setMnemonic('p'); + java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneatributy/Překlady"); // NOI18N + tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N + tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tlačítkoPřidatActionPerformed(evt); + } + }); + + tlačítkoSmazat.setMnemonic('s'); + tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N + tlačítkoSmazat.setEnabled(false); + tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tlačítkoSmazatActionPerformed(evt); + } + }); + + tlačítkoZnovuNačíst.setMnemonic('z'); + tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N + tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tlačítkoZnovuNačístActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(tlačítkoPřidat) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(tlačítkoSmazat) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(tlačítkoZnovuNačíst) + .addContainerGap(222, Short.MAX_VALUE)) + .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(tlačítkoPřidat) + .addComponent(tlačítkoSmazat) + .addComponent(tlačítkoZnovuNačíst)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed + model.přidejAtribut(new Atribut()); + }//GEN-LAST:event_tlačítkoPřidatActionPerformed + + private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed + try { + model.odeberAtribut(vybranýAtribut); + } catch (IOException e) { + zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e); + } + }//GEN-LAST:event_tlačítkoSmazatActionPerformed + + private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed + try { + model.načtiAtributy(); + } catch (IOException e) { + zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e); + } + }//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane posuvnýPanel; + private javax.swing.JButton tlačítkoPřidat; + private javax.swing.JButton tlačítkoSmazat; + private javax.swing.JButton tlačítkoZnovuNačíst; + // End of variables declaration//GEN-END:variables +}