public AddEditServerForCheckerDialog(MinecraftServer minecraftServer) {
    super(
        null,
        Language.INSTANCE.localize(
            (minecraftServer == null ? "tools.addserver" : "tools.editserver")),
        ModalityType.APPLICATION_MODAL);
    setSize(300, 200);
    setLocationRelativeTo(null);
    setLayout(new BorderLayout());
    setIconImage(Utils.getImage("/assets/image/Icon.png"));
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    setResizable(false);

    setupComponents();

    if (minecraftServer != null) {
      this.serverEditing = minecraftServer;
      addEditButton.setText(Language.INSTANCE.localize("common.edit"));
      serverName.setText(minecraftServer.getName());
      serverHost.setText(minecraftServer.getHost());
      serverPort.setText(minecraftServer.getPort() + "");
    }

    setVisible(true);
  }
Ejemplo n.º 2
0
 @Override
 public void onRelocalization() {
   this.newInstanceButton.setText(Language.INSTANCE.localize("common.newinstance"));
   this.createServerButton.setText(Language.INSTANCE.localize("common.createserver"));
   this.supportButton.setText(Language.INSTANCE.localize("common.support"));
   this.websiteButton.setText(Language.INSTANCE.localize("common.website"));
   this.modsButton.setText(Language.INSTANCE.localize("pack.viewmods"));
 }
Ejemplo n.º 3
0
  @Override
  public void onRelocalization() {
    this.forgeLoggingLevelLabel.setText(
        Language.INSTANCE.localize("settings" + ".forgelogginglevel") + ":");
    this.forgeLoggingLevelLabel.setToolTipText(
        "<html>"
            + Language.INSTANCE.localizeWithReplace(
                "settings" + "" + ".forgelogginglevelhelp", "<br/><br/>")
            + "</html>");

    this.daysOfLogsToKeepLabel.setText(
        Language.INSTANCE.localize("settings.daysoflogstokeep") + "?");
    this.daysOfLogsToKeepLabel.setToolTipText(
        Language.INSTANCE.localize("settings.daysoflogstokeephelp"));

    this.enableLeaderboardsLabel.setText(Language.INSTANCE.localize("settings.leaderboards") + "?");
    this.enableLeaderboardsLabel.setToolTipText(
        Language.INSTANCE.localize("settings.leaderboardshelp"));

    this.enableLoggingLabel.setText(Language.INSTANCE.localize("settings.logging") + "?");
    this.enableLoggingLabel.setToolTipText(
        "<html>"
            + Language.INSTANCE.localizeWithReplace(
                "settings" + "" + ".logginghelp", "<br/>" + "</html>"));

    this.enableOpenEyeReportingLabel.setText(Language.INSTANCE.localize("settings.openeye") + "?");
    this.enableOpenEyeReportingLabel.setToolTipText(
        "<html>"
            + Utils.splitMultilinedString(
                Language.INSTANCE.localize("settings.openeyehelp"), 80, "<br/>")
            + "</html>");
  }
Ejemplo n.º 4
0
 @Override
 public void onRelocalization() {
   this.playButton.setText(Language.INSTANCE.localize("common.play"));
   this.reinstallButton.setText(Language.INSTANCE.localize("common.reinstall"));
   this.updateButton.setText(Language.INSTANCE.localize("common.update"));
   this.renameButton.setText(Language.INSTANCE.localize("instance.rename"));
   this.backupButton.setText(Language.INSTANCE.localize("common.backup"));
   this.cloneButton.setText(Language.INSTANCE.localize("instance.clone"));
   this.deleteButton.setText(Language.INSTANCE.localize("common.delete"));
   this.editButton.setText(Language.INSTANCE.localize("common.editmods"));
   this.openButton.setText(Language.INSTANCE.localize("common.openfolder"));
 }
Ejemplo n.º 5
0
  private final class ContextMenu extends JPopupMenu {
    private final JMenuItem FORCE_QUIT =
        new JMenuItem(Language.INSTANCE.localize("common.forcequit"));

    public ContextMenu() {
      super();

      this.FORCE_QUIT.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              System.exit(0);
            }
          });
      this.add(this.FORCE_QUIT);
    }
  }
  private void setupComponents() {
    // Middle Panel Stuff
    middle = new JPanel();
    middle.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    // Server Name

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    serverNameLabel = new JLabel(Language.INSTANCE.localize("tools.serverchecker.name") + ": ");
    middle.add(serverNameLabel, gbc);

    gbc.gridx++;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    serverName = new JTextField(16);
    middle.add(serverName, gbc);

    // Server Host/IP

    gbc.gridx = 0;
    gbc.gridy++;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    serverHostLabel = new JLabel(Language.INSTANCE.localize("tools.serverchecker.ip") + ": ");
    middle.add(serverHostLabel, gbc);

    gbc.gridx++;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    serverHost = new JTextField(16);
    middle.add(serverHost, gbc);

    // Server Port

    gbc.gridx = 0;
    gbc.gridy++;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    serverPortLabel = new JLabel(Language.INSTANCE.localize("tools.serverchecker.port") + ": ");
    middle.add(serverPortLabel, gbc);

    gbc.gridx++;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    serverPort = new JTextField(16);
    serverPort.setText("25565");
    middle.add(serverPort, gbc);

    // Bottom Panel Stuff
    bottom = new JPanel();
    bottom.setLayout(new FlowLayout());

    addEditButton = new JButton(Language.INSTANCE.localize("common.add"));
    addEditButton.addActionListener(this);
    bottom.add(addEditButton);

    closeButton = new JButton(Language.INSTANCE.localize("common.close"));
    closeButton.addActionListener(this);
    bottom.add(closeButton);

    add(middle, BorderLayout.CENTER);
    add(bottom, BorderLayout.SOUTH);
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == addEditButton) {
      if (serverName.getText().isEmpty()
          || serverHost.getText().isEmpty()
          || serverPort.getText().isEmpty()) {
        JOptionPane.showMessageDialog(
            App.settings.getParent(),
            Language.INSTANCE.localize("tools" + "" + ".serverchecker.notallfields"),
            Language.INSTANCE.localize("common.error"),
            JOptionPane.ERROR_MESSAGE);
      } else if (!isValidPort()) {
        JOptionPane.showMessageDialog(
            App.settings.getParent(),
            Language.INSTANCE.localize("settings" + "" + ".proxyportinvalid"),
            Language.INSTANCE.localize("common.error"),
            JOptionPane.ERROR_MESSAGE);
      } else {
        String name = serverName.getText();
        final String host = serverHost.getText();
        final int port = Integer.parseInt(serverPort.getText().replaceAll("[^0-9]", ""));
        QueryVersion qv = null;

        final ProgressDialog dialog =
            new ProgressDialog(
                Language.INSTANCE.localize("tools.serverchecker" + "" + ".checkingserver"),
                0,
                Language.INSTANCE.localize("tools.serverchecker.checkingserver"),
                "Cancelled Server Check!");
        dialog.addThread(
            new Thread() {
              @Override
              public void run() {
                dialog.setReturnValue(MCQuery.getMinecraftServerQueryVersion(host, port));
                dialog.close();
              }
            });
        dialog.start();

        if (dialog.getReturnValue() != null) {
          qv = (QueryVersion) dialog.getReturnValue();
        }

        if (qv == null) {
          JOptionPane.showMessageDialog(
              App.settings.getParent(),
              Language.INSTANCE.localize("tools" + "" + ".serverchecker.couldntconnect"),
              Language.INSTANCE.localize("common.error"),
              JOptionPane.ERROR_MESSAGE);
        } else {
          App.TOASTER.pop(
              Language.INSTANCE.localize(
                  (this.serverEditing == null
                      ? "tools" + "" + ".serverchecker.serveradded"
                      : "tools.serverchecker.serveredited")));
          if (this.serverEditing == null) {
            App.settings.addCheckingServer(new MinecraftServer(name, host, port, qv));
          } else {
            this.serverEditing.setName(name);
            this.serverEditing.setHost(host);
            this.serverEditing.setPort(port);
            this.serverEditing.setQueryVersion(qv);
            App.settings.saveCheckingServers();
          }
          close();
        }
      }
    } else if (e.getSource() == closeButton) {
      close();
    }
  }
Ejemplo n.º 8
0
/**
 * Class for displaying instances in the Instance Tab
 *
 * @author Ryan
 */
public class InstanceCard extends CollapsiblePanel implements RelocalizationListener {
  private final JSplitPane splitter = new JSplitPane();
  private final Instance instance;
  private final JPanel rightPanel = new JPanel();
  private final JTextArea descArea = new JTextArea();
  private final ImagePanel image;
  private final JButton playButton = new JButton(Language.INSTANCE.localize("common.play"));
  private final JButton reinstallButton =
      new JButton(Language.INSTANCE.localize("common.reinstall"));
  private final JButton updateButton = new JButton(Language.INSTANCE.localize("common.update"));
  private final JButton renameButton = new JButton(Language.INSTANCE.localize("common.rename"));
  private final JButton backupButton = new JButton(Language.INSTANCE.localize("common.backup"));
  private final JButton cloneButton = new JButton(Language.INSTANCE.localize("instance.clone"));
  private final JButton deleteButton = new JButton(Language.INSTANCE.localize("common.delete"));
  private final JButton editButton = new JButton(Language.INSTANCE.localize("common.editmods"));
  private final JButton openButton = new JButton(Language.INSTANCE.localize("common.openfolder"));

  public InstanceCard(Instance instance) {
    super(instance);
    this.instance = instance;
    this.image = new ImagePanel(instance.getImage().getImage());
    this.splitter.setLeftComponent(this.image);
    this.splitter.setRightComponent(this.rightPanel);
    this.splitter.setEnabled(false);

    this.descArea.setText(instance.getPackDescription());
    this.descArea.setBorder(BorderFactory.createEmptyBorder());
    this.descArea.setEditable(false);
    this.descArea.setHighlighter(null);
    this.descArea.setLineWrap(true);
    this.descArea.setWrapStyleWord(true);
    this.descArea.setEditable(false);

    JPanel top = new JPanel(new FlowLayout());
    JPanel bottom = new JPanel(new FlowLayout());
    JSplitPane as = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    as.setEnabled(false);
    as.setTopComponent(top);
    as.setBottomComponent(bottom);
    top.add(this.playButton);
    top.add(this.reinstallButton);
    top.add(this.updateButton);
    top.add(this.renameButton);
    top.add(this.backupButton);
    bottom.add(this.cloneButton);
    bottom.add(this.deleteButton);
    bottom.add(this.editButton);
    bottom.add(this.openButton);

    this.rightPanel.setLayout(new BorderLayout());
    this.rightPanel.setPreferredSize(new Dimension(this.rightPanel.getPreferredSize().width, 180));
    this.rightPanel.add(
        new JScrollPane(
            this.descArea,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
        BorderLayout.CENTER);
    this.rightPanel.add(as, BorderLayout.SOUTH);

    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(this.splitter, BorderLayout.CENTER);

    RelocalizationManager.addListener(this);

    if (!instance.hasUpdate()) {
      this.updateButton.setVisible(false);
    }

    this.addActionListeners();
    this.addMouseListeners();
    this.validatePlayable();
  }

  private void validatePlayable() {
    if (!instance.isPlayable()) {
      for (ActionListener al : playButton.getActionListeners()) {
        playButton.removeActionListener(al);
      }
      playButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String[] options = {Language.INSTANCE.localize("common.ok")};
              JOptionPane.showOptionDialog(
                  App.settings.getParent(),
                  Language.INSTANCE.localize("instance" + "" + ".corruptplay"),
                  Language.INSTANCE.localize("instance.corrupt"),
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
            }
          });
      for (ActionListener al : backupButton.getActionListeners()) {
        backupButton.removeActionListener(al);
      }
      backupButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String[] options = {Language.INSTANCE.localize("common.ok")};
              JOptionPane.showOptionDialog(
                  App.settings.getParent(),
                  Language.INSTANCE.localize("instance" + "" + ".corruptbackup"),
                  Language.INSTANCE.localize("instance.corrupt"),
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
            }
          });
      for (ActionListener al : cloneButton.getActionListeners()) {
        cloneButton.removeActionListener(al);
      }
      cloneButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String[] options = {Language.INSTANCE.localize("common.ok")};
              JOptionPane.showOptionDialog(
                  App.settings.getParent(),
                  Language.INSTANCE.localize("instance" + "" + ".corruptclone"),
                  Language.INSTANCE.localize("instance.corrupt"),
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
            }
          });
    }
  }

  private void addActionListeners() {
    this.playButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (instance.hasUpdate()
                && !instance.hasUpdateBeenIgnored(instance.getLatestVersion())
                && !instance.isDev()) {
              String[] options = {
                Language.INSTANCE.localize("common.yes"),
                Language.INSTANCE.localize("common" + ".no"),
                Language.INSTANCE.localize("instance.dontremindmeagain")
              };
              int ret =
                  JOptionPane.showOptionDialog(
                      App.settings.getParent(),
                      "<html><p align=\"center\">"
                          + Language.INSTANCE.localizeWithReplace(
                              "instance" + "" + ".updatenow", "<br/><br/>")
                          + "</p></html>",
                      Language.INSTANCE.localize("instance" + "" + ".updateavailable"),
                      JOptionPane.DEFAULT_OPTION,
                      JOptionPane.ERROR_MESSAGE,
                      null,
                      options,
                      options[0]);
              if (ret == 0) {
                if (App.settings.getAccount() == null) {
                  String[] optionss = {Language.INSTANCE.localize("common.ok")};
                  JOptionPane.showOptionDialog(
                      App.settings.getParent(),
                      Language.INSTANCE.localize("instance.cantupdate"),
                      Language.INSTANCE.localize("instance.noaccountselected"),
                      JOptionPane.DEFAULT_OPTION,
                      JOptionPane.ERROR_MESSAGE,
                      null,
                      optionss,
                      optionss[0]);
                } else {
                  new InstanceInstallerDialog(instance, true, false);
                }
              } else if (ret == 1 || ret == JOptionPane.CLOSED_OPTION) {
                if (!App.settings.isMinecraftLaunched()) {
                  if (instance.launch()) {
                    App.settings.setMinecraftLaunched(true);
                  }
                }
              } else if (ret == 2) {
                instance.ignoreUpdate();
                if (!App.settings.isMinecraftLaunched()) {
                  if (instance.launch()) {
                    App.settings.setMinecraftLaunched(true);
                  }
                }
              }
            } else {
              if (!App.settings.isMinecraftLaunched()) {
                if (instance.launch()) {
                  App.settings.setMinecraftLaunched(true);
                }
              }
            }
          }
        });
    this.reinstallButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (App.settings.getAccount() == null) {
              String[] options = {Language.INSTANCE.localize("common.ok")};
              JOptionPane.showOptionDialog(
                  App.settings.getParent(),
                  Language.INSTANCE.localize("instance" + "" + ".cantreinstall"),
                  Language.INSTANCE.localize("instance.noaccountselected"),
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
            } else {
              new InstanceInstallerDialog(instance);
            }
          }
        });
    this.updateButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (App.settings.getAccount() == null) {
              String[] options = {Language.INSTANCE.localize("common.ok")};
              JOptionPane.showOptionDialog(
                  App.settings.getParent(),
                  Language.INSTANCE.localize("instance" + "" + ".cantupdate"),
                  Language.INSTANCE.localize("instance.noaccountselected"),
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
            } else {
              new InstanceInstallerDialog(instance, true, false);
            }
          }
        });
    this.renameButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            new RenameInstanceDialog(instance);
          }
        });
    this.backupButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (App.settings.isAdvancedBackupsEnabled()) {
              new BackupDialog(instance).setVisible(true);
            } else {
              if (instance.getSavesDirectory().exists()) {
                int ret =
                    JOptionPane.showConfirmDialog(
                        App.settings.getParent(),
                        "<html><p align=\"center\">"
                            + Language.INSTANCE.localizeWithReplace("backup.sure", "<br/><br/>")
                            + "</p></html>",
                        Language.INSTANCE.localize(
                            "backup" + "" + ".backingup", instance.getName()),
                        JOptionPane.YES_NO_OPTION);
                if (ret == JOptionPane.YES_OPTION) {
                  final JDialog dialog =
                      new JDialog(
                          App.settings.getParent(),
                          Language.INSTANCE.localizeWithReplace(
                              "backup.backingup", instance.getName()),
                          ModalityType.APPLICATION_MODAL);
                  dialog.setSize(300, 100);
                  dialog.setLocationRelativeTo(App.settings.getParent());
                  dialog.setResizable(false);

                  JPanel topPanel = new JPanel();
                  topPanel.setLayout(new BorderLayout());
                  JLabel doing =
                      new JLabel(
                          Language.INSTANCE.localizeWithReplace(
                              "backup.backingup", instance.getName()));
                  doing.setHorizontalAlignment(JLabel.CENTER);
                  doing.setVerticalAlignment(JLabel.TOP);
                  topPanel.add(doing);

                  JPanel bottomPanel = new JPanel();
                  bottomPanel.setLayout(new BorderLayout());
                  JProgressBar progressBar = new JProgressBar();
                  bottomPanel.add(progressBar, BorderLayout.NORTH);
                  progressBar.setIndeterminate(true);

                  dialog.add(topPanel, BorderLayout.CENTER);
                  dialog.add(bottomPanel, BorderLayout.SOUTH);

                  final Thread backupThread =
                      new Thread() {
                        public void run() {
                          Timestamp timestamp = new Timestamp(new Date().getTime());
                          String time = timestamp.toString().replaceAll("[^0-9]", "_");
                          String filename =
                              instance.getSafeName()
                                  + "-"
                                  + time.substring(0, time.lastIndexOf("_"))
                                  + ".zip";
                          Utils.zip(
                              instance.getSavesDirectory(),
                              new File(App.settings.getBackupsDir(), filename));
                          dialog.dispose();
                          App.TOASTER.pop(
                              Language.INSTANCE.localizeWithReplace(
                                  "backup.backupcomplete", " " + filename));
                        }
                      };
                  backupThread.start();
                  dialog.addWindowListener(
                      new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                          backupThread.interrupt();
                          dialog.dispose();
                        }
                      });
                  dialog.setVisible(true);
                }
              } else {
                String[] options = {Language.INSTANCE.localize("common.ok")};
                JOptionPane.showOptionDialog(
                    App.settings.getParent(),
                    Language.INSTANCE.localize("backup" + ".nosaves"),
                    Language.INSTANCE.localize("backup.nosavestitle"),
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE,
                    null,
                    options,
                    options[0]);
              }
            }
          }
        });
    this.editButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            new EditModsDialog(instance);
          }
        });
    this.openButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Utils.openExplorer(instance.getRootDirectory());
          }
        });
    this.cloneButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String clonedName =
                JOptionPane.showInputDialog(
                    App.settings.getParent(),
                    Language.INSTANCE.localize("instance.cloneenter"),
                    Language.INSTANCE.localize("instance" + "" + ".clonetitle"),
                    JOptionPane.INFORMATION_MESSAGE);
            if (clonedName != null
                && clonedName.length() >= 1
                && App.settings.getInstanceByName(clonedName) == null
                && App.settings.getInstanceBySafeName(clonedName.replaceAll("[^A-Za-z0-9]", ""))
                    == null
                && clonedName.replaceAll("[^A-Za-z0-9]", "").length() >= 1) {

              final String newName = clonedName;
              final ProgressDialog dialog =
                  new ProgressDialog(
                      Language.INSTANCE.localize("instance" + "" + ".clonetitle"),
                      0,
                      Language.INSTANCE.localize("instance.cloninginstance"),
                      null);
              dialog.addThread(
                  new Thread() {
                    @Override
                    public void run() {
                      App.settings.cloneInstance(instance, newName);
                      dialog.close();
                      App.TOASTER.pop(
                          Language.INSTANCE.localizeWithReplace(
                              "instance.clonedsuccessfully", instance.getName()));
                    }
                  });
              dialog.start();
            } else if (clonedName == null || clonedName.equals("")) {
              LogManager.error("Error Occured While Cloning Instance! Dialog Closed/Cancelled!");
              JOptionPane.showMessageDialog(
                  App.settings.getParent(),
                  "<html><p align=\"center\">"
                      + Language.INSTANCE.localizeWithReplace(
                          "instance.errorclone", instance.getName() + "<br/><br/>")
                      + "</p></html>",
                  Language.INSTANCE.localize("common.error"),
                  JOptionPane.ERROR_MESSAGE);
            } else if (clonedName.replaceAll("[^A-Za-z0-9]", "").length() == 0) {
              LogManager.error("Error Occured While Cloning Instance! Invalid Name!");
              JOptionPane.showMessageDialog(
                  App.settings.getParent(),
                  "<html><p align=\"center\">"
                      + Language.INSTANCE.localizeWithReplace(
                          "instance.errorclone", instance.getName() + "<br/><br/>")
                      + "</p></html>",
                  Language.INSTANCE.localize("common.error"),
                  JOptionPane.ERROR_MESSAGE);
            } else {
              LogManager.error(
                  "Error Occured While Cloning Instance! Instance With That Name Already Exists!");
              JOptionPane.showMessageDialog(
                  App.settings.getParent(),
                  "<html><p align=\"center\">"
                      + Language.INSTANCE.localizeWithReplace(
                          "instance.errorclone", instance.getName() + "<br/><br/>")
                      + "</p></html>",
                  Language.INSTANCE.localize("common.error"),
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });
    this.deleteButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            int response =
                JOptionPane.showConfirmDialog(
                    App.settings.getParent(),
                    Language.INSTANCE.localize("instance.deletesure"),
                    Language.INSTANCE.localize("instance" + "" + ".deleteinstance"),
                    JOptionPane.YES_NO_OPTION);
            if (response == JOptionPane.YES_OPTION) {
              final ProgressDialog dialog =
                  new ProgressDialog(
                      Language.INSTANCE.localize("instance" + "" + ".deletetitle"),
                      0,
                      Language.INSTANCE.localize("instance.deletinginstance"),
                      null);
              dialog.addThread(
                  new Thread() {
                    @Override
                    public void run() {
                      App.settings.removeInstance(instance);
                      dialog.close();
                      App.TOASTER.pop(
                          Language.INSTANCE.localizeWithReplace(
                              "instance.deletedsuccessfully", instance.getName()));
                    }
                  });
              dialog.start();
            }
          }
        });
  }

  private void addMouseListeners() {
    this.image.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() >= 2) {
              if (instance.hasUpdate()
                  && !instance.hasUpdateBeenIgnored(instance.getLatestVersion())
                  && !instance.isDev()) {
                String[] options = {
                  Language.INSTANCE.localize("common.yes"),
                  Language.INSTANCE.localize("common.no"),
                  Language.INSTANCE.localize("instance" + "" + ".dontremindmeagain")
                };
                int ret =
                    JOptionPane.showOptionDialog(
                        App.settings.getParent(),
                        "<html><p align=\"center\">"
                            + Language.INSTANCE.localizeWithReplace(
                                "instance" + "" + ".updatenow", "<br/><br/>")
                            + "</p></html>",
                        Language.INSTANCE.localize("instance.updateavailable"),
                        JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE,
                        null,
                        options,
                        options[0]);
                if (ret == 0) {
                  if (App.settings.getAccount() == null) {
                    String[] optionss = {Language.INSTANCE.localize("common.ok")};
                    JOptionPane.showOptionDialog(
                        App.settings.getParent(),
                        Language.INSTANCE.localize("instance.cantupdate"),
                        Language.INSTANCE.localize("instance.noaccountselected"),
                        JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE,
                        null,
                        optionss,
                        optionss[0]);
                  } else {
                    new InstanceInstallerDialog(instance, true, false);
                  }
                } else if (ret == 1 || ret == JOptionPane.CLOSED_OPTION) {
                  if (!App.settings.isMinecraftLaunched()) {
                    if (instance.launch()) {
                      App.settings.setMinecraftLaunched(true);
                    }
                  }
                } else if (ret == 2) {
                  instance.ignoreUpdate();
                  if (!App.settings.isMinecraftLaunched()) {
                    if (instance.launch()) {
                      App.settings.setMinecraftLaunched(true);
                    }
                  }
                }
              } else {
                if (!App.settings.isMinecraftLaunched()) {
                  if (instance.launch()) {
                    App.settings.setMinecraftLaunched(true);
                  }
                }
              }
            } else if (e.getButton() == MouseEvent.BUTTON3) {
              JPopupMenu rightClickMenu = new JPopupMenu();
              JMenuItem changeImageItem =
                  new JMenuItem(Language.INSTANCE.localize("instance.changeimage"));
              JMenuItem updateItem = new JMenuItem("Update Instance");
              rightClickMenu.add(changeImageItem);
              rightClickMenu.add(updateItem);
              rightClickMenu.show(image, e.getX(), e.getY());
              changeImageItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      JFileChooser chooser = new JFileChooser();
                      chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                      chooser.setAcceptAllFileFilterUsed(false);
                      chooser.setFileFilter(new FileNameExtensionFilter("PNG Files", "png"));
                      int ret = chooser.showOpenDialog(App.settings.getParent());
                      if (ret == JFileChooser.APPROVE_OPTION) {
                        File img = chooser.getSelectedFile();
                        if (img.getAbsolutePath().endsWith(".png")) {
                          try {
                            Utils.safeCopy(
                                img, new File(instance.getRootDirectory(), "instance.png"));
                            image.setImage(instance.getImage().getImage());
                            instance.save();
                          } catch (IOException e1) {
                            e1.printStackTrace(System.err);
                          }
                        }
                      }
                    }
                  });
              updateItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      if (instance.hasUpdate()
                          && !instance.hasUpdateBeenIgnored(instance.getLatestVersion())
                          && !instance.isDev()) {
                        String[] options = {
                          Language.INSTANCE.localize("common.yes"),
                          Language.INSTANCE.localize("common.no"),
                          Language.INSTANCE.localize("instance" + "" + ".dontremindmeagain")
                        };
                        int ret =
                            JOptionPane.showOptionDialog(
                                App.settings.getParent(),
                                "<html><p align=\"center\">"
                                    + Language.INSTANCE.localize(
                                        "instance" + "" + ".updatenow", "<br/><br/>")
                                    + "</p></html>",
                                Language.INSTANCE.localize("instance" + "" + ".updateavailable"),
                                JOptionPane.DEFAULT_OPTION,
                                JOptionPane.ERROR_MESSAGE,
                                null,
                                options,
                                options[0]);
                        if (ret == 0) {
                          if (App.settings.getAccount() == null) {
                            String[] optionss = {Language.INSTANCE.localize("common.ok")};
                            JOptionPane.showOptionDialog(
                                App.settings.getParent(),
                                Language.INSTANCE.localize("instance.cantupdate"),
                                Language.INSTANCE.localize("instance.noaccountselected"),
                                JOptionPane.DEFAULT_OPTION,
                                JOptionPane.ERROR_MESSAGE,
                                null,
                                optionss,
                                optionss[0]);
                          } else {
                            new InstanceInstallerDialog(instance, true, false);
                          }
                        } else if (ret == 1 || ret == JOptionPane.CLOSED_OPTION) {
                          if (!App.settings.isMinecraftLaunched()) {
                            if (instance.launch()) {
                              App.settings.setMinecraftLaunched(true);
                            }
                          }
                        } else if (ret == 2) {
                          instance.ignoreUpdate();
                          if (!App.settings.isMinecraftLaunched()) {
                            if (instance.launch()) {
                              App.settings.setMinecraftLaunched(true);
                            }
                          }
                        }
                      } else {
                        if (!App.settings.isMinecraftLaunched()) {
                          if (instance.launch()) {
                            App.settings.setMinecraftLaunched(true);
                          }
                        }
                      }
                    }
                  });
            }
          }

          @Override
          public void mouseEntered(MouseEvent e) {
            super.mouseEntered(e);
            setCursor(new Cursor(Cursor.HAND_CURSOR));
          }

          @Override
          public void mouseExited(MouseEvent e) {
            super.mouseExited(e);
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
          }
        });
  }

  @Override
  public void onRelocalization() {
    this.playButton.setText(Language.INSTANCE.localize("common.play"));
    this.reinstallButton.setText(Language.INSTANCE.localize("common.reinstall"));
    this.updateButton.setText(Language.INSTANCE.localize("common.update"));
    this.renameButton.setText(Language.INSTANCE.localize("instance.rename"));
    this.backupButton.setText(Language.INSTANCE.localize("common.backup"));
    this.cloneButton.setText(Language.INSTANCE.localize("instance.clone"));
    this.deleteButton.setText(Language.INSTANCE.localize("common.delete"));
    this.editButton.setText(Language.INSTANCE.localize("common.editmods"));
    this.openButton.setText(Language.INSTANCE.localize("common.openfolder"));
  }
}
Ejemplo n.º 9
0
/**
 * Class for displaying packs in the Pack Tab
 *
 * @author Ryan
 */
public class PackCard extends CollapsiblePanel implements RelocalizationListener {
  private static final long serialVersionUID = -2617283435728223314L;
  private final JTextArea descArea = new JTextArea();
  private final JButton newInstanceButton =
      new JButton(Language.INSTANCE.localize("common.newinstance"));
  private final JButton createServerButton =
      new JButton(Language.INSTANCE.localize("common.createserver"));
  private final JButton supportButton = new JButton(Language.INSTANCE.localize("common.support"));
  private final JButton websiteButton = new JButton(Language.INSTANCE.localize("common.website"));
  private final JButton modsButton = new JButton(Language.INSTANCE.localize("pack.viewmods"));
  private final JPanel actionsPanel = new JPanel(new BorderLayout());
  private final JSplitPane splitter = new JSplitPane();
  private final GridBagConstraints gbc = new GridBagConstraints();
  private final Pack pack;

  public PackCard(final Pack pack) {
    super(pack);
    RelocalizationManager.addListener(this);
    this.pack = pack;

    this.splitter.setLeftComponent(new PackImagePanel(pack));
    this.splitter.setRightComponent(this.actionsPanel);
    this.splitter.setEnabled(false);

    JPanel abPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    abPanel.add(this.newInstanceButton);
    abPanel.add(this.createServerButton);
    abPanel.add(this.supportButton);
    abPanel.add(this.websiteButton);
    abPanel.add(this.modsButton);

    this.descArea.setText(pack.getDescription());
    this.descArea.setLineWrap(true);
    this.descArea.setEditable(false);
    this.descArea.setHighlighter(null);
    this.descArea.setWrapStyleWord(true);

    this.actionsPanel.add(
        new JScrollPane(
            this.descArea,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
        BorderLayout.CENTER);
    this.actionsPanel.add(abPanel, BorderLayout.SOUTH);
    this.actionsPanel.setPreferredSize(
        new Dimension(this.actionsPanel.getPreferredSize().width, 180));

    this.getContentPane().add(this.splitter);

    this.addActionListeners();

    if (this.pack.getVersionCount() == 0) {
      this.modsButton.setVisible(false);
    }
  }

  public Pack getPack() {
    return this.pack;
  }

  private void addActionListeners() {
    this.newInstanceButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (App.settings.isInOfflineMode()) {
              String[] options = {Language.INSTANCE.localize("common.ok")};
              JOptionPane.showOptionDialog(
                  App.settings.getParent(),
                  Language.INSTANCE.localize("pack" + "" + ".offlinenewinstance"),
                  Language.INSTANCE.localize("common.offline"),
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
            } else {
              if (App.settings.getAccount() == null) {
                String[] options = {Language.INSTANCE.localize("common.ok")};
                JOptionPane.showOptionDialog(
                    App.settings.getParent(),
                    Language.INSTANCE.localize("instance" + ".cannotcreate"),
                    Language.INSTANCE.localize("instance.noaccountselected"),
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE,
                    null,
                    options,
                    options[0]);
              } else {
                new InstanceInstallerDialog(pack);
              }
            }
          }
        });
    this.createServerButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (App.settings.isInOfflineMode()) {
              String[] options = {Language.INSTANCE.localize("common.ok")};
              JOptionPane.showOptionDialog(
                  App.settings.getParent(),
                  Language.INSTANCE.localize("pack" + "" + ".offlinecreateserver"),
                  Language.INSTANCE.localize("common.offline"),
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
            } else {
              if (App.settings.getAccount() == null) {
                String[] options = {Language.INSTANCE.localize("common.ok")};
                JOptionPane.showOptionDialog(
                    App.settings.getParent(),
                    Language.INSTANCE.localize("instance" + ".cannotcreate"),
                    Language.INSTANCE.localize("instance.noaccountselected"),
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE,
                    null,
                    options,
                    options[0]);
              } else {
                new InstanceInstallerDialog(pack, true);
              }
            }
          }
        });
    this.supportButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Utils.openBrowser(pack.getSupportURL());
          }
        });
    this.websiteButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Utils.openBrowser(pack.getWebsiteURL());
          }
        });

    this.modsButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            new ViewModsDialog(pack).setVisible(true);
          }
        });
  }

  @Override
  public void onRelocalization() {
    this.newInstanceButton.setText(Language.INSTANCE.localize("common.newinstance"));
    this.createServerButton.setText(Language.INSTANCE.localize("common.createserver"));
    this.supportButton.setText(Language.INSTANCE.localize("common.support"));
    this.websiteButton.setText(Language.INSTANCE.localize("common.website"));
    this.modsButton.setText(Language.INSTANCE.localize("pack.viewmods"));
  }
}
Ejemplo n.º 10
0
 @Override
 public String getTitle() {
   return Language.INSTANCE.localize("tabs.settings");
 }
Ejemplo n.º 11
0
  public LoggingSettingsTab() {
    RelocalizationManager.addListener(this);
    // Forge Logging Level
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.insets = LABEL_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    forgeLoggingLevelLabel =
        new JLabelWithHover(
            Language.INSTANCE.localize("settings.forgelogginglevel") + ":",
            HELP_ICON,
            "<html>"
                + Language.INSTANCE.localizeWithReplace(
                    "settings.forgelogginglevelhelp", "<br/><br/>")
                + "</html>");
    add(forgeLoggingLevelLabel, gbc);

    gbc.gridx++;
    gbc.insets = FIELD_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    forgeLoggingLevel = new JComboBox<String>();
    forgeLoggingLevel.addItem("SEVERE");
    forgeLoggingLevel.addItem("WARNING");
    forgeLoggingLevel.addItem("INFO");
    forgeLoggingLevel.addItem("CONFIG");
    forgeLoggingLevel.addItem("FINE");
    forgeLoggingLevel.addItem("FINER");
    forgeLoggingLevel.addItem("FINEST");
    forgeLoggingLevel.setSelectedItem(App.settings.getForgeLoggingLevel());
    add(forgeLoggingLevel, gbc);

    // Days of logs to keep

    gbc.gridx = 0;
    gbc.gridy++;
    gbc.insets = LABEL_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    daysOfLogsToKeepLabel =
        new JLabelWithHover(
            Language.INSTANCE.localize("settings.daysoflogstokeep") + ":",
            HELP_ICON,
            Language.INSTANCE.localize("settings.daysoflogstokeephelp"));
    add(daysOfLogsToKeepLabel, gbc);

    daysOfLogsToKeepModel = new SpinnerNumberModel(App.settings.getDaysOfLogsToKeep(), 1, 30, 1);

    gbc.gridx++;
    gbc.insets = FIELD_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    daysOfLogsToKeep = new JSpinner(daysOfLogsToKeepModel);
    daysOfLogsToKeep.setValue(App.settings.getDaysOfLogsToKeep());
    add(daysOfLogsToKeep, gbc);

    // Enable Leaderboards

    gbc.gridx = 0;
    gbc.gridy++;
    gbc.insets = LABEL_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    enableLeaderboardsLabel =
        new JLabelWithHover(
            Language.INSTANCE.localize("settings.leaderboards") + "?",
            HELP_ICON,
            Language.INSTANCE.localize("settings.leaderboardshelp"));
    add(enableLeaderboardsLabel, gbc);

    gbc.gridx++;
    gbc.insets = FIELD_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    enableLeaderboards = new JCheckBox();
    if (App.settings.enableLeaderboards()) {
      enableLeaderboards.setSelected(true);
    }
    if (!App.settings.enableLogs()) {
      enableLeaderboards.setEnabled(false);
    }
    add(enableLeaderboards, gbc);

    // Enable Logging

    gbc.gridx = 0;
    gbc.gridy++;
    gbc.insets = LABEL_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    enableLoggingLabel =
        new JLabelWithHover(
            Language.INSTANCE.localize("settings.logging") + "?",
            HELP_ICON,
            "<html>"
                + Language.INSTANCE.localizeWithReplace(
                    "settings.logginghelp", "<br/>" + "</html>"));
    add(enableLoggingLabel, gbc);

    gbc.gridx++;
    gbc.insets = FIELD_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    enableLogs = new JCheckBox();
    enableLogs.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!enableLogs.isSelected()) {
              enableOpenEyeReporting.setSelected(false);
              enableOpenEyeReporting.setEnabled(false);
              enableLeaderboards.setSelected(false);
              enableLeaderboards.setEnabled(false);
            } else {
              enableOpenEyeReporting.setSelected(true);
              enableOpenEyeReporting.setEnabled(true);
              enableLeaderboards.setSelected(true);
              enableLeaderboards.setEnabled(true);
            }
          }
        });
    if (App.settings.enableLogs()) {
      enableLogs.setSelected(true);
    }
    add(enableLogs, gbc);

    // Enable OpenEye Reporting

    gbc.gridx = 0;
    gbc.gridy++;
    gbc.insets = LABEL_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
    enableOpenEyeReportingLabel =
        new JLabelWithHover(
            Language.INSTANCE.localize("settings.openeye") + "?",
            HELP_ICON,
            "<html>"
                + Utils.splitMultilinedString(
                    Language.INSTANCE.localize("settings" + "" + ".openeyehelp"), 80, "<br/>")
                + "</html>");
    add(enableOpenEyeReportingLabel, gbc);

    gbc.gridx++;
    gbc.insets = FIELD_INSETS;
    gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    enableOpenEyeReporting = new JCheckBox();
    if (!App.settings.enableLogs()) {
      enableOpenEyeReporting.setEnabled(false);
    }
    if (App.settings.enableOpenEyeReporting()) {
      enableOpenEyeReporting.setSelected(true);
    }
    add(enableOpenEyeReporting, gbc);
  }
Ejemplo n.º 12
0
 @Override
 public String getTitle() {
   return Language.INSTANCE.localize("settings.loggingtab");
 }