KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > workbench > WorkbenchControlPanel


1 /*
2  * WebSphinx web-crawling toolkit
3  *
4  * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */

32
33 package websphinx.workbench;
34
35 import java.awt.*;
36 import java.io.*;
37 import java.net.URL JavaDoc;
38 import websphinx.*;
39 import rcm.awt.Constrain;
40 import rcm.awt.PopupDialog;
41 import rcm.awt.TabPanel;
42 import rcm.awt.BorderPanel;
43 import rcm.awt.ClosableFrame;
44 import rcm.util.Win;
45
46 public class WorkbenchControlPanel extends PopupDialog {
47     WebGraph g;
48     WebOutline o;
49
50     Choice nodeChoice;
51     Choice pageChoice;
52     Choice linkChoice;
53     Checkbox automatic;
54
55     Button applyButton;
56     Button okButton;
57     Button cancelButton;
58
59     public WorkbenchControlPanel (WebGraph g, WebOutline o) {
60         super (Win.findFrame (g != null ? (Component)g : (Component)o), "Workbench Control Panel", true);
61
62         this.g = g;
63         this.o = o;
64
65         setLayout (new GridBagLayout ());
66
67         Constrain.add (this, new Label ("Display:"),
68                        Constrain.labelLike (0, 0));
69         Constrain.add (this, nodeChoice = new Choice (),
70                        Constrain.fieldLike (1, 0));
71         nodeChoice.addItem ("icons");
72         nodeChoice.addItem ("titles");
73         nodeChoice.addItem ("absolute URLs");
74         nodeChoice.addItem ("relative URLs");
75         nodeChoice.select (g != null ? g.defaultRendering : o.defaultRendering+1);
76
77         Constrain.add (this, new Label ("Pages:"),
78                        Constrain.labelLike (0, 1));
79         Constrain.add (this, pageChoice = new Choice (),
80                        Constrain.fieldLike (1, 1));
81         pageChoice.addItem ("visited pages");
82         pageChoice.addItem ("all pages");
83
84         Constrain.add (this, new Label ("Links:"),
85                        Constrain.labelLike (0, 2));
86         Constrain.add (this, linkChoice = new Choice (),
87                        Constrain.fieldLike (1, 2));
88         linkChoice.addItem ("tree links");
89         linkChoice.addItem ("all links");
90
91         if (g != null)
92             switch (g.defaultFilter) {
93                 case WebGraph.NO_LINKS:
94                 case WebGraph.RETRIEVED_LINKS:
95                     pageChoice.select (0);
96                     linkChoice.select (0);
97                     break;
98                 case WebGraph.WALKED_LINKS:
99                 case WebGraph.TREE_LINKS:
100                     pageChoice.select (1);
101                     linkChoice.select (0);
102                     break;
103                 case WebGraph.ALL_LINKS:
104                     pageChoice.select (1);
105                     linkChoice.select (1);
106                     break;
107             }
108         else {
109             pageChoice.select (o.defaultFilter == WebOutline.ALL_LINKS ? 1 : 0);
110             linkChoice.disable ();
111         }
112
113
114         Constrain.add (this, automatic = new Checkbox ("Automatic layout"),
115                        Constrain.labelLike (1, 3));
116         if (g != null)
117             automatic.setState (g.getAutomaticLayout ());
118         else
119             g.disable ();
120
121         Panel panel;
122         Constrain.add (this, panel = new Panel(),
123                        Constrain.centered (Constrain.labelLike (0, 4, 2)));
124         panel.add (applyButton = new Button ("Apply"));
125         panel.add (okButton = new Button ("OK"));
126         panel.add (cancelButton = new Button ("Cancel"));
127
128         pack ();
129     }
130
131     void writeBack () {
132         if (g != null) g.setAutomaticLayout (automatic.getState ());
133
134         switch (nodeChoice.getSelectedIndex ()) {
135         case 0:
136             if (g != null) g.setNodeRendering (WebGraph.ICON);
137             if (o != null) o.setNodeRendering (WebOutline.TITLE);
138             break;
139         case 1:
140             if (g != null) g.setNodeRendering (WebGraph.TITLE);
141             if (o != null) o.setNodeRendering (WebOutline.TITLE);
142             break;
143         case 2:
144             if (g != null) g.setNodeRendering (WebGraph.ABSOLUTE_URL);
145             if (o != null) o.setNodeRendering (WebOutline.ABSOLUTE_URL);
146             break;
147         case 3:
148             if (g != null) g.setNodeRendering (WebGraph.RELATIVE_URL);
149             if (o != null) o.setNodeRendering (WebOutline.RELATIVE_URL);
150             break;
151         }
152
153         switch (pageChoice.getSelectedIndex ()) {
154         case 0:
155             if (g != null) g.setLinkFilter (WebGraph.RETRIEVED_LINKS);
156             if (o != null) o.setLinkFilter (WebOutline.RETRIEVED_LINKS);
157             break;
158         case 1:
159             if (o != null) o.setLinkFilter (WebOutline.WALKED_LINKS);
160             switch (linkChoice.getSelectedIndex ()) {
161             case 0:
162                 if (g != null) g.setLinkFilter (WebGraph.WALKED_LINKS);
163                 break;
164             case 1:
165                 if (g != null) g.setLinkFilter (WebGraph.ALL_LINKS);
166                 break;
167             }
168             break;
169         }
170     }
171
172     public boolean handleEvent (Event event) {
173         if (event.id == Event.ACTION_EVENT) {
174             if (event.target == applyButton)
175                 writeBack ();
176             else if (event.target == okButton) {
177                 writeBack ();
178                 close ();
179             }
180             else if (event.target == cancelButton)
181                 close ();
182             else
183                 return super.handleEvent (event);
184         }
185         else if (event.id == Event.WINDOW_DESTROY)
186             dispose ();
187         else
188             return super.handleEvent (event);
189
190         return true;
191     }
192 }
193
Popular Tags