franta-hg@19: /**
franta-hg@19: * Rozšířené atributy – program na správu rozšířených atributů souborů
franta-hg@19: * Copyright © 2012 František Kučera (frantovo.cz)
franta-hg@22: *
franta-hg@19: * This program is free software: you can redistribute it and/or modify
franta-hg@19: * it under the terms of the GNU General Public License as published by
franta-hg@19: * the Free Software Foundation, either version 3 of the License, or
franta-hg@19: * (at your option) any later version.
franta-hg@22: *
franta-hg@19: * This program is distributed in the hope that it will be useful,
franta-hg@19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@22: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@19: * GNU General Public License for more details.
franta-hg@22: *
franta-hg@19: * You should have received a copy of the GNU General Public License
franta-hg@22: * along with this program. If not, see .
franta-hg@19: */
franta-hg@6: package cz.frantovo.rozsireneAtributy.gui;
franta-hg@6:
franta-hg@10: import cz.frantovo.rozsireneAtributy.Atribut;
franta-hg@10: import java.io.IOException;
franta-hg@15: import java.util.ResourceBundle;
franta-hg@10: import java.util.logging.Level;
franta-hg@10: import java.util.logging.Logger;
franta-hg@10: import javax.swing.JOptionPane;
franta-hg@16: import javax.swing.JTable;
franta-hg@16: import javax.swing.ListSelectionModel;
franta-hg@10: import javax.swing.event.ListSelectionEvent;
franta-hg@10: import javax.swing.event.ListSelectionListener;
franta-hg@6:
franta-hg@6: /**
franta-hg@6: *
franta-hg@6: * @author fiki
franta-hg@6: */
franta-hg@6: public class Panel extends javax.swing.JPanel {
franta-hg@6:
franta-hg@10: private static final Logger log = Logger.getLogger(Panel.class.getSimpleName());
franta-hg@15: private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
franta-hg@10: private Model model;
franta-hg@10: private Atribut vybranýAtribut;
franta-hg@16: private JTable tabulka;
franta-hg@6:
franta-hg@10: public Panel(Model model) {
franta-hg@6: this.model = model;
franta-hg@10: initComponents();
franta-hg@16:
franta-hg@16: tabulka = new JTable(model);
franta-hg@22: tabulka.getColumnModel().getColumn(0).setCellEditor(new EditorNázvůAtributů());
franta-hg@16: tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
franta-hg@16: posuvnýPanel.setViewportView(tabulka);
franta-hg@16:
franta-hg@11: /** Výběr aktuálního atributu v tabulce */
franta-hg@10: tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
franta-hg@6:
franta-hg@22: @Override
franta-hg@10: public void valueChanged(ListSelectionEvent e) {
franta-hg@10: int řádek = tabulka.getSelectedRow();
franta-hg@10: if (řádek < 0) {
franta-hg@10: vybranýAtribut = null;
franta-hg@10: tlačítkoSmazat.setEnabled(false);
franta-hg@10: } else {
franta-hg@10: vybranýAtribut = getModel().getAtribut(řádek);
franta-hg@10: tlačítkoSmazat.setEnabled(true);
franta-hg@10: }
franta-hg@10: }
franta-hg@10: });
franta-hg@10: }
franta-hg@10:
franta-hg@10: private Model getModel() {
franta-hg@10: return model;
franta-hg@10: }
franta-hg@10:
franta-hg@10: private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
franta-hg@15: JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
franta-hg@10: log.log(Level.WARNING, hláška, chyba);
franta-hg@10: }
franta-hg@10:
franta-hg@10: @SuppressWarnings("unchecked")
franta-hg@6: // //GEN-BEGIN:initComponents
franta-hg@6: private void initComponents() {
franta-hg@6:
franta-hg@10: posuvnýPanel = new javax.swing.JScrollPane();
franta-hg@10: tlačítkoPřidat = new javax.swing.JButton();
franta-hg@10: tlačítkoSmazat = new javax.swing.JButton();
franta-hg@10: tlačítkoZnovuNačíst = new javax.swing.JButton();
franta-hg@6:
franta-hg@11: tlačítkoPřidat.setMnemonic('p');
franta-hg@15: java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneAtributy/Překlady"); // NOI18N
franta-hg@15: tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
franta-hg@10: tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
franta-hg@10: public void actionPerformed(java.awt.event.ActionEvent evt) {
franta-hg@10: tlačítkoPřidatActionPerformed(evt);
franta-hg@10: }
franta-hg@10: });
franta-hg@10:
franta-hg@11: tlačítkoSmazat.setMnemonic('s');
franta-hg@15: tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
franta-hg@10: tlačítkoSmazat.setEnabled(false);
franta-hg@10: tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
franta-hg@10: public void actionPerformed(java.awt.event.ActionEvent evt) {
franta-hg@10: tlačítkoSmazatActionPerformed(evt);
franta-hg@10: }
franta-hg@10: });
franta-hg@10:
franta-hg@11: tlačítkoZnovuNačíst.setMnemonic('z');
franta-hg@15: tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
franta-hg@10: tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
franta-hg@10: public void actionPerformed(java.awt.event.ActionEvent evt) {
franta-hg@10: tlačítkoZnovuNačístActionPerformed(evt);
franta-hg@10: }
franta-hg@10: });
franta-hg@6:
franta-hg@6: javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
franta-hg@6: this.setLayout(layout);
franta-hg@6: layout.setHorizontalGroup(
franta-hg@6: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
franta-hg@10: .addGroup(layout.createSequentialGroup()
franta-hg@10: .addContainerGap()
franta-hg@10: .addComponent(tlačítkoPřidat)
franta-hg@10: .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
franta-hg@10: .addComponent(tlačítkoSmazat)
franta-hg@10: .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
franta-hg@10: .addComponent(tlačítkoZnovuNačíst)
franta-hg@11: .addContainerGap(186, Short.MAX_VALUE))
franta-hg@11: .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
franta-hg@6: );
franta-hg@6: layout.setVerticalGroup(
franta-hg@6: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
franta-hg@10: .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
franta-hg@10: .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
franta-hg@10: .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
franta-hg@10: .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
franta-hg@10: .addComponent(tlačítkoPřidat)
franta-hg@10: .addComponent(tlačítkoSmazat)
franta-hg@10: .addComponent(tlačítkoZnovuNačíst))
franta-hg@10: .addContainerGap())
franta-hg@6: );
franta-hg@6: }// //GEN-END:initComponents
franta-hg@6:
franta-hg@10: private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
franta-hg@10: model.přidejAtribut(new Atribut());
franta-hg@10: }//GEN-LAST:event_tlačítkoPřidatActionPerformed
franta-hg@6:
franta-hg@10: private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
franta-hg@10: try {
franta-hg@10: model.odeberAtribut(vybranýAtribut);
franta-hg@10: } catch (IOException e) {
franta-hg@15: zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
franta-hg@10: }
franta-hg@10: }//GEN-LAST:event_tlačítkoSmazatActionPerformed
franta-hg@10:
franta-hg@10: private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
franta-hg@10: try {
franta-hg@10: model.načtiAtributy();
franta-hg@10: } catch (IOException e) {
franta-hg@15: zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
franta-hg@10: }
franta-hg@10: }//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
franta-hg@6: // Variables declaration - do not modify//GEN-BEGIN:variables
franta-hg@10: private javax.swing.JScrollPane posuvnýPanel;
franta-hg@10: private javax.swing.JButton tlačítkoPřidat;
franta-hg@10: private javax.swing.JButton tlačítkoSmazat;
franta-hg@10: private javax.swing.JButton tlačítkoZnovuNačíst;
franta-hg@6: // End of variables declaration//GEN-END:variables
franta-hg@6: }