source: main/trunk/greenstone3/src/java/org/greenstone/applet/phind/JResultDisplay.java@ 38800

Last change on this file since 38800 was 38800, checked in by anupama, 4 months ago

Added some extra class comments to indicate the new classes added are swing ports to work with the new JAppelt JPhind (instead of the old awt Applet Phind). The port of the phind applet's classes from awt to swing are with an eye on getting the Phind applet to work with webswing which doesn't work with awt Applets only with JApplet, as Dr Bainbridge had warned.

File size: 3.6 KB
Line 
1/**********************************************************************
2 *
3 * ResultDisplay.java -- Phrase list holder for Phind java applet
4 *
5 * Copyright 1997-2000 Gordon W. Paynter
6 * Copyright 2000 The New Zealand Digital Library Project
7 *
8 * A component of the Greenstone digital library software
9 * from the New Zealand Digital Library Project at the
10 * University of Waikato, New Zealand.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 *********************************************************************/
27
28/*********************************************************************
29
30JResultDisplay is a swing port of awt ResultDisplay to be used by swing
31JPhind JApplet a.o.t Phind awt Applet.
32
33This class is used in the Phind java applet (Phind.java).
34
35A ResultDisplay is a Panel that can display a single Component, which will
36be a ResultBox or PhindTitle object.
37
38ResultBoxes can be "chained" together with their "prev" and "next" fields,
39allowing us to have an arbitrary number of "displays" in which to show
40phrase lists.
41
42Main methods:
43* emptyContents will remove the component and emptyAll the "next" display
44* display will add an item to the first (ie: most "prev") available box
45
46**********************************************************************/
47package org.greenstone.applet.phind;
48//package org.nzdl.gsdl.Phind;
49
50import javax.swing.JPanel;
51import javax.swing.JComponent;
52import java.awt.BorderLayout;
53
54
55class JResultDisplay extends JPanel {
56
57 JPhind phind;
58 JResultDisplay prev, next;
59 JComponent current;
60 boolean empty;
61
62 // Create a new Display
63 JResultDisplay(JPhind ph, JResultDisplay pr) {
64 phind = ph;
65 prev = pr;
66 next = null;
67 if (prev != null) prev.next = this;
68 setLayout(new BorderLayout());
69
70 empty = true;
71 current = new JPhindTitle(ph);
72 add(current);
73 }
74
75 // Empty the contents of the display,
76 // and all the next displays
77 void emptyContents() {
78 if (empty == false) {
79 empty = true;
80 current = new JPhindTitle(phind);
81 removeAll();
82 add(current);
83 }
84 if (next != null) next.emptyContents();
85 }
86
87 // Set the contents of this display
88 JComponent setContents( JComponent r ) {
89 removeAll();
90 add(r, BorderLayout.CENTER);
91 current = r;
92 empty = false;
93 if (r.getClass().getName().equals("ResultBox")) {
94 ((JResultBox) r).display = this;
95 }
96 return r;
97 }
98
99
100
101 // Display a component in the "most previous" display
102 JResultDisplay display( JComponent r ) {
103
104 if (prev == null) {
105 // if there is no previous box, add the component here
106 setContents(r);
107 return this;
108
109 } else if (prev.empty == true) {
110 // if the previous box is empty, add the component to it instead
111 return prev.display(r);
112
113 } else if (empty == true) {
114 // if this box is empty, add the component to it
115 setContents(r);
116 return this;
117
118 } else {
119 // if this box is occupied,
120 // shift it's contents prev-wards and add here.
121 prev.display(current);
122 setContents(r);
123 return this;
124 }
125 }
126
127}
128
129
130
Note: See TracBrowser for help on using the repository browser.