Esempio n. 1
0
    void drawScreen() {

      teams.add(myTeams);
      teams.add(manageTeams, "growx");
      teams.add(new JSeparator(), "growx");

      for (Team team : Global.Teams) {
        JPanel thisTeam = team.teamPreview();
        JButton startTeam = new JButton("Draft!");
        startTeam.addActionListener(
            (ActionEvent e) -> {
              DraftScreen called = new DraftScreen(team, this);
              called.Switch();
            });
        thisTeam.add(startTeam, "east");
        thisTeam.setBorder(BorderFactory.createLineBorder(Color.black));
        teamsInner.add(thisTeam, "growx");
      }
      teams.add(teamScroll);

      players.add(myPlayers);
      players.add(managePlayers, "growx");
      players.add(new JSeparator());

      for (Player player : Global.Players) {
        JPanel thisPlayer = player.playerPreview();
        JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16));
        modify.setMargin(new Insets(0, 0, 0, 0));
        modify.addActionListener(
            (ActionEvent e) -> {
              new ModifyPlayerPopup(player, this, null);
            });
        thisPlayer.add(modify, "east");
        thisPlayer.setBorder(BorderFactory.createLineBorder(Color.black));
        playersInner.add(thisPlayer, "growx");
      }
      players.add(playerScroll);

      teamDraft.add(teamDraftL, "span, center");
      teamDraft.add(teams, "grow");
      teamDraft.add(players, "grow");

      Eve.add(quick);
      Eve.add(viewAll);
      Eve.add(teamDraft, "span");

      Adam.add(Eve);
      Adam.setSize(windowSize);
    }
Esempio n. 2
0
    /**
     * Creates a panel with a custom built hero pool display. WARNING: DELETE THIS FRAME WHEN YOU
     * ARE DONE OR YOU WILL CAUSE A MEMORY LEAK.
     *
     * @param preview Do you want a hero preview at the top?
     */
    public PoolBuilder(
        boolean previewFlag, String size, HeroReturner function, Hero[] disableList) {
      heroFactions.put("RadiantStrength", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("DireStrength", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("RadiantAgility", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("DireAgility", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("RadiantIntelligence", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("DireIntelligence", new JPanel(new WrapLayout(FlowLayout.LEADING)));

      preview.add(portrait);
      preview.add(info);

      Str.setBorder(BorderFactory.createLineBorder(Color.black));
      Agi.setBorder(BorderFactory.createLineBorder(Color.black));
      Int.setBorder(BorderFactory.createLineBorder(Color.black));

      info.setEditable(false);

      for (Hero hero : Global.AllHeroes.values()) {
        JLabel label = new JLabel(hero.portraitSmall);
        heroFactions.get(hero.side + hero.attribute).add(label);
        // Disable the button if the hero it contains matches the disableList.
        if (Global.existsInPool(hero.abbrv, disableList)) {
          label.setEnabled(false);
        } else {
          label.addMouseListener(
              new MouseAdapter() {
                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                  if (previewFlag) {
                    portrait.setIcon(hero.portraitLarge);

                    info.setText(hero.name + " the " + hero.title + "\n");
                  } else {
                    if (label.isEnabled()) {
                      try {
                        scrollPane.getVerticalScrollBar().setValue(0);
                        function.heroEquals(hero);
                        function.mouseEventEquals(evt);
                        function.call();
                      } catch (Exception ex) {
                        Logger.getLogger(WindowManager.class.getName()).log(Level.SEVERE, null, ex);
                      }
                    }
                  }
                }
              });
        }
        heroPanels.put(hero.abbrv, label);
      }

      heroes.add(
          new JLabel(ResourceRetriever.getImage("Radiant.png", 24, 24)),
          "span, split 3, center, grow");
      heroes.add(new JLabel(ResourceRetriever.getImage("STR.png", 24, 24)), "shrink, center");
      heroes.add(new JLabel(ResourceRetriever.getImage("Dire.png", 24, 24)), "span, center, grow");
      Str.add(heroFactions.get("RadiantStrength"), "grow, width 100:pref:260, center");
      Str.add(heroFactions.get("DireStrength"), "grow, width 100:pref:260, center");
      heroes.add(Str, "span, height min:0:pref");

      heroes.add(
          new JLabel(ResourceRetriever.getImage("Radiant.png", 24, 24)),
          "span, split 3, center, grow");
      heroes.add(new JLabel(ResourceRetriever.getImage("AGI.png", 24, 24)), "shrink, center");
      heroes.add(new JLabel(ResourceRetriever.getImage("Dire.png", 24, 24)), "span, center, grow");
      Agi.add(heroFactions.get("RadiantAgility"), "grow, width 100:pref:260, center");
      Agi.add(heroFactions.get("DireAgility"), "grow, width 100:pref:260, center");
      heroes.add(Agi, "span, height pref!");

      heroes.add(
          new JLabel(ResourceRetriever.getImage("Radiant.png", 24, 24)),
          "span, split 3, center, grow");
      heroes.add(new JLabel(ResourceRetriever.getImage("INT.png", 24, 24)), "shrink, center");
      heroes.add(new JLabel(ResourceRetriever.getImage("Dire.png", 24, 24)), "span, center, grow");
      Int.add(heroFactions.get("RadiantIntelligence"), "grow, width 100:pref:260, center");
      Int.add(heroFactions.get("DireIntelligence"), "grow, width 100:pref:260, center");
      heroes.add(Int, "span, height pref!");

      if (previewFlag) {
        pool.add(preview);
      }
      scrollPane.getVerticalScrollBar().setUnitIncrement(16);
      scrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
      pool.add(scrollPane);
    }
Esempio n. 3
0
  class PoolBuilder {
    JPanel pool = new JPanel(new MigLayout("flowy, insets 0,", "grow, fill", ""));
    JPanel preview = new JPanel(new MigLayout("insets 0"));
    JPanel heroes = new JPanel(new MigLayout("wrap 2", "grow, fill", ""));
    Map<String, JPanel> heroFactions = new HashMap<>();
    Map<String, JLabel> heroPanels = new HashMap<>();
    JPanel Str = new JPanel(new MigLayout("", "[grow 50][grow 50]", ""));
    JPanel Agi = new JPanel(new MigLayout("", "[grow 50][grow 50]", ""));
    JPanel Int = new JPanel(new MigLayout("", "[grow 50][grow 50]", ""));
    JLabel portrait = new JLabel(ResourceRetriever.getImage("Transparent.png", 256, 144));
    JScrollPane scrollPane = new JScrollPane(heroes);
    JTextArea info = new JTextArea();

    /**
     * Creates a panel with a custom built hero pool display. WARNING: DELETE THIS FRAME WHEN YOU
     * ARE DONE OR YOU WILL CAUSE A MEMORY LEAK.
     *
     * @param preview Do you want a hero preview at the top?
     */
    public PoolBuilder(
        boolean previewFlag, String size, HeroReturner function, Hero[] disableList) {
      heroFactions.put("RadiantStrength", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("DireStrength", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("RadiantAgility", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("DireAgility", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("RadiantIntelligence", new JPanel(new WrapLayout(FlowLayout.LEADING)));
      heroFactions.put("DireIntelligence", new JPanel(new WrapLayout(FlowLayout.LEADING)));

      preview.add(portrait);
      preview.add(info);

      Str.setBorder(BorderFactory.createLineBorder(Color.black));
      Agi.setBorder(BorderFactory.createLineBorder(Color.black));
      Int.setBorder(BorderFactory.createLineBorder(Color.black));

      info.setEditable(false);

      for (Hero hero : Global.AllHeroes.values()) {
        JLabel label = new JLabel(hero.portraitSmall);
        heroFactions.get(hero.side + hero.attribute).add(label);
        // Disable the button if the hero it contains matches the disableList.
        if (Global.existsInPool(hero.abbrv, disableList)) {
          label.setEnabled(false);
        } else {
          label.addMouseListener(
              new MouseAdapter() {
                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                  if (previewFlag) {
                    portrait.setIcon(hero.portraitLarge);

                    info.setText(hero.name + " the " + hero.title + "\n");
                  } else {
                    if (label.isEnabled()) {
                      try {
                        scrollPane.getVerticalScrollBar().setValue(0);
                        function.heroEquals(hero);
                        function.mouseEventEquals(evt);
                        function.call();
                      } catch (Exception ex) {
                        Logger.getLogger(WindowManager.class.getName()).log(Level.SEVERE, null, ex);
                      }
                    }
                  }
                }
              });
        }
        heroPanels.put(hero.abbrv, label);
      }

      heroes.add(
          new JLabel(ResourceRetriever.getImage("Radiant.png", 24, 24)),
          "span, split 3, center, grow");
      heroes.add(new JLabel(ResourceRetriever.getImage("STR.png", 24, 24)), "shrink, center");
      heroes.add(new JLabel(ResourceRetriever.getImage("Dire.png", 24, 24)), "span, center, grow");
      Str.add(heroFactions.get("RadiantStrength"), "grow, width 100:pref:260, center");
      Str.add(heroFactions.get("DireStrength"), "grow, width 100:pref:260, center");
      heroes.add(Str, "span, height min:0:pref");

      heroes.add(
          new JLabel(ResourceRetriever.getImage("Radiant.png", 24, 24)),
          "span, split 3, center, grow");
      heroes.add(new JLabel(ResourceRetriever.getImage("AGI.png", 24, 24)), "shrink, center");
      heroes.add(new JLabel(ResourceRetriever.getImage("Dire.png", 24, 24)), "span, center, grow");
      Agi.add(heroFactions.get("RadiantAgility"), "grow, width 100:pref:260, center");
      Agi.add(heroFactions.get("DireAgility"), "grow, width 100:pref:260, center");
      heroes.add(Agi, "span, height pref!");

      heroes.add(
          new JLabel(ResourceRetriever.getImage("Radiant.png", 24, 24)),
          "span, split 3, center, grow");
      heroes.add(new JLabel(ResourceRetriever.getImage("INT.png", 24, 24)), "shrink, center");
      heroes.add(new JLabel(ResourceRetriever.getImage("Dire.png", 24, 24)), "span, center, grow");
      Int.add(heroFactions.get("RadiantIntelligence"), "grow, width 100:pref:260, center");
      Int.add(heroFactions.get("DireIntelligence"), "grow, width 100:pref:260, center");
      heroes.add(Int, "span, height pref!");

      if (previewFlag) {
        pool.add(preview);
      }
      scrollPane.getVerticalScrollBar().setUnitIncrement(16);
      scrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
      pool.add(scrollPane);
    }

    public void disableHero(Hero hero) {
      heroPanels.get(hero.abbrv).setEnabled(false);
    }
  }
Esempio n. 4
0
    void drawScreen(Team teamPassed) {

      if (teamPassed != null) {
        // We're editing a current team
        team = teamPassed;
        for (Player player : team.getPlayers()) {
          JPanel thisPlayer = player.playerPreview();
          JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16));
          modify.setMargin(new Insets(0, 0, 0, 0));
          modify.addActionListener(
              (ActionEvent e) -> {
                new ModifyPlayerPopup(player, this, null);
              });
          JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16));
          delete.setMargin(new Insets(0, 0, 0, 0));
          delete.addActionListener(
              (ActionEvent e) -> {
                Object[] options = {"Remove Player from team", "Delete Player", "Cancel"};
                JFrame frame = new JFrame();
                int answer =
                    JOptionPane.showOptionDialog(
                        frame,
                        "Are you sure you would like to delete \"" + player.name + "?\"",
                        "Confirm Delete",
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        Global.QUESTIONPIC,
                        options,
                        options[2]);
                if (answer == 0) {
                  team.removePlayer(player);
                  refresh();
                } else if (answer == 1) {
                  // Teams without uniqueID's don't get added to players yet,
                  //   so the player needs to be manually removed.
                  if (team.globalIndex == -1) {
                    team.removePlayer(player);
                  }
                  player.delete();
                  refresh();
                }
              });
          thisPlayer.add(delete, "east");
          thisPlayer.add(modify, "east");
          thisPlayer.setBorder(BorderFactory.createLineBorder(Color.black));
          players.add(thisPlayer, "growx");
        }
        name.setText(team.name);
      } else {
        // This is a new Team
        team = new Team("New Team");
        name.setText(team.name);
        name.setFont(new Font("Ariel", Font.PLAIN, 20));
        name.select(0, name.getText().length());
      }

      players.setBorder(BorderFactory.createLineBorder(Color.black));

      south.add(addPlayers);
      south.add(new JLabel("Players"));
      south.add(players, "span, grow");
      south.add(cancel, "span, right, split 2");
      south.add(save, "span, right");

      Eve.add(name);
      Eve.add(south);
    }
Esempio n. 5
0
  class ModifyTeamScreen extends Screen {
    JPanel south = new JPanel(new MigLayout("wrap 2", "[][grow]", "[][grow][]"));
    JPanel players = new JPanel(new MigLayout("flowy", "grow, fill"));
    JTextField name = new JTextField("Team Name");
    JButton addPlayers = new JButton(ResourceRetriever.getImage("plus.png", 16, 16));
    JButton cancel = new JButton("Cancel");
    JButton save = new JButton("Save");
    Team team;
    JWindow popup = new JWindow();
    JPanel inner = new JPanel(new MigLayout("flowy", "[grow, fill]", ""));
    JScrollPane innerScroll = new JScrollPane(inner);
    Dimension windowSize = new Dimension(400, 400);
    Screen caller;

    public ModifyTeamScreen(Team teamPassed, Screen callerScreen) {

      Eve.setLayout(new MigLayout("flowy", "[grow, fill]", "[][grow, fill]"));

      cancel.addActionListener(
          (ActionEvent e) -> {
            caller.Return();
          });

      save.addActionListener(
          (ActionEvent e) -> {
            team.name = name.getText();
            if (team.globalIndex == -1) {
              team.saveTeam(true);
            } else {
              team.saveTeam(false);
            }
            callerScreen.refresh();
            caller.Return();
          });
      addPlayers.setMargin(new Insets(0, 0, 0, 0));
      addPlayers.addActionListener(
          (ActionEvent e) -> {
            if (team.getPlayers().length < 5) {
              JButton cancelB = new JButton("Cancel");
              cancelB.addActionListener(
                  (ActionEvent f) -> {
                    inner.removeAll();
                    popup.dispose();
                  });
              inner.add(cancelB);
              JButton newPlayer = new JButton("New Player");
              newPlayer.addActionListener(
                  (ActionEvent f) -> {
                    inner.removeAll();
                    popup.dispose();
                    ModifyPlayerPopup addNewPlayer = new ModifyPlayerPopup(null, this, team);
                  });
              inner.add(newPlayer);
              inner.add(new JSeparator(), "growx");
              for (Player player : Global.Players) {
                boolean playerInCurrentTeam = false;
                for (Player teamPlayer : team.getPlayers()) {
                  if (teamPlayer.globalIndex == player.globalIndex) {
                    playerInCurrentTeam = true;
                    break;
                  }
                }
                if (!playerInCurrentTeam) {
                  JPanel oldPlayer = player.playerPreview();
                  JButton choose = new JButton("Add!");
                  choose.addActionListener(
                      (ActionEvent f) -> {
                        team.addPlayer(player);
                        inner.removeAll();
                        popup.dispose();
                        refresh();
                      });
                  oldPlayer.add(choose, "east");
                  oldPlayer.setBorder(BorderFactory.createLineBorder(Color.black));
                  inner.add(oldPlayer);
                }
              }
              innerScroll.getVerticalScrollBar().setUnitIncrement(16);
              innerScroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
              popup.add(innerScroll);
              popup.setSize(350, 400);
              popup.setLocation(MouseInfo.getPointerInfo().getLocation());
              popup.setVisible(true);
            } else {
              JOptionPane.showMessageDialog(
                  null,
                  "You cannot add more than 5 players per team.\nPlease remove one before adding another.");
            }
          });

      caller = callerScreen;

      drawScreen(teamPassed);
    }

    void drawScreen(Team teamPassed) {

      if (teamPassed != null) {
        // We're editing a current team
        team = teamPassed;
        for (Player player : team.getPlayers()) {
          JPanel thisPlayer = player.playerPreview();
          JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16));
          modify.setMargin(new Insets(0, 0, 0, 0));
          modify.addActionListener(
              (ActionEvent e) -> {
                new ModifyPlayerPopup(player, this, null);
              });
          JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16));
          delete.setMargin(new Insets(0, 0, 0, 0));
          delete.addActionListener(
              (ActionEvent e) -> {
                Object[] options = {"Remove Player from team", "Delete Player", "Cancel"};
                JFrame frame = new JFrame();
                int answer =
                    JOptionPane.showOptionDialog(
                        frame,
                        "Are you sure you would like to delete \"" + player.name + "?\"",
                        "Confirm Delete",
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        Global.QUESTIONPIC,
                        options,
                        options[2]);
                if (answer == 0) {
                  team.removePlayer(player);
                  refresh();
                } else if (answer == 1) {
                  // Teams without uniqueID's don't get added to players yet,
                  //   so the player needs to be manually removed.
                  if (team.globalIndex == -1) {
                    team.removePlayer(player);
                  }
                  player.delete();
                  refresh();
                }
              });
          thisPlayer.add(delete, "east");
          thisPlayer.add(modify, "east");
          thisPlayer.setBorder(BorderFactory.createLineBorder(Color.black));
          players.add(thisPlayer, "growx");
        }
        name.setText(team.name);
      } else {
        // This is a new Team
        team = new Team("New Team");
        name.setText(team.name);
        name.setFont(new Font("Ariel", Font.PLAIN, 20));
        name.select(0, name.getText().length());
      }

      players.setBorder(BorderFactory.createLineBorder(Color.black));

      south.add(addPlayers);
      south.add(new JLabel("Players"));
      south.add(players, "span, grow");
      south.add(cancel, "span, right, split 2");
      south.add(save, "span, right");

      Eve.add(name);
      Eve.add(south);
    }

    @Override
    void refresh() {
      team.name = name.getText();
      south.removeAll();
      players.removeAll();
      Eve.removeAll();
      drawScreen(team);
      Eve.revalidate();
      Eve.repaint();
    }

    @Override
    void Switch() {
      Adam.remove(caller.Eve);
      Adam.add(Eve);
      Adam.revalidate();
      Adam.setMinimumSize(windowSize);
      Adam.repaint();
    }

    @Override
    void Return() {}
  }
Esempio n. 6
0
  class ModifyPlayerPopup {
    JFrame Cain = new JFrame();
    JPanel Enoch = new JPanel(new MigLayout("flowy", "[grow, fill]", "[][grow, fill]"));
    JPanel south = new JPanel(new MigLayout("wrap 2", "[][grow]", "[][grow][]"));
    JPanel heroes = new JPanel(new WrapLayout(FlowLayout.LEADING));
    JTextField name = new JTextField("Player Name");
    JButton addHeroes = new JButton(ResourceRetriever.getImage("plus.png", 16, 16));
    JButton cancel = new JButton("Cancel");
    JButton save = new JButton("Save");
    Player player;
    JWindow popup = new JWindow();
    JPanel inner = new JPanel(new MigLayout("", "[grow, fill]", "[grow, fill]"));
    JButton back;
    PoolBuilder pool;

    public ModifyPlayerPopup(Player playerPassed, Screen callerScreen, Team team) {

      cancel.addActionListener(
          (ActionEvent e) -> {
            Cain.dispose();
          });

      save.addActionListener(
          (ActionEvent e) -> {
            player.name = name.getText();

            if (player.globalIndex == -1) {
              player.savePlayer();
            } else {
              Global.Players.set(player.globalIndex, player);
              player.writePlayer();
            }
            if (team != null) {
              team.addPlayer(player);
            }

            callerScreen.refresh();
            Cain.dispose();
          });

      if (playerPassed != null) {
        // We're editing a current player
        player = playerPassed;
        for (Hero hero : player.getPlayList()) {
          JLabel heroLabel = new JLabel(hero.portraitSmall);
          heroLabel.addMouseListener(
              new MouseAdapter() {
                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                  player.removeHero(hero);
                  refresh();
                }
              });
          heroes.add(heroLabel);
        }
        name.setText(player.name);
      } else {
        // This is a new Player
        Cain.setTitle("Add a player");
        player = new Player("New Player");
      }
      addHeroes.setMargin(new Insets(0, 0, 0, 0));
      addHeroes.addActionListener(
          (ActionEvent e) -> {
            pool = new PoolBuilder(false, "small", new Returner(), player.getPlayList());
            back = new JButton("Cancel");
            back.addActionListener(
                (ActionEvent p) -> {
                  inner.removeAll();
                  popup.dispose();
                });
            JLabel note = new JLabel("Right click to add multiple heroes.");
            inner.add(back, "wrap");
            inner.add(note, "wrap");
            inner.add(pool.pool, "growx");
            popup.add(inner);
            popup.setSize(700, 500);
            popup.setLocation(MouseInfo.getPointerInfo().getLocation());
            popup.setVisible(true);
          });

      name.setFont(new Font("Ariel", Font.PLAIN, 20));
      name.select(0, name.getText().length());

      heroes.setBorder(BorderFactory.createLineBorder(Color.black));

      south.add(addHeroes);
      south.add(new JLabel("Heroes"));
      south.add(heroes, "span, grow");
      south.add(cancel, "span, right, split 2");
      south.add(save, "span, right");

      Enoch.add(name);
      Enoch.add(south);

      Cain.add(Enoch);
      Cain.setMinimumSize(new Dimension(400, 350));
      Cain.setVisible(true);
    }

    public class Returner extends HeroReturner {
      @Override
      public Void call() throws Exception {
        player.addHero(this.hero);
        JLabel heroLabel = new JLabel(this.hero.portraitSmall);
        heroLabel.addMouseListener(
            new MouseAdapter() {
              @Override
              public void mouseClicked(java.awt.event.MouseEvent e) {
                player.removeHero(hero);
                refresh();
              }
            });

        heroes.add(heroLabel);
        heroes.revalidate();
        heroes.repaint();
        if (e.getButton() == 3) {
          back.setText("Done");
          pool.disableHero(this.hero);
        } else {
          // Button 1 (Or three I suppose??)
          inner.removeAll();
          popup.dispose();
        }
        return null;
      }
    }

    void refresh() {
      heroes.removeAll();
      for (Hero hero : player.getPlayList()) {
        JLabel heroLabel = new JLabel(hero.portraitSmall);
        heroLabel.addMouseListener(
            new MouseAdapter() {
              @Override
              public void mouseClicked(java.awt.event.MouseEvent evt) {
                player.removeHero(hero);
                refresh();
              }
            });
        heroes.add(heroLabel);
      }
      heroes.revalidate();
      heroes.repaint();
    }
  }
Esempio n. 7
0
    void drawScreen() {

      Eve.add(back, "span 2");
      Eve.add(info, "spany 2, grow");
      Eve.add(addB);
      Eve.add(label);
      Eve.add(viewScroll, "span, grow");

      switch (type) {
        case "team":
          label.setText("Teams:");
          if (Global.Teams.isEmpty()) {
            view.add(new JLabel("No teams to display"));
          } else {
            for (Team team : Global.Teams) {
              JPanel thisTeam = team.teamPreview();
              JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16));
              modify.setMargin(new Insets(0, 0, 0, 0));
              modify.addActionListener(
                  (ActionEvent e) -> {
                    called = new ModifyTeamScreen(team, this);
                    called.Switch();
                  });
              JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16));
              delete.setMargin(new Insets(0, 0, 0, 0));
              delete.addActionListener(
                  (ActionEvent e) -> {
                    Object[] options = {"Yes", "No"};
                    JFrame frame = new JFrame();
                    int answer =
                        JOptionPane.showOptionDialog(
                            frame,
                            "Are you sure you would like to delete team \"" + team.name + "?\"",
                            "Confirm Delete",
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                            Global.QUESTIONPIC,
                            options,
                            options[1]);
                    if (answer == 0) {
                      team.delete();
                      refresh();
                    }
                  });
              thisTeam.add(delete, "east");
              thisTeam.add(modify, "east");
              thisTeam.setBorder(BorderFactory.createLineBorder(Color.black));
              view.add(thisTeam, "growx");
            }
          }
          break;
        case "player":
          label.setText("Players:");
          if (Global.Players.isEmpty()) {
            view.add(new JLabel("No players to display"));
          } else {
            for (Player player : Global.Players) {
              JPanel thisPlayer = player.playerPreview();
              JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16));
              modify.setMargin(new Insets(0, 0, 0, 0));
              modify.addActionListener(
                  (ActionEvent e) -> {
                    new ModifyPlayerPopup(player, this, null);
                  });
              JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16));
              delete.setMargin(new Insets(0, 0, 0, 0));
              delete.addActionListener(
                  (ActionEvent e) -> {
                    Object[] options = {"I didn't like him anyways...", "No"};
                    JFrame frame = new JFrame();
                    int answer =
                        JOptionPane.showOptionDialog(
                            frame,
                            "Are you sure you would like to delete \"" + player.name + "?\"",
                            "Confirm Delete",
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                            Global.QUESTIONPIC,
                            options,
                            options[1]);
                    if (answer == 0) {
                      player.delete();
                      refresh();
                    }
                  });
              thisPlayer.add(delete, "east");
              thisPlayer.add(modify, "east");
              thisPlayer.setBorder(BorderFactory.createLineBorder(Color.black));
              view.add(thisPlayer, "growx");
            }
          }
          break;
      }
    }
Esempio n. 8
0
  class ManageScreen extends Screen {
    JPanel info = new JPanel(new MigLayout());
    JPanel view = new JPanel(new MigLayout("flowy", "grow, fill"));
    JScrollPane viewScroll = new JScrollPane(view);
    JButton back = new JButton("Back");
    JButton addB = new JButton(ResourceRetriever.getImage("plus.png", 16, 16));
    JLabel label = new JLabel();
    String type;
    Dimension windowSize = new Dimension(400, 400);
    Screen caller;
    Screen called;

    public ManageScreen(String type, Screen callerScreen) {
      caller = callerScreen;

      Eve.setLayout(new MigLayout("wrap 3", "[][grow 25][grow 75]", "[][][grow]"));
      this.type = type;

      back.addActionListener(
          (ActionEvent e) -> {
            caller.refresh();
            caller.Return();
          });
      addB.setMargin(new Insets(0, 0, 0, 0));
      addB.addActionListener(
          (ActionEvent e) -> {
            if (type.matches("player")) {
              new ModifyPlayerPopup(null, this, null);
            } else if (type.matches("team")) {
              called = new ModifyTeamScreen(null, this);
              called.Switch();
            }
          });

      view.setBorder(BorderFactory.createLineBorder(Color.black));

      viewScroll.getVerticalScrollBar().setUnitIncrement(16);

      this.drawScreen();
    }

    void drawScreen() {

      Eve.add(back, "span 2");
      Eve.add(info, "spany 2, grow");
      Eve.add(addB);
      Eve.add(label);
      Eve.add(viewScroll, "span, grow");

      switch (type) {
        case "team":
          label.setText("Teams:");
          if (Global.Teams.isEmpty()) {
            view.add(new JLabel("No teams to display"));
          } else {
            for (Team team : Global.Teams) {
              JPanel thisTeam = team.teamPreview();
              JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16));
              modify.setMargin(new Insets(0, 0, 0, 0));
              modify.addActionListener(
                  (ActionEvent e) -> {
                    called = new ModifyTeamScreen(team, this);
                    called.Switch();
                  });
              JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16));
              delete.setMargin(new Insets(0, 0, 0, 0));
              delete.addActionListener(
                  (ActionEvent e) -> {
                    Object[] options = {"Yes", "No"};
                    JFrame frame = new JFrame();
                    int answer =
                        JOptionPane.showOptionDialog(
                            frame,
                            "Are you sure you would like to delete team \"" + team.name + "?\"",
                            "Confirm Delete",
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                            Global.QUESTIONPIC,
                            options,
                            options[1]);
                    if (answer == 0) {
                      team.delete();
                      refresh();
                    }
                  });
              thisTeam.add(delete, "east");
              thisTeam.add(modify, "east");
              thisTeam.setBorder(BorderFactory.createLineBorder(Color.black));
              view.add(thisTeam, "growx");
            }
          }
          break;
        case "player":
          label.setText("Players:");
          if (Global.Players.isEmpty()) {
            view.add(new JLabel("No players to display"));
          } else {
            for (Player player : Global.Players) {
              JPanel thisPlayer = player.playerPreview();
              JButton modify = new JButton(ResourceRetriever.getImage("edit.png", 16, 16));
              modify.setMargin(new Insets(0, 0, 0, 0));
              modify.addActionListener(
                  (ActionEvent e) -> {
                    new ModifyPlayerPopup(player, this, null);
                  });
              JButton delete = new JButton(ResourceRetriever.getImage("X.png", 16, 16));
              delete.setMargin(new Insets(0, 0, 0, 0));
              delete.addActionListener(
                  (ActionEvent e) -> {
                    Object[] options = {"I didn't like him anyways...", "No"};
                    JFrame frame = new JFrame();
                    int answer =
                        JOptionPane.showOptionDialog(
                            frame,
                            "Are you sure you would like to delete \"" + player.name + "?\"",
                            "Confirm Delete",
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE,
                            Global.QUESTIONPIC,
                            options,
                            options[1]);
                    if (answer == 0) {
                      player.delete();
                      refresh();
                    }
                  });
              thisPlayer.add(delete, "east");
              thisPlayer.add(modify, "east");
              thisPlayer.setBorder(BorderFactory.createLineBorder(Color.black));
              view.add(thisPlayer, "growx");
            }
          }
          break;
      }
    }

    @Override
    void refresh() {
      info.removeAll();
      view.removeAll();
      Eve.removeAll();
      this.drawScreen();
      Eve.revalidate();
      Eve.repaint();
    }

    void Switch() {
      Adam.remove(caller.Eve);
      Adam.add(Eve);
      Adam.revalidate();
      Adam.setMinimumSize(windowSize);
      Adam.setSize(windowSize);
      Adam.repaint();
    }

    @Override
    void Return() {
      Adam.remove(called.Eve);
      Adam.add(Eve);
      Adam.revalidate();
      Adam.setMinimumSize(windowSize);
      Adam.repaint();
    }
  }