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