diff options
Diffstat (limited to 'NET/worlds/console/TreePanel.java')
| -rw-r--r-- | NET/worlds/console/TreePanel.java | 359 |
1 files changed, 359 insertions, 0 deletions
diff --git a/NET/worlds/console/TreePanel.java b/NET/worlds/console/TreePanel.java new file mode 100644 index 0000000..5bf8135 --- /dev/null +++ b/NET/worlds/console/TreePanel.java @@ -0,0 +1,359 @@ +/* */ package NET.worlds.console; +/* */ +/* */ import java.awt.BorderLayout; +/* */ import java.awt.Color; +/* */ import java.awt.Dimension; +/* */ import java.awt.Event; +/* */ import java.awt.Font; +/* */ import java.awt.FontMetrics; +/* */ import java.awt.Graphics; +/* */ import java.awt.Point; +/* */ import java.awt.Rectangle; +/* */ import java.awt.Scrollbar; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class TreePanel +/* */ extends ExposedPanel +/* */ implements DialogDisabled +/* */ { +/* */ private static final long serialVersionUID = -5534860983354876334L; +/* 42 */ private Vector<TreeNode> items = new Vector(); +/* */ private boolean delayRepaints; +/* */ private boolean needRepaint; +/* */ private boolean needRecalc; +/* */ private boolean needMakeVisible; +/* 47 */ private Scrollbar scrollbar = new WiderScrollbar(); +/* 48 */ private int scrollPos = 0; +/* */ private int linesVisible; +/* 50 */ private int selectedIndex = -1; +/* 51 */ private boolean hasFocus = true; +/* 52 */ private Font nFont = new Font(Console.message("TreeFont"), 0, 13); +/* */ +/* 54 */ private FontMetrics nFontMetrics = getFontMetrics(this.nFont); +/* 55 */ private Font bFont = new Font(Console.message("TreeFont"), 1, 11); +/* */ +/* 57 */ private FontMetrics bFontMetrics = getFontMetrics(this.bFont); +/* 58 */ private int fontHeight = Math.max(this.nFontMetrics.getHeight(), +/* 59 */ this.bFontMetrics.getHeight()); +/* 60 */ private int itemHeight = this.fontHeight; +/* */ +/* */ private boolean isDialogDisabled; +/* 63 */ private static final int[] cxs = { 006 }; +/* 64 */ private static final int[] cys = { 6, -6 }; +/* 65 */ private MoveablePolygon closedIcon = new MoveablePolygon(cxs, cys); +/* */ +/* 67 */ private static final int[] oxs = { -5, 6 }; +/* 68 */ private static final int[] oys = { 006 }; +/* 69 */ private MoveablePolygon openedIcon = new MoveablePolygon(oxs, oys); +/* */ +/* 71 */ private static final Color normBGColor = new Color(80, 80, 80); +/* 72 */ private static final Color normFGColor = new Color(190, 190, 190); +/* 73 */ private static final Color selFGColor = new Color(255, 255, 175); +/* */ private static final int indentPixels = 14; +/* */ +/* */ public TreePanel() { +/* 77 */ setBackground(normBGColor); +/* 78 */ setLayout(new BorderLayout()); +/* 79 */ add("East", this.scrollbar); +/* 80 */ this.scrollbar.setVisible(false); +/* */ } +/* */ +/* */ public synchronized void delayRepaints(boolean state) { +/* 84 */ if (!(this.delayRepaints = state)) { +/* 85 */ if (this.needRecalc) +/* 86 */ recalc(); +/* 87 */ if (this.needMakeVisible) +/* 88 */ makeVisible(this.selectedIndex); +/* 89 */ if (this.needRepaint) { +/* 90 */ repaint(); +/* */ } +/* */ } +/* */ } +/* */ +/* */ private synchronized void needRepaint(boolean needRecalc, boolean needMakeVisible) { +/* 96 */ this.needRepaint = true; +/* 97 */ this.needRecalc |= needRecalc; +/* 98 */ this.needMakeVisible |= needMakeVisible; +/* 99 */ delayRepaints(this.delayRepaints); +/* */ } +/* */ +/* */ public synchronized int getSelectedIndex() { +/* 103 */ return this.selectedIndex; +/* */ } +/* */ +/* */ public synchronized void select(int item) { +/* 107 */ this.selectedIndex = item; +/* 108 */ needRepaint(false, true); +/* */ } +/* */ +/* */ public void setFocus(boolean hasFocus) { +/* 112 */ if (this.hasFocus != hasFocus) { +/* 113 */ this.hasFocus = hasFocus; +/* 114 */ needRepaint(false, false); +/* */ } +/* */ } +/* */ +/* */ public boolean hasFocus() +/* */ { +/* 120 */ return this.hasFocus; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void setBounds(int x, int y, int w, int h) +/* */ { +/* 129 */ super.setBounds(x, y, w, h); +/* 130 */ needRepaint(true, false); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized TreeNode getSelectedNode() +/* */ { +/* 143 */ if (this.selectedIndex != -1) +/* 144 */ return (TreeNode)this.items.elementAt(this.selectedIndex); +/* 145 */ return null; +/* */ } +/* */ +/* */ public synchronized void reset(Vector<TreeNode> items) { +/* 149 */ this.items = items; +/* 150 */ needRepaint(true, false); +/* */ } +/* */ +/* */ public synchronized void removeAllElements() { +/* 154 */ this.items.removeAllElements(); +/* 155 */ needRepaint(true, false); +/* */ } +/* */ +/* */ public synchronized void insertElementAt(TreeNode ele, int index) { +/* 159 */ this.items.insertElementAt(ele, index); +/* 160 */ needRepaint(true, false); +/* */ } +/* */ +/* */ public synchronized void removeElementAt(int index) { +/* 164 */ this.items.removeElementAt(index); +/* 165 */ needRepaint(true, false); +/* */ } +/* */ +/* */ public synchronized void addElement(TreeNode ele) { +/* 169 */ this.items.addElement(ele); +/* 170 */ needRepaint(true, false); +/* */ } +/* */ +/* */ public int countElements() { +/* 174 */ return this.items.size(); +/* */ } +/* */ +/* */ public TreeNode elementAt(int index) { +/* 178 */ return (TreeNode)this.items.elementAt(index); +/* */ } +/* */ +/* */ public TreeNode elementAt(Point p) { +/* 182 */ int item = this.scrollPos + p.y / this.itemHeight; +/* 183 */ if (item < this.items.size()) +/* 184 */ return (TreeNode)this.items.elementAt(item); +/* 185 */ return null; +/* */ } +/* */ +/* */ private void makeVisible(int item) { +/* 189 */ int count = this.items.size(); +/* 190 */ if ((count > this.linesVisible) && ( +/* 191 */ (item < this.scrollPos) || (item >= this.scrollPos + this.linesVisible))) { +/* 192 */ setScrollValue(Math.min(item * this.itemHeight, this.scrollbar.getMaximum())); +/* */ } +/* 194 */ this.needMakeVisible = false; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public synchronized void recalc() +/* */ { +/* 204 */ int height = getSize().height; +/* 205 */ this.linesVisible = Math.max(1, height / this.itemHeight); +/* 206 */ int count = this.items.size(); +/* 207 */ if (count > this.linesVisible) { +/* 208 */ if (!this.scrollbar.isVisible()) { +/* 209 */ this.scrollbar.setVisible(true); +/* 210 */ validate(); +/* */ } +/* 212 */ this.scrollbar.setValues(this.scrollPos * this.itemHeight, this.linesVisible * +/* 213 */ this.itemHeight, 0, count * this.itemHeight); +/* 214 */ this.scrollbar.setPageIncrement(this.linesVisible * this.itemHeight); +/* 215 */ this.scrollbar.setLineIncrement(this.itemHeight); +/* */ } else { +/* 217 */ if (this.scrollbar.isVisible()) { +/* 218 */ this.scrollbar.setVisible(false); +/* 219 */ validate(); +/* */ } +/* 221 */ this.scrollPos = 0; +/* */ } +/* 223 */ this.needRecalc = false; +/* */ } +/* */ +/* */ public synchronized void paint(Graphics g) +/* */ { +/* 228 */ super.paint(g); +/* */ +/* 230 */ int height = getSize().height; +/* 231 */ int count = this.items.size(); +/* 232 */ int y = 0; +/* 233 */ for (int i = this.scrollPos; i < count; i++) { +/* 234 */ TreeNode node = elementAt(i); +/* 235 */ String name = node.toString(); +/* 236 */ boolean isTitle = node.displayAsTitle(); +/* 237 */ Font font = this.nFont; +/* 238 */ FontMetrics metrics = this.nFontMetrics; +/* 239 */ if (isTitle) { +/* 240 */ font = this.bFont; +/* 241 */ metrics = this.bFontMetrics; +/* */ } +/* 243 */ g.setFont(font); +/* 244 */ int ascent = metrics.getAscent(); +/* 245 */ int x = node.getLevel() * 14; +/* 246 */ g.setColor(normFGColor); +/* 247 */ if (node.isOpen()) { +/* 248 */ this.openedIcon.drawFilled(g, x + 5, y + ascent - 5); +/* */ } else +/* 250 */ this.closedIcon.drawFilled(g, x + 5, y + ascent - 5); +/* 251 */ if (i == this.selectedIndex) +/* 252 */ g.setColor(selFGColor); +/* 253 */ g.drawString(name, x + 11 + 5, y + ascent); +/* 254 */ if ((i == this.selectedIndex) && (this.hasFocus)) +/* 255 */ g.drawRect(x + 11 + 3, y, metrics.stringWidth(name) + 3, +/* 256 */ this.itemHeight); +/* 257 */ y += this.itemHeight; +/* 258 */ if (y >= height) +/* */ break; +/* */ } +/* 261 */ this.needRepaint = false; +/* */ } +/* */ +/* */ @Deprecated +/* */ public boolean handleEvent(Event e) +/* */ { +/* 267 */ if (this.isDialogDisabled) { +/* 268 */ return false; +/* */ } +/* 270 */ switch (e.id) { +/* */ case 601: +/* 272 */ return scrollLineUp(); +/* */ case 602: +/* 274 */ return scrollLineDown(); +/* */ case 603: +/* 276 */ return scrollPageUp(); +/* */ case 604: +/* 278 */ return scrollPageDown(); +/* */ case 605: +/* 280 */ return scrollAbsolute(); +/* */ } +/* 282 */ return super.handleEvent(e); +/* */ } +/* */ +/* */ public void dialogDisable(boolean disable) +/* */ { +/* 287 */ this.isDialogDisabled = disable; +/* */ } +/* */ +/* */ public synchronized boolean mouseDown(Event e, int x, int y) +/* */ { +/* 292 */ setFocus(true); +/* 293 */ int item = this.scrollPos + y / this.itemHeight; +/* 294 */ if ((item >= 0) && (item < this.items.size())) +/* 295 */ if (e.clickCount == 1) { +/* 296 */ treeSelect(item); +/* */ +/* */ +/* 299 */ int yStart = y / this.itemHeight * this.itemHeight; +/* 300 */ TreeNode node = elementAt(item); +/* 301 */ MoveablePolygon widget = node.isOpen() ? this.openedIcon : +/* 302 */ this.closedIcon; +/* 303 */ FontMetrics metrics = node.displayAsTitle() ? this.nFontMetrics : +/* 304 */ this.bFontMetrics; +/* 305 */ widget.moveTo(node.getLevel() * 14 + 5, yStart + +/* 306 */ metrics.getAscent() - 5); +/* 307 */ if (widget.getBoundingBox().contains(x, y)) +/* 308 */ treeOpen(item); +/* */ } else { +/* 310 */ treeOpen(item); +/* */ } +/* 312 */ return true; +/* */ } +/* */ +/* */ +/* */ public void treeSelect(int item) {} +/* */ +/* */ public void treeOpen(int item) {} +/* */ +/* */ private boolean setScrollValue(int value) +/* */ { +/* 322 */ value = Math.max(this.scrollbar.getMinimum(), value); +/* 323 */ value = Math.min(this.scrollbar.getMaximum(), value); +/* 324 */ this.scrollPos = (value / this.itemHeight); +/* 325 */ this.scrollbar.setValue(this.scrollPos * this.itemHeight); +/* 326 */ needRepaint(false, false); +/* 327 */ return true; +/* */ } +/* */ +/* */ private boolean scrollLineUp() { +/* 331 */ return setScrollValue(this.scrollPos * this.itemHeight - +/* 332 */ this.scrollbar.getLineIncrement()); +/* */ } +/* */ +/* */ private boolean scrollLineDown() { +/* 336 */ return setScrollValue(this.scrollPos * this.itemHeight + +/* 337 */ this.scrollbar.getLineIncrement()); +/* */ } +/* */ +/* */ private boolean scrollPageUp() { +/* 341 */ return setScrollValue(this.scrollPos * this.itemHeight - +/* 342 */ this.scrollbar.getPageIncrement()); +/* */ } +/* */ +/* */ private boolean scrollPageDown() { +/* 346 */ return setScrollValue(this.scrollPos * this.itemHeight + +/* 347 */ this.scrollbar.getPageIncrement()); +/* */ } +/* */ +/* */ private boolean scrollAbsolute() { +/* 351 */ return setScrollValue(this.scrollbar.getValue()); +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\TreePanel.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |