Skip to content

Commit 87ed79c

Browse files
committed
Merge pull request #75 from ProgrammingLife3/refactor/resizeadapter
Refactor/resizeadapter
2 parents d04d328 + e46b46c commit 87ed79c

File tree

2 files changed

+61
-33
lines changed

2 files changed

+61
-33
lines changed

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

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import newick.ParseException;
44
import tudelft.ti2806.pl3.controls.KeyController;
5+
import tudelft.ti2806.pl3.controls.ResizeAdapter;
56
import tudelft.ti2806.pl3.controls.ScrollListener;
67
import tudelft.ti2806.pl3.controls.WindowController;
78
import tudelft.ti2806.pl3.data.graph.GraphDataRepository;
@@ -23,8 +24,6 @@
2324
import java.awt.Component;
2425
import java.awt.Dimension;
2526
import java.awt.Rectangle;
26-
import java.awt.event.ComponentAdapter;
27-
import java.awt.event.ComponentEvent;
2827
import java.io.File;
2928
import java.io.FileNotFoundException;
3029
import java.io.IOException;
@@ -122,7 +121,7 @@ public void setUpFrame() {
122121
}
123122

124123
private void setUpUi() {
125-
this.addComponentListener(resizeAdapter());
124+
this.addComponentListener(new ResizeAdapter(this));
126125
setZoomBarView();
127126
setGraphView();
128127
setSideBarView();
@@ -134,7 +133,7 @@ private void setUpUi() {
134133
public void makeGraphFromFolder() {
135134
try {
136135
File folder = FileSelector.selectFolder("Select data folder", this);
137-
File[] files = FileSelector.getFilesFromFolder(folder, ".node.graph", ".edge.graph",".nwk");
136+
File[] files = FileSelector.getFilesFromFolder(folder, ".node.graph", ".edge.graph", ".nwk");
138137
makeGraph(files[0], files[1], files[2]);
139138
} catch (FileSelectorException | NullPointerException exception) {
140139
if (DialogUtil.confirm("Error!", "Your file was not found. Want to try again?")) {
@@ -277,35 +276,6 @@ public void setZoomBarView() {
277276
view.setVisible(true);
278277
}
279278

280-
/**
281-
* Creates an adapter that updates screen sizes for the components in the view.
282-
*
283-
* @return the adapter
284-
*/
285-
private ComponentAdapter resizeAdapter() {
286-
return new ComponentAdapter() {
287-
@Override
288-
public void componentResized(ComponentEvent e) {
289-
Rectangle bounds = new Rectangle(main.getWidth(), main.getHeight());
290-
291-
size.setWidth((int) bounds.getWidth());
292-
size.setHeight((int) bounds.getHeight());
293-
size.calculate();
294-
295-
getSideBarController().getPanel().setBounds(0, size.getMenubarHeight(),
296-
size.getSidebarWidth(), size.getHeight());
297-
getGraphController().getPanel().setBounds(0, 0, size.getWidth(),
298-
size.getHeight() - size.getZoombarHeight());
299-
getZoomBarController().getPanel().setBounds(0,
300-
size.getHeight() - size.getZoombarHeight(),
301-
size.getWidth(), size.getZoombarHeight());
302-
getPhyloController().getView().updateSize();
303-
304-
main.repaint();
305-
}
306-
};
307-
}
308-
309279
@Override
310280
public GraphController getGraphController() {
311281
return graphController;
@@ -331,4 +301,12 @@ public FindgenesController getFindgenesController() {
331301
return findgenesController;
332302
}
333303

304+
public Rectangle getBounds() {
305+
return new Rectangle(main.getWidth(), main.getHeight());
306+
}
307+
308+
public void repaint(){
309+
main.repaint();
310+
}
311+
334312
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package tudelft.ti2806.pl3.controls;
2+
3+
import tudelft.ti2806.pl3.Application;
4+
import tudelft.ti2806.pl3.ScreenSize;
5+
6+
import java.awt.Rectangle;
7+
import java.awt.event.ComponentAdapter;
8+
import java.awt.event.ComponentEvent;
9+
10+
/**
11+
* Creates an adapter that updates screen sizes for the components in the view.
12+
*
13+
* Created by Kasper on 16-6-2015.
14+
*/
15+
public class ResizeAdapter extends ComponentAdapter {
16+
17+
private Application application;
18+
19+
public ResizeAdapter(Application application) {
20+
super();
21+
this.application = application;
22+
}
23+
24+
25+
26+
@Override
27+
public void componentResized(ComponentEvent e) {
28+
Rectangle bounds = application.getBounds();
29+
ScreenSize size = ScreenSize.getInstance();
30+
31+
size.setWidth((int) bounds.getWidth());
32+
size.setHeight((int) bounds.getHeight());
33+
size.calculate();
34+
35+
application.getSideBarController().getPanel().setBounds(0, size.getMenubarHeight(),
36+
size.getSidebarWidth(), size.getHeight());
37+
application.getGraphController().getPanel().setBounds(0, 0, size.getWidth(),
38+
size.getHeight() - size.getZoombarHeight());
39+
application.getZoomBarController().getPanel().setBounds(0,
40+
size.getHeight() - size.getZoombarHeight(),
41+
size.getWidth(), size.getZoombarHeight());
42+
application.getPhyloController().getView().updateSize();
43+
44+
application.repaint();
45+
}
46+
47+
public ComponentAdapter getResizer(){
48+
return this;
49+
}
50+
}

0 commit comments

Comments
 (0)