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.

SkillPage.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.event.ActionEvent;
  24. import java.awt.event.ActionListener;
  25. import java.util.ArrayList;
  26. import java.util.Collections;
  27. import java.util.List;
  28. import javax.swing.JSeparator;
  29. import net.miginfocom.swing.MigLayout;
  30. import uk.co.md87.evetool.AccountManager;
  31. import uk.co.md87.evetool.ApiFactory;
  32. import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
  33. import uk.co.md87.evetool.ui.ContentPanel.Page;
  34. import uk.co.md87.evetool.ui.ContextPanel;
  35. import uk.co.md87.evetool.ui.MainWindow;
  36. import uk.co.md87.evetool.ui.components.FilterButton;
  37. import uk.co.md87.evetool.ui.components.HeaderPanel;
  38. import uk.co.md87.evetool.ui.components.ListablePanel;
  39. import uk.co.md87.evetool.ui.data.TrainedSkillInfoSurrogate;
  40. import uk.co.md87.evetool.ui.dialogs.listableconfig.ListableConfigDialog;
  41. import uk.co.md87.evetool.ui.listable.ListableComparator;
  42. import uk.co.md87.evetool.ui.listable.ListableConfig;
  43. import uk.co.md87.evetool.ui.listable.ListableParser;
  44. /**
  45. *
  46. * TODO: Document SkillPage
  47. * @author chris
  48. */
  49. public class SkillPage extends Page implements ActionListener {
  50. /**
  51. * A version number for this class. It should be changed whenever the class
  52. * structure is changed (or anything else that would prevent serialized
  53. * objects being unserialized with the new class).
  54. */
  55. private static final long serialVersionUID = 10;
  56. private final MainWindow window;
  57. private final ApiFactory factory;
  58. private ListableConfig config;
  59. public SkillPage(final MainWindow window, final AccountManager manager,
  60. final ApiFactory factory) {
  61. this.window = window;
  62. this.factory = factory;
  63. setLayout(new MigLayout("fillx, wrap 1"));
  64. config = new ListableConfig();
  65. config.topLeft = new ListableConfig.BasicConfigElement("name");
  66. config.topRight = new ListableConfig.CompoundConfigElement(
  67. new ListableConfig.BasicConfigElement("trained skillpoints"),
  68. new ListableConfig.LiteralConfigElement("/"),
  69. new ListableConfig.BasicConfigElement("max skillpoints"));
  70. config.bottomLeft = new ListableConfig.BasicConfigElement("group name");
  71. config.bottomRight = new ListableConfig.BasicConfigElement("time to next level");
  72. config.group = new ListableConfig.BasicConfigElement("group name");
  73. config.sortOrder = new ListableConfig.ConfigElement[]{
  74. new ListableConfig.BasicConfigElement("group name"),
  75. new ListableConfig.BasicConfigElement("current level"),
  76. new ListableConfig.BasicConfigElement("trained skillpoints"),
  77. };
  78. }
  79. /** {@inheritDoc} */
  80. @Override
  81. public boolean isReady() {
  82. return character != null && character.getSheet() != null
  83. && character.getSheet().wasSuccessful();
  84. }
  85. /** {@inheritDoc} */
  86. @Override
  87. public void activated(final ContextPanel context) {
  88. final FilterButton button = new FilterButton();
  89. button.addActionListener(this);
  90. context.add(button, "growy, al right");
  91. updatePage();
  92. }
  93. protected void updatePage() {
  94. removeAll();
  95. final ListableParser parser = new ListableParser(TrainedSkillInfoSurrogate.class);
  96. final List<TrainedSkillInfoSurrogate> list = new ArrayList<TrainedSkillInfoSurrogate>();
  97. for (TrainedSkillInfo skill : character.getSheet().getResult().getSkills()) {
  98. list.add(new TrainedSkillInfoSurrogate(skill));
  99. }
  100. if (config.sortOrder != null) {
  101. Collections.sort(list, new ListableComparator(config.sortOrder, parser));
  102. }
  103. String lastGroup = null;
  104. boolean first = true;
  105. for (TrainedSkillInfoSurrogate skill : list) {
  106. if (config.group != null) {
  107. final String thisGroup = config.group.getValue(skill, parser);
  108. if (lastGroup == null || !thisGroup.equals(lastGroup)) {
  109. first = true;
  110. lastGroup = thisGroup;
  111. add(new HeaderPanel(lastGroup), "growx, pushx");
  112. }
  113. }
  114. if (first) {
  115. first = false;
  116. } else {
  117. add(new JSeparator(), "growx, pushx");
  118. }
  119. add(new ListablePanel(skill, parser, config),
  120. "growx, pushx");
  121. }
  122. revalidate();
  123. }
  124. public void setConfig(final ListableConfig config) {
  125. this.config = config;
  126. updatePage();
  127. }
  128. /** {@inheritDoc} */
  129. @Override
  130. public void actionPerformed(final ActionEvent e) {
  131. new ListableConfigDialog(window, this, config, new TrainedSkillInfoSurrogate(
  132. character.getSheet().getResult().getSkills().get(0))).setVisible(true);
  133. }
  134. }