comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:78b7fc5391a2
1 /*
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
3
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package uk.ac.qmul.eecs.ccmi.gui;
20
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.InputEvent;
24 import java.awt.event.KeyEvent;
25
26 import javax.swing.AbstractAction;
27 import javax.swing.JTabbedPane;
28 import javax.swing.KeyStroke;
29
30 import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory;
31 import uk.ac.qmul.eecs.ccmi.speech.SpeechUtilities;
32
33 /**
34 *
35 * The tabbed pane of the editor. On each tab a {@code DiagramPanel} is displayed.
36 *
37 */
38 @SuppressWarnings("serial")
39 public class EditorTabbedPane extends JTabbedPane {
40 /**
41 * Creates a new {@code EditorTabbedPane}
42 *
43 * @param frame the frame when this tabbed pane will be placed
44 */
45 public EditorTabbedPane(EditorFrame frame){
46 setFocusTraversalKeysEnabled(false);
47
48 SpeechUtilities.changeTabListener(this,frame);
49 getAccessibleContext().setAccessibleName("tab ");
50
51 /* shut up the narrator upon pressing ctrl */
52 getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTROL,InputEvent.CTRL_DOWN_MASK),"ctrldown");
53 getActionMap().put("ctrldown",new AbstractAction(){
54 public void actionPerformed(ActionEvent evt){
55 NarratorFactory.getInstance().shutUp();
56 }
57 });
58 }
59
60 /**
61 * Sets the title of the tab containing a component.
62 *
63 * @param component the component in the tab whose title has to be set
64 * @param title the new title
65 */
66 public void setComponentTabTitle(Component component, String title){
67 int index = indexOfComponent(component);
68 if(index == -1)
69 return;
70 setTitleAt(index,title);
71 }
72
73 /**
74 * Returns the title of the tab containing a component.
75 *
76 * @param component the component contained by the tab
77 * @return the title of the tab containing {@code component}
78 */
79 public String getComponentTabTitle(Component component){
80 int index = indexOfComponent(component);
81 if(index == -1)
82 return null;
83 return getTitleAt(index);
84 }
85
86 /**
87 * Repaints the title on a tab containing a component.
88 *
89 * @param component the component contained by the tab whose title will be repainted
90 */
91 public void refreshComponentTabTitle(Component component){
92 setComponentTabTitle(component,component.getName());
93 }
94
95 @Override
96 public DiagramPanel getComponentAt(int n){
97 return (DiagramPanel)super.getComponent(n);
98 }
99
100 /**
101 * The components in an {@code EditorTabbedPane} are all instances of {@code DiagramPanel}, which in turns
102 * holds an instance of {@code Diagram}. This utility methods retrieves the index of
103 * the {@code DiagramPanel} whose diagram has the same name than the {@code String} passed as argument.
104 *
105 * @param diagramName the name of the diagram to look for
106 * @return the index of the diagram named as {@code diagramName} or {@code -1} if
107 * such diagram doesn't exist
108 */
109 public int getDiagramNameTabIndex(String diagramName){
110 for(int i=0; i<getTabCount();i++){
111 DiagramPanel dPanel = getComponentAt(i);
112 if(diagramName.equals(dPanel.getDiagram().getName())){
113 return i;
114 }
115 }
116 return -1;
117 }
118
119 /**
120 * The components in an {@code EditorTabbedPane} are all instances of {@code DiagramPanel}, which in turns
121 * hold an instance of {@code Diagram}. This method returns the index of the {@code DiagramPanel}
122 * whose diagram has been saved on the file system at the path specified as argument.
123 *
124 * @param path a path on the file system identifying the diagram
125 * @return the index of the {@code DiagramPanel} whose diagram has been saved on
126 * the file system in {@code path}, or {@code -1} if such diagram doesn't exist
127 */
128 public int getPathTabIndex(String path){
129 for(int i=0; i<getTabCount();i++){
130 DiagramPanel dPanel = getComponentAt(i);
131 if(path.equals(dPanel.getFilePath())){
132 return i;
133 }
134 }
135 return -1;
136 }
137 }