Skip to content

Commit 8d5aa57

Browse files
committed
Merge pull request #91 from ProgrammingLife3/fix/bettercontrolmenu
Fix/bettercontrolmenu
2 parents 3a252a9 + 9e012d9 commit 8d5aa57

File tree

7 files changed

+64
-46
lines changed

7 files changed

+64
-46
lines changed

src/main/java/tudelft/ti2806/pl3/Constants.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tudelft.ti2806.pl3;
22

33
/**
4+
* Constants contains every string used in the GUI.
45
* Created by Mathieu Post on 17-6-15.
56
*/
67
public class Constants {
@@ -10,6 +11,7 @@ public class Constants {
1011
public static final char MINUS = '-';
1112
public static final char ARROW_RIGHT = '\u2192';
1213
public static final char ARROW_LEFT = '\u2190';
14+
public static final String SPACE = "Space";
1315

1416
// Name of the application.
1517
public static final String APP_NAME = "Helix" + POWER;
@@ -28,7 +30,11 @@ public class Constants {
2830
+ "- Kasper Wendel\n"
2931
+ "\n"
3032
+ "The code of this application is open source and can be found on GitHub: \n";
31-
public static final String INFO_CONTROLS = APP_NAME + " uses key shortcuts to make life easier. "
33+
public static final String INFO_CONTROLS = "To achieve semantic zooming " + APP_NAME
34+
+ " combines nodes to new nodes, we call it wrapping."
35+
+ "When a node has a square icon it means that it can unwrap to more nodes. "
36+
+ "If it has a circle icon it's fully unwrapped.\n"
37+
+ APP_NAME + " uses key shortcuts to make life easier. "
3238
+ "All the controls that can be used are listed below. \n"
3339
+ "\n"
3440
+ "Zooming in \t " + PLUS + " \n"
@@ -37,10 +43,11 @@ public class Constants {
3743
+ "Move the view to the left \t " + ARROW_LEFT + " \n"
3844
+ "Move the view to the right \t " + ARROW_RIGHT + " \n"
3945
+ "Gene navigation window \t G \n"
40-
+ "Hide/show phylogenetic tree window \t spacebar \n"
46+
+ "Hide/show phylogenetic tree window \t " + SPACE + " \n"
4147
+ "\n"
4248
+ "All of the menus can be controlled with the underlined letter, "
4349
+ "hold the ALT key to activate this.";
50+
4451
public static final String INFO_GITHUB_URL = "https://github.com/ProgrammingLife3/ProgrammingLife3";
4552

4653
// Menu constants.
@@ -60,6 +67,7 @@ public class Constants {
6067
public static final String MENU_VIEW_RESET = "Reset view";
6168
public static final String MENU_VIEW_NAVIGATE_TO_GENE = "Navigate to gene";
6269
public static final String MENU_VIEW_METADATA = "Filter on metadata";
70+
public static final String MENU_VIEW_PYLO = "Phylogenetic view";
6371

6472
public static final String MENU_HELP = "Help";
6573
public static final String MENU_HELP_CONTROLS = "Controls";
@@ -68,4 +76,10 @@ public class Constants {
6876
public static final String DIALOG_ERROR = "Error!";
6977
public static final String DETAILVIEW_GENOMES = "Genomes:";
7078
public static final String DETAILVIEW_LABELS = "Labels:";
79+
80+
// Phylogenetic view constants.
81+
public static final String PHYLO_WINDOW_TITLE = "Select Genomes";
82+
public static final String PHYLO_BUTTON_LABEL_UPDATE = "Update";
83+
public static final String PHYLO_LABEL_PHYLOGENETIC_TREE = "Phylogenetic tree";
84+
public static final String PHYLO_LABEL_COMMON_ANCESTOR = "Common ancestor";
7185
}

src/main/java/tudelft/ti2806/pl3/controls/KeyController.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class KeyController implements KeyListener {
1515

1616
/**
1717
* Constructor removes the old keylisteners and makes our own.
18-
*
18+
*
1919
* @param app
2020
* that is controlled
2121
*/
@@ -32,23 +32,23 @@ public KeyController(Application app) {
3232
public void release() {
3333
app.removeKeyListener(this);
3434
}
35-
35+
3636
/**
3737
* KeyTyped is triggered when the unicode character represented by this key
3838
* is sent by the keyboard to system input.
39-
*
39+
*
4040
* @param event
4141
* key that is typed
4242
*/
43-
43+
4444
@Override
4545
public void keyTyped(KeyEvent event) {
46-
46+
4747
}
48-
48+
4949
/**
5050
* KeyPressed is triggered when the key goes down.
51-
*
51+
*
5252
* @param event
5353
* key that is pressed
5454
*/
@@ -58,10 +58,6 @@ public void keyPressed(KeyEvent event) {
5858
app.stop();
5959
}
6060

61-
if (event.getKeyCode() == KeyEvent.VK_SPACE) {
62-
app.getSideBarController().toggleSideBar();
63-
}
64-
6561
if (event.getKeyCode() == KeyEvent.VK_EQUALS) {
6662
app.getGraphController().zoomLevelUp();
6763
}
@@ -77,15 +73,15 @@ public void keyPressed(KeyEvent event) {
7773
app.getGraphController().removeDetailView();
7874
}
7975

80-
76+
8177
/**
8278
* KeyReleased is triggered when the key comes up.
83-
*
79+
*
8480
* @param event
8581
* key that is releases
8682
*/
8783
@Override
8884
public void keyReleased(KeyEvent event) {
89-
85+
9086
}
9187
}

src/main/java/tudelft/ti2806/pl3/menubar/MenuBarController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
public class MenuBarController implements ActionListener, Controller {
4040

4141
private final MenuBarView menuBarView;
42-
4342
private final Application application;
4443

4544
/**
@@ -102,6 +101,10 @@ private void showFindGenes() {
102101
application.getFindGenesController().openDialog();
103102
}
104103

104+
private void toggleSideBar() {
105+
application.getSideBarController().toggleSideBar();
106+
}
107+
105108
private void filterMetadata() {
106109
application.getMetaFilterController().openDialog();
107110
}
@@ -119,6 +122,7 @@ private void displayControls() {
119122

120123
/**
121124
* Make a {@link JTextPane} with controls text.
125+
*
122126
* @return JTextpane with control text.
123127
*/
124128
public JTextPane makeControls() {
@@ -148,6 +152,7 @@ private void displayAbout() {
148152

149153
/**
150154
* Make a {@link JTextPane} with about me text.
155+
*
151156
* @return JTextpane with about me text.
152157
*/
153158
public JTextPane makeAbout() {
@@ -250,6 +255,9 @@ public void actionPerformed(ActionEvent e) {
250255
case Constants.MENU_HELP_ABOUT:
251256
displayAbout();
252257
break;
258+
case Constants.MENU_VIEW_PYLO:
259+
toggleSideBar();
260+
break;
253261
default:
254262
break;
255263
}

src/main/java/tudelft/ti2806/pl3/menubar/MenuBarView.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ private JMenu setUpView() {
9292
JMenuItem findGenes = new JMenuItem(Constants.MENU_VIEW_NAVIGATE_TO_GENE);
9393
findGenes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,0));
9494
findGenes.setMnemonic(KeyEvent.VK_G);
95-
JMenuItem filterMetadata = new JMenuItem("Filter on metadata");
95+
JMenuItem phylo = new JMenuItem(Constants.MENU_VIEW_PYLO);
96+
phylo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0));
97+
phylo.setMnemonic(KeyEvent.VK_P);
98+
JMenuItem filterMetadata = new JMenuItem(Constants.MENU_VIEW_METADATA);
9699
filterMetadata.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,0));
97100
filterMetadata.setMnemonic(KeyEvent.VK_F);
98101

@@ -103,6 +106,7 @@ private JMenu setUpView() {
103106
viewMenu.add(reset);
104107
viewMenu.add(findGenes);
105108
viewMenu.add(filterMetadata);
109+
viewMenu.add(phylo);
106110

107111
return viewMenu;
108112
}

src/main/java/tudelft/ti2806/pl3/sidebar/phylotree/PhyloView.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tudelft.ti2806.pl3.sidebar.phylotree;
22

33
import newick.NewickParser;
4+
import tudelft.ti2806.pl3.Constants;
45
import tudelft.ti2806.pl3.ScreenSize;
56
import tudelft.ti2806.pl3.View;
67
import tudelft.ti2806.pl3.util.Resources;
@@ -36,12 +37,8 @@
3637
* Created by Kasper on 20-5-2015.
3738
*/
3839
public class PhyloView extends JPanel implements View, Observer {
39-
private static final String WINDOW_TITLE = "Select Genomes";
40-
private static final String BUTTON_LABEL_UPDATE = "Update";
41-
private static final String ICON_BACTERIA = "pictures/bacteria_small.jpg";
4240

43-
public static final String LABEL_PHYLOGENETIC_TREE = "Phylogenetic tree";
44-
public static final String LABEL_COMMON_ANCESTOR = "Common ancestor";
41+
private static final String ICON_BACTERIA = "pictures/bacteria_small.jpg";
4542

4643
private JTree jTree;
4744
private List<String> selected = new ArrayList<>();
@@ -72,7 +69,7 @@ private void setUpUserInterface() {
7269
final int width = ScreenSize.getInstance().getSideBarWidth() - 10;
7370
final int height = ScreenSize.getInstance().getHeight() - 100;
7471

75-
header = new JLabel(WINDOW_TITLE);
72+
header = new JLabel(Constants.PHYLO_WINDOW_TITLE);
7673
header.setPreferredSize(new Dimension(width, 50));
7774

7875
scroller = new JScrollPane(jTree,
@@ -89,7 +86,7 @@ private void setUpUserInterface() {
8986
this.add(emptyLabel);
9087
add(Box.createVerticalGlue());
9188

92-
button = new JButton(BUTTON_LABEL_UPDATE);
89+
button = new JButton(Constants.PHYLO_BUTTON_LABEL_UPDATE);
9390
button.setVisible(false);
9491
this.add(button);
9592
button.setPreferredSize(new Dimension(200, 50));
@@ -112,7 +109,7 @@ private void setUpLook() {
112109
* @return Root node.
113110
*/
114111
private DefaultMutableTreeNode convertTree(NewickParser.TreeNode tree) {
115-
DefaultMutableTreeNode root = new DefaultMutableTreeNode(LABEL_PHYLOGENETIC_TREE);
112+
DefaultMutableTreeNode root = new DefaultMutableTreeNode(Constants.PHYLO_LABEL_PHYLOGENETIC_TREE);
116113
convertChildren(tree, root);
117114

118115
return root;
@@ -131,7 +128,7 @@ private void convertChildren(NewickParser.TreeNode tree, DefaultMutableTreeNode
131128
for (NewickParser.TreeNode child : tree.getChildren()) {
132129
DefaultMutableTreeNode childNode;
133130
if (child.getName() == null) {
134-
childNode = new DefaultMutableTreeNode(LABEL_COMMON_ANCESTOR);
131+
childNode = new DefaultMutableTreeNode(Constants.PHYLO_LABEL_COMMON_ANCESTOR);
135132
} else {
136133
childNode = new DefaultMutableTreeNode(child.getName());
137134
}
@@ -197,8 +194,8 @@ public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
197194
DefaultMutableTreeNode select = (DefaultMutableTreeNode) path
198195
.getLastPathComponent();
199196
String selectName = select.toString();
200-
if (selectName.equals(LABEL_COMMON_ANCESTOR)
201-
|| selectName.equals(LABEL_PHYLOGENETIC_TREE)) {
197+
if (selectName.equals(Constants.PHYLO_LABEL_COMMON_ANCESTOR)
198+
|| selectName.equals(Constants.PHYLO_LABEL_PHYLOGENETIC_TREE)) {
202199
selected.addAll(getChildsOfAncestor(select));
203200
} else {
204201
selected.add(select.toString());
@@ -237,7 +234,7 @@ private List<String> getChildsOfAncestor(DefaultMutableTreeNode name) {
237234
while (children.hasMoreElements()) {
238235
DefaultMutableTreeNode next = (DefaultMutableTreeNode) children
239236
.nextElement();
240-
if (next.toString().equals(LABEL_COMMON_ANCESTOR)) {
237+
if (next.toString().equals(Constants.PHYLO_LABEL_COMMON_ANCESTOR)) {
241238
selected.addAll(getChildsOfAncestor(next));
242239
} else {
243240
selected.add(next.toString());

src/test/java/tudelft/ti2806/pl3/controls/KeyControllerTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.mockito.Mock;
66
import org.mockito.runners.MockitoJUnitRunner;
77
import tudelft.ti2806.pl3.Application;
8-
import tudelft.ti2806.pl3.sidebar.SideBarController;
98
import tudelft.ti2806.pl3.visualization.GraphController;
109

1110
import java.awt.event.KeyEvent;
@@ -40,19 +39,6 @@ public void testEscape() {
4039
verify(application, times(1)).stop();
4140
}
4241

43-
@Test
44-
public void testSpace() {
45-
KeyController keyController = new KeyController(application);
46-
when(keyEvent.getKeyCode()).thenReturn(KeyEvent.VK_SPACE);
47-
SideBarController sideBarController = mock(SideBarController.class);
48-
when(application.getSideBarController()).thenReturn(sideBarController);
49-
when(application.getGraphController()).thenReturn(mock(GraphController.class));
50-
51-
keyController.keyPressed(keyEvent);
52-
verify(application, times(1)).getSideBarController();
53-
verify(sideBarController, times(1)).toggleSideBar();
54-
}
55-
5642
@Test
5743
public void testPlus() {
5844
KeyController keyController = new KeyController(application);

src/test/java/tudelft/ti2806/pl3/menubar/MenuBarControllerTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import tudelft.ti2806.pl3.Application;
1616
import tudelft.ti2806.pl3.Constants;
1717
import tudelft.ti2806.pl3.findgenes.FindGenesController;
18+
import tudelft.ti2806.pl3.sidebar.SideBarController;
1819
import tudelft.ti2806.pl3.visualization.GraphController;
1920

2021
import java.awt.event.ActionEvent;
@@ -149,6 +150,17 @@ public void testActionShowFindGenes() {
149150
verify(findgenesController, times(1)).openDialog();
150151
}
151152

153+
@Test
154+
public void testActionSideBar() {
155+
SideBarController sideBarController = mock(SideBarController.class);
156+
when(actionEvent.getActionCommand()).thenReturn(Constants.MENU_VIEW_PYLO);
157+
when(application.getSideBarController()).thenReturn(sideBarController);
158+
menuBarController.actionPerformed(actionEvent);
159+
160+
verify(application, times(1)).getSideBarController();
161+
verify(sideBarController, times(1)).toggleSideBar();
162+
}
163+
152164
@Test
153165
public void testMakeControls() {
154166
String expected = Constants.INFO_CONTROLS;
@@ -160,8 +172,9 @@ public void testMakeControls() {
160172
public void testMakeAbout() {
161173
String expected = Constants.INFO_ABOUT + "githublink";
162174
String result = menuBarController.makeAbout().getText();
163-
// assertEquals(expected, result);
164-
// assertEquals(result.contains(expected), expected.contains(result));
175+
// this test is not working
176+
//assertEquals(expected, result);
177+
//assertEquals(result.contains(expected), expected.contains(result));
165178
}
166179

167180
}

0 commit comments

Comments
 (0)