package NET.worlds.scape; import java.awt.CardLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.Panel; import java.awt.Point; import java.util.Vector; class TabbedDisplayPanel extends Panel { private int count; private Vector cards = new Vector(); private Vector cardNames = new Vector(); TabbedDisplayPanel() { this.setLayout(new CardLayout()); } void addItem(Component c) { this.insertItem(this.cards.size(), c); } void insertItem(int index, Component c) { String cardName = "" + this.count++; this.cardNames.insertElementAt(cardName, index); this.cards.insertElementAt(c, index); this.add(cardName, c); this.validate(); this.repaint(); } void removeItem(int index) { this.remove((Component)this.cards.elementAt(index)); this.cards.removeElementAt(index); this.cardNames.removeElementAt(index); } @Override public Component getComponent(int index) { return (Component)this.cards.elementAt(index); } void setChoice(int index) { ((CardLayout)this.getLayout()).show(this, (String)this.cardNames.elementAt(index)); } @Override public Insets insets() { return new Insets(0, 2, 2, 0); } @Override public void paint(Graphics g) { g.setColor(this.getBackground()); if (this.cards.size() != 0) { Dimension size = this.size(); vLine(g, 1, 0, size.height); g.setColor(this.getBackground().brighter()); vLine(g, 0, 0, size.height - 2); g.setColor(this.getBackground().darker()); hLine(g, 0, size.height - 1, size.width - 1); vLine(g, size.width - 1, size.height - 1, 0); hLine(g, 1, size.height - 2, size.width - 2); vLine(g, size.width - 2, size.height - 2, 0); } else { g.fillRect(0, 0, this.size().width, this.size().height); } } private static void vLine(Graphics g, int x1, int y1, int y2) { g.drawLine(x1, y1, x1, y2); } private static void hLine(Graphics g, int x1, int y1, int x2) { g.drawLine(x1, y1, x2, y1); } @Override public Component locate(int x, int y) { if (!this.inside(x, y)) { return null; } else { int n = this.countComponents(); for (int i = 0; i < n; i++) { Component c = this.getComponent(i); Point loc = c.location(); if (c != null && c.isVisible() && c.inside(x - loc.x, y - loc.y)) { return c; } } return this; } } }