001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui;
034:
035: import java.awt.GridBagConstraints;
036: import java.awt.GridBagLayout;
037: import java.awt.Insets;
038: import java.awt.event.ActionEvent;
039:
040: import javax.swing.JButton;
041: import javax.swing.JPanel;
042: import javax.swing.JTextField;
043: import javax.swing.SwingConstants;
044:
045: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
046:
047: public class RecordPanel extends JPanel {
048: private GridBagLayout gridBagLayout1 = new GridBagLayout();
049: private JButton startButton = new JButton();
050: private JButton prevButton = new JButton();
051: private JTextField textField = new JTextField(4);
052: private JButton nextButton = new JButton();
053: private JButton endButton = new JButton();
054: private RecordPanelModel model;
055:
056: public RecordPanel(RecordPanelModel model) {
057: this .model = model;
058:
059: try {
060: jbInit();
061: } catch (Exception e) {
062: e.printStackTrace();
063: }
064:
065: setIcon(startButton, "Start.gif");
066: setIcon(prevButton, "Prev.gif");
067: setIcon(nextButton, "Next.gif");
068: setIcon(endButton, "End.gif");
069: updateAppearance();
070: }
071:
072: private void setIcon(JButton button, String filename) {
073: button.setIcon(IconLoader.icon(filename));
074: button.setText("");
075: }
076:
077: public void updateAppearance() {
078: startButton.setEnabled(model.getCurrentIndex() > 0);
079: prevButton.setEnabled(model.getCurrentIndex() > 0);
080: nextButton.setEnabled(model.getCurrentIndex() < (model
081: .getRecordCount() - 1));
082: endButton.setEnabled(model.getCurrentIndex() < (model
083: .getRecordCount() - 1));
084: textField.setText("" + (model.getCurrentIndex() + 1));
085: }
086:
087: private void jbInit() throws Exception {
088: startButton.setFocusPainted(false);
089: startButton.setMargin(new Insets(0, 0, 0, 0));
090: prevButton.setFocusPainted(false);
091: prevButton.setMargin(new Insets(0, 0, 0, 0));
092: nextButton.setFocusPainted(false);
093: nextButton.setMargin(new Insets(0, 0, 0, 0));
094: endButton.setFocusPainted(false);
095: endButton.setMargin(new Insets(0, 0, 0, 0));
096: startButton.setText("|<");
097: prevButton.setText("<");
098: startButton
099: .addActionListener(new java.awt.event.ActionListener() {
100: public void actionPerformed(ActionEvent e) {
101: startButton_actionPerformed(e);
102: }
103: });
104: this .setLayout(gridBagLayout1);
105: prevButton
106: .addActionListener(new java.awt.event.ActionListener() {
107: public void actionPerformed(ActionEvent e) {
108: prevButton_actionPerformed(e);
109: }
110: });
111: nextButton.setText(">");
112: nextButton
113: .addActionListener(new java.awt.event.ActionListener() {
114: public void actionPerformed(ActionEvent e) {
115: nextButton_actionPerformed(e);
116: }
117: });
118: endButton.setText(">|");
119: endButton
120: .addActionListener(new java.awt.event.ActionListener() {
121: public void actionPerformed(ActionEvent e) {
122: endButton_actionPerformed(e);
123: }
124: });
125: textField.setEditable(false);
126: textField.setHorizontalAlignment(SwingConstants.RIGHT);
127: this .add(startButton, new GridBagConstraints(0, 0, 1, 1, 0.0,
128: 0.0, GridBagConstraints.CENTER,
129: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
130: this .add(prevButton, new GridBagConstraints(1, 0, 1, 1, 0.0,
131: 0.0, GridBagConstraints.CENTER,
132: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
133: this .add(textField, new GridBagConstraints(2, 0, 1, 1, 0.0,
134: 0.0, GridBagConstraints.CENTER,
135: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
136: this .add(nextButton, new GridBagConstraints(3, 0, 1, 1, 0.0,
137: 0.0, GridBagConstraints.CENTER,
138: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
139: this .add(endButton, new GridBagConstraints(4, 0, 1, 1, 0.0,
140: 0.0, GridBagConstraints.CENTER,
141: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
142: }
143:
144: void nextButton_actionPerformed(ActionEvent e) {
145: model.setCurrentIndex(model.getCurrentIndex() + 1);
146: updateAppearance();
147: }
148:
149: void endButton_actionPerformed(ActionEvent e) {
150: model.setCurrentIndex(model.getRecordCount() - 1);
151: updateAppearance();
152: }
153:
154: void prevButton_actionPerformed(ActionEvent e) {
155: model.setCurrentIndex(model.getCurrentIndex() - 1);
156: updateAppearance();
157: }
158:
159: void startButton_actionPerformed(ActionEvent e) {
160: model.setCurrentIndex(0);
161: updateAppearance();
162: }
163: }
|