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