f@0: /* f@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool f@0: f@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: package uk.ac.qmul.eecs.ccmi.gui; f@0: f@0: import java.awt.Component; f@0: import java.awt.event.ActionEvent; f@0: import java.awt.event.InputEvent; f@0: import java.awt.event.KeyEvent; f@0: f@0: import javax.swing.AbstractAction; f@0: import javax.swing.JTabbedPane; f@0: import javax.swing.KeyStroke; f@0: f@0: import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory; f@0: import uk.ac.qmul.eecs.ccmi.speech.SpeechUtilities; f@0: f@0: /** f@0: * f@0: * The tabbed pane of the editor. On each tab a {@code DiagramPanel} is displayed. f@0: * f@0: */ f@0: @SuppressWarnings("serial") f@0: public class EditorTabbedPane extends JTabbedPane { f@0: /** f@0: * Creates a new {@code EditorTabbedPane} f@0: * f@0: * @param frame the frame when this tabbed pane will be placed f@0: */ f@0: public EditorTabbedPane(EditorFrame frame){ f@0: setFocusTraversalKeysEnabled(false); f@0: f@0: SpeechUtilities.changeTabListener(this,frame); f@0: getAccessibleContext().setAccessibleName("tab "); f@0: f@0: /* shut up the narrator upon pressing ctrl */ f@0: getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTROL,InputEvent.CTRL_DOWN_MASK),"ctrldown"); f@0: getActionMap().put("ctrldown",new AbstractAction(){ f@0: public void actionPerformed(ActionEvent evt){ f@0: NarratorFactory.getInstance().shutUp(); f@0: } f@0: }); f@0: } f@0: f@0: /** f@0: * Sets the title of the tab containing a component. f@0: * f@0: * @param component the component in the tab whose title has to be set f@0: * @param title the new title f@0: */ f@0: public void setComponentTabTitle(Component component, String title){ f@0: int index = indexOfComponent(component); f@0: if(index == -1) f@0: return; f@0: setTitleAt(index,title); f@0: } f@0: f@0: /** f@0: * Returns the title of the tab containing a component. f@0: * f@0: * @param component the component contained by the tab f@0: * @return the title of the tab containing {@code component} f@0: */ f@0: public String getComponentTabTitle(Component component){ f@0: int index = indexOfComponent(component); f@0: if(index == -1) f@0: return null; f@0: return getTitleAt(index); f@0: } f@0: f@0: /** f@0: * Repaints the title on a tab containing a component. f@0: * f@0: * @param component the component contained by the tab whose title will be repainted f@0: */ f@0: public void refreshComponentTabTitle(Component component){ f@0: setComponentTabTitle(component,component.getName()); f@0: } f@0: f@0: @Override f@0: public DiagramPanel getComponentAt(int n){ f@0: return (DiagramPanel)super.getComponent(n); f@0: } f@0: f@0: /** f@0: * The components in an {@code EditorTabbedPane} are all instances of {@code DiagramPanel}, which in turns f@0: * holds an instance of {@code Diagram}. This utility methods retrieves the index of f@0: * the {@code DiagramPanel} whose diagram has the same name than the {@code String} passed as argument. f@0: * f@0: * @param diagramName the name of the diagram to look for f@0: * @return the index of the diagram named as {@code diagramName} or {@code -1} if f@0: * such diagram doesn't exist f@0: */ f@0: public int getDiagramNameTabIndex(String diagramName){ f@0: for(int i=0; i