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