PagedTableFooter.java :  » Swing-Library » Swinglets » com » javelin » swinglets » table » Java Open Source

Java Open Source » Swing Library » Swinglets 
Swinglets » com » javelin » swinglets » table » PagedTableFooter.java
/*
 * Copyright Javelin Software, All rights reserved.
 */
 
package com.javelin.swinglets.table;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

import javax.swing.table.*;
import com.javelin.swinglets.*;
import com.javelin.swinglets.table.*;
import com.javelin.swinglets.plaf.*;

/**
 * PagedTableFooter defines a table footer that can page. 
 * <p>
 * 
 * @author Dino Fancellu
 */
 
public class PagedTableFooter extends STableFooter implements ActionListener
{
    
   /**
    * Creates a PagedTableFooter. 
    * This defaults to invisible.
    */
    public PagedTableFooter( STable table ) 
    {
        super( table );
        
        setTableFooterRenderer( "com.javelin.swinglets.plaf.html.HTMLLookAndFeel", 
            new com.javelin.swinglets.plaf.html.HTMLPagedTableFooterRenderer() );
            
        setTableFooterRenderer( "com.javelin.swinglets.plaf.javascript.JSLookAndFeel", 
            new com.javelin.swinglets.plaf.html.HTMLPagedTableFooterRenderer() );
            
        addActionListener( this );
    }
    
    protected String labels[]={"BEGINNING","PREV","NEXT","END"};
    //protected String labels[]={"BEGINNING","PREV","NEXT"};//,"END"};
    protected String commands[]={"B","P","N","E"};
        
    public int getLabelCount()
    {
        return labels.length+1;   
    }
        
    public String getLabel(int x)
    {
        if (x==4)
        {
            PagedTableModel mod=(PagedTableModel)getTable().getModel();
            int page=((mod.getOffset()/mod.getPageSize())+1);
            int totalPages=((mod.getModel().getRowCount()/mod.getPageSize())+1);
              
            return "Page "+page+"/"+totalPages;
        }
        else
        {
            return labels[x];   
        }
    }
    
    public String getCommand(int x)
    {
        if (x==4)
        {
            return null;  
        }
        else
            return commands[x];
    }
    
   /** 
    * Process an ActionEvent, and sort the appropriate column.
    */
    public void actionPerformed( ActionEvent event )
    {
        TableModel oldmodel=getTable().getModel();
        if( oldmodel == null ) return;
        
        if( !( oldmodel instanceof PagedTableModel ))
        {
            // this will happen only once, as after this it is a PagedTableModel
            getTable().setModel( new PagedTableModel( oldmodel ) );
        }
        
        if (getTable().getModel() instanceof PagedTableModel)
        {
            PagedTableModel mod=(PagedTableModel)getTable().getModel();   
            String command=event.getActionCommand();
             
            if ("B".equals(command))
            {
                mod.gotoStart();  
            }
            else if ("P".equals(command))
            {
                mod.gotoPrev();  
            }
            else if ("N".equals(command))
            {
                mod.gotoNext();  
            }
            else if ("E".equals(command))
            {
                mod.gotoEnd();  
            }
        }
        
        //System.out.println( event );
    }
    
    // PRIVATE //////////////////////////////////////////////////////////////
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.