2 * Rozšířené atributy – program na správu rozšířených atributů souborů
3 * Copyright © 2012 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package cz.frantovo.rozsireneatributy.gui;
19 import cz.frantovo.rozsireneatributy.Atribut;
20 import java.io.IOException;
21 import java.util.ResourceBundle;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import javax.swing.JOptionPane;
25 import javax.swing.JTable;
26 import javax.swing.ListSelectionModel;
27 import javax.swing.event.ListSelectionEvent;
28 import javax.swing.event.ListSelectionListener;
34 public class Panel extends javax.swing.JPanel {
36 private static final int SLOUPEC_NÁZVU = 0;
37 private static final Logger log = Logger.getLogger(Panel.class.getSimpleName());
38 private static final ResourceBundle překlady = ResourceBundle.getBundle(Atribut.class.getPackageName() + ".Překlady");
40 private Atribut vybranýAtribut;
41 private JTable tabulka;
43 public Panel(Model model) {
47 tabulka = new JTable(model);
49 tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
50 posuvnýPanel.setViewportView(tabulka);
52 /** Výběr aktuálního atributu v tabulce */
53 tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
56 public void valueChanged(ListSelectionEvent e) {
57 int řádek = tabulka.getSelectedRow();
59 vybranýAtribut = null;
60 tlačítkoSmazat.setEnabled(false);
62 vybranýAtribut = getModel().getAtribut(řádek);
63 tlačítkoSmazat.setEnabled(true);
69 private void nastavEditor() {
70 tabulka.getColumnModel().getColumn(SLOUPEC_NÁZVU).setCellEditor(new EditorNázvůAtributů());
73 private Model getModel() {
77 public void setModel(Model model) {
79 tabulka.setModel(model);
83 private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
84 JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
85 log.log(Level.WARNING, hláška, chyba);
88 @SuppressWarnings("unchecked")
89 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
90 private void initComponents() {
92 posuvnýPanel = new javax.swing.JScrollPane();
93 tlačítkoPřidat = new javax.swing.JButton();
94 tlačítkoSmazat = new javax.swing.JButton();
95 tlačítkoZnovuNačíst = new javax.swing.JButton();
97 tlačítkoPřidat.setMnemonic('p');
98 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneatributy/Překlady"); // NOI18N
99 tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
100 tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
101 public void actionPerformed(java.awt.event.ActionEvent evt) {
102 tlačítkoPřidatActionPerformed(evt);
106 tlačítkoSmazat.setMnemonic('s');
107 tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
108 tlačítkoSmazat.setEnabled(false);
109 tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
110 public void actionPerformed(java.awt.event.ActionEvent evt) {
111 tlačítkoSmazatActionPerformed(evt);
115 tlačítkoZnovuNačíst.setMnemonic('z');
116 tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
117 tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
118 public void actionPerformed(java.awt.event.ActionEvent evt) {
119 tlačítkoZnovuNačístActionPerformed(evt);
123 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
124 this.setLayout(layout);
125 layout.setHorizontalGroup(
126 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127 .addGroup(layout.createSequentialGroup()
129 .addComponent(tlačítkoPřidat)
130 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
131 .addComponent(tlačítkoSmazat)
132 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
133 .addComponent(tlačítkoZnovuNačíst)
134 .addContainerGap(222, Short.MAX_VALUE))
135 .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
137 layout.setVerticalGroup(
138 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
139 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
140 .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
141 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
142 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
143 .addComponent(tlačítkoPřidat)
144 .addComponent(tlačítkoSmazat)
145 .addComponent(tlačítkoZnovuNačíst))
148 }// </editor-fold>//GEN-END:initComponents
150 private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
151 model.přidejAtribut(new Atribut());
152 }//GEN-LAST:event_tlačítkoPřidatActionPerformed
154 private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
156 model.odeberAtribut(vybranýAtribut);
157 } catch (IOException e) {
158 zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
160 }//GEN-LAST:event_tlačítkoSmazatActionPerformed
162 private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
164 model.načtiAtributy();
165 } catch (IOException e) {
166 zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
168 }//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
169 // Variables declaration - do not modify//GEN-BEGIN:variables
170 private javax.swing.JScrollPane posuvnýPanel;
171 private javax.swing.JButton tlačítkoPřidat;
172 private javax.swing.JButton tlačítkoSmazat;
173 private javax.swing.JButton tlačítkoZnovuNačíst;
174 // End of variables declaration//GEN-END:variables