PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/at/ac/tuwien/sepm/svt3000/guiNew/MainFrame.java

https://bitbucket.org/sepm_qse14/sepm_svt3000
Java | 834 lines | 579 code | 150 blank | 105 comment | 105 complexity | 11d357075fcd5e2dd0cb1d4c4c8faf55 MD5 | raw file
  1. package at.ac.tuwien.sepm.svt3000.guiNew;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.awt.FlowLayout;
  5. import java.awt.Font;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.KeyEvent;
  9. import java.awt.event.WindowAdapter;
  10. import java.awt.event.WindowEvent;
  11. import java.lang.reflect.Method;
  12. import java.util.Arrays;
  13. import java.util.Date;
  14. import javax.swing.Box;
  15. import javax.swing.ImageIcon;
  16. import javax.swing.JButton;
  17. import javax.swing.JFrame;
  18. import javax.swing.JLabel;
  19. import javax.swing.JMenu;
  20. import javax.swing.JMenuBar;
  21. import javax.swing.JMenuItem;
  22. import javax.swing.JOptionPane;
  23. import javax.swing.JPanel;
  24. import javax.swing.JProgressBar;
  25. import javax.swing.JSeparator;
  26. import javax.swing.KeyStroke;
  27. import javax.swing.SwingConstants;
  28. import javax.swing.UIManager;
  29. import org.apache.log4j.Logger;
  30. import org.jdesktop.swingx.JXStatusBar;
  31. import at.ac.tuwien.sepm.svt3000.i18n.Messages;
  32. import at.ac.tuwien.sepm.svt3000.service.IFileService;
  33. import at.ac.tuwien.sepm.svt3000.service.IUserService;
  34. import at.ac.tuwien.sepm.svt3000.service.impl.FileService;
  35. import at.ac.tuwien.sepm.svt3000.service.impl.StudyService;
  36. import at.ac.tuwien.sepm.svt3000.service.impl.UserService;
  37. public class MainFrame extends JFrame implements ActionListener {
  38. private static final long serialVersionUID = 1L;
  39. private static Logger log = Logger.getLogger(MainFrame.class);
  40. /**
  41. * Singleton
  42. *
  43. */
  44. private static class SingletonHolder {
  45. private static MainFrame instance = new MainFrame();
  46. }
  47. public static MainFrame getInstance() {
  48. return SingletonHolder.instance;
  49. }
  50. /**
  51. * Completely recreate the singleton and all relating gui singletons
  52. * @return
  53. */
  54. public static MainFrame getNewInstance() {
  55. SingletonHolder.instance = new MainFrame();
  56. SubscribeMainPanel.getNewInstance();
  57. SearchMainPanel.getNewInstance();
  58. ProgressMainPanel.getNewInstance();
  59. CalendarMainPanel.getNewInstance();
  60. ToDoMainPanel.getNewInstance();
  61. return SingletonHolder.instance;
  62. }
  63. // accordion objects
  64. private JAccordion acc = null;
  65. private JPanel currentMainView = null;
  66. // menu bar objects
  67. private JMenuItem options= null;
  68. private JMenuItem pull= null;
  69. private JMenuItem push= null;
  70. private JMenuItem vcOptions= null;
  71. private JMenuItem inscribeStudy= null;
  72. private JMenuItem switchStudy= null;
  73. private JMenuItem deleteStudy = null;
  74. private JMenuItem removeUser = null;
  75. private JMenuItem logoutUser = null;
  76. private JMenuItem propertyItem1 = null;
  77. private JMenuItem hilfe_extra = null;
  78. private JMenuItem german = null;
  79. private JMenu language = null;
  80. private JMenuItem english = null;
  81. // menu panel objects
  82. private ToDoMenuPanel toDoMenuPanel = null;
  83. private CalendarMenuPanel calendarMenuPanel = null;
  84. // popup frame objects
  85. private JProgressBar progressBar = null;
  86. private InscribeStudyFrame inscribeFrame = null;
  87. private SwitchStudyFrame switchFrame = null;
  88. private DeleteStudyFrame deleteStudyFrame = null;
  89. private PullFrame pullFrame = null;
  90. private PushFrame pushFrame = null;
  91. // logout button
  92. private JButton logout = null;
  93. // subscribe main panel
  94. private SubscribeMainPanel subscribeMainPanel = null;
  95. // status bar objects
  96. private JLabel statusLabel = new JLabel();
  97. private JLabel statusLabelLanguage = new JLabel();
  98. private JLabel statusLabelUser = new JLabel();
  99. private JLabel statusLabelStudy = new JLabel();
  100. private JLabel statusLabelCurrentState = new JLabel("Idle");
  101. JXStatusBar.Constraint c4 = null;
  102. // service objects
  103. private IUserService us;
  104. private IFileService fs;
  105. /**
  106. * Constructor, initalizes MainFrame
  107. */
  108. private MainFrame(){
  109. super("SVT-3000");
  110. this.setSize(1000, 700);
  111. this.initializeLookAndFeel();
  112. us = UserService.getInstance();
  113. fs = new FileService();
  114. Messages.setLanguage(us.getCurrentUser().getLanguage());
  115. toDoMenuPanel = new ToDoMenuPanel();
  116. calendarMenuPanel = new CalendarMenuPanel();
  117. subscribeMainPanel = SubscribeMainPanel.getInstance();
  118. //subscribeMainPanel = new SubscribeMainPanel();
  119. this.initializeMenu();
  120. this.initializeAccordion();
  121. //this.addComponentListener(this);
  122. this.setCurrentView();
  123. this.setMinimumSize(new Dimension(880, 680));
  124. // initialize the status bar
  125. initStatusBar();
  126. // Window Listener for Closing Frame
  127. addWindowListener(new WindowAdapter() {
  128. public void windowClosing(WindowEvent arg0) {
  129. super.windowClosing(arg0);
  130. System.exit(0);
  131. }
  132. });
  133. }
  134. /**
  135. * Initialize the status bar
  136. */
  137. private void initStatusBar() {
  138. /**
  139. * Statusbar
  140. * @author: manu
  141. */
  142. JLabel statusbar = new JLabel();
  143. statusbar.setPreferredSize(new Dimension(1000, 25));
  144. statusLabel.setPreferredSize(new Dimension(120, 25));
  145. statusLabel.setVerticalAlignment(JLabel.TOP);
  146. statusLabelLanguage.setPreferredSize(new Dimension(80, 25));
  147. statusLabelLanguage.setVerticalAlignment(JLabel.TOP);
  148. statusLabelUser.setPreferredSize(new Dimension(120, 25));
  149. statusLabelUser.setVerticalAlignment(JLabel.TOP);
  150. statusLabelStudy.setPreferredSize(new Dimension(300, 25));
  151. statusLabelStudy.setVerticalAlignment(JLabel.TOP);
  152. statusLabelCurrentState.setPreferredSize(new Dimension(200, 25));
  153. statusLabelCurrentState.setVerticalAlignment(JLabel.TOP);
  154. if (System.getProperty("os.name").contains("Windows")) {
  155. statusLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
  156. statusLabelLanguage.setFont(new Font("SansSerif", Font.PLAIN, 12));
  157. statusLabelUser.setFont(new Font("SansSerif", Font.PLAIN, 12));
  158. statusLabelStudy.setFont(new Font("SansSerif", Font.PLAIN, 12));
  159. statusLabelCurrentState.setFont(new Font("SansSerif", Font.PLAIN, 12));
  160. }
  161. else {
  162. statusLabel.setFont(new Font("DejaVu Sans", Font.PLAIN, 12));
  163. statusLabelLanguage.setFont(new Font("DejaVu Sans", Font.PLAIN, 12));
  164. statusLabelUser.setFont(new Font("DejaVu Sans", Font.PLAIN, 12));
  165. statusLabelStudy.setFont(new Font("DejaVu Sans", Font.PLAIN, 12));
  166. statusLabelCurrentState.setFont(new Font("DejaVu Sans", Font.PLAIN, 12));
  167. }
  168. String language = Messages.BUNDLE_NAME;
  169. statusLabelUser.setText(Messages.getString("MainFrame.39") + ": " + UserService.getInstance().getCurrentUser());
  170. statusLabelStudy.setText(Messages.getString("MainFrame.40") + ": " + StudyService.getInstance().getCurrentStudy());
  171. language = language.substring(language.length() -2, language.length());
  172. if (language.equals("de"))
  173. statusLabelLanguage.setText(Messages.getString("MainFrame.35"));
  174. else
  175. statusLabelLanguage.setText(Messages.getString("MainFrame.36"));
  176. statusbar.setLayout(new FlowLayout(0, 20, 5));
  177. progressBar = new JProgressBar();
  178. progressBar.setStringPainted(true);
  179. statusbar.add(statusLabel);
  180. statusbar.add(new JSeparator(JSeparator.VERTICAL));
  181. statusbar.add(statusLabelLanguage);
  182. statusbar.add(statusLabelUser);
  183. statusbar.add(statusLabelStudy);
  184. statusbar.add(statusLabelCurrentState);
  185. this.add(statusbar, BorderLayout.SOUTH);
  186. }
  187. /**
  188. * @author chris
  189. * Rerender all panels
  190. */
  191. public void rerenderAll() {
  192. SubscribeMainPanel.getInstance().validate();
  193. SubscribeMainPanel.getInstance().repaint();
  194. SubscribeFilePanel.getInstance().refresh();
  195. SubscribeTablePanel.getInstance();
  196. // @author markus
  197. SubscribeTablePanel.initializeCourses();
  198. ProgressMainPanel.getInstance().refreshGui();
  199. ToDoMainPanel.getInstance().showToDos();
  200. CalendarMainPanel.getInstance().showDates();
  201. SubscribeMainPanel.getInstance().setDivider(300);
  202. }
  203. /**
  204. * Set current state in status bar
  205. * @author manu
  206. */
  207. public void setCurrentState(String state) {
  208. statusLabelCurrentState.setText(state);
  209. statusLabelCurrentState.paintImmediately(statusLabelCurrentState.getVisibleRect());
  210. }
  211. /**
  212. * Set current user in status bar
  213. * @param user Current User to show in status bar
  214. */
  215. public void setUser(String user) {
  216. statusLabelUser.setText(Messages.getString("MainFrame.39") + ": " + user);
  217. }
  218. /**
  219. * Set current study in status bar
  220. * @param study Current study to show in status bar
  221. */
  222. public void setStudy(String study) {
  223. statusLabelStudy.setText(Messages.getString("MainFrame.40") + ": " + study);
  224. }
  225. /**
  226. * Set status bar text
  227. * @param text Text to set in status bar
  228. */
  229. public void setStatusText(String text) {
  230. this.statusLabel.setText(text);
  231. }
  232. public void setProgress(int i){
  233. progressBar.setValue(i);
  234. }
  235. /**
  236. * Get active panel in main frame as String
  237. * @return Active Panel as String Object
  238. */
  239. public String getActivePanelString() {
  240. int visible = acc.getVisibleBar();
  241. switch (visible) {
  242. case 0:
  243. return Messages.getString("MainFrame.statusbar.active.subscribed");
  244. case 1:
  245. return Messages.getString("MainFrame.statusbar.active.search");
  246. case 2:
  247. return Messages.getString("MainFrame.statusbar.active.progress");
  248. case 3:
  249. return Messages.getString("MainFrame.statusbar.active.calendar");
  250. case 4:
  251. return Messages.getString("MainFrame.statusbar.active.todo");
  252. }
  253. return "";
  254. }
  255. /**
  256. * Set nimbus - look and feel if available
  257. */
  258. private void initializeLookAndFeel(){
  259. UIManager.LookAndFeelInfo plafinfo[] = UIManager.getInstalledLookAndFeels();
  260. boolean nimbusfound=false;
  261. int nimbusindex=0;
  262. for (int look = 0; look < plafinfo.length; look++) {
  263. if(plafinfo[look].getClassName().toLowerCase().contains(Messages.getString("MainFrame.3"))) { //$NON-NLS-1$
  264. nimbusfound=true;
  265. nimbusindex=look;
  266. }
  267. }
  268. try {
  269. if(nimbusfound) {
  270. UIManager.setLookAndFeel(plafinfo[nimbusindex].getClassName());
  271. }
  272. else
  273. UIManager.setLookAndFeel(
  274. UIManager.getCrossPlatformLookAndFeelClassName());
  275. }
  276. catch(Exception e) {}
  277. }
  278. /**
  279. * Set the accordion(menu) on the left side
  280. */
  281. private void initializeAccordion(){
  282. acc = new JAccordion();
  283. acc.setPreferredSize(new Dimension(240, this.getHeight()));
  284. acc.addBar(Messages.getString("MainFrame.4"), SubscribeMenuPanel.getInstance()); //$NON-NLS-1$
  285. acc.addBar(Messages.getString("MainFrame.5"), SearchMenuPanel.getInstance()); //$NON-NLS-1$
  286. acc.addBar(Messages.getString("MainFrame.6"), ProgressMenuPanel.getInstance()); //$NON-NLS-1$
  287. acc.addBar(Messages.getString("MainFrame.7"), calendarMenuPanel); //$NON-NLS-1$
  288. acc.addBar(Messages.getString("MainFrame.8"), toDoMenuPanel); //$NON-NLS-1$
  289. getContentPane().setLayout(new BorderLayout(0, 0));
  290. acc.setVisibleBar(0);
  291. getContentPane().add(acc, BorderLayout.WEST);
  292. }
  293. /**
  294. * Set the mainMenu on top
  295. */
  296. private void initializeMenu(){
  297. JMenuBar menuBar = new JMenuBar();
  298. this.setJMenuBar(menuBar);
  299. JMenu user_menu = new JMenu(Messages.getString("MainFrame.menubar.user")); //$NON-NLS-1$
  300. user_menu.add(getLogoutUser());
  301. user_menu.add(getRemoveUser());
  302. JMenu study_menu = new JMenu(Messages.getString("MainFrame.15")); //$NON-NLS-1$
  303. study_menu.add(getInscribeStudy());
  304. study_menu.add(getSwitchStudy());
  305. study_menu.add(getDeleteStudy());
  306. JMenu datei_versioncontrol = new JMenu(Messages.getString("MainFrame.menubar.version")); //$NON-NLS-1$
  307. datei_versioncontrol.add(getVcPull());
  308. datei_versioncontrol.add(getVcPush()); //$NON-NLS-1$
  309. datei_versioncontrol.add(getVcOptions()); //$NON-NLS-1$
  310. datei_versioncontrol.addActionListener(new MenuBarListener());
  311. JMenu datei_options = new JMenu(Messages.getString("MainFrame.16")); //$NON-NLS-1$
  312. datei_options.add(getOptions());
  313. datei_options.add(getLanguage());
  314. datei_options.addActionListener(new MenuBarListener());
  315. JMenu datei_extra = new JMenu("Info"); //$NON-NLS-1$
  316. hilfe_extra = new JMenuItem(Messages.getString("MainFrame.42"));
  317. propertyItem1 = new JMenuItem(Messages.getString("MainFrame.20"), new ImageIcon("src/main/resources/icons/info-icon-small.png")); //$NON-NLS-1$ //$NON-NLS-2$
  318. hilfe_extra.addActionListener(new MenuBarListener());
  319. propertyItem1.addActionListener(new MenuBarListener());
  320. datei_extra.add(hilfe_extra);
  321. datei_extra.add(propertyItem1);
  322. datei_extra.addActionListener(new MenuBarListener());
  323. menuBar.add(user_menu);
  324. menuBar.add(study_menu);
  325. menuBar.add(datei_versioncontrol);
  326. menuBar.add(datei_options);
  327. menuBar.add(datei_extra);
  328. menuBar.add(Box.createHorizontalGlue());
  329. logout = new JButton(Messages.getString("MainFrame.menubar.logout"));
  330. logout.setIcon(new ImageIcon("src/main/resources/icons/logout.png"));
  331. logout.setHorizontalTextPosition(SwingConstants.LEFT);
  332. logout.addActionListener(new MenuBarListener());
  333. menuBar.add(logout);
  334. }
  335. /**
  336. * Set the currently shown panel
  337. */
  338. //i<=0 && i>=4
  339. public void setCurrentView(int i){
  340. acc.setVisibleBar(i);
  341. setCurrentView();
  342. }
  343. /**
  344. * Change view to subscribed --> new appointment
  345. * * @param type: type==0 -> todo, else ->appointment
  346. */
  347. public void changeToNewAppointment(int type){
  348. subscribeMainPanel.getTabPanel().setActiveTab(2);
  349. subscribeMainPanel.getTabPanel().getAppPanel().setActiveTab(0);
  350. if(type == 0){
  351. subscribeMainPanel.getTabPanel().getAppPanel().getNewAppPanel().setToDoView();
  352. }
  353. else{
  354. subscribeMainPanel.getTabPanel().getAppPanel().getNewAppPanel().setDateView();
  355. }
  356. setCurrentView(0);
  357. subscribeMainPanel.setDivider(300);
  358. }
  359. /**
  360. * Change view to subscribed --> change appointment
  361. * @param type: type==0 -> todo, else ->appointment
  362. */
  363. public void changeToChangeAppointment(int type){
  364. subscribeMainPanel.getTabPanel().setActiveTab(2);
  365. subscribeMainPanel.getTabPanel().getAppPanel().setActiveTab(1);
  366. if(type == 0){
  367. subscribeMainPanel.getTabPanel().getAppPanel().getChangeAppPanel().setToDoView();
  368. }
  369. else{
  370. subscribeMainPanel.getTabPanel().getAppPanel().getChangeAppPanel().setDateView();
  371. }
  372. setCurrentView(0);
  373. }
  374. /**
  375. * set current view. dependent of the accordion-menu status
  376. */
  377. public void setCurrentView(){
  378. //load subscribe view
  379. if(acc.getVisibleBar() == 0){
  380. if(currentMainView != null){
  381. getContentPane().remove(currentMainView);
  382. }
  383. setStatusText(Messages.getString("MainFrame.24")); //$NON-NLS-1$
  384. currentMainView = subscribeMainPanel;
  385. getContentPane().add(currentMainView, BorderLayout.CENTER);
  386. SubscribeTablePanel.getInstance().setDetails();
  387. setCurrentState("Idle");
  388. }
  389. //load search view
  390. else if(acc.getVisibleBar() == 1){
  391. if(currentMainView != null){
  392. getContentPane().remove(currentMainView);
  393. }
  394. setStatusText(Messages.getString("MainFrame.25")); //$NON-NLS-1$
  395. currentMainView = SearchMainPanel.getInstance();
  396. getContentPane().add(currentMainView, BorderLayout.CENTER);
  397. setCurrentState("Idle");
  398. }
  399. //load progress view
  400. else if(acc.getVisibleBar() == 2){
  401. // @author markus
  402. if(currentMainView != null){
  403. getContentPane().remove(currentMainView);
  404. }
  405. setStatusText(Messages.getString("MainFrame.27")); //$NON-NLS-1$
  406. currentMainView = ProgressMainPanel.getInstance();
  407. ((ProgressMainPanel)currentMainView).refreshGui();
  408. getContentPane().add(currentMainView, BorderLayout.CENTER);
  409. setCurrentState("Idle");
  410. }
  411. //load calendar view
  412. else if(acc.getVisibleBar() == 3){
  413. if(currentMainView != null){
  414. getContentPane().remove(currentMainView);
  415. }
  416. setStatusText(Messages.getString("MainFrame.28")); //$NON-NLS-1$
  417. currentMainView = CalendarMainPanel.getInstance();
  418. ((CalendarMainPanel)currentMainView).setCourse(null);
  419. ((CalendarMainPanel)currentMainView).setDate(new Date());
  420. ((CalendarMainPanel)currentMainView).showDates();
  421. calendarMenuPanel.updateComboBox();
  422. calendarMenuPanel.flagDates();
  423. getContentPane().add(currentMainView, BorderLayout.CENTER);
  424. setCurrentState("Idle");
  425. }
  426. //load todo view
  427. else if(acc.getVisibleBar() == 4){
  428. if(currentMainView != null){
  429. getContentPane().remove(currentMainView);
  430. }
  431. setStatusText(Messages.getString("MainFrame.29")); //$NON-NLS-1$
  432. currentMainView = ToDoMainPanel.getInstance();
  433. ToDoMainPanel.getInstance().showToDos();
  434. toDoMenuPanel.updateComboBox();
  435. getContentPane().add(currentMainView, BorderLayout.CENTER);
  436. setCurrentState("Idle");
  437. }
  438. this.validate();
  439. this.repaint();
  440. }
  441. private JMenu getLanguage(){
  442. language = new JMenu(Messages.getString("MainFrame.12")); //$NON-NLS-1$
  443. german = new JMenuItem(Messages.getString("MainFrame.13")); //$NON-NLS-1$
  444. english = new JMenuItem(Messages.getString("MainFrame.14")); //$NON-NLS-1$
  445. language.addActionListener(new MenuBarListener());
  446. german.addActionListener(new MenuBarListener());
  447. english.addActionListener(new MenuBarListener());
  448. language.add(german);
  449. language.add(english);
  450. return language;
  451. }
  452. // --- MENU ITEMS ---
  453. private JMenuItem getInscribeStudy() {
  454. if (inscribeStudy == null) {
  455. inscribeStudy = new JMenuItem(Messages.getString("MainFrame.menubar.inscribe")); //$NON-NLS-1$
  456. inscribeStudy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
  457. inscribeStudy.addActionListener(new MenuBarListener());
  458. }
  459. return inscribeStudy;
  460. }
  461. private JMenuItem getSwitchStudy() {
  462. if (switchStudy == null) {
  463. switchStudy = new JMenuItem(Messages.getString("MainFrame.menubar.switch")); //$NON-NLS-1$
  464. switchStudy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
  465. switchStudy.addActionListener(new MenuBarListener());
  466. }
  467. return switchStudy;
  468. }
  469. private JMenuItem getDeleteStudy() {
  470. if (deleteStudy == null) {
  471. deleteStudy = new JMenuItem(Messages.getString("MainFrame.32")); //$NON-NLS-1$
  472. deleteStudy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK));
  473. deleteStudy.addActionListener(new MenuBarListener());
  474. }
  475. return deleteStudy;
  476. }
  477. private JMenuItem getOptions() {
  478. if (options == null) {
  479. options = new JMenuItem(Messages.getString("MainFrame.30")); //$NON-NLS-1$
  480. options.addActionListener(new MenuBarListener());
  481. }
  482. return options;
  483. }
  484. private JMenuItem getVcPull() {
  485. if (pull == null) {
  486. pull = new JMenuItem(Messages.getString("MainFrame.menubar.version.pull")); //$NON-NLS-1$
  487. //pull.setEnabled(SettingService.getInstance().isVersionControlUsed());
  488. pull.addActionListener(new MenuBarListener());
  489. }
  490. return pull;
  491. }
  492. private JMenuItem getVcPush() {
  493. if (push == null) {
  494. push = new JMenuItem(Messages.getString("MainFrame.menubar.version.push")); //$NON-NLS-1$
  495. //push.setEnabled(SettingService.getInstance().isVersionControlUsed());
  496. push.addActionListener(new MenuBarListener());
  497. }
  498. return push;
  499. }
  500. private JMenuItem getVcOptions() {
  501. if (vcOptions == null) {
  502. vcOptions = new JMenuItem(Messages.getString("MainFrame.menubar.version.settings")); //$NON-NLS-1$
  503. vcOptions.addActionListener(new MenuBarListener());
  504. }
  505. return vcOptions;
  506. }
  507. private JMenuItem getRemoveUser() {
  508. if (removeUser == null) {
  509. removeUser = new JMenuItem(Messages.getString("MainFrame.menubar.deleteuser")); //$NON-NLS-1$
  510. removeUser.addActionListener(new MenuBarListener());
  511. }
  512. return removeUser;
  513. }
  514. private JMenuItem getLogoutUser() {
  515. if (logoutUser == null) {
  516. logoutUser = new JMenuItem(Messages.getString("MainFrame.menubar.logout")); //$NON-NLS-1$
  517. logoutUser.addActionListener(new MenuBarListener());
  518. }
  519. return logoutUser;
  520. }
  521. // --- POPUP FRAMES ---
  522. /**
  523. * Get the info frame
  524. * @return Info Frame
  525. */
  526. private JFrame getInfoFrame() {
  527. return new InfoFrame();
  528. }
  529. private OptionsFrame getOptionsFrame() {
  530. return new OptionsFrame();
  531. }
  532. private JFrame getInscribeFrame() {
  533. inscribeFrame = new InscribeStudyFrame(Messages.getString("InscribeStudyFrame.title")); //$NON-NLS-1$
  534. if(inscribeFrame.isVisible()== false){
  535. inscribeFrame.setVisible(true);
  536. }
  537. return inscribeFrame;
  538. }
  539. private JFrame getSwitchFrame() {
  540. switchFrame = new SwitchStudyFrame(Messages.getString("SwitchStudyFrame.title")); //$NON-NLS-1$
  541. if(switchFrame.isVisible()== false){
  542. switchFrame.setVisible(true);
  543. }
  544. return switchFrame;
  545. }
  546. private JFrame getDeleteFrame() {
  547. deleteStudyFrame = new DeleteStudyFrame(Messages.getString("MainFrame.37")); //$NON-NLS-1$
  548. if(deleteStudyFrame.isVisible()== false){
  549. deleteStudyFrame.setVisible(true);
  550. }
  551. return deleteStudyFrame;
  552. }
  553. private JFrame getPullFrame() {
  554. pullFrame = new PullFrame(Messages.getString("PullFrame.title")); //$NON-NLS-1$
  555. if(pullFrame.isVisible()== false){
  556. pullFrame.setVisible(true);
  557. }
  558. return pullFrame;
  559. }
  560. private JFrame getPushFrame() {
  561. pushFrame = new PushFrame(Messages.getString("PushFrame.title")); //$NON-NLS-1$
  562. if(pushFrame.isVisible()== false){
  563. pushFrame.setVisible(true);
  564. }
  565. return pushFrame;
  566. }
  567. private MainFrame getThis() {
  568. return this;
  569. }
  570. /**
  571. * @author manu
  572. */
  573. public static void openWebsite(String url) {
  574. String osName = System.getProperty("os.name");
  575. final String[] browsers = { "firefox", "opera", "konqueror", "epiphany",
  576. "seamonkey", "galeon", "kazehakase", "mozilla", "netscape" };
  577. try {
  578. if (osName.startsWith("Mac OS")) {
  579. Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
  580. Method openURL = fileMgr.getDeclaredMethod("openURL",
  581. new Class[] {String.class});
  582. openURL.invoke(null, new Object[] {url});
  583. }
  584. else if (osName.startsWith("Windows"))
  585. Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
  586. //assume Unix or Linux
  587. else {
  588. boolean found = false;
  589. for (String browser : browsers)
  590. if (!found) {
  591. found = Runtime.getRuntime().exec(
  592. new String[] {"which", browser}).waitFor() == 0;
  593. if (found)
  594. Runtime.getRuntime().exec(new String[] {browser, url});
  595. }
  596. if (!found)
  597. throw new Exception(Arrays.toString(browsers));
  598. }
  599. }
  600. catch (Exception e) {
  601. JOptionPane.showMessageDialog(null, "Error attempting to launch web browser\n" + e.toString());
  602. }
  603. }
  604. /**
  605. * Listener class for the menu bar
  606. *
  607. */
  608. class MenuBarListener implements ActionListener {
  609. //for menubar
  610. @Override
  611. public void actionPerformed(ActionEvent e) {
  612. String[] yesNoOptions = {Messages.getString("SubscribeMenuPanel.13"), Messages.getString("SubscribeMenuPanel.9")};
  613. if (e.getSource() == options){
  614. getOptionsFrame();
  615. }
  616. if (e.getSource() == hilfe_extra) {
  617. openWebsite("http://svt3000.mlanner.com/site/handbuch.html");
  618. }
  619. if (e.getSource() == vcOptions){
  620. OptionsFrame of = getOptionsFrame();
  621. of.setTab(OptionsFrame.VERSION_CONTROL_INDEX);
  622. }
  623. if (e.getSource() == pull) {
  624. if (!UserService.getInstance().getCurrentUser().isSvnUsed()) {
  625. JOptionPane.showMessageDialog(getThis(), Messages.getString("VersionControl.notactive"), Messages.getString("VersionControl.notactive.title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
  626. } else {
  627. getPullFrame();
  628. }
  629. }
  630. if (e.getSource() == push) {
  631. if (!UserService.getInstance().getCurrentUser().isSvnUsed()) {
  632. JOptionPane.showMessageDialog(getThis(), Messages.getString("VersionControl.notactive"), Messages.getString("VersionControl.notactive.title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
  633. } else {
  634. getPushFrame();
  635. }
  636. }
  637. if (e.getSource() == switchStudy) {
  638. getSwitchFrame();
  639. }
  640. if (e.getSource() == deleteStudy) {
  641. getDeleteFrame();
  642. }
  643. if (e.getSource() == removeUser) {
  644. int choice = JOptionPane.showOptionDialog(getThis(), Messages.getString("DeleteUserFrame.confirm"), Messages.getString("DeleteUserFrame.confirm.title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
  645. if (choice == JOptionPane.YES_OPTION) {
  646. fs.removeUserDirectory();
  647. us.removeUser(us.getCurrentUser().getName());
  648. getThis().dispose();
  649. new WelcomeFrame();
  650. }
  651. }
  652. //Deutsch
  653. if (e.getSource() == german) {
  654. int sure = JOptionPane.showOptionDialog(null,
  655. Messages.getString("MainFrame.33"), Messages.getString("MainFrame.34"),
  656. JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_OPTION, null, yesNoOptions, null);
  657. if (sure == 0)
  658. UserService.getInstance().updateLanguageSettings("de");
  659. }
  660. //English
  661. if (e.getSource() == english) {
  662. int sure = JOptionPane.showOptionDialog(null, Messages.getString("MainFrame.33"), Messages.getString("MainFrame.34"),
  663. JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_OPTION, null, yesNoOptions, null);
  664. if (sure == 0)
  665. UserService.getInstance().updateLanguageSettings("en");
  666. }
  667. if (e.getSource() == inscribeStudy)
  668. getInscribeFrame();
  669. if (e.getSource() == propertyItem1){
  670. getInfoFrame();
  671. }
  672. if ((e.getSource() == logout) || (e.getSource() == logoutUser)) {
  673. log.info("logout button pressed.");
  674. // TODO auto push
  675. us.updateLogoutCurrentUser(true);
  676. getThis().dispose();
  677. new WelcomeFrame();
  678. }
  679. }
  680. }
  681. @Override
  682. public void actionPerformed(ActionEvent e) {
  683. }
  684. }