001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.table;
006:
007: import java.awt.*;
008: import java.awt.event.*;
009: import java.util.*;
010: import java.io.*;
011:
012: import javax.swing.table.*;
013: import com.javelin.swinglets.*;
014: import com.javelin.swinglets.table.*;
015: import com.javelin.swinglets.plaf.*;
016:
017: /**
018: * PagedTableFooter defines a table footer that can page.
019: * <p>
020: *
021: * @author Dino Fancellu
022: */
023:
024: public class PagedTableFooter extends STableFooter implements
025: ActionListener {
026:
027: /**
028: * Creates a PagedTableFooter.
029: * This defaults to invisible.
030: */
031: public PagedTableFooter(STable table) {
032: super (table);
033:
034: setTableFooterRenderer(
035: "com.javelin.swinglets.plaf.html.HTMLLookAndFeel",
036: new com.javelin.swinglets.plaf.html.HTMLPagedTableFooterRenderer());
037:
038: setTableFooterRenderer(
039: "com.javelin.swinglets.plaf.javascript.JSLookAndFeel",
040: new com.javelin.swinglets.plaf.html.HTMLPagedTableFooterRenderer());
041:
042: addActionListener(this );
043: }
044:
045: protected String labels[] = { "BEGINNING", "PREV", "NEXT", "END" };
046: //protected String labels[]={"BEGINNING","PREV","NEXT"};//,"END"};
047: protected String commands[] = { "B", "P", "N", "E" };
048:
049: public int getLabelCount() {
050: return labels.length + 1;
051: }
052:
053: public String getLabel(int x) {
054: if (x == 4) {
055: PagedTableModel mod = (PagedTableModel) getTable()
056: .getModel();
057: int page = ((mod.getOffset() / mod.getPageSize()) + 1);
058: int totalPages = ((mod.getModel().getRowCount() / mod
059: .getPageSize()) + 1);
060:
061: return "Page " + page + "/" + totalPages;
062: } else {
063: return labels[x];
064: }
065: }
066:
067: public String getCommand(int x) {
068: if (x == 4) {
069: return null;
070: } else
071: return commands[x];
072: }
073:
074: /**
075: * Process an ActionEvent, and sort the appropriate column.
076: */
077: public void actionPerformed(ActionEvent event) {
078: TableModel oldmodel = getTable().getModel();
079: if (oldmodel == null)
080: return;
081:
082: if (!(oldmodel instanceof PagedTableModel)) {
083: // this will happen only once, as after this it is a PagedTableModel
084: getTable().setModel(new PagedTableModel(oldmodel));
085: }
086:
087: if (getTable().getModel() instanceof PagedTableModel) {
088: PagedTableModel mod = (PagedTableModel) getTable()
089: .getModel();
090: String command = event.getActionCommand();
091:
092: if ("B".equals(command)) {
093: mod.gotoStart();
094: } else if ("P".equals(command)) {
095: mod.gotoPrev();
096: } else if ("N".equals(command)) {
097: mod.gotoNext();
098: } else if ("E".equals(command)) {
099: mod.gotoEnd();
100: }
101: }
102:
103: //System.out.println( event );
104: }
105:
106: // PRIVATE //////////////////////////////////////////////////////////////
107:
108: }
|