java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.java
author František Kučera <franta-hg@frantovo.cz>
Tue Dec 28 17:02:08 2010 +0100 (2010-12-28)
changeset 15 8854e172a18f
parent 13 6c633be53dd6
child 19 c20edbed09c3
permissions -rw-r--r--
Lokalizace + anglický překlad.
     1 package cz.frantovo.rozsireneAtributy;
     2 
     3 import cz.frantovo.rozsireneAtributy.gui.Model;
     4 import cz.frantovo.rozsireneAtributy.gui.Panel;
     5 import java.awt.BorderLayout;
     6 import java.awt.event.ActionEvent;
     7 import java.awt.event.ActionListener;
     8 import java.awt.event.KeyEvent;
     9 import java.io.File;
    10 import java.io.IOException;
    11 import java.text.MessageFormat;
    12 import java.util.ResourceBundle;
    13 import java.util.logging.Level;
    14 import java.util.logging.Logger;
    15 import javax.swing.JComponent;
    16 import javax.swing.JFrame;
    17 import javax.swing.JOptionPane;
    18 import javax.swing.KeyStroke;
    19 
    20 /**
    21  * Spouštěč programu
    22  *
    23  * http://freedesktop.org/wiki/CommonExtendedAttributes
    24  * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
    25  * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really
    26  *
    27  * $ setfattr -n "user.fiki.pozdrav" -v 'Dobrý den!' pokus.txt
    28  * (v javě pak pracujeme s klíči bez předpony „user.“)
    29  *
    30  * @author fiki
    31  */
    32 public class Startér {
    33 
    34 	private static final Logger log = Logger.getLogger(Startér.class.getSimpleName());
    35 	private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
    36 
    37 	/**
    38 	 * @param args název souboru
    39 	 * @throws IOException TODO: ošetřit výjimku
    40 	 */
    41 	public static void main(String[] args) throws IOException {
    42 
    43 
    44 		if (args.length == 1 && args[0].length() > 0) {
    45 			File soubor = new File(args[0]);
    46 
    47 			if (soubor.exists()) {
    48 				log.log(Level.INFO, "Pracuji se souborem: {0}", soubor);
    49 
    50 				Model model = new Model(soubor);
    51 
    52 				final JFrame f = new JFrame();
    53 				Panel p = new Panel(model);
    54 
    55 				f.setLayout(new BorderLayout());
    56 				f.add(p, BorderLayout.CENTER);
    57 
    58 				/** Ukončení programu klávesou Escape */
    59 				f.getRootPane().registerKeyboardAction(new ActionListener() {
    60 
    61 					public void actionPerformed(ActionEvent ae) {
    62 						f.dispose();
    63 					}
    64 				}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    65 
    66 				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    67 				f.setTitle(MessageFormat.format(překlady.getString("titulek"), soubor));
    68 				f.setSize(640, 240);
    69 				f.setLocationRelativeTo(null);
    70 				f.setVisible(true);
    71 			} else {
    72 				ukončiChybou(MessageFormat.format(překlady.getString("chyba.souborNeexistuje"), soubor));
    73 			}
    74 		} else {
    75 			ukončiChybou(překlady.getString("chyba.chybíParametr"));
    76 		}
    77 	}
    78 
    79 	private static void ukončiChybou(String hláška) {
    80 		log.log(Level.SEVERE, hláška);
    81 		JOptionPane.showMessageDialog(null, hláška, překlady.getString("chyba.titulek"), JOptionPane.ERROR_MESSAGE);
    82 		System.exit(1);
    83 	}
    84 }