001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.serverconfig.cache;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023:
024: import javax.swing.*;
025:
026: /**
027: * Panel for setting an individual cache's settings.
028: *
029: * @author Matthew Large
030: * @version $Revision: 1.1 $
031: *
032: */
033: public class CacheSettings extends JPanel implements LayoutManager,
034: KeyListener {
035:
036: /**
037: * Cache size label.
038: */
039: private JLabel m_cacheSizeLabel = null;
040:
041: /**
042: * Cache size text field.
043: */
044: private JTextField m_cacheSizeTextField = null;
045:
046: /**
047: * true if the cache size has changed.
048: */
049: private boolean m_bcacheSizeChanged = false;
050:
051: /**
052: * Cache configuration options panel that this settings object belongs to.
053: */
054: private CacheServerConfigOptions m_optionsPanel = null;
055:
056: /**
057: * Name of the cache object these settings apply to.
058: */
059: private String m_sObjectName = null;
060:
061: /**
062: * Constructs a new cache settings object.
063: *
064: * @param sObjectName name of the cache object these settings apply to.
065: * @param optionsPanel cache configuration options panel that this settings object belongs to.
066: */
067: public CacheSettings(String sObjectName,
068: CacheServerConfigOptions optionsPanel) {
069: super ();
070: this .m_optionsPanel = optionsPanel;
071: this .m_sObjectName = sObjectName;
072: this .setup();
073: }
074:
075: /**
076: * Initialises this object.
077: *
078: */
079: private void setup() {
080: String fontName = "Dialog";
081: int fontSize = 11;
082: Font font = new Font(fontName, Font.PLAIN, fontSize);
083:
084: this .setLayout(this );
085:
086: this .m_cacheSizeLabel = new JLabel(this .m_sObjectName);
087: this .m_cacheSizeLabel.setFont(font);
088: this .add(m_cacheSizeLabel);
089:
090: this .m_cacheSizeTextField = new JTextField();
091: this .m_cacheSizeTextField.setFont(font);
092: this .m_cacheSizeTextField.addKeyListener(this );
093: this .add(this .m_cacheSizeTextField);
094: }
095:
096: /* (non-Javadoc)
097: * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
098: */
099: public void keyReleased(KeyEvent ke) {
100: if (ke.getSource() == this .m_cacheSizeTextField) {
101: this .m_bcacheSizeChanged = true;
102: }
103: this .m_optionsPanel.fireChangesMade();
104: }
105:
106: /**
107: * Checks if the cache size option has changed.
108: *
109: * @return true if the cache size option has changed.
110: */
111: public boolean isCacheSizeChanged() {
112: return this .m_bcacheSizeChanged;
113: }
114:
115: /**
116: * Sets whether the cache size option value has changed.
117: *
118: * @param bcacheSizeChanged true to set that the cache size option has changed.
119: */
120: public void setCacheSizeChanged(boolean bcacheSizeChanged) {
121: this .m_bcacheSizeChanged = bcacheSizeChanged;
122: }
123:
124: /**
125: * Returns the cache size option value.
126: *
127: * @return the cache size option value.
128: */
129: public String getCacheSize() {
130: return this .m_cacheSizeTextField.getText();
131: }
132:
133: /**
134: * Sets the cache size option value.
135: *
136: * @param sCacheSize the cache size option value.
137: */
138: public void setCacheSize(String sCacheSize) {
139: this .m_cacheSizeTextField.setText(sCacheSize);
140: }
141:
142: /**
143: * Returns the name of the cache object these settings apply to.
144: *
145: * @return name of the cache object these settings apply to.
146: */
147: public String getObjectName() {
148: return this .m_sObjectName;
149: }
150:
151: /* (non-Javadoc)
152: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
153: */
154: public void layoutContainer(Container arg0) {
155: this .m_cacheSizeLabel.setSize(150, 20);
156: this .m_cacheSizeLabel.setLocation(20, 0);
157:
158: this .m_cacheSizeTextField.setSize(150, 20);
159: this .m_cacheSizeTextField.setLocation(150, 5);
160: }
161:
162: /* (non-Javadoc)
163: * @see java.awt.Component#getPreferredSize()
164: */
165: public Dimension getPreferredSize() {
166: return new Dimension(350, 30);
167: }
168:
169: /* (non-Javadoc)
170: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
171: */
172: public Dimension minimumLayoutSize(Container arg0) {
173: return this .getPreferredSize();
174: }
175:
176: /* (non-Javadoc)
177: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
178: */
179: public Dimension preferredLayoutSize(Container arg0) {
180: return this .getPreferredSize();
181: }
182:
183: /* (non-Javadoc)
184: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
185: */
186: public void removeLayoutComponent(Component arg0) {
187: }
188:
189: /* (non-Javadoc)
190: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
191: */
192: public void addLayoutComponent(String arg0, Component arg1) {
193: }
194:
195: /* (non-Javadoc)
196: * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
197: */
198: public void keyPressed(KeyEvent arg0) {
199: }
200:
201: /* (non-Javadoc)
202: * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
203: */
204: public void keyTyped(KeyEvent arg0) {
205: }
206:
207: /**
208: * @param arg0
209: */
210: private CacheSettings(boolean arg0) {
211: super (arg0);
212: }
213:
214: /**
215: * @param arg0
216: */
217: private CacheSettings(LayoutManager arg0) {
218: super (arg0);
219: }
220:
221: /**
222: * @param arg0
223: * @param arg1
224: */
225: private CacheSettings(LayoutManager arg0, boolean arg1) {
226: super(arg0, arg1);
227: }
228:
229: }
|