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