001: /*
002: * Created on 11/08/2004
003: *
004: * ============================================================================
005: * GNU Lesser General Public License
006: * ============================================================================
007: *
008: * Swing Components - visit http://sf.net/projects/gfd
009: *
010: * Copyright (C) 2004 Igor Regis da Silva Simões
011: *
012: * This library is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU Lesser General Public
014: * License as published by the Free Software Foundation; either
015: * version 2.1 of the License, or (at your option) any later version.
016: *
017: * This library is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
020: * Lesser General Public License for more details.
021: *
022: * You should have received a copy of the GNU Lesser General Public
023: * License along with this library; if not, write to the Free Software
024: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
025: */
026: package br.com.gfpshare.beans.aplicativos;
027:
028: import java.awt.BorderLayout;
029: import java.awt.Dimension;
030: import java.awt.GridBagConstraints;
031: import java.awt.GridBagLayout;
032: import java.awt.event.ActionListener;
033: import java.awt.event.MouseEvent;
034: import java.awt.event.MouseListener;
035: import java.security.InvalidParameterException;
036: import java.util.ArrayList;
037:
038: import javax.swing.JButton;
039: import javax.swing.JComponent;
040: import javax.swing.JFrame;
041: import javax.swing.JPanel;
042: import javax.swing.JScrollPane;
043: import javax.swing.JSplitPane;
044: import javax.swing.JTable;
045: import javax.swing.JTextArea;
046: import javax.swing.JTextField;
047: import javax.swing.SwingConstants;
048:
049: import br.com.gfpshare.beans.MessageView;
050: import br.com.gfpshare.beans.PaginadorDeTabela;
051: import br.com.gfpshare.beans.RequiredFieldLabel;
052: import br.com.gfpshare.beans.ZLabel;
053: import br.com.gfpshare.beans.ZTextArea;
054:
055: /**
056: * @author Igor Regis da Silva Simões
057: *
058: */
059: public class PainelTelaBasica extends JPanel {
060: private int oldDividerLocationVertical = 0;
061:
062: private int oldDividerLocationHorizontal = 0;
063:
064: private ZLabel jlDescricao;
065:
066: private PainelBotoes painelBotoes;
067:
068: private JPanel jpCampos;
069:
070: private JPanel jpDescricao;
071:
072: private JPanel jpDados;
073:
074: private JButton jbReport;
075:
076: private JPanel jpPaginacao;
077:
078: private JPanel jpPesquisa;
079:
080: private JScrollPane jspDescricao;
081:
082: private JScrollPane jspDados;
083:
084: private JSplitPane jspNorte;
085:
086: private JSplitPane jspPrincipal;
087:
088: private JTable jtDados;
089:
090: private ZTextArea jtaDescricao;
091:
092: private PaginadorDeTabela pdtPaginador;
093:
094: private ArrayList requiredFields = new ArrayList(1);
095:
096: /**
097: * Comment for <code>DATA_COMPONENTS_AREA</code>
098: */
099: public static final int DATA_COMPONENTS_AREA = 0;
100:
101: /**
102: * Comment for <code>TABLE_HEADER_AREA</code>
103: */
104: public static final int TABLE_HEADER_AREA = 1;
105:
106: /**
107: * Comment for <code>TABLE_AREA</code>
108: */
109: public static final int TABLE_AREA = 2;
110:
111: /**
112: *
113: */
114: public PainelTelaBasica() {
115: initComponents();
116: inicializar();
117: }
118:
119: /**
120: * @param componente
121: * @param constraints
122: * @param area
123: */
124: public void addComponent(JComponent componente,
125: GridBagConstraints constraints, int area) {
126: if (componente instanceof RequiredFieldLabel) {
127: if (((RequiredFieldLabel) componente).isRequired())
128: requiredFields.add(componente);
129: }
130: switch (area) {
131: case DATA_COMPONENTS_AREA:
132: jpCampos.add(componente, constraints);
133: break;
134: case TABLE_AREA:
135: jpDados.add(componente, constraints);
136: break;
137: case TABLE_HEADER_AREA:
138: jpPaginacao.add(componente, constraints);
139: break;
140: default:
141: throw new InvalidParameterException(""); //$NON-NLS-1$
142: }
143: }
144:
145: /**
146: * @param componente
147: * @param area
148: */
149: public void removeComponent(JComponent componente, int area) {
150: if (componente instanceof RequiredFieldLabel) {
151: if (((RequiredFieldLabel) componente).isRequired())
152: requiredFields.remove(componente);
153: }
154: switch (area) {
155: case DATA_COMPONENTS_AREA:
156: jpCampos.remove(componente);
157: break;
158: case TABLE_AREA:
159: jpDados.remove(componente);
160: break;
161: case TABLE_HEADER_AREA:
162: jpPaginacao.remove(componente);
163: break;
164: default:
165: throw new InvalidParameterException(
166: "Area de inserção para componentes inválida!"); //$NON-NLS-1$
167: }
168: }
169:
170: /**
171: * @return painel contendo os botões da tela
172: */
173: public PainelBotoes getPainelBotoes() {
174: return painelBotoes;
175: }
176:
177: /**
178: * @return TextArea da tela
179: */
180: public JTextArea getTextAreaDescricao() {
181: return jtaDescricao;
182: }
183:
184: /**
185: * @param txtArea
186: */
187: public void setTextAreaDescricao(ZTextArea txtArea) {
188: jtaDescricao = txtArea;
189: }
190:
191: /**
192: * Inicializa os componentes
193: */
194: private void inicializar() {
195: pdtPaginador.setConfiguracao(jtDados);
196: }
197:
198: /**
199: * @return Returns the jtDados.
200: */
201: public JTable getJtDados() {
202: return jtDados;
203: }
204:
205: /**
206: * @param jtDados The jtDados to set.
207: */
208: public void setJtDados(JTable jtDados) {
209: this .jtDados = jtDados;
210: jspDados.setViewportView(jtDados);
211: inicializar();
212: }
213:
214: /**
215: * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always
216: * regenerated by the Form Editor.
217: */
218: private void initComponents() {
219: GridBagConstraints gridBagConstraints;
220:
221: jspPrincipal = new JSplitPane();
222: jpDados = new JPanel();
223: jspDados = new JScrollPane();
224: jpPaginacao = new JPanel();
225: pdtPaginador = new PaginadorDeTabela();
226: jpPesquisa = new JPanel();
227: jspNorte = new JSplitPane();
228: jpCampos = new JPanel();
229: jpDescricao = new JPanel();
230: jspDescricao = new JScrollPane();
231: jtaDescricao = new ZTextArea();
232: jlDescricao = new ZLabel();
233: painelBotoes = new PainelBotoes();
234:
235: FormListener formListener = new FormListener();
236:
237: setJtDados(new JTable());
238:
239: jspPrincipal.setDividerLocation(200);
240: jspPrincipal.setDividerSize(8);
241: jspPrincipal.setOrientation(JSplitPane.VERTICAL_SPLIT);
242: jspPrincipal.setOneTouchExpandable(true);
243: jpDados.setLayout(new GridBagLayout());
244: jpDados.setPreferredSize(new Dimension(453, 150));
245:
246: jbReport = new JButton();
247: jbReport.setText(PainelTelaBasicaMessages.getMessages()
248: .getString("Report"));
249: jbReport.setToolTipText(PainelTelaBasicaMessages.getMessages()
250: .getString("ReportToolTip"));
251: jbReport.setMnemonic(PainelTelaBasicaMessages.getMessages()
252: .getString("ReportMnemonic").charAt(0));
253: jbReport.setIcon(IconeFactory.getIconeFactory().getImageIcon(
254: "tamanho=pequena;/icones/32x32/fileprint.png"));
255: jbReport.setActionCommand("Report");
256:
257: gridBagConstraints = new GridBagConstraints();
258: gridBagConstraints.gridx = 0;
259: gridBagConstraints.gridy = 0;
260: gridBagConstraints.anchor = GridBagConstraints.WEST;
261: gridBagConstraints.weightx = 0;
262: gridBagConstraints.weighty = 0;
263: jpPaginacao.add(jbReport, gridBagConstraints);
264:
265: gridBagConstraints = new GridBagConstraints();
266: gridBagConstraints.gridx = 0;
267: gridBagConstraints.gridy = 1;
268: gridBagConstraints.fill = GridBagConstraints.BOTH;
269: gridBagConstraints.weightx = 1.0;
270: gridBagConstraints.weighty = 1.0;
271: jpDados.add(jspDados, gridBagConstraints);
272:
273: jpPaginacao.setLayout(new GridBagLayout());
274: jpPaginacao.addMouseListener(formListener);
275:
276: gridBagConstraints = new GridBagConstraints();
277: gridBagConstraints.gridx = 6;
278: gridBagConstraints.gridy = 0;
279: gridBagConstraints.anchor = GridBagConstraints.EAST;
280: gridBagConstraints.weightx = 1.0;
281: jpPaginacao.add(pdtPaginador, gridBagConstraints);
282:
283: gridBagConstraints = new GridBagConstraints();
284: gridBagConstraints.gridx = 0;
285: gridBagConstraints.gridy = 0;
286: gridBagConstraints.fill = GridBagConstraints.BOTH;
287: jpDados.add(jpPaginacao, gridBagConstraints);
288:
289: jspPrincipal.setBottomComponent(jpDados);
290:
291: jpPesquisa.setLayout(new GridBagLayout());
292:
293: jspNorte.setDividerLocation(430);
294: jspNorte.setDividerSize(8);
295: jspNorte.setOneTouchExpandable(true);
296: jpCampos.setLayout(new GridBagLayout());
297:
298: jpCampos.setPreferredSize(new Dimension(100, 26));
299: jpCampos.addMouseListener(formListener);
300:
301: jspNorte.setLeftComponent(jpCampos);
302:
303: jpDescricao.setLayout(new BorderLayout());
304:
305: jpDescricao.setMinimumSize(new Dimension(100, 100));
306: jspDescricao.setViewportView(jtaDescricao);
307:
308: jpDescricao.add(jspDescricao, BorderLayout.CENTER);
309:
310: jlDescricao.setHorizontalAlignment(SwingConstants.CENTER);
311: jlDescricao.setText(PainelTelaBasicaMessages.getMessages()
312: .getString("Descricao")); //$NON-NLS-1$
313: jlDescricao
314: .setDisplayedMnemonic(PainelTelaBasicaMessages
315: .getMessages().getString("DescricaoMnemonic")
316: .charAt(0));
317: jlDescricao.setRequiredField(jtaDescricao);
318: jlDescricao.setToolTipText(PainelTelaBasicaMessages
319: .getMessages().getString("DescricaoToolTip"));
320: jlDescricao.addMouseListener(formListener);
321:
322: jpDescricao.add(jlDescricao, BorderLayout.NORTH);
323:
324: jspNorte.setRightComponent(jpDescricao);
325:
326: gridBagConstraints = new GridBagConstraints();
327: gridBagConstraints.gridx = 0;
328: gridBagConstraints.gridy = 0;
329: gridBagConstraints.fill = GridBagConstraints.BOTH;
330: gridBagConstraints.weightx = 1.0;
331: gridBagConstraints.weighty = 1.0;
332: jpPesquisa.add(jspNorte, gridBagConstraints);
333:
334: gridBagConstraints = new GridBagConstraints();
335: gridBagConstraints.gridx = 1;
336: gridBagConstraints.gridy = 0;
337: gridBagConstraints.fill = GridBagConstraints.BOTH;
338: jpPesquisa.add(painelBotoes, gridBagConstraints);
339:
340: jspPrincipal.setTopComponent(jpPesquisa);
341:
342: setLayout(new BorderLayout());
343: add(jspPrincipal, BorderLayout.CENTER);
344: }
345:
346: /**
347: * Adiciona um listener ao botão de impressão
348: * @param actionListener
349: */
350: public void addPrintButtonListener(ActionListener actionListener) {
351: jbReport.addActionListener(actionListener);
352: }
353:
354: /**
355: * Remove um listener do botão de impressão
356: * @param actionListener
357: */
358: public void removePrintButtonListener(ActionListener actionListener) {
359: jbReport.removeActionListener(actionListener);
360: }
361:
362: public void setPrintButtonVisible(boolean value) {
363: jbReport.setVisible(value);
364: }
365:
366: private class FormListener implements MouseListener {
367:
368: /**
369: * @see MouseListener#mouseClicked(MouseEvent)
370: */
371: public void mouseClicked(MouseEvent e) {
372: //Sem implementação nescessária
373: }
374:
375: /**
376: * @see MouseListener#mouseEntered(MouseEvent)
377: */
378: public void mouseEntered(MouseEvent e) {
379: //Sem implementação nescessária
380: }
381:
382: /**
383: * @see MouseListener#mouseExited(MouseEvent)
384: */
385: public void mouseExited(MouseEvent e) {
386: //Sem implementação nescessária
387: }
388:
389: /**
390: * @see MouseListener#mousePressed(MouseEvent)
391: */
392: public void mousePressed(MouseEvent e) {
393: if (e.getSource() == jpPaginacao) {
394: PainelTelaBasica.this .jpPaginacaoMousePressed(e);
395: } else if (e.getSource() == jpCampos) {
396: PainelTelaBasica.this .jpCamposMousePressed(e);
397: } else if (e.getSource() == jlDescricao) {
398: PainelTelaBasica.this .jlDescricaoMousePressed(e);
399: }
400: }
401:
402: /**
403: * @see MouseListener#mouseReleased(MouseEvent)
404: */
405: public void mouseReleased(MouseEvent e) {
406: //Sem implementação nescessária
407: }
408: }
409:
410: private void jlDescricaoMousePressed(MouseEvent evt) {
411: if (evt.getClickCount() == 2) {
412: if (jlDescricao.getWidth() + jspNorte.getDividerSize() + 2 == jspNorte
413: .getWidth()) {
414: jspNorte.setDividerLocation(oldDividerLocationVertical);
415: jspPrincipal
416: .setDividerLocation(oldDividerLocationHorizontal);
417: } else {
418: oldDividerLocationVertical = jspNorte
419: .getDividerLocation();
420: jspNorte.setDividerLocation(0.0);
421: oldDividerLocationHorizontal = jspPrincipal
422: .getDividerLocation();
423: jspPrincipal.setDividerLocation(1.0);
424: }
425: }
426: }
427:
428: public void jpCamposMousePressed(MouseEvent evt) {
429: if (evt.getClickCount() == 2) {
430: if (jpCampos.getWidth() + jspNorte.getDividerSize() + 2 == jspNorte
431: .getWidth()) {
432: jspNorte.setDividerLocation(oldDividerLocationVertical);
433: jspPrincipal
434: .setDividerLocation(oldDividerLocationHorizontal);
435: } else {
436: oldDividerLocationVertical = jspNorte
437: .getDividerLocation();
438: jspNorte.setDividerLocation(1.0);
439: oldDividerLocationHorizontal = jspPrincipal
440: .getDividerLocation();
441: jspPrincipal.setDividerLocation(1.0);
442:
443: }
444: }
445: }
446:
447: private void jpPaginacaoMousePressed(MouseEvent evt) {
448: if (evt.getClickCount() == 2) {
449: if (jpDados.getHeight() + jspPrincipal.getDividerSize() + 2 == jspPrincipal
450: .getHeight()) {
451: jspPrincipal
452: .setDividerLocation(oldDividerLocationHorizontal);
453: } else {
454: oldDividerLocationHorizontal = jspPrincipal
455: .getDividerLocation();
456: jspPrincipal.setDividerLocation(0.0);
457: }
458: }
459: }
460:
461: /**
462: * @return Returns the pdtPaginador.
463: */
464: public PaginadorDeTabela getPdtPaginador() {
465: return pdtPaginador;
466: }
467:
468: /**
469: * Seta a posição o divisor da tela vertical
470: * @param location
471: */
472: public void setVerticalDividerLocation(int location) {
473: jspNorte.setDividerLocation(location);
474: }
475:
476: /**
477: * Seta posição o divisor da tela vertical por percentual
478: * @param location
479: */
480: public void setVerticalDividerLocation(double location) {
481: jspNorte.setDividerLocation(location);
482: }
483:
484: /**
485: * Seta a posição o divisor da tela horizontal
486: * @param location
487: */
488: public void setHorizontalDividerLocation(int location) {
489: jspPrincipal.setDividerLocation(location);
490: }
491:
492: /**
493: * @param args
494: * TODO Remover este método
495: */
496: public static void main(String[] args) {
497: JFrame f = new JFrame();
498: f.setSize(800, 600);
499: f.getContentPane().setLayout(new BorderLayout());
500:
501: PainelTelaBasica t = new PainelTelaBasica();
502: JTextField jtfNome = new JTextField();
503: jtfNome.setMinimumSize(new java.awt.Dimension(100, 20));
504: jtfNome.setPreferredSize(new java.awt.Dimension(100, 20));
505: GridBagConstraints gridBagConstraints = new GridBagConstraints();
506: gridBagConstraints.gridx = 1;
507: gridBagConstraints.gridy = 0;
508: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
509: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
510: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
511: t.addComponent(jtfNome, gridBagConstraints,
512: DATA_COMPONENTS_AREA);
513:
514: //t.removeComponent(jtfNome, DATA_COMPONENTS_AREA);
515:
516: f.getContentPane().add(t, BorderLayout.CENTER);
517: f.setVisible(true);
518: }
519:
520: /**
521: * Determina uma cor para o label do campo descricao
522: * @param isReq
523: */
524: public void setDescricaoRequired(boolean isReq,
525: MessageView messageView) {
526: jlDescricao.setValidationNotNull(isReq);
527: jlDescricao.setMessageView(messageView);
528: }
529:
530: /**
531: * Destaca os campo de preenchimento obrigatório
532: */
533: public void showRequiredFields() {
534: for (int i = 0; i < requiredFields.size(); i++) {
535: ((RequiredFieldLabel) requiredFields.get(i))
536: .highlight(true);
537: }
538: jlDescricao.highlight(true);
539: }
540:
541: /**
542: * Reseta o destaque os campo de preenchimento obrigatório
543: */
544: public void hideRequiredFields() {
545: for (int i = 0; i < requiredFields.size(); i++) {
546: ((RequiredFieldLabel) requiredFields.get(i))
547: .highlight(false);
548: }
549: jlDescricao.highlight(false);
550: }
551: }
|