diff -r 41e91ea94acb -r ec0e970e0830 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorHodnotAtributů.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorHodnotAtributů.java Sat Dec 16 19:09:35 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +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.Konfigurace; -import cz.frantovo.rozsireneatributy.Konfigurace.DefiniceAtributu; -import cz.frantovo.rozsireneatributy.Konfigurace.DefiniceHodnoty; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.EventObject; -import java.util.Objects; -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; -import javax.swing.table.TableModel; - -/** - * Umožňuje výběr hodnoty atributu z předvoleného seznamu. - * - * @author Ing. František Kučera (frantovo.cz) - */ -public class EditorHodnotAtributů - extends JComboBox - implements TableCellEditor { - - private final Konfigurace konfigurace; - private JTable tabulka; - private TableModel model; - private int řádek; - private int sloupec; - protected EventListenerList posluchače = new EventListenerList(); - protected ChangeEvent událost = new ChangeEvent(this); - - public EditorHodnotAtributů(Konfigurace konfigurace) { - super(); - this.konfigurace = konfigurace; - 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); - } - } - } - - private void obnovHodnoty(Object hodnotaAtributu) { - removeAllItems(); - - if (hodnotaAtributu == null) { - hodnotaAtributu = ""; - } else if (!(hodnotaAtributu instanceof String)) { - hodnotaAtributu = String.valueOf(hodnotaAtributu); - } - addItem((String) hodnotaAtributu); - setSelectedItem(hodnotaAtributu); - - Object názevAtributu = model.getValueAt(řádek, Panel.SLOUPEC_NÁZVU); - for (DefiniceAtributu da : konfigurace.getAtributy()) { - if (Objects.equals(názevAtributu, da.getNázev())) { - for (DefiniceHodnoty dh : da.getHodnoty()) { - addItem(dh.getNázev()); - } - } - } - - } - - @Override - public Component getTableCellEditorComponent( - JTable tabulka, - Object hodnota, - boolean vybraná, - int řádek, - int sloupec) // - { - this.řádek = řádek; - this.sloupec = sloupec; - this.tabulka = tabulka; - this.model = tabulka.getModel(); - obnovHodnoty(hodnota); - // TODO: více různých instancí? - 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); - } -}