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, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package cz.frantovo.rozsireneAtributy.gui;
20 import cz.frantovo.rozsireneAtributy.Atribut;
21 import java.io.IOException;
22 import java.util.ResourceBundle;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.swing.JOptionPane;
26 import javax.swing.JTable;
27 import javax.swing.ListSelectionModel;
28 import javax.swing.event.ListSelectionEvent;
29 import javax.swing.event.ListSelectionListener;
35 public class Panel extends javax.swing.JPanel {
37 private static final Logger log = Logger.getLogger(Panel.class.getSimpleName());
38 private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
40 private Atribut vybranýAtribut;
41 private JTable tabulka;
43 public Panel(Model model) {
47 tabulka = new JTable(model);
48 tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
49 posuvnýPanel.setViewportView(tabulka);
51 /** Výběr aktuálního atributu v tabulce */
52 tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
54 public void valueChanged(ListSelectionEvent e) {
55 int řádek = tabulka.getSelectedRow();
57 vybranýAtribut = null;
58 tlačítkoSmazat.setEnabled(false);
60 vybranýAtribut = getModel().getAtribut(řádek);
61 tlačítkoSmazat.setEnabled(true);
67 private Model getModel() {
71 private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
72 JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
73 log.log(Level.WARNING, hláška, chyba);
76 @SuppressWarnings("unchecked")
77 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
78 private void initComponents() {
80 posuvnýPanel = new javax.swing.JScrollPane();
81 tlačítkoPřidat = new javax.swing.JButton();
82 tlačítkoSmazat = new javax.swing.JButton();
83 tlačítkoZnovuNačíst = new javax.swing.JButton();
85 tlačítkoPřidat.setMnemonic('p');
86 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneAtributy/Překlady"); // NOI18N
87 tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
88 tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
89 public void actionPerformed(java.awt.event.ActionEvent evt) {
90 tlačítkoPřidatActionPerformed(evt);
94 tlačítkoSmazat.setMnemonic('s');
95 tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
96 tlačítkoSmazat.setEnabled(false);
97 tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
98 public void actionPerformed(java.awt.event.ActionEvent evt) {
99 tlačítkoSmazatActionPerformed(evt);
103 tlačítkoZnovuNačíst.setMnemonic('z');
104 tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
105 tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
106 public void actionPerformed(java.awt.event.ActionEvent evt) {
107 tlačítkoZnovuNačístActionPerformed(evt);
111 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
112 this.setLayout(layout);
113 layout.setHorizontalGroup(
114 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
115 .addGroup(layout.createSequentialGroup()
117 .addComponent(tlačítkoPřidat)
118 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
119 .addComponent(tlačítkoSmazat)
120 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
121 .addComponent(tlačítkoZnovuNačíst)
122 .addContainerGap(186, Short.MAX_VALUE))
123 .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
125 layout.setVerticalGroup(
126 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
128 .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
129 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
130 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
131 .addComponent(tlačítkoPřidat)
132 .addComponent(tlačítkoSmazat)
133 .addComponent(tlačítkoZnovuNačíst))
136 }// </editor-fold>//GEN-END:initComponents
138 private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
139 model.přidejAtribut(new Atribut());
140 }//GEN-LAST:event_tlačítkoPřidatActionPerformed
142 private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
144 model.odeberAtribut(vybranýAtribut);
145 } catch (IOException e) {
146 zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
148 }//GEN-LAST:event_tlačítkoSmazatActionPerformed
150 private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
152 model.načtiAtributy();
153 } catch (IOException e) {
154 zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
156 }//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
157 // Variables declaration - do not modify//GEN-BEGIN:variables
158 private javax.swing.JScrollPane posuvnýPanel;
159 private javax.swing.JButton tlačítkoPřidat;
160 private javax.swing.JButton tlačítkoSmazat;
161 private javax.swing.JButton tlačítkoZnovuNačíst;
162 // End of variables declaration//GEN-END:variables