📄 jpagebar.java
字号:
{
String index = (String) iter.next();
//JXHyperlink hyperlink = new JXHyperlink();
Cab2bHyperlink hyperlink = new Cab2bHyperlink();
hyperlink.setText(index);
hyperlink.addActionListener(this);
indicesPanel.add(hyperlink);
}
indices.removeElement(previousInidicesText);
indices.removeElement(previousPageText);
indices.removeElement(nextPageText);
indices.removeElement(nextPageIndicesText);
//System.out.println("getIndicesPanel() : indices : "+indices);
return indicesPanel;
}
protected void changeIndicesPanel(JXPanel newIndicesPanel)
{
this.remove(indicesPanel);
indicesPanel = newIndicesPanel;
this.add(indicesPanel);
this.updateUI();
}
/**
* @param args
*/
public static void main(String[] args) {
Vector subIndices = new Vector();
subIndices.add("1");
subIndices.add("2");
subIndices.add("3");
subIndices.add("4");
subIndices.add("5");
subIndices.add("6");
subIndices.add("7");
subIndices.add("8");
subIndices.add("9");
subIndices.add("10");
subIndices.add("12");
Vector<PageElement> elements = new Vector<PageElement>();
String alphabets = "AbCDEfGHHJAsHHhhHHHdGEWYVCBZXhSHhhasHqwHhHH";
for(int i = 0; i < alphabets.length(); i++)
{
PageElement element = new PageElementImpl();
element.setDisplayName(alphabets.charAt(i)+"-123");
elements.add(element);
}
// for(int i = 0; i < 52; i++)
// {
// PageElement element = new PageElementImpl();
// element.setDisplayName("ABC-"+i);
// elements.add(element);
// }
//NumericPager pager = new NumericPager( elements );
AlphabeticPager pager = new AlphabeticPager(elements);
//PaginationModel pageModel = new PaginationModel(elements, pager);
Vector allIndices = pager.getAllPageIndices();
JPagination pagi = new JPagination(elements, pager);
JPageBar pageBar = new JPageBar(allIndices, subIndices, pagi);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(400,70));
frame.getContentPane().add(pageBar);
frame.setVisible(true);
}
/**
* This should be the action listener for both main pageBar hyperlinks,
* and sub PageBar hyperlink.
*/
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if(obj instanceof Cab2bHyperlink)
{
Cab2bHyperlink hyperlink = (Cab2bHyperlink) obj;
//hyperlink.setClickedColor(Color.RED);
String index = hyperlink.getText();
//System.out.println("index selected "+index);
String currPageIndex = "";
if(index.equals(nextPageIndicesText))
{
if(pageBarModel.hasNextIndices())
{
currentIndices = pageBarModel.nextIndices();
//System.out.println("indices actionPerformed >>>> "+indices);
JXPanel newIndicesPanel = getIndicesPanel(currentIndices);
changeIndicesPanel(newIndicesPanel);
String firstPageIndex = (String)currentIndices.get(0);
Vector<PageElement> firstPage = paginationModel.getPage(firstPageIndex);
JXPanel newPagePanel = pagination.getPagePanel(firstPage);
pagination.changePagePanel(newPagePanel);
currPageIndex = firstPageIndex;
}
}else if(index.equals(previousInidicesText))
{
if(pageBarModel.hasPreviousIndices())
{
currentIndices = pageBarModel.previousIndices();
//System.out.println("indices actionPerformed <<<< "+indices);
JXPanel newIndicesPanel = getIndicesPanel(currentIndices);
changeIndicesPanel(newIndicesPanel);
String firstPageIndex = (String)currentIndices.get(0);
Vector<PageElement> firstPage = paginationModel.getPage(firstPageIndex);
JXPanel newPagePanel = pagination.getPagePanel(firstPage);
pagination.changePagePanel(newPagePanel);
currPageIndex = firstPageIndex;
}
}else
{
if(index.equals(nextPageText))
{
if(paginationModel.hasNextPage())
{
Vector nextPage = paginationModel.nextPage();
JXPanel newPagePanel = pagination.getPagePanel(nextPage);
pagination.changePagePanel(newPagePanel);
currPageIndex = paginationModel.getCurrentPageIndex();
//System.out.println("current page Index > "+currPageIndex);
if(! currentIndices.contains(currPageIndex))
{
currentIndices = pageBarModel.nextIndices();
JXPanel newIndicesPanel = getIndicesPanel(currentIndices);
changeIndicesPanel(newIndicesPanel);
}
}
}else if(index.equals(previousPageText))
{
if(paginationModel.hasPreviousPage())
{
Vector previousPage = paginationModel.previousPage();
JXPanel newPagePanel = pagination.getPagePanel(previousPage);
pagination.changePagePanel(newPagePanel);
currPageIndex = paginationModel.getCurrentPageIndex();
//System.out.println("current page index < "+currPageIndex);
if(! currentIndices.contains(currPageIndex))
{
currentIndices = pageBarModel.previousIndices();
JXPanel newIndicesPanel = getIndicesPanel(currentIndices);
changeIndicesPanel(newIndicesPanel);
}
}
}else
{
currPageIndex = index;
Vector pageRequested = paginationModel.getPage(index);
JXPanel newPagePanel = pagination.getPagePanel(pageRequested);
pagination.changePagePanel(newPagePanel);
}
}
displayLinkColor(currPageIndex);
}
}
private void displayLinkColor(String currentPageIndex)
{
for(int i = 0; i< indicesPanel.getComponentCount(); i++)
{
Cab2bHyperlink hyperLink = (Cab2bHyperlink) indicesPanel.getComponent(i);
if(hyperLink.getText().equalsIgnoreCase(currentPageIndex))
{
hyperLink.setClicked(true);
hyperLink.setClickedColor(Color.RED);
hyperLink.updateUI();
hyperLink.repaint();
}else
hyperLink.setClicked(false);
}
indicesPanel.updateUI();
indicesPanel.repaint();
}
private class PageBarModel
{
int indicesPerView = PaginationConstants.DEFAULT_INDICES_PER_VIEW;
Vector brokenPageIndices;
int currentPageIndices = -1;
int noOfBrokenPageIndices = 0;
public PageBarModel(Vector fullPageIndices)
{
brokenPageIndices = breakFullIndices(fullPageIndices);
}
public boolean hasNextIndices()
{
if(currentPageIndices == brokenPageIndices.size()-1)
return false;
return true;
}
public boolean hasPreviousIndices()
{
if(currentPageIndices == 0)
return false;
return true;
}
public Vector nextIndices()
{
return (Vector)brokenPageIndices.get(++currentPageIndices);
}
public Vector previousIndices()
{
return (Vector) brokenPageIndices.get(--currentPageIndices);
}
public String toString()
{
return brokenPageIndices.toString();
}
private Vector breakFullIndices(Vector fullIndices)
{
Vector returner = new Vector();
Iterator indexIter = fullIndices.iterator();
int counter = 0;
Vector subIndices = new Vector();
while(indexIter.hasNext())
{
String index = (String) indexIter.next();
if(counter == indicesPerView)
{
counter = 0;
noOfBrokenPageIndices++;
returner.add(subIndices);
subIndices = new Vector();
}
subIndices.add(index);
counter++;
}
returner.add(subIndices);
return returner;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -