Desktop tool for browsing account info from EVE-Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OverviewPage.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.pages;
  23. import java.awt.Color;
  24. import java.awt.Font;
  25. import java.io.IOException;
  26. import java.util.HashMap;
  27. import java.util.Map;
  28. import java.util.logging.Level;
  29. import java.util.logging.Logger;
  30. import javax.imageio.ImageIO;
  31. import javax.swing.BorderFactory;
  32. import javax.swing.ImageIcon;
  33. import javax.swing.JButton;
  34. import javax.swing.JLabel;
  35. import javax.swing.JPanel;
  36. import javax.swing.SwingUtilities;
  37. import javax.swing.border.BevelBorder;
  38. import net.miginfocom.swing.MigLayout;
  39. import uk.co.md87.evetool.Account;
  40. import uk.co.md87.evetool.AccountManager;
  41. import uk.co.md87.evetool.ApiFactory;
  42. import uk.co.md87.evetool.api.EveApi;
  43. import uk.co.md87.evetool.ui.ContentPanel.Page;
  44. import uk.co.md87.evetool.ui.ContextPanel;
  45. import uk.co.md87.evetool.ui.components.AddButton;
  46. import uk.co.md87.evetool.ui.components.FilterButton;
  47. import uk.co.md87.evetool.ui.workers.AccountUpdateWorker;
  48. /**
  49. *
  50. * TODO: Document OverviewPage
  51. * @author chris
  52. */
  53. public class OverviewPage extends Page implements AccountManager.AccountListener {
  54. private final ApiFactory factory;
  55. private final Map<Account, EveApi> apis = new HashMap<Account, EveApi>();
  56. private final Map<Account, JPanel> panels = new HashMap<Account, JPanel>();
  57. public OverviewPage(final ContextPanel context, final AccountManager manager,
  58. final ApiFactory factory) {
  59. this.factory = factory;
  60. setLayout(new MigLayout("fillx"));
  61. for (Account account : manager.getAccounts(this)) {
  62. addAccount(account);
  63. }
  64. context.add(new AddButton("Add account"), "growy");
  65. context.add(new FilterButton(), "growy, al right");
  66. }
  67. protected void addAccount(final Account account) {
  68. final JLabel header = new JLabel("Account #" + account.getId());
  69. final JPanel headerP = new JPanel(new MigLayout("fillx"));
  70. header.setFont(header.getFont().deriveFont(14f).deriveFont(Font.BOLD));
  71. headerP.setBorder(BorderFactory.createCompoundBorder(
  72. BorderFactory.createBevelBorder(BevelBorder.RAISED),
  73. BorderFactory.createEmptyBorder(0, 5, 0, 5)));
  74. headerP.add(header, "growx");
  75. try {
  76. final JButton editButton = new JButton(new ImageIcon(ImageIO
  77. .read(getClass().getResource("../res/edit-inactive.png"))));
  78. editButton.setRolloverIcon(new ImageIcon(ImageIO
  79. .read(getClass().getResource("../res/edit.png"))));
  80. editButton.setBorder(BorderFactory.createEmptyBorder());
  81. editButton.setOpaque(false);
  82. editButton.setContentAreaFilled(false);
  83. final JButton delButton = new JButton(new ImageIcon(ImageIO
  84. .read(getClass().getResource("../res/close-inactive.png"))));
  85. delButton.setRolloverIcon(new ImageIcon(ImageIO
  86. .read(getClass().getResource("../res/close-active.png"))));
  87. delButton.setBorder(BorderFactory.createEmptyBorder());
  88. delButton.setOpaque(false);
  89. delButton.setContentAreaFilled(false);
  90. headerP.add(editButton, "al right");
  91. headerP.add(delButton, "al right");
  92. } catch (IOException ex) {
  93. Logger.getLogger(getClass().getName()).log(Level.SEVERE,
  94. "Error loading images", ex);
  95. }
  96. add(headerP, "span, growx, wrap");
  97. final JPanel panel = new JPanel(new MigLayout(" fillx", "[|fill,grow|fill,grow]"));
  98. panel.add(new JLabel("Loading..."), "span");
  99. add(panel, "growx, wrap");
  100. panels.put(account, panel);
  101. apis.put(account, account.getApi(factory));
  102. new AccountUpdateWorker(apis.get(account), panel).execute();
  103. }
  104. /** {@inheritDoc} */
  105. @Override
  106. public void accountAdded(final Account account) {
  107. SwingUtilities.invokeLater(new Runnable() {
  108. /** {@inheritDoc} */
  109. @Override
  110. public void run() {
  111. addAccount(account);
  112. }
  113. });
  114. }
  115. }