|
001 /*
002 * AP(r) Computer Science GridWorld Case Study:
003 * Copyright(c) 2002-2006 College Entrance Examination Board
004 * (http://www.collegeboard.com).
005 *
006 * This code is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation.
009 *
010 * This code is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License forfor is a looping structure for repeatedly executing a block of code more details.
014 *
015 * @authorthis is the Javadoc tag for documenting who created the source code Julie Zelenski
016 * @authorthis is the Javadoc tag for documenting who created the source code Cay Horstmann
017 */
018
019 packagepackage is used to name the directory or folder a class is in info.gridworld.gui;
020
021 importimport means to make the classes and/or packages available in this program info.gridworld.grid.Grid;
022 importimport means to make the classes and/or packages available in this program info.gridworld.grid.Location;
023
024 importimport means to make the classes and/or packages available in this program java.awt.Color;
025 importimport means to make the classes and/or packages available in this program java.awt.Component;
026 importimport means to make the classes and/or packages available in this program java.awt.Dimension;
027 importimport means to make the classes and/or packages available in this program java.awt.Font;
028 importimport means to make the classes and/or packages available in this program java.awt.Graphics;
029 importimport means to make the classes and/or packages available in this program java.awt.Graphics2D;
030 importimport means to make the classes and/or packages available in this program java.awt.Insets;
031 importimport means to make the classes and/or packages available in this program java.awt.Point;
032 importimport means to make the classes and/or packages available in this program java.awt.Rectangle;
033 importimport means to make the classes and/or packages available in this program java.awt.RenderingHints;
034 importimport means to make the classes and/or packages available in this program java.awt.event.ActionEvent;
035 importimport means to make the classes and/or packages available in this program java.awt.event.ActionListener;
036 importimport means to make the classes and/or packages available in this program java.awt.event.MouseEvent;
037 importimport means to make the classes and/or packages available in this program java.awt.font.FontRenderContext;
038 importimport means to make the classes and/or packages available in this program java.awt.font.LineMetrics;
039 importimport means to make the classes and/or packages available in this program java.awt.geom.Rectangle2D;
040 importimport means to make the classes and/or packages available in this program java.text.MessageFormat;
041 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
042 importimport means to make the classes and/or packages available in this program java.util.ResourceBundle;
043
044 importimport means to make the classes and/or packages available in this program javax.swing.JPanel;
045 importimport means to make the classes and/or packages available in this program javax.swing.JToolTip;
046 importimport means to make the classes and/or packages available in this program javax.swing.JViewport;
047 importimport means to make the classes and/or packages available in this program javax.swing.Scrollable;
048 importimport means to make the classes and/or packages available in this program javax.swing.SwingConstants;
049 importimport means to make the classes and/or packages available in this program javax.swing.SwingUtilities;
050 importimport means to make the classes and/or packages available in this program javax.swing.Timer;
051 importimport means to make the classes and/or packages available in this program javax.swing.ToolTipManager;
052
053 /**
054 * A <code>GridPanel</code> is a panel containing a graphical display of the
055 * grid occupants. <br />
056 * This code is not tested on the AP CS A and AB exams. It contains GUI
057 * implementation details that are not intended to be understood by AP CS
058 * students.
059 */
060
061 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects GridPanel extendsextends means to customize or extend the functionality of a class JPanel implementsimplements means providing method bodies for the methods declared in the corresponding interface Scrollable,
062 PseudoInfiniteViewport.Pannable
063 {open braces start code blocks and must be matched with a close brace
064 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer MIN_CELL_SIZE =this assignment operator makes the left side equal to the right side 12;
065 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer DEFAULT_CELL_SIZE =this assignment operator makes the left side equal to the right side 48;
066 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer DEFAULT_CELL_COUNT =this assignment operator makes the left side equal to the right side 10;
067 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer TIP_DELAY =this assignment operator makes the left side equal to the right side 1000;
068
069 privateprivate is used to restrict access to the current class only Grid<?> grid;
070 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer numRows, numCols, originRow, originCol;
071 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer cellSize; // the size of each cell, EXCLUDING the gridlines
072 privateprivate is used to restrict access to the current class only booleanboolean is a type that is either true or false toolTipsEnabled;
073 privateprivate is used to restrict access to the current class only Color backgroundColor =this assignment operator makes the left side equal to the right side Color.WHITE;
074 privateprivate is used to restrict access to the current class only ResourceBundle resources;
075 privateprivate is used to restrict access to the current class only DisplayMap displayMap;
076 privateprivate is used to restrict access to the current class only Location currentLocation;
077 privateprivate is used to restrict access to the current class only Timer tipTimer;
078 privateprivate is used to restrict access to the current class only JToolTip tip;
079 privateprivate is used to restrict access to the current class only JPanel glassPane;
080
081 /**
082 * Construct a newnew is used to create objects by calling the constructor GridPanel object with no grid. The view will be
083 * empty.
084 */
085 publicpublic is used to indicate unrestricted access (any other class can have access) GridPanel(DisplayMap map, ResourceBundle res)
086 {open braces start code blocks and must be matched with a close brace
087 displayMap =this assignment operator makes the left side equal to the right side map;
088 resources =this assignment operator makes the left side equal to the right side res;
089 setToolTipsEnabled(truetrue is the boolean value that is the opposite of false);
090 }close braces end code blocks and must match an earlier open brace
091
092 /**
093 * Paint thisthis means the current object (the implicit parameter) component.
094 * @paramthis is the Javadoc tag for documenting the purpose of parameters g the Graphics object to use to render thisthis means the current object (the implicit parameter) component
095 */
096 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value paintComponent(Graphics g)
097 {open braces start code blocks and must be matched with a close brace
098 Graphics2D g2 =this assignment operator makes the left side equal to the right side (Graphics2D) g;
099
100 super.paintComponent(g2);
101 ifif executes the next statement only if the condition in parenthesis evaluates to true (grid ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object)
102 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
103
104 Insets insets =this assignment operator makes the left side equal to the right side getInsets();
105 g2.setColor(backgroundColor);
106 g2.fillRect(insets.left, insets.top, numCols * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1, numRows
107 * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1);
108
109 drawWatermark(g2);
110 drawGridlines(g2);
111 drawOccupants(g2);
112 drawCurrentLocation(g2);
113 }close braces end code blocks and must match an earlier open brace
114
115 /**
116 * Draw one occupant object. First verify that the object is actually
117 * visible before any drawing, set up the clip appropriately and use the
118 * DisplayMap to determine which object to call upon to render thisthis means the current object (the implicit parameter)
119 * particular Locatable. Note that we save and restore the graphics
120 * transform to restore back to normalcy no matter what the renderer did to
121 * to the coordinate system.
122 * @paramthis is the Javadoc tag for documenting the purpose of parameters g2 the Graphics2D object to use to render
123 * @paramthis is the Javadoc tag for documenting the purpose of parameters xleft the leftmost pixel of the rectangle
124 * @paramthis is the Javadoc tag for documenting the purpose of parameters ytop the topmost pixel of the rectangle
125 * @paramthis is the Javadoc tag for documenting the purpose of parameters obj the Locatable object to draw
126 */
127 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value drawOccupant(Graphics2D g2, intint is the type for whole numbers and it is short for integer xleft, intint is the type for whole numbers and it is short for integer ytop, Object obj)
128 {open braces start code blocks and must be matched with a close brace
129 Rectangle cellToDraw =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Rectangle(xleft, ytop, cellSize, cellSize);
130
131 // Only draw if the object is visible within the current clipping
132 // region.
133 ifif executes the next statement only if the condition in parenthesis evaluates to true (cellToDraw.intersects(g2.getClip().getBounds()))
134 {open braces start code blocks and must be matched with a close brace
135 Graphics2D g2copy =this assignment operator makes the left side equal to the right side (Graphics2D) g2.create();
136 g2copy.clip(cellToDraw);
137 // Get the drawing object to display this occupant.
138 Display displayObj =this assignment operator makes the left side equal to the right side displayMap.findDisplayFor(obj.getClass());
139 displayObj.draw(obj, thisthis means the current object (the implicit parameter), g2copy, cellToDraw);
140 g2copy.dispose();
141 }close braces end code blocks and must match an earlier open brace
142 }close braces end code blocks and must match an earlier open brace
143
144 /**
145 * Draw the gridlines forfor is a looping structure for repeatedly executing a block of code the grid. We only draw the portion of the
146 * lines that intersect the current clipping bounds.
147 * @paramthis is the Javadoc tag for documenting the purpose of parameters g2 the Graphics2 object to use to render
148 */
149 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value drawGridlines(Graphics2D g2)
150 {open braces start code blocks and must be matched with a close brace
151 Rectangle curClip =this assignment operator makes the left side equal to the right side g2.getClip().getBounds();
152 intint is the type for whole numbers and it is short for integer top =this assignment operator makes the left side equal to the right side getInsets().top, left =this assignment operator makes the left side equal to the right side getInsets().left;
153
154 intint is the type for whole numbers and it is short for integer miny =this assignment operator makes the left side equal to the right side Math.max(0, (curClip.y - top) / (cellSize +adds two numbers together or concatenates Strings together 1)) * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together top;
155 intint is the type for whole numbers and it is short for integer minx =this assignment operator makes the left side equal to the right side Math.max(0, (curClip.x - left) / (cellSize +adds two numbers together or concatenates Strings together 1)) * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together left;
156 intint is the type for whole numbers and it is short for integer maxy =this assignment operator makes the left side equal to the right side Math.min(numRows,
157 (curClip.y +adds two numbers together or concatenates Strings together curClip.height - top +adds two numbers together or concatenates Strings together cellSize) / (cellSize +adds two numbers together or concatenates Strings together 1))
158 * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together top;
159 intint is the type for whole numbers and it is short for integer maxx =this assignment operator makes the left side equal to the right side Math.min(numCols,
160 (curClip.x +adds two numbers together or concatenates Strings together curClip.width - left +adds two numbers together or concatenates Strings together cellSize) / (cellSize +adds two numbers together or concatenates Strings together 1))
161 * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together left;
162
163 g2.setColor(Color.GRAY);
164 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer y =this assignment operator makes the left side equal to the right side miny; y <=this evaluates to true if the left side is not more than the right side maxy; y +=this increases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1)
165 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer x =this assignment operator makes the left side equal to the right side minx; x <=this evaluates to true if the left side is not more than the right side maxx; x +=this increases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1)
166 {open braces start code blocks and must be matched with a close brace
167 Location loc =this assignment operator makes the left side equal to the right side locationForPoint(
168 newnew is used to create objects by calling the constructor Point(x +adds two numbers together or concatenates Strings together cellSize / 2, y +adds two numbers together or concatenates Strings together cellSize / 2));
169 ifif executes the next statement only if the condition in parenthesis evaluates to true (loc !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) !this is the not operator, which changes true to false and false to truegrid.isValid(loc))
170 g2.fillRect(x +adds two numbers together or concatenates Strings together 1, y +adds two numbers together or concatenates Strings together 1, cellSize, cellSize);
171 }close braces end code blocks and must match an earlier open brace
172
173 g2.setColor(Color.BLACK);
174 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer y =this assignment operator makes the left side equal to the right side miny; y <=this evaluates to true if the left side is not more than the right side maxy; y +=this increases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1)
175 // draw horizontal lines
176 g2.drawLine(minx, y, maxx, y);
177
178 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer x =this assignment operator makes the left side equal to the right side minx; x <=this evaluates to true if the left side is not more than the right side maxx; x +=this increases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1)
179 // draw vertical lines
180 g2.drawLine(x, miny, x, maxy);
181 }close braces end code blocks and must match an earlier open brace
182
183 /**
184 * Draws the occupants of the grid.
185 * @paramthis is the Javadoc tag for documenting the purpose of parameters g2 the graphics context
186 */
187 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value drawOccupants(Graphics2D g2)
188 {open braces start code blocks and must be matched with a close brace
189 ArrayList<Location> occupantLocs =this assignment operator makes the left side equal to the right side grid.getOccupiedLocations();
190 forfor is a looping structure for repeatedly executing a block of code (intint is the type for whole numbers and it is short for integer index =this assignment operator makes the left side equal to the right side 0; index < occupantLocs.size(); index++this is the increment operator, which increases the variable by 1)
191 {open braces start code blocks and must be matched with a close brace
192 Location loc =this assignment operator makes the left side equal to the right side (Location) occupantLocs.get(index);
193
194 intint is the type for whole numbers and it is short for integer xleft =this assignment operator makes the left side equal to the right side colToXCoord(loc.getCol());
195 intint is the type for whole numbers and it is short for integer ytop =this assignment operator makes the left side equal to the right side rowToYCoord(loc.getRow());
196 drawOccupant(g2, xleft, ytop, grid.get(loc));
197 }close braces end code blocks and must match an earlier open brace
198 }close braces end code blocks and must match an earlier open brace
199
200 /**
201 * Draws a square that marks the current location.
202 * @paramthis is the Javadoc tag for documenting the purpose of parameters g2 the graphics context
203 */
204 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value drawCurrentLocation(Graphics2D g2)
205 {open braces start code blocks and must be matched with a close brace
206 trytry is for executing a code block that may experience exceptions (errors)
207 {open braces start code blocks and must be matched with a close brace
208 ifif executes the next statement only if the condition in parenthesis evaluates to true ("hide".equals(System.getProperty("info.gridworld.gui.selection")))
209 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
210 }close braces end code blocks and must match an earlier open brace
211 catchcatch means to handle an exception that may occur (SecurityException ex)
212 {open braces start code blocks and must be matched with a close brace
213 // oh well...
214 }close braces end code blocks and must match an earlier open brace
215 ifif executes the next statement only if the condition in parenthesis evaluates to true (currentLocation !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)
216 {open braces start code blocks and must be matched with a close brace
217 Point p =this assignment operator makes the left side equal to the right side pointForLocation(currentLocation);
218 g2.drawRect(p.x - cellSize / 2 - 2, p.y - cellSize / 2 - 2,
219 cellSize +adds two numbers together or concatenates Strings together 3, cellSize +adds two numbers together or concatenates Strings together 3);
220 }close braces end code blocks and must match an earlier open brace
221 }close braces end code blocks and must match an earlier open brace
222
223 /**
224 * Draws a watermark that shows the version number ifif executes the next statement only if the condition in parenthesis evaluates to true it is < 1.0
225 * @paramthis is the Javadoc tag for documenting the purpose of parameters g2 the graphics context
226 */
227 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value drawWatermark(Graphics2D g2)
228 {open braces start code blocks and must be matched with a close brace
229 String versionId =this assignment operator makes the left side equal to the right side resources.getString("version.id");
230 ifif executes the next statement only if the condition in parenthesis evaluates to true ("1.00".compareTo(versionId) ==this is the comparison operator which evaluates to true if both sides are the same 0) returnreturn means to provide the result of the method and/or cease execution of the method immediately; // TODO: Better mechanism
231
232 trytry is for executing a code block that may experience exceptions (errors)
233 {open braces start code blocks and must be matched with a close brace
234 ifif executes the next statement only if the condition in parenthesis evaluates to true ("hide".equals(System.getProperty("info.gridworld.gui.watermark")))
235 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
236 }close braces end code blocks and must match an earlier open brace
237 catchcatch means to handle an exception that may occur (SecurityException ex)
238 {open braces start code blocks and must be matched with a close brace
239 // oh well...
240 }close braces end code blocks and must match an earlier open brace
241
242 g2 =this assignment operator makes the left side equal to the right side (Graphics2D) g2.create();
243 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
244 RenderingHints.VALUE_ANTIALIAS_ON);
245 Rectangle rect =this assignment operator makes the left side equal to the right side getBounds();
246 g2.setPaint(newnew is used to create objects by calling the constructor Color(0xE3, 0xD3, 0xD3));
247 finalfinal means not changeable (often used for constants) intint is the type for whole numbers and it is short for integer WATERMARK_FONT_SIZE =this assignment operator makes the left side equal to the right side 100;
248 g2.setFont(newnew is used to create objects by calling the constructor Font("SansSerif", Font.BOLD, WATERMARK_FONT_SIZE));
249 FontRenderContext frc =this assignment operator makes the left side equal to the right side g2.getFontRenderContext();
250 Rectangle2D bounds =this assignment operator makes the left side equal to the right side g2.getFont().getStringBounds(versionId, frc);
251 floatfloat is the type for numbers that can contain decimal fractions centerX =this assignment operator makes the left side equal to the right side rect.x +adds two numbers together or concatenates Strings together rect.width / 2;
252 floatfloat is the type for numbers that can contain decimal fractions centerY =this assignment operator makes the left side equal to the right side rect.y +adds two numbers together or concatenates Strings together rect.height / 2;
253 floatfloat is the type for numbers that can contain decimal fractions leftX =this assignment operator makes the left side equal to the right side centerX - (floatfloat is the type for numbers that can contain decimal fractions) bounds.getWidth() / 2;
254 LineMetrics lm =this assignment operator makes the left side equal to the right side g2.getFont().getLineMetrics(versionId, frc);
255 floatfloat is the type for numbers that can contain decimal fractions baselineY =this assignment operator makes the left side equal to the right side centerY - lm.getHeight() / 2 +adds two numbers together or concatenates Strings together lm.getAscent();
256 g2.drawString(versionId, leftX, baselineY);
257 }close braces end code blocks and must match an earlier open brace
258
259 /**
260 * Enables/disables showing of tooltip giving information about the
261 * occupant beneath the mouse.
262 * @paramthis is the Javadoc tag for documenting the purpose of parameters flag truetrue is the boolean value that is the opposite of false/falsefalse is a value for the boolean type and means not true to enable/disable tool tips
263 */
264 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setToolTipsEnabled(booleanboolean is a type that is either true or false flag)
265 {open braces start code blocks and must be matched with a close brace
266 trytry is for executing a code block that may experience exceptions (errors)
267 {open braces start code blocks and must be matched with a close brace
268 ifif executes the next statement only if the condition in parenthesis evaluates to true ("hide".equals(System.getProperty("info.gridworld.gui.tooltips")))
269 flag =this assignment operator makes the left side equal to the right side falsefalse is a value for the boolean type and means not true;
270 }close braces end code blocks and must match an earlier open brace
271 catchcatch means to handle an exception that may occur (SecurityException ex)
272 {open braces start code blocks and must be matched with a close brace
273 // oh well...
274 }close braces end code blocks and must match an earlier open brace
275 ifif executes the next statement only if the condition in parenthesis evaluates to true (flag)
276 ToolTipManager.sharedInstance().registerComponent(thisthis means the current object (the implicit parameter));
277 elseelse is what happens when the if condition is false
278 ToolTipManager.sharedInstance().unregisterComponent(thisthis means the current object (the implicit parameter));
279 toolTipsEnabled =this assignment operator makes the left side equal to the right side flag;
280 }close braces end code blocks and must match an earlier open brace
281
282 /**
283 * Sets the grid being displayed. Reset the cellSize to be the
284 * largest that fits the entire grid in the current visible area (use
285 * defaultdefault is what is executed when no cases are matched ifif executes the next statement only if the condition in parenthesis evaluates to true grid is too large).
286 * @paramthis is the Javadoc tag for documenting the purpose of parameters gr the grid to display
287 */
288 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setGrid(Grid<?> gr)
289 {open braces start code blocks and must be matched with a close brace
290 currentLocation =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Location(0, 0);
291 JViewport vp =this assignment operator makes the left side equal to the right side getEnclosingViewport(); // before changing, reset
292 // scroll/pan position
293 ifif executes the next statement only if the condition in parenthesis evaluates to true (vp !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)
294 vp.setViewPosition(newnew is used to create objects by calling the constructor Point(0, 0));
295
296 grid =this assignment operator makes the left side equal to the right side gr;
297 originRow =this assignment operator makes the left side equal to the right side originCol =this assignment operator makes the left side equal to the right side 0;
298
299 ifif executes the next statement only if the condition in parenthesis evaluates to true (grid.getNumRows() ==this is the comparison operator which evaluates to true if both sides are the same -1 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) grid.getNumCols() ==this is the comparison operator which evaluates to true if both sides are the same -1)
300 {open braces start code blocks and must be matched with a close brace
301 numRows =this assignment operator makes the left side equal to the right side numCols =this assignment operator makes the left side equal to the right side 2000;
302 // This determines the "virtual" size of the pan world
303 }close braces end code blocks and must match an earlier open brace
304 elseelse is what happens when the if condition is false
305 {open braces start code blocks and must be matched with a close brace
306 numRows =this assignment operator makes the left side equal to the right side grid.getNumRows();
307 numCols =this assignment operator makes the left side equal to the right side grid.getNumCols();
308 }close braces end code blocks and must match an earlier open brace
309 recalculateCellSize(MIN_CELL_SIZE);
310 }close braces end code blocks and must match an earlier open brace
311
312 // private helpers to calculate extra width/height needs for borders/insets.
313 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer extraWidth()
314 {open braces start code blocks and must be matched with a close brace
315 returnreturn means to provide the result of the method and/or cease execution of the method immediately getInsets().left +adds two numbers together or concatenates Strings together getInsets().right;
316 }close braces end code blocks and must match an earlier open brace
317
318 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer extraHeight()
319 {open braces start code blocks and must be matched with a close brace
320 returnreturn means to provide the result of the method and/or cease execution of the method immediately getInsets().top +adds two numbers together or concatenates Strings together getInsets().left;
321 }close braces end code blocks and must match an earlier open brace
322
323 /**
324 * Returns the desired size of the display, forfor is a looping structure for repeatedly executing a block of code use by layout manager.
325 * @returnnull preferred size
326 */
327 publicpublic is used to indicate unrestricted access (any other class can have access) Dimension getPreferredSize()
328 {open braces start code blocks and must be matched with a close brace
329 returnreturn means to provide the result of the method and/or cease execution of the method immediately newnew is used to create objects by calling the constructor Dimension(numCols * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together extraWidth(),
330 numRows * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together extraHeight());
331 }close braces end code blocks and must match an earlier open brace
332
333 /**
334 * Returns the minimum size of the display, forfor is a looping structure for repeatedly executing a block of code use by layout manager.
335 * @returnnull minimum size
336 */
337 publicpublic is used to indicate unrestricted access (any other class can have access) Dimension getMinimumSize()
338 {open braces start code blocks and must be matched with a close brace
339 returnreturn means to provide the result of the method and/or cease execution of the method immediately newnew is used to create objects by calling the constructor Dimension(numCols * (MIN_CELL_SIZE +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together extraWidth(),
340 numRows * (MIN_CELL_SIZE +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together extraHeight());
341 }close braces end code blocks and must match an earlier open brace
342
343 /**
344 * Zooms in the display by doubling the current cell size.
345 */
346 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value zoomIn()
347 {open braces start code blocks and must be matched with a close brace
348 cellSize *=this multiplies the variable on the left by the value on the right and stores the result in the variable 2;
349 revalidate();
350 }close braces end code blocks and must match an earlier open brace
351
352 /**
353 * Zooms out the display by halving the current cell size.
354 */
355 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value zoomOut()
356 {open braces start code blocks and must be matched with a close brace
357 cellSize =this assignment operator makes the left side equal to the right side Math.max(cellSize / 2, MIN_CELL_SIZE);
358 revalidate();
359 }close braces end code blocks and must match an earlier open brace
360
361 /**
362 * Pans the display back to the origin, so that 0, 0 is at the the upper
363 * left of the visible viewport.
364 */
365 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value recenter(Location loc)
366 {open braces start code blocks and must be matched with a close brace
367 originRow =this assignment operator makes the left side equal to the right side loc.getRow();
368 originCol =this assignment operator makes the left side equal to the right side loc.getCol();
369 repaint();
370 JViewport vp =this assignment operator makes the left side equal to the right side getEnclosingViewport();
371 ifif executes the next statement only if the condition in parenthesis evaluates to true (vp !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)
372 {open braces start code blocks and must be matched with a close brace
373 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to trueisPannableUnbounded()
374 ||this is boolean or, meaning if either or both are true then the result is true !this is the not operator, which changes true to false and false to true(vp instanceofinstanceof is an operator for determining if the types are compatible PseudoInfiniteViewport))
375 vp.setViewPosition(pointForLocation(loc));
376 elseelse is what happens when the if condition is false
377 showPanTip();
378 }close braces end code blocks and must match an earlier open brace
379 }close braces end code blocks and must match an earlier open brace
380
381 /**
382 * Given a Point determine which grid location (ifif executes the next statement only if the condition in parenthesis evaluates to true any) is under the
383 * mouse. This method is used by the GUI when creating Fish by clicking on
384 * cells in the display.
385 * @paramthis is the Javadoc tag for documenting the purpose of parameters p the Point in question (in display's coordinate system)
386 * @returnnull the Location beneath the event (which may not be a
387 * valid location in the grid)
388 */
389 publicpublic is used to indicate unrestricted access (any other class can have access) Location locationForPoint(Point p)
390 {open braces start code blocks and must be matched with a close brace
391 returnreturn means to provide the result of the method and/or cease execution of the method immediately newnew is used to create objects by calling the constructor Location(yCoordToRow(p.y), xCoordToCol(p.x));
392 }close braces end code blocks and must match an earlier open brace
393
394 publicpublic is used to indicate unrestricted access (any other class can have access) Point pointForLocation(Location loc)
395 {open braces start code blocks and must be matched with a close brace
396 returnreturn means to provide the result of the method and/or cease execution of the method immediately newnew is used to create objects by calling the constructor Point(colToXCoord(loc.getCol()) +adds two numbers together or concatenates Strings together cellSize / 2,
397 rowToYCoord(loc.getRow()) +adds two numbers together or concatenates Strings together cellSize / 2);
398 }close braces end code blocks and must match an earlier open brace
399
400 // private helpers to convert between (x,y) and (row,col)
401 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer xCoordToCol(intint is the type for whole numbers and it is short for integer xCoord)
402 {open braces start code blocks and must be matched with a close brace
403 returnreturn means to provide the result of the method and/or cease execution of the method immediately (xCoord - 1 - getInsets().left) / (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together originCol;
404 }close braces end code blocks and must match an earlier open brace
405
406 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer yCoordToRow(intint is the type for whole numbers and it is short for integer yCoord)
407 {open braces start code blocks and must be matched with a close brace
408 returnreturn means to provide the result of the method and/or cease execution of the method immediately (yCoord - 1 - getInsets().top) / (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together originRow;
409 }close braces end code blocks and must match an earlier open brace
410
411 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer colToXCoord(intint is the type for whole numbers and it is short for integer col)
412 {open braces start code blocks and must be matched with a close brace
413 returnreturn means to provide the result of the method and/or cease execution of the method immediately (col - originCol) * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together getInsets().left;
414 }close braces end code blocks and must match an earlier open brace
415
416 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer rowToYCoord(intint is the type for whole numbers and it is short for integer row)
417 {open braces start code blocks and must be matched with a close brace
418 returnreturn means to provide the result of the method and/or cease execution of the method immediately (row - originRow) * (cellSize +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together getInsets().top;
419 }close braces end code blocks and must match an earlier open brace
420
421 /**
422 * Given a MouseEvent, determine what text to place in the floating tool tip
423 * when the the mouse hovers over thisthis means the current object (the implicit parameter) location. If the mouse is over a
424 * valid grid cell. we provide some information about the cell and
425 * its contents. This method is automatically called on mouse-moved events
426 * since we register forfor is a looping structure for repeatedly executing a block of code tool tips.
427 * @paramthis is the Javadoc tag for documenting the purpose of parameters evt the MouseEvent in question
428 * @returnnull the tool tip string forfor is a looping structure for repeatedly executing a block of code thisthis means the current object (the implicit parameter) location
429 */
430 publicpublic is used to indicate unrestricted access (any other class can have access) String getToolTipText(MouseEvent evt)
431 {open braces start code blocks and must be matched with a close brace
432 Location loc =this assignment operator makes the left side equal to the right side locationForPoint(evt.getPoint());
433 returnreturn means to provide the result of the method and/or cease execution of the method immediately getToolTipText(loc);
434 }close braces end code blocks and must match an earlier open brace
435
436 privateprivate is used to restrict access to the current class only String getToolTipText(Location loc)
437 {open braces start code blocks and must be matched with a close brace
438 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truetoolTipsEnabled ||this is boolean or, meaning if either or both are true then the result is true loc ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object ||this is boolean or, meaning if either or both are true then the result is true !this is the not operator, which changes true to false and false to truegrid.isValid(loc))
439 returnreturn means to provide the result of the method and/or cease execution of the method immediately nullnull is the value used to refer to a non-existant object;
440 Object f =this assignment operator makes the left side equal to the right side grid.get(loc);
441 ifif executes the next statement only if the condition in parenthesis evaluates to true (f !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)
442 returnreturn means to provide the result of the method and/or cease execution of the method immediately MessageFormat.format(resources
443 .getString("cell.tooltip.nonempty"), newnew is used to create objects by calling the constructor Object[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays
444 {open braces start code blocks and must be matched with a close brace loc, f }close braces end code blocks and must match an earlier open brace);
445 elseelse is what happens when the if condition is false
446 returnreturn means to provide the result of the method and/or cease execution of the method immediately MessageFormat.format(resources
447 .getString("cell.tooltip.empty"), newnew is used to create objects by calling the constructor Object[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays
448 {open braces start code blocks and must be matched with a close brace loc, f }close braces end code blocks and must match an earlier open brace);
449 }close braces end code blocks and must match an earlier open brace
450
451 /**
452 * Sets the current location.
453 * @paramthis is the Javadoc tag for documenting the purpose of parameters loc the newnew is used to create objects by calling the constructor location
454 */
455 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setCurrentLocation(Location loc)
456 {open braces start code blocks and must be matched with a close brace
457 currentLocation =this assignment operator makes the left side equal to the right side loc;
458 }close braces end code blocks and must match an earlier open brace
459
460 /**
461 * Gets the current location.
462 * @returnnull the currently selected location (marked with a bold square)
463 */
464 publicpublic is used to indicate unrestricted access (any other class can have access) Location getCurrentLocation()
465 {open braces start code blocks and must be matched with a close brace
466 returnreturn means to provide the result of the method and/or cease execution of the method immediately currentLocation;
467 }close braces end code blocks and must match an earlier open brace
468
469 /**
470 * Moves the current location by a given amount.
471 * @paramthis is the Javadoc tag for documenting the purpose of parameters dr the number of rows by which to move the location
472 * @paramthis is the Javadoc tag for documenting the purpose of parameters dc the number of columns by which to move the location
473 */
474 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value moveLocation(intint is the type for whole numbers and it is short for integer dr, intint is the type for whole numbers and it is short for integer dc)
475 {open braces start code blocks and must be matched with a close brace
476 Location newLocation =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Location(currentLocation.getRow() +adds two numbers together or concatenates Strings together dr,
477 currentLocation.getCol() +adds two numbers together or concatenates Strings together dc);
478 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to truegrid.isValid(newLocation))
479 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
480
481 currentLocation =this assignment operator makes the left side equal to the right side newLocation;
482
483 JViewport viewPort =this assignment operator makes the left side equal to the right side getEnclosingViewport();
484 ifif executes the next statement only if the condition in parenthesis evaluates to true (isPannableUnbounded())
485 {open braces start code blocks and must be matched with a close brace
486 ifif executes the next statement only if the condition in parenthesis evaluates to true (originRow > currentLocation.getRow())
487 originRow =this assignment operator makes the left side equal to the right side currentLocation.getRow();
488 ifif executes the next statement only if the condition in parenthesis evaluates to true (originCol > currentLocation.getCol())
489 originCol =this assignment operator makes the left side equal to the right side currentLocation.getCol();
490 Dimension dim =this assignment operator makes the left side equal to the right side viewPort.getSize();
491 intint is the type for whole numbers and it is short for integer rows =this assignment operator makes the left side equal to the right side dim.height / (cellSize +adds two numbers together or concatenates Strings together 1);
492 intint is the type for whole numbers and it is short for integer cols =this assignment operator makes the left side equal to the right side dim.width / (cellSize +adds two numbers together or concatenates Strings together 1);
493 ifif executes the next statement only if the condition in parenthesis evaluates to true (originRow +adds two numbers together or concatenates Strings together rows - 1 < currentLocation.getRow())
494 originRow =this assignment operator makes the left side equal to the right side currentLocation.getRow() - rows +adds two numbers together or concatenates Strings together 1;
495 ifif executes the next statement only if the condition in parenthesis evaluates to true (originCol +adds two numbers together or concatenates Strings together rows - 1 < currentLocation.getCol())
496 originCol =this assignment operator makes the left side equal to the right side currentLocation.getCol() - cols +adds two numbers together or concatenates Strings together 1;
497 }close braces end code blocks and must match an earlier open brace
498 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true (viewPort !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)
499 {open braces start code blocks and must be matched with a close brace
500 intint is the type for whole numbers and it is short for integer dx =this assignment operator makes the left side equal to the right side 0;
501 intint is the type for whole numbers and it is short for integer dy =this assignment operator makes the left side equal to the right side 0;
502 Point p =this assignment operator makes the left side equal to the right side pointForLocation(currentLocation);
503 Rectangle locRect =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Rectangle(p.x - cellSize / 2, p.y
504 - cellSize / 2, cellSize +adds two numbers together or concatenates Strings together 1, cellSize +adds two numbers together or concatenates Strings together 1);
505
506 Rectangle viewRect =this assignment operator makes the left side equal to the right side viewPort.getViewRect();
507 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to trueviewRect.contains(locRect))
508 {open braces start code blocks and must be matched with a close brace
509 whilewhile is a looping structure for executing code repeatedly (locRect.x < viewRect.x +adds two numbers together or concatenates Strings together dx)
510 dx -=this decreases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1;
511 whilewhile is a looping structure for executing code repeatedly (locRect.y < viewRect.y +adds two numbers together or concatenates Strings together dy)
512 dy -=this decreases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1;
513 whilewhile is a looping structure for executing code repeatedly (locRect.getMaxX() > viewRect.getMaxX() +adds two numbers together or concatenates Strings together dx)
514 dx +=this increases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1;
515 whilewhile is a looping structure for executing code repeatedly (locRect.getMaxY() > viewRect.getMaxY() +adds two numbers together or concatenates Strings together dy)
516 dy +=this increases the variable on the left by the value on the right cellSize +adds two numbers together or concatenates Strings together 1;
517
518 Point pt =this assignment operator makes the left side equal to the right side viewPort.getViewPosition();
519 pt.x +=this increases the variable on the left by the value on the right dx;
520 pt.y +=this increases the variable on the left by the value on the right dy;
521 viewPort.setViewPosition(pt);
522 }close braces end code blocks and must match an earlier open brace
523 }close braces end code blocks and must match an earlier open brace
524 repaint();
525 showTip(getToolTipText(currentLocation),
526 pointForLocation(currentLocation));
527 }close braces end code blocks and must match an earlier open brace
528
529 /**
530 * Show a tool tip.
531 * @paramthis is the Javadoc tag for documenting the purpose of parameters tipText the tool tip text
532 * @paramthis is the Javadoc tag for documenting the purpose of parameters pt the pixel position over which to show the tip
533 */
534 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value showTip(String tipText, Point pt)
535 {open braces start code blocks and must be matched with a close brace
536 ifif executes the next statement only if the condition in parenthesis evaluates to true (getRootPane() ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object)
537 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
538 // draw in glass pane to appear on top of other components
539 ifif executes the next statement only if the condition in parenthesis evaluates to true (glassPane ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object)
540 {open braces start code blocks and must be matched with a close brace
541 getRootPane().setGlassPane(glassPane =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor JPanel());
542 glassPane.setOpaque(falsefalse is a value for the boolean type and means not true);
543 glassPane.setLayout(nullnull is the value used to refer to a non-existant object); // will control layout manually
544 glassPane.add(tip =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor JToolTip());
545 tipTimer =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Timer(TIP_DELAY, newnew is used to create objects by calling the constructor ActionListener()
546 {open braces start code blocks and must be matched with a close brace
547 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value actionPerformed(ActionEvent evt)
548 {open braces start code blocks and must be matched with a close brace
549 glassPane.setVisible(falsefalse is a value for the boolean type and means not true);
550 }close braces end code blocks and must match an earlier open brace
551 }close braces end code blocks and must match an earlier open brace);
552 tipTimer.setRepeats(falsefalse is a value for the boolean type and means not true);
553 }close braces end code blocks and must match an earlier open brace
554 ifif executes the next statement only if the condition in parenthesis evaluates to true (tipText ==this is the comparison operator which evaluates to true if both sides are the same nullnull is the value used to refer to a non-existant object)
555 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
556
557 // set tip text to identify current origin of pannable view
558 tip.setTipText(tipText);
559
560 // position tip to appear at upper left corner of viewport
561 tip.setLocation(SwingUtilities.convertPoint(thisthis means the current object (the implicit parameter), pt, glassPane));
562 tip.setSize(tip.getPreferredSize());
563
564 // show glass pane (it contains tip)
565 glassPane.setVisible(truetrue is the boolean value that is the opposite of false);
566 glassPane.repaint();
567
568 // this timer will hide the glass pane after a short delay
569 tipTimer.restart();
570 }close braces end code blocks and must match an earlier open brace
571
572 /**
573 * Calculate the cell size to use given the current viewable region and the
574 * the number of rows and columns in the grid. We use the largest
575 * cellSize that will fit in the viewable region, bounded to be at least the
576 * parameter minSize.
577 */
578 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value recalculateCellSize(intint is the type for whole numbers and it is short for integer minSize)
579 {open braces start code blocks and must be matched with a close brace
580 ifif executes the next statement only if the condition in parenthesis evaluates to true (numRows ==this is the comparison operator which evaluates to true if both sides are the same 0 ||this is boolean or, meaning if either or both are true then the result is true numCols ==this is the comparison operator which evaluates to true if both sides are the same 0)
581 {open braces start code blocks and must be matched with a close brace
582 cellSize =this assignment operator makes the left side equal to the right side 0;
583 }close braces end code blocks and must match an earlier open brace
584 elseelse is what happens when the if condition is false
585 {open braces start code blocks and must be matched with a close brace
586 JViewport vp =this assignment operator makes the left side equal to the right side getEnclosingViewport();
587 Dimension viewableSize =this assignment operator makes the left side equal to the right side (vp !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object) ? vp.getSize() : getSize();
588 intint is the type for whole numbers and it is short for integer desiredCellSize =this assignment operator makes the left side equal to the right side Math.min(
589 (viewableSize.height - extraHeight()) / numRows,
590 (viewableSize.width - extraWidth()) / numCols) - 1;
591 // now we want to approximate this with
592 // DEFAULT_CELL_SIZE * Math.pow(2, k)
593 cellSize =this assignment operator makes the left side equal to the right side DEFAULT_CELL_SIZE;
594 ifif executes the next statement only if the condition in parenthesis evaluates to true (cellSize <=this evaluates to true if the left side is not more than the right side desiredCellSize)
595 whilewhile is a looping structure for executing code repeatedly (2 * cellSize <=this evaluates to true if the left side is not more than the right side desiredCellSize)
596 cellSize *=this multiplies the variable on the left by the value on the right and stores the result in the variable 2;
597 elseelse is what happens when the if condition is false
598 whilewhile is a looping structure for executing code repeatedly (cellSize / 2 >=this evaluates to true if the left side is not less than the right side Math.max(desiredCellSize, MIN_CELL_SIZE))
599 cellSize /=this divides the variable on the left by the value on the right and stores the result in the variable 2;
600 }close braces end code blocks and must match an earlier open brace
601 revalidate();
602 }close braces end code blocks and must match an earlier open brace
603
604 // helper to get our parent viewport, if we are in one.
605 privateprivate is used to restrict access to the current class only JViewport getEnclosingViewport()
606 {open braces start code blocks and must be matched with a close brace
607 Component parent =this assignment operator makes the left side equal to the right side getParent();
608 returnreturn means to provide the result of the method and/or cease execution of the method immediately (parent instanceofinstanceof is an operator for determining if the types are compatible JViewport) ? (JViewport) parent : nullnull is the value used to refer to a non-existant object;
609 }close braces end code blocks and must match an earlier open brace
610
611 // GridPanel implements the Scrollable interface to get nicer behavior in a
612 // JScrollPane. The 5 methods below are the methods in that interface
613
614 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getScrollableUnitIncrement(Rectangle visibleRect,
615 intint is the type for whole numbers and it is short for integer orientation, intint is the type for whole numbers and it is short for integer direction)
616 {open braces start code blocks and must be matched with a close brace
617 returnreturn means to provide the result of the method and/or cease execution of the method immediately cellSize +adds two numbers together or concatenates Strings together 1;
618 }close braces end code blocks and must match an earlier open brace
619
620 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getScrollableBlockIncrement(Rectangle visibleRect,
621 intint is the type for whole numbers and it is short for integer orientation, intint is the type for whole numbers and it is short for integer direction)
622 {open braces start code blocks and must be matched with a close brace
623 ifif executes the next statement only if the condition in parenthesis evaluates to true (orientation ==this is the comparison operator which evaluates to true if both sides are the same SwingConstants.VERTICAL)
624 returnreturn means to provide the result of the method and/or cease execution of the method immediately (intint is the type for whole numbers and it is short for integer) (visibleRect.height * .9);
625 elseelse is what happens when the if condition is false
626 returnreturn means to provide the result of the method and/or cease execution of the method immediately (intint is the type for whole numbers and it is short for integer) (visibleRect.width * .9);
627 }close braces end code blocks and must match an earlier open brace
628
629 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false getScrollableTracksViewportWidth()
630 {open braces start code blocks and must be matched with a close brace
631 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
632 }close braces end code blocks and must match an earlier open brace
633
634 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false getScrollableTracksViewportHeight()
635 {open braces start code blocks and must be matched with a close brace
636 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
637 }close braces end code blocks and must match an earlier open brace
638
639 publicpublic is used to indicate unrestricted access (any other class can have access) Dimension getPreferredScrollableViewportSize()
640 {open braces start code blocks and must be matched with a close brace
641 returnreturn means to provide the result of the method and/or cease execution of the method immediately newnew is used to create objects by calling the constructor Dimension(DEFAULT_CELL_COUNT * (DEFAULT_CELL_SIZE +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together extraWidth(),
642 DEFAULT_CELL_COUNT * (DEFAULT_CELL_SIZE +adds two numbers together or concatenates Strings together 1) +adds two numbers together or concatenates Strings together 1 +adds two numbers together or concatenates Strings together extraHeight());
643 }close braces end code blocks and must match an earlier open brace
644
645 // GridPanel implements the PseudoInfiniteViewport.Pannable interface to
646 // play nicely with the pan behavior for unbounded view.
647 // The 3 methods below are the methods in that interface.
648
649 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value panBy(intint is the type for whole numbers and it is short for integer hDelta, intint is the type for whole numbers and it is short for integer vDelta)
650 {open braces start code blocks and must be matched with a close brace
651 originCol +=this increases the variable on the left by the value on the right hDelta / (cellSize +adds two numbers together or concatenates Strings together 1);
652 originRow +=this increases the variable on the left by the value on the right vDelta / (cellSize +adds two numbers together or concatenates Strings together 1);
653 repaint();
654 }close braces end code blocks and must match an earlier open brace
655
656 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false isPannableUnbounded()
657 {open braces start code blocks and must be matched with a close brace
658 returnreturn means to provide the result of the method and/or cease execution of the method immediately grid !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) (grid.getNumRows() ==this is the comparison operator which evaluates to true if both sides are the same -1 ||this is boolean or, meaning if either or both are true then the result is true grid.getNumCols() ==this is the comparison operator which evaluates to true if both sides are the same -1);
659 }close braces end code blocks and must match an earlier open brace
660
661 /**
662 * Shows a tool tip over the upper left corner of the viewport with the
663 * contents of the pannable view's pannable tip text (typically a string
664 * identifiying the corner point). Tip is removed after a shortshort is the type for whole numbers (they have a smaller range than int) delay.
665 */
666 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value showPanTip()
667 {open braces start code blocks and must be matched with a close brace
668 String tipText =this assignment operator makes the left side equal to the right side nullnull is the value used to refer to a non-existant object;
669 Point upperLeft =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Point(0, 0);
670 JViewport vp =this assignment operator makes the left side equal to the right side getEnclosingViewport();
671 ifif executes the next statement only if the condition in parenthesis evaluates to true (!this is the not operator, which changes true to false and false to trueisPannableUnbounded() &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) vp !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)
672 upperLeft =this assignment operator makes the left side equal to the right side vp.getViewPosition();
673 Location loc =this assignment operator makes the left side equal to the right side locationForPoint(upperLeft);
674 ifif executes the next statement only if the condition in parenthesis evaluates to true (loc !=this is the not equals operator which evaluates to true if both sides are different nullnull is the value used to refer to a non-existant object)
675 tipText =this assignment operator makes the left side equal to the right side getToolTipText(loc);
676
677 showTip(tipText, getLocation());
678 }close braces end code blocks and must match an earlier open brace
679 }close braces end code blocks and must match an earlier open brace
680
681 //Uploaded on Sat Feb 19 13:40:40 EST 2011
|