001: /*
002: * WebSphinx web-crawling toolkit
003: *
004: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
020: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
022: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
023: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: *
031: */
032:
033: package websphinx.workbench;
034:
035: import java.awt.*;
036: import java.io.*;
037: import java.net.URL;
038: import websphinx.*;
039: import rcm.awt.Constrain;
040: import rcm.awt.PopupDialog;
041: import rcm.awt.TabPanel;
042: import rcm.awt.BorderPanel;
043: import rcm.awt.ClosableFrame;
044: import rcm.util.Win;
045:
046: public class WorkbenchControlPanel extends PopupDialog {
047: WebGraph g;
048: WebOutline o;
049:
050: Choice nodeChoice;
051: Choice pageChoice;
052: Choice linkChoice;
053: Checkbox automatic;
054:
055: Button applyButton;
056: Button okButton;
057: Button cancelButton;
058:
059: public WorkbenchControlPanel(WebGraph g, WebOutline o) {
060: super (Win.findFrame(g != null ? (Component) g : (Component) o),
061: "Workbench Control Panel", true);
062:
063: this .g = g;
064: this .o = o;
065:
066: setLayout(new GridBagLayout());
067:
068: Constrain.add(this , new Label("Display:"), Constrain.labelLike(
069: 0, 0));
070: Constrain.add(this , nodeChoice = new Choice(), Constrain
071: .fieldLike(1, 0));
072: nodeChoice.addItem("icons");
073: nodeChoice.addItem("titles");
074: nodeChoice.addItem("absolute URLs");
075: nodeChoice.addItem("relative URLs");
076: nodeChoice.select(g != null ? g.defaultRendering
077: : o.defaultRendering + 1);
078:
079: Constrain.add(this , new Label("Pages:"), Constrain.labelLike(0,
080: 1));
081: Constrain.add(this , pageChoice = new Choice(), Constrain
082: .fieldLike(1, 1));
083: pageChoice.addItem("visited pages");
084: pageChoice.addItem("all pages");
085:
086: Constrain.add(this , new Label("Links:"), Constrain.labelLike(0,
087: 2));
088: Constrain.add(this , linkChoice = new Choice(), Constrain
089: .fieldLike(1, 2));
090: linkChoice.addItem("tree links");
091: linkChoice.addItem("all links");
092:
093: if (g != null)
094: switch (g.defaultFilter) {
095: case WebGraph.NO_LINKS:
096: case WebGraph.RETRIEVED_LINKS:
097: pageChoice.select(0);
098: linkChoice.select(0);
099: break;
100: case WebGraph.WALKED_LINKS:
101: case WebGraph.TREE_LINKS:
102: pageChoice.select(1);
103: linkChoice.select(0);
104: break;
105: case WebGraph.ALL_LINKS:
106: pageChoice.select(1);
107: linkChoice.select(1);
108: break;
109: }
110: else {
111: pageChoice
112: .select(o.defaultFilter == WebOutline.ALL_LINKS ? 1
113: : 0);
114: linkChoice.disable();
115: }
116:
117: Constrain.add(this ,
118: automatic = new Checkbox("Automatic layout"), Constrain
119: .labelLike(1, 3));
120: if (g != null)
121: automatic.setState(g.getAutomaticLayout());
122: else
123: g.disable();
124:
125: Panel panel;
126: Constrain.add(this , panel = new Panel(), Constrain
127: .centered(Constrain.labelLike(0, 4, 2)));
128: panel.add(applyButton = new Button("Apply"));
129: panel.add(okButton = new Button("OK"));
130: panel.add(cancelButton = new Button("Cancel"));
131:
132: pack();
133: }
134:
135: void writeBack() {
136: if (g != null)
137: g.setAutomaticLayout(automatic.getState());
138:
139: switch (nodeChoice.getSelectedIndex()) {
140: case 0:
141: if (g != null)
142: g.setNodeRendering(WebGraph.ICON);
143: if (o != null)
144: o.setNodeRendering(WebOutline.TITLE);
145: break;
146: case 1:
147: if (g != null)
148: g.setNodeRendering(WebGraph.TITLE);
149: if (o != null)
150: o.setNodeRendering(WebOutline.TITLE);
151: break;
152: case 2:
153: if (g != null)
154: g.setNodeRendering(WebGraph.ABSOLUTE_URL);
155: if (o != null)
156: o.setNodeRendering(WebOutline.ABSOLUTE_URL);
157: break;
158: case 3:
159: if (g != null)
160: g.setNodeRendering(WebGraph.RELATIVE_URL);
161: if (o != null)
162: o.setNodeRendering(WebOutline.RELATIVE_URL);
163: break;
164: }
165:
166: switch (pageChoice.getSelectedIndex()) {
167: case 0:
168: if (g != null)
169: g.setLinkFilter(WebGraph.RETRIEVED_LINKS);
170: if (o != null)
171: o.setLinkFilter(WebOutline.RETRIEVED_LINKS);
172: break;
173: case 1:
174: if (o != null)
175: o.setLinkFilter(WebOutline.WALKED_LINKS);
176: switch (linkChoice.getSelectedIndex()) {
177: case 0:
178: if (g != null)
179: g.setLinkFilter(WebGraph.WALKED_LINKS);
180: break;
181: case 1:
182: if (g != null)
183: g.setLinkFilter(WebGraph.ALL_LINKS);
184: break;
185: }
186: break;
187: }
188: }
189:
190: public boolean handleEvent(Event event) {
191: if (event.id == Event.ACTION_EVENT) {
192: if (event.target == applyButton)
193: writeBack();
194: else if (event.target == okButton) {
195: writeBack();
196: close();
197: } else if (event.target == cancelButton)
198: close();
199: else
200: return super .handleEvent(event);
201: } else if (event.id == Event.WINDOW_DESTROY)
202: dispose();
203: else
204: return super .handleEvent(event);
205:
206: return true;
207: }
208: }
|