java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Startér.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 11 Dec 2023 00:28:30 +0100
branchv_0
changeset 28 c2ffda907125
parent 27 java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.java@dc5786f3482b
child 29 8d42303538ed
permissions -rw-r--r--
oprava názvu balíčku
franta-hg@19
     1
/**
franta-hg@19
     2
 * Rozšířené atributy – program na správu rozšířených atributů souborů
franta-hg@19
     3
 * Copyright © 2012 František Kučera (frantovo.cz)
franta-hg@28
     4
 *
franta-hg@19
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@19
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@27
     7
 * the Free Software Foundation, either version 3 of the License.
franta-hg@28
     8
 *
franta-hg@19
     9
 * This program is distributed in the hope that it will be useful,
franta-hg@19
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@19
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
franta-hg@19
    12
 * GNU General Public License for more details.
franta-hg@28
    13
 *
franta-hg@19
    14
 * You should have received a copy of the GNU General Public License
franta-hg@19
    15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
franta-hg@19
    16
 */
franta-hg@28
    17
package cz.frantovo.rozsireneatributy;
franta-hg@4
    18
franta-hg@28
    19
import cz.frantovo.rozsireneatributy.gui.Model;
franta-hg@28
    20
import cz.frantovo.rozsireneatributy.gui.Panel;
franta-hg@6
    21
import java.awt.BorderLayout;
franta-hg@11
    22
import java.awt.event.ActionEvent;
franta-hg@11
    23
import java.awt.event.ActionListener;
franta-hg@11
    24
import java.awt.event.KeyEvent;
franta-hg@6
    25
import java.io.File;
franta-hg@6
    26
import java.io.IOException;
franta-hg@15
    27
import java.text.MessageFormat;
franta-hg@15
    28
import java.util.ResourceBundle;
franta-hg@6
    29
import java.util.logging.Level;
franta-hg@6
    30
import java.util.logging.Logger;
franta-hg@11
    31
import javax.swing.JComponent;
franta-hg@6
    32
import javax.swing.JFrame;
franta-hg@7
    33
import javax.swing.JOptionPane;
franta-hg@11
    34
import javax.swing.KeyStroke;
franta-hg@6
    35
franta-hg@4
    36
/**
franta-hg@4
    37
 * Spouštěč programu
franta-hg@6
    38
 *
franta-hg@6
    39
 * http://freedesktop.org/wiki/CommonExtendedAttributes
franta-hg@6
    40
 * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
franta-hg@6
    41
 * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really
franta-hg@6
    42
 *
franta-hg@6
    43
 * $ setfattr -n "user.fiki.pozdrav" -v 'Dobrý den!' pokus.txt
franta-hg@6
    44
 * (v javě pak pracujeme s klíči bez předpony „user.“)
franta-hg@6
    45
 *
franta-hg@4
    46
 * @author fiki
franta-hg@4
    47
 */
franta-hg@5
    48
public class Startér {
franta-hg@4
    49
franta-hg@6
    50
	private static final Logger log = Logger.getLogger(Startér.class.getSimpleName());
franta-hg@28
    51
	private static final ResourceBundle překlady = ResourceBundle.getBundle(Atribut.class.getPackageName() + ".Překlady");
franta-hg@6
    52
franta-hg@8
    53
	/**
franta-hg@8
    54
	 * @param args název souboru
franta-hg@8
    55
	 * @throws IOException TODO: ošetřit výjimku
franta-hg@8
    56
	 */
franta-hg@6
    57
	public static void main(String[] args) throws IOException {
franta-hg@6
    58
franta-hg@15
    59
franta-hg@7
    60
		if (args.length == 1 && args[0].length() > 0) {
franta-hg@6
    61
			File soubor = new File(args[0]);
franta-hg@6
    62
franta-hg@7
    63
			if (soubor.exists()) {
franta-hg@7
    64
				log.log(Level.INFO, "Pracuji se souborem: {0}", soubor);
franta-hg@6
    65
franta-hg@7
    66
				Model model = new Model(soubor);
franta-hg@6
    67
franta-hg@11
    68
				final JFrame f = new JFrame();
franta-hg@7
    69
				Panel p = new Panel(model);
franta-hg@6
    70
franta-hg@7
    71
				f.setLayout(new BorderLayout());
franta-hg@7
    72
				f.add(p, BorderLayout.CENTER);
franta-hg@6
    73
franta-hg@11
    74
				/** Ukončení programu klávesou Escape */
franta-hg@11
    75
				f.getRootPane().registerKeyboardAction(new ActionListener() {
franta-hg@11
    76
franta-hg@11
    77
					public void actionPerformed(ActionEvent ae) {
franta-hg@11
    78
						f.dispose();
franta-hg@11
    79
					}
franta-hg@11
    80
				}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
franta-hg@11
    81
franta-hg@8
    82
				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
franta-hg@15
    83
				f.setTitle(MessageFormat.format(překlady.getString("titulek"), soubor));
franta-hg@7
    84
				f.setSize(640, 240);
franta-hg@7
    85
				f.setLocationRelativeTo(null);
franta-hg@7
    86
				f.setVisible(true);
franta-hg@7
    87
			} else {
franta-hg@15
    88
				ukončiChybou(MessageFormat.format(překlady.getString("chyba.souborNeexistuje"), soubor));
franta-hg@7
    89
			}
franta-hg@6
    90
		} else {
franta-hg@15
    91
			ukončiChybou(překlady.getString("chyba.chybíParametr"));
franta-hg@6
    92
		}
franta-hg@4
    93
	}
franta-hg@7
    94
franta-hg@7
    95
	private static void ukončiChybou(String hláška) {
franta-hg@7
    96
		log.log(Level.SEVERE, hláška);
franta-hg@15
    97
		JOptionPane.showMessageDialog(null, hláška, překlady.getString("chyba.titulek"), JOptionPane.ERROR_MESSAGE);
franta-hg@7
    98
		System.exit(1);
franta-hg@7
    99
	}
franta-hg@4
   100
}