java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java
branchv_0
changeset 31 1ab5ce94a146
parent 30 d511e4bf7d8f
     1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java	Tue Dec 12 21:19:11 2023 +0100
     1.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java	Fri Dec 15 01:36:17 2023 +0100
     1.3 @@ -1,22 +1,23 @@
     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 + *
     1.9   * This program is free software: you can redistribute it and/or modify
    1.10   * it under the terms of the GNU General Public License as published by
    1.11   * the Free Software Foundation, either version 3 of the License.
    1.12 - * 
    1.13 + *
    1.14   * This program is distributed in the hope that it will be useful,
    1.15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17   * GNU General Public License for more details.
    1.18 - * 
    1.19 + *
    1.20   * You should have received a copy of the GNU General Public License
    1.21   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22   */
    1.23  package cz.frantovo.rozsireneatributy.gui;
    1.24  
    1.25  import cz.frantovo.rozsireneatributy.Atribut;
    1.26 +import cz.frantovo.rozsireneatributy.Konfigurace;
    1.27  import java.io.File;
    1.28  import java.io.IOException;
    1.29  import java.io.RandomAccessFile;
    1.30 @@ -46,28 +47,32 @@
    1.31  		.getLogger(Model.class.getSimpleName());
    1.32  	private static final ResourceBundle překlady = ResourceBundle
    1.33  		.getBundle(Atribut.class.getPackageName() + ".Překlady");
    1.34 -	private String[] sloupečky = {
    1.35 +	private final String[] sloupečky = {
    1.36  		překlady.getString("tabulka.název"),
    1.37  		překlady.getString("tabulka.hodnota")
    1.38  	};
    1.39 -	private Set<TableModelListener> posluchače = new HashSet<>();
    1.40 -	private File soubor;
    1.41 -	private UserDefinedFileAttributeView souborovýSystém;
    1.42 -	private List<Atribut> atributy = new ArrayList<>();
    1.43 +	private final Set<TableModelListener> posluchače = new HashSet<>();
    1.44 +	private final Konfigurace konfigurace;
    1.45 +	private final UserDefinedFileAttributeView souborovýSystém;
    1.46 +	private final List<Atribut> atributy = new ArrayList<>();
    1.47  
    1.48  	private RandomAccessFile zámekSoubor;
    1.49  	private FileChannel zámekKanál;
    1.50  	private FileLock zámek;
    1.51  
    1.52 -	public Model(File soubor) throws IOException {
    1.53 -		this.soubor = soubor;
    1.54 -		Path cesta = soubor.toPath();
    1.55 +	public Model(Konfigurace konfigurace) throws IOException {
    1.56 +		this.konfigurace = konfigurace;
    1.57 +		Path cesta = konfigurace.getSoubor().toPath();
    1.58  		FileSystemProvider posyktovatelFS = cesta.getFileSystem().provider();
    1.59  		souborovýSystém = posyktovatelFS
    1.60  			.getFileAttributeView(cesta, UserDefinedFileAttributeView.class);
    1.61  		načtiAtributy();
    1.62  	}
    1.63  
    1.64 +	public Konfigurace getKonfigurace() {
    1.65 +		return konfigurace;
    1.66 +	}
    1.67 +
    1.68  	@Override
    1.69  	public int getRowCount() {
    1.70  		return atributy.size();
    1.71 @@ -95,12 +100,13 @@
    1.72  
    1.73  	@Override
    1.74  	public Object getValueAt(int m, int n) {
    1.75 -		if (n == 0) {
    1.76 -			return atributy.get(m).getKlíč();
    1.77 -		} else if (n == 1) {
    1.78 -			return atributy.get(m).getHodnota();
    1.79 -		} else {
    1.80 -			return null;
    1.81 +		switch (n) {
    1.82 +			case 0:
    1.83 +				return atributy.get(m).getKlíč();
    1.84 +			case 1:
    1.85 +				return atributy.get(m).getHodnota();
    1.86 +			default:
    1.87 +				return null;
    1.88  		}
    1.89  	}
    1.90  
    1.91 @@ -109,7 +115,9 @@
    1.92  		Atribut a = atributy.get(m);
    1.93  		try {
    1.94  			if (n == 0) {
    1.95 -				/** Měníme klíč – název atributu */
    1.96 +				/**
    1.97 +				 * Měníme klíč – název atributu
    1.98 +				 */
    1.99  				String novýKlíč = String.valueOf(hodnota);
   1.100  				if (!novýKlíč.equals(a.getKlíč())) {
   1.101  					if (a.isPlatnýKlíč()) {
   1.102 @@ -121,7 +129,9 @@
   1.103  					}
   1.104  				}
   1.105  			} else if (n == 1) {
   1.106 -				/** Měníme hodnotu atributu */
   1.107 +				/**
   1.108 +				 * Měníme hodnotu atributu
   1.109 +				 */
   1.110  				a.setHodnota(String.valueOf(hodnota));
   1.111  				if (a.isPlatnýKlíč() && a.isPlatnáHodnota()) {
   1.112  					souborovýSystém.write(a.getKlíč(), a.getHodnotaBajty());
   1.113 @@ -182,7 +192,7 @@
   1.114  	}
   1.115  
   1.116  	public boolean isZámekPodporovaný() {
   1.117 -		return soubor.isFile();
   1.118 +		return konfigurace.getSoubor().isFile();
   1.119  	}
   1.120  
   1.121  	public void nastavZámek(boolean zamknout) throws IOException {
   1.122 @@ -192,7 +202,7 @@
   1.123  		}
   1.124  
   1.125  		if (zamknout && zámekSoubor == null) {
   1.126 -			zámekSoubor = new RandomAccessFile(soubor, "rw");
   1.127 +			zámekSoubor = new RandomAccessFile(konfigurace.getSoubor(), "rw");
   1.128  			zámekKanál = zámekSoubor.getChannel();
   1.129  			zámek = zámekKanál.lock();
   1.130  		} else if (!zamknout && zámekSoubor != null) {