1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sourceforge.jhunters.pool.ui;
18
19 import java.util.List;
20
21 import javafx.beans.value.ChangeListener;
22 import javafx.beans.value.ObservableValue;
23 import javafx.event.ActionEvent;
24 import javafx.event.EventHandler;
25 import javafx.scene.control.Menu;
26 import javafx.scene.control.MenuBar;
27 import javafx.scene.control.MenuItem;
28 import javafx.scene.control.Tab;
29 import javafx.scene.control.TabPane;
30 import net.sourceforge.jhunters.pool.PoolException;
31 import net.sourceforge.jhunters.pool.data.DataSet;
32
33
34
35
36 public class MainTabView extends TabPane {
37
38
39
40 private static final String TAB_COMPETITION = GuiResource.TAB_COMPETITION.getValue();
41
42
43
44
45 private static final String TAB_MAINT = GuiResource.TAB_MAINT.getValue();
46
47
48
49
50 private static final int WIDTH_MARGIN = 20;
51
52
53
54
55 private final CompetitionPanel theCompetitions;
56
57
58
59
60 private final MaintenancePanel theMaint;
61
62
63
64
65 private final MenuItem theSaveMenu;
66
67
68
69
70
71
72 protected MainTabView(final AppControl pControl) throws PoolException {
73
74 List<Tab> myTabs = getTabs();
75
76
77 setPrefWidth(HuntersPool.WIDTH_STAGE - WIDTH_MARGIN);
78 setPrefHeight(HuntersPool.HEIGHT_STAGE - WIDTH_MARGIN);
79
80
81 theCompetitions = new CompetitionPanel(pControl);
82
83
84 Tab myTab = new Tab();
85 myTab.setText(TAB_COMPETITION);
86 myTab.setContent(theCompetitions);
87 myTabs.add(myTab);
88
89
90 theMaint = new MaintenancePanel(pControl, theCompetitions);
91
92
93 myTab = new Tab();
94 myTab.setText(TAB_MAINT);
95 myTab.setContent(theMaint);
96 myTabs.add(myTab);
97
98
99 setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
100
101
102 theSaveMenu = new MenuItem(GuiResource.MENUITEM_SAVE.getValue());
103 }
104
105
106
107
108
109 protected void setData(final DataSet pData) {
110
111 theCompetitions.setData(pData);
112 theMaint.setData(pData);
113
114
115 theSaveMenu.setDisable(!pData.isUpdated());
116
117
118 pData.updatedProperty().addListener(
119 new ChangeListener<Boolean>() {
120 public void changed(final ObservableValue<? extends Boolean> pValue,
121 final Boolean pOldState,
122 final Boolean pNewState) {
123 theSaveMenu.setDisable(!pNewState);
124 }
125 });
126 }
127
128
129
130
131
132
133 protected MenuBar buildMenuBar(final AppControl pControl) {
134
135 MenuBar myMenuBar = new MenuBar();
136 Menu myFileMenu = new Menu(GuiResource.MENU_FILE.getValue());
137 Menu myHelpMenu = new Menu(GuiResource.MENU_HELP.getValue());
138 myMenuBar.getMenus().addAll(myFileMenu, myHelpMenu);
139 MenuItem myNewItem = new MenuItem(GuiResource.MENUITEM_NEW.getValue());
140 myNewItem.setOnAction(new EventHandler<ActionEvent>() {
141 @Override
142 public void handle(final ActionEvent e) {
143 pControl.createNewData();
144 }
145 });
146 MenuItem myOpenItem = new MenuItem(GuiResource.MENUITEM_OPEN.getValue());
147 myOpenItem.setOnAction(new EventHandler<ActionEvent>() {
148 @Override
149 public void handle(final ActionEvent e) {
150 pControl.chooseAndLoadFile();
151 }
152 });
153 theSaveMenu.setOnAction(new EventHandler<ActionEvent>() {
154 @Override
155 public void handle(final ActionEvent e) {
156 pControl.saveToFile();
157 }
158 });
159 MenuItem mySaveAsItem = new MenuItem(GuiResource.MENUITEM_SAVEAS.getValue());
160 mySaveAsItem.setOnAction(new EventHandler<ActionEvent>() {
161 @Override
162 public void handle(final ActionEvent e) {
163 pControl.saveAsFile();
164 }
165 });
166 myFileMenu.getItems().addAll(myNewItem, myOpenItem, theSaveMenu, mySaveAsItem);
167 MenuItem myAboutItem = new MenuItem(GuiResource.MENUITEM_ABOUT.getValue());
168 myAboutItem.setOnAction(new EventHandler<ActionEvent>() {
169 @Override
170 public void handle(final ActionEvent e) {
171 AboutBox myAbout = new AboutBox(pControl.getStage());
172 myAbout.show();
173 }
174 });
175 myHelpMenu.getItems().add(myAboutItem);
176 theSaveMenu.setDisable(true);
177 return myMenuBar;
178 }
179 }