1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.webphotos.gui;
17
18 import java.awt.event.KeyEvent;
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.io.IOException;
22 import java.text.ParseException;
23 import java.util.logging.Level;
24 import javax.swing.*;
25 import javax.swing.event.DocumentListener;
26 import javax.swing.event.TableModelEvent;
27 import net.sf.webphotos.Album;
28 import net.sf.webphotos.BancoImagem;
29 import net.sf.webphotos.PhotoDTO;
30 import net.sf.webphotos.action.*;
31 import net.sf.webphotos.dao.jpa.CategoryDAO;
32 import net.sf.webphotos.dao.jpa.CreditsDAO;
33 import net.sf.webphotos.gui.util.TableModelAlbum;
34 import net.sf.webphotos.gui.util.TableModelFoto;
35 import net.sf.webphotos.gui.util.TableSorter;
36 import net.sf.webphotos.model.CategoryVO;
37 import net.sf.webphotos.model.CreditsVO;
38 import net.sf.webphotos.tools.Thumbnail;
39 import net.sf.webphotos.util.ApplicationContextResource;
40 import net.sf.webphotos.util.Util;
41 import net.sf.webphotos.util.legacy.CacheFTP;
42 import org.apache.log4j.Logger;
43
44
45
46
47
48
49 public class PainelWebFotos extends javax.swing.JPanel {
50
51 private static Logger log = Logger.getLogger(PainelWebFotos.class);
52 private static PainelWebFotos janela;
53
54
55
56 public static final String ACAO_NOVO = "novo";
57
58
59
60 public static final String ACAO_CANCELAR = "cancelar";
61
62
63
64 public static final String ACAO_FINALIZAR = "finalizar";
65
66
67
68 public static final String ACAO_ALTERAR = "alterar";
69
70
71
72
73
74
75 public static void montagemComboPesquisa(Boolean force) {
76 final String[] categoriasArray = Album.getAlbum().getCategoriasArray(force);
77 final DefaultComboBoxModel defaultComboBoxModel = new javax.swing.DefaultComboBoxModel(categoriasArray);
78 final DefaultComboBoxModel defaultComboBoxModelPainelPesquisa = new javax.swing.DefaultComboBoxModel(categoriasArray);
79
80 defaultComboBoxModel.insertElementAt("", 0);
81 defaultComboBoxModel.setSelectedItem(defaultComboBoxModel.getElementAt(0));
82
83 defaultComboBoxModelPainelPesquisa.insertElementAt("Todas as Categorias", 0);
84 defaultComboBoxModelPainelPesquisa.setSelectedItem(defaultComboBoxModelPainelPesquisa.getElementAt(0));
85
86 lstCategoriasAlbum.setModel(defaultComboBoxModel);
87 painelPesquisa.setCategoriasPesquisaComboBoxModel(defaultComboBoxModelPainelPesquisa);
88 }
89
90
91
92
93 private PainelWebFotos() {
94
95 TableModelAlbum.getModel().setUltimoSQL(Util.getConfig().getString("sql1"));
96
97
98 try {
99 mascaraData = new javax.swing.text.MaskFormatter("##/##/####");
100 } catch (ParseException ex) {
101 log.error("Parsing Problem", ex);
102 }
103
104 initComponents();
105 try {
106 rotinasExtras();
107 } catch (Exception ex) {
108 log.error("Unexpected", ex);
109 }
110
111 }
112
113
114
115
116
117
118
119 private void initComponents() {
120 java.awt.GridBagConstraints gridBagConstraints;
121
122 lstCreditosTabelaFotos = new javax.swing.JComboBox();
123 menuFoto = new javax.swing.JPopupMenu();
124 menuItemFotoUp = new javax.swing.JMenuItem();
125 menuItemFotoDown = new javax.swing.JMenuItem();
126 menuSeparadorFoto = new javax.swing.JSeparator();
127 menuItemFotoRedoThumbs = new javax.swing.JMenuItem();
128 menuItemFotoDelete = new javax.swing.JMenuItem();
129 menuAlbum = new javax.swing.JPopupMenu();
130 menuItemAlbumRedoXML = new javax.swing.JMenuItem();
131 menuItemAlbumRedoJS = new javax.swing.JMenuItem();
132 menuSeparadorAlbum1 = new javax.swing.JSeparator();
133 menuItemAlbumUp = new javax.swing.JMenuItem();
134 menuItemAlbumDown = new javax.swing.JMenuItem();
135 menuSeparadorAlbum2 = new javax.swing.JSeparator();
136 menuItemAlbumRedoThumbs = new javax.swing.JMenuItem();
137 menuItemAlbumDelete = new javax.swing.JMenuItem();
138 painelPesquisa = new net.sf.webphotos.gui.component.PainelPesquisa();
139 painelAlbuns = new javax.swing.JPanel();
140 scrAlbuns = new javax.swing.JScrollPane();
141 tbAlbuns = new javax.swing.JTable();
142 lblTabelaInfo = new javax.swing.JLabel();
143 painelDadosAlbum = new javax.swing.JPanel();
144 painelInfoAlbum = new javax.swing.JPanel();
145 lblAlbum = new javax.swing.JLabel();
146 txtTitulo = new javax.swing.JTextField();
147 lblCategoria = new javax.swing.JLabel();
148 lstCategoriasAlbum = new javax.swing.JComboBox();
149 buttonAddCategory = new net.sf.webphotos.gui.component.BotaoIcone();
150 lblData = new javax.swing.JLabel();
151 txtData = new javax.swing.JFormattedTextField();
152 lblDescricao = new javax.swing.JLabel();
153 scrDescricao = new javax.swing.JScrollPane();
154 txtDescricao = new javax.swing.JTextArea();
155 scrFotos = new javax.swing.JScrollPane();
156 tbFotos = new javax.swing.JTable();
157 painelFormFoto = new javax.swing.JPanel();
158 painelFoto = new net.sf.webphotos.gui.component.PainelFoto();
159 lblLegenda = new javax.swing.JLabel();
160 scrLegenda = new javax.swing.JScrollPane();
161 txtLegenda = new javax.swing.JTextArea();
162 lstCreditos = new javax.swing.JComboBox();
163 buttonAddCredits = new net.sf.webphotos.gui.component.BotaoIcone();
164 painelControle = new javax.swing.JPanel();
165 scrLog = new javax.swing.JScrollPane();
166 txtLog = new javax.swing.JTextArea();
167 painelToolBar = new javax.swing.JPanel();
168 btFTP = new net.sf.webphotos.gui.component.BotaoIcone();
169 btUpload = new net.sf.webphotos.gui.component.BotaoIcone();
170 btDownload = new net.sf.webphotos.gui.component.BotaoIcone();
171 btAdicionarFotos = new net.sf.webphotos.gui.component.BotaoIcone();
172 btAlterar = new javax.swing.JButton();
173 btNovo = new javax.swing.JButton();
174
175 lstCreditosTabelaFotos.setModel(new javax.swing.DefaultComboBoxModel(net.sf.webphotos.PhotoDTO.getCreditosArray()));
176
177 menuItemFotoUp.setText("Enviar Foto");
178 menuItemFotoUp.addActionListener(new java.awt.event.ActionListener() {
179 public void actionPerformed(java.awt.event.ActionEvent evt) {
180 menuItemFotoUpActionPerformed(evt);
181 }
182 });
183 menuFoto.add(menuItemFotoUp);
184
185 menuItemFotoDown.setText("Receber Foto");
186 menuItemFotoDown.addActionListener(new java.awt.event.ActionListener() {
187 public void actionPerformed(java.awt.event.ActionEvent evt) {
188 menuItemFotoDownActionPerformed(evt);
189 }
190 });
191 menuFoto.add(menuItemFotoDown);
192 menuFoto.add(menuSeparadorFoto);
193
194 menuItemFotoRedoThumbs.setText("Refaz Thumbs");
195 menuItemFotoRedoThumbs.addActionListener(new java.awt.event.ActionListener() {
196 public void actionPerformed(java.awt.event.ActionEvent evt) {
197 menuItemFotoRedoThumbsActionPerformed(evt);
198 }
199 });
200 menuFoto.add(menuItemFotoRedoThumbs);
201
202 menuItemFotoDelete.setText("Excluir Foto");
203 menuItemFotoDelete.addActionListener(new java.awt.event.ActionListener() {
204 public void actionPerformed(java.awt.event.ActionEvent evt) {
205 menuItemFotoDeleteActionPerformed(evt);
206 }
207 });
208 menuFoto.add(menuItemFotoDelete);
209
210 menuItemAlbumRedoXML.setText("Gerar Arquivo XML");
211 menuItemAlbumRedoXML.addActionListener(new java.awt.event.ActionListener() {
212 public void actionPerformed(java.awt.event.ActionEvent evt) {
213 menuItemAlbumRedoXMLActionPerformed(evt);
214 }
215 });
216 menuAlbum.add(menuItemAlbumRedoXML);
217
218 menuItemAlbumRedoJS.setText("Gerar Arquivo JS");
219 menuItemAlbumRedoJS.addActionListener(new java.awt.event.ActionListener() {
220 public void actionPerformed(java.awt.event.ActionEvent evt) {
221 menuItemAlbumRedoJSActionPerformed(evt);
222 }
223 });
224 menuAlbum.add(menuItemAlbumRedoJS);
225 menuAlbum.add(menuSeparadorAlbum1);
226
227 menuItemAlbumUp.setText("Enviar Album");
228 menuItemAlbumUp.addActionListener(new java.awt.event.ActionListener() {
229 public void actionPerformed(java.awt.event.ActionEvent evt) {
230 menuItemAlbumUpActionPerformed(evt);
231 }
232 });
233 menuAlbum.add(menuItemAlbumUp);
234
235 menuItemAlbumDown.setText("Receber Album");
236 menuItemAlbumDown.addActionListener(new java.awt.event.ActionListener() {
237 public void actionPerformed(java.awt.event.ActionEvent evt) {
238 menuItemAlbumDownActionPerformed(evt);
239 }
240 });
241 menuAlbum.add(menuItemAlbumDown);
242 menuAlbum.add(menuSeparadorAlbum2);
243
244 menuItemAlbumRedoThumbs.setText("Refaz Thumbs");
245 menuAlbum.add(menuItemAlbumRedoThumbs);
246
247 menuItemAlbumDelete.setText("Apagar Album");
248 menuAlbum.add(menuItemAlbumDelete);
249
250 setName("PainelWebFotos");
251 setLayout(new java.awt.GridBagLayout());
252 gridBagConstraints = new java.awt.GridBagConstraints();
253 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
254 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
255 gridBagConstraints.weightx = 1.0;
256 add(painelPesquisa, gridBagConstraints);
257 painelPesquisa.addPopupMouseListener((AcaoPopup) ApplicationContextResource.getBean("acaoPopup"));
258
259 painelAlbuns.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
260 painelAlbuns.setPreferredSize(new java.awt.Dimension(462, 150));
261 painelAlbuns.setRequestFocusEnabled(false);
262 painelAlbuns.setLayout(new java.awt.BorderLayout());
263
264 scrAlbuns.addComponentListener(new java.awt.event.ComponentAdapter() {
265 public void componentResized(java.awt.event.ComponentEvent evt) {
266 tbAlbunsChanged(evt);
267 }
268 });
269
270 tbAlbuns.setModel(new TableSorter(TableModelAlbum.getModel(), tbAlbuns.getTableHeader()));
271 tbAlbuns.setToolTipText("Use o botão direito para mais opções");
272 tbAlbuns.setName("tbAlbuns");
273 tbAlbuns.addMouseListener(new java.awt.event.MouseAdapter() {
274 public void mouseClicked(java.awt.event.MouseEvent evt) {
275 tbAlbunsMouseClicked(evt);
276 }
277 public void mousePressed(java.awt.event.MouseEvent evt) {
278 tbAlbunsPopupCalled(evt);
279 }
280 public void mouseReleased(java.awt.event.MouseEvent evt) {
281 tbAlbunsPopupCalled(evt);
282 }
283 });
284 scrAlbuns.setViewportView(tbAlbuns);
285
286 painelAlbuns.add(scrAlbuns, java.awt.BorderLayout.CENTER);
287
288 lblTabelaInfo.setFont(new java.awt.Font("SansSerif", 0, 10));
289 lblTabelaInfo.setText("0 álbuns encontrados");
290 painelAlbuns.add(lblTabelaInfo, java.awt.BorderLayout.SOUTH);
291
292 gridBagConstraints = new java.awt.GridBagConstraints();
293 gridBagConstraints.gridx = 0;
294 gridBagConstraints.gridy = 1;
295 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
296 gridBagConstraints.weightx = 1.0;
297 gridBagConstraints.weighty = 1.0;
298 add(painelAlbuns, gridBagConstraints);
299
300 painelDadosAlbum.setLayout(new javax.swing.BoxLayout(painelDadosAlbum, javax.swing.BoxLayout.LINE_AXIS));
301
302 painelInfoAlbum.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
303 painelInfoAlbum.setMinimumSize(new java.awt.Dimension(500, 250));
304 painelInfoAlbum.setPreferredSize(new java.awt.Dimension(500, 300));
305 painelInfoAlbum.setLayout(new java.awt.GridBagLayout());
306
307 lblAlbum.setText("Album:");
308 gridBagConstraints = new java.awt.GridBagConstraints();
309 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
310 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
311 painelInfoAlbum.add(lblAlbum, gridBagConstraints);
312
313 txtTitulo.setName("txtTitulo");
314 txtTitulo.setPreferredSize(new java.awt.Dimension(477, 22));
315 gridBagConstraints = new java.awt.GridBagConstraints();
316 gridBagConstraints.gridx = 1;
317 gridBagConstraints.gridy = 0;
318 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
319 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
320 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
321 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
322 painelInfoAlbum.add(txtTitulo, gridBagConstraints);
323
324 lblCategoria.setText("Categoria:");
325 gridBagConstraints = new java.awt.GridBagConstraints();
326 gridBagConstraints.gridx = 0;
327 gridBagConstraints.gridy = 1;
328 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
329 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
330 painelInfoAlbum.add(lblCategoria, gridBagConstraints);
331
332 lstCategoriasAlbum.setModel(new javax.swing.DefaultComboBoxModel(Album.getAlbum().getCategoriasArray()));
333 lstCategoriasAlbum.setName("lstCategoriasAlbum");
334 gridBagConstraints = new java.awt.GridBagConstraints();
335 gridBagConstraints.gridx = 1;
336 gridBagConstraints.gridy = 1;
337 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
338 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
339 gridBagConstraints.weightx = 5.0;
340 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
341 painelInfoAlbum.add(lstCategoriasAlbum, gridBagConstraints);
342
343 buttonAddCategory.setIconPrefix("plus");
344 buttonAddCategory.setMargin(new java.awt.Insets(2, 2, 2, 2));
345 buttonAddCategory.setName("buttonAddCategory");
346 buttonAddCategory.addActionListener(new java.awt.event.ActionListener() {
347 public void actionPerformed(java.awt.event.ActionEvent evt) {
348 buttonAddCategoryActionPerformed(evt);
349 }
350 });
351 gridBagConstraints = new java.awt.GridBagConstraints();
352 gridBagConstraints.gridx = 2;
353 gridBagConstraints.gridy = 1;
354 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
355 painelInfoAlbum.add(buttonAddCategory, gridBagConstraints);
356
357 lblData.setText("Data:");
358 gridBagConstraints = new java.awt.GridBagConstraints();
359 gridBagConstraints.gridx = 3;
360 gridBagConstraints.gridy = 1;
361 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
362 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
363 painelInfoAlbum.add(lblData, gridBagConstraints);
364
365 txtData.setMinimumSize(new java.awt.Dimension(11, 22));
366 txtData.setPreferredSize(new java.awt.Dimension(72, 22));
367 gridBagConstraints = new java.awt.GridBagConstraints();
368 gridBagConstraints.gridx = 4;
369 gridBagConstraints.gridy = 1;
370 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
371 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
372 gridBagConstraints.weightx = 1.0;
373 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
374 painelInfoAlbum.add(txtData, gridBagConstraints);
375
376 lblDescricao.setText("Descrição:");
377 gridBagConstraints = new java.awt.GridBagConstraints();
378 gridBagConstraints.gridx = 0;
379 gridBagConstraints.gridy = 2;
380 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
381 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
382 painelInfoAlbum.add(lblDescricao, gridBagConstraints);
383
384 scrDescricao.setAutoscrolls(true);
385
386 txtDescricao.setLineWrap(true);
387 txtDescricao.setWrapStyleWord(true);
388 txtDescricao.setName("txtDescricao");
389 scrDescricao.setViewportView(txtDescricao);
390
391 gridBagConstraints = new java.awt.GridBagConstraints();
392 gridBagConstraints.gridx = 1;
393 gridBagConstraints.gridy = 2;
394 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
395 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
396 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
397 gridBagConstraints.weighty = 5.0;
398 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
399 painelInfoAlbum.add(scrDescricao, gridBagConstraints);
400
401 tbFotos.setToolTipText("Use o botão direito para mais opções");
402 tbFotos.setName("tbFotos");
403 tbFotos.addMouseListener(new java.awt.event.MouseAdapter() {
404 public void mousePressed(java.awt.event.MouseEvent evt) {
405 tbFotosPopupCalled(evt);
406 }
407 public void mouseReleased(java.awt.event.MouseEvent evt) {
408 tbFotosPopupCalled(evt);
409 }
410 });
411 scrFotos.setViewportView(tbFotos);
412
413 gridBagConstraints = new java.awt.GridBagConstraints();
414 gridBagConstraints.gridx = 0;
415 gridBagConstraints.gridy = 3;
416 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
417 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
418 gridBagConstraints.weighty = 10.0;
419 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
420 painelInfoAlbum.add(scrFotos, gridBagConstraints);
421
422 painelDadosAlbum.add(painelInfoAlbum);
423
424 painelFormFoto.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
425 painelFormFoto.setMaximumSize(new java.awt.Dimension(210, 2147483647));
426 painelFormFoto.setMinimumSize(new java.awt.Dimension(210, 24));
427 painelFormFoto.setPreferredSize(new java.awt.Dimension(210, 24));
428 painelFormFoto.setLayout(new java.awt.GridBagLayout());
429 gridBagConstraints = new java.awt.GridBagConstraints();
430 gridBagConstraints.gridx = 0;
431 gridBagConstraints.gridy = 0;
432 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
433 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
434 gridBagConstraints.weightx = 1.0;
435 gridBagConstraints.weighty = 5.0;
436 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
437 painelFormFoto.add(painelFoto, gridBagConstraints);
438
439 lblLegenda.setText("Legenda e crédito:");
440 gridBagConstraints = new java.awt.GridBagConstraints();
441 gridBagConstraints.gridx = 0;
442 gridBagConstraints.gridy = 1;
443 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
444 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
445 gridBagConstraints.weightx = 1.0;
446 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
447 painelFormFoto.add(lblLegenda, gridBagConstraints);
448
449 scrLegenda.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
450 scrLegenda.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
451
452 txtLegenda.setLineWrap(true);
453 txtLegenda.setWrapStyleWord(true);
454 txtLegenda.setName("txtLegenda");
455 txtLegenda.addFocusListener(new java.awt.event.FocusAdapter() {
456 public void focusGained(java.awt.event.FocusEvent evt) {
457 txtLegendaFocusGained(evt);
458 }
459 public void focusLost(java.awt.event.FocusEvent evt) {
460 txtLegendaFocusLost(evt);
461 }
462 });
463 scrLegenda.setViewportView(txtLegenda);
464
465 gridBagConstraints = new java.awt.GridBagConstraints();
466 gridBagConstraints.gridx = 0;
467 gridBagConstraints.gridy = 2;
468 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
469 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
470 gridBagConstraints.weightx = 1.0;
471 gridBagConstraints.weighty = 3.0;
472 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
473 painelFormFoto.add(scrLegenda, gridBagConstraints);
474
475 lstCreditos.setModel(new javax.swing.DefaultComboBoxModel(net.sf.webphotos.PhotoDTO.getCreditosArray()));
476 lstCreditos.setName("lstCreditos");
477 gridBagConstraints = new java.awt.GridBagConstraints();
478 gridBagConstraints.gridx = 0;
479 gridBagConstraints.gridy = 3;
480 gridBagConstraints.gridwidth = 3;
481 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
482 gridBagConstraints.weightx = 1.0;
483 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
484 painelFormFoto.add(lstCreditos, gridBagConstraints);
485
486 buttonAddCredits.setIconPrefix("plus");
487 buttonAddCredits.setMargin(new java.awt.Insets(2, 2, 2, 2));
488 buttonAddCredits.setName("buttonAddCredits");
489 buttonAddCredits.addActionListener(new java.awt.event.ActionListener() {
490 public void actionPerformed(java.awt.event.ActionEvent evt) {
491 buttonAddCreditsActionPerformed(evt);
492 }
493 });
494 gridBagConstraints = new java.awt.GridBagConstraints();
495 gridBagConstraints.gridx = 3;
496 gridBagConstraints.gridy = 3;
497 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
498 painelFormFoto.add(buttonAddCredits, gridBagConstraints);
499
500 painelDadosAlbum.add(painelFormFoto);
501
502 gridBagConstraints = new java.awt.GridBagConstraints();
503 gridBagConstraints.gridx = 0;
504 gridBagConstraints.gridy = 2;
505 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
506 gridBagConstraints.weightx = 1.0;
507 gridBagConstraints.weighty = 1.5;
508 add(painelDadosAlbum, gridBagConstraints);
509
510 painelControle.setMaximumSize(new java.awt.Dimension(32767, 73));
511 painelControle.setMinimumSize(new java.awt.Dimension(710, 73));
512 painelControle.setLayout(new java.awt.GridBagLayout());
513
514 scrLog.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
515 scrLog.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
516 scrLog.setAutoscrolls(true);
517 scrLog.setMaximumSize(new java.awt.Dimension(32767, 63));
518 scrLog.setMinimumSize(new java.awt.Dimension(24, 63));
519 scrLog.setPreferredSize(new java.awt.Dimension(22, 63));
520
521 txtLog.setFont(new java.awt.Font("Courier", 0, 11));
522 scrLog.setViewportView(txtLog);
523
524 gridBagConstraints = new java.awt.GridBagConstraints();
525 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
526 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
527 gridBagConstraints.weightx = 100.0;
528 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
529 painelControle.add(scrLog, gridBagConstraints);
530
531 painelToolBar.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
532 painelToolBar.setLayout(new java.awt.GridBagLayout());
533
534 btFTP.setIconPrefix("ftp");
535 btFTP.setToolTipText("Realiza a trasferência dos Álbuns Marcados");
536 gridBagConstraints = new java.awt.GridBagConstraints();
537 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
538 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
539 painelToolBar.add(btFTP, gridBagConstraints);
540
541 btUpload.setIconPrefix("up");
542 btUpload.setToolTipText("Marca o Álbum para Upload");
543 gridBagConstraints = new java.awt.GridBagConstraints();
544 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
545 painelToolBar.add(btUpload, gridBagConstraints);
546
547 btDownload.setIconPrefix("down");
548 btDownload.setToolTipText("Marca o Álbum para Download");
549 gridBagConstraints = new java.awt.GridBagConstraints();
550 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
551 painelToolBar.add(btDownload, gridBagConstraints);
552
553 btAdicionarFotos.setIconPrefix("camera");
554 btAdicionarFotos.setName("buttonAddPhotos");
555 btAdicionarFotos.setToolTipText("Adiciona uma nova foto ao Álbum");
556 gridBagConstraints = new java.awt.GridBagConstraints();
557 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
558 painelToolBar.add(btAdicionarFotos, gridBagConstraints);
559
560 btAlterar.setText("alterar");
561 btAlterar.setToolTipText("Efetiva as alterações do álbum");
562 btAlterar.setActionCommand(ACAO_ALTERAR);
563 btAlterar.setEnabled(false);
564 gridBagConstraints = new java.awt.GridBagConstraints();
565 gridBagConstraints.gridx = 0;
566 gridBagConstraints.gridy = 1;
567 gridBagConstraints.gridwidth = 2;
568 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
569 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
570 painelToolBar.add(btAlterar, gridBagConstraints);
571
572 btNovo.setText("Adicionar");
573 btNovo.setToolTipText("Criar novo álbum");
574 btNovo.setActionCommand(ACAO_NOVO);
575 btNovo.setName("btNovo");
576 gridBagConstraints = new java.awt.GridBagConstraints();
577 gridBagConstraints.gridx = 2;
578 gridBagConstraints.gridy = 1;
579 gridBagConstraints.gridwidth = 2;
580 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
581 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
582 painelToolBar.add(btNovo, gridBagConstraints);
583
584 gridBagConstraints = new java.awt.GridBagConstraints();
585 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
586 gridBagConstraints.weightx = 1.0;
587 painelControle.add(painelToolBar, gridBagConstraints);
588
589 gridBagConstraints = new java.awt.GridBagConstraints();
590 gridBagConstraints.gridx = 0;
591 gridBagConstraints.gridy = 3;
592 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
593 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
594 gridBagConstraints.weightx = 1.0;
595 add(painelControle, gridBagConstraints);
596 }
597
598
599
600
601
602 private void menuItemAlbumRedoJSActionPerformed(java.awt.event.ActionEvent evt) {
603
604 (new SwingWorker<Void, Object>() {
605 @Override
606 protected Void doInBackground() throws Exception {
607 String caminhoAlbum;
608 FileWriter out;
609
610 setCursorWait(true);
611
612
613
614 int albumAtual = Album.getAlbum().getAlbumID();
615 int[] rowsID = tbAlbuns.getSelectedRows();
616 for (int rowID : rowsID) {
617 log.info("Gravando arquivo JS do álbum: " + tbAlbuns.getValueAt(rowID, 0).toString());
618 Album.getAlbum().loadAlbum(Integer.parseInt(tbAlbuns.getValueAt(rowID, 0).toString()));
619 caminhoAlbum = Util.getAlbunsRoot().getPath() + File.separator + Album.getAlbum().getAlbumID();
620 try {
621 out = new FileWriter(caminhoAlbum + File.separator + Album.getAlbum().getAlbumID() + ".js");
622 out.write(Album.getAlbum().toJavaScript());
623 out.flush();
624 out.close();
625
626 log.info("Arquivo JS gravado.");
627 } catch (IOException ex) {
628 log.error("Error trying to write a JS File", ex);
629 }
630
631 }
632 Album.getAlbum().loadAlbum(albumAtual);
633 setCursorWait(false);
634
635 return null;
636 }
637 }).execute();
638
639 }
640
641
642
643
644
645 private void menuItemAlbumRedoXMLActionPerformed(java.awt.event.ActionEvent evt) {
646
647 (new SwingWorker<Void, Object>() {
648 @Override
649 protected Void doInBackground() throws Exception {
650 String caminhoAlbum;
651 FileWriter out;
652
653 setCursorWait(true);
654
655
656
657 int albumAtual = Album.getAlbum().getAlbumID();
658 int[] rowsID = tbAlbuns.getSelectedRows();
659 for (int rowID : rowsID) {
660 log.info("Gravando arquivo XML do álbum: " + tbAlbuns.getValueAt(rowID, 0).toString());
661 Album.getAlbum().loadAlbum(Integer.parseInt(tbAlbuns.getValueAt(rowID, 0).toString()));
662 caminhoAlbum = Util.getAlbunsRoot().getPath() + File.separator + Album.getAlbum().getAlbumID();
663 try {
664 out = new FileWriter(caminhoAlbum + File.separator + Album.getAlbum().getAlbumID() + ".xml");
665 out.write(Album.getAlbum().toXML());
666 out.flush();
667 out.close();
668
669 log.info("Arquivo XML gravado.");
670 } catch (IOException ex) {
671 log.error("Error trying to write a XML File", ex);
672 }
673
674 }
675 Album.getAlbum().loadAlbum(albumAtual);
676 setCursorWait(false);
677 return null;
678 }
679 }).execute();
680
681 }
682
683 private void menuItemAlbumDownActionPerformed(java.awt.event.ActionEvent evt) {
684 PainelWebFotos.marcaAlbunsFTP(2);
685 }
686
687 private void menuItemAlbumUpActionPerformed(java.awt.event.ActionEvent evt) {
688 PainelWebFotos.marcaAlbunsFTP(1);
689 }
690
691 private void tbAlbunsPopupCalled(java.awt.event.MouseEvent evt) {
692 if (tbAlbuns.getSelectedRowCount() <= 1) {
693 int selecao = tbAlbuns.rowAtPoint(evt.getPoint());
694 tbAlbuns.setRowSelectionInterval(selecao, selecao);
695 }
696 if (evt.isPopupTrigger()) {
697 menuAlbum.show(evt.getComponent(), evt.getX(), evt.getY());
698 }
699 }
700
701 private void menuItemFotoDeleteActionPerformed(java.awt.event.ActionEvent evt) {
702
703 }
704
705 private void menuItemFotoRedoThumbsActionPerformed(java.awt.event.ActionEvent evt) {
706
707 (new SwingWorker<Void, Object>() {
708 @Override
709 protected Void doInBackground() throws Exception {
710 setCursorWait(true);
711 int[] rowsID = tbFotos.getSelectedRows();
712 for (int rowID : rowsID) {
713 PhotoDTO fotoSelecionada = Album.getAlbum().getFoto(Integer.parseInt(tbFotos.getValueAt(rowID, 0).toString()));
714 String caminhoAlbum = Util.getAlbunsRoot().getPath() + File.separator + Album.getAlbum().getAlbumID();
715 String caminhoArquivo = caminhoAlbum + File.separator + fotoSelecionada.getFotoID() + ".jpg";
716 log.debug("Foto: " + caminhoArquivo + " " + Integer.parseInt(tbFotos.getValueAt(tbFotos.getSelectedRow(), 0).toString()));
717 Thumbnail.makeThumbs(caminhoArquivo);
718 }
719 setCursorWait(false);
720 return null;
721 }
722 }).execute();
723
724 }
725
726 private void menuItemFotoDownActionPerformed(java.awt.event.ActionEvent evt) {
727 PainelWebFotos.marcaFotosFTP(2);
728 }
729
730 private void menuItemFotoUpActionPerformed(java.awt.event.ActionEvent evt) {
731 PainelWebFotos.marcaFotosFTP(1);
732 }
733
734 private void txtLegendaFocusLost(java.awt.event.FocusEvent evt) {
735 PhotoDTO f;
736 String nomeArquivoNovo;
737
738 try {
739
740 int fID = Integer.parseInt(tbFotos.getModel().getValueAt(indiceFoto, 0).toString());
741 f = Album.getAlbum().getFoto(fID);
742 } catch (Exception ex) {
743
744 nomeArquivoNovo = (String) tbFotos.getModel().getValueAt(indiceFoto, 0);
745 f = Album.getAlbum().getFoto(nomeArquivoNovo);
746 }
747
748 f.setLegenda(txtLegenda.getText());
749 TableModelFoto.getModel().update();
750 TableModelFoto.getModel().fireTableCellUpdated(indiceFoto, 1);
751 }
752
753 private void txtLegendaFocusGained(java.awt.event.FocusEvent evt) {
754 indiceFoto = tbFotos.getSelectedRow();
755 }
756
757 private void tbFotosPopupCalled(java.awt.event.MouseEvent evt) {
758 if (tbFotos.getSelectedRowCount() <= 1) {
759 int selecao = tbFotos.rowAtPoint(evt.getPoint());
760 tbFotos.setRowSelectionInterval(selecao, selecao);
761 }
762 if (evt.isPopupTrigger()) {
763 menuFoto.show(evt.getComponent(), evt.getX(), evt.getY());
764 }
765 }
766
767 private void tbAlbunsChanged(java.awt.event.ComponentEvent evt) {
768 Util.ajustaLargura(tbAlbuns, Util.getProperty("colunas1"));
769 }
770
771 private void tbAlbunsMouseClicked(java.awt.event.MouseEvent evt) {
772 tbAlbunsItemSelected();
773 }
774
775 private void buttonAddCategoryActionPerformed(java.awt.event.ActionEvent evt) {
776 String categoryName = JOptionPane.showInputDialog(this, "Type the new category name", "New Category", JOptionPane.INFORMATION_MESSAGE);
777
778 if (categoryName.isEmpty()) {
779 return;
780 }
781
782 CategoryVO categoryVO = new CategoryVO(categoryName);
783
784 CategoryDAO categoryDAO = (CategoryDAO) ApplicationContextResource.getBean("categoryDAO");
785 try {
786 categoryDAO.save(categoryVO);
787 } catch (Exception ex) {
788 JOptionPane.showMessageDialog(this, "Can't add category, see aplication log for details", "Error", JOptionPane.ERROR_MESSAGE);
789 java.util.logging.Logger.getLogger(PainelWebFotos.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
790 }
791 PainelWebFotos.montagemComboPesquisa(Boolean.TRUE);
792 }
793
794 private void buttonAddCreditsActionPerformed(java.awt.event.ActionEvent evt) {
795 String creditsName = JOptionPane.showInputDialog(this, "Type the new credits name", "New Credits", JOptionPane.INFORMATION_MESSAGE);
796
797 if (creditsName.isEmpty()) {
798 return;
799 }
800
801 CreditsVO creditsVO = new CreditsVO(creditsName);
802
803 CreditsDAO creditsDAO = (CreditsDAO) ApplicationContextResource.getBean("creditsDAO");
804
805 try {
806 creditsDAO.save(creditsVO);
807
808
809 PhotoDTO.populaCreditos();
810 populateCreditsComboBox();
811 } catch (Exception ex) {
812 JOptionPane.showMessageDialog(this, "Can't add credits, see aplication log for details", "Error", JOptionPane.ERROR_MESSAGE);
813 java.util.logging.Logger.getLogger(PainelWebFotos.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
814 }
815 }
816
817
818
819
820
821
822
823 public static PainelWebFotos getInstance() {
824 if (janela == null) {
825 janela = new PainelWebFotos();
826 }
827 return janela;
828 }
829
830
831
832
833
834
835
836
837
838
839 public static void marcaFotosFTP(int comando) {
840 try {
841 for (int indiceFotoSelecionada : tbFotos.getSelectedRows()) {
842 PhotoDTO fotoSelecionada = Album.getAlbum().getFotos()[indiceFotoSelecionada];
843 CacheFTP.getCache().addCommand(comando, Album.getAlbum().getAlbumID(), fotoSelecionada.getFotoID());
844 }
845 } catch (Exception e) {
846 log.error("Error marking Photos", e);
847 }
848 }
849
850
851
852
853
854
855
856
857
858
859 public static void marcaAlbunsFTP(int comando) {
860 try {
861 for (int indiceAlbumSelecionado : tbAlbuns.getSelectedRows()) {
862 CacheFTP.getCache().addCommand(comando, Integer.parseInt(tbAlbuns.getValueAt(indiceAlbumSelecionado, 0).toString()), 0);
863 }
864 } catch (Exception e) {
865 log.error("Error marking Albuns", e);
866 }
867 }
868
869
870
871
872
873
874 private static void rotinasExtras() throws Exception {
875
876
877
878
879 Action acaoExcluirAlbum = (Action) ApplicationContextResource.getBean("acaoExcluirAlbum");
880 tbAlbuns.registerKeyboardAction(acaoExcluirAlbum,
881 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0),
882 javax.swing.JComponent.WHEN_FOCUSED);
883
884
885 btAdicionarFotos.addActionListener(new AcaoAdicionarFoto(tbFotos, lstCreditosTabelaFotos, "Adicionar fotos no álbum"));
886
887
888 javax.swing.Action acaoExcluirFoto = new AcaoExcluirFoto(tbFotos);
889 tbFotos.registerKeyboardAction(acaoExcluirFoto,
890 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0),
891 javax.swing.JComponent.WHEN_FOCUSED);
892
893
894 javax.swing.Action acaoAlterarAlbum = new AcaoAlterarAlbum(btNovo, btAlterar);
895 btAlterar.addActionListener(acaoAlterarAlbum);
896 btNovo.addActionListener(acaoAlterarAlbum);
897
898
899 lstCategoriasAlbum.addItemListener(new AcaoItemListener());
900
901
902 txtDescricao.registerKeyboardAction(null,
903 KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), JComponent.WHEN_FOCUSED);
904
905
906
907 AcaoItemListener acaoItemListener = new AcaoItemListener(tbFotos);
908 lstCreditos.addItemListener(acaoItemListener);
909 lstCreditosTabelaFotos.addItemListener(acaoItemListener);
910
911
912 Util.setLoggingTextArea(txtLog);
913 Util.ajustaLargura(tbAlbuns, Util.getConfig().getString("colunas1"));
914
915
916 apresentaNumReg();
917 atualizaTabelaFotos();
918 montagemComboPesquisa(Boolean.FALSE);
919
920
921 DocumentListener acaoDocumentListener = (DocumentListener) ApplicationContextResource.getBean("acaoDocumentListener");
922
923 txtTitulo.getDocument().addDocumentListener(acaoDocumentListener);
924 txtData.getDocument().addDocumentListener(acaoDocumentListener);
925 txtDescricao.getDocument().addDocumentListener(acaoDocumentListener);
926 txtLegenda.getDocument().addDocumentListener(acaoDocumentListener);
927
928
929 mascaraData.install(txtData);
930
931
932 tbFotos.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {
933 @Override
934 public void valueChanged(javax.swing.event.ListSelectionEvent e) {
935
936 if (e.getValueIsAdjusting()) {
937 return;
938 }
939
940 javax.swing.ListSelectionModel lsm =
941 (javax.swing.ListSelectionModel) e.getSource();
942 if (!lsm.isSelectionEmpty()) {
943
944 PainelWebFotos.getInstance().carregaFoto();
945 }
946 }
947 });
948
949
950 tbFotos.getModel().addTableModelListener(new javax.swing.event.TableModelListener() {
951 @Override
952 public void tableChanged(TableModelEvent e) {
953 Util.ajustaLargura(tbFotos, Util.getProperty("colunas2"));
954 }
955 });
956
957
958 tbAlbuns.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {
959 @Override
960 public void valueChanged(javax.swing.event.ListSelectionEvent e) {
961
962 if (e.getValueIsAdjusting()) {
963 return;
964 }
965
966 javax.swing.ListSelectionModel lsm =
967 (javax.swing.ListSelectionModel) e.getSource();
968 if (!lsm.isSelectionEmpty()) {
969
970 PainelWebFotos.getInstance().tbAlbunsItemSelected();
971 }
972 }
973 });
974
975
976 tbAlbuns.getModel().addTableModelListener(new javax.swing.event.TableModelListener() {
977 @Override
978 public void tableChanged(TableModelEvent e) {
979 Util.ajustaLargura(tbAlbuns, Util.getProperty("colunas1"));
980 }
981 });
982
983
984 resetAlbum();
985 onoffPauta(false);
986 }
987
988
989
990
991
992
993
994
995 public static void setCursorWait(boolean valor) {
996 if (valor) {
997 PainelWebFotos.getInstance().setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
998 } else {
999 PainelWebFotos.getInstance().setCursor(null);
1000 }
1001 }
1002
1003
1004
1005
1006
1007
1008 public static void alteracaoFinalizada() {
1009 documentoAlterado = false;
1010 btAlterar.setEnabled(false);
1011 }
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021 public static void alteracaoDetectada() {
1022 if (controlarAlteracoes) {
1023 if (Album.getAlbum().getNmAlbum().equals(txtTitulo.getText())
1024 && Album.getAlbum().getDtInsercao().equals(txtData.getText())
1025 && Album.getAlbum().getDescricao().equals(txtDescricao.getText())
1026 && Album.getAlbum().getCategoriaID() == Album.getAlbum().getLstCategoriasID(lstCategoriasAlbum.getSelectedItem().toString())
1027 && Album.getAlbum().toString().equals(ultimoAlbum)) {
1028 alteracaoFinalizada();
1029 return;
1030 }
1031 documentoAlterado = true;
1032 btAlterar.setEnabled(true);
1033 }
1034 }
1035
1036
1037
1038
1039
1040
1041
1042
1043 public static void detectarAlteracoes(boolean valor) {
1044 controlarAlteracoes = valor;
1045 }
1046
1047
1048
1049
1050 private void tbAlbunsItemSelected() {
1051
1052 if (tbFotos.isEditing()) {
1053 tbFotos.removeEditor();
1054 }
1055
1056
1057 if (btNovo.getActionCommand().equals(ACAO_FINALIZAR)) {
1058 Object[] opcoes = {"Retornar", "Abandonar álbum"};
1059 Object valorInicial = opcoes[0];
1060
1061 int retorno = javax.swing.JOptionPane.showOptionDialog(null,
1062 "O álbum que você estava criando não foi finalizado",
1063 "Cancelar criação de álbum ?",
1064 javax.swing.JOptionPane.OK_OPTION,
1065 javax.swing.JOptionPane.QUESTION_MESSAGE,
1066 null,
1067 opcoes,
1068 valorInicial);
1069
1070 if (retorno == 0) {
1071 tbAlbuns.setRowSelectionInterval(linhaSelecionadaAlbum, linhaSelecionadaAlbum);
1072 return;
1073 } else {
1074 botaoCancelar();
1075 }
1076 }
1077
1078 if (documentoAlterado) {
1079 if (checarAlteracoes() == 0) {
1080 tbAlbuns.setRowSelectionInterval(linhaSelecionadaAlbum, linhaSelecionadaAlbum);
1081 return;
1082 }
1083 }
1084
1085 setCursorWait(true);
1086 linhaSelecionadaAlbum = tbAlbuns.getSelectedRow();
1087 Object indice = tbAlbuns.getModel().getValueAt(linhaSelecionadaAlbum, 0);
1088 int i = Integer.parseInt(indice.toString());
1089 Album.getAlbum().loadAlbum(i);
1090 ultimoAlbum = Album.getAlbum().toString();
1091 carregaAlbum();
1092
1093 tbFotos.setRowSelectionInterval(0, 0);
1094 carregaFoto();
1095 setCursorWait(false);
1096 }
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107 public static boolean atualizaAlbum() {
1108 Album album = Album.getAlbum();
1109 PhotoDTO[] fotos = album.getFotos();
1110 String titulo = txtTitulo.getText();
1111 String descricao = txtDescricao.getText();
1112 String data = txtData.getText();
1113 int categoriaIndice = lstCategoriasAlbum.getSelectedIndex();
1114 String msgErro = "";
1115 java.text.SimpleDateFormat dataBR = new java.text.SimpleDateFormat("dd/MM/yy");
1116 dataBR.setLenient(false);
1117
1118
1119 if (titulo.length() < 1) {
1120 msgErro = "\n - Álbum";
1121 }
1122 if (descricao.length() < 1) {
1123 msgErro = msgErro + "\n - Descrição";
1124 }
1125 if (categoriaIndice < 1) {
1126 msgErro = msgErro + "\n - Categoria";
1127 }
1128
1129
1130 try {
1131 dataBR.parse(data);
1132 } catch (Exception e) {
1133 msgErro = "\n - Data (" + data + ") inválida";
1134 Util.log("[PainelWebFotos.atualizaAlbum]/ERRO: " + e.getMessage());
1135 }
1136
1137
1138 if (fotos.length == 0) {
1139 msgErro = msgErro + "\n - Não existem fotos cadastradas nesse álbum";
1140 }
1141 for (int i = 0; i < fotos.length; i++) {
1142 PhotoDTO photoDTO = fotos[i];
1143 final boolean creditoIDNotOk = photoDTO.getCreditoID() == 0;
1144 final boolean legendaNotOk = photoDTO.getLegenda().isEmpty();
1145 if (creditoIDNotOk || legendaNotOk) {
1146 msgErro = msgErro + "\n - Informação sobre foto na linha " + (i + 1) + ": "
1147 + (creditoIDNotOk ? "\n - Credito não foi escolhido" : "")
1148 + (legendaNotOk ? "\n - Legenda não foi preenchida" : "");
1149 }
1150 }
1151
1152 if (msgErro.length() > 0) {
1153 javax.swing.JOptionPane.showMessageDialog(null, "Preencha corretamente os campos:\n" + msgErro, "Erro no preenchimento", javax.swing.JOptionPane.ERROR_MESSAGE);
1154 return false;
1155 }
1156
1157
1158 album.setNmAlbum(titulo);
1159 album.setDescricao(descricao);
1160 album.setDtInsercao(data);
1161 album.setCategoriaID(album.getLstCategoriasID(lstCategoriasAlbum.getSelectedItem().toString()));
1162
1163 return true;
1164 }
1165
1166
1167 private void carregaAlbum() {
1168
1169 controlarAlteracoes = false;
1170 onoffPauta(true);
1171 resetFoto();
1172 onoffFoto(false);
1173
1174 Album b = Album.getAlbum();
1175
1176 albumID = b.getAlbumID();
1177 txtTitulo.setText(b.getNmAlbum());
1178 txtTitulo.setCaretPosition(0);
1179 txtData.setText(b.getDtInsercao());
1180 txtDescricao.setText(b.getDescricao());
1181 txtDescricao.setCaretPosition(0);
1182
1183 int i = Album.getAlbum().getLstCategoriasIndex(b.getCategoriaID());
1184 lstCategoriasAlbum.setSelectedIndex(i + 1);
1185
1186
1187 atualizaTabelaFotos();
1188 alteracaoFinalizada();
1189 controlarAlteracoes = true;
1190 }
1191
1192 private void carregaFoto() {
1193 int indiceCredito;
1194 Object indice = tbFotos.getModel().getValueAt(tbFotos.getSelectedRow(), 0);
1195 String caminho;
1196 PhotoDTO f;
1197 int fotoID;
1198
1199 try {
1200 fotoID = Integer.parseInt(indice.toString());
1201 f = Album.getAlbum().getFoto(fotoID);
1202 caminho = BancoImagem.getLocalPath(albumID) + File.separator + "_b" + fotoID + ".jpg";
1203 indiceCredito = PhotoDTO.getLstCreditosIndex(f.getCreditoNome()) + 1;
1204 } catch (NumberFormatException e) {
1205 f = Album.getAlbum().getFoto(indice.toString());
1206 caminho = f.getCaminhoArquivo();
1207
1208 if (f.getCreditoID() == 0) {
1209 indiceCredito = 0;
1210 } else {
1211 indiceCredito = PhotoDTO.getLstCreditosIndex(f.getCreditoNome()) + 1;
1212 }
1213 }
1214
1215 if (f == null) {
1216 return;
1217 }
1218 painelFoto.loadImage(caminho);
1219
1220
1221 controlarAlteracoes = false;
1222 txtLegenda.setText(f.getLegenda());
1223 txtLegenda.setCaretPosition(0);
1224 log.debug("indiceCredito: " + indiceCredito);
1225 try {
1226 lstCreditos.setSelectedIndex(indiceCredito);
1227 } catch (Exception e) {
1228 log.error("Contagem: " + lstCreditos.getItemCount(), e);
1229 }
1230 controlarAlteracoes = true;
1231 onoffFoto(true);
1232
1233 painelFoto.getLblFotoInfo().setText((f.getAltura() == 0) ? "?? x ??" : f.getLargura() + "x" + f.getAltura());
1234 }
1235
1236 private int checarAlteracoes() {
1237 if (documentoAlterado) {
1238 Object[] opcoes = {"Retornar", "Abandonar alterações"};
1239 Object valorInicial = opcoes[0];
1240
1241 return javax.swing.JOptionPane.showOptionDialog(null,
1242 "Houve alterações neste álbum que não foram salvas.\n\nPara salvar as alterações clique em \"Retornar\" e finalize suas alterações.\nPara prosseguir sem salvar, clique em \"Abandonar alterações\"\n",
1243 "Cancelar alterações ?",
1244 javax.swing.JOptionPane.OK_OPTION,
1245 javax.swing.JOptionPane.QUESTION_MESSAGE,
1246 null,
1247 opcoes,
1248 valorInicial);
1249 }
1250 return 1;
1251 }
1252
1253 private static void onoffPauta(boolean valor) {
1254 txtTitulo.setEnabled(valor);
1255 txtData.setEnabled(valor);
1256 lstCategoriasAlbum.setEnabled(valor);
1257 txtDescricao.setEnabled(valor);
1258 btAdicionarFotos.setEnabled(valor);
1259 }
1260
1261 private static void onoffFoto(boolean valor) {
1262 txtLegenda.setEnabled(valor);
1263 lstCreditos.setEnabled(valor);
1264 }
1265
1266
1267
1268
1269
1270 public static void apresentaNumReg() {
1271 int numReg = TableModelAlbum.getModel().getRowCount();
1272 String msg;
1273 if (numReg == 0) {
1274 msg = "Nenhum ábum encontrado. Para ver outros álbuns, deixe a caixa de texto \"palavra(s)\" vazia e clique em Pesquisar.";
1275 } else if (numReg == 1) {
1276 msg = "1 álbum encontrado";
1277 } else {
1278 msg = (numReg + " álbuns encontrados");
1279 }
1280 lblTabelaInfo.setText(msg);
1281 }
1282
1283 private static void atualizaTabelaFotos() {
1284 TableModelFoto.getModel().update();
1285 TableModelFoto.getModel().fireTableDataChanged();
1286
1287
1288 tbFotos.setModel(new TableSorter(TableModelFoto.getModel(), tbFotos.getTableHeader()));
1289
1290
1291 tbFotos.getColumnModel().getColumn(2).setCellEditor(new javax.swing.DefaultCellEditor(lstCreditosTabelaFotos));
1292 Util.ajustaLargura(tbFotos, Util.getConfig().getString("colunas2"));
1293
1294 tbFotos.repaint();
1295 painelFoto.clear();
1296 }
1297
1298
1299
1300
1301
1302
1303
1304
1305 public static void botaoNovo() {
1306 detectarAlteracoes(false);
1307 btAlterar.setText("Cancelar");
1308 btAlterar.setActionCommand(ACAO_CANCELAR);
1309 btAlterar.setToolTipText("Cancela a criação do álbum");
1310 btNovo.setText("Finalizar");
1311 btNovo.setActionCommand(ACAO_FINALIZAR);
1312 btNovo.setToolTipText("Adiciona o álbum ao banco de dados");
1313 btAlterar.setEnabled(true);
1314 resetAlbum();
1315 resetFoto();
1316 onoffPauta(true);
1317 try {
1318 java.text.SimpleDateFormat dataBR = new java.text.SimpleDateFormat("dd/MM/yy");
1319 txtData.setText(dataBR.format(new java.util.Date()));
1320 } catch (Exception e) {
1321 Util.log("ERRO: " + e.getMessage());
1322 }
1323
1324 AcaoAdicionarFoto a = new AcaoAdicionarFoto(tbFotos, lstCreditosTabelaFotos, "Criando novo álbum - Selecione os arquivos");
1325 a.actionPerformed(null);
1326
1327 txtTitulo.requestFocus(true);
1328 }
1329
1330
1331
1332
1333
1334 public static void botaoCancelar() {
1335 btAlterar.setText("Alterar");
1336 btAlterar.setActionCommand(ACAO_ALTERAR);
1337 btAlterar.setToolTipText("Efetiva as alterações do álbum");
1338 btNovo.setText("Novo");
1339 btNovo.setActionCommand(ACAO_NOVO);
1340 btNovo.setToolTipText("Criar novo álbum");
1341 btAlterar.setEnabled(false);
1342 resetAlbum();
1343 resetFoto();
1344 onoffPauta(false);
1345 alteracaoFinalizada();
1346 detectarAlteracoes(true);
1347 }
1348
1349
1350
1351
1352
1353 public static void botaoFinalizar() {
1354 btAlterar.setText("Alterar");
1355 btAlterar.setActionCommand(ACAO_ALTERAR);
1356 btAlterar.setToolTipText("Efetiva as alterações do álbum");
1357 btNovo.setText("Novo");
1358 btNovo.setActionCommand(ACAO_NOVO);
1359 btNovo.setToolTipText("Criar novo álbum");
1360 btAlterar.setEnabled(false);
1361 resetAlbum();
1362 resetFoto();
1363 alteracaoFinalizada();
1364 detectarAlteracoes(true);
1365 onoffPauta(false);
1366 }
1367
1368
1369
1370
1371
1372
1373 public static void resetFoto() {
1374 controlarAlteracoes = false;
1375 txtLegenda.setText("");
1376 try {
1377 lstCreditos.setSelectedIndex(0);
1378 } catch (Exception e) {
1379 Util.log("[PainelWebPhotos.resetFoto()]/ERRO: " + e.getMessage());
1380 }
1381 painelFoto.clear();
1382 painelFoto.getLblFotoInfo().setText("");
1383 onoffFoto(false);
1384 controlarAlteracoes = true;
1385 }
1386
1387
1388
1389
1390 public static void resetAlbum() {
1391
1392 Album.getAlbum().clear();
1393 txtTitulo.setText("");
1394 txtData.setText("");
1395 try {
1396 lstCategoriasAlbum.setSelectedIndex(0);
1397 } catch (Exception e) {
1398 Util.log("[PainelWebPhotos.resetAlbum()]/ERRO: " + e.getMessage());
1399 }
1400 txtDescricao.setText("");
1401 txtLegenda.setText("");
1402 try {
1403 lstCreditos.setSelectedIndex(0);
1404 } catch (Exception e) {
1405 Util.log("[PainelWebPhotos.resetAlbum()]/ERRO: " + e.getMessage());
1406 }
1407
1408 TableModelFoto.getModel().update();
1409 TableModelFoto.getModel().fireTableDataChanged();
1410 tbFotos.setModel(new TableSorter(TableModelFoto.getModel(), tbFotos.getTableHeader()));
1411
1412 tbFotos.repaint();
1413 painelFoto.clear();
1414
1415
1416 onoffFoto(false);
1417 }
1418 private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(PainelWebFotos.class.getName());
1419
1420 private static net.sf.webphotos.gui.component.BotaoIcone btAdicionarFotos;
1421 private static javax.swing.JButton btAlterar;
1422 private static net.sf.webphotos.gui.component.BotaoIcone btDownload;
1423 private static net.sf.webphotos.gui.component.BotaoIcone btFTP;
1424 private static javax.swing.JButton btNovo;
1425 private static net.sf.webphotos.gui.component.BotaoIcone btUpload;
1426 private static net.sf.webphotos.gui.component.BotaoIcone buttonAddCategory;
1427 private static net.sf.webphotos.gui.component.BotaoIcone buttonAddCredits;
1428 private static javax.swing.JLabel lblAlbum;
1429 private static javax.swing.JLabel lblCategoria;
1430 private static javax.swing.JLabel lblData;
1431 private static javax.swing.JLabel lblDescricao;
1432 private static javax.swing.JLabel lblLegenda;
1433 private static javax.swing.JLabel lblTabelaInfo;
1434 private static javax.swing.JComboBox lstCategoriasAlbum;
1435 private static javax.swing.JComboBox lstCreditos;
1436 private static javax.swing.JComboBox lstCreditosTabelaFotos;
1437 private static javax.swing.JPopupMenu menuAlbum;
1438 private static javax.swing.JPopupMenu menuFoto;
1439 private static javax.swing.JMenuItem menuItemAlbumDelete;
1440 private static javax.swing.JMenuItem menuItemAlbumDown;
1441 private static javax.swing.JMenuItem menuItemAlbumRedoJS;
1442 private static javax.swing.JMenuItem menuItemAlbumRedoThumbs;
1443 private static javax.swing.JMenuItem menuItemAlbumRedoXML;
1444 private static javax.swing.JMenuItem menuItemAlbumUp;
1445 private static javax.swing.JMenuItem menuItemFotoDelete;
1446 private static javax.swing.JMenuItem menuItemFotoDown;
1447 private static javax.swing.JMenuItem menuItemFotoRedoThumbs;
1448 private static javax.swing.JMenuItem menuItemFotoUp;
1449 private static javax.swing.JSeparator menuSeparadorAlbum1;
1450 private static javax.swing.JSeparator menuSeparadorAlbum2;
1451 private static javax.swing.JSeparator menuSeparadorFoto;
1452 private static javax.swing.JPanel painelAlbuns;
1453 private static javax.swing.JPanel painelControle;
1454 private static javax.swing.JPanel painelDadosAlbum;
1455 private static javax.swing.JPanel painelFormFoto;
1456 private static net.sf.webphotos.gui.component.PainelFoto painelFoto;
1457 private static javax.swing.JPanel painelInfoAlbum;
1458 private static net.sf.webphotos.gui.component.PainelPesquisa painelPesquisa;
1459 private static javax.swing.JPanel painelToolBar;
1460 private static javax.swing.JScrollPane scrAlbuns;
1461 private static javax.swing.JScrollPane scrDescricao;
1462 private static javax.swing.JScrollPane scrFotos;
1463 private static javax.swing.JScrollPane scrLegenda;
1464 private static javax.swing.JScrollPane scrLog;
1465 private static javax.swing.JTable tbAlbuns;
1466 private static javax.swing.JTable tbFotos;
1467 private static javax.swing.JFormattedTextField txtData;
1468 private static javax.swing.JTextArea txtDescricao;
1469 private static javax.swing.JTextArea txtLegenda;
1470 private static javax.swing.JTextArea txtLog;
1471 private static javax.swing.JTextField txtTitulo;
1472
1473
1474 private int albumID;
1475
1476 private int linhaSelecionadaAlbum;
1477 private int indiceFoto;
1478
1479 private static String ultimoAlbum;
1480
1481 private static boolean controlarAlteracoes;
1482 private static boolean documentoAlterado;
1483
1484 private static javax.swing.text.MaskFormatter mascaraData;
1485
1486
1487
1488
1489
1490
1491 public static javax.swing.JTable getTbAlbuns() {
1492 return tbAlbuns;
1493 }
1494
1495
1496
1497
1498
1499
1500 public static javax.swing.JComboBox getLstCreditos() {
1501 return lstCreditos;
1502 }
1503
1504
1505
1506
1507
1508
1509
1510 public static javax.swing.JComboBox getLstCreditosTabelaFotos() {
1511 return lstCreditosTabelaFotos;
1512 }
1513
1514
1515
1516
1517
1518
1519 public static javax.swing.JTable getTbFotos() {
1520 return tbFotos;
1521 }
1522
1523
1524
1525
1526
1527
1528 public static javax.swing.JTextArea getTxtLegenda() {
1529 return txtLegenda;
1530 }
1531
1532
1533
1534
1535
1536
1537 public static javax.swing.JTextArea getTxtLog() {
1538 return txtLog;
1539 }
1540
1541
1542
1543
1544
1545
1546
1547 public static javax.swing.text.MaskFormatter getMascaraData() {
1548 return mascaraData;
1549 }
1550
1551
1552
1553
1554
1555
1556
1557 public static void setMascaraData(javax.swing.text.MaskFormatter aMascaraData) {
1558 mascaraData = aMascaraData;
1559 }
1560
1561 private void populateCreditsComboBox() {
1562 final DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel(PhotoDTO.getCreditosArray());
1563 lstCreditos.setModel(defaultComboBoxModel);
1564 lstCreditosTabelaFotos.setModel(defaultComboBoxModel);
1565 lstCreditos.insertItemAt("", 0);
1566 }
1567 }