1 package sk.stuba.fiit.foo07.genex.gui;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.io.File;
6 import java.io.IOException;
7
8 import javax.swing.JButton;
9 import javax.swing.JFileChooser;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.JTextField;
13 import javax.swing.SwingUtilities;
14 import javax.swing.WindowConstants;
15 import javax.swing.filechooser.FileNameExtensionFilter;
16
17 import sk.stuba.fiit.foo07.genex.common.SettingsHelper;
18
19
20
21
22
23
24
25
26
27
28
29 public class PropertiesDialog extends javax.swing.JDialog {
30
31
32
33
34 private static final long serialVersionUID = 4005386130323361864L;
35 private JLabel jLabel1;
36 private JTextField jTxtHeveaPath;
37 private JButton jBtnHeveaPath;
38 private JButton jBtnOK;
39
40
41
42
43 public static void main(String[] args) {
44 SwingUtilities.invokeLater(new Runnable() {
45 public void run() {
46 JFrame frame = new JFrame();
47 PropertiesDialog inst = new PropertiesDialog(frame);
48 inst.setVisible(true);
49 }
50 });
51 }
52
53 public PropertiesDialog(JFrame frame) {
54 super(frame);
55 initGUI();
56 }
57
58 private void initGUI() {
59
60 try {
61 {
62 String hevea_path = SettingsHelper.getSetting("hevea_path");
63
64 this.setTitle("Nastavenia");
65 getContentPane().setLayout(null);
66 this.setResizable(false);
67 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
68 this.setModalityType(ModalityType.DOCUMENT_MODAL);
69 this.setLocationByPlatform(true);
70 {
71 jLabel1 = new JLabel();
72 getContentPane().add(jLabel1);
73 jLabel1.setText("Cesta k programu Hevea");
74 jLabel1.setBounds(12, 12, 260, 14);
75 jLabel1.setForeground(new java.awt.Color(100, 0, 0));
76 }
77 {
78 jTxtHeveaPath = new JTextField();
79 getContentPane().add(jTxtHeveaPath);
80 jTxtHeveaPath.setBounds(12, 32, 477, 21);
81 jTxtHeveaPath.setBackground(new java.awt.Color(255, 255,
82 240));
83 jTxtHeveaPath.setForeground(new java.awt.Color(0, 0, 255));
84 if (hevea_path != null)
85 jTxtHeveaPath.setText(hevea_path);
86
87 }
88 {
89 jBtnHeveaPath = new JButton();
90 getContentPane().add(jBtnHeveaPath);
91 jBtnHeveaPath.setText("...");
92 jBtnHeveaPath.setBounds(495, 32, 34, 21);
93 jBtnHeveaPath.addActionListener(new ActionListener() {
94 public void actionPerformed(ActionEvent evt) {
95 jBtnHeveaPathActionPerformed(evt);
96 }
97 });
98 }
99 {
100 jBtnOK = new JButton();
101 getContentPane().add(jBtnOK);
102 jBtnOK.setText("OK");
103 jBtnOK.setBounds(433, 304, 96, 21);
104 jBtnOK.setMnemonic(java.awt.event.KeyEvent.VK_O);
105 jBtnOK.addActionListener(new ActionListener() {
106 public void actionPerformed(ActionEvent evt) {
107 jBtnOKActionPerformed(evt);
108 }
109 });
110 }
111 }
112 this.setSize(551, 372);
113 } catch (Exception e) {
114 e.printStackTrace();
115 }
116 }
117
118 private void jBtnHeveaPathActionPerformed(ActionEvent evt) {
119 JFileChooser jfc = new JFileChooser(".");
120 jfc.setFileFilter(new FileNameExtensionFilter("Spustiteľné súbory",
121 "exe"));
122 int state = jfc.showOpenDialog(this);
123 if (state == JFileChooser.CANCEL_OPTION)
124 return;
125
126 File f = jfc.getSelectedFile();
127 if (f == null)
128 return;
129 jTxtHeveaPath.setText(f.getAbsolutePath());
130 }
131
132 private void jBtnOKActionPerformed(ActionEvent evt) {
133 setVisible(false);
134 try {
135 SettingsHelper.setSetting("hevea_path", jTxtHeveaPath.getText());
136 } catch (IOException e) {
137 e.printStackTrace();
138 System.err.println("Error: " + e.getLocalizedMessage());
139 }
140 }
141
142 }