java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Startér.java
author František Kučera <franta-hg@frantovo.cz>
Wed Dec 15 20:31:43 2010 +0100 (2010-12-15)
changeset 7 48d5fdb68798
parent 6 734f104f2869
child 8 971755766006
permissions -rw-r--r--
Spouštěcí skript a zpracování chyb.
     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 	public static void main(String[] args) throws IOException {
    29 
    30 		if (args.length == 1 && args[0].length() > 0) {
    31 			File soubor = new File(args[0]);
    32 
    33 			if (soubor.exists()) {
    34 				log.log(Level.INFO, "Pracuji se souborem: {0}", soubor);
    35 
    36 				Model model = new Model(soubor);
    37 
    38 				JFrame f = new JFrame();
    39 				Panel p = new Panel(model);
    40 
    41 				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    42 				f.setTitle("Rozšířené stributy souboru: " + soubor);
    43 				f.setLayout(new BorderLayout());
    44 				f.add(p, BorderLayout.CENTER);
    45 
    46 				f.setSize(640, 240);
    47 				f.setLocationRelativeTo(null);
    48 				f.setVisible(true);
    49 			} else {
    50 				ukončiChybou("Soubor neexistuje: " + soubor);
    51 			}
    52 		} else {
    53 			ukončiChybou("Očekávám právě jeden parametr – název souboru.");
    54 		}
    55 	}
    56 
    57 	private static void ukončiChybou(String hláška) {
    58 		log.log(Level.SEVERE, hláška);
    59 		JOptionPane.showMessageDialog(null, hláška, "Chyba", JOptionPane.ERROR_MESSAGE);
    60 		System.exit(1);
    61 	}
    62 }