source: trunk/gsdl/src/phind/client/ResultTitle.java@ 1681

Last change on this file since 1681 was 1681, checked in by paynter, 24 years ago

Eliminated all calls to getSize() and setSize() and replaced them with
size() and resize(). This is a backwards step in the sense that size and
resize are deprecated, but setSize and getSize don't work on some browsers.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
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
30This class is used in the Phind java applet (Phind.java).
31
32ResultTitle is part of the result list displayed to the user. It lists the
33phrase in the Result box, the number of expansions it occurs in, and the
34number of documents it occurs in.
35
36**********************************************************************/
37
38
39import java.awt.Canvas;
40import java.awt.Graphics;
41import java.awt.Font;
42import java.awt.FontMetrics;
43import java.awt.Dimension;
44import java.awt.Color;
45
46
47public class ResultTitle extends Canvas {
48
49 // Other objects associated with this
50 Phind phind;
51 ResultBox parent;
52 ResultCanvas canvas;
53
54 // fonts and font spacings to use
55 Font plain, bold;
56 Graphics g;
57
58 // Create a ResultTitle from the ResultBox which is its parent.
59 ResultTitle(ResultBox p) {
60
61 parent = p;
62 phind = p.phind;
63 canvas = p.c;
64 g = getGraphics();
65
66 plain = phind.plainFont;
67 bold = phind.boldFont;
68
69 // Note: the size() and resize() methods are deprecated, but the newer
70 // getSize() and setSize() methods fail in NetScape 4
71 //Dimension d = getSize();
72 Dimension d = size();
73 d.height = phind.fontSize + 10;
74 //setSize(d);
75 resize(d);
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 = size();
87
88 g.setFont(plain);
89 int margin = g.getFontMetrics().stringWidth(" 8888 ");
90 int y = phind.fontSize + 5;
91
92 int rightMargin = canvas.size().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 expansions = "";
106 if (parent.numberOfExpansions <= 0) {
107 expansions = "no phrases";
108 } else if (parent.numberOfExpansions == 1) {
109 expansions = "1 phrase";
110 } else if (parent.expansionsRetrieved == parent.numberOfExpansions) {
111 expansions = parent.numberOfExpansions + " phrases";
112 } else {
113 expansions = "first " + parent.expansionsRetrieved + " of " + parent.numberOfExpansions + " phrases";
114 }
115
116 String documents = "";
117 if (parent.numberOfDocuments <= 0) {
118 documents = "no documents";
119 } else if (parent.documentsRetrieved == 1) {
120 documents = "1 document";
121 } else if (parent.documentsRetrieved == parent.numberOfDocuments) {
122 documents = parent.numberOfDocuments + " documents";
123 } else {
124 documents = "first " + parent.documentsRetrieved + " of " + parent.numberOfDocuments + " documents";
125 }
126
127 // Draw the text
128 g.setFont(bold);
129 g.drawString(phrase, 0, y);
130 int tab = g.getFontMetrics().stringWidth(phrase + " ");
131
132 g.setFont(plain);
133 String status = "(" + expansions + ", " + documents + ")";
134 g.drawString(status, tab, y);
135 tab = tab + g.getFontMetrics().stringWidth(status);
136
137 if (tab < firstColumn) {
138 g.drawString("docs", firstColumn, y);
139 g.drawString("freq", secondColumn, y);
140 }
141 }
142}
Note: See TracBrowser for help on using the repository browser.