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.getColumnModel().getColumn(0).setCellEditor(new EditorNázvůAtributů());
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 Model getModel() {
73 private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
74 JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
75 log.log(Level.WARNING, hláška, chyba);
78 @SuppressWarnings("unchecked")
79 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
80 private void initComponents() {
82 posuvnýPanel = new javax.swing.JScrollPane();
83 tlačítkoPřidat = new javax.swing.JButton();
84 tlačítkoSmazat = new javax.swing.JButton();
85 tlačítkoZnovuNačíst = new javax.swing.JButton();
87 tlačítkoPřidat.setMnemonic('p');
88 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneAtributy/Překlady"); // NOI18N
89 tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
90 tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
91 public void actionPerformed(java.awt.event.ActionEvent evt) {
92 tlačítkoPřidatActionPerformed(evt);
96 tlačítkoSmazat.setMnemonic('s');
97 tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
98 tlačítkoSmazat.setEnabled(false);
99 tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
100 public void actionPerformed(java.awt.event.ActionEvent evt) {
101 tlačítkoSmazatActionPerformed(evt);
105 tlačítkoZnovuNačíst.setMnemonic('z');
106 tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
107 tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
108 public void actionPerformed(java.awt.event.ActionEvent evt) {
109 tlačítkoZnovuNačístActionPerformed(evt);
113 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
114 this.setLayout(layout);
115 layout.setHorizontalGroup(
116 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117 .addGroup(layout.createSequentialGroup()
119 .addComponent(tlačítkoPřidat)
120 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
121 .addComponent(tlačítkoSmazat)
122 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
123 .addComponent(tlačítkoZnovuNačíst)
124 .addContainerGap(186, Short.MAX_VALUE))
125 .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
127 layout.setVerticalGroup(
128 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
130 .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
131 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
132 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
133 .addComponent(tlačítkoPřidat)
134 .addComponent(tlačítkoSmazat)
135 .addComponent(tlačítkoZnovuNačíst))
138 }// </editor-fold>//GEN-END:initComponents
140 private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
141 model.přidejAtribut(new Atribut());
142 }//GEN-LAST:event_tlačítkoPřidatActionPerformed
144 private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
146 model.odeberAtribut(vybranýAtribut);
147 } catch (IOException e) {
148 zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
150 }//GEN-LAST:event_tlačítkoSmazatActionPerformed
152 private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
154 model.načtiAtributy();
155 } catch (IOException e) {
156 zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
158 }//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
159 // Variables declaration - do not modify//GEN-BEGIN:variables
160 private javax.swing.JScrollPane posuvnýPanel;
161 private javax.swing.JButton tlačítkoPřidat;
162 private javax.swing.JButton tlačítkoSmazat;
163 private javax.swing.JButton tlačítkoZnovuNačíst;
164 // End of variables declaration//GEN-END:variables