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