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@15
|
26 |
import java.text.MessageFormat;
|
franta-hg@15
|
27 |
import java.util.ResourceBundle;
|
franta-hg@6
|
28 |
import java.util.logging.Level;
|
franta-hg@6
|
29 |
import java.util.logging.Logger;
|
franta-hg@11
|
30 |
import javax.swing.JComponent;
|
franta-hg@6
|
31 |
import javax.swing.JFrame;
|
franta-hg@7
|
32 |
import javax.swing.JOptionPane;
|
franta-hg@11
|
33 |
import javax.swing.KeyStroke;
|
franta-hg@6
|
34 |
|
franta-hg@4
|
35 |
/**
|
franta-hg@4
|
36 |
* Spouštěč programu
|
franta-hg@6
|
37 |
*
|
franta-hg@6
|
38 |
* http://freedesktop.org/wiki/CommonExtendedAttributes
|
franta-hg@6
|
39 |
* http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
|
franta-hg@29
|
40 |
* http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html
|
franta-hg@31
|
41 |
* #so-what-is-a-path-really
|
franta-hg@6
|
42 |
*
|
franta-hg@31
|
43 |
* $ setfattr -n "user.franta.pozdrav" -v 'Dobrý den!' pokus.txt (v javě pak
|
franta-hg@31
|
44 |
* pracujeme s klíči bez předpony „user.“)
|
franta-hg@31
|
45 |
*
|
franta-hg@30
|
46 |
* @author Ing. František Kučera (frantovo.cz)
|
franta-hg@4
|
47 |
*/
|
franta-hg@5
|
48 |
public class Startér {
|
franta-hg@4
|
49 |
|
franta-hg@29
|
50 |
private static final Logger log = Logger
|
franta-hg@29
|
51 |
.getLogger(Startér.class.getSimpleName());
|
franta-hg@29
|
52 |
private static final ResourceBundle překlady = ResourceBundle
|
franta-hg@29
|
53 |
.getBundle(Atribut.class.getPackageName() + ".Překlady");
|
franta-hg@6
|
54 |
|
franta-hg@8
|
55 |
/**
|
franta-hg@8
|
56 |
* @param args název souboru
|
franta-hg@8
|
57 |
*/
|
franta-hg@31
|
58 |
public static void main(String[] args) {
|
franta-hg@6
|
59 |
|
franta-hg@31
|
60 |
try {
|
franta-hg@31
|
61 |
// TODO: načítat konfiguraci i z XML souboru
|
franta-hg@31
|
62 |
CLIParser parser = new CLIParser();
|
franta-hg@31
|
63 |
Konfigurace konfigurace = parser.parsujParametry(args);
|
franta-hg@15
|
64 |
|
franta-hg@31
|
65 |
File soubor = konfigurace.getSoubor();
|
franta-hg@6
|
66 |
|
franta-hg@7
|
67 |
if (soubor.exists()) {
|
franta-hg@7
|
68 |
log.log(Level.INFO, "Pracuji se souborem: {0}", soubor);
|
franta-hg@6
|
69 |
|
franta-hg@31
|
70 |
Model model = new Model(konfigurace);
|
franta-hg@6
|
71 |
|
franta-hg@11
|
72 |
final JFrame f = new JFrame();
|
franta-hg@7
|
73 |
Panel p = new Panel(model);
|
franta-hg@6
|
74 |
|
franta-hg@7
|
75 |
f.setLayout(new BorderLayout());
|
franta-hg@7
|
76 |
f.add(p, BorderLayout.CENTER);
|
franta-hg@6
|
77 |
|
franta-hg@31
|
78 |
// Ukončení programu klávesou Escape:
|
franta-hg@11
|
79 |
f.getRootPane().registerKeyboardAction(new ActionListener() {
|
franta-hg@11
|
80 |
|
franta-hg@31
|
81 |
@Override
|
franta-hg@11
|
82 |
public void actionPerformed(ActionEvent ae) {
|
franta-hg@11
|
83 |
f.dispose();
|
franta-hg@11
|
84 |
}
|
franta-hg@29
|
85 |
},
|
franta-hg@29
|
86 |
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
franta-hg@29
|
87 |
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
franta-hg@11
|
88 |
|
franta-hg@34
|
89 |
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
franta-hg@29
|
90 |
f.setTitle(MessageFormat
|
franta-hg@29
|
91 |
.format(překlady.getString("titulek"), soubor));
|
franta-hg@7
|
92 |
f.setSize(640, 240);
|
franta-hg@7
|
93 |
f.setLocationRelativeTo(null);
|
franta-hg@7
|
94 |
f.setVisible(true);
|
franta-hg@7
|
95 |
} else {
|
franta-hg@29
|
96 |
ukončiChybou(MessageFormat.format(překlady
|
franta-hg@29
|
97 |
.getString("chyba.souborNeexistuje"), soubor));
|
franta-hg@7
|
98 |
}
|
franta-hg@31
|
99 |
} catch (Exception e) {
|
franta-hg@31
|
100 |
log.log(Level.SEVERE, překlady.getString("chyba"), e);
|
franta-hg@31
|
101 |
ukončiChybou(e.getLocalizedMessage());
|
franta-hg@6
|
102 |
}
|
franta-hg@4
|
103 |
}
|
franta-hg@7
|
104 |
|
franta-hg@7
|
105 |
private static void ukončiChybou(String hláška) {
|
franta-hg@7
|
106 |
log.log(Level.SEVERE, hláška);
|
franta-hg@29
|
107 |
JOptionPane.showMessageDialog(null, hláška, překlady
|
franta-hg@29
|
108 |
.getString("chyba.titulek"), JOptionPane.ERROR_MESSAGE);
|
franta-hg@7
|
109 |
System.exit(1);
|
franta-hg@7
|
110 |
}
|
franta-hg@4
|
111 |
}
|