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