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@22
|
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@22
|
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@22
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
franta-hg@19
|
12 |
* GNU General Public License for more details.
|
franta-hg@22
|
13 |
*
|
franta-hg@19
|
14 |
* You should have received a copy of the GNU General Public License
|
franta-hg@22
|
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.gui;
|
franta-hg@6
|
18 |
|
franta-hg@28
|
19 |
import cz.frantovo.rozsireneatributy.Atribut;
|
franta-hg@10
|
20 |
import java.io.IOException;
|
franta-hg@15
|
21 |
import java.util.ResourceBundle;
|
franta-hg@10
|
22 |
import java.util.logging.Level;
|
franta-hg@10
|
23 |
import java.util.logging.Logger;
|
franta-hg@10
|
24 |
import javax.swing.JOptionPane;
|
franta-hg@16
|
25 |
import javax.swing.JTable;
|
franta-hg@16
|
26 |
import javax.swing.ListSelectionModel;
|
franta-hg@10
|
27 |
import javax.swing.event.ListSelectionEvent;
|
franta-hg@10
|
28 |
import javax.swing.event.ListSelectionListener;
|
franta-hg@6
|
29 |
|
franta-hg@6
|
30 |
/**
|
franta-hg@30
|
31 |
* @author Ing. František Kučera (frantovo.cz)
|
franta-hg@6
|
32 |
*/
|
franta-hg@6
|
33 |
public class Panel extends javax.swing.JPanel {
|
franta-hg@6
|
34 |
|
franta-hg@32
|
35 |
public static final int SLOUPEC_NÁZVU = 0;
|
franta-hg@32
|
36 |
public static final int SLOUPEC_HODNOTY = 1;
|
franta-hg@29
|
37 |
private static final Logger log = Logger
|
franta-hg@29
|
38 |
.getLogger(Panel.class.getSimpleName());
|
franta-hg@29
|
39 |
private static final ResourceBundle překlady = ResourceBundle
|
franta-hg@29
|
40 |
.getBundle(Atribut.class.getPackageName() + ".Překlady");
|
franta-hg@10
|
41 |
private Model model;
|
franta-hg@10
|
42 |
private Atribut vybranýAtribut;
|
franta-hg@16
|
43 |
private JTable tabulka;
|
franta-hg@6
|
44 |
|
franta-hg@10
|
45 |
public Panel(Model model) {
|
franta-hg@6
|
46 |
this.model = model;
|
franta-hg@10
|
47 |
initComponents();
|
franta-hg@16
|
48 |
|
franta-hg@30
|
49 |
tlačítkoZamknout.setEnabled(model.isZámekPodporovaný());
|
franta-hg@30
|
50 |
tlačítkoZamknout.setToolTipText(model.isZámekPodporovaný()
|
franta-hg@30
|
51 |
? překlady.getString("zamknout.popis")
|
franta-hg@30
|
52 |
: překlady.getString("chyba.lzeZamknoutJenSoubor"));
|
franta-hg@30
|
53 |
|
franta-hg@16
|
54 |
tabulka = new JTable(model);
|
franta-hg@23
|
55 |
nastavEditor();
|
franta-hg@16
|
56 |
tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
franta-hg@16
|
57 |
posuvnýPanel.setViewportView(tabulka);
|
franta-hg@32
|
58 |
|
franta-hg@11
|
59 |
/** Výběr aktuálního atributu v tabulce */
|
franta-hg@29
|
60 |
tabulka.getSelectionModel().addListSelectionListener(
|
franta-hg@29
|
61 |
new ListSelectionListener() {
|
franta-hg@6
|
62 |
|
franta-hg@22
|
63 |
@Override
|
franta-hg@10
|
64 |
public void valueChanged(ListSelectionEvent e) {
|
franta-hg@10
|
65 |
int řádek = tabulka.getSelectedRow();
|
franta-hg@10
|
66 |
if (řádek < 0) {
|
franta-hg@10
|
67 |
vybranýAtribut = null;
|
franta-hg@10
|
68 |
tlačítkoSmazat.setEnabled(false);
|
franta-hg@10
|
69 |
} else {
|
franta-hg@10
|
70 |
vybranýAtribut = getModel().getAtribut(řádek);
|
franta-hg@10
|
71 |
tlačítkoSmazat.setEnabled(true);
|
franta-hg@10
|
72 |
}
|
franta-hg@10
|
73 |
}
|
franta-hg@10
|
74 |
});
|
franta-hg@10
|
75 |
}
|
franta-hg@10
|
76 |
|
franta-hg@23
|
77 |
private void nastavEditor() {
|
franta-hg@29
|
78 |
tabulka.getColumnModel().getColumn(SLOUPEC_NÁZVU)
|
franta-hg@31
|
79 |
.setCellEditor(new EditorNázvůAtributů(model.getKonfigurace()));
|
franta-hg@32
|
80 |
tabulka.getColumnModel().getColumn(SLOUPEC_HODNOTY)
|
franta-hg@32
|
81 |
.setCellEditor(new EditorHodnotAtributů(model.getKonfigurace()));
|
franta-hg@23
|
82 |
}
|
franta-hg@23
|
83 |
|
franta-hg@10
|
84 |
private Model getModel() {
|
franta-hg@10
|
85 |
return model;
|
franta-hg@10
|
86 |
}
|
franta-hg@10
|
87 |
|
franta-hg@23
|
88 |
public void setModel(Model model) {
|
franta-hg@23
|
89 |
this.model = model;
|
franta-hg@23
|
90 |
tabulka.setModel(model);
|
franta-hg@23
|
91 |
nastavEditor();
|
franta-hg@23
|
92 |
}
|
franta-hg@23
|
93 |
|
franta-hg@10
|
94 |
private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
|
franta-hg@30
|
95 |
JOptionPane.showMessageDialog(this, hláška + "\n"
|
franta-hg@30
|
96 |
+ chyba.getLocalizedMessage(),
|
franta-hg@30
|
97 |
překlady.getString("chyba.titulek"), JOptionPane.ERROR_MESSAGE);
|
franta-hg@10
|
98 |
log.log(Level.WARNING, hláška, chyba);
|
franta-hg@10
|
99 |
}
|
franta-hg@10
|
100 |
|
franta-hg@10
|
101 |
@SuppressWarnings("unchecked")
|
franta-hg@6
|
102 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
franta-hg@6
|
103 |
private void initComponents() {
|
franta-hg@6
|
104 |
|
franta-hg@10
|
105 |
posuvnýPanel = new javax.swing.JScrollPane();
|
franta-hg@10
|
106 |
tlačítkoPřidat = new javax.swing.JButton();
|
franta-hg@10
|
107 |
tlačítkoSmazat = new javax.swing.JButton();
|
franta-hg@10
|
108 |
tlačítkoZnovuNačíst = new javax.swing.JButton();
|
franta-hg@30
|
109 |
tlačítkoZamknout = new javax.swing.JToggleButton();
|
franta-hg@6
|
110 |
|
franta-hg@11
|
111 |
tlačítkoPřidat.setMnemonic('p');
|
franta-hg@28
|
112 |
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneatributy/Překlady"); // NOI18N
|
franta-hg@15
|
113 |
tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
|
franta-hg@10
|
114 |
tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
|
franta-hg@10
|
115 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
franta-hg@10
|
116 |
tlačítkoPřidatActionPerformed(evt);
|
franta-hg@10
|
117 |
}
|
franta-hg@10
|
118 |
});
|
franta-hg@10
|
119 |
|
franta-hg@11
|
120 |
tlačítkoSmazat.setMnemonic('s');
|
franta-hg@15
|
121 |
tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
|
franta-hg@10
|
122 |
tlačítkoSmazat.setEnabled(false);
|
franta-hg@10
|
123 |
tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
|
franta-hg@10
|
124 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
franta-hg@10
|
125 |
tlačítkoSmazatActionPerformed(evt);
|
franta-hg@10
|
126 |
}
|
franta-hg@10
|
127 |
});
|
franta-hg@10
|
128 |
|
franta-hg@11
|
129 |
tlačítkoZnovuNačíst.setMnemonic('z');
|
franta-hg@15
|
130 |
tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
|
franta-hg@10
|
131 |
tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
|
franta-hg@10
|
132 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
franta-hg@10
|
133 |
tlačítkoZnovuNačístActionPerformed(evt);
|
franta-hg@10
|
134 |
}
|
franta-hg@10
|
135 |
});
|
franta-hg@6
|
136 |
|
franta-hg@30
|
137 |
tlačítkoZamknout.setText(bundle.getString("zamknout")); // NOI18N
|
franta-hg@30
|
138 |
tlačítkoZamknout.addActionListener(new java.awt.event.ActionListener() {
|
franta-hg@30
|
139 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
franta-hg@30
|
140 |
tlačítkoZamknoutActionPerformed(evt);
|
franta-hg@30
|
141 |
}
|
franta-hg@30
|
142 |
});
|
franta-hg@30
|
143 |
|
franta-hg@6
|
144 |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
franta-hg@6
|
145 |
this.setLayout(layout);
|
franta-hg@6
|
146 |
layout.setHorizontalGroup(
|
franta-hg@6
|
147 |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
franta-hg@10
|
148 |
.addGroup(layout.createSequentialGroup()
|
franta-hg@10
|
149 |
.addContainerGap()
|
franta-hg@10
|
150 |
.addComponent(tlačítkoPřidat)
|
franta-hg@10
|
151 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
franta-hg@10
|
152 |
.addComponent(tlačítkoSmazat)
|
franta-hg@10
|
153 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
franta-hg@10
|
154 |
.addComponent(tlačítkoZnovuNačíst)
|
franta-hg@30
|
155 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
franta-hg@30
|
156 |
.addComponent(tlačítkoZamknout)
|
franta-hg@30
|
157 |
.addContainerGap(122, Short.MAX_VALUE))
|
franta-hg@11
|
158 |
.addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
|
franta-hg@6
|
159 |
);
|
franta-hg@6
|
160 |
layout.setVerticalGroup(
|
franta-hg@6
|
161 |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
franta-hg@10
|
162 |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
franta-hg@10
|
163 |
.addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
|
franta-hg@10
|
164 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
franta-hg@10
|
165 |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
franta-hg@10
|
166 |
.addComponent(tlačítkoPřidat)
|
franta-hg@10
|
167 |
.addComponent(tlačítkoSmazat)
|
franta-hg@30
|
168 |
.addComponent(tlačítkoZnovuNačíst)
|
franta-hg@30
|
169 |
.addComponent(tlačítkoZamknout))
|
franta-hg@10
|
170 |
.addContainerGap())
|
franta-hg@6
|
171 |
);
|
franta-hg@6
|
172 |
}// </editor-fold>//GEN-END:initComponents
|
franta-hg@6
|
173 |
|
franta-hg@10
|
174 |
private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
|
franta-hg@10
|
175 |
model.přidejAtribut(new Atribut());
|
franta-hg@10
|
176 |
}//GEN-LAST:event_tlačítkoPřidatActionPerformed
|
franta-hg@6
|
177 |
|
franta-hg@10
|
178 |
private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
|
franta-hg@10
|
179 |
try {
|
franta-hg@10
|
180 |
model.odeberAtribut(vybranýAtribut);
|
franta-hg@10
|
181 |
} catch (IOException e) {
|
franta-hg@29
|
182 |
zobrazChybovouHlášku(překlady
|
franta-hg@29
|
183 |
.getString("chyba.nepodařiloSeSmazat"), e);
|
franta-hg@10
|
184 |
}
|
franta-hg@10
|
185 |
}//GEN-LAST:event_tlačítkoSmazatActionPerformed
|
franta-hg@10
|
186 |
|
franta-hg@10
|
187 |
private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
|
franta-hg@10
|
188 |
try {
|
franta-hg@10
|
189 |
model.načtiAtributy();
|
franta-hg@10
|
190 |
} catch (IOException e) {
|
franta-hg@29
|
191 |
zobrazChybovouHlášku(překlady
|
franta-hg@29
|
192 |
.getString("chyba.nepodařiloSeNačíst"), e);
|
franta-hg@10
|
193 |
}
|
franta-hg@10
|
194 |
}//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
|
franta-hg@30
|
195 |
|
franta-hg@30
|
196 |
private void tlačítkoZamknoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZamknoutActionPerformed
|
franta-hg@30
|
197 |
try {
|
franta-hg@30
|
198 |
model.nastavZámek(tlačítkoZamknout.isSelected());
|
franta-hg@30
|
199 |
} catch (Exception e) {
|
franta-hg@30
|
200 |
zobrazChybovouHlášku(překlady
|
franta-hg@30
|
201 |
.getString("chyba.nepodařiloSeNastavitZámek"), e);
|
franta-hg@30
|
202 |
}
|
franta-hg@30
|
203 |
}//GEN-LAST:event_tlačítkoZamknoutActionPerformed
|
franta-hg@30
|
204 |
|
franta-hg@6
|
205 |
// Variables declaration - do not modify//GEN-BEGIN:variables
|
franta-hg@10
|
206 |
private javax.swing.JScrollPane posuvnýPanel;
|
franta-hg@10
|
207 |
private javax.swing.JButton tlačítkoPřidat;
|
franta-hg@10
|
208 |
private javax.swing.JButton tlačítkoSmazat;
|
franta-hg@30
|
209 |
private javax.swing.JToggleButton tlačítkoZamknout;
|
franta-hg@10
|
210 |
private javax.swing.JButton tlačítkoZnovuNačíst;
|
franta-hg@6
|
211 |
// End of variables declaration//GEN-END:variables
|
franta-hg@6
|
212 |
}
|