⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpagebar.java

📁 Document will be uploaded soon
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.component.pagination;

/**
 *
 * TODO Error on clicking < sometime, not able reproduce.
 *
 * Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.Vector.get(Unknown Source)
	at com.component.pagination.JPageBar$PageBarModel.previousIndices(JPageBar.java:260)
	at com.component.pagination.JPageBar.actionPerformed(JPageBar.java:205)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at org.jdesktop.swingx.JXHyperlink.fireActionPerformed(JXHyperlink.java:227)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

 */

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JFrame;

import org.jdesktop.swingx.JXPanel;

import com.component.Cab2bHyperlink;

/**
 * A panel to display navigation hyperlinks like next page, prevoius page
 * to move sequentially from current page to next and previous pages
 * respectively, and page indices hyperlinks for random access of pages.
 * 
 * If number of page indices to display is large, there will be hyperlinks to 
 * access next and previous set of page indices.
 * 
 * Sub page bar should come here for 2-level pagination.
 * 
 * Note : Numeric Pager will never sub page bar.
 * 
 * Getting all main page indices at once is fine,
 * but for getting sub page indices for a given main page index should happen
 * for each click on that main page index. 
 * 
 * @author chetan_bh
 */
public class JPageBar extends JXPanel implements ActionListener{
	
	@Deprecated
	JComboBox paginationTypeCombo;
	
	@Deprecated
	JComboBox elementsPerPageCombo;
	
	
	JXPanel indicesPanel;
	
	JXPanel subIndicesPanel;
	
	/**
	 * A model for page bar. To handle page indices
	 */
	PageBarModel pageBarModel;
	
	/**
	 * TODO Not functional yet.
	 * A model for second level page bar.
	 */
	PageBarModel subPageBaraModel;
	
	/**
	 * A vector of all page indices.
	 */
	Vector indices;
	
	/**
	 * A vector of all sub page indices.
	 */
	Vector subIndices;
	
	/**
	 * A subset of page indices which is currently displayed in the page bar. 
	 */
	Vector currentIndices;
	
	Vector currentSubIndices;
	
	/**
	 * Reference to parent Pagination panel.
	 */
	JPagination pagination;
	
	/**
	 * Reference to the current pagination model.
	 */
	PaginationModel paginationModel;
	
	String nextPageText = PaginationConstants.DEFAULT_PAGE_NEXT_STRING;
	
	String previousPageText = PaginationConstants.DEFAULT_PAGE_PREVIOUS_STRING;
	
	String nextPageIndicesText = PaginationConstants.DEFAULT_PAGE_INDICES_NEXT_STRING;
	
	String previousInidicesText = PaginationConstants.DEFAULT_PAGE_INDICES_PREVIOUS_STRING;
	
	public JPageBar(Vector indices, Vector subIndices, JPagination pagination)
	{
		this(indices, subIndices, pagination, new String[] { PaginationConstants.DEFAULT_PAGE_INDICES_PREVIOUS_STRING, 
															 PaginationConstants.DEFAULT_PAGE_PREVIOUS_STRING,
															 PaginationConstants.DEFAULT_PAGE_NEXT_STRING,
															 PaginationConstants.DEFAULT_PAGE_INDICES_NEXT_STRING
			  });
	}
	
	public JPageBar(Vector indices, Vector subIndices, JPagination pagination, String[] navigationLinksText)
	{	
		if(navigationLinksText != null && navigationLinksText.length == 4)
		{
			if(navigationLinksText[0] != null && !(navigationLinksText[0].trim().equals("")))
				previousInidicesText = navigationLinksText[0];
			if(navigationLinksText[1] != null && !(navigationLinksText[1].trim().equals("")))
				previousPageText = navigationLinksText[1];
			if(navigationLinksText[2] != null && !(navigationLinksText[2].trim().equals("")))
				nextPageText = navigationLinksText[2];
			if(navigationLinksText[3] != null && !(navigationLinksText[3].trim().equals("")))
				nextPageIndicesText = navigationLinksText[3];
		}
		
		this.indices = indices;
		this.subIndices = subIndices;
		
		this.pagination = pagination;
		this.paginationModel = pagination.getPaginationModel();
		
		pageBarModel = new PageBarModel(indices);
		subPageBaraModel = new PageBarModel(subIndices);
		
		//currentIndices = pageBarModel.nextIndices();
		
		//System.out.println("indices "+indices);
		// TODO how to dynamically update this list of plugged in pagers.
		paginationTypeCombo = new JComboBox(new Object[] {"Numeric","Alphabetic","Frequency","Keyword"});
		elementsPerPageCombo = new JComboBox(new Object[] {"5","10","15","20"});
		intiGUI();
	}
	
	/**
	 * Initialize the page bar GUI.
	 *
	 */
	private void intiGUI()
	{
		setLayout(new RiverLayout());
		//setPreferredSize(new Dimension(200,50));
		//this.add(indicesLabel);
		currentIndices = pageBarModel.nextIndices();
		indicesPanel = getIndicesPanel(currentIndices);
		//this.add(paginationTypeCombo);  // TODO needed later
		//this.add(elementsPerPage);      // TODO needed as and when required.
		
		currentSubIndices = subPageBaraModel.nextIndices();
		try{
			throw new Exception();
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		System.out.println("currentSubIndices <<>> "+currentSubIndices);
		subIndicesPanel = getSubIndicesPanel(currentSubIndices);
		this.add("",subIndicesPanel);
		this.add("br",indicesPanel);

	}
	
	private JXPanel getSubIndicesPanel(Vector subIndices)
	{
		subIndices.add(0, previousInidicesText);
		subIndices.add(1, previousPageText);
		
		subIndices.add(nextPageText);
		subIndices.add(nextPageIndicesText);
		
		JXPanel subIndicesPanel = new JXPanel();
		subIndicesPanel.setLayout(new FlowLayout());
		Iterator iter = subIndices.iterator();
		//indicesPanel.add()
		while(iter.hasNext())
		{
			String index = (String) iter.next();
			//JXHyperlink hyperlink = new JXHyperlink();
			Cab2bHyperlink hyperlink = new Cab2bHyperlink();
			hyperlink.setText(index);
			hyperlink.addActionListener(this);
			subIndicesPanel.add(hyperlink);
		}
		
		subIndices.removeElement(previousInidicesText);
		subIndices.removeElement(previousPageText);
		subIndices.removeElement(nextPageText);
		subIndices.removeElement(nextPageIndicesText);
		
		return subIndicesPanel;
	}
	
	public void setSubPageIndices(Vector allSubPageIndices)
	{
		if(allSubPageIndices != null && allSubPageIndices.size() > 0)
		{
			
		}
	}
	
	/**
	 * By Default this function adds Next, Forward > >>
	 * and previous, Bacward < << links to the given indices.
	 * @param indices
	 * @return
	 */
	private JXPanel getIndicesPanel(Vector indices)
	{
		indices.add(0, previousInidicesText);
		indices.add(1, previousPageText);
		
		indices.add(nextPageText);
		indices.add(nextPageIndicesText);
		
		JXPanel indicesPanel = new JXPanel();
		indicesPanel.setLayout(new FlowLayout());
		Iterator iter = indices.iterator();
		//indicesPanel.add()
		while(iter.hasNext())

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -