source: main/trunk/greenstone3/src/java/org/greenstone/applet/phind/JResultTitle.java@ 38799

Last change on this file since 38799 was 38799, checked in by anupama, 4 months ago
  1. ScrollPane wasn't being used and it didn't workout with the way the code used the scrollbar to calculate positioning, so I instantiated and used a JScrollBar instead in the same manner the awt ScrollBar was being used. 2. JResultTitle bar (JResultBox's row of column headings) wasn't appearing and neither was the scrollbar, or else the centre pane (ResultCanvas with results) wasn't appearing. The layout wasn't working except on resize. The solution was that ordering of adding to the layout had an effect. (Instantiating the objects added to the layout was order dependent also, as one kept a pointer to the other.) The solution turned to setPreferredSize() on the JResultTitle in its constructor, rather than calling setSize(). This fixed the layout and now I don't want to fiddle with it any more as it works out for the JApplet just as for the Applet, and still works when the JPhind JApplet class is run as an application from the commandline as well.
File size: 4.8 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//package org.nzdl.gsdl.Phind;
39package org.greenstone.applet.phind;
40import javax.swing.JComponent; //import java.awt.Canvas;
41import java.awt.Graphics;
42import java.awt.Font;
43import java.awt.FontMetrics;
44import java.awt.Dimension;
45import java.awt.Color;
46
47
48public class JResultTitle extends JComponent {
49
50 // Other objects associated with this
51 JPhind phind;
52 JResultBox parent;
53 JResultCanvas 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 JResultTitle(JResultBox 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 setPreferredSize(d);
75
76 }
77
78
79 public void paintComponent(Graphics g) {
80 super.paintComponent(g);
81
82 // calculate the canvas size, margins, and spacing
83 Dimension canvasSize = getSize();
84
85 g.setFont(plain);
86 int margin = g.getFontMetrics().stringWidth(" 8888 ");
87 int y = phind.fontSize + 5;
88
89 int rightMargin = canvas.getSize().width;
90 int secondColumn = rightMargin - margin;
91 int firstColumn = secondColumn - margin;
92
93 g.setColor(Color.white);
94 g.fillRect(0, 0, canvasSize.width, canvasSize.height);
95 g.setColor(Color.black);
96
97
98 // What is the phrase we are searching for?
99 String phrase = parent.searchPhrase.replace('+', ' ');
100
101 // Construct the description phrase
102 String links = "";
103 if (parent.numberOfThesaurusLinks <= 0) {
104 links = "";
105 } else if (parent.numberOfThesaurusLinks == 1) {
106 links = "1 link";
107 } else if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) {
108 links = parent.numberOfThesaurusLinks + " links";
109 } else {
110 links = parent.thesaurusLinksRetrieved + " of "
111 + parent.numberOfThesaurusLinks + " links";
112 }
113
114 String expansions = "";
115 if (parent.numberOfExpansions <= 0) {
116 expansions = "no phrases";
117 } else if (parent.numberOfExpansions == 1) {
118 expansions = "1 phrase";
119 } else if (parent.expansionsRetrieved == parent.numberOfExpansions) {
120 expansions = parent.numberOfExpansions + " phrases";
121 } else {
122 expansions = parent.expansionsRetrieved + " of "
123 + parent.numberOfExpansions + " phrases";
124 }
125
126 String documents = "";
127 if (parent.numberOfDocuments <= 0) {
128 documents = "no documents";
129 } else if (parent.documentsRetrieved == 1) {
130 documents = "1 document";
131 } else if (parent.documentsRetrieved == parent.numberOfDocuments) {
132 documents = parent.numberOfDocuments + " documents";
133 } else {
134 documents = parent.documentsRetrieved + " of "
135 + parent.numberOfDocuments + " documents";
136 }
137
138 String status = "(";
139 if (parent.numberOfThesaurusLinks > 0) {
140 status = status + links + ", ";
141 }
142 status = status + expansions + ", " + documents + ")";
143
144
145 // Draw the text
146 g.setFont(bold);
147 g.drawString(phrase, 0, y);
148 int tab = g.getFontMetrics().stringWidth(phrase + " ");
149
150 g.setFont(plain);
151 g.drawString(status, tab, y);
152 tab = tab + g.getFontMetrics().stringWidth(status);
153
154 if (tab < firstColumn) {
155 g.drawString("docs", firstColumn, y);
156 g.drawString("freq", secondColumn, y);
157 }
158 }
159}
Note: See TracBrowser for help on using the repository browser.