/** Continue to scroll to the left or right for every time step */ public void actionPerformed(ActionEvent e) { if (directedToLeft) { wheeler.scrollLeft(); } else { wheeler.scrollRight(); } }
/** Constructs new TabbedExplorer that is scrollable if specified as true. */ public TabbedExplorer(boolean scrollable) { super(); this.scrollable = scrollable; this.drawerCards = new ArrayList<TabCard>(); this.canvasPane = new JPanel(new BorderLayout()); canvasPane.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, CGraphite.blue)); this.setBackground(Color.black); this.timer = new Timer(300, this); menu = new JPopupMenu(); wheeler = new CWheeler(new ArrayList<JComponent>(), false, Color.black); wheeler.setPreferredSize(new Dimension(wheeler.getPreferredSize().width, BUTTON_HEIGHT)); left = new CTabButton("<<"); left.setPreferredSize(BUTTON_DIMENSION); left.addMouseListener(this); right = new CTabButton(">>"); right.setPreferredSize(BUTTON_DIMENSION); right.addMouseListener(this); down = new CTabButton("V"); down.setPreferredSize(BUTTON_DIMENSION); down.addMouseListener(this); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 0; gbc.weighty = 0; gbc.fill = GridBagConstraints.NONE; add(left, gbc); gbc.gridx++; gbc.weightx = 1; gbc.fill = GridBagConstraints.BOTH; add(wheeler, gbc); gbc.gridx++; gbc.weightx = 0; gbc.fill = GridBagConstraints.NONE; add(right, gbc); gbc.gridx++; add(down, gbc); gbc.gridx = 0; gbc.gridy++; gbc.gridwidth = 4; gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; add(canvasPane, gbc); }
/** Start the timer when the user presses the mouse. */ public void mousePressed(MouseEvent e) { if (e.getSource().equals(left)) { directedToLeft = true; wheeler.scrollLeft(); timer.start(); } else if (e.getSource().equals(right)) { directedToLeft = false; wheeler.scrollRight(); timer.start(); } else if (e.getSource().equals(down)) { menu.show(down, 5, 5); } }
/** * 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); }
/** * Scroll to a particular draw at the specified index * * @param index */ void scrollToWheelItem(int index) { if (index >= 0 && index < drawerCards.size()) { wheeler.scrollToWheelItem(drawerCards.get(index).getButton()); } }