/** * Selects the canvas at the specified index. If the index is out of bounds, perform no action. * * @param index - the index of the canvas to be viewed. * @requires none (INDEX DOES NOT HAVE TO BE WITHIN BOUNDS) */ public void selectCanvas(int index) { if (index >= 0 && index < drawerCards.size()) { TabCard card = drawerCards.get(index); canvasPane.removeAll(); canvasPane.add(card.getScroll()); canvasPane.revalidate(); canvasPane.repaint(); for (TabCard otherCard : drawerCards) { otherCard.getButton().toggleSelected(false); } card.getButton().toggleSelected(true); this.selectedIndex = index; this.revalidate(); } }
/** * Reassigns the set of canvases that this explorer controls. Though the collection of canvas mnay * be empty, it may not be null. * * @param items * @requires items != null && for each element in item, element!= null */ public void setDrawersCard(List<? extends Canvas> items) { drawerCards.clear(); menu.removeAll(); List<JComponent> buttons = new ArrayList<JComponent>(); for (int i = 0; i < items.size(); i++) { TabCard card = new TabCard(i, items.get(i), this, scrollable); drawerCards.add(card); buttons.add(card.getButton()); card.getButton().setPreferredSize(new Dimension(125, BUTTON_HEIGHT)); menu.add(card.getMenuItem()); } wheeler.setElements(buttons); this.selectCanvas(0); }