Mercurial > hg > accesspd
diff java/src/uk/ac/qmul/eecs/ccmi/gui/EditorTabbedPane.java @ 0:78b7fc5391a2
first import, outcome of NIME 2014 hackaton
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Tue, 08 Jul 2014 16:28:59 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/src/uk/ac/qmul/eecs/ccmi/gui/EditorTabbedPane.java Tue Jul 08 16:28:59 2014 +0100 @@ -0,0 +1,137 @@ +/* + CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool + + Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +package uk.ac.qmul.eecs.ccmi.gui; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +import javax.swing.AbstractAction; +import javax.swing.JTabbedPane; +import javax.swing.KeyStroke; + +import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory; +import uk.ac.qmul.eecs.ccmi.speech.SpeechUtilities; + +/** + * + * The tabbed pane of the editor. On each tab a {@code DiagramPanel} is displayed. + * + */ +@SuppressWarnings("serial") +public class EditorTabbedPane extends JTabbedPane { + /** + * Creates a new {@code EditorTabbedPane} + * + * @param frame the frame when this tabbed pane will be placed + */ + public EditorTabbedPane(EditorFrame frame){ + setFocusTraversalKeysEnabled(false); + + SpeechUtilities.changeTabListener(this,frame); + getAccessibleContext().setAccessibleName("tab "); + + /* shut up the narrator upon pressing ctrl */ + getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTROL,InputEvent.CTRL_DOWN_MASK),"ctrldown"); + getActionMap().put("ctrldown",new AbstractAction(){ + public void actionPerformed(ActionEvent evt){ + NarratorFactory.getInstance().shutUp(); + } + }); + } + + /** + * Sets the title of the tab containing a component. + * + * @param component the component in the tab whose title has to be set + * @param title the new title + */ + public void setComponentTabTitle(Component component, String title){ + int index = indexOfComponent(component); + if(index == -1) + return; + setTitleAt(index,title); + } + + /** + * Returns the title of the tab containing a component. + * + * @param component the component contained by the tab + * @return the title of the tab containing {@code component} + */ + public String getComponentTabTitle(Component component){ + int index = indexOfComponent(component); + if(index == -1) + return null; + return getTitleAt(index); + } + + /** + * Repaints the title on a tab containing a component. + * + * @param component the component contained by the tab whose title will be repainted + */ + public void refreshComponentTabTitle(Component component){ + setComponentTabTitle(component,component.getName()); + } + + @Override + public DiagramPanel getComponentAt(int n){ + return (DiagramPanel)super.getComponent(n); + } + + /** + * The components in an {@code EditorTabbedPane} are all instances of {@code DiagramPanel}, which in turns + * holds an instance of {@code Diagram}. This utility methods retrieves the index of + * the {@code DiagramPanel} whose diagram has the same name than the {@code String} passed as argument. + * + * @param diagramName the name of the diagram to look for + * @return the index of the diagram named as {@code diagramName} or {@code -1} if + * such diagram doesn't exist + */ + public int getDiagramNameTabIndex(String diagramName){ + for(int i=0; i<getTabCount();i++){ + DiagramPanel dPanel = getComponentAt(i); + if(diagramName.equals(dPanel.getDiagram().getName())){ + return i; + } + } + return -1; + } + + /** + * The components in an {@code EditorTabbedPane} are all instances of {@code DiagramPanel}, which in turns + * hold an instance of {@code Diagram}. This method returns the index of the {@code DiagramPanel} + * whose diagram has been saved on the file system at the path specified as argument. + * + * @param path a path on the file system identifying the diagram + * @return the index of the {@code DiagramPanel} whose diagram has been saved on + * the file system in {@code path}, or {@code -1} if such diagram doesn't exist + */ + public int getPathTabIndex(String path){ + for(int i=0; i<getTabCount();i++){ + DiagramPanel dPanel = getComponentAt(i); + if(path.equals(dPanel.getFilePath())){ + return i; + } + } + return -1; + } +}