diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/ScrollingImagePanel.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/scape/ScrollingImagePanel.java')
| -rw-r--r-- | NET/worlds/scape/ScrollingImagePanel.java | 457 |
1 files changed, 457 insertions, 0 deletions
diff --git a/NET/worlds/scape/ScrollingImagePanel.java b/NET/worlds/scape/ScrollingImagePanel.java new file mode 100644 index 0000000..417662d --- /dev/null +++ b/NET/worlds/scape/ScrollingImagePanel.java @@ -0,0 +1,457 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.console.Console; +/* */ import NET.worlds.console.DialogDisabled; +/* */ import NET.worlds.console.ExposedPanel; +/* */ import NET.worlds.console.WiderScrollbar; +/* */ import NET.worlds.network.URL; +/* */ import java.awt.BorderLayout; +/* */ import java.awt.Color; +/* */ import java.awt.Component; +/* */ import java.awt.Container; +/* */ import java.awt.Dimension; +/* */ import java.awt.Event; +/* */ import java.awt.Font; +/* */ import java.awt.FontMetrics; +/* */ import java.awt.Frame; +/* */ import java.awt.Graphics; +/* */ import java.awt.GridBagConstraints; +/* */ import java.awt.GridBagLayout; +/* */ import java.awt.Image; +/* */ import java.awt.MediaTracker; +/* */ import java.awt.Point; +/* */ import java.awt.Scrollbar; +/* */ import java.awt.Toolkit; +/* */ import java.io.PrintStream; +/* */ import java.util.Enumeration; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class ScrollingImagePanel +/* */ extends ExposedPanel +/* */ implements LibraryDropTarget, DialogDisabled +/* */ { +/* */ private static final long serialVersionUID = 1L; +/* 47 */ private Scrollbar scrollbar = new WiderScrollbar(); +/* */ private Vector<ScrollingListElement> items; +/* */ private int cellWidth; +/* */ private int cellHeight; +/* 51 */ private Font font = new Font(Console.message("ScImageFont"), 1, 12); +/* */ +/* 53 */ private FontMetrics metrics = getFontMetrics(this.font); +/* 54 */ private int ascent = this.metrics.getAscent(); +/* 55 */ private int descent = this.metrics.getDescent(); +/* 56 */ private int textHeight = this.ascent + this.descent; +/* 57 */ private int scrollPos = 0; +/* */ private ClickEventHandler handler; +/* */ private ScrollingListElement downClicked; +/* */ private boolean isDownClicked; +/* */ private int maxScrollPos; +/* 62 */ private boolean useIcons = false; +/* */ +/* */ private boolean isDialogDisabled; +/* */ +/* */ public ScrollingImagePanel(ClickEventHandler handler, Vector<?> icons, boolean showIcons) +/* */ { +/* 68 */ this.handler = handler; +/* 69 */ setFont(this.font); +/* 70 */ setForeground(Color.black); +/* 71 */ setBackground(Color.lightGray); +/* 72 */ this.items = new Vector(); +/* 73 */ setContents(icons, false); +/* 74 */ setLayout(new BorderLayout()); +/* 75 */ add("East", this.scrollbar); +/* 76 */ this.useIcons = showIcons; +/* */ } +/* */ +/* */ public void resetContents(Vector<?> icons) +/* */ { +/* 81 */ setContents(icons); +/* */ } +/* */ +/* */ protected void add(GridBagLayout gbag, Component comp, GridBagConstraints c) +/* */ { +/* 86 */ gbag.setConstraints(comp, c); +/* 87 */ add(comp); +/* */ } +/* */ +/* */ @Deprecated +/* */ public boolean handleEvent(Event e) +/* */ { +/* 93 */ if (this.isDialogDisabled) { +/* 94 */ return false; +/* */ } +/* 96 */ switch (e.id) { +/* */ case 601: +/* 98 */ return scrollLineUp(); +/* */ case 602: +/* 100 */ return scrollLineDown(); +/* */ case 603: +/* 102 */ return scrollPageUp(); +/* */ case 604: +/* 104 */ return scrollPageDown(); +/* */ case 605: +/* 106 */ return scrollAbsolute(); +/* */ } +/* 108 */ return super.handleEvent(e); +/* */ } +/* */ +/* */ +/* */ public void dialogDisable(boolean disable) +/* */ { +/* 114 */ this.isDialogDisabled = disable; +/* */ } +/* */ +/* */ private void setContents(Vector<?> icons) +/* */ { +/* 119 */ setContents(icons, true); +/* */ } +/* */ +/* */ private void setContents(Vector<?> icons, boolean showIt) +/* */ { +/* 124 */ this.items.removeAllElements(); +/* 125 */ int count = icons.size(); +/* 126 */ for (int i = 0; i < count; i++) +/* 127 */ addIcon((Iconic)icons.elementAt(i), false); +/* 128 */ if (showIt) { +/* 129 */ recalc(getSize().width, getSize().height); +/* 130 */ repaint(); +/* */ } +/* */ } +/* */ +/* */ private void addIcon(Iconic icon, boolean showIt) +/* */ { +/* 136 */ String title = icon.getIconCaption(); +/* 137 */ int titleWidth = title != null ? this.metrics.stringWidth(title) : 0; +/* 138 */ URL name = icon.getIconURL(); +/* 139 */ Image image = null; +/* 140 */ if (name != null) { +/* 141 */ MediaTracker tracker = new MediaTracker(this); +/* 142 */ image = Toolkit.getDefaultToolkit().getImage(name.unalias()); +/* 143 */ tracker.addImage(image, 0); +/* */ try { +/* 145 */ tracker.waitForID(0); +/* */ } +/* */ catch (InterruptedException localInterruptedException) {} +/* 148 */ if (tracker.isErrorID(0)) { +/* 149 */ image = null; +/* */ +/* 151 */ System.out.println("Error loading " + name); +/* */ } +/* */ } +/* 154 */ this.items.addElement(new ScrollingListElement(image, title, titleWidth)); +/* */ } +/* */ +/* */ private void findCellSize() +/* */ { +/* 159 */ this.cellWidth = 30; +/* 160 */ this.cellHeight = 0; +/* 161 */ if (this.useIcons) { +/* 162 */ this.cellHeight = 30; +/* */ } +/* 164 */ Enumeration<ScrollingListElement> e = this.items.elements(); +/* 165 */ while (e.hasMoreElements()) { +/* 166 */ ScrollingListElement item = (ScrollingListElement)e.nextElement(); +/* 167 */ this.cellWidth = Math.max(this.cellWidth, item.titleWidth); +/* 168 */ if ((this.useIcons) && (item.image != null)) { +/* 169 */ this.cellWidth = Math.max(this.cellWidth, +/* 170 */ item.image.getWidth(this)); +/* 171 */ this.cellHeight = Math.max(this.cellHeight, +/* 172 */ item.image.getHeight(this)); +/* */ } +/* */ } +/* 175 */ this.cellWidth += 2; +/* 176 */ this.cellHeight += this.textHeight + 2; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setBounds(int x, int y, int w, int h) +/* */ { +/* 188 */ super.setBounds(x, y, w, h); +/* 189 */ recalc(w, h); +/* 190 */ repaint(); +/* */ } +/* */ +/* */ private void recalc(int w, int h) +/* */ { +/* 195 */ findCellSize(); +/* */ +/* */ +/* */ +/* 199 */ this.scrollPos = 0; +/* 200 */ this.scrollbar.setValue(this.scrollPos); +/* */ +/* */ +/* 203 */ for (int pass = 0; pass < 2; pass++) { +/* 204 */ int scrollbarWidth = 0; +/* 205 */ if (pass == 1) +/* 206 */ scrollbarWidth = this.scrollbar.getSize().width; +/* 207 */ int lines = 0; +/* 208 */ if (this.cellWidth != 0) { +/* 209 */ int imagesPerLine = Math.max(1, (w - scrollbarWidth) / +/* 210 */ this.cellWidth); +/* 211 */ lines = (this.items.size() + imagesPerLine - 1) / imagesPerLine * +/* 212 */ this.cellHeight; +/* */ } +/* 214 */ if (lines > h) { +/* 215 */ if (pass == 0) { +/* 216 */ if (!this.scrollbar.isVisible()) { +/* 217 */ this.scrollbar.setVisible(true); +/* 218 */ validate(); +/* */ } +/* */ } +/* */ else { +/* 222 */ this.maxScrollPos = lines; +/* 223 */ this.scrollbar.setValues(this.scrollPos, h, 0, lines); +/* 224 */ this.scrollbar.setPageIncrement(h); +/* 225 */ this.scrollbar.setLineIncrement(this.cellHeight); +/* 226 */ break; +/* */ } +/* */ } +/* */ else { +/* 230 */ if (!this.scrollbar.isVisible()) break; +/* 231 */ this.scrollbar.setVisible(false); +/* 232 */ validate(); +/* */ +/* 234 */ break; +/* */ } +/* */ } +/* */ +/* 238 */ clearHitTest(); +/* */ } +/* */ +/* */ private void clearHitTest() +/* */ { +/* 243 */ int count = this.items.size(); +/* 244 */ for (int i = 0; i < count; i++) { +/* 245 */ ScrollingListElement e = (ScrollingListElement)this.items.elementAt(i); +/* 246 */ e.x = (e.y = -1); +/* */ } +/* */ } +/* */ +/* */ private ScrollingListElement findCell(int x, int y) +/* */ { +/* 252 */ int count = this.items.size(); +/* 253 */ for (int i = 0; i < count; i++) { +/* 254 */ ScrollingListElement e = (ScrollingListElement)this.items.elementAt(i); +/* 255 */ if ((x >= 0) && (y >= 0) && (x < e.x) && (y < e.y)) +/* 256 */ return e; +/* */ } +/* 258 */ return null; +/* */ } +/* */ +/* */ private void buttonAction(boolean down) +/* */ { +/* 263 */ if (this.isDownClicked != down) { +/* 264 */ this.isDownClicked = down; +/* 265 */ Graphics g = getGraphics(); +/* 266 */ drawCell(g, this.downClicked, this.isDownClicked); +/* 267 */ g.dispose(); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private Component findComponent(Point p) +/* */ { +/* 281 */ Point screenLoc = getLocationOnScreen(); +/* 282 */ Container cur = null; +/* 283 */ for (Container tmp = getParent(); !(tmp instanceof Frame); +/* 284 */ tmp = cur.getParent()) +/* 285 */ cur = tmp; +/* 286 */ Point parentCoords = cur.getLocationOnScreen(); +/* 287 */ p.x = (p.x + screenLoc.x - parentCoords.x); +/* 288 */ p.y = (p.y + screenLoc.y - parentCoords.y); +/* */ +/* */ +/* */ +/* 292 */ Component found = cur; +/* */ for (;;) { +/* 294 */ Component c = found.getComponentAt(p.x, p.y); +/* 295 */ if ((c == found) || (c == null)) +/* */ break; +/* 297 */ Point tmp = c.getLocation(); +/* 298 */ p.x -= tmp.x; +/* 299 */ p.y -= tmp.y; +/* 300 */ found = c; +/* */ } +/* 302 */ return found; +/* */ } +/* */ +/* */ @Deprecated +/* */ public boolean mouseUp(Event event, int x, int y) +/* */ { +/* 308 */ if (this.downClicked != null) { +/* 309 */ Point p = new Point(x, y); +/* 310 */ buttonAction(false); +/* 311 */ this.handler.clickEvent(findComponent(p), p, 2); +/* 312 */ this.downClicked = null; +/* 313 */ return true; +/* */ } +/* 315 */ return false; +/* */ } +/* */ +/* */ public int itemAt(Point p) +/* */ { +/* 320 */ ScrollingListElement cell = findCell(p.x, p.y); +/* 321 */ if (cell != null) +/* 322 */ return this.items.indexOf(cell); +/* 323 */ return -1; +/* */ } +/* */ +/* */ +/* */ +/* */ @Deprecated +/* */ public boolean mouseDown(Event event, int x, int y) +/* */ { +/* 331 */ if ((this.downClicked == null) && +/* 332 */ ((this.downClicked = findCell(x, y)) != null)) { +/* 333 */ buttonAction(true); +/* 334 */ int flags = 1; +/* 335 */ if (event.metaDown()) +/* 336 */ flags |= 0x4; +/* 337 */ this.handler.clickEvent(this, new Point(x, y), flags); +/* 338 */ return true; +/* */ } +/* 340 */ return false; +/* */ } +/* */ +/* */ @Deprecated +/* */ public boolean mouseDrag(Event event, int x, int y) +/* */ { +/* 346 */ if (this.downClicked != null) { +/* 347 */ Point p = new Point(x, y); +/* 348 */ this.handler.clickEvent(findComponent(p), p, 8); +/* 349 */ return true; +/* */ } +/* 351 */ return false; +/* */ } +/* */ +/* */ +/* */ private void drawCell(Graphics g, ScrollingListElement e, boolean depressed) +/* */ { +/* 357 */ int x = e.x - this.cellWidth; +/* 358 */ int y = e.y - this.cellHeight; +/* 359 */ int imageBoxHeight = this.cellHeight - this.textHeight; +/* 360 */ int yTextOffset = imageBoxHeight + this.ascent; +/* 361 */ Color normColor = g.getColor(); +/* 362 */ g.setColor(getBackground()); +/* 363 */ g.draw3DRect(x, y, this.cellWidth - 1, this.cellHeight - 1, !depressed); +/* 364 */ g.setColor(normColor); +/* 365 */ if ((this.useIcons) && (e.image != null)) { +/* 366 */ int imageWidth = e.image.getWidth(this); +/* 367 */ int imageHeight = e.image.getHeight(this); +/* 368 */ g.drawImage(e.image, x + (this.cellWidth - imageWidth) / 2, +/* 369 */ y + (imageBoxHeight - imageHeight) / 2, +/* 370 */ null); +/* */ } +/* 372 */ if (e.title != null) { +/* 373 */ g.drawString(e.title, x + (this.cellWidth - e.titleWidth) / 2, +/* 374 */ y + yTextOffset); +/* */ } +/* */ } +/* */ +/* */ public void paint(Graphics g) { +/* 379 */ Color normColor = g.getColor(); +/* 380 */ super.paint(g); +/* 381 */ g.setColor(normColor); +/* */ +/* 383 */ clearHitTest(); +/* 384 */ int width = getSize().width; +/* 385 */ int height = getSize().height; +/* */ +/* 387 */ int x = 0; +/* 388 */ int y = -this.scrollbar.getValue(); +/* 389 */ int count = this.items.size(); +/* 390 */ for (int i = 0; i < count; i++) { +/* 391 */ if (y + this.cellHeight > 0) { +/* 392 */ ScrollingListElement e = +/* 393 */ (ScrollingListElement)this.items.elementAt(i); +/* 394 */ e.x = (x + this.cellWidth); +/* 395 */ e.y = (y + this.cellHeight); +/* 396 */ drawCell(g, e, false); +/* */ } +/* 398 */ x += this.cellWidth; +/* */ +/* */ +/* 401 */ if (x + this.cellWidth > width) { +/* 402 */ x = 0; +/* 403 */ if (y += this.cellHeight >= height) +/* */ break; +/* */ } +/* */ } +/* */ } +/* */ +/* 409 */ public boolean isIconsVisible() { return this.useIcons; } +/* */ +/* */ public void setIconsVisible(boolean showIcons) { +/* 412 */ this.useIcons = showIcons; +/* 413 */ recalc(getSize().width, getSize().height); +/* 414 */ repaint(); +/* */ } +/* */ +/* */ private boolean setScrollValue(int value) +/* */ { +/* 419 */ this.scrollPos = Math.max(this.scrollbar.getMinimum(), value); +/* 420 */ this.scrollPos = +/* 421 */ Math.min(this.maxScrollPos, this.scrollPos); +/* 422 */ this.scrollbar.setValue(this.scrollPos); +/* 423 */ repaint(); +/* 424 */ return true; +/* */ } +/* */ +/* */ private boolean scrollLineUp() +/* */ { +/* 429 */ return setScrollValue(this.scrollPos - this.scrollbar.getLineIncrement()); +/* */ } +/* */ +/* */ private boolean scrollLineDown() +/* */ { +/* 434 */ return setScrollValue(this.scrollPos + this.scrollbar.getLineIncrement()); +/* */ } +/* */ +/* */ private boolean scrollPageUp() +/* */ { +/* 439 */ return setScrollValue(this.scrollPos - this.scrollbar.getPageIncrement()); +/* */ } +/* */ +/* */ private boolean scrollPageDown() +/* */ { +/* 444 */ return setScrollValue(this.scrollPos + this.scrollbar.getPageIncrement()); +/* */ } +/* */ +/* */ private boolean scrollAbsolute() +/* */ { +/* 449 */ return setScrollValue(this.scrollbar.getValue()); +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\ScrollingImagePanel.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |