diff -r d511e4bf7d8f -r 1ab5ce94a146 java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java Tue Dec 12 21:19:11 2023 +0100 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/gui/Model.java Fri Dec 15 01:36:17 2023 +0100 @@ -1,22 +1,23 @@ /** * 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 cz.frantovo.rozsireneatributy.Konfigurace; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; @@ -46,28 +47,32 @@ .getLogger(Model.class.getSimpleName()); private static final ResourceBundle překlady = ResourceBundle .getBundle(Atribut.class.getPackageName() + ".Překlady"); - private String[] sloupečky = { + private final String[] sloupečky = { překlady.getString("tabulka.název"), překlady.getString("tabulka.hodnota") }; - private Set posluchače = new HashSet<>(); - private File soubor; - private UserDefinedFileAttributeView souborovýSystém; - private List atributy = new ArrayList<>(); + private final Set posluchače = new HashSet<>(); + private final Konfigurace konfigurace; + private final UserDefinedFileAttributeView souborovýSystém; + private final List atributy = new ArrayList<>(); private RandomAccessFile zámekSoubor; private FileChannel zámekKanál; private FileLock zámek; - public Model(File soubor) throws IOException { - this.soubor = soubor; - Path cesta = soubor.toPath(); + public Model(Konfigurace konfigurace) throws IOException { + this.konfigurace = konfigurace; + Path cesta = konfigurace.getSoubor().toPath(); FileSystemProvider posyktovatelFS = cesta.getFileSystem().provider(); souborovýSystém = posyktovatelFS .getFileAttributeView(cesta, UserDefinedFileAttributeView.class); načtiAtributy(); } + public Konfigurace getKonfigurace() { + return konfigurace; + } + @Override public int getRowCount() { return atributy.size(); @@ -95,12 +100,13 @@ @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; + switch (n) { + case 0: + return atributy.get(m).getKlíč(); + case 1: + return atributy.get(m).getHodnota(); + default: + return null; } } @@ -109,7 +115,9 @@ Atribut a = atributy.get(m); try { if (n == 0) { - /** Měníme klíč – název atributu */ + /** + * Měníme klíč – název atributu + */ String novýKlíč = String.valueOf(hodnota); if (!novýKlíč.equals(a.getKlíč())) { if (a.isPlatnýKlíč()) { @@ -121,7 +129,9 @@ } } } else if (n == 1) { - /** Měníme hodnotu atributu */ + /** + * 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()); @@ -182,7 +192,7 @@ } public boolean isZámekPodporovaný() { - return soubor.isFile(); + return konfigurace.getSoubor().isFile(); } public void nastavZámek(boolean zamknout) throws IOException { @@ -192,7 +202,7 @@ } if (zamknout && zámekSoubor == null) { - zámekSoubor = new RandomAccessFile(soubor, "rw"); + zámekSoubor = new RandomAccessFile(konfigurace.getSoubor(), "rw"); zámekKanál = zámekSoubor.getChannel(); zámek = zámekKanál.lock(); } else if (!zamknout && zámekSoubor != null) {