java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorHodnotAtributů.java
branchv_0
changeset 39 ec0e970e0830
parent 38 41e91ea94acb
child 40 1978eaf429de
     1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/EditorHodnotAtributů.java	Sat Dec 16 19:09:35 2023 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,155 +0,0 @@
     1.4 -/**
     1.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
     1.6 - * Copyright © 2012 František Kučera (frantovo.cz)
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, either version 3 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.19 - */
    1.20 -package cz.frantovo.rozsireneatributy.gui;
    1.21 -
    1.22 -import cz.frantovo.rozsireneatributy.Konfigurace;
    1.23 -import cz.frantovo.rozsireneatributy.Konfigurace.DefiniceAtributu;
    1.24 -import cz.frantovo.rozsireneatributy.Konfigurace.DefiniceHodnoty;
    1.25 -import java.awt.Component;
    1.26 -import java.awt.event.ActionEvent;
    1.27 -import java.awt.event.ActionListener;
    1.28 -import java.util.EventObject;
    1.29 -import java.util.Objects;
    1.30 -import javax.swing.JComboBox;
    1.31 -import javax.swing.JTable;
    1.32 -import javax.swing.event.CellEditorListener;
    1.33 -import javax.swing.event.ChangeEvent;
    1.34 -import javax.swing.event.EventListenerList;
    1.35 -import javax.swing.table.TableCellEditor;
    1.36 -import javax.swing.table.TableModel;
    1.37 -
    1.38 -/**
    1.39 - * Umožňuje výběr hodnoty atributu z předvoleného seznamu.
    1.40 - *
    1.41 - * @author Ing. František Kučera (frantovo.cz)
    1.42 - */
    1.43 -public class EditorHodnotAtributů
    1.44 -	extends JComboBox<String>
    1.45 -	implements TableCellEditor {
    1.46 -
    1.47 -	private final Konfigurace konfigurace;
    1.48 -	private JTable tabulka;
    1.49 -	private TableModel model;
    1.50 -	private int řádek;
    1.51 -	private int sloupec;
    1.52 -	protected EventListenerList posluchače = new EventListenerList();
    1.53 -	protected ChangeEvent událost = new ChangeEvent(this);
    1.54 -
    1.55 -	public EditorHodnotAtributů(Konfigurace konfigurace) {
    1.56 -		super();
    1.57 -		this.konfigurace = konfigurace;
    1.58 -		setEditable(true);
    1.59 -		addActionListener(new ActionListener() {
    1.60 -
    1.61 -			@Override
    1.62 -			public void actionPerformed(ActionEvent e) {
    1.63 -				fireEditiaceSkončila();
    1.64 -			}
    1.65 -		});
    1.66 -	}
    1.67 -
    1.68 -	protected void fireEditiaceSkončila() {
    1.69 -		for (Object posluchač : posluchače.getListenerList()) {
    1.70 -			if (posluchač instanceof CellEditorListener) {
    1.71 -				((CellEditorListener) posluchač).editingStopped(událost);
    1.72 -			}
    1.73 -		}
    1.74 -	}
    1.75 -
    1.76 -	protected void fireEditiaceZrušena() {
    1.77 -		for (Object posluchač : posluchače.getListenerList()) {
    1.78 -			if (posluchač instanceof CellEditorListener) {
    1.79 -				((CellEditorListener) posluchač).editingCanceled(událost);
    1.80 -			}
    1.81 -		}
    1.82 -	}
    1.83 -
    1.84 -	private void obnovHodnoty(Object hodnotaAtributu) {
    1.85 -		removeAllItems();
    1.86 -
    1.87 -		if (hodnotaAtributu == null) {
    1.88 -			hodnotaAtributu = "";
    1.89 -		} else if (!(hodnotaAtributu instanceof String)) {
    1.90 -			hodnotaAtributu = String.valueOf(hodnotaAtributu);
    1.91 -		}
    1.92 -		addItem((String) hodnotaAtributu);
    1.93 -		setSelectedItem(hodnotaAtributu);
    1.94 -
    1.95 -		Object názevAtributu = model.getValueAt(řádek, Panel.SLOUPEC_NÁZVU);
    1.96 -		for (DefiniceAtributu da : konfigurace.getAtributy()) {
    1.97 -			if (Objects.equals(názevAtributu, da.getNázev())) {
    1.98 -				for (DefiniceHodnoty dh : da.getHodnoty()) {
    1.99 -					addItem(dh.getNázev());
   1.100 -				}
   1.101 -			}
   1.102 -		}
   1.103 -
   1.104 -	}
   1.105 -
   1.106 -	@Override
   1.107 -	public Component getTableCellEditorComponent(
   1.108 -		JTable tabulka,
   1.109 -		Object hodnota,
   1.110 -		boolean vybraná,
   1.111 -		int řádek,
   1.112 -		int sloupec) //
   1.113 -	{
   1.114 -		this.řádek = řádek;
   1.115 -		this.sloupec = sloupec;
   1.116 -		this.tabulka = tabulka;
   1.117 -		this.model = tabulka.getModel();
   1.118 -		obnovHodnoty(hodnota);
   1.119 -		// TODO: více různých instancí?
   1.120 -		return this;
   1.121 -	}
   1.122 -
   1.123 -	@Override
   1.124 -	public Object getCellEditorValue() {
   1.125 -		return getSelectedItem();
   1.126 -	}
   1.127 -
   1.128 -	@Override
   1.129 -	public boolean isCellEditable(EventObject anEvent) {
   1.130 -		return true;
   1.131 -	}
   1.132 -
   1.133 -	@Override
   1.134 -	public boolean shouldSelectCell(EventObject anEvent) {
   1.135 -		return true;
   1.136 -	}
   1.137 -
   1.138 -	@Override
   1.139 -	public boolean stopCellEditing() {
   1.140 -		fireEditiaceSkončila();
   1.141 -		return true;
   1.142 -	}
   1.143 -
   1.144 -	@Override
   1.145 -	public void cancelCellEditing() {
   1.146 -		fireEditiaceZrušena();
   1.147 -	}
   1.148 -
   1.149 -	@Override
   1.150 -	public void addCellEditorListener(CellEditorListener l) {
   1.151 -		posluchače.add(CellEditorListener.class, l);
   1.152 -	}
   1.153 -
   1.154 -	@Override
   1.155 -	public void removeCellEditorListener(CellEditorListener l) {
   1.156 -		posluchače.remove(CellEditorListener.class, l);
   1.157 -	}
   1.158 -}