Source Code Cross Referenced for PaginadorDeTabela.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfpshare » beans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Personal Finance Manager » br.com.gfpshare.beans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 12/07/2003
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:
027:        package br.com.gfpshare.beans;
028:
029:        import java.awt.CardLayout;
030:        import java.awt.Dimension;
031:        import java.awt.GridBagConstraints;
032:        import java.awt.GridBagLayout;
033:        import java.awt.Insets;
034:        import java.awt.Point;
035:        import java.awt.event.ActionEvent;
036:        import java.awt.event.ActionListener;
037:        import java.awt.event.ComponentEvent;
038:        import java.awt.event.ComponentListener;
039:        import java.awt.event.KeyEvent;
040:        import java.awt.event.KeyListener;
041:        import java.awt.event.MouseWheelEvent;
042:        import java.awt.event.MouseWheelListener;
043:        import java.text.NumberFormat;
044:
045:        import javax.swing.BorderFactory;
046:        import javax.swing.ImageIcon;
047:        import javax.swing.JButton;
048:        import javax.swing.JComponent;
049:        import javax.swing.JFormattedTextField;
050:        import javax.swing.JLabel;
051:        import javax.swing.JPanel;
052:        import javax.swing.JScrollPane;
053:        import javax.swing.JTable;
054:        import javax.swing.JViewport;
055:        import javax.swing.border.BevelBorder;
056:        import javax.swing.event.AncestorListener;
057:        import javax.swing.event.TableModelListener;
058:        import javax.swing.table.DefaultTableModel;
059:        import javax.swing.text.DefaultFormatterFactory;
060:        import javax.swing.text.NumberFormatter;
061:
062:        /**
063:         * Componente responsável por efetuar pagiação de JTables.
064:         * <p>
065:         * <p>
066:         * Forma de usar:
067:         * <p>
068:         * <p>
069:         * <b>1 - </b>Insira o componente no painel da aplicação.
070:         * <p>
071:         * <b>2 - </b>Insira um Scroll e insira a tabela no mesmo.
072:         * <p>
073:         * <p>
074:         * &nbsp;&nbsp;&nbsp; <b>Obs.: </b>O próprio componente desbilitará a barra de rolagem vertical em tempo de execução, &nbsp;&nbsp;&nbsp;portanto não é
075:         * nescessário realizar esta alteração no VisualAge, porém o JTable deve &nbsp;&nbsp;&nbsp;estar contido em um JScrollPane.
076:         * <p>
077:         * <p>
078:         * <b>3 - </b>Chame o método:
079:         * <p>
080:         * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>configurar(JTable)</code><br>
081:         * <br>
082:         * A chamada a este método faz com que o PaginadorDeTabela realize a paginação da tabela que foi passada. <br>
083:         * A paginação atualmente ocorre através da manipulação do componente JViewport; presente na JScrollPane, o JViewport é o componente originalmente respossável
084:         * pelo scrolling de um componente, porém usulamente seu posicionamento é controlado por um JScrollBar. O PaginadorDeTabela substitui a função JScrollBar porém
085:         * realizando o reposicionamento do JViewport em bloco, criando assim a sensação de paginação.
086:         * <p>
087:         * <p>
088:         * Existe ainda uma funcionalidade que permite exibir uma página específica da tabela, para tanto basta que o usuário esteja com o foco no JTable e preciona as
089:         * teclas Ctlr+L. <br>
090:         * <br>
091:         * Ao pressionar estas teclas a interface do PaginadorDeTabela muda do default: <br>
092:         * <br>
093:         * Texto: "Pagina X de N" com botões de avançar e retroceder <br>
094:         * <br>
095:         * para: <br>
096:         * <br>
097:         * Botão "Exibir página:" com JMaskedField para digitação da página desejada pelo usuário. <br>
098:         * <br>
099:         * Ao digitar o número da página basta usuário precionar a tecla "Enter" ou clicar no botão "Exibir Página", dessa forma o PaginadorDeTabela efetuará a
100:         * paginação para a página solicitada.
101:         * <p>
102:         * <p>
103:         * Data de criação: (21/1/2003 09:06:47)
104:         * <p>
105:         * 
106:         * @autor: Igor Regis da Silva Simoes - GECAF
107:         */
108:        public class PaginadorDeTabela extends JPanel {
109:
110:            private JLabel jlAtual = null;
111:
112:            private JLabel jlDe = null;
113:
114:            private JLabel jlPagina = null;
115:
116:            private JLabel jlTotal = null;
117:
118:            private JButton jbAvancar = null;
119:
120:            private JButton jbRetornar = null;
121:
122:            private JTable tabela = null;
123:
124:            private int quantMaxima = 0;
125:
126:            private boolean colocarFocoNaTabela = false;
127:
128:            private int linhas = 0;
129:
130:            private JPanel jpBusca = null;
131:
132:            private JPanel jpPaginacao = null;
133:
134:            private JButton jbPaginar = null;
135:
136:            private JFormattedTextField jftfPara = null;
137:
138:            private IvjEventHandler ivjEventHandler = new IvjEventHandler();
139:
140:            private KeyEventHandler kEH = new KeyEventHandler();
141:
142:            private TableListener tListener = new TableListener();
143:
144:            /**
145:             *
146:             */
147:            private class KeyEventHandler implements  ComponentListener,
148:                    KeyListener, MouseWheelListener {
149:                /**
150:                 * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
151:                 */
152:                public void keyPressed(KeyEvent e) {
153:                    if (e.getSource() == PaginadorDeTabela.this .getTabela())
154:                        tabela_KeyPressed(e);
155:                }
156:
157:                /**
158:                 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
159:                 */
160:                public void componentResized(ComponentEvent e) {
161:                    if (e.getSource() == PaginadorDeTabela.this .getTabela()
162:                            .getParent())
163:                        tabelaContainer_ComponentResized();
164:                }
165:
166:                /**
167:                 * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
168:                 */
169:                public void keyReleased(KeyEvent e) {
170:                    //Não fazemos nada neste caso
171:                }
172:
173:                /**
174:                 * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
175:                 */
176:                public void keyTyped(KeyEvent e) {
177:                    //Não fazemos nada neste caso
178:                }
179:
180:                /**
181:                 * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
182:                 */
183:                public void componentHidden(ComponentEvent e) {
184:                    //Não fazemos nada neste caso
185:                }
186:
187:                /**
188:                 * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
189:                 */
190:                public void componentMoved(ComponentEvent e) {
191:                    //Não fazemos nada neste caso
192:                }
193:
194:                /**
195:                 * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
196:                 */
197:                public void componentShown(ComponentEvent e) {
198:                    //Não fazemos nada neste caso
199:                }
200:
201:                /**
202:                 * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
203:                 */
204:                public void mouseWheelMoved(MouseWheelEvent e) {
205:                    if (e.getWheelRotation() > 0)
206:                        exibirProximaPagina();
207:                    else
208:                        exibirPaginaAnterior();
209:                }
210:            }
211:
212:            /**
213:             *
214:             */
215:            private class TableListener implements  TableModelListener,
216:                    AncestorListener {
217:
218:                /**
219:                 * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
220:                 */
221:                public void tableChanged(javax.swing.event.TableModelEvent e) {
222:                    inicializar();
223:                }
224:
225:                /**
226:                 * @see javax.swing.event.AncestorListener#ancestorAdded(javax.swing.event.AncestorEvent)
227:                 */
228:                public void ancestorAdded(javax.swing.event.AncestorEvent event) {
229:                    inicializar();
230:                }
231:
232:                /**
233:                 * @see javax.swing.event.AncestorListener#ancestorMoved(javax.swing.event.AncestorEvent)
234:                 */
235:                public void ancestorMoved(javax.swing.event.AncestorEvent event) {
236:                    //Não fazemos nada neste caso
237:                }
238:
239:                /**
240:                 * @see javax.swing.event.AncestorListener#ancestorRemoved(javax.swing.event.AncestorEvent)
241:                 */
242:                public void ancestorRemoved(
243:                        javax.swing.event.AncestorEvent event) {
244:                    //Não fazemos nada neste caso
245:                }
246:
247:            }
248:
249:            /**
250:             *
251:             */
252:            private class IvjEventHandler implements  ActionListener {
253:                /**
254:                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
255:                 */
256:                public void actionPerformed(ActionEvent e) {
257:                    if (e.getSource() == PaginadorDeTabela.this .getJbAvancar())
258:                        jbAvancar_ActionPerformed(e);
259:                    if (e.getSource() == PaginadorDeTabela.this .getJbRetornar())
260:                        jbRetornar_ActionPerformed(e);
261:                    if (e.getSource() == PaginadorDeTabela.this .getJbPaginar())
262:                        jbPaginar_ActionPerformed(e);
263:                    if (e.getSource() == PaginadorDeTabela.this .getJtfIrPara())
264:                        getJbPaginar().doClick();
265:                }
266:            }
267:
268:            /**
269:             */
270:            public PaginadorDeTabela() {
271:                super ();
272:                initialize();
273:            }
274:
275:            /**
276:             * Configura o componente com os parametros passados.
277:             * 
278:             * @param tabela JTable
279:             */
280:            public void setConfiguracao(JTable tabela) {
281:                setTabela(tabela);
282:                inicializar();
283:            }
284:
285:            /**
286:             * Retorna a tabela usada para configurar este paginador
287:             * 
288:             * @return retorna a tebela
289:             */
290:            public JComponent getConfiguracao() {
291:                return tabela;
292:            }
293:
294:            /**
295:             * Método responsavel por paginar um JTable.
296:             * 
297:             * @param pagAtual A pagina atualmente exibida pelo paginador
298:             */
299:            protected void exibirPagina(int pagAtual) {
300:                //Seta o label
301:                getJlAtual().setText("" + pagAtual); //$NON-NLS-1$
302:                getJlAtual().setToolTipText("" + pagAtual); //$NON-NLS-1$
303:
304:                //Seta a posição do JViewport para a posição da página desejada.
305:                try {
306:                    ((JViewport) getTabela().getParent())
307:                            .setViewPosition(new Point(0, getTabela()
308:                                    .getCellRect(0, 0, true).height
309:                                    * (quantMaxima) * (pagAtual - 1)));
310:                } catch (ClassCastException e) {
311:                    throw new RuntimeException(e);
312:                }
313:
314:                //Habilita/Desabilita os botões conforme o nescessário
315:                if (Integer.parseInt(getJlTotal().getText()) > pagAtual) {
316:                    getJbAvancar().setEnabled(true);
317:                } else {
318:                    getJbAvancar().setEnabled(false);
319:                }
320:                if (pagAtual > 1) {
321:                    getJbRetornar().setEnabled(true);
322:                } else {
323:                    getJbRetornar().setEnabled(false);
324:                }
325:
326:                if (isColocarFocoNaTabela()) {
327:                    if (getTabela().getRowCount() != 0)
328:                        getTabela().setRowSelectionInterval(
329:                                (quantMaxima) * (pagAtual - 1),
330:                                (quantMaxima) * (pagAtual - 1));
331:                    getTabela().requestFocus();
332:                }
333:                revalidate();
334:                repaint();
335:            }
336:
337:            /**
338:             * Método responsavel por paginar para a página anterior, uma matriz em um JTable. Data de criação: (12/8/2002 17:19:42)
339:             */
340:            protected void exibirPaginaAnterior() {
341:                int pagAtual = Integer.parseInt(getJlAtual().getText());
342:                exibirPagina(pagAtual == 1 ? pagAtual : --pagAtual);
343:            }
344:
345:            /**
346:             * Método responsavel por paginar para a página seguinte, uma matriz em um JTable. Data de criação: (12/8/2002 17:19:42)
347:             */
348:            protected void exibirProximaPagina() {
349:                int pagAtual = Integer.parseInt(getJlAtual().getText());
350:                exibirPagina(pagAtual == Integer.parseInt(getJlTotal()
351:                        .getText().trim()) ? pagAtual : ++pagAtual);
352:            }
353:
354:            /**
355:             * Retorna o valor de propriedade JButton2.
356:             * 
357:             * @return javax.swing.JButton
358:             */
359:            protected JButton getJbAvancar() {
360:                if (jbAvancar == null) {
361:                    try {
362:                        jbAvancar = new JButton();
363:                        jbAvancar.setName("JbAvancar"); //$NON-NLS-1$
364:                        jbAvancar.setText(""); //$NON-NLS-1$
365:                        jbAvancar.setMaximumSize(new Dimension(25, 25));
366:                        jbAvancar.setPreferredSize(new Dimension(25, 25));
367:                        jbAvancar.setEnabled(false);
368:                        jbAvancar.setMinimumSize(new Dimension(25, 25));
369:                        jbAvancar.setIcon(new ImageIcon(getClass().getResource(
370:                                "/icones/16x16/forward.png"))); //$NON-NLS-1$
371:                        jbAvancar.setToolTipText(PaginadorDeTabelaMessages
372:                                .getMessages().getString("avancarToolTip")); //$NON-NLS-1$
373:                        jbAvancar.setBorder(BorderFactory
374:                                .createBevelBorder(BevelBorder.RAISED));
375:
376:                    } catch (Throwable e) {
377:                        throw new RuntimeException(e);
378:                    }
379:                }
380:                return jbAvancar;
381:            }
382:
383:            /**
384:             * Retorna o valor de propriedade JbPaginar.
385:             * 
386:             * @return javax.swing.JButton
387:             */
388:            private JButton getJbPaginar() {
389:                if (jbPaginar == null) {
390:                    try {
391:                        jbPaginar = new JButton();
392:                        jbPaginar.setName("JbPaginar"); //$NON-NLS-1$
393:                        jbPaginar.setPreferredSize(new Dimension(100, 25));
394:                        jbPaginar.setText(PaginadorDeTabelaMessages
395:                                .getMessages().getString("abrirPagina")); //$NON-NLS-1$
396:                        jbPaginar.setMinimumSize(new Dimension(100, 25));
397:                        jbPaginar.setMaximumSize(new Dimension(100, 19));
398:                    } catch (Throwable e) {
399:                        throw new RuntimeException(e);
400:                    }
401:                }
402:                return jbPaginar;
403:            }
404:
405:            /**
406:             * Retorna o valor de propriedade JButton1.
407:             * 
408:             * @return javax.swing.JButton
409:             */
410:            protected JButton getJbRetornar() {
411:                if (jbRetornar == null) {
412:                    try {
413:                        jbRetornar = new JButton();
414:                        jbRetornar.setName("JbRetornar"); //$NON-NLS-1$
415:                        jbRetornar.setText(""); //$NON-NLS-1$
416:                        jbRetornar.setMaximumSize(new Dimension(25, 25));
417:                        jbRetornar.setPreferredSize(new Dimension(25, 25));
418:                        jbRetornar.setMinimumSize(new Dimension(25, 25));
419:                        jbRetornar.setEnabled(false);
420:                        jbRetornar.setIcon(new ImageIcon(getClass()
421:                                .getResource("/icones/16x16/back.png"))); //$NON-NLS-1$
422:                        jbRetornar.setToolTipText(PaginadorDeTabelaMessages
423:                                .getMessages().getString("voltarPagina")); //$NON-NLS-1$
424:                        jbRetornar.setBorder(BorderFactory
425:                                .createBevelBorder(BevelBorder.RAISED));
426:                    } catch (Throwable e) {
427:                        throw new RuntimeException(e);
428:                    }
429:                }
430:                return jbRetornar;
431:            }
432:
433:            /**
434:             * Retorna o valor de propriedade JlAtual.
435:             * 
436:             * @return javax.swing.JLabel
437:             */
438:            protected JLabel getJlAtual() {
439:                if (jlAtual == null) {
440:                    try {
441:                        jlAtual = new JLabel();
442:                        jlAtual.setName("JlAtual"); //$NON-NLS-1$
443:                        jlAtual.setText("0"); //$NON-NLS-1$
444:                        jlAtual.setMaximumSize(new Dimension(25, 15));
445:                        jlAtual.setMinimumSize(new Dimension(25, 15));
446:                    } catch (Throwable e) {
447:                        throw new RuntimeException(e);
448:                    }
449:                }
450:                return jlAtual;
451:            }
452:
453:            /**
454:             * Retorna o valor de propriedade JlDe.
455:             * 
456:             * @return javax.swing.JLabel
457:             */
458:            private JLabel getJlDe() {
459:                if (jlDe == null) {
460:                    try {
461:                        jlDe = new JLabel();
462:                        jlDe.setName("JlDe"); //$NON-NLS-1$
463:                        jlDe.setText(PaginadorDeTabelaMessages.getMessages()
464:                                .getString("de")); //$NON-NLS-1$
465:                    } catch (Throwable e) {
466:                        throw new RuntimeException(e);
467:                    }
468:                }
469:                return jlDe;
470:            }
471:
472:            /**
473:             * Retorna o valor de propriedade JlPagina.
474:             * 
475:             * @return javax.swing.JLabel
476:             */
477:            private JLabel getJlPagina() {
478:                if (jlPagina == null) {
479:                    try {
480:                        jlPagina = new JLabel();
481:                        jlPagina.setName("JlPagina"); //$NON-NLS-1$
482:                        jlPagina.setText(PaginadorDeTabelaMessages
483:                                .getMessages().getString("Pagina")); //$NON-NLS-1$
484:                        jlPagina.setMinimumSize(new Dimension(50, 15));
485:                    } catch (Throwable e) {
486:                        throw new RuntimeException(e);
487:                    }
488:                }
489:                return jlPagina;
490:            }
491:
492:            /**
493:             * Retorna o valor de propriedade JlTotal.
494:             * 
495:             * @return javax.swing.JLabel
496:             */
497:            protected JLabel getJlTotal() {
498:                if (jlTotal == null) {
499:                    try {
500:                        jlTotal = new JLabel();
501:                        jlTotal.setName("JlTotal"); //$NON-NLS-1$
502:                        jlTotal.setText("0"); //$NON-NLS-1$
503:                        jlTotal.setMinimumSize(new Dimension(25, 15));
504:                    } catch (Throwable e) {
505:                        throw new RuntimeException(e);
506:                    }
507:                }
508:                return jlTotal;
509:            }
510:
511:            /**
512:             * Retorna o valor de propriedade JPanel2.
513:             * 
514:             * @return javax.swing.JPanel
515:             */
516:            private JPanel getJpBusca() {
517:                if (jpBusca == null) {
518:                    try {
519:                        jpBusca = new JPanel();
520:                        jpBusca.setName("JpBusca"); //$NON-NLS-1$
521:                        jpBusca.setOpaque(false);
522:                        jpBusca.setLayout(new GridBagLayout());
523:
524:                        GridBagConstraints constraintsJtfIrPara = new GridBagConstraints();
525:                        constraintsJtfIrPara.gridx = 1;
526:                        constraintsJtfIrPara.gridy = 0;
527:                        constraintsJtfIrPara.insets = new Insets(4, 0, 4, 0);
528:                        constraintsJtfIrPara.fill = GridBagConstraints.HORIZONTAL;
529:                        constraintsJtfIrPara.weightx = 0.6;
530:                        getJpBusca().add(getJtfIrPara(), constraintsJtfIrPara);
531:
532:                        GridBagConstraints constraintsJbPaginar = new GridBagConstraints();
533:                        constraintsJbPaginar.gridx = 0;
534:                        constraintsJbPaginar.gridy = 0;
535:                        constraintsJbPaginar.insets = new Insets(4, 0, 4, 4);
536:                        constraintsJbPaginar.fill = GridBagConstraints.HORIZONTAL;
537:                        constraintsJbPaginar.weightx = 0.4;
538:                        getJpBusca().add(getJbPaginar(), constraintsJbPaginar);
539:                    } catch (Throwable e) {
540:                        throw new RuntimeException(e);
541:                    }
542:                }
543:                return jpBusca;
544:            }
545:
546:            /**
547:             * Retorna o valor de propriedade JPanel1.
548:             * 
549:             * @return javax.swing.JPanel
550:             */
551:            private JPanel getJpPaginacao() {
552:                if (jpPaginacao == null) {
553:                    try {
554:                        jpPaginacao = new JPanel();
555:                        jpPaginacao.setName("JpPaginacao"); //$NON-NLS-1$
556:                        jpPaginacao.setOpaque(false);
557:                        jpPaginacao.setLayout(new GridBagLayout());
558:                        jpPaginacao.setPreferredSize(new Dimension(200, 28));
559:                        jpPaginacao.setMinimumSize(new Dimension(200, 28));
560:
561:                        GridBagConstraints constraintsJlPagina = new GridBagConstraints();
562:                        constraintsJlPagina.gridx = -1;
563:                        constraintsJlPagina.gridy = -1;
564:                        constraintsJlPagina.insets = new Insets(4, 0, 4, 0);
565:                        getJpPaginacao()
566:                                .add(getJlPagina(), constraintsJlPagina);
567:
568:                        GridBagConstraints constraintsJlAtual = new GridBagConstraints();
569:                        constraintsJlAtual.gridx = -1;
570:                        constraintsJlAtual.gridy = -1;
571:                        constraintsJlAtual.fill = GridBagConstraints.HORIZONTAL;
572:                        constraintsJlAtual.insets = new Insets(4, 4, 4, 0);
573:                        getJpPaginacao().add(getJlAtual(), constraintsJlAtual);
574:
575:                        GridBagConstraints constraintsJlDe = new GridBagConstraints();
576:                        constraintsJlDe.gridx = -1;
577:                        constraintsJlDe.gridy = -1;
578:                        constraintsJlDe.insets = new Insets(4, 0, 4, 0);
579:                        getJpPaginacao().add(getJlDe(), constraintsJlDe);
580:
581:                        GridBagConstraints constraintsJlTotal = new GridBagConstraints();
582:                        constraintsJlTotal.gridx = -1;
583:                        constraintsJlTotal.gridy = -1;
584:                        constraintsJlTotal.insets = new Insets(4, 1, 4, 4);
585:                        getJpPaginacao().add(getJlTotal(), constraintsJlTotal);
586:
587:                        GridBagConstraints constraintsJbRetornar = new GridBagConstraints();
588:                        constraintsJbRetornar.gridx = -1;
589:                        constraintsJbRetornar.gridy = -1;
590:                        constraintsJbRetornar.insets = new Insets(4, 4, 4, 0);
591:                        getJpPaginacao().add(getJbRetornar(),
592:                                constraintsJbRetornar);
593:
594:                        GridBagConstraints constraintsJbAvancar = new GridBagConstraints();
595:                        constraintsJbAvancar.gridx = -1;
596:                        constraintsJbAvancar.gridy = -1;
597:                        constraintsJbAvancar.insets = new Insets(4, 0, 4, 0);
598:                        getJpPaginacao().add(getJbAvancar(),
599:                                constraintsJbAvancar);
600:                    } catch (Throwable e) {
601:                        throw new RuntimeException(e);
602:                    }
603:                }
604:                return jpPaginacao;
605:            }
606:
607:            /**
608:             * Retorna o valor de propriedade JtfIrPara.
609:             * 
610:             * @return javax.swing.JFormattedTextField
611:             */
612:            private JFormattedTextField getJtfIrPara() {
613:                if (jftfPara == null) {
614:                    try {
615:                        jftfPara = new JFormattedTextField();
616:                        jftfPara.setName("JtfIrPara"); //$NON-NLS-1$
617:                        jftfPara
618:                                .setFormatterFactory(new DefaultFormatterFactory(
619:                                        new NumberFormatter(NumberFormat
620:                                                .getIntegerInstance())));
621:                        jftfPara.setPreferredSize(new Dimension(35, 20));
622:                        jftfPara.setMinimumSize(new Dimension(20, 19));
623:                        jftfPara.setMaximumSize(new Dimension(20, 19));
624:                    } catch (Throwable e) {
625:                        throw new RuntimeException(e);
626:                    }
627:                }
628:                return jftfPara;
629:            }
630:
631:            /**
632:             * Retorna o número de registros contidos no JTable Data de criação: (30/5/2003 10:07:30)
633:             * 
634:             * @return Número de registros do JTable
635:             */
636:            public int getLinhas() {
637:                return linhas;
638:            }
639:
640:            /**
641:             * Data de criação: (21/1/2003 09:45:01)
642:             * 
643:             * @return javax.swing.JTable
644:             */
645:            private JTable getTabela() {
646:                return tabela;
647:            }
648:
649:            /**
650:             * Realiza operações de inicialização do componente. Este método também é chamado quando a tela é redimencionada. Data de criação: (21/1/2003 15:59:18)
651:             */
652:            public void inicializar() {
653:                if (getTabela() == null)
654:                    return;
655:
656:                if (getTabela().getRowHeight() <= 0)
657:                    return;
658:
659:                setLinhas(tabela.getRowCount());
660:
661:                //Determina a quantidade máxima de linhas suportadas pela tabela.
662:                quantMaxima = (getTabela().getParent().getSize().height / getTabela()
663:                        .getRowHeight());
664:
665:                quantMaxima = quantMaxima < 1 ? 1 : quantMaxima;
666:
667:                //Se estiver sendo exibido mais de 66% da última linha, será contado mais uma linha na quantidade máxima que pode ser exibida
668:                if (getTabela().getParent().getSize().height - quantMaxima
669:                        * getTabela().getCellRect(0, 0, true).height > getTabela()
670:                        .getCellRect(0, 0, true).height * 0.66)
671:                    quantMaxima++;
672:
673:                //A quantidade de páginas que podem ser exibidas é determinada pelo total de registros (getLinhas()) dividido pelo total que pode ser
674:                //exibido em cada página.
675:                int paginas = (getLinhas() % quantMaxima > 0 ? getLinhas()
676:                        / quantMaxima + 1 : getLinhas() / quantMaxima);
677:
678:                //Ajusta o tamanho do JTable, caso necessário, para que possa ser exibida a última página com um número menor de registros do que é normalmente
679:                // exibido.
680:                getTabela().setSize(
681:                        new Dimension(getTabela().getWidth(), quantMaxima
682:                                * getTabela().getCellRect(0, 0, true).height
683:                                * paginas));
684:                getTabela().setMinimumSize(
685:                        new Dimension(getTabela().getWidth(), quantMaxima
686:                                * getTabela().getCellRect(0, 0, true).height
687:                                * paginas));
688:                getTabela().setPreferredSize(
689:                        new Dimension(getTabela().getWidth(), quantMaxima
690:                                * getTabela().getCellRect(0, 0, true).height
691:                                * paginas));
692:
693:                getJlTotal().setText("" + paginas); //$NON-NLS-1$
694:                getJlTotal().setToolTipText("" + paginas); //$NON-NLS-1$
695:
696:                int pagAtual = Integer.parseInt(getJlAtual().getText());
697:                if (pagAtual > 1 && pagAtual <= paginas) {
698:                    exibirPagina(Integer.parseInt(getJlAtual().getText()));
699:                } else {
700:                    getJlAtual().setText("1"); //$NON-NLS-1$
701:                    getJlAtual().setToolTipText("1"); //$NON-NLS-1$
702:                    exibirPagina(1);
703:                }
704:
705:                if (getLinhas() > quantMaxima)
706:                    getJbAvancar().setEnabled(true);
707:                else
708:                    getJbAvancar().setEnabled(false);
709:
710:            }
711:
712:            /**
713:             * Inicializa conexões
714:             * 
715:             * @exception java.lang.Exception A descrição da exceção.
716:             */
717:            private void initConnections() throws java.lang.Exception {
718:
719:                getJbAvancar().addActionListener(ivjEventHandler);
720:                getJbRetornar().addActionListener(ivjEventHandler);
721:                getJbPaginar().addActionListener(ivjEventHandler);
722:                getJtfIrPara().addActionListener(ivjEventHandler);
723:            }
724:
725:            /**
726:             * Inicializa a classe.
727:             */
728:            private void initialize() {
729:                try {
730:                    setName("PaginadorDeTabela"); //$NON-NLS-1$
731:                    setOpaque(false);
732:                    setPreferredSize(new Dimension(200, 28));
733:                    setLayout(new CardLayout());
734:                    setSize(200, 32);
735:                    setMinimumSize(new Dimension(200, 28));
736:                    add(getJpPaginacao(), getJpPaginacao().getName());
737:                    add(getJpBusca(), getJpBusca().getName());
738:                    initConnections();
739:                } catch (Throwable e) {
740:                    throw new RuntimeException(e);
741:                }
742:            }
743:
744:            /**
745:             * Data de criação: (24/3/2003 10:44:51)
746:             * 
747:             * @return boolean
748:             */
749:            public boolean isColocarFocoNaTabela() {
750:                return colocarFocoNaTabela;
751:            }
752:
753:            private void jbAvancar_ActionPerformed(ActionEvent actionEvent) {
754:                exibirProximaPagina();
755:            }
756:
757:            private void jbPaginar_ActionPerformed(ActionEvent actionEvent) {
758:                if (((Long) getJtfIrPara().getValue()).intValue() <= Integer
759:                        .parseInt(getJlTotal().getText().trim())
760:                        && ((Long) getJtfIrPara().getValue()).intValue() > 0) {
761:                    exibirPagina(((Long) getJtfIrPara().getValue()).intValue());
762:                    ((CardLayout) getLayout()).show(this , getJpPaginacao()
763:                            .getName());
764:                    getJtfIrPara().setText(""); //$NON-NLS-1$
765:                } else {
766:                    getJtfIrPara().setText(""); //$NON-NLS-1$
767:                }
768:            }
769:
770:            private void jbRetornar_ActionPerformed(ActionEvent actionEvent) {
771:                exibirPaginaAnterior();
772:            }
773:
774:            /**
775:             * Data de criação: (18/3/2003 14:39:43)
776:             */
777:            public void limparDados() {
778:                if (getTabela() != null)
779:                    if (getTabela().getModel() instanceof  DefaultTableModel)
780:                        getTabela().setModel(new DefaultTableModel());
781:                if (getJlAtual() != null)
782:                    getJlAtual().setText("0"); //$NON-NLS-1$
783:                if (getJlTotal() != null)
784:                    getJlTotal().setText("0"); //$NON-NLS-1$
785:
786:            }
787:
788:            /**
789:             * Data de criação: (24/3/2003 10:44:51)
790:             * 
791:             * @param newColocarFocoNaTabela boolean
792:             */
793:            public void setColocarFocoNaTabela(boolean newColocarFocoNaTabela) {
794:                colocarFocoNaTabela = newColocarFocoNaTabela;
795:            }
796:
797:            /**
798:             * Retorna as linas Data de criação: (30/5/2003 10:07:30)
799:             * 
800:             * @param newLinhas int
801:             */
802:            private void setLinhas(int newLinhas) {
803:                linhas = newLinhas;
804:            }
805:
806:            /**
807:             * Seta a tabela que será paginada
808:             * 
809:             * @param newTabela Tabela que será pagiada
810:             * @throws IllegalArgumentException Será lançada em caso de o JTable passado não estiver contido em um JScrollPane
811:             */
812:            private void setTabela(JTable newTabela)
813:                    throws IllegalArgumentException {
814:                /*
815:                 * Tenta retirar a barra de rolagem vertical e horizontal. Esta instrução so funcioara se o JTable estiver inserido em um JScrollPane. Caso contrário
816:                 * será lançada uma axceção que não precisa nescessáriamente ser tratada.
817:                 */
818:                try {
819:                    ((JScrollPane) newTabela.getParent().getParent())
820:                            .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
821:                } catch (ClassCastException cce) {
822:                    throw new IllegalArgumentException(
823:                            "O JTable não está contido em um JScrollPane ou classe derivada"); //$NON-NLS-1$
824:                } catch (Exception e) {
825:                    throw new RuntimeException(e);
826:                }
827:
828:                //Inicializa a propriedade e seta os listeners de:
829:                tabela = newTabela;
830:                getTabela().addKeyListener(kEH); //Tecla de atalho;
831:                getTabela().addMouseWheelListener(kEH);
832:                getTabela().getModel().addTableModelListener(tListener);
833:                getTabela().addAncestorListener(tListener);
834:                getTabela().getParent().addComponentListener(kEH); //Resize da tela.
835:            }
836:
837:            /**
838:             * Metodo que trtata os eventos de teclado sobre o JTable que está sendo paginado.
839:             * 
840:             * @param keyEvent Evento de teclado gerado.
841:             */
842:            protected void tabela_KeyPressed(KeyEvent keyEvent) {
843:                if (keyEvent.getKeyCode() == KeyEvent.VK_DOWN) {
844:                    int pagAtual = Integer.parseInt(getJlAtual().getText());
845:                    if (getTabela().getSelectedRow() >= (quantMaxima)
846:                            * (pagAtual) - 1)
847:                        exibirProximaPagina();
848:                }
849:                if (keyEvent.getKeyCode() == KeyEvent.VK_PAGE_DOWN
850:                        || (keyEvent.getKeyCode() == KeyEvent.VK_RIGHT & keyEvent
851:                                .isAltDown())) {
852:                    exibirProximaPagina();
853:                }
854:                if (keyEvent.getKeyCode() == KeyEvent.VK_UP) {
855:                    int pagAtual = Integer.parseInt(getJlAtual().getText());
856:                    if (getTabela().getSelectedRow() <= (quantMaxima)
857:                            * (pagAtual - 1))
858:                        exibirPaginaAnterior();
859:                }
860:                if (keyEvent.getKeyCode() == KeyEvent.VK_PAGE_UP
861:                        || (keyEvent.getKeyCode() == KeyEvent.VK_LEFT & keyEvent
862:                                .isAltDown())) {
863:                    exibirPaginaAnterior();
864:                }
865:                if (keyEvent.getKeyCode() == KeyEvent.VK_L
866:                        && keyEvent.isControlDown()) {
867:                    ((CardLayout) getLayout()).show(this , getJpBusca()
868:                            .getName());
869:                    getJtfIrPara().requestFocus();
870:                }
871:            }
872:
873:            /**
874:             * Data de criação: (21/1/2003 17:09:47)
875:             */
876:            private void tabelaContainer_ComponentResized() {
877:                inicializar();
878:            }
879:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.