diff options
Diffstat (limited to 'NET/worlds/scape/TabbedPanel.java')
| -rw-r--r-- | NET/worlds/scape/TabbedPanel.java | 329 |
1 files changed, 329 insertions, 0 deletions
diff --git a/NET/worlds/scape/TabbedPanel.java b/NET/worlds/scape/TabbedPanel.java new file mode 100644 index 0000000..5de0751 --- /dev/null +++ b/NET/worlds/scape/TabbedPanel.java @@ -0,0 +1,329 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.console.Console; +/* */ import NET.worlds.console.DialogDisabled; +/* */ import java.awt.BorderLayout; +/* */ import java.awt.Color; +/* */ import java.awt.Component; +/* */ import java.awt.Dimension; +/* */ import java.awt.Event; +/* */ import java.awt.Font; +/* */ import java.awt.FontMetrics; +/* */ import java.awt.Graphics; +/* */ import java.awt.Insets; +/* */ import java.awt.Panel; +/* */ import java.awt.Point; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class TabbedPanel +/* */ extends Panel +/* */ implements ClickEventHandler, DialogDisabled +/* */ { +/* */ private static final long serialVersionUID = 1L; +/* 36 */ private Vector<String> entries = new Vector(); +/* */ private int rows; +/* */ private int itemWidth; +/* */ private int itemHeight; +/* */ private int itemsPerRow; +/* */ private int choice; +/* */ private Font nFont; +/* */ private FontMetrics nFontMetrics; +/* */ private Font bFont; +/* */ private FontMetrics bFontMetrics; +/* */ private int fontHeight; +/* 47 */ private TabbedDisplayPanel disp = new TabbedDisplayPanel(); +/* */ private ClickEventHandler handler; +/* */ private boolean needRecalc; +/* */ private boolean isDialogDisabled; +/* */ +/* */ public TabbedPanel(ClickEventHandler handler) +/* */ { +/* 54 */ this.handler = handler; +/* 55 */ setLayout(new BorderLayout()); +/* 56 */ add("Center", this.disp); +/* */ } +/* */ +/* */ public TabbedPanel() +/* */ { +/* 61 */ this(null); +/* 62 */ this.handler = this; +/* */ } +/* */ +/* */ public void addItem(String name, Component c) +/* */ { +/* 67 */ this.entries.addElement(name); +/* 68 */ this.needRecalc = true; +/* 69 */ repaint(); +/* 70 */ this.disp.addItem(c); +/* */ } +/* */ +/* */ public void insertItem(int index, String name, Component c) +/* */ { +/* 75 */ this.entries.insertElementAt(name, index); +/* 76 */ this.disp.insertItem(index, c); +/* 77 */ if (index <= this.choice) +/* 78 */ this.choice = Math.min(this.choice + 1, this.entries.size() - 1); +/* 79 */ this.needRecalc = true; +/* 80 */ repaint(); +/* */ } +/* */ +/* */ public void removeItem(int index) +/* */ { +/* 85 */ this.entries.removeElementAt(index); +/* 86 */ this.disp.removeItem(index); +/* 87 */ if (index == this.choice) { +/* 88 */ int count = this.entries.size(); +/* 89 */ if (count > 0) { +/* 90 */ this.choice = Math.min(this.choice, count - 1); +/* 91 */ this.disp.setChoice(this.choice); +/* */ } +/* */ } +/* 94 */ else if (index < this.choice) { +/* 95 */ this.choice -= 1; } +/* 96 */ this.needRecalc = true; +/* 97 */ repaint(); +/* */ } +/* */ +/* */ public void select(int index) +/* */ { +/* 102 */ this.choice = index; +/* 103 */ repaint(); +/* 104 */ this.disp.setChoice(index); +/* */ } +/* */ +/* */ public String getName(int index) +/* */ { +/* 109 */ return (String)this.entries.elementAt(index); +/* */ } +/* */ +/* */ public void setName(int index, String name) +/* */ { +/* 114 */ this.entries.setElementAt(name, index); +/* 115 */ this.needRecalc = true; +/* 116 */ repaint(); +/* */ } +/* */ +/* */ public Component getComponent(int index) +/* */ { +/* 121 */ if (index < this.entries.size()) +/* 122 */ return this.disp.getComponent(index); +/* 123 */ return null; +/* */ } +/* */ +/* */ public int selected() +/* */ { +/* 128 */ return this.choice; +/* */ } +/* */ +/* */ public int itemAt(Point p) +/* */ { +/* 133 */ if (!this.needRecalc) { +/* 134 */ Point tab = new Point(0, 0); +/* 135 */ int count = this.entries.size(); +/* 136 */ for (int i = 0; i < count; i++) { +/* 137 */ getPosition(i, tab); +/* 138 */ if ((p.x >= tab.x) && (p.y >= tab.y) && (p.x < tab.x + this.itemWidth) && +/* 139 */ (p.y < tab.y + this.itemHeight)) +/* 140 */ return i; +/* */ } +/* */ } +/* 143 */ return -1; +/* */ } +/* */ +/* */ public void addNotify() +/* */ { +/* 148 */ super.addNotify(); +/* 149 */ this.nFont = new Font(Console.message("NotifyFont"), 0, 13); +/* */ +/* 151 */ this.nFontMetrics = getFontMetrics(this.nFont); +/* 152 */ this.bFont = new Font(Console.message("NotifyFont"), 1, 14); +/* */ +/* 154 */ this.bFontMetrics = getFontMetrics(this.bFont); +/* 155 */ this.fontHeight = Math.max(this.nFontMetrics.getHeight(), +/* 156 */ this.bFontMetrics.getHeight()); +/* 157 */ this.itemHeight = (this.fontHeight + 5); +/* */ } +/* */ +/* */ public Insets insets() +/* */ { +/* 162 */ if (this.needRecalc) +/* 163 */ recalc(); +/* 164 */ return new Insets(this.rows * this.itemHeight, 0, 0, 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setBounds(int x, int y, int width, int height) +/* */ { +/* 175 */ super.setBounds(x, y, width, height); +/* 176 */ this.needRecalc = true; +/* 177 */ repaint(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private void recalc() +/* */ { +/* 185 */ int count = this.entries.size(); +/* 186 */ this.itemWidth = 0; +/* 187 */ for (int i = 0; i < count; i++) { +/* 188 */ String name = (String)this.entries.elementAt(i); +/* 189 */ int w = Math.max(this.bFontMetrics.stringWidth(name), +/* 190 */ this.nFontMetrics.stringWidth(" " + name + " ")); +/* 191 */ this.itemWidth = Math.max(w, this.itemWidth); +/* */ } +/* 193 */ this.itemWidth += 4; +/* 194 */ this.itemsPerRow = Math.max(1, getSize().width / this.itemWidth); +/* 195 */ this.rows = ((count + this.itemsPerRow - 1) / this.itemsPerRow); +/* 196 */ this.needRecalc = false; +/* 197 */ invalidate(); +/* 198 */ validate(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void getPosition(int entry, Point pos) +/* */ { +/* 207 */ int entryRow = entry / this.itemsPerRow; +/* 208 */ int displayRow = entryRow; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 221 */ int column = entry - entryRow * this.itemsPerRow; +/* 222 */ pos.x = (column * this.itemWidth); +/* 223 */ pos.y = ((this.rows - 1 - displayRow) * this.itemHeight - 2); +/* */ } +/* */ +/* */ private static void vLine(Graphics g, int x1, int y1, int y2) +/* */ { +/* 228 */ g.drawLine(x1, y1, x1, y2); +/* */ } +/* */ +/* */ private static void hLine(Graphics g, int x1, int y1, int x2) +/* */ { +/* 233 */ g.drawLine(x1, y1, x2, y1); +/* */ } +/* */ +/* */ public void paint(Graphics g) +/* */ { +/* 238 */ if (this.needRecalc) { +/* 239 */ recalc(); +/* */ } +/* 241 */ g.setColor(getBackground()); +/* 242 */ g.fillRect(0, 0, getSize().width, getSize().height); +/* */ +/* 244 */ int count = this.entries.size(); +/* 245 */ if (count != 0) { +/* 246 */ Point p = new Point(0, 0); +/* 247 */ int maxWidth = this.itemWidth - 4; +/* 248 */ for (int i = 0; i < count; i++) { +/* 249 */ getPosition(i, p); +/* 250 */ String ent = (String)this.entries.elementAt(i); +/* 251 */ int x1 = p.x; +/* 252 */ int y1 = p.y + 4; +/* 253 */ int y2 = y1 + this.fontHeight; +/* 254 */ int yFont = y1; +/* 255 */ Font font = this.nFont; +/* 256 */ FontMetrics fm = this.nFontMetrics; +/* 257 */ boolean selected = i == this.choice; +/* 258 */ if (selected) { +/* 259 */ y1 = p.y + 2; +/* 260 */ y2 = y1 + this.fontHeight + 4; +/* 261 */ yFont = y1 + 1; +/* 262 */ font = this.bFont; +/* 263 */ fm = this.bFontMetrics; +/* */ } +/* 265 */ int width = fm.stringWidth(ent); +/* 266 */ int spacing = (maxWidth - width) / 2; +/* 267 */ int x2 = x1 + maxWidth; +/* 268 */ g.setFont(font); +/* 269 */ g.setColor(getBackground().brighter()); +/* 270 */ if (selected) { +/* 271 */ hLine(g, 0, y2, x1); +/* 272 */ hLine(g, x2 + 3, y2, getSize().width); +/* */ } +/* 274 */ vLine(g, x1, y2, y1 + 2); +/* 275 */ g.drawLine(x1, y1 + 2, x1 + 2, y1); +/* 276 */ hLine(g, x1 + 2, y1, x2); +/* 277 */ g.setColor(getBackground().darker()); +/* 278 */ vLine(g, x2 + 1, y1 + 1, y2); +/* 279 */ vLine(g, x2 + 2, y1 + 2, y2); +/* 280 */ g.setColor(getForeground()); +/* 281 */ g.drawString(ent, x1 + 1 + spacing, yFont + +/* 282 */ fm.getAscent() + fm.getLeading()); +/* */ } +/* */ } +/* */ } +/* */ +/* */ public void clickEvent(Component who, Point location, int flags) {} +/* */ +/* */ @Deprecated +/* */ public boolean mouseDown(Event event, int x, int y) +/* */ { +/* 292 */ Point p = new Point(x, y); +/* 293 */ int tmp = itemAt(p); +/* 294 */ if (tmp != -1) { +/* 295 */ this.choice = tmp; +/* 296 */ repaint(); +/* 297 */ this.disp.setChoice(this.choice); +/* 298 */ int flags = 1; +/* 299 */ if (event.metaDown()) +/* 300 */ flags |= 0x4; +/* 301 */ this.handler.clickEvent(this, p, flags); +/* 302 */ return true; +/* */ } +/* 304 */ return false; +/* */ } +/* */ +/* */ @Deprecated +/* */ public boolean handleEvent(Event event) +/* */ { +/* 310 */ if (this.isDialogDisabled) +/* 311 */ return false; +/* 312 */ return super.handleEvent(event); +/* */ } +/* */ +/* */ public void dialogDisable(boolean disable) +/* */ { +/* 317 */ this.isDialogDisabled = disable; +/* 318 */ Component c = getComponent(selected()); +/* 319 */ if ((c != null) && ((c instanceof DialogDisabled))) { +/* 320 */ ((DialogDisabled)c).dialogDisable(disable); +/* */ } +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\TabbedPanel.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |