Пример #1
2
 /**
  * This function is used to re-run the analyser, and re-create the rows corresponding the its
  * results.
  */
 private void refreshReviewTable() {
   reviewPanel.removeAll();
   rows.clear();
   GridBagLayout gbl = new GridBagLayout();
   reviewPanel.setLayout(gbl);
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.fill = GridBagConstraints.HORIZONTAL;
   gbc.gridy = 0;
   try {
     Map<String, Long> sums =
         analyser.processLogFile(config.getLogFilename(), fromDate.getDate(), toDate.getDate());
     for (Entry<String, Long> entry : sums.entrySet()) {
       String project = entry.getKey();
       double hours = 1.0 * entry.getValue() / (1000 * 3600);
       addRow(gbl, gbc, project, hours);
     }
     for (String project : main.getProjectsTree().getTopLevelProjects())
       if (!rows.containsKey(project)) addRow(gbl, gbc, project, 0);
     gbc.insets = new Insets(10, 0, 0, 0);
     addLeftLabel(gbl, gbc, "TOTAL");
     gbc.gridx = 1;
     gbc.weightx = 1;
     totalLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3));
     gbl.setConstraints(totalLabel, gbc);
     reviewPanel.add(totalLabel);
     gbc.weightx = 0;
     addRightLabel(gbl, gbc);
   } catch (IOException e) {
     e.printStackTrace();
   }
   recomputeTotal();
   pack();
 }
    private String buildLabelText(
        @NotNull final String text,
        @NotNull final Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap) {
      final StringBuilder labelText = new StringBuilder(text);
      final String disabledTag = FLAG_TO_TAG.get(ParameterInfoUIContextEx.Flag.DISABLE);

      final Map<Integer, Integer> faultMap = new HashMap<>();
      if (isDisabledBeforeHighlight) {
        final String tag = getTag(disabledTag);
        labelText.insert(0, tag);
        faultMap.put(0, tag.length());
      }

      for (Map.Entry<TextRange, ParameterInfoUIContextEx.Flag> entry : flagsMap.entrySet()) {
        final TextRange highlightRange = entry.getKey();
        final ParameterInfoUIContextEx.Flag flag = entry.getValue();

        final String tagValue = FLAG_TO_TAG.get(flag);
        final String tag = getTag(tagValue);

        int startOffset = highlightRange.getStartOffset();
        int endOffset = highlightRange.getEndOffset() + tag.length();

        for (Map.Entry<Integer, Integer> entry1 : faultMap.entrySet()) {
          if (entry1.getKey() < highlightRange.getStartOffset()) {
            startOffset += entry1.getValue();
          }
          if (entry1.getKey() < highlightRange.getEndOffset()) {
            endOffset += entry1.getValue();
          }
        }

        if (flag == ParameterInfoUIContextEx.Flag.HIGHLIGHT && isDisabledBeforeHighlight) {
          final String disableCloseTag = getClosingTag(disabledTag);
          labelText.insert(startOffset, disableCloseTag);
          faultMap.put(highlightRange.getStartOffset(), disableCloseTag.length());
        }

        labelText.insert(startOffset, tag);
        faultMap.put(highlightRange.getStartOffset(), tag.length());

        final String endTag = getClosingTag(tagValue);
        labelText.insert(endOffset, endTag);
        faultMap.put(highlightRange.getEndOffset(), endTag.length());
      }
      return XmlStringUtil.wrapInHtml(labelText);
    }
  public void removeEntryPoint(RefElement anEntryPoint) {
    if (anEntryPoint instanceof RefClass) {
      RefClass refClass = (RefClass) anEntryPoint;
      if (!refClass.isInterface()) {
        anEntryPoint = refClass.getDefaultConstructor();
      }
    }

    if (anEntryPoint == null) return;

    myTemporaryEntryPoints.remove(anEntryPoint);

    Set<Map.Entry<String, SmartRefElementPointer>> set = myPersistentEntryPoints.entrySet();
    String key = null;
    for (Map.Entry<String, SmartRefElementPointer> entry : set) {
      SmartRefElementPointer value = entry.getValue();
      if (value.getRefElement() == anEntryPoint) {
        key = entry.getKey();
        break;
      }
    }

    if (key != null) {
      myPersistentEntryPoints.remove(key);
      ((RefElementImpl) anEntryPoint).setEntry(false);
    }

    if (anEntryPoint.isPermanentEntry() && anEntryPoint.isValid()) {
      final Project project = anEntryPoint.getElement().getProject();
      final EntryPointsManagerImpl entryPointsManager = getInstance(project);
      if (this != entryPointsManager) {
        entryPointsManager.removeEntryPoint(anEntryPoint);
      }
    }
  }
 /**
  * Prepare branch descriptors for existing configuration
  *
  * @param target the target
  * @param roots the vcs root
  * @return the list of branch descriptors
  * @throws VcsException in case of error
  */
 private List<BranchDescriptor> prepareBranchDescriptors(
     BranchConfiguration target, List<VirtualFile> roots) throws VcsException {
   Map<String, String> map =
       target == null ? Collections.<String, String>emptyMap() : target.getReferences();
   List<BranchDescriptor> rc = new ArrayList<BranchDescriptor>();
   for (VirtualFile root : roots) {
     BranchDescriptor d = new BranchDescriptor();
     d.root = root;
     d.storedReference = map.remove(root.getPath());
     if (d.storedReference != null) {
       d.storedRoot = d.root.getPath();
     }
     d.currentReference = myConfig.describeRoot(root);
     if (d.storedReference != null && !myModify) {
       d.referenceToCheckout = d.storedReference;
     } else {
       d.referenceToCheckout = d.currentReference;
     }
     Branch.listAsStrings(myProject, root, false, true, d.existingBranches, null);
     Branch.listAsStrings(myProject, root, true, true, d.referencesToSelect, null);
     d.updateStatus();
     rc.add(d);
   }
   for (Map.Entry<String, String> m : map.entrySet()) {
     String root = m.getKey();
     String ref = m.getValue();
     BranchDescriptor d = new BranchDescriptor();
     d.storedReference = ref;
     d.storedRoot = root;
     d.referenceToCheckout = ref;
     d.updateStatus();
     rc.add(d);
   }
   return rc;
 }
Пример #5
0
 public void printIdentified() {
   System.out.println("Identified elements follow");
   XMLOutputter outputter = new XMLOutputter();
   for (Map.Entry<String, XMLModelIdentifiable> stringXMLModelIdentifiableEntry :
       identifiedElements.entrySet()) {
     System.out.println("Original name: " + stringXMLModelIdentifiableEntry.getKey());
     stringXMLModelIdentifiableEntry.getValue().print(outputter, System.out);
   }
 }
 @Override
 @Nullable
 public ToolWindow getToolWindowByDescriptor(@NotNull final RunContentDescriptor descriptor) {
   for (Map.Entry<String, ContentManager> entry : myToolwindowIdToContentManagerMap.entrySet()) {
     if (getRunContentByDescriptor(entry.getValue(), descriptor) != null) {
       return ToolWindowManager.getInstance(myProject).getToolWindow(entry.getKey());
     }
   }
   return null;
 }
  private ActionCallback processAjusted(
      final Map<Object, Condition> adjusted, final Set<Object> originallySelected) {
    final ActionCallback result = new ActionCallback();

    final Set<Object> allSelected = myUi.getSelectedElements();

    Set<Object> toSelect = new HashSet<Object>();
    for (Map.Entry<Object, Condition> entry : adjusted.entrySet()) {
      if (entry.getValue().value(entry.getKey())) continue;

      for (final Object eachSelected : allSelected) {
        if (isParentOrSame(entry.getKey(), eachSelected)) continue;
        toSelect.add(entry.getKey());
      }
      if (allSelected.isEmpty()) {
        toSelect.add(entry.getKey());
      }
    }

    final Object[] newSelection = ArrayUtil.toObjectArray(toSelect);

    if (newSelection.length > 0) {
      myUi._select(
          newSelection,
          new Runnable() {
            @Override
            public void run() {
              final Set<Object> hangByParent = new HashSet<Object>();
              processUnsuccessfulSelections(
                  newSelection,
                  new Function<Object, Object>() {
                    @Override
                    public Object fun(final Object o) {
                      if (myUi.isInStructure(o) && !adjusted.get(o).value(o)) {
                        hangByParent.add(o);
                      } else {
                        addAdjustedSelection(o, adjusted.get(o), null);
                      }
                      return null;
                    }
                  },
                  originallySelected);

              processHangByParent(hangByParent).notify(result);
            }
          },
          false,
          true,
          true);
    } else {
      result.setDone();
    }

    return result;
  }
Пример #8
0
 @NotNull
 private static <K, V> Map<V, K> invertMap(@NotNull Map<K, V> map) {
   final Map<V, K> inverted = new HashMap<V, K>();
   for (Map.Entry<K, V> entry : map.entrySet()) {
     final V value = entry.getValue();
     if (!inverted.containsKey(value)) {
       inverted.put(value, entry.getKey());
     }
   }
   return inverted;
 }
  @NotNull
  public List<String> getDirNames() {
    final List<String> selectedDirs = new ArrayList<String>();

    for (Map.Entry<String, JCheckBox> entry : myCheckBoxes.entrySet()) {
      if (entry.getValue().isSelected()) {
        selectedDirs.add(entry.getKey());
      }
    }
    return selectedDirs;
  }
 private PropertiesFile getSelectedPropertiesFile() {
   if (mySelectedEditor == null) return null;
   PropertiesFile selectedFile = null;
   for (Map.Entry<PropertiesFile, Editor> entry : myEditors.entrySet()) {
     Editor editor = entry.getValue();
     if (editor == mySelectedEditor) {
       selectedFile = entry.getKey();
       break;
     }
   }
   return selectedFile;
 }
 @NotNull
 private Set<Usage> getReadOnlyUsages() {
   final Set<Usage> result = new THashSet<Usage>();
   final Set<Map.Entry<Usage, UsageNode>> usages = myUsageNodes.entrySet();
   for (Map.Entry<Usage, UsageNode> entry : usages) {
     Usage usage = entry.getKey();
     UsageNode node = entry.getValue();
     if (node != null && node != NULL_NODE && !node.isExcluded() && usage.isReadOnly()) {
       result.add(usage);
     }
   }
   return result;
 }
 @Nullable
 public InnerSearchableConfigurable findSubConfigurable(@NotNull final Class pageClass) {
   if (mySubPanelFactories == null) {
     buildConfigurables();
   }
   for (Map.Entry<ColorAndFontPanelFactory, InnerSearchableConfigurable> entry :
       mySubPanelFactories.entrySet()) {
     if (pageClass.isInstance(entry.getValue().createPanel().getSettingsPage())) {
       return entry.getValue();
     }
   }
   return null;
 }
Пример #13
0
 private String generateOverviewText() throws InsufficientDataException {
   StringBuilder sb = new StringBuilder();
   final String team = config.getTeam();
   double total = checkTotal();
   final String nl = System.getProperty("line.separator");
   for (Entry<String, Row> entry : rows.entrySet()) {
     double hours = Double.parseDouble(entry.getValue().hoursTF.getText());
     double fraction = hours / total;
     if (fraction < 0.004) continue;
     String line = team + ", " + decimalFormat.format(fraction) + ", " + entry.getKey();
     sb.append(line + nl);
   }
   return sb.toString();
 }
  @Override
  public void dispose() {
    if (mySelectedEditor != null) {
      for (final Map.Entry<PropertiesFile, Editor> entry : myEditors.entrySet()) {
        if (mySelectedEditor.equals(entry.getValue())) {
          writeEditorPropertyValue(mySelectedEditor, entry.getKey(), null);
        }
      }
    }

    VirtualFileManager.getInstance().removeVirtualFileListener(myVfsListener);
    myDisposed = true;
    Disposer.dispose(myStructureViewComponent);
    releaseAllEditors();
  }
  @Override
  @NotNull
  public Set<Usage> getExcludedUsages() {
    Set<Usage> result = new THashSet<Usage>();
    for (Map.Entry<Usage, UsageNode> entry : myUsageNodes.entrySet()) {
      UsageNode node = entry.getValue();
      Usage usage = entry.getKey();
      if (node == NULL_NODE || node == null) {
        continue;
      }
      if (node.isExcluded()) {
        result.add(usage);
      }
    }

    return result;
  }
Пример #16
0
 /** Draw the entire panel from the state */
 @SuppressWarnings("rawtypes")
 public void drawState() {
   // clear();
   Map.Entry entry;
   Point pt;
   Color col;
   synchronized (state) {
     for (Iterator it = state.entrySet().iterator(); it.hasNext(); ) {
       entry = (Map.Entry) it.next();
       pt = (Point) entry.getKey();
       col = (Color) entry.getValue();
       gr.setColor(col);
       gr.fillOval(pt.x, pt.y, 10, 10);
     }
   }
   repaint();
 }
Пример #17
0
 /**
  * \ Draw saved State (color dots on panel) on WhiteBoard
  *
  * @param outstream
  * @throws IOException
  */
 public void writeState(OutputStream outstream) throws IOException {
   if (state == null) return;
   synchronized (state) {
     DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(outstream));
     // DataOutputStream dos=new DataOutputStream(outstream);
     dos.writeInt(state.size());
     for (Map.Entry<Point, Color> entry : state.entrySet()) {
       Point point = entry.getKey();
       Color col = entry.getValue();
       dos.writeInt(point.x);
       dos.writeInt(point.x);
       dos.writeInt(col.getRGB());
     }
     dos.flush();
     System.out.println("wrote " + state.size() + " elements");
   }
 }
Пример #18
0
  public void prefixIdentifiedNames(String prefix, Map<String, String> special, boolean keepID) {
    if (special == null) {
      special = new HashMap<String, String>();
    }

    for (Map.Entry<String, XMLModelIdentifiable> stringXMLModelIdentifiableEntry :
        identifiedElements.entrySet()) {
      String newName;
      if (special.containsKey(stringXMLModelIdentifiableEntry.getKey())) { // assign a special name
        newName = special.get(stringXMLModelIdentifiableEntry.getKey());
        if (keepID) {
          stringXMLModelIdentifiableEntry.getValue().restoreDefinition();
        } else {
          stringXMLModelIdentifiableEntry.getValue().removeDefinition();
        }
      } else {
        newName = prefix + stringXMLModelIdentifiableEntry.getKey();
      }
      stringXMLModelIdentifiableEntry.getValue().rename(newName);
    }
  }
Пример #19
0
  /**
   * Makes a POST request and returns the server response.
   *
   * @param urlString the URL to post to
   * @param nameValuePairs a map of name/value pairs to supply in the request.
   * @return the server reply (either from the input stream or the error stream)
   */
  public static String doPost(String urlString, Map<String, String> nameValuePairs)
      throws IOException {
    URL url = new URL(urlString);
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);

    PrintWriter out = new PrintWriter(connection.getOutputStream());

    boolean first = true;
    for (Map.Entry<String, String> pair : nameValuePairs.entrySet()) {
      if (first) first = false;
      else out.print('&');
      String name = pair.getKey();
      String value = pair.getValue();
      out.print(name);
      out.print('=');
      out.print(URLEncoder.encode(value, "UTF-8"));
    }

    out.close();

    Scanner in;
    StringBuilder response = new StringBuilder();
    try {
      in = new Scanner(connection.getInputStream());
    } catch (IOException e) {
      if (!(connection instanceof HttpURLConnection)) throw e;
      InputStream err = ((HttpURLConnection) connection).getErrorStream();
      if (err == null) throw e;
      in = new Scanner(err);
    }

    while (in.hasNextLine()) {
      response.append(in.nextLine());
      response.append("\n");
    }

    in.close();
    return response.toString();
  }
Пример #20
0
    public TaskWrite(Map map1, Map m_max, Map m_min, DBCollection coll, ModbusSlaveSet slave) {

      try {
        synchronized (slave) {
          Calendar calener = Calendar.getInstance();
          Date d1 = calener.getTime();
          Date d2 = new Date(calener.getTime().getTime() - 5000);
          BasicDBObject b2 = new BasicDBObject();
          b2.put("$gte", d2);
          b2.put("$lte", d1);
          DBCursor cursor =
              coll.find(new BasicDBObject("_id", b2)).sort(new BasicDBObject("_id", -1)).limit(1);
          while (cursor.hasNext()) {
            DBObject dbo = cursor.next();
            Set set1 = map1.entrySet();
            Iterator it1 = set1.iterator();
            while (it1.hasNext()) {
              Map.Entry<String, Map<String, String>> entry =
                  (Map.Entry<String, Map<String, String>>) it1.next();
              Map<String, String> map2 = entry.getValue();
              for (Iterator it2 = map2.entrySet().iterator(); it2.hasNext(); ) {
                Map.Entry<String, String> entry2 = (Map.Entry<String, String>) it2.next();
                String name = entry2.getKey().toString();
                String paramAddr = entry2.getValue().toString();
                int fun = (int) (Double.parseDouble(paramAddr));
                if (paramAddr.substring(0, 1).equals("4")) {
                  double value = Double.parseDouble(dbo.get(name).toString());
                  double dmax = (Double) m_max.get(name);
                  double dmin = (Double) m_min.get(name);
                  double dValue = 0;
                  if (value > dmax || value < dmin) {
                    if (value >= 0) {
                      dValue = 32000 * (int) (value / dmax);
                    }
                    if (value < 0) {
                      dValue = -32000 * (int) (value / dmin);
                    }
                    // slave.getProcessImage(3).setInputRegister(fun % 10000, (short) dValue);
                  } else { /// 参数超限报警
                    JOptionPane.showMessageDialog(null, "参数超限");
                    slave.stop();
                  }
                }
                if (paramAddr.substring(0, 1).equals("3")) {
                  double value = Double.parseDouble(dbo.get(name).toString());
                  double dmax = (Double) m_max.get(name);
                  double dmin = (Double) m_min.get(name);
                  double dValue = 0;
                  if (value > dmax || value < dmin) {
                    if (value >= 0) {
                      dValue = 32000 * (int) (value / dmax);
                    }
                    if (value < 0) {
                      dValue = -32000 * (int) (value / dmin);
                    }
                    // slave.getProcessImage(3).setHoldingRegister(fun % 10000, (short) dValue);
                  } else { /// 参数超限报警
                    JOptionPane.showMessageDialog(null, "参数超限");
                    slave.stop();
                  }
                  ;
                }
                if (paramAddr.substring(0, 1).equals("2")) {
                  String value = dbo.get(name).toString();
                  /// slave.getProcessImage(4).setInput(fun % 10000, Boolean.valueOf(value));
                }
                if (paramAddr.substring(0, 1).equals("1")) {
                  String value = dbo.get(name).toString();
                  // slave.getProcessImage(4).setCoil(fun % 10000, Boolean.valueOf(value));
                }
              }
            }
          }
        }
      } catch (Exception ex) {
      }
    }
Пример #21
0
    public TaskRead(Map map1, Map m_max, Map m_min, DBCollection coll, ModbusSlaveSet slave) {
      try {
        //// 此处只要点击开始就能保存数据
        /// 方案:利用数据源发送单个布尔型变量(1,0)交替,链接成功,先判断是否链接成功,然后在保存数据
        synchronized (slave) {
          Map map = new HashMap();
          Set set1 = map1.entrySet();
          Iterator it1 = set1.iterator();
          while (it1.hasNext()) {
            Map.Entry<String, Map<String, String>> entry =
                (Map.Entry<String, Map<String, String>>) it1.next();
            Map<String, String> map2 = entry.getValue();
            for (Iterator it2 = map2.entrySet().iterator(); it2.hasNext(); ) {
              Map.Entry<String, String> entry2 = (Map.Entry<String, String>) it2.next();
              String name = entry2.getKey().toString();
              String paramAddr = entry2.getValue().toString();
              int fun = (int) (Double.parseDouble(paramAddr));
              if (paramAddr.substring(0, 1).equals("4")) {
                Short d4 = slave.getProcessImage(1).getInputRegister(fun % 10000);
                double dmax = (Double) m_max.get(name);
                double dmin = (Double) m_min.get(name);
                double dValue = 0;
                if (d4 >= 0) {
                  dValue = dmax * d4 / 32000;
                } else {
                  dValue = dmin * d4 / (-32000);
                }
                map.put(name, dValue);
              }
              if (paramAddr.substring(0, 1).equals("3")) {
                Short d3 = slave.getProcessImage(1).getHoldingRegister(fun % 10000);
                double dmax = (Double) m_max.get(name);
                double dmin = (Double) m_min.get(name);
                double dValue = 0;

                if (d3 >= 0) {
                  dValue = dmax * d3 / 32000;
                } else {
                  dValue = dmin * d3 / (-32000);
                }
                map.put(name, dValue);
              }
              if (paramAddr.substring(0, 1).equals("2")) {
                map.put(name, slave.getProcessImage(2).getInput(fun % 10000));
              }
              if (paramAddr.substring(0, 1).equals("1")) {
                Boolean a = slave.getProcessImage(2).getCoil(fun % 10000 - 1);
                map.put(name, a);
              }
            }
          }

          Calendar calendar = Calendar.getInstance();
          Date dd = calendar.getTime();

          BasicDBObject doc = new BasicDBObject();
          doc.put("_id", dd);

          Set set = map.entrySet();
          Iterator it = set.iterator();
          while (it.hasNext()) {
            Map.Entry<String, String> entry1 = (Map.Entry<String, String>) it.next();
            doc.put(entry1.getKey(), entry1.getValue());
          }
          coll.insert(doc);
        }
      } catch (Exception ex) {
      }
    }
 public Set getEntrySet() {
   return properties.entrySet();
 }
Пример #23
0
  // TODO: Refactor method
  private void removeLines(
      Map<Position, Piece> pieceMap,
      PieceColor pieceColor,
      Map<PieceColor, Set<Line.Segment>> linesTakenBy,
      Map<PieceColor, Set<Position>> piecesBackTo) {
    Set<Line.Segment> intersectingSegments;
    Set<Line.Segment> segmentsNotRemoved = new HashSet<>();

    do {
      intersectingSegments = new HashSet<>();
      Set<Line.Segment> removableSegmentsThisPlayer =
          getRemovableLineSegments(pieceMap, pieceColor);
      for (Line.Segment segment : removableSegmentsThisPlayer) {
        // Remove the line segments that are not intersecting with other line segments of the set
        boolean intersectionFound = false;

        for (Line.Segment otherSegment : removableSegmentsThisPlayer) {
          if (!segment.equals(otherSegment) && !segmentsNotRemoved.contains(otherSegment)) {
            if (segment.intersectsWith(otherSegment)) {
              if (!segmentsNotRemoved.contains(segment)) {
                intersectingSegments.add(segment);
                intersectionFound = true;
              }
            }
          }
        }

        if (!intersectionFound) {
          if (!segmentsNotRemoved.contains(segment)) {
            linesTakenBy.get(pieceColor).add(segment);
          }
        }
      }

      if (intersectingSegments.size() > 0) {
        Line.Segment segment = intersectingSegments.iterator().next();
        currentRemoveSelection = segment.getOccupiedPositions(pieceMap);

        int dialogResult =
            GipfBoardComponent.showConfirmDialog(
                gipfBoardState.players.current().pieceColor
                    + ", do you want to remove "
                    + segment
                        .getOccupiedPositions(pieceMap)
                        .stream()
                        .map(Position::getName)
                        .sorted()
                        .collect(toList())
                    + "?",
                "Remove line segment");
        if (dialogResult == JOptionPane.YES_OPTION) {
          // Remove the line
          linesTakenBy.get(pieceColor).add(segment);
        } else if (dialogResult == JOptionPane.NO_OPTION) {
          // Don't remove the line
          segmentsNotRemoved.add(segment);
        }
        currentRemoveSelection = new HashSet<>();
      }

      for (Line.Segment segment : linesTakenBy.get(pieceColor)) {
        Predicate<Map.Entry<Position, Piece>> isNormalPiece =
            entry -> entry.getValue().getPieceType() == NORMAL;
        Predicate<Map.Entry<Position, Piece>> isCurrentPlayersColor =
            entry -> entry.getValue().getPieceColor() == pieceColor;
        Predicate<Map.Entry<Position, Piece>> doesPlayerWantToRemoveGipf =
            entry -> {
              currentRemoveSelection.add(entry.getKey());
              int dialogResult =
                  GipfBoardComponent.showConfirmDialog(
                      gipfBoardState.players.current().pieceColor
                          + ", do you want to remove the Gipf at "
                          + entry.getKey().getName()
                          + "?",
                      "Remove Gipf");
              currentRemoveSelection = new HashSet<>();
              return dialogResult == JOptionPane.YES_OPTION;
            };

        Map<Position, Piece> piecesRemovedMap =
            segment.getOccupiedPositions(pieceMap).stream().collect(toMap(p -> p, pieceMap::get));

        piecesBackTo
            .get(pieceColor)
            .addAll(
                piecesRemovedMap
                    .entrySet()
                    .stream()
                    .filter(isCurrentPlayersColor.and(isNormalPiece.or(doesPlayerWantToRemoveGipf)))
                    .map(Map.Entry::getKey)
                    .collect(toSet()));

        piecesBackTo
            .get(null)
            .addAll(
                piecesRemovedMap
                    .entrySet()
                    .stream()
                    .filter(
                        isCurrentPlayersColor
                            .negate()
                            .and(isNormalPiece.or(doesPlayerWantToRemoveGipf)))
                    .map(Map.Entry::getKey)
                    .collect(toSet()));
      }

      piecesBackTo.values().forEach(positionSet -> removePiecesFromPieceMap(pieceMap, positionSet));
    } while (intersectingSegments.size() > 0);

    return;
  }
Пример #24
0
  public void createPopupMenu() {
    popupMenu = new JPopupMenu();
    JMenuItem menuItem = null;
    JMenu subMenu = null;
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Message", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sendMessage(currentJIDStatus);
          }
        });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Chat", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            sendChat(currentJIDStatus);
          }
        });
    popupMenu.add(menuItem);
    subMenu = new JMenu(I18N.gettext("main.main.rostermenu.Subscriptions"));
    menuItem = new JMenuItem(I18N.gettext("main.main.rostermenu.Subscribe_from"));
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Subscribe_from", menuItem);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            backend.send(new Presence(currentJIDStatus.getJID(), "subscribe"));
          }
        });
    subMenu.add(menuItem);
    menuItem = new JMenuItem(I18N.gettext("main.main.rostermenu.Unsubscribe_from"));
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Unsubscribe_from", menuItem);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            backend.send(new Presence(currentJIDStatus.getJID(), "unsubscribe"));
          }
        });
    subMenu.add(menuItem);
    popupMenu.add(subMenu);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Remove", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JID to = currentJIDStatus.getJID();
            if (JOptionPane.showConfirmDialog(
                    main,
                    MessageFormat.format(
                        I18N.gettext("main.popup.Really_remove_{0}_from_all_groups_?"),
                        new Object[] {new String(to.toString())}),
                    I18N.gettext("main.main.rostermenu.Remove"),
                    JOptionPane.YES_NO_OPTION)
                == JOptionPane.YES_OPTION) {
              // backend.remove(currentJIDStatus.getJID());
              IQXRoster roster = new IQXRoster(new RosterItem(to, null, "remove", null, null));
              backend.send(new InfoQuery("set", roster));
            }
          }
        });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Rename", menuItem, true);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String nick =
                JOptionPane.showInputDialog(
                    main,
                    MessageFormat.format(
                        I18N.gettext("main.popup.Rename_{0}_to:"),
                        new Object[] {new String(currentJIDStatus.getNick())}));
            if (nick == null) return;
            IQXRoster roster =
                new IQXRoster(
                    new RosterItem(
                        currentJIDStatus.getJID(),
                        nick,
                        null,
                        null,
                        currentJIDStatus.getGroupsCopy()));
            backend.send(new InfoQuery("set", roster));
          }
        });
    popupMenu.add(menuItem);
    subMenu = new JMenu();
    I18N.setTextAndMnemonic("main.main.rostermenu.Group", subMenu);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Change_Group", menuItem, true);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new GroupDialog(currentGroup, currentJIDStatus, backend).show();
          }
        });
    subMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Add_to_Group", menuItem, true);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new GroupDialog(currentJIDStatus, backend).show();
          }
        });
    subMenu.add(menuItem);
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Remove_from_group", menuItem, true);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JID to = currentJIDStatus.getJID();
            if (currentJIDStatus.groupCount() == 1) {
              if (JOptionPane.showConfirmDialog(
                      main,
                      MessageFormat.format(
                          I18N.gettext("main.popup.{0}_is_in_the_last_group,_remove_completely?"),
                          new Object[] {new String(to.toString())}),
                      I18N.gettext("main.main.rostermenu.Remove"),
                      JOptionPane.YES_NO_OPTION)
                  == JOptionPane.YES_OPTION) {
                IQXRoster roster = new IQXRoster(new RosterItem(to, null, "remove", null, null));
                backend.send(new InfoQuery("set", roster));
              }
            } else {
              nu.fw.jeti.util.StringArray groups = currentJIDStatus.getGroupsCopy();
              groups.remove(currentGroup);
              IQXRoster roster =
                  new IQXRoster(new RosterItem(to, currentJIDStatus.getNick(), null, null, groups));
              backend.send(new InfoQuery("set", roster));
            }
          }
        });
    subMenu.add(menuItem);
    popupMenu.add(subMenu);
    if (onlineTree) {
      menuItem = new JMenuItem();
      I18N.setTextAndMnemonic("main.main.rostermenu.Local_Time", menuItem, true);
      menuItem.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              backend.send(new InfoQuery(currentJIDStatus.getCompleteJID(), "get", new IQTime()));
            }
          });
      popupMenu.add(menuItem);
    }
    if (!onlineTree) {
      menuItem = new JMenuItem();
      I18N.setTextAndMnemonic("main.main.rostermenu.Last_Seen", menuItem, true);
      menuItem.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              backend.send(new InfoQuery(currentJIDStatus.getJID(), "get", new IQLast()));
            }
          });
      popupMenu.add(menuItem);
    }
    if (onlineTree) {
      menuItem = new JMenuItem();
      I18N.setTextAndMnemonic("main.main.rostermenu.Local_Version", menuItem, true);
      menuItem.addActionListener(
          new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              backend.send(
                  new InfoQuery(currentJIDStatus.getCompleteJID(), "get", new IQVersion()));
            }
          });
      popupMenu.add(menuItem);
    }
    menuItem = new JMenuItem();
    I18N.setTextAndMnemonic("main.main.rostermenu.Invisible", menuItem);
    menuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            backend.send(new Presence(currentJIDStatus.getJID(), "invisible"));
          }
        });
    popupMenu.add(menuItem);
    if (menuItems != null) {
      for (Iterator i = menuItems.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        JMenuItem item = new JMenuItem((String) entry.getKey());
        final RosterMenuListener listener = (RosterMenuListener) entry.getValue();
        item.addActionListener(
            new java.awt.event.ActionListener() {
              public void actionPerformed(ActionEvent e) {
                listener.actionPerformed(currentJIDStatus, currentJIDStatusGroup2);
              }
            });
        popupMenu.add(item);
      }
    }
  }
Пример #25
0
 public void reloadShortcuts() {
   for (Map.Entry<FPref, KeyboardShortcutField> e : shortcutFields.entrySet()) {
     e.getValue().reload(e.getKey());
   }
 }