java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.java
author František Kučera <franta-hg@frantovo.cz>
Wed Dec 15 20:41:38 2010 +0100 (2010-12-15)
changeset 8 971755766006
parent 7 48d5fdb68798
child 11 9b399cde6a3b
permissions -rw-r--r--
drobnosti
     1 package cz.frantovo.rozsireneAtributy;
     2 
     3 import cz.frantovo.rozsireneAtributy.gui.Panel;
     4 import java.awt.BorderLayout;
     5 import java.io.File;
     6 import java.io.IOException;
     7 import java.util.logging.Level;
     8 import java.util.logging.Logger;
     9 import javax.swing.JFrame;
    10 import javax.swing.JOptionPane;
    11 
    12 /**
    13  * Spouštěč programu
    14  *
    15  * http://freedesktop.org/wiki/CommonExtendedAttributes
    16  * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
    17  * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really
    18  *
    19  * $ setfattr -n "user.fiki.pozdrav" -v 'Dobrý den!' pokus.txt
    20  * (v javě pak pracujeme s klíči bez předpony „user.“)
    21  *
    22  * @author fiki
    23  */
    24 public class Startér {
    25 
    26 	private static final Logger log = Logger.getLogger(Startér.class.getSimpleName());
    27 
    28 	/**
    29 	 * @param args název souboru
    30 	 * @throws IOException TODO: ošetřit výjimku
    31 	 */
    32 	public static void main(String[] args) throws IOException {
    33 
    34 		if (args.length == 1 && args[0].length() > 0) {
    35 			File soubor = new File(args[0]);
    36 
    37 			if (soubor.exists()) {
    38 				log.log(Level.INFO, "Pracuji se souborem: {0}", soubor);
    39 
    40 				Model model = new Model(soubor);
    41 
    42 				JFrame f = new JFrame();
    43 				Panel p = new Panel(model);
    44 
    45 				f.setLayout(new BorderLayout());
    46 				f.add(p, BorderLayout.CENTER);
    47 
    48 				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    49 				f.setTitle("Rozšířené stributy souboru: " + soubor);
    50 				f.setSize(640, 240);
    51 				f.setLocationRelativeTo(null);
    52 				f.setVisible(true);
    53 			} else {
    54 				ukončiChybou("Soubor neexistuje: " + soubor);
    55 			}
    56 		} else {
    57 			ukončiChybou("Očekávám právě jeden parametr – název souboru.");
    58 		}
    59 	}
    60 
    61 	private static void ukončiChybou(String hláška) {
    62 		log.log(Level.SEVERE, hláška);
    63 		JOptionPane.showMessageDialog(null, hláška, "Chyba", JOptionPane.ERROR_MESSAGE);
    64 		System.exit(1);
    65 	}
    66 }