KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > displaycomponents > search > SearchTabPanel


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 package org.openharmonise.him.displaycomponents.search;
21
22 import java.awt.*;
23 import java.awt.event.*;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URI JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.rmi.RemoteException JavaDoc;
28 import java.text.*;
29 import java.util.*;
30 import java.util.List JavaDoc;
31
32 import javax.swing.*;
33 import javax.xml.rpc.ServiceException JavaDoc;
34
35 import org.openharmonise.commons.xml.namespace.*;
36 import org.openharmonise.him.*;
37 import org.openharmonise.him.configuration.*;
38 import org.openharmonise.him.displaycomponents.*;
39 import org.openharmonise.him.editors.report.swing.*;
40 import org.openharmonise.him.harmonise.*;
41 import org.openharmonise.him.window.messages.MessageHandler;
42 import org.openharmonise.him.window.swing.ResourcePathCellRenderer;
43 import org.openharmonise.swing.FontManager;
44 import org.openharmonise.swing.datefield.*;
45 import org.openharmonise.vfs.context.*;
46 import org.openharmonise.vfs.gui.*;
47 import org.openharmonise.vfs.search.*;
48 import org.openharmonise.vfs.servers.*;
49 import org.openharmonise.webdav.client.webservice.SearchDetailsService;
50
51
52 /**
53  * The search form panel.
54  *
55  * @author Matthew Large
56  * @version $Revision: 1.5 $
57  *
58  */

59 public class SearchTabPanel
60     extends JPanel
61     implements ActionListener, LayoutManager, KeyListener, ContextListener {
62
63     /**
64      * Search display component.
65      */

66     private SearchDisplayComponent m_display = null;
67     
68     /**
69      * Selected highlight colour.
70      */

71     private Color m_selectedColor = new Color(173, 169, 143);
72
73     /**
74      * Label for free-text search field.
75      */

76     private JLabel m_textLabel = null;
77     
78     /**
79      * Free-text search field.
80      */

81     private JTextField m_textTextField = null;
82     
83     /**
84      * Free-text search type selector.
85      */

86     private JComboBox m_textComboBox = null;
87     
88     /**
89      * Label for search in selector.
90      */

91     private JLabel m_inLabel = null;
92     
93     /**
94      * Search in selector.
95      */

96     private JComboBox m_inCombo = null;
97
98     /**
99      * Search button.
100      */

101     private JButton m_searchButton = null;
102
103     /**
104      * Label for options.
105      */

106     private JLabel m_optionsLabel = null;
107
108     /**
109      * Checkbox for publication date.
110      */

111     private JCheckBox m_publicationDateCheck = null;
112     
113     /**
114      * Publication date text field.
115      */

116     private JDateField m_publicationDateField = null;
117     
118     /**
119      * Publication date operator selector.
120      */

121     private JComboBox m_publicationDateCombo = null;
122     
123     /**
124      * Check box for author name.
125      */

126     private JCheckBox m_authorCheck = null;
127     
128     /**
129      * Author name text field.
130      */

131     private JTextField m_authorTextField = null;
132     private JComboTree m_authorTree = null;
133     
134     /**
135      * Identifier for title option.
136      */

137     private static String JavaDoc TEXT_OPTION_TITLE = "Title";
138     
139     /**
140      * Identifier for contents option.
141      */

142     private static String JavaDoc TEXT_OPTION_CONTENTS = "Contents";
143     
144     private List JavaDoc m_aStopWords = null;
145
146     /**
147      * Constructs a new search tab panel.
148      *
149      * @param display Search display component
150      */

151     public SearchTabPanel(SearchDisplayComponent display) {
152         super();
153         this.m_display = display;
154         this.setup();
155     }
156
157     /**
158      * Configures the search form.
159      *
160      */

161     private void setup() {
162         ContextHandler.getInstance().addListener(ContextType.CONTEXT_SYSTEM_PROP_CHANGED, this);
163         
164         this.setLayout(this);
165
166 // String fontName = "Dialog";
167
// int fontSize = 11;
168
// Font font = new Font(fontName, Font.PLAIN, fontSize);
169
// Font fontBold = new Font(fontName, Font.BOLD, fontSize);
170

171         m_textLabel = new JLabel("Containing the text:");
172         m_textLabel.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD ) );
173         this.add(m_textLabel);
174
175         m_textTextField = new JTextField();
176         m_textTextField.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD ) );
177         m_textTextField.addKeyListener(this);
178         this.add(m_textTextField);
179         
180         String JavaDoc[] aTextOptions = new String JavaDoc[]{"Title", "Contents"};
181         this.m_textComboBox = new JComboBox(aTextOptions);
182         this.m_textComboBox.setActionCommand("TEXT_OPTIONS");
183         this.add(m_textComboBox);
184         
185
186         m_inLabel = new JLabel("Search in...");
187         m_inLabel.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD ) );
188         this.add(m_inLabel);
189
190         Object JavaDoc[] sPaths = this.getComboData();
191         m_inCombo = new JComboBox(sPaths);
192         m_inCombo.addActionListener(this);
193         m_inCombo.setActionCommand("COMBO");
194         m_inCombo.setRenderer(
195             new ResourcePathCellRenderer(
196                 ServerList.getInstance().getHarmoniseServer().getVFS()));
197         m_inCombo.setFont( FontManager.getInstance().getFont( FontManager.FONT_RESOURCE_TITLE ) );
198         this.add(m_inCombo);
199
200         m_searchButton = new JButton("Search");
201         m_searchButton.setActionCommand("SEARCH");
202         m_searchButton.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD ) );
203         m_searchButton.setIcon(
204             IconManager.getInstance().getIcon("16-command-search.gif"));
205         m_searchButton.addActionListener(this);
206         this.add(m_searchButton);
207
208         this.m_optionsLabel = new JLabel(" Options");
209         this.m_optionsLabel.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD_BOLD ) );
210         this.add(this.m_optionsLabel);
211
212         this.m_publicationDateCheck = new JCheckBox("Publication date");
213         this.m_publicationDateCheck.setActionCommand("PUBDATE");
214         this.m_publicationDateCheck.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD ) );
215         this.m_publicationDateCheck.addActionListener(this);
216         this.add(this.m_publicationDateCheck);
217
218         Date dt = new Date();
219         this.m_publicationDateField = new JDateField("yyyy-MM-dd");
220         this.m_publicationDateField.setBorder( BorderFactory.createLineBorder(Color.BLACK) );
221         this.m_publicationDateField.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD ) );
222         this.m_publicationDateField.setVisible(false);
223         this.add(this.m_publicationDateField);
224
225         String JavaDoc[] pubDateOperators = new String JavaDoc[] { "=", ">", "<" };
226         this.m_publicationDateCombo = new JComboBox(pubDateOperators);
227         this.m_publicationDateCombo.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD_BOLD ) );
228         this.m_publicationDateCombo.setVisible(false);
229         this.add(this.m_publicationDateCombo);
230
231         this.m_authorCheck = new JCheckBox("Author");
232         this.m_authorCheck.setActionCommand("CREAT");
233         this.m_authorCheck.setFont( FontManager.getInstance().getFont( FontManager.FONT_STANDARD ) );
234         this.m_authorCheck.addActionListener(this);
235         this.add(this.m_authorCheck);
236         
237         this.m_authorTree = new JComboTree();
238         this.m_authorTree.addCollectionPath(HarmonisePaths.PATH_VALUES + "/admin/content_workers/authors");
239         this.m_authorTree.setVisible(false);
240         this.add(this.m_authorTree);
241
242     }
243
244     /* (non-Javadoc)
245      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
246      */

247     public void layoutContainer(Container arg0) {
248         int nHeight = 5;
249
250         this.m_textComboBox.setSize(this.getParent().getWidth() - 20, 20);
251         this.m_textComboBox.setLocation(10, nHeight);
252         nHeight = nHeight + this.m_textComboBox.getSize().height + 5;
253
254         this.m_textLabel.setSize(this.getParent().getWidth() - 20, 20);
255         this.m_textLabel.setLocation(10, nHeight);
256         nHeight = nHeight + this.m_textLabel.getSize().height + 5;
257
258         this.m_textTextField.setSize(this.getParent().getWidth() - 20, 20);
259         this.m_textTextField.setLocation(10, nHeight);
260         nHeight = nHeight + this.m_textTextField.getSize().height + 5;
261
262         this.m_inLabel.setSize(this.getParent().getWidth() - 20, 20);
263         this.m_inLabel.setLocation(10, nHeight);
264         nHeight = nHeight + this.m_inLabel.getSize().height + 5;
265
266         this.m_inCombo.setSize(this.getParent().getWidth() - 20, 20);
267         this.m_inCombo.setLocation(10, nHeight);
268         nHeight = nHeight + this.m_inCombo.getSize().height + 5;
269
270         this.m_optionsLabel.setSize(this.getParent().getWidth() - 20, 20);
271         this.m_optionsLabel.setLocation(10, nHeight);
272         nHeight = nHeight + this.m_optionsLabel.getSize().height + 5;
273
274         this.m_publicationDateCheck.setSize(
275             this.getParent().getWidth() - 20,
276             20);
277         this.m_publicationDateCheck.setLocation(10, nHeight);
278         nHeight = nHeight + this.m_publicationDateCheck.getSize().height + 5;
279
280         if (this.m_publicationDateCheck.isSelected()) {
281             this.m_publicationDateField.setSize(
282                 this.getParent().getWidth() - 70,
283                 20);
284             this.m_publicationDateField.setLocation(10, nHeight);
285
286             this.m_publicationDateCombo.setSize(40, 20);
287             this.m_publicationDateCombo.setLocation(
288                 this.getParent().getWidth() - 50,
289                 nHeight);
290             nHeight =
291                 nHeight + this.m_publicationDateField.getSize().height + 5;
292         }
293
294         this.m_authorCheck.setSize(
295             this.getParent().getWidth() - 20,
296             20);
297         this.m_authorCheck.setLocation(10, nHeight);
298         nHeight = nHeight + this.m_authorCheck.getSize().height + 5;
299         
300         if(this.m_authorCheck.isSelected()) {
301             this.m_authorTree.setSize(
302                     this.getParent().getWidth() - 20,
303                     20);
304
305             this.m_authorTree.setLocation(10, nHeight);
306             nHeight =
307                 nHeight + this.m_authorTree.getSize().height + 5;
308         }
309
310         nHeight = nHeight + 5;
311         this.m_searchButton.setSize(90, 25);
312         this.m_searchButton.setLocation(
313             this.getParent().getWidth()
314                 - this.m_searchButton.getSize().width
315                 - 10,
316             nHeight);
317         nHeight = nHeight + this.m_searchButton.getSize().height + 5;
318     }
319
320     /* (non-Javadoc)
321      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
322      */

323     public void actionPerformed(Acti