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