java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java
branchv_0
changeset 28 c2ffda907125
parent 27 dc5786f3482b
child 29 8d42303538ed
     1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/gui/Panel.java	Mon Dec 11 00:10:33 2023 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,175 +0,0 @@
     1.4 -/**
     1.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
     1.6 - * Copyright © 2012 František Kučera (frantovo.cz)
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, either version 3 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.19 - */
    1.20 -package cz.frantovo.rozsireneAtributy.gui;
    1.21 -
    1.22 -import cz.frantovo.rozsireneAtributy.Atribut;
    1.23 -import java.io.IOException;
    1.24 -import java.util.ResourceBundle;
    1.25 -import java.util.logging.Level;
    1.26 -import java.util.logging.Logger;
    1.27 -import javax.swing.JOptionPane;
    1.28 -import javax.swing.JTable;
    1.29 -import javax.swing.ListSelectionModel;
    1.30 -import javax.swing.event.ListSelectionEvent;
    1.31 -import javax.swing.event.ListSelectionListener;
    1.32 -
    1.33 -/**
    1.34 - *
    1.35 - * @author fiki
    1.36 - */
    1.37 -public class Panel extends javax.swing.JPanel {
    1.38 -
    1.39 -	private static final int SLOUPEC_NÁZVU = 0;
    1.40 -	private static final Logger log = Logger.getLogger(Panel.class.getSimpleName());
    1.41 -	private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
    1.42 -	private Model model;
    1.43 -	private Atribut vybranýAtribut;
    1.44 -	private JTable tabulka;
    1.45 -
    1.46 -	public Panel(Model model) {
    1.47 -		this.model = model;
    1.48 -		initComponents();
    1.49 -
    1.50 -		tabulka = new JTable(model);
    1.51 -		nastavEditor();
    1.52 -		tabulka.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    1.53 -		posuvnýPanel.setViewportView(tabulka);
    1.54 -
    1.55 -		/** Výběr aktuálního atributu v tabulce */
    1.56 -		tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    1.57 -
    1.58 -			@Override
    1.59 -			public void valueChanged(ListSelectionEvent e) {
    1.60 -				int řádek = tabulka.getSelectedRow();
    1.61 -				if (řádek < 0) {
    1.62 -					vybranýAtribut = null;
    1.63 -					tlačítkoSmazat.setEnabled(false);
    1.64 -				} else {
    1.65 -					vybranýAtribut = getModel().getAtribut(řádek);
    1.66 -					tlačítkoSmazat.setEnabled(true);
    1.67 -				}
    1.68 -			}
    1.69 -		});
    1.70 -	}
    1.71 -
    1.72 -	private void nastavEditor() {
    1.73 -		tabulka.getColumnModel().getColumn(SLOUPEC_NÁZVU).setCellEditor(new EditorNázvůAtributů());
    1.74 -	}
    1.75 -
    1.76 -	private Model getModel() {
    1.77 -		return model;
    1.78 -	}
    1.79 -
    1.80 -	public void setModel(Model model) {
    1.81 -		this.model = model;
    1.82 -		tabulka.setModel(model);
    1.83 -		nastavEditor();
    1.84 -	}
    1.85 -
    1.86 -	private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
    1.87 -		JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
    1.88 -		log.log(Level.WARNING, hláška, chyba);
    1.89 -	}
    1.90 -
    1.91 -	@SuppressWarnings("unchecked")
    1.92 -    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    1.93 -    private void initComponents() {
    1.94 -
    1.95 -        posuvnýPanel = new javax.swing.JScrollPane();
    1.96 -        tlačítkoPřidat = new javax.swing.JButton();
    1.97 -        tlačítkoSmazat = new javax.swing.JButton();
    1.98 -        tlačítkoZnovuNačíst = new javax.swing.JButton();
    1.99 -
   1.100 -        tlačítkoPřidat.setMnemonic('p');
   1.101 -        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneAtributy/Překlady"); // NOI18N
   1.102 -        tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
   1.103 -        tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
   1.104 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
   1.105 -                tlačítkoPřidatActionPerformed(evt);
   1.106 -            }
   1.107 -        });
   1.108 -
   1.109 -        tlačítkoSmazat.setMnemonic('s');
   1.110 -        tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
   1.111 -        tlačítkoSmazat.setEnabled(false);
   1.112 -        tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
   1.113 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
   1.114 -                tlačítkoSmazatActionPerformed(evt);
   1.115 -            }
   1.116 -        });
   1.117 -
   1.118 -        tlačítkoZnovuNačíst.setMnemonic('z');
   1.119 -        tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
   1.120 -        tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
   1.121 -            public void actionPerformed(java.awt.event.ActionEvent evt) {
   1.122 -                tlačítkoZnovuNačístActionPerformed(evt);
   1.123 -            }
   1.124 -        });
   1.125 -
   1.126 -        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
   1.127 -        this.setLayout(layout);
   1.128 -        layout.setHorizontalGroup(
   1.129 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   1.130 -            .addGroup(layout.createSequentialGroup()
   1.131 -                .addContainerGap()
   1.132 -                .addComponent(tlačítkoPřidat)
   1.133 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   1.134 -                .addComponent(tlačítkoSmazat)
   1.135 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   1.136 -                .addComponent(tlačítkoZnovuNačíst)
   1.137 -                .addContainerGap(186, Short.MAX_VALUE))
   1.138 -            .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
   1.139 -        );
   1.140 -        layout.setVerticalGroup(
   1.141 -            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   1.142 -            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
   1.143 -                .addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
   1.144 -                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   1.145 -                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
   1.146 -                    .addComponent(tlačítkoPřidat)
   1.147 -                    .addComponent(tlačítkoSmazat)
   1.148 -                    .addComponent(tlačítkoZnovuNačíst))
   1.149 -                .addContainerGap())
   1.150 -        );
   1.151 -    }// </editor-fold>//GEN-END:initComponents
   1.152 -
   1.153 -	private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
   1.154 -		model.přidejAtribut(new Atribut());
   1.155 -	}//GEN-LAST:event_tlačítkoPřidatActionPerformed
   1.156 -
   1.157 -	private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
   1.158 -		try {
   1.159 -			model.odeberAtribut(vybranýAtribut);
   1.160 -		} catch (IOException e) {
   1.161 -			zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
   1.162 -		}
   1.163 -	}//GEN-LAST:event_tlačítkoSmazatActionPerformed
   1.164 -
   1.165 -	private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
   1.166 -		try {
   1.167 -			model.načtiAtributy();
   1.168 -		} catch (IOException e) {
   1.169 -			zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
   1.170 -		}
   1.171 -	}//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
   1.172 -    // Variables declaration - do not modify//GEN-BEGIN:variables
   1.173 -    private javax.swing.JScrollPane posuvnýPanel;
   1.174 -    private javax.swing.JButton tlačítkoPřidat;
   1.175 -    private javax.swing.JButton tlačítkoSmazat;
   1.176 -    private javax.swing.JButton tlačítkoZnovuNačíst;
   1.177 -    // End of variables declaration//GEN-END:variables
   1.178 -}