1 21 package net.mlw.vlh.swing.support; 22 23 import java.awt.GridBagConstraints ; 24 import java.awt.GridBagLayout ; 25 import java.awt.Insets ; 26 import java.awt.event.ActionListener ; 27 import java.text.MessageFormat ; 28 import java.util.ResourceBundle ; 29 30 import javax.swing.JButton ; 31 import javax.swing.JLabel ; 32 import javax.swing.JPanel ; 33 import javax.swing.SwingConstants ; 34 35 import net.mlw.vlh.PagingInfo; 36 import net.mlw.vlh.swing.PagingComponent; 37 import net.mlw.vlh.swing.ValueListHelper; 38 39 43 public class DefaultPagingPanel extends JPanel implements PagingComponent 44 { 45 private ActionListener actionListener; 46 47 private PagingInfo pagingInfo = null; 48 49 private JLabel description = new JLabel (); 50 51 private ResourceBundle resourceBundle; 52 53 private JButton first; 54 55 private JButton previous; 56 57 private JButton next; 58 59 private JButton last; 60 61 private String pagingLabel = null; 62 63 public DefaultPagingPanel() 64 { 65 first = new JButton (new ArrowIcon(SwingConstants.LEFT, 2)); 66 first.setActionCommand(ValueListHelper.ACTION_COMMAND_FIRST); 67 first.setEnabled(false); 68 69 previous = new JButton (new ArrowIcon(SwingConstants.LEFT)); 70 previous.setActionCommand(ValueListHelper.ACTION_COMMAND_PREVIOUS); 71 previous.setEnabled(false); 72 73 next = new JButton (new ArrowIcon(SwingConstants.RIGHT)); 74 next.setActionCommand(ValueListHelper.ACTION_COMMAND_NEXT); 75 next.setEnabled(false); 76 77 last = new JButton (new ArrowIcon(SwingConstants.RIGHT, 2)); 78 last.setActionCommand(ValueListHelper.ACTION_COMMAND_LAST); 79 last.setEnabled(false); 80 81 init(); 82 } 83 84 protected void init() 85 { 86 setLayout(new GridBagLayout ()); 87 GridBagConstraints gbc = new java.awt.GridBagConstraints (); 88 gbc.insets = new Insets (1, 1, 1, 1); 89 90 gbc.gridx = 0; 91 gbc.weightx = 0.2; 92 gbc.anchor = GridBagConstraints.WEST; 93 add(description, gbc); 94 95 gbc.gridx = 1; 96 gbc.weightx = 0.1; 97 gbc.anchor = GridBagConstraints.CENTER; 98 add(first); 99 100 gbc.gridx = 2; 101 add(previous); 102 103 gbc.gridx = 3; 104 add(next); 105 106 gbc.gridx = 4; 107 add(last); 108 } 109 110 public void setPagingInfo(PagingInfo pagingInfo) 111 { 112 this.pagingInfo = pagingInfo; 113 int numberOfPages = pagingInfo.getTotalNumberOfEntries() / pagingInfo.getPagingNumberPer() + 1; 114 115 Object [] messageParameters = new Object [] 116 { new Integer (pagingInfo.getPagingPage()), new Integer (pagingInfo.getTotalNumberOfPages()), new Integer (pagingInfo 117 .getTotalNumberOfEntries()) }; 118 119 if (pagingLabel == null) 120 { 121 description.setText(MessageFormat.format(resourceBundle.getString("paging.text.pageFromTotal"), messageParameters)); 122 } 123 else 124 { 125 description.setText(MessageFormat.format(pagingLabel, messageParameters)); 126 } 127 128 first.setEnabled(pagingInfo.getPagingPage() > 1); 129 previous.setEnabled(pagingInfo.getPagingPage() > 1); 130 next.setEnabled(pagingInfo.getPagingPage() < pagingInfo.getTotalNumberOfPages()); 131 last.setEnabled(pagingInfo.getPagingPage() < pagingInfo.getTotalNumberOfPages()); 132 } 133 134 138 public void addActionListener(ActionListener actionListener) 139 { 140 first.addActionListener(actionListener); 141 previous.addActionListener(actionListener); 142 next.addActionListener(actionListener); 143 last.addActionListener(actionListener); 144 } 145 146 150 public ResourceBundle getResourceBundle() 151 { 152 if (resourceBundle == null) 153 { 154 resourceBundle = ResourceBundle.getBundle("swingLook"); 155 } 156 return resourceBundle; 157 } 158 159 163 public void setResourceBundle(ResourceBundle resourceBundle) 164 { 165 this.resourceBundle = resourceBundle; 166 } 167 168 public void setPagingLabel(String pagingLabel) 169 { 170 this.pagingLabel = pagingLabel; 171 } 172 } | Popular Tags |