001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: */
010:
011: package components;
012:
013: import soif.CSID;
014: import soif.Results;
015: import soif.SOIF;
016: import soif.Search;
017: import soif.Taxonomy;
018: import soif.TaxonomyNode;
019: import util.Key;
020: import util.SysInfo;
021:
022: import netscape.application.Button;
023: import netscape.application.Color;
024: import netscape.application.Rect;
025: import netscape.application.Size;
026: import netscape.application.Target;
027: import netscape.application.TextField;
028: import netscape.application.View;
029:
030: import components.SearchPopupField;
031: import components.SearchTextField;
032:
033: /**
034: Search panel w/ button and textfield.
035: *
036: */
037: public class SearchView extends View implements Target {
038: public Button searchBtn;
039: public SearchTextField searchTF;
040: public SearchPopupField searchPF;
041: private String CGILocation;
042: private String CGITarget;
043: private CSID csid;
044: private Search search; // SGP: why private? could
045: // eliminate methods.
046:
047: // SGP: i don't suppose these need to be private,
048: // unless some kind of validation is going to happen.
049: private String display;
050: private String sort;
051: private int count;
052: private String ql;
053:
054: private boolean m_showPopup = false;
055: private boolean m_showText = true;
056:
057: /**
058: * Constructor.
059: */
060: public SearchView(int x, int y, int width, int height,
061: String CGILocation, String CGITarget, CSID csid,
062: String display, String sort, int count, String ql) {
063: super (x, y, width, height);
064:
065: this .CGILocation = CGILocation;
066: this .CGITarget = CGITarget;
067: this .csid = csid;
068: this .display = display;
069: this .sort = sort;
070: this .count = count;
071: this .ql = ql;
072:
073: search = new Search();
074:
075: searchBtn = new Button();
076: searchBtn.setTitle(Messages.CMD_SEARCH);
077: searchBtn.setCommand(Messages.CMD_SEARCH);
078: searchBtn.setBounds(width - searchBtn.minSize().width
079: // SGP: why 2?
080: - (graphical.Header.WIDGETHGAP ),
081: graphical.Header.WIDGETVGAP, searchBtn.minSize().width,
082: searchBtn.minSize().height);
083: searchBtn.setTarget(this );
084: searchBtn
085: .setHorizResizeInstruction(View.LEFT_MARGIN_CAN_CHANGE);
086:
087: // Create text entry field (default), but do not add it to view until used.
088: searchTF = new SearchTextField(graphical.Header.WIDGETHGAP,
089: graphical.Header.WIDGETVGAP, width
090: - (graphical.Header.WIDGETHGAP * 3)
091: - searchBtn.width(), searchBtn.height());
092: searchTF.setHorizResizeInstruction(View.WIDTH_CAN_CHANGE);
093: searchTF.setBackgroundColor(Color.lightGray);
094: searchTF.setCommand(Messages.CMD_SEARCH);
095: searchTF.setTarget(this );
096:
097: // Create popup entry field but do not add it to view until used.
098: Rect boundsRect = searchTF.bounds();
099: searchPF = new SearchPopupField(boundsRect);
100: searchPF.setHorizResizeInstruction(View.WIDTH_CAN_CHANGE);
101:
102: addSubview(searchBtn);
103: }
104:
105: /**
106: * Set the attributes to be retrieved.
107: * @param display attribute list, e.g. "score,url,title"
108: */
109: public void setDisplay(String display) {
110: this .display = display;
111: }
112:
113: /**
114: * Set the attributes to sort by.
115: * @param sort sort list, e.g. "-score,+title"
116: */
117: public void setSort(String sort) {
118: this .sort = sort;
119: }
120:
121: /**
122: * Set the attributes to sort by.
123: * @param sort sort list, e.g. "-score,+title"
124: */
125: public void setCount(int count) {
126: this .count = count;
127: }
128:
129: public int getStatus() {
130: return search.getStatus();
131: }
132:
133: public SOIF getSOIFResult() {
134: return search.getSOIFResult();
135: }
136:
137: public int resultCount() {
138: return search.resultCount();
139: }
140:
141: public Size minSize() {
142: return new Size(searchTF.width()
143: + (graphical.Header.WIDGETHGAP * 3)
144: + searchBtn.minSize().width, searchTF.minSize().height
145: + (graphical.Header.WIDGETVGAP * 2));
146: }
147:
148: /**
149: * Enable/Disable SearchView data entry field.
150: */
151: public void enableTextField(boolean enable) {
152: if (enable == true) {
153: searchTF.setEditable(true);
154: searchTF.setSelectable(true);
155: searchTF.startFocus();
156: searchTF.setTextColor(graphical.Header.TEXTCOLOR);
157: } else {
158: searchTF.setEditable(false);
159: searchTF.setSelectable(false);
160: searchTF.stopFocus();
161: searchTF.setTextColor(graphical.Header.DISABLEDTEXTCOLOR);
162: }
163: }
164:
165: /**
166: * Show SearchView data entry field as a TextField.
167: */
168: public void showTextField(boolean show) {
169: if (show == m_showText) {
170: return;
171: }
172:
173: if (show == true) {
174: Rect boundsRect = this .bounds(); // View bounds
175: // Reposition text fiels as window could have been resized since
176: // last displayed and we want field to fill window.
177: boundsRect = new Rect(graphical.Header.WIDGETHGAP,
178: graphical.Header.WIDGETVGAP, boundsRect.width
179: - (graphical.Header.WIDGETHGAP * 3)
180: - searchBtn.width(), searchBtn.height());
181: searchTF.setBounds(boundsRect);
182: addSubview(searchTF);
183: setDirty(true);
184: } else {
185: searchTF.removeFromSuperview();
186: setDirty(true);
187: }
188:
189: m_showText = show;
190: }
191:
192: /**
193: * Show SearchView data entry field as a Popup.
194: */
195: public void showPopupField(boolean show) {
196: if (show == m_showPopup) {
197: return;
198: }
199:
200: if (show == true) {
201: setDirty(true);
202: Rect boundsRect = this .bounds(); // View bounds
203: // Reposition popup as window could have been resized since
204: // last displayed and we want field to fill window.
205: boundsRect = new Rect(graphical.Header.WIDGETHGAP,
206: graphical.Header.WIDGETVGAP, boundsRect.width
207: - (graphical.Header.WIDGETHGAP * 3)
208: - searchBtn.width(), searchBtn.height());
209: searchPF.setBounds(boundsRect);
210: addSubview(searchPF);
211: } else {
212: searchPF.removeFromSuperview();
213: setDirty(true);
214: }
215:
216: m_showPopup = show;
217: }
218:
219: /**
220: * Load SearchView data entry popup field.
221: */
222: public void loadPopupField(Taxonomy taxonomy) {
223: // System.out.println("taxonomy=======\n" + taxonomy + "\n=======");
224: searchPF.removeAllItems();
225: taxonomy.binaryTree.resetEnumeration();
226:
227: while (taxonomy.binaryTree.hasMoreElements(true)) {
228: taxonomy.binaryTree.nextElement(true);
229: Object o = taxonomy.binaryTree.getValue();
230:
231: if (o instanceof TaxonomyNode) {
232: searchPF.addItem(((TaxonomyNode) o).getId(),
233: ((TaxonomyNode) o).getId());
234: }
235: }
236: }
237:
238: public void searchBtnPress() {
239: searchTF.setEditable(false);
240: searchBtn.setEnabled(false);
241: draw();
242:
243: search = new Search(searchTF.stringValue(), display, sort,
244: count, ql, csid, CGILocation);
245:
246: search.doQuery();
247:
248: searchTF.setEditable(true);
249: searchBtn.setEnabled(true);
250: draw();
251:
252: // SGP: some sort of callback
253: }
254:
255: public void performCommand(String command, Object arg) {
256: if (Messages.CMD_SEARCH.equals(command)) {
257: searchBtnPress();
258: }
259: }
260: }
|