コード例 #1
0
ファイル: GalaxyViewer.java プロジェクト: runholen/stars
  public GalaxyViewer(Settings settings, boolean animatorFrame) throws Exception {
    super("Stars GalaxyViewer");
    this.settings = settings;
    this.animatorFrame = animatorFrame;
    if (settings.gameName.equals("")) throw new Exception("GameName not defined in settings.");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    File dir = new File(settings.directory);
    File map = new File(dir, settings.getGameName() + ".MAP");
    if (map.exists() == false) {
      File f = new File(dir.getParentFile(), settings.getGameName() + ".MAP");
      if (f.exists()) map = f;
      else {
        String error = "Could not find " + map.getAbsolutePath() + "\n";
        error += "Export this file from Stars! (Only needs to be done one time pr game)";
        throw new Exception(error);
      }
    }
    Vector<File> mFiles = new Vector<File>();
    Vector<File> hFiles = new Vector<File>();
    for (File f : dir.listFiles()) {
      if (f.getName().toUpperCase().endsWith("MAP")) continue;
      if (f.getName().toUpperCase().endsWith("HST")) continue;
      if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".M")) mFiles.addElement(f);
      else if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".H"))
        hFiles.addElement(f);
    }
    if (mFiles.size() == 0) throw new Exception("No M-files found matching game name.");
    if (hFiles.size() == 0) throw new Exception("No H-files found matching game name.");
    parseMapFile(map);
    Vector<File> files = new Vector<File>();
    files.addAll(mFiles);
    files.addAll(hFiles);
    p = new Parser(files);
    calculateColors();

    // UI:
    JPanel cp = (JPanel) getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(universe, BorderLayout.CENTER);
    JPanel south = createPanel(0, hw, new JLabel("Search: "), search, names, zoom, colorize);
    search.setPreferredSize(new Dimension(100, -1));
    cp.add(south, BorderLayout.SOUTH);
    hw.addActionListener(this);
    names.addActionListener(this);
    zoom.addChangeListener(this);
    search.addKeyListener(this);
    colorize.addActionListener(this);
    setSize(800, 600);
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screen.width - getWidth()) / 2, (screen.height - getHeight()) / 2);
    setVisible(animatorFrame == false);
    if (animatorFrame) names.setSelected(false);
  }
コード例 #2
0
ファイル: GalaxyViewer.java プロジェクト: runholen/stars
    public static Settings init() throws Exception {
      File f = new File("galaxyviewer.ini");
      if (f.getAbsoluteFile().getParentFile().getName().equals("bin"))
        f = new File("..", "galaxyviewer.ini");
      Settings settings;
      if (f.exists()) {
        settings = new Settings();
        BufferedReader in = new BufferedReader(new FileReader(f));
        while (true) {
          String s = in.readLine();
          if (s == null) break;
          if (s.contains("=") == false) continue;
          String[] el = s.split("=", -1);
          if (el[0].equalsIgnoreCase("PlayerNr"))
            settings.playerNr = Integer.parseInt(el[1].trim()) - 1;
          if (el[0].equalsIgnoreCase("GameName")) settings.gameName = el[1].trim();
          if (el[0].equalsIgnoreCase("GameDir")) settings.directory = el[1].trim();
        }
        in.close();
      } else settings = new Settings();

      JTextField pNr = new JTextField("" + (settings.playerNr + 1));
      JTextField gName = new JTextField(settings.gameName);
      JTextField dir = new JTextField("" + settings.directory);

      JPanel p = new JPanel();
      p.setLayout(new GridLayout(3, 2));
      p.add(new JLabel("Player nr"));
      p.add(pNr);
      p.add(new JLabel("Game name"));
      p.add(gName);
      p.add(new JLabel("Game directory"));
      p.add(dir);
      gName.setToolTipText("Do not include file extensions");
      String[] el = {"Ok", "Cancel"};
      int ok =
          JOptionPane.showOptionDialog(
              null,
              p,
              "Choose settings",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              el,
              el[0]);
      if (ok != 0) System.exit(0);
      settings.playerNr = Integer.parseInt(pNr.getText().trim()) - 1;
      settings.directory = dir.getText().trim();
      settings.gameName = gName.getText().trim();
      BufferedWriter out = new BufferedWriter(new FileWriter(f));
      out.write("PlayerNr=" + (settings.playerNr + 1) + "\n");
      out.write("GameName=" + settings.gameName + "\n");
      out.write("GameDir=" + settings.directory + "\n");
      out.flush();
      out.close();
      return settings;
    }
コード例 #3
0
ファイル: GalaxyViewer.java プロジェクト: runholen/stars
 public static void main(String[] args) throws Exception {
   try {
     Settings settings = Settings.init();
     new GalaxyViewer(settings, false);
   } catch (Exception ex) {
     ex.printStackTrace();
     System.err.println(ex.toString());
     JOptionPane.showMessageDialog(null, ex.toString());
     System.exit(0);
   }
 }
コード例 #4
0
ファイル: SettingsWindow.java プロジェクト: Audio/chatar
  private SettingsWindow() {
    this.settings = Settings.getInstance();

    setAlwaysOnTop(true);
    setDefaultCloseOperation(HIDE_ON_CLOSE);
    setIconImage(new ImageIcon("img/settings-icon.png").getImage());
    setResizable(false);
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    setTitle("Osobní nastavení");

    createMainPanel();
    createTabs();
    reloadSettings();

    addWindowListener(this);
  }
コード例 #5
0
ファイル: Main.java プロジェクト: nagyistoce/jabberskype
  public static Logger initLogger() {
    Logger initlogger = Logger.getLogger(settings.getMainClass());
    initlogger.setLevel(settings.getLogLevel());
    boolean addconsole = false;
    if (settings.getLogToFile()) {
      try {
        Handler handler = new FileHandler(settings.getLogFile(), true);
        handler.setFormatter(new SimpleFormatter());
        initlogger.addHandler(handler);
      } catch (Exception e) {
        Logger().warning("Could not set logfile " + settings.getLogFile() + ": " + e.getMessage());
        addconsole = true;
      }
    }
    addconsole = settings.getLogToConsole() || addconsole;
    if (addconsole) {
      initlogger.addHandler(new ConsoleHandler());
    }
    // restore original log state
    logger.setLevel(templevel);
    templevel = null;

    return initlogger;
  }
コード例 #6
0
ファイル: Main.java プロジェクト: nagyistoce/jabberskype
 private static void saveUpdateSettings() {
   settings.setAutoUpdate(autoupdate.getCheckForUpdates());
   settings.setExperimental(autoupdate.getIncludeExperiemental());
   settings.setMinor(autoupdate.getIncludeMinor());
   settings.saveSettings();
 }
コード例 #7
0
ファイル: Main.java プロジェクト: nagyistoce/jabberskype
  public Main(
      String args[],
      String cmd_name,
      OSSpecific os_name,
      String settings_name,
      final String window_name,
      String logger_name,
      String about_name,
      String pref_name) {
    if (cmd == null) {
      cmd = new CommandLine(args);
    }

    if (!cmd.getHelp()) {
      if (os_name == null) {
        os = OSSpecific.getInstance();
      } else {
        os = (OSSpecific) newInstance(cmd_name);
      }
      if (settings_name == null) {
        settings = new Settings();
      } else {
        settings = (Settings) newInstance(settings_name);
      }
      settings.loadSettings();
      if (logger_name == null) {
        logger = initLogger();
      } else {
        logger = (Logger) newInstance(logger_name);
      }
      Logger().info("Custom logger now in use.");

      aboutclass = about_name;
      prefclass = pref_name;

      ActionListener update =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              saveUpdateSettings();
            }
          };
      ActionListener cancel =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              cancelUpdate(window_name);
            }
          };
      WindowListener closewindow =
          new WindowListener() {
            public void windowClosing(WindowEvent e) {
              cancelUpdate(window_name);
            }

            public void windowClosed(WindowEvent e) {}

            public void windowOpened(WindowEvent e) {}

            public void windowIconified(WindowEvent e) {}

            public void windowDeiconified(WindowEvent e) {}

            public void windowActivated(WindowEvent e) {}

            public void windowDeactivated(WindowEvent e) {}

            public void windowGainedFocus(WindowEvent e) {}

            public void windowLostFocus(WindowEvent e) {}

            public void windowStateChanged(WindowEvent e) {}
          };
      autoupdate = new AutoUpdate();
      autoupdate.checkForUpdates(
          settings.getTitle(),
          settings.getUpdateUrl(),
          settings.getVersion(),
          settings.getBuild(),
          settings.getAllowMinor(),
          settings.getAllowExperimental(),
          settings.getAllowAutoUpdate(),
          settings.getMinor(),
          settings.getExperimental(),
          settings.getAutoUpdate(),
          update,
          cancel,
          closewindow);
    }
  }
コード例 #8
0
  public PrefsGUI() {
    final Settings settings = Main.getSettings();
    settings.reloadSettings();

    memoryBash.setText(String.valueOf(settings.getMemBash()));
    maxConsoleLines.setText(String.valueOf(settings.getMaxConsoleLines()));
    sshEnabled.setSelected(settings.getSSHEnabled());
    sshUsername.setText(settings.getSSHUsername());
    sshPassword.setText(settings.getSSHPassword());
    sshHost.setText(settings.getSSHHost());
    stickyScrollbar.setSelected(settings.getStickyScrollBar());
    closeOnStop.setSelected(settings.getCloseWindowOnStop());
    askToExport.setSelected(settings.getAskExportLog());

    if (closeOnStop.isSelected()) {
      askToExport.setSelected(false);
      askToExport.setEnabled(false);
    } else {
      askToExport.setEnabled(true);
    }

    disableSSH();

    sshEnabled.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            sshUsername.setEnabled(sshEnabled.isSelected());
            sshHost.setEnabled(sshEnabled.isSelected());
            sshPassword.setEnabled(sshEnabled.isSelected());
            passwordLabel.setEnabled(sshEnabled.isSelected());
          }
        });

    closeOnStop.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (closeOnStop.isSelected()) {
              askToExport.setSelected(false);
              askToExport.setEnabled(false);
            } else {
              askToExport.setEnabled(true);
            }
          }
        });

    applyButton.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          @Override
          public void actionPerformed(ActionEvent e) {
            String errors = "";
            try {
              settings.setMemBash(Integer.parseInt(memoryBash.getText()));
            } catch (NumberFormatException nfe) {
              String message = "[Lava Control] ERROR: Text in memory bash settings is invalid.";
              System.out.println(message);
              errors = errors + "\n" + message;
            }

            try {
              settings.setMaxConsoleLines(Integer.parseInt(maxConsoleLines.getText()));
            } catch (NumberFormatException nfe) {
              String message =
                  "[Lava Control] ERROR: Text in max console lines settings is\ninvalid.";
              System.out.println(message);
              errors = errors + "\n" + message;
            }

            settings.setSSHEnabled(sshEnabled.isSelected());

            settings.setSSHUsername(sshUsername.getText());
            settings.setSSHPassword(sshPassword.getText());
            settings.setSSHHost(sshHost.getText());

            settings.setStickyScrollBar(stickyScrollbar.isSelected());
            settings.setCloseWindowOnStop(closeOnStop.isSelected());
            settings.setAskExportLog(askToExport.isSelected());

            settings.saveSettings();

            ImageIcon scaled =
                new ImageIcon(
                    Main.getIcon().getImage().getScaledInstance(96, 96, Image.SCALE_SMOOTH));
            if (!errors.equals("")) {
              JOptionPane.showMessageDialog(
                  Main.prefsFrame,
                  "<html><b>Error!</b> Couldn't save your settings:\n"
                      + errors
                      + "\n\nPlease fix these errors and then hit apply again\nto completely save all settings.",
                  "",
                  JOptionPane.ERROR_MESSAGE,
                  scaled);
            } else {
              JOptionPane.showMessageDialog(
                  Main.prefsFrame,
                  "<html><b>Success!</b></html> Settings were successfully applied.",
                  "",
                  JOptionPane.INFORMATION_MESSAGE,
                  scaled);
            }
          }
        });

    restoreDefaultsButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Main.getSettings().deleteSettings();

            memoryBash.setText(String.valueOf(settings.getMemBash()));
            maxConsoleLines.setText(String.valueOf(settings.getMaxConsoleLines()));
            sshEnabled.setSelected(settings.getSSHEnabled());
            sshUsername.setText(settings.getSSHUsername());
            sshPassword.setText(settings.getSSHPassword());
            sshHost.setText(settings.getSSHHost());
            stickyScrollbar.setSelected(settings.getStickyScrollBar());
            closeOnStop.setSelected(settings.getCloseWindowOnStop());
            askToExport.setSelected(settings.getAskExportLog());
          }
        });

    cancelButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Main.prefsFrame.setVisible(false);
          }
        });

    memoryBash.setBorder(new RoundedCornerBorder(6));
    sshUsername.setBorder(new RoundedCornerBorder(6));
    sshHost.setBorder(new RoundedCornerBorder(6));
    sshPassword.setBorder(new RoundedCornerBorder(6));
    maxConsoleLines.setBorder(new RoundedCornerBorder(6));
  }
コード例 #9
0
ファイル: SettingsWindow.java プロジェクト: Audio/chatar
  private void saveSettings() throws InvalidAttributeValueException {
    if (userForm.getNickname().isEmpty())
      throw new InvalidAttributeValueException("Přezdívka musí být vyplněna");
    else if (userForm.getUsername().isEmpty())
      throw new InvalidAttributeValueException("Uživatelské jméno musí být vyplněno");

    settings.setUserProperty("nickname", userForm.getNickname());
    settings.setUserProperty("altnickname", userForm.getAltNickname());
    settings.setUserProperty("username", userForm.getUsername());
    settings.setUserProperty("realname", userForm.getRealname());
    settings.setUserProperty("email", userForm.getEmail());

    settings.setEventEnabled("log-chat", eventsForm.isLogChatChecked());
    settings.setEventEnabled("rejoin-after-kick", eventsForm.isRejoinChecked());
    settings.setEventEnabled("clickable-links", eventsForm.isClickableLinksChecked());
    settings.setEventEnabled("ask-for-quit", eventsForm.isAskForQuitChecked());

    settings.setViewEnabled("display-topic", viewForm.isDisplayTopicChecked());
    settings.setViewEnabled("timestamp-enabled", viewForm.isTimestampEnabled());
    settings.setViewTimestampFormat(viewForm.getTimestampFormat());

    settings.setBlockedNicknames(blockedForm.getBlockedNicknames());

    settings.store();
  }
コード例 #10
0
ファイル: SettingsWindow.java プロジェクト: Audio/chatar
  private void reloadSettings() {
    userForm.setNickname(settings.getUserProperty("nickname"));
    userForm.setAltNickname(settings.getUserProperty("altnickname"));
    userForm.setUsername(settings.getUserProperty("username"));
    userForm.setRealname(settings.getUserProperty("realname"));
    userForm.setEmail(settings.getUserProperty("email"));

    eventsForm.setLogChatChecked(settings.isEventEnabled("log-chat"));
    eventsForm.setRejoinChecked(settings.isEventEnabled("rejoin-after-kick"));
    eventsForm.setClickableLinksChecked(settings.isEventEnabled("clickable-links"));
    eventsForm.setAskForQuitChecked(settings.isEventEnabled("ask-for-quit"));

    viewForm.setDisplayTopicChecked(settings.isViewEnabled("display-topic"));
    viewForm.setTimestampEnabled(settings.isViewEnabled("timestamp-enabled"));
    viewForm.setTimestampFormat(settings.getViewTimestampFormat());

    blockedForm.setBlockedNicknames(settings.getBlockedNicknames());
  }