franta-hg@6
|
1 |
package cz.frantovo.rozsireneAtributy.gui;
|
franta-hg@6
|
2 |
|
franta-hg@10
|
3 |
import cz.frantovo.rozsireneAtributy.Atribut;
|
franta-hg@10
|
4 |
import java.io.IOException;
|
franta-hg@15
|
5 |
import java.util.ResourceBundle;
|
franta-hg@10
|
6 |
import java.util.logging.Level;
|
franta-hg@10
|
7 |
import java.util.logging.Logger;
|
franta-hg@10
|
8 |
import javax.swing.JOptionPane;
|
franta-hg@10
|
9 |
import javax.swing.event.ListSelectionEvent;
|
franta-hg@10
|
10 |
import javax.swing.event.ListSelectionListener;
|
franta-hg@6
|
11 |
|
franta-hg@6
|
12 |
/**
|
franta-hg@6
|
13 |
*
|
franta-hg@6
|
14 |
* @author fiki
|
franta-hg@6
|
15 |
*/
|
franta-hg@6
|
16 |
public class Panel extends javax.swing.JPanel {
|
franta-hg@6
|
17 |
|
franta-hg@10
|
18 |
private static final Logger log = Logger.getLogger(Panel.class.getSimpleName());
|
franta-hg@15
|
19 |
private static final ResourceBundle překlady = ResourceBundle.getBundle("cz.frantovo.rozsireneAtributy.Překlady");
|
franta-hg@10
|
20 |
private Model model;
|
franta-hg@10
|
21 |
private Atribut vybranýAtribut;
|
franta-hg@6
|
22 |
|
franta-hg@10
|
23 |
public Panel(Model model) {
|
franta-hg@6
|
24 |
this.model = model;
|
franta-hg@10
|
25 |
initComponents();
|
franta-hg@6
|
26 |
tabulka.setModel(model);
|
franta-hg@11
|
27 |
|
franta-hg@11
|
28 |
/** Výběr aktuálního atributu v tabulce */
|
franta-hg@10
|
29 |
tabulka.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
franta-hg@6
|
30 |
|
franta-hg@10
|
31 |
public void valueChanged(ListSelectionEvent e) {
|
franta-hg@10
|
32 |
int řádek = tabulka.getSelectedRow();
|
franta-hg@10
|
33 |
if (řádek < 0) {
|
franta-hg@10
|
34 |
vybranýAtribut = null;
|
franta-hg@10
|
35 |
tlačítkoSmazat.setEnabled(false);
|
franta-hg@10
|
36 |
} else {
|
franta-hg@10
|
37 |
vybranýAtribut = getModel().getAtribut(řádek);
|
franta-hg@10
|
38 |
tlačítkoSmazat.setEnabled(true);
|
franta-hg@10
|
39 |
}
|
franta-hg@10
|
40 |
}
|
franta-hg@10
|
41 |
});
|
franta-hg@10
|
42 |
}
|
franta-hg@10
|
43 |
|
franta-hg@10
|
44 |
private Model getModel() {
|
franta-hg@10
|
45 |
return model;
|
franta-hg@10
|
46 |
}
|
franta-hg@10
|
47 |
|
franta-hg@10
|
48 |
private void zobrazChybovouHlášku(String hláška, Throwable chyba) {
|
franta-hg@15
|
49 |
JOptionPane.showMessageDialog(this, hláška, překlady.getString("chyba"), JOptionPane.ERROR_MESSAGE);
|
franta-hg@10
|
50 |
log.log(Level.WARNING, hláška, chyba);
|
franta-hg@10
|
51 |
}
|
franta-hg@10
|
52 |
|
franta-hg@10
|
53 |
@SuppressWarnings("unchecked")
|
franta-hg@6
|
54 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
franta-hg@6
|
55 |
private void initComponents() {
|
franta-hg@6
|
56 |
|
franta-hg@10
|
57 |
posuvnýPanel = new javax.swing.JScrollPane();
|
franta-hg@6
|
58 |
tabulka = new javax.swing.JTable();
|
franta-hg@10
|
59 |
tlačítkoPřidat = new javax.swing.JButton();
|
franta-hg@10
|
60 |
tlačítkoSmazat = new javax.swing.JButton();
|
franta-hg@10
|
61 |
tlačítkoZnovuNačíst = new javax.swing.JButton();
|
franta-hg@6
|
62 |
|
franta-hg@6
|
63 |
tabulka.setModel(new javax.swing.table.DefaultTableModel(
|
franta-hg@6
|
64 |
new Object [][] {
|
franta-hg@6
|
65 |
{null, null, null, null},
|
franta-hg@6
|
66 |
{null, null, null, null},
|
franta-hg@6
|
67 |
{null, null, null, null},
|
franta-hg@6
|
68 |
{null, null, null, null}
|
franta-hg@6
|
69 |
},
|
franta-hg@6
|
70 |
new String [] {
|
franta-hg@6
|
71 |
"Title 1", "Title 2", "Title 3", "Title 4"
|
franta-hg@6
|
72 |
}
|
franta-hg@6
|
73 |
));
|
franta-hg@10
|
74 |
tabulka.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
franta-hg@10
|
75 |
posuvnýPanel.setViewportView(tabulka);
|
franta-hg@10
|
76 |
|
franta-hg@11
|
77 |
tlačítkoPřidat.setMnemonic('p');
|
franta-hg@15
|
78 |
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/frantovo/rozsireneAtributy/Překlady"); // NOI18N
|
franta-hg@15
|
79 |
tlačítkoPřidat.setText(bundle.getString("přidatAtribut")); // NOI18N
|
franta-hg@10
|
80 |
tlačítkoPřidat.addActionListener(new java.awt.event.ActionListener() {
|
franta-hg@10
|
81 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
franta-hg@10
|
82 |
tlačítkoPřidatActionPerformed(evt);
|
franta-hg@10
|
83 |
}
|
franta-hg@10
|
84 |
});
|
franta-hg@10
|
85 |
|
franta-hg@11
|
86 |
tlačítkoSmazat.setMnemonic('s');
|
franta-hg@15
|
87 |
tlačítkoSmazat.setText(bundle.getString("smazatAtribut")); // NOI18N
|
franta-hg@10
|
88 |
tlačítkoSmazat.setEnabled(false);
|
franta-hg@10
|
89 |
tlačítkoSmazat.addActionListener(new java.awt.event.ActionListener() {
|
franta-hg@10
|
90 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
franta-hg@10
|
91 |
tlačítkoSmazatActionPerformed(evt);
|
franta-hg@10
|
92 |
}
|
franta-hg@10
|
93 |
});
|
franta-hg@10
|
94 |
|
franta-hg@11
|
95 |
tlačítkoZnovuNačíst.setMnemonic('z');
|
franta-hg@15
|
96 |
tlačítkoZnovuNačíst.setText(bundle.getString("znovuNačíst")); // NOI18N
|
franta-hg@10
|
97 |
tlačítkoZnovuNačíst.addActionListener(new java.awt.event.ActionListener() {
|
franta-hg@10
|
98 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
franta-hg@10
|
99 |
tlačítkoZnovuNačístActionPerformed(evt);
|
franta-hg@10
|
100 |
}
|
franta-hg@10
|
101 |
});
|
franta-hg@6
|
102 |
|
franta-hg@6
|
103 |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
franta-hg@6
|
104 |
this.setLayout(layout);
|
franta-hg@6
|
105 |
layout.setHorizontalGroup(
|
franta-hg@6
|
106 |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
franta-hg@10
|
107 |
.addGroup(layout.createSequentialGroup()
|
franta-hg@10
|
108 |
.addContainerGap()
|
franta-hg@10
|
109 |
.addComponent(tlačítkoPřidat)
|
franta-hg@10
|
110 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
franta-hg@10
|
111 |
.addComponent(tlačítkoSmazat)
|
franta-hg@10
|
112 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
franta-hg@10
|
113 |
.addComponent(tlačítkoZnovuNačíst)
|
franta-hg@11
|
114 |
.addContainerGap(186, Short.MAX_VALUE))
|
franta-hg@11
|
115 |
.addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
|
franta-hg@6
|
116 |
);
|
franta-hg@6
|
117 |
layout.setVerticalGroup(
|
franta-hg@6
|
118 |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
franta-hg@10
|
119 |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
franta-hg@10
|
120 |
.addComponent(posuvnýPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
|
franta-hg@10
|
121 |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
franta-hg@10
|
122 |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
franta-hg@10
|
123 |
.addComponent(tlačítkoPřidat)
|
franta-hg@10
|
124 |
.addComponent(tlačítkoSmazat)
|
franta-hg@10
|
125 |
.addComponent(tlačítkoZnovuNačíst))
|
franta-hg@10
|
126 |
.addContainerGap())
|
franta-hg@6
|
127 |
);
|
franta-hg@6
|
128 |
}// </editor-fold>//GEN-END:initComponents
|
franta-hg@6
|
129 |
|
franta-hg@10
|
130 |
private void tlačítkoPřidatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoPřidatActionPerformed
|
franta-hg@10
|
131 |
model.přidejAtribut(new Atribut());
|
franta-hg@10
|
132 |
}//GEN-LAST:event_tlačítkoPřidatActionPerformed
|
franta-hg@6
|
133 |
|
franta-hg@10
|
134 |
private void tlačítkoSmazatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoSmazatActionPerformed
|
franta-hg@10
|
135 |
try {
|
franta-hg@10
|
136 |
model.odeberAtribut(vybranýAtribut);
|
franta-hg@10
|
137 |
} catch (IOException e) {
|
franta-hg@15
|
138 |
zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeSmazat"), e);
|
franta-hg@10
|
139 |
}
|
franta-hg@10
|
140 |
}//GEN-LAST:event_tlačítkoSmazatActionPerformed
|
franta-hg@10
|
141 |
|
franta-hg@10
|
142 |
private void tlačítkoZnovuNačístActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tlačítkoZnovuNačístActionPerformed
|
franta-hg@10
|
143 |
try {
|
franta-hg@10
|
144 |
model.načtiAtributy();
|
franta-hg@10
|
145 |
} catch (IOException e) {
|
franta-hg@15
|
146 |
zobrazChybovouHlášku(překlady.getString("chyba.nepodařiloSeNačíst"), e);
|
franta-hg@10
|
147 |
}
|
franta-hg@10
|
148 |
}//GEN-LAST:event_tlačítkoZnovuNačístActionPerformed
|
franta-hg@6
|
149 |
// Variables declaration - do not modify//GEN-BEGIN:variables
|
franta-hg@10
|
150 |
private javax.swing.JScrollPane posuvnýPanel;
|
franta-hg@6
|
151 |
private javax.swing.JTable tabulka;
|
franta-hg@10
|
152 |
private javax.swing.JButton tlačítkoPřidat;
|
franta-hg@10
|
153 |
private javax.swing.JButton tlačítkoSmazat;
|
franta-hg@10
|
154 |
private javax.swing.JButton tlačítkoZnovuNačíst;
|
franta-hg@6
|
155 |
// End of variables declaration//GEN-END:variables
|
franta-hg@6
|
156 |
}
|