1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * ResultTitle.java -- describe the contents of a ResultBox
|
---|
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 |
|
---|
30 | This class is used in the Phind java applet (Phind.java).
|
---|
31 |
|
---|
32 | ResultTitle is part of the result list displayed to the user. It lists the
|
---|
33 | phrase in the Result box, the number of expansions it occurs in, and the
|
---|
34 | number of documents it occurs in.
|
---|
35 |
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 | //package org.nzdl.gsdl.Phind;
|
---|
39 | package org.greenstone.applet.phind;
|
---|
40 | import java.awt.Canvas;
|
---|
41 | import java.awt.Graphics;
|
---|
42 | import java.awt.Font;
|
---|
43 | import java.awt.FontMetrics;
|
---|
44 | import java.awt.Dimension;
|
---|
45 | import java.awt.Color;
|
---|
46 |
|
---|
47 |
|
---|
48 | public class ResultTitle extends Canvas {
|
---|
49 |
|
---|
50 | // Other objects associated with this
|
---|
51 | Phind phind;
|
---|
52 | ResultBox parent;
|
---|
53 | ResultCanvas canvas;
|
---|
54 |
|
---|
55 | // fonts and font spacings to use
|
---|
56 | Font plain, bold;
|
---|
57 | Graphics g;
|
---|
58 |
|
---|
59 | // Create a ResultTitle from the ResultBox which is its parent.
|
---|
60 | ResultTitle(ResultBox p) {
|
---|
61 |
|
---|
62 | parent = p;
|
---|
63 | phind = p.phind;
|
---|
64 | canvas = p.c;
|
---|
65 | g = getGraphics();
|
---|
66 |
|
---|
67 | plain = phind.plainFont;
|
---|
68 | bold = phind.boldFont;
|
---|
69 |
|
---|
70 | // Note: the size() and resize() methods are deprecated, but the newer
|
---|
71 | // getSize() and setSize() methods fail in NetScape 4
|
---|
72 | Dimension d = getSize();
|
---|
73 | d.height = phind.fontSize + 10;
|
---|
74 | setSize(d);
|
---|
75 |
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 | public void update(Graphics g) {
|
---|
80 | paint(g);
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void paint(Graphics g) {
|
---|
84 |
|
---|
85 | // calculate the canvas size, margins, and spacing
|
---|
86 | Dimension canvasSize = getSize();
|
---|
87 |
|
---|
88 | g.setFont(plain);
|
---|
89 | int margin = g.getFontMetrics().stringWidth(" 8888 ");
|
---|
90 | int y = phind.fontSize + 5;
|
---|
91 |
|
---|
92 | int rightMargin = canvas.getSize().width;
|
---|
93 | int secondColumn = rightMargin - margin;
|
---|
94 | int firstColumn = secondColumn - margin;
|
---|
95 |
|
---|
96 | g.setColor(Color.white);
|
---|
97 | g.fillRect(0, 0, canvasSize.width, canvasSize.height);
|
---|
98 | g.setColor(Color.black);
|
---|
99 |
|
---|
100 |
|
---|
101 | // What is the phrase we are searching for?
|
---|
102 | String phrase = parent.searchPhrase.replace('+', ' ');
|
---|
103 |
|
---|
104 | // Construct the description phrase
|
---|
105 | String links = "";
|
---|
106 | if (parent.numberOfThesaurusLinks <= 0) {
|
---|
107 | links = "";
|
---|
108 | } else if (parent.numberOfThesaurusLinks == 1) {
|
---|
109 | links = "1 link";
|
---|
110 | } else if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) {
|
---|
111 | links = parent.numberOfThesaurusLinks + " links";
|
---|
112 | } else {
|
---|
113 | links = parent.thesaurusLinksRetrieved + " of "
|
---|
114 | + parent.numberOfThesaurusLinks + " links";
|
---|
115 | }
|
---|
116 |
|
---|
117 | String expansions = "";
|
---|
118 | if (parent.numberOfExpansions <= 0) {
|
---|
119 | expansions = "no phrases";
|
---|
120 | } else if (parent.numberOfExpansions == 1) {
|
---|
121 | expansions = "1 phrase";
|
---|
122 | } else if (parent.expansionsRetrieved == parent.numberOfExpansions) {
|
---|
123 | expansions = parent.numberOfExpansions + " phrases";
|
---|
124 | } else {
|
---|
125 | expansions = parent.expansionsRetrieved + " of "
|
---|
126 | + parent.numberOfExpansions + " phrases";
|
---|
127 | }
|
---|
128 |
|
---|
129 | String documents = "";
|
---|
130 | if (parent.numberOfDocuments <= 0) {
|
---|
131 | documents = "no documents";
|
---|
132 | } else if (parent.documentsRetrieved == 1) {
|
---|
133 | documents = "1 document";
|
---|
134 | } else if (parent.documentsRetrieved == parent.numberOfDocuments) {
|
---|
135 | documents = parent.numberOfDocuments + " documents";
|
---|
136 | } else {
|
---|
137 | documents = parent.documentsRetrieved + " of "
|
---|
138 | + parent.numberOfDocuments + " documents";
|
---|
139 | }
|
---|
140 |
|
---|
141 | String status = "(";
|
---|
142 | if (parent.numberOfThesaurusLinks > 0) {
|
---|
143 | status = status + links + ", ";
|
---|
144 | }
|
---|
145 | status = status + expansions + ", " + documents + ")";
|
---|
146 |
|
---|
147 |
|
---|
148 | // Draw the text
|
---|
149 | g.setFont(bold);
|
---|
150 | g.drawString(phrase, 0, y);
|
---|
151 | int tab = g.getFontMetrics().stringWidth(phrase + " ");
|
---|
152 |
|
---|
153 | g.setFont(plain);
|
---|
154 | g.drawString(status, tab, y);
|
---|
155 | tab = tab + g.getFontMetrics().stringWidth(status);
|
---|
156 |
|
---|
157 | if (tab < firstColumn) {
|
---|
158 | g.drawString("docs", firstColumn, y);
|
---|
159 | g.drawString("freq", secondColumn, y);
|
---|
160 | }
|
---|
161 | }
|
---|
162 | }
|
---|