001: package com.salmonllc.examples.example15;
002:
003: //The Salmon Open Framework for Internet Applications (SOFIA)
004: //Copyright (C) 1999 - 2002, Salmon LLC
005: //
006: //This program is free software; you can redistribute it and/or
007: //modify it under the terms of the GNU General Public License version 2
008: //as published by the Free Software Foundation;
009: //
010: //This program is distributed in the hope that it will be useful,
011: //but WITHOUT ANY WARRANTY; without even the implied warranty of
012: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: //GNU General Public License for more details.
014: //
015: //You should have received a copy of the GNU General Public License
016: //along with this program; if not, write to the Free Software
017: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: //
019: //For more information please visit http://www.salmonllc.com
020:
021: import com.salmonllc.sql.*;
022: import com.salmonllc.swing.*;
023:
024: import javax.swing.*;
025: import java.awt.*;
026: import java.util.Hashtable;
027: import java.util.Enumeration;
028:
029: /**
030: * The panel with the detail data for each row.
031: */
032:
033: public class DetailPanel extends JPanel {
034:
035: private Dimension _capSize = new Dimension(100, 25);
036: private Dimension _fieldSize = new Dimension(200, 25);
037: private Icon _errorIcon;
038: private JComponent _firstField;
039: private Hashtable _components = new Hashtable();
040: MainPanel _mainPan;
041:
042: public class LocalTextField extends STextField {
043: boolean _skinEnabled = true;
044:
045: public boolean isSkinEnabled() {
046: return _skinEnabled;
047: }
048:
049: public void setSkinEnabled(boolean skinEnabled) {
050: _skinEnabled = skinEnabled;
051: }
052: }
053:
054: public DetailPanel(DataStoreProxy ds, Icon errorIcon, MainPanel pan) {
055: _mainPan = pan;
056:
057: //create the GUI
058: try {
059: _errorIcon = errorIcon;
060:
061: setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
062: JPanel p = new JPanel();
063: p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
064: p.add(Box.createRigidArea(new Dimension(0, 10)));
065: addFieldToGrid(p, ds, "contact.first_name", "First Name");
066: addFieldToGrid(p, ds, "contact.last_name", "Last Name");
067: addFieldToGrid(p, ds, "contact.email_address",
068: "Email Address");
069: addFieldToGrid(p, ds, "contact.address", "Street Address");
070: addFieldToGrid(p, ds, "contact.city", "City");
071: addFieldToGrid(p, ds, "contact.state", "State");
072: addFieldToGrid(p, ds, "contact.zip", "Zip");
073: addFieldToGrid(p, ds, "contact.main_phone", "Main Phone");
074: addFieldToGrid(p, ds, "contact.alt_phone",
075: "Alternate Phone");
076: addFieldToGrid(p, ds, "contact.cell_phone", "Cell Phone");
077:
078: p.add(Box.createRigidArea(new Dimension(300, 10)));
079:
080: SErrorList l = new SErrorList();
081: l.setDataStoreAndPanel(ds, p);
082: Box b = Box.createHorizontalBox();
083: l.setPreferredSize(new Dimension(300, 50));
084: l.setMaximumSize(new Dimension(300, 50));
085: b.add(l);
086: p.add(b);
087:
088: p.add(Box.createRigidArea(new Dimension(0, 10)));
089: add(new JScrollPane(p));
090:
091: } catch (Exception e) {
092: e.printStackTrace();
093: }
094: }
095:
096: /**
097: * It's a bit of work to add a new field for editing so we have a method that does it
098: */
099: private void addFieldToGrid(JPanel p, DataStoreProxy ds,
100: String column, String caption) {
101: SLabel l = new SLabel(caption);
102: l.addValidateColumn(ds, column, _errorIcon);
103: l.setMaximumSize(_capSize);
104: l.setMinimumSize(_capSize);
105: l.setName("detailCap." + column);
106:
107: STextField f = new LocalTextField();
108: f.setColumn(ds, column);
109: f.setMaximumSize(_fieldSize);
110: f.setMinimumSize(_fieldSize);
111: f.setName("detailField." + column);
112:
113: Box b = Box.createHorizontalBox();
114: b.add(l);
115: b.add(f);
116: p.add(b);
117:
118: _components.put(column, f);
119: if (_firstField == null)
120: _firstField = f;
121: f.addKeyListener(_mainPan.getKeyHandler());
122: }
123:
124: /**
125: * return the list of edit fields in the panel
126: */
127: public Hashtable getFields() {
128: return _components;
129: }
130:
131: /**
132: * Sets focus to the first field in the panel
133: */
134: public void grabFocus() {
135: _firstField.grabFocus();
136: }
137:
138: /**
139: * Sets all the text fields in the panel to enabled or not
140: */
141: public void setEnabled(boolean enabled) {
142: if (enabled != isEnabled()) {
143: super.setEnabled(enabled);
144: Enumeration enum = _components.elements();
145: while (enum.hasMoreElements()) {
146: Component comp = (JComponent)enum.nextElement();
147: if (comp instanceof LocalTextField && enabled)
148: comp.setEnabled(((LocalTextField)comp).isSkinEnabled());
149: else
150: comp.setEnabled(enabled);
151: }
152: }
153:
154: }
155:
156: }
|