Esempio n. 1
0
 public final void refresh() {
   RT = Runtime.getRuntime();
   txtMaxMem.setText(Long.toString(RT.maxMemory() / 1048576));
   txtTotalMem.setText(Long.toString(RT.totalMemory() / 1048576));
   this.txtUsedMem.setText(Long.toString((RT.totalMemory() - RT.freeMemory()) / 1048576));
   this.txtStorage.setText(
       new DecimalFormat(".000").format(WorkDir.getUsableSpace() / 1000000000F));
   this.lblFolder.setText(WorkDir.getAbsolutePath());
 }
Esempio n. 2
0
 public void updateValues() {
   String snipeAtCfg = JConfig.queryConfiguration("snipemilliseconds", "30000");
   String autoSubtractShipping = JConfig.queryConfiguration("snipe.subtract_shipping", "false");
   long snipeAt = Long.parseLong(snipeAtCfg);
   snipeTime.setText(Long.toString(snipeAt / 1000));
   autoSubtractShippingBox.setSelected(autoSubtractShipping.equals("true"));
 }
Esempio n. 3
0
 public void GetRecentPaperSize() {
   String id = Long.toString(robot_uid);
   paper_left = Double.parseDouble(prefs.get(id + "_paper_left", "0"));
   paper_right = Double.parseDouble(prefs.get(id + "_paper_right", "0"));
   paper_top = Double.parseDouble(prefs.get(id + "_paper_top", "0"));
   paper_bottom = Double.parseDouble(prefs.get(id + "_paper_bottom", "0"));
 }
Esempio n. 4
0
  public void apply() {
    long newSnipeAt = Long.parseLong(snipeTime.getText()) * 1000;

    //  Set the default snipe for everything to be whatever was typed in.
    JConfig.setConfiguration("snipemilliseconds", Long.toString(newSnipeAt));
    JConfig.setConfiguration(
        "snipe.subtract_shipping", autoSubtractShippingBox.isSelected() ? "true" : "false");
  }
Esempio n. 5
0
 // save paper limits
 public void SetRecentPaperSize() {
   String id = Long.toString(robot_uid);
   prefs.putDouble(id + "_paper_left", paper_left);
   prefs.putDouble(id + "_paper_right", paper_right);
   prefs.putDouble(id + "_paper_top", paper_top);
   prefs.putDouble(id + "_paper_bottom", paper_bottom);
   previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);
 }
Esempio n. 6
0
 void SaveConfig() {
   String id = Long.toString(robot_uid);
   prefs.put(id + "_limit_top", Double.toString(limit_top));
   prefs.put(id + "_limit_bottom", Double.toString(limit_bottom));
   prefs.put(id + "_limit_right", Double.toString(limit_right));
   prefs.put(id + "_limit_left", Double.toString(limit_left));
   prefs.put(id + "_m1invert", Boolean.toString(m1invert));
   prefs.put(id + "_m2invert", Boolean.toString(m2invert));
 }
Esempio n. 7
0
 void LoadConfig() {
   String id = Long.toString(robot_uid);
   limit_top = Double.valueOf(prefs.get(id + "_limit_top", "0"));
   limit_bottom = Double.valueOf(prefs.get(id + "_limit_bottom", "0"));
   limit_left = Double.valueOf(prefs.get(id + "_limit_left", "0"));
   limit_right = Double.valueOf(prefs.get(id + "_limit_right", "0"));
   m1invert = Boolean.parseBoolean(prefs.get(id + "_m1invert", "false"));
   m2invert = Boolean.parseBoolean(prefs.get(id + "_m2invert", "false"));
 }
Esempio n. 8
0
  /** Generates a formatted string representation of a large integer number. */
  private String formatLong(Long value) {
    if (value == null) return "-";

    if (value < 1024) {
      return value.toString();
    } else if (value < 1048576) {
      double k = ((double) value) / 1024.0;
      return String.format("%1$.1fK", k);
    } else if (value < 1073741824) {
      double m = ((double) value) / 1048576.0;
      return String.format("%1$.1fM", m);
    } else {
      double g = ((double) value) / 1073741824.0;
      return String.format("%1$.1fG", g);
    }
  }
Esempio n. 9
0
 public void genSeed(ActionEvent e) {
   long seed = 0;
   boolean redo = false;
   do {
     redo = false;
     String seedString =
         JOptionPane.showInputDialog(
             this, "Enter a number:", Long.toString(rand.nextLong(), 36)
             // "Random Seed", JOptionPane.QUESTION_MESSAGE
             );
     if (seedString == null) return;
     try {
       seed = Long.parseLong(seedString, 36);
     } catch (NumberFormatException ex) {
       JOptionPane.showMessageDialog(this, "Use only letters and numbers, max 12 characters.");
       redo = true;
     }
   } while (redo);
   genSeed(seed);
 }
Esempio n. 10
0
  public String get_status() {

    String jsontext = new String("");

    try {

      JSONObject obj = new JSONObject();

      obj.put("version", network.versionx);
      obj.put("status", "active");
      obj.put("program_status", network.programst);
      obj.put("listing_size", network.listing_size);
      obj.put("buffer_size", network.send_buffer_size);
      obj.put("mining_status", network.mining_status);
      obj.put("key", network.base58_id);
      obj.put("tor_active", Integer.toString(network.tor_active));
      obj.put("last_block", network.last_block_id);
      obj.put("last_block_timestamp", network.last_block_timestamp);
      obj.put("last_block_hash", network.last_block_idx);
      obj.put("difficulty", Long.toString(network.difficultyx));
      obj.put("last_mining_id", network.last_block_mining_idx);
      obj.put("prev_mining_id", network.prev_block_mining_idx);
      obj.put("blocktimesx", network.blocktimesx);
      obj.put("my_token_total", Integer.toString(network.database_listings_owner));
      obj.put("last_block_time", network.last_block_time);
      obj.put("database_listings_total", network.database_listings_total);
      obj.put("database_unconfirmed_total", network.database_unconfirmed_total);

      StringWriter out = new StringWriter();
      obj.writeJSONString(out);
      jsontext = out.toString();
      // System.out.println(jsonText);

    } catch (Exception e) {
      e.printStackTrace();
      statex = "0";
      jsontext = "error";
    }

    return jsontext;
  } // ***************************************
Esempio n. 11
0
  /**
   * Complete the handshake, load robot-specific configuration, update the menu, repaint the preview
   * with the limits.
   *
   * @return true if handshake succeeds.
   */
  public boolean ConfirmPort() {
    if (portConfirmed == true) return true;
    String hello = "HELLO WORLD! I AM DRAWBOT #";
    int found = line3.lastIndexOf(hello);
    if (found >= 0) {
      portConfirmed = true;

      // get the UID reported by the robot
      String[] lines = line3.substring(found + hello.length()).split("\\r?\\n");
      if (lines.length > 0) {
        try {
          robot_uid = Long.parseLong(lines[0]);
        } catch (NumberFormatException e) {
        }
      }

      // new robots have UID=0
      if (robot_uid == 0) GetNewRobotUID();

      mainframe.setTitle("Drawbot #" + Long.toString(robot_uid) + " connected");

      // load machine specific config
      GetRecentPaperSize();
      LoadConfig();
      if (limit_top == 0 && limit_bottom == 0 && limit_left == 0 && limit_right == 0) {
        UpdateConfig();
      }

      previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right);
      SendConfig();

      UpdateMenuBar();
      previewPane.setConnected(true);
    }
    return portConfirmed;
  }
 @SuppressWarnings("HardCodedStringLiteral")
 @NotNull
 public String getDescription() {
   final StringBuilder buf = StringBuilderSpinAllocator.alloc();
   try {
     buf.append("<html><body>");
     buf.append(getDisplayName());
     if (myInvalidMessage != null && !myInvalidMessage.isEmpty()) {
       buf.append("<br><font color='red'>");
       buf.append(DebuggerBundle.message("breakpoint.warning", myInvalidMessage));
       buf.append("</font>");
     }
     buf.append("&nbsp;<br>&nbsp;");
     buf.append(DebuggerBundle.message("breakpoint.property.name.suspend.policy")).append(" : ");
     if (DebuggerSettings.SUSPEND_NONE.equals(getSuspendPolicy()) || !isSuspend()) {
       buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.none"));
     } else if (DebuggerSettings.SUSPEND_ALL.equals(getSuspendPolicy())) {
       buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.all"));
     } else if (DebuggerSettings.SUSPEND_THREAD.equals(getSuspendPolicy())) {
       buf.append(DebuggerBundle.message("breakpoint.properties.panel.option.suspend.thread"));
     }
     buf.append("&nbsp;<br>&nbsp;");
     buf.append(DebuggerBundle.message("breakpoint.property.name.log.message")).append(": ");
     buf.append(isLogEnabled() ? CommonBundle.getYesButtonText() : CommonBundle.getNoButtonText());
     if (isLogExpressionEnabled()) {
       buf.append("&nbsp;<br>&nbsp;");
       buf.append(DebuggerBundle.message("breakpoint.property.name.log.expression")).append(": ");
       buf.append(XmlStringUtil.escapeString(getLogMessage().getText()));
     }
     if (isConditionEnabled()
         && getCondition() != null
         && getCondition().getText() != null
         && !getCondition().getText().isEmpty()) {
       buf.append("&nbsp;<br>&nbsp;");
       buf.append(DebuggerBundle.message("breakpoint.property.name.condition")).append(": ");
       buf.append(XmlStringUtil.escapeString(getCondition().getText()));
     }
     if (isCountFilterEnabled()) {
       buf.append("&nbsp;<br>&nbsp;");
       buf.append(DebuggerBundle.message("breakpoint.property.name.pass.count")).append(": ");
       buf.append(getCountFilter());
     }
     if (isClassFiltersEnabled()) {
       buf.append("&nbsp;<br>&nbsp;");
       buf.append(DebuggerBundle.message("breakpoint.property.name.class.filters")).append(": ");
       ClassFilter[] classFilters = getClassFilters();
       for (ClassFilter classFilter : classFilters) {
         buf.append(classFilter.getPattern()).append(" ");
       }
     }
     if (isInstanceFiltersEnabled()) {
       buf.append("&nbsp;<br>&nbsp;");
       buf.append(DebuggerBundle.message("breakpoint.property.name.instance.filters"));
       InstanceFilter[] instanceFilters = getInstanceFilters();
       for (InstanceFilter instanceFilter : instanceFilters) {
         buf.append(Long.toString(instanceFilter.getId())).append(" ");
       }
     }
     buf.append("</body></html>");
     return buf.toString();
   } finally {
     StringBuilderSpinAllocator.dispose(buf);
   }
 }
  public void reset() {
    EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    UISettings uiSettings = UISettings.getInstance();
    VcsApplicationSettings vcsSettings = VcsApplicationSettings.getInstance();

    // Display

    myCbSmoothScrolling.setSelected(editorSettings.isSmoothScrolling());

    // Brace highlighting

    myCbHighlightBraces.setSelected(codeInsightSettings.HIGHLIGHT_BRACES);
    myCbHighlightScope.setSelected(codeInsightSettings.HIGHLIGHT_SCOPE);
    myCbHighlightIdentifierUnderCaret.setSelected(
        codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET);

    // Virtual space

    myCbUseSoftWrapsAtEditor.setSelected(
        editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR));
    myCbUseCustomSoftWrapIndent.setSelected(editorSettings.isUseCustomSoftWrapIndent());
    myCustomSoftWrapIndent.setText(Integer.toString(editorSettings.getCustomSoftWrapIndent()));
    myCbShowSoftWrapsOnlyOnCaretLine.setSelected(!editorSettings.isAllSoftWrapsShown());
    updateSoftWrapSettingsRepresentation();

    myCbVirtualSpace.setSelected(editorSettings.isVirtualSpace());
    myCbCaretInsideTabs.setSelected(editorSettings.isCaretInsideTabs());
    myCbVirtualPageAtBottom.setSelected(editorSettings.isAdditionalPageAtBottom());

    // Limits
    myClipboardContentLimitTextField.setText(Integer.toString(uiSettings.MAX_CLIPBOARD_CONTENTS));

    // Strip trailing spaces on save

    String stripTrailingSpaces = editorSettings.getStripTrailingSpaces();
    if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE.equals(stripTrailingSpaces)) {
      myStripTrailingSpacesCombo.setSelectedItem(STRIP_NONE);
    } else if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED.equals(
        stripTrailingSpaces)) {
      myStripTrailingSpacesCombo.setSelectedItem(STRIP_CHANGED);
    } else if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE.equals(
        stripTrailingSpaces)) {
      myStripTrailingSpacesCombo.setSelectedItem(STRIP_ALL);
    }
    explainTrailingSpaces(stripTrailingSpaces);

    myCbEnsureBlankLineBeforeCheckBox.setSelected(editorSettings.isEnsureNewLineAtEOF());
    myCbShowQuickDocOnMouseMove.setSelected(editorSettings.isShowQuickDocOnMouseOverElement());
    myQuickDocDelayTextField.setText(
        Long.toString(editorSettings.getQuickDocOnMouseOverElementDelayMillis()));
    myQuickDocDelayTextField.setEnabled(editorSettings.isShowQuickDocOnMouseOverElement());
    myQuickDocDelayLabel.setEnabled(editorSettings.isShowQuickDocOnMouseOverElement());

    // Advanced mouse
    myCbEnableDnD.setSelected(editorSettings.isDndEnabled());
    myCbEnableWheelFontChange.setSelected(editorSettings.isWheelFontChangeEnabled());
    myCbHonorCamelHumpsWhenSelectingByClicking.setSelected(
        editorSettings.isMouseClickSelectionHonorsCamelWords());

    myRbPreferMovingCaret.setSelected(editorSettings.isRefrainFromScrolling());
    myRbPreferScrolling.setSelected(!editorSettings.isRefrainFromScrolling());

    myRecentFilesLimitField.setText(Integer.toString(uiSettings.RECENT_FILES_LIMIT));

    myCbRenameLocalVariablesInplace.setSelected(editorSettings.isVariableInplaceRenameEnabled());
    myPreselectCheckBox.setSelected(editorSettings.isPreselectRename());
    myShowInlineDialogForCheckBox.setSelected(editorSettings.isShowInlineLocalDialog());

    myShowNotificationAfterReformatCodeCheckBox.setSelected(
        editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION);
    myShowNotificationAfterOptimizeImportsCheckBox.setSelected(
        editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION);

    myShowLSTInGutterCheckBox.setSelected(vcsSettings.SHOW_LST_GUTTER_MARKERS);
    myShowWhitespacesModificationsInLSTGutterCheckBox.setSelected(
        vcsSettings.SHOW_WHITESPACES_IN_LST);
    myShowWhitespacesModificationsInLSTGutterCheckBox.setEnabled(
        myShowLSTInGutterCheckBox.isSelected());

    myErrorHighlightingPanel.reset();

    RichCopySettings settings = RichCopySettings.getInstance();
    myCbEnableRichCopyByDefault.setSelected(settings.isEnabled());
    myRichCopyColorSchemeComboBox.removeAllItems();
    EditorColorsScheme[] schemes = EditorColorsManager.getInstance().getAllSchemes();
    myRichCopyColorSchemeComboBox.addItem(RichCopySettings.ACTIVE_GLOBAL_SCHEME_MARKER);
    for (EditorColorsScheme scheme : schemes) {
      myRichCopyColorSchemeComboBox.addItem(scheme.getName());
    }
    String toSelect = settings.getSchemeName();
    if (!StringUtil.isEmpty(toSelect)) {
      myRichCopyColorSchemeComboBox.setSelectedItem(toSelect);
    }
  }
Esempio n. 14
0
  /**
   * applyMove applies the given move to the board. First, the new piece is added to the startPos
   * Then the pieces are moved in the direction of the move, and finally pieces that need to be
   * removed are removed from the board
   *
   * @param move the move that is applied
   */
  public void applyMove(Move move) {
    // An invalidMoveException can be thrown if applying that move would mean to place pieces on an
    // illegal position.
    try {
      moveCounter++;
      // If there's already a winner, the move won't be applied
      if (gipfBoardState.players.winner() != null) return;

      /*
       * Prepare for creating a new child GipfBoardState. The pieceMap and playersInGame objects of the current
       * gipfBoardState are unmodifiable, so we have to create modifiable copies.
       * If the move turns out to be legal, a new child GipfBoardState will be generated, based on the modified
       * copies of the PieceMap and the PlayersInGame objects.
       */
      // The piece map returned by getPieceMap() is unmodifiable, so it has to be converted to a new
      // (hash) map
      // the newPieceMap can be modified, after that a new GipfBoardState can be generated.
      Map<Position, Piece> newPieceMap = new HashMap<>(gipfBoardState.getPieceMap());

      // The same is true for the PlayersInGame object. It is unmodifiable, so a new instance has to
      // be created
      // for the new board state.
      PlayersInGame newPlayers = new PlayersInGame(gipfBoardState.players);

      // If the current player has enough pieces left in the reserve to perform the move (1 for a
      // normal move, 2 for
      // a Gipf move.)
      if (newPlayers.current().reserve >= move.addedPiece.getPieceValue()) {
        /*
         * Move the piece
         */
        // Each move adds a new piece to the board
        newPieceMap.put(move.startPos, move.addedPiece);

        // Move it into the direction determined by the move
        movePiecesTowards(newPieceMap, move.startPos, move.direction);

        /*
         * Remove the lines and pieces that can be removed from the board
         */
        // Create an object that keeps track of which piece is taken by whom. An EnumMap instead of
        // a HashMap is
        // used, because all keys correspond with values from the PieceColor enum.
        Map<PieceColor, Set<Line.Segment>> linesTakenBy = new EnumMap<>(PieceColor.class);
        linesTakenBy.put(WHITE, new HashSet<>());
        linesTakenBy.put(BLACK, new HashSet<>());

        // Create an object that keeps track of which individual pieces are taken by whom.
        // A HashMap is used because it can handle null keys, in contrast with EnumMaps.
        Map<PieceColor, Set<Position>> piecesBackTo = new HashMap<>();
        piecesBackTo.put(WHITE, new HashSet<>());
        piecesBackTo.put(BLACK, new HashSet<>());
        piecesBackTo.put(null, new HashSet<>()); // Used for pieces that are removed from the board

        /*
         * Distinguish between complete and incomplete moves.
         *  - Complete moves:
         *    are generated by the getAllowedMoves() method and contain all information about that move,
         *    including a choice for which lines or gipf pieces will be removed.
         *  - Incomplete moves:
         *    are performed by human players. These moves don't contain the information of which pieces are
         *    removed. This means that there may be user interaction required if the player must choose between
         *    multiple lines or gipf pieces that can be removed.
         */
        if (move.isCompleteMove) {
          // Complete moves are the easiest to handle, the positions of pieces that are removed are
          // already
          // determined.
          // This means that we only have to read the values for the pieces that are returned to
          // each player
          // into the piecesBackTo map.
          piecesBackTo.get(WHITE).addAll(move.piecesToWhite);
          piecesBackTo.get(BLACK).addAll(move.piecesToBlack);
          piecesBackTo.get(null).addAll(move.piecesRemoved);
        } else {
          // Now we have incomplete moves. This means that we have to remove the pieces that are
          // required to
          // be removed. If the player must choose between different pieces / lines, the removeLines
          // method
          // will ask the player to make a choice.

          // Get the lines that are taken by the current player (retrieved from linesTakenBy) and
          // store them
          // in the piecesBackTo map. The opponent's pieces are stored in piecesBackTo.get(null),
          // because they
          // are removed from the board.
          removeLines(newPieceMap, newPlayers.current().pieceColor, linesTakenBy, piecesBackTo);
          // linesTakenBy.get(newPlayers.current().pieceColor).addAll(getRemovableLineSegments(newPieceMap, newPlayers.current().pieceColor));

          // Get the lines that are taken by the opponent (retrieved from the linesTakenBy map), and
          // store
          // them in the piecesBackTo map. The current player's pieces are stored in
          // piecesBackTO.get(null),
          // because they are removed from the board.
          PieceColor opponentColor = newPlayers.current().pieceColor == WHITE ? BLACK : WHITE;
          removeLines(newPieceMap, opponentColor, linesTakenBy, piecesBackTo);
          // linesTakenBy.get(opponentColor).addAll(getRemovableLineSegments(newPieceMap,
          // opponentColor));
        }
        gameLogger.log(move.toString());

        // Each value in the piecesBackTo map is a set, and each element (position) of the sets of
        // all values
        // is removed from the pieceMap.
        // The number of the returned pieces for each player are added to their reserve.
        for (Map.Entry<PieceColor, Set<Position>> removedPieces : piecesBackTo.entrySet()) {
          if (removedPieces.getKey() != null) {
            // Calculate the sum for the pieces returned to this player. Normal pieces have a value
            // of 1,
            // gipf pieces a value of 2 determined in Piece.getPieceValue().
            int returnedPiecesSum =
                removedPieces
                    .getValue()
                    .stream()
                    .mapToInt(
                        position -> {
                          if (newPieceMap.containsKey(position))
                            return newPieceMap.get(position).getPieceValue();
                          else return 1;
                        })
                    .sum();

            newPlayers.get(removedPieces.getKey()).reserve += returnedPiecesSum;
            gameLogger.log(removedPieces.getKey() + " retrieved " + returnedPiecesSum + " pieces");
          }

          // The pieces are not earlier removed from the board, because the returnedPiecesSum
          // variable can
          // only be set if all the pieces are still on the board.
          removePiecesFromPieceMap(newPieceMap, removedPieces.getValue());
        }

        /*
         * Set the properties for the player, based on the move
         */
        if (move.addedPiece.getPieceType() == PieceType.GIPF) {
          newPlayers.current().hasPlacedGipfPieces = true;
        }
        if (!newPlayers.current().isPlacingGipfPieces) {
          newPlayers.current().hasPlacedNormalPieces = true;
        }

        // Update the current player's reserve for the last added piece
        newPlayers.current().reserve -= move.addedPiece.getPieceValue();

        /*
         * Check whether it is game over
         */
        // If we create a new GipfBoardState based on the calculated properties, will there be a
        // game over situation?
        if (getGameOverState(new GipfBoardState(null, newPieceMap, newPlayers))) {
          // If the current player causes a game over situation, the other player (updateCurrent()),
          // will be
          // the winner of the game.
          newPlayers = newPlayers.updateCurrent().makeCurrentPlayerWinner();
          gameLogger.log("Game over! " + newPlayers.winner().pieceColor + " won!");

          if (moveCounter != 1) {
            if (SettingsSingleton.getInstance().showExperimentOutput) {
              String moveCountString = Integer.toString(moveCounter);
              String durationString =
                  Long.toString(Duration.between(gameStartInstant, Instant.now()).toMillis());
              String winnerString = newPlayers.winner().pieceColor.toString();
              String whiteAlgorithm = whitePlayer.getClass().getSimpleName();
              String blackAlgorithm = blackPlayer.getClass().getSimpleName();

              ExperimentLogger.get()
                  .log(
                      whiteAlgorithm
                          + "; "
                          + blackAlgorithm
                          + "; "
                          + moveCountString
                          + "; "
                          + durationString
                          + "; "
                          + winnerString);
            }
          }
        }

        // We don't need to update the current player if the game has ended
        if (newPlayers.winner() == null) {
          newPlayers = newPlayers.updateCurrent();
        }

        // Create a new gipfBoardState, based on the calculated PieceMap and PlayersInGame objects.
        GipfBoardState newGipfBoardState =
            new GipfBoardState(gipfBoardState, newPieceMap, newPlayers);
        boardHistory.add(gipfBoardState);
        this.gipfBoardState = newGipfBoardState;
      } else {
        gameLogger.log("No pieces left");
      }

      // Recalculate the properties of this gipfBoardState
      gipfBoardState.boardStateProperties.updateBoardState();

    } catch (InvalidMoveException e) {
      System.out.println("Move not applied");
    }
  }
 public HaskellToolsConfigurable(@NotNull Project project) {
   this.propertiesComponent = PropertiesComponent.getInstance(project);
   properties =
       Arrays.asList(
           new Tool(
               project,
               "stylish-haskell",
               ToolKey.STYLISH_HASKELL_KEY,
               stylishPath,
               stylishFlags,
               stylishAutoFind,
               stylishVersion),
           new Tool(
               project,
               "hlint",
               ToolKey.HLINT_KEY,
               hlintPath,
               hlintFlags,
               hlintAutoFind,
               hlintVersion),
           new Tool(
               project,
               "ghc-mod",
               ToolKey.GHC_MOD_KEY,
               ghcModPath,
               ghcModFlags,
               ghcModAutoFind,
               ghcModVersion,
               "version"),
           new Tool(
               project,
               "ghc-modi",
               ToolKey.GHC_MODI_KEY,
               ghcModiPath,
               ghcModiFlags,
               ghcModiAutoFind,
               ghcModiVersion,
               "version",
               SettingsChangeNotifier.GHC_MODI_TOPIC),
           new PropertyField(
               ToolKey.GHC_MODI_TIMEOUT_KEY,
               ghcModiTimeout,
               Long.toString(ToolKey.getGhcModiTimeout(project))),
           new Tool(
               project,
               "hindent",
               ToolKey.HINDENT_KEY,
               hindentPath,
               hindentFlags,
               hindentAutoFind,
               hindentVersion));
   // Validate that we can only enter numbers in the timeout field.
   final Color originalBackground = ghcModiTimeout.getBackground();
   ghcModiTimeout.setInputVerifier(
       new InputVerifier() {
         @Override
         public boolean verify(JComponent input) {
           JTextAccessorField field = (JTextAccessorField) input;
           try {
             //noinspection ResultOfMethodCallIgnored
             Long.parseLong(field.getText());
           } catch (NumberFormatException e) {
             field.setBackground(JBColor.RED);
             return false;
           }
           field.setBackground(originalBackground);
           return true;
         }
       });
 }
Esempio n. 16
0
 public void genSeed(long seed) {
   System.out.println(Long.toString(seed, 36));
   showPuzzle(new AngryPuzzle(wordList, seed));
 }
Esempio n. 17
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   g.drawString(Long.toString(heure), getWidth() / 2 - taille, getHeight() / 2);
 }
Esempio n. 18
0
    public void
        run() { // ************************************************************************************

      String jsonText2 = new String("");

      JSONObject obj_out = new JSONObject();

      ServerSocket welcomeSocket;

      while (true) {

        try { // *********************************************************

          welcomeSocket = new ServerSocket(network.api_port, 0, InetAddress.getByName("localhost"));
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient =
              new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
          clientSentence = inFromClient.readLine();

          JSONParser parser = new JSONParser();

          try { // *********************************************************

            statex = "0";
            responsex = "e00";
            jsonText = "";

            if (!clientSentence.contains("")) {
              throw new EmptyStackException();
            }
            Object obj = parser.parse(clientSentence);

            jsonObject = (JSONObject) obj;

            String request = (String) jsonObject.get("request");

            String item_id = new String("");
            String item_array = new String("");
            String old_key = new String("");
            String node = new String("");
            try {
              item_id = (String) jsonObject.get("item_id").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_id...");
            }
            try {
              item_array = (String) jsonObject.get("item_array").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_array...");
            }
            try {
              old_key = (String) jsonObject.get("key").toString();
            } catch (Exception e) {
              System.out.println("extra info no key...");
            }
            try {
              node = (String) jsonObject.get("node").toString();
            } catch (Exception e) {
              System.out.println("extra info no node...");
            }

            while (network.database_in_use == 1 && !request.equals("status")) {

              System.out.println("Database in use...");
              try {
                Thread.sleep(1000);
              } catch (InterruptedException e) {
              }
            } // **************************************************************

            if (request.equals("status")) {
              statex = "1";
              responsex = get_status();
            } // ***************************
            else if (request.equals("get_version")) {
              statex = "1";
              responsex = network.versionx;
            } //
            else if (request.equals("get_tor_active")) {
              statex = "1";
              responsex = Integer.toString(network.tor_active);
            } //
            else if (request.equals("get_last_block")) {
              statex = "1";
              responsex = network.last_block_id;
            } //
            else if (request.equals("get_last_block_timestamp")) {
              statex = "1";
              responsex = network.last_block_timestamp;
            } //
            else if (request.equals("get_last_block_hash")) {
              statex = "1";
              responsex = network.last_block_idx;
            } //
            else if (request.equals("get_difficulty")) {
              statex = "1";
              responsex = Long.toString(network.difficultyx);
            } //
            else if (request.equals("get_last_mining_id")) {
              statex = "1";
              responsex = network.last_block_mining_idx;
            } //
            else if (request.equals("get_prev_mining_id")) {
              statex = "1";
              responsex = network.prev_block_mining_idx;
            } //
            else if (request.equals("get_last_unconfirmed_id")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_token_total")) {
              statex = "1";
              responsex = Integer.toString(network.database_listings_owner);
            } //
            else if (request.equals("get_my_id_list")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_ids_limit")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_token")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_settings")) {
              statex = "1";
              responsex = get_settings_array();
            } //
            else if (request.equals("get_mining_info")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_new_keys")) {
              statex = "1";
              responsex = build_keysx();
            } //
            else if (request.equals("delete_node")) {
              statex = "1";
              responsex = delete_node(node);
            } //
            else if (request.equals("delete_all_nodes")) {
              statex = "1";
              responsex = delete_all_nodes();
            } //
            else if (request.equals("set_new_node")) {
              statex = "1";
              responsex = set_new_node(node);
            } //
            else if (request.equals("set_old_key")) {
              statex = "1";
              responsex = set_old_key(old_key);
            } //
            else if (request.equals("set_new_block")) {
              statex = "1";
              responsex = set_new_block(item_array);
            } //
            else if (request.equals("set_edit_block")) {
              statex = "1";
              update_state = "set_edit_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("set_transfer_block")) {
              statex = "1";
              update_state = "set_transfer_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("system_restart")) {
              statex = "1";
              responsex = "restarting";
              toolkit = Toolkit.getDefaultToolkit();
              xtimerx = new Timer();
              xtimerx.schedule(new RemindTask_restart(), 0);
            } //
            else if (request.equals("system_exit")) {
              statex = "1";
              System.exit(0);
            } //
            else {
              statex = "0";
              responsex = "e01 UnknownRequestException";
            }

          } // try
          catch (ParseException e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e02 ParseException";
          } catch (Exception e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e03 Exception";
          }

          JSONObject obj = new JSONObject();
          obj.put("response", statex);
          try {
            obj.put("message", responsex);
          } catch (Exception e) {
            e.printStackTrace();
          }

          StringWriter outs = new StringWriter();
          obj.writeJSONString(outs);
          jsonText = outs.toString();
          System.out.println("SEND RESPONSE " + responsex);

          outToClient.writeBytes(jsonText + '\n');
          welcomeSocket.close();

        } catch (Exception e) {
          e.printStackTrace();
          System.out.println("Server ERROR x3");
        }
      } // **********while
    } // runx***************************************************************************************************
Esempio n. 19
0
  public String update_token(String req_array) {

    System.out.println("Update");

    String jsonarry = new String("");

    try {

      JSONParser parser = new JSONParser();
      Object obj = parser.parse(req_array);
      JSONObject jsonObject = (JSONObject) obj;

      String id = (String) jsonObject.get("id");
      String hash_id = (String) jsonObject.get("hash_id");
      String sig_id = (String) jsonObject.get("sig_id");
      String date_id = (String) jsonObject.get("date_id");
      String owner_id = (String) jsonObject.get("owner_id");
      String owner_rating = (String) jsonObject.get("owner_rating");
      String currency = (String) jsonObject.get("currency");
      String custom_template = (String) jsonObject.get("custom_template");
      String custom_1 = (String) jsonObject.get("custom_1");
      String custom_2 = (String) jsonObject.get("custom_2");
      String custom_3 = (String) jsonObject.get("custom_3");
      String item_errors = (String) jsonObject.get("item_errors");
      String item_date_listed = (String) jsonObject.get("item_date_listed");
      String item_date_listed_day = (String) jsonObject.get("item_date_listed_da");
      String item_date_listed_int = (String) jsonObject.get("item_date_listed_int");
      String item_hits = (String) jsonObject.get("item_hits");
      String item_confirm_code = (String) jsonObject.get("item_confirm_code");
      String item_confirmed = (String) jsonObject.get("item_confirmed");
      String item_cost = (String) jsonObject.get("item_cost");
      String item_description = (String) jsonObject.get("item_description");
      String item_id = (String) jsonObject.get("item_id");
      String item_price = (String) jsonObject.get("item_price");
      String item_weight = (String) jsonObject.get("item_weight");
      String item_listing_id = (String) jsonObject.get("item_listing_id");
      String item_notes = (String) jsonObject.get("item_notes");
      String item_package_d = (String) jsonObject.get("item_package_d");
      String item_package_l = (String) jsonObject.get("item_package_l");
      String item_package_w = (String) jsonObject.get("item_package_w");
      String item_part_number = (String) jsonObject.get("item_part_number");
      String item_title = (String) jsonObject.get("item_title");
      String item_title_url = (String) jsonObject.get("item_title");
      String item_type = (String) jsonObject.get("item_type");
      String item_search_1 = (String) jsonObject.get("item_search_1");
      String item_search_2 = (String) jsonObject.get("item_search_2");
      String item_search_3 = (String) jsonObject.get("item_search_3");
      String item_site_id = (String) jsonObject.get("item_site_id");
      String item_site_url = (String) jsonObject.get("item_site_url");
      String item_picture_1 = (String) jsonObject.get("item_picture_1");
      String item_total_on_hand = (String) jsonObject.get("item_total_on_hand");
      String sale_payment_address = (String) jsonObject.get("sale_payment_address");
      String sale_payment_type = (String) jsonObject.get("sale_payment_type");
      String sale_fees = (String) jsonObject.get("sale_fees");
      String sale_id = (String) jsonObject.get("sale_id");
      String sale_seller_id = (String) jsonObject.get("sale_seller_id");
      String sale_status = (String) jsonObject.get("sale_status");
      String sale_tax = (String) jsonObject.get("sale_tax");
      String sale_shipping_company = (String) jsonObject.get("sale_shipping_company");
      String sale_shipping_in = (String) jsonObject.get("sale_shipping_in");
      String sale_shipping_out = (String) jsonObject.get("sale_shipping_out");
      String sale_source_of_sale = (String) jsonObject.get("sale_source_of_sale");
      String sale_total_sale_amount = (String) jsonObject.get("sale_total_sale_amount");
      String sale_tracking_number = (String) jsonObject.get("sale_tracking_number");
      String sale_transaction_id = (String) jsonObject.get("sale_transaction_id");
      String sale_transaction_info = (String) jsonObject.get("sale_transaction_info");
      String seller_address_1 = (String) jsonObject.get("seller_address_1");
      String seller_address_2 = (String) jsonObject.get("seller_address_2");
      String seller_address_city = (String) jsonObject.get("seller_address_city");
      String seller_address_state = (String) jsonObject.get("seller_address_state");
      String seller_address_zip = (String) jsonObject.get("seller_address_zip");
      String seller_address_country = (String) jsonObject.get("seller_address_country");
      String seller_id = (String) jsonObject.get("seller_id");
      String seller_ip = (String) jsonObject.get("seller_ip");
      String seller_email = (String) jsonObject.get("seller_email");
      String seller_first_name = (String) jsonObject.get("seller_first_name");
      String seller_last_name = (String) jsonObject.get("seller_last_name");
      String seller_notes = (String) jsonObject.get("seller_notes");
      String seller_phone = (String) jsonObject.get("seller_phone");
      String seller_logo = (String) jsonObject.get("seller_logo");
      String seller_url = (String) jsonObject.get("seller_url");

      try {
        if (currency.length() < 1) {}
      } catch (Exception e) {
        currency = new String("1");
      }
      try {
        if (custom_template.length() < 1) {}
      } catch (Exception e) {
        custom_template = new String("2");
      }
      try {
        if (custom_1.length() < 1) {}
      } catch (Exception e) {
        custom_1 = new String("3");
      }
      try {
        if (custom_2.length() < 1) {}
      } catch (Exception e) {
        custom_2 = new String("4");
      }
      try {
        if (custom_3.length() < 1) {}
      } catch (Exception e) {
        custom_3 = new String("5");
      }
      try {
        if (item_errors.length() < 1) {}
      } catch (Exception e) {
        item_errors = new String("6");
      }
      try {
        if (item_date_listed.length() < 1) {}
      } catch (Exception e) {
        item_date_listed = new String("7");
      }
      try {
        if (item_date_listed_day.length() < 1) {}
      } catch (Exception e) {
        item_date_listed_day = new String("8");
      }
      try {
        if (item_date_listed_int.length() < 1) {}
      } catch (Exception e) {
        item_date_listed_int = new String("9");
      }
      try {
        if (item_hits.length() < 1) {}
      } catch (Exception e) {
        item_hits = new String("10");
      }
      try {
        if (item_confirm_code.length() < 1) {}
      } catch (Exception e) {
        item_confirm_code = new String("11");
      }
      try {
        if (item_confirmed.length() < 1) {}
      } catch (Exception e) {
        item_confirmed = new String("12");
      }
      try {
        if (item_cost.length() < 1) {}
      } catch (Exception e) {
        item_cost = new String("13");
      }
      try {
        if (item_description.length() < 1) {}
      } catch (Exception e) {
        item_description = new String("14");
      }
      try {
        if (item_id.length() < 1) {}
      } catch (Exception e) {
        item_id = new String("15");
      }
      try {
        if (item_price.length() < 1) {}
      } catch (Exception e) {
        item_price = new String("16");
      }
      try {
        if (item_weight.length() < 1) {}
      } catch (Exception e) {
        item_weight = new String("17");
      }
      try {
        if (item_notes.length() < 1) {}
      } catch (Exception e) {
        item_notes = new String("18");
      }
      try {
        if (item_package_d.length() < 1) {}
      } catch (Exception e) {
        item_package_d = new String("19");
      }
      try {
        if (item_package_l.length() < 1) {}
      } catch (Exception e) {
        item_package_l = new String("20");
      }
      try {
        if (item_package_w.length() < 1) {}
      } catch (Exception e) {
        item_package_w = new String("21");
      }
      try {
        if (item_part_number.length() < 1) {}
      } catch (Exception e) {
        item_part_number = new String("22");
      }
      try {
        if (item_title.length() < 1) {}
      } catch (Exception e) {
        item_title = new String("23");
      }
      try {
        if (item_title_url.length() < 1) {}
      } catch (Exception e) {
        item_title_url = new String("24");
      }
      try {
        if (item_type.length() < 1) {}
      } catch (Exception e) {
        item_type = new String("25");
      }
      try {
        if (item_search_1.length() < 1) {}
      } catch (Exception e) {
        item_search_1 = new String("26");
      }
      try {
        if (item_search_2.length() < 1) {}
      } catch (Exception e) {
        item_search_2 = new String("27");
      }
      try {
        if (item_search_3.length() < 1) {}
      } catch (Exception e) {
        item_search_3 = new String("28");
      }
      try {
        if (item_site_url.length() < 1) {}
      } catch (Exception e) {
        item_site_url = new String("29");
      }
      try {
        if (item_picture_1.length() < 1) {}
      } catch (Exception e) {
        item_picture_1 = new String("30");
      }
      try {
        if (item_total_on_hand.length() < 1) {}
      } catch (Exception e) {
        item_total_on_hand = new String("31");
      }

      String tokenx[] = new String[network.listing_size];

      if (Integer.parseInt(id) >= network.base_int
          && Integer.parseInt(id) <= (network.hard_token_limit + network.base_int)) {

        krypton_database_get_token2 getxt = new krypton_database_get_token2();
        tokenx = getxt.get_token(id);

        // update the noose
        tokenx[3] = Long.toString(System.currentTimeMillis());

        tokenx[4] = network.settingsx[5];

        tokenx[6] = currency;
        tokenx[7] = custom_template;
        tokenx[8] = custom_1;
        tokenx[9] = custom_2;
        tokenx[10] = custom_3;
        tokenx[11] = item_errors;
        tokenx[12] = item_date_listed;
        tokenx[13] = item_date_listed_day;
        tokenx[14] = item_date_listed_int;
        tokenx[15] = item_hits;
        tokenx[16] = item_confirm_code;
        tokenx[17] = item_confirmed;
        tokenx[18] = item_cost;
        tokenx[19] = item_description;
        tokenx[20] = item_id;
        tokenx[21] = item_price;
        tokenx[22] = item_weight;

        tokenx[24] = item_notes;
        tokenx[25] = item_package_d;
        tokenx[26] = item_package_l;
        tokenx[27] = item_package_w;
        tokenx[28] = item_part_number;
        tokenx[29] = item_title;
        tokenx[30] = item_title_url;
        tokenx[31] = item_type;
        tokenx[32] = item_search_1;
        tokenx[33] = item_search_2;
        tokenx[34] = item_search_3;

        tokenx[36] = item_site_url;
        tokenx[37] = item_picture_1;
        tokenx[38] = item_total_on_hand;

        // to help with search
        tokenx[30] = tokenx[29].toLowerCase();

        // base 58
        if (update_state.equals("set_edit_block")) {
          tokenx[60] = network.base58_id;
        } else if (update_state.equals("set_transfer_block")) {
          tokenx[60] = seller_id;
        }

        // seller info
        tokenx[63] = network.settingsx[11]; // name
        tokenx[64] = network.settingsx[12]; // last
        tokenx[54] = network.settingsx[13]; // address
        tokenx[55] = network.settingsx[14]; // address2
        tokenx[56] = network.settingsx[15]; // city
        tokenx[57] = network.settingsx[16]; // state
        tokenx[58] = network.settingsx[17]; // zip
        tokenx[59] = network.settingsx[18]; // country

        tokenx[39] = network.settingsx[19]; // btc
        tokenx[62] = network.settingsx[20]; // email
        tokenx[66] = network.settingsx[21]; // phone
        tokenx[68] = network.settingsx[22]; // website

        // sign

        try {

          String build_hash = new String("");

          build_hash = tokenx[0];
          for (int loop = 3; loop < tokenx.length; loop++) {

            build_hash = build_hash + tokenx[loop]; // save everything else
          } // *************************************************

          String hashx = new String(build_hash);
          byte[] sha256_1x = MessageDigest.getInstance("SHA-256").digest(hashx.getBytes());
          System.out.println(Base64.toBase64String(sha256_1x));

          tokenx[1] = Base64.toBase64String(sha256_1x);

          byte[] message = Base64.toBase64String(sha256_1x).getBytes("UTF8");

          byte[] clear = Base64.decode(network.settingsx[4]);
          PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(clear);
          KeyFactory fact = KeyFactory.getInstance("RSA");
          PrivateKey priv = fact.generatePrivate(keySpec);
          Arrays.fill(clear, (byte) 0);

          Signature sigx = Signature.getInstance("SHA1WithRSA"); // MD5WithRSA
          sigx.initSign(priv);
          sigx.update(message);
          byte[] signatureBytesx = sigx.sign();
          // System.out.println("Public: " + Base64.toBase64String(pub.getEncoded()));
          System.out.println("Singature: " + Base64.toBase64String(signatureBytesx));

          String signxx = Base64.toBase64String(signatureBytesx);

          tokenx[2] = signxx;

          byte[] keyxb3 = Base64.decode(tokenx[4]);

          X509EncodedKeySpec keySpecx3 = new X509EncodedKeySpec(keyxb3);
          KeyFactory factx3 = KeyFactory.getInstance("RSA");
          PublicKey pubx3 = factx3.generatePublic(keySpecx3);
          Arrays.fill(keyxb3, (byte) 0);

          Signature sigpk3 = Signature.getInstance("SHA1WithRSA"); // MD5WithRSA
          byte[] messagex3 = Base64.toBase64String(sha256_1x).getBytes("UTF8");

          byte[] signatureBytesx3 = Base64.decode(signxx);

          sigpk3.initVerify(pubx3);
          sigpk3.update(messagex3);

          boolean testsx = sigpk3.verify(signatureBytesx3);

          System.out.println("testsx " + testsx);

          if (testsx) {

            statex = "1";
            jsonarry = "Updated";

          } // ********
          else {

            statex = "0";
            jsonarry = "Update error. Information did not pass signature test.";
          } // **

          if (update_state.equals("set_edit_block")) {
            network.icon.displayMessage(
                "Krypton", "Token updated ID (" + tokenx[0] + ")", TrayIcon.MessageType.INFO);
          } else if (update_state.equals("set_transfer_block")) {
            network.icon.displayMessage(
                "Krypton", "Token transfer ID (" + tokenx[0] + ")", TrayIcon.MessageType.INFO);
          }

          // send the update
          tokenx_buffer = tokenx;
          toolkit = Toolkit.getDefaultToolkit();
          xtimerx = new Timer();
          xtimerx.schedule(new RemindTask_send_update(), 0);
          // send the update

        } catch (Exception e) {
          e.printStackTrace();
        }

      } // if
      else {
        System.out.println("Update item error cannot find item.");
        statex = "0";
        jsonarry = "Update item error cannot find item.";
      }

    } catch (Exception e) {
      e.printStackTrace();
      statex = "0";
      jsonarry = "Error";
    } // *****************

    return jsonarry;
  } // *****************