# HG changeset patch # User František Kučera # Date 1349615502 -7200 # Node ID bf06eb899671058e015261202a93ea389b10f4b1 # Parent c0e70d138e420ce3be7e788b3f14bc6b662ac9b2 nabídka standardizovaných atributů http://www.freedesktop.org/wiki/CommonExtendedAttributes diff -r c0e70d138e42 -r bf06eb899671 java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java --- a/java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java Sun Oct 07 15:10:42 2012 +0200 +++ b/java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java Sun Oct 07 15:11:42 2012 +0200 @@ -100,6 +100,7 @@ add(p, BorderLayout.CENTER); } else { // TODO: zobrazit chybu + log.log(Level.WARNING, "Soubor neexistuje nebo nemáme práva na čtení: {0}", s); } } catch (IOException e) { log.log(Level.WARNING, "Chyba při změně souboru.", e); diff -r c0e70d138e42 -r bf06eb899671 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 Sun Oct 07 15:11:42 2012 +0200 @@ -0,0 +1,174 @@ +/** + * 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, or + * (at your option) any later version. + * + * 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 c0e70d138e42 -r bf06eb899671 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java Sun Oct 07 15:10:42 2012 +0200 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Model.java Sun Oct 07 15:11:42 2012 +0200 @@ -28,6 +28,7 @@ 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; @@ -43,9 +44,9 @@ 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 HashSet posluchače = new HashSet(); + private Set posluchače = new HashSet<>(); private UserDefinedFileAttributeView souborovýSystém; - private ArrayList atributy = new ArrayList(); + private List atributy = new ArrayList<>(); public Model(File soubor) throws IOException { Path cesta = soubor.toPath(); @@ -54,26 +55,32 @@ 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íč(); @@ -84,6 +91,7 @@ } } + @Override public void setValueAt(Object hodnota, int m, int n) { Atribut a = atributy.get(m); try { @@ -111,10 +119,12 @@ } } + @Override public void addTableModelListener(TableModelListener l) { posluchače.add(l); } + @Override public void removeTableModelListener(TableModelListener l) { posluchače.remove(l); } diff -r c0e70d138e42 -r bf06eb899671 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java Sun Oct 07 15:10:42 2012 +0200 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java Sun Oct 07 15:11:42 2012 +0200 @@ -1,19 +1,19 @@ /** * 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, or * (at your option) any later version. - * + * * 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 + * 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 . + * along with this program. If not, see . */ package cz.frantovo.rozsireneAtributy.gui; @@ -45,12 +45,14 @@ initComponents(); tabulka = new JTable(model); + tabulka.getColumnModel().getColumn(0).setCellEditor(new EditorNázvůAtributů()); 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) {