Desktop tool for browsing account info from EVE-Online
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

MainWindow.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2009 Chris Smith
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package uk.co.md87.evetool.ui;
  23. import java.awt.AWTException;
  24. import java.awt.Dimension;
  25. import java.awt.Image;
  26. import java.awt.SystemTray;
  27. import java.awt.TrayIcon;
  28. import java.io.IOException;
  29. import java.util.Map;
  30. import java.util.TreeMap;
  31. import java.util.logging.Level;
  32. import java.util.logging.Logger;
  33. import javax.imageio.ImageIO;
  34. import javax.swing.JFrame;
  35. import javax.swing.UIManager;
  36. import net.miginfocom.swing.MigLayout;
  37. import uk.co.md87.evetool.AccountManager;
  38. import uk.co.md87.evetool.ApiFactory;
  39. import uk.co.md87.evetool.ConfigManager;
  40. import uk.co.md87.evetool.ui.ContentPanel.Page;
  41. import uk.co.md87.evetool.ui.data.AccountChar;
  42. import uk.co.md87.evetool.ui.pages.OverviewPage;
  43. import uk.co.md87.evetool.ui.pages.ShipsPage;
  44. import uk.co.md87.evetool.ui.pages.SkillPage;
  45. /**
  46. *
  47. * TODO: Document MainWindow
  48. * @author chris
  49. */
  50. public class MainWindow extends JFrame {
  51. /**
  52. * A version number for this class. It should be changed whenever the class
  53. * structure is changed (or anything else that would prevent serialized
  54. * objects being unserialized with the new class).
  55. */
  56. private static final long serialVersionUID = 10;
  57. private AccountChar selectedChar = null;
  58. private final AccountManager manager;
  59. private final ApiFactory factory;
  60. private final MenuPanel menuPanel;
  61. private final ConfigManager config;
  62. private final ContentPanel contentPanel;
  63. private final ContextPanel contextPanel;
  64. private final Map<String, ContentPanel.Page> pages;
  65. public MainWindow(final AccountManager manager,
  66. final ApiFactory factory, final ConfigManager config) {
  67. super("EVE Tool - No character selected");
  68. UIManager.put("swing.boldMetal", false);
  69. this.factory = factory;
  70. this.manager = manager;
  71. this.config = config;
  72. this.contextPanel = new ContextPanel();
  73. pages = new TreeMap<String, ContentPanel.Page>();
  74. pages.put("Overview", new OverviewPage(this, manager, factory, config));
  75. pages.put("Skills", new SkillPage(this, manager, factory));
  76. pages.put("Ships", new ShipsPage(this, manager, factory));
  77. this.menuPanel = new MenuPanel(this, pages);
  78. this.contentPanel = new ContentPanel(this, manager, factory, pages);
  79. setLayout(new MigLayout("insets 0, fill, wrap 2", "[]0[fill,grow]",
  80. "[fill,grow]0[]"));
  81. addComponents();
  82. setMinimumSize(new Dimension(300, 300));
  83. setSize(new Dimension(800, 600));
  84. setDefaultCloseOperation(EXIT_ON_CLOSE);
  85. setPage("Overview");
  86. try {
  87. final Image image = ImageIO.read(getClass().getResource("res/icon.png"));
  88. setIconImage(image);
  89. if (SystemTray.isSupported()) {
  90. final TrayIcon trayicon = new TrayIcon(image
  91. .getScaledInstance(SystemTray.getSystemTray().getTrayIconSize().width,
  92. SystemTray.getSystemTray().getTrayIconSize().height,
  93. Image.SCALE_SMOOTH), "EVE Tool");
  94. SystemTray.getSystemTray().add(trayicon);
  95. }
  96. } catch (IOException ex) {
  97. Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
  98. } catch (AWTException ex) {
  99. Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
  100. }
  101. }
  102. public void setPage(final String page) {
  103. menuPanel.setSelectedPage(page);
  104. contextPanel.removeAll();
  105. pages.get(page).activated(contextPanel);
  106. contentPanel.show(page);
  107. contextPanel.revalidate();
  108. }
  109. public void setSelectedChar(final AccountChar newChar) {
  110. selectedChar = newChar;
  111. for (Page page : pages.values()) {
  112. page.setActiveChar(newChar);
  113. }
  114. menuPanel.setSelectedChar(newChar);
  115. setTitle("EVE Tool - " + newChar.getCharInfo().getName());
  116. config.setGeneralSetting("selectedChar", newChar.getCharInfo().getId());
  117. }
  118. public ContextPanel getContextPanel() {
  119. return contextPanel;
  120. }
  121. protected void addComponents() {
  122. add(menuPanel, "width 201!, spany2");
  123. add(contentPanel);
  124. add(contextPanel, "growx, height 30!");
  125. add(new StatusPanel(this), "growx, span, height 30!");
  126. }
  127. }