gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.impl / src / main / java / org / gvsig / raster / swing / impl / pagedtable / PaginationBarPanel.java @ 1556
History | View | Annotate | Download (4.34 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.raster.swing.impl.pagedtable; |
25 |
|
26 |
import java.awt.Dimension; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.util.Observable; |
30 |
import java.util.Observer; |
31 |
|
32 |
import javax.swing.ImageIcon; |
33 |
import javax.swing.JButton; |
34 |
import javax.swing.JLabel; |
35 |
import javax.swing.JPanel; |
36 |
|
37 |
import org.gvsig.andami.IconThemeHelper; |
38 |
import org.gvsig.i18n.Messages; |
39 |
|
40 |
public class PaginationBarPanel extends JPanel implements Observer { |
41 |
private static final long serialVersionUID = 1L; |
42 |
private JButton up = null; |
43 |
private JButton down = null; |
44 |
private JLabel selectedPag = null; |
45 |
private JLabel nPages = null; |
46 |
private String pathToImagesForTest = "/src/main/resources/images/"; |
47 |
|
48 |
public PaginationBarPanel(TableControllerListener tableListener) {
|
49 |
if(tableListener != null) |
50 |
tableListener.setPaginationBarPanel(this);
|
51 |
initialize(tableListener); |
52 |
} |
53 |
|
54 |
private void initialize(TableControllerListener tableListener) { |
55 |
this.setLayout(new GridBagLayout()); |
56 |
|
57 |
GridBagConstraints gbc = new GridBagConstraints(); |
58 |
gbc.fill = GridBagConstraints.VERTICAL;
|
59 |
gbc.anchor = GridBagConstraints.NORTH;
|
60 |
|
61 |
add(getButtonUp(), gbc); |
62 |
|
63 |
gbc.anchor = GridBagConstraints.CENTER;
|
64 |
gbc.gridy = 1;
|
65 |
gbc.weighty = 1;
|
66 |
|
67 |
JPanel p = new JPanel(new GridBagLayout()); |
68 |
GridBagConstraints gbc1 = new GridBagConstraints(); |
69 |
gbc1.fill = GridBagConstraints.NONE;
|
70 |
gbc1.gridx = 0;
|
71 |
gbc1.gridy = 0;
|
72 |
p.add(getNPages(), gbc1); |
73 |
gbc1.gridy = 1;
|
74 |
p.add(getSelectedPage(), gbc1); |
75 |
add(p, gbc); |
76 |
|
77 |
gbc.weighty = 0;
|
78 |
gbc.anchor = GridBagConstraints.SOUTH;
|
79 |
gbc.gridy = 2;
|
80 |
|
81 |
add(getButtonDown(), gbc); |
82 |
|
83 |
getButtonUp().addActionListener(tableListener); |
84 |
getButtonDown().addActionListener(tableListener); |
85 |
} |
86 |
|
87 |
public JLabel getSelectedPage() { |
88 |
if(selectedPag == null) |
89 |
selectedPag = new JLabel("-"); |
90 |
return selectedPag;
|
91 |
} |
92 |
|
93 |
public JLabel getNPages() { |
94 |
if(nPages == null) |
95 |
nPages = new JLabel("-"); |
96 |
return nPages;
|
97 |
} |
98 |
|
99 |
private ImageIcon loadIcon(String iconName) { |
100 |
ImageIcon icon = null; |
101 |
try {
|
102 |
icon = IconThemeHelper.getImageIcon(iconName); |
103 |
} catch(NullPointerException e) {} |
104 |
if(icon == null) |
105 |
icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".png", ""); |
106 |
if(icon == null) |
107 |
icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".gif", ""); |
108 |
return icon;
|
109 |
} |
110 |
|
111 |
public JButton getButtonUp() { |
112 |
if (up == null) { |
113 |
up = new JButton(""); |
114 |
up.setEnabled(false);
|
115 |
up.setPreferredSize(new Dimension(22, 22)); |
116 |
up.setIcon(loadIcon("up-16x16"));
|
117 |
up.setActionCommand("");
|
118 |
up.setToolTipText(Messages.getText("prev_pag"));
|
119 |
} |
120 |
return up;
|
121 |
} |
122 |
|
123 |
public JButton getButtonDown() { |
124 |
if (down == null) { |
125 |
down = new JButton(""); |
126 |
down.setEnabled(false);
|
127 |
down.setPreferredSize(new Dimension(22, 22)); |
128 |
down.setIcon(loadIcon("down-16x16"));
|
129 |
down.setActionCommand("");
|
130 |
down.setToolTipText(Messages.getText("next_pag"));
|
131 |
} |
132 |
return down;
|
133 |
} |
134 |
|
135 |
public void update(Observable o, Object arg) { |
136 |
Pager pager = (Pager)o; |
137 |
if(o instanceof Pager && arg instanceof Integer) { |
138 |
if(pager.getPageCount() == 0) { |
139 |
getNPages().setText("-");
|
140 |
getSelectedPage().setText("-");
|
141 |
} else {
|
142 |
getNPages().setText(pager.getPageCount() + "");
|
143 |
getSelectedPage().setText(pager.getSelectedPageNumber() + 1 + ""); |
144 |
} |
145 |
} |
146 |
} |
147 |
} |