@Override
    public Object findElement(String s) {
      List<ObjectWithWeight> elements = new ArrayList<ObjectWithWeight>();
      s = s.trim();
      final ListIterator<Object> it = getElementIterator(0);
      while (it.hasNext()) {
        final ObjectWithWeight o = new ObjectWithWeight(it.next(), s, getComparator());
        if (!o.weights.isEmpty()) {
          elements.add(o);
        }
      }
      ObjectWithWeight cur = null;
      ArrayList<ObjectWithWeight> current = new ArrayList<ObjectWithWeight>();
      for (ObjectWithWeight element : elements) {
        if (cur == null) {
          cur = element;
          current.add(cur);
          continue;
        }

        final int i = element.compareWith(cur);
        if (i == 0) {
          current.add(element);
        } else if (i < 0) {
          cur = element;
          current.clear();
          current.add(cur);
        }
      }

      return current.isEmpty() ? null : findClosestTo(myInitialPsiElement, current);
    }
Пример #2
0
 public GElementFAState getState(String name) {
   ListIterator e = elements.listIterator();
   while (e.hasNext()) {
     GElement element = (GElement) e.next();
     if (element.getClass().equals(GElementFAState.class)) {
       GElementFAState state = (GElementFAState) element;
       if (state.state.name.equals(name)) return state;
     }
   }
   return null;
 }
Пример #3
0
 public GLink getTransition(FATransition transition) {
   ListIterator e = elements.listIterator();
   while (e.hasNext()) {
     GElement element = (GElement) e.next();
     if (element.getClass().equals(GLink.class)) {
       GLink link = (GLink) element;
       if (getState1(link).state.name.equals(transition.s1)
           && getState2(link).state.name.equals(transition.s2)
           && Tool.symbolsInPattern(link.pattern).contains(transition.symbol)) {
         return link;
       }
     }
   }
   return null;
 }
Пример #4
0
 public void removeState(GElementFAState s) {
   machine.removeState(s.state);
   removeElement(s);
   // Remove any other link which is using the state s
   ListIterator e = elements.listIterator();
   while (e.hasNext()) {
     GElement element = (GElement) e.next();
     if (element.getClass().equals(GLink.class)) {
       GLink link = (GLink) element;
       if (link.source == s || link.target == s) {
         removeElement(link);
         e = elements.listIterator();
       }
     }
   }
 }
Пример #5
0
  /**
   * paintComponent schreibt alle Laendernamen an die entsprechende Stelle der Landkarte
   * (Hintergrundgrafik) und zeichnet die Laendergrenzen auf der Landkarte nach.
   *
   * @param g Zeichenflaeche der Landkarte
   */
  public void paintComponent(Graphics g) {
    Shape shape;

    Graphics2D g2d = (Graphics2D) g;
    g2d.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
    Font myFont = new Font("Times New Roman", Font.BOLD, 12);
    g2d.setFont(myFont);

    g2d.setStroke(new BasicStroke(2.0f));

    Territory territory;
    Color color;

    ListIterator territories = worldMap.getTerritories().listIterator();

    while (territories.hasNext()) {
      territory = (Territory) territories.next();

      if (territory.getOwner() != null) {
        color = territory.getOwner().getPlayerColor();
      } else {
        color = Color.WHITE;
      }

      g2d.setColor(color);
      g2d.drawString(
          territory.getName(),
          (int) territory.getMidpoint().getX() - 15,
          (int) territory.getMidpoint().getY() - 10);

      g2d.drawString(
          new Integer(territory.getArmySize()).toString(),
          (int) territory.getMidpoint().getX(),
          (int) territory.getMidpoint().getY());
    }

    if (territoryBattle.size() != 0) {
      for (int j = 0; j < territoryBattle.size(); j++) {
        g2d.setColor(territoryBattle.get(j).getOwner().getPlayerColor());
        // g2d.fillPolygon(territoryTmp.getFrontiers());   Sieht bei unseren Grenzen nicht huebsch
        // aus
        g2d.drawPolygon(territoryBattle.get(j).getFrontiers());
      }
    }

    repaint();
  }
Пример #6
0
  /**
   * Outputs filled with points listOfPointsToBeConnected. Finds the point with the lowest Y - that
   * will be the first point of the broken line. If It finds several points with equal Ys - makes a
   * line from the most left (lowest X) point to the most right point, then connects this point with
   * next point with the lowest Y from the remaining set. The last point of the broken line will be
   * the point with the highest Y, or if there will be several points with the highest Y - the point
   * with the highest X from this set.
   */
  void connectPoints() {

    ArrayList<MyPoint> pointsInOneRow =
        new ArrayList<MyPoint>(); // will store points with equal Ys.
    MyPoint currentPoint, nextPoint;
    ListIterator<MyPoint> itr;

    while (randomListOfPoints.size() > 0) {

      pointsInOneRow.clear(); // clear the pointsInOneRow.
      itr = randomListOfPoints.listIterator();
      // initialize list iterator and place it before the first element in the randomListOfPoints.
      currentPoint = itr.next(); // the first element from the randomListOfPoints.
      itr.remove(); // delete the first element from the randomListOfPoints.
      if (itr.hasNext()) { // if it's not the end of the randomListOfPoints.

        nextPoint = itr.next(); // the second element from the randomListOfPoints.

      } else {

        // the point not from the range of possible Xs and Ys, so we can be sure that its' Y won't
        // be equal to the currentPoints'.
        nextPoint = new MyPoint(-1, -1);
      }
      pointsInOneRow.add(
          currentPoint); // add current point to a list of points, that lies on one line.
      // if the currentPoint and the nextPoint are on the same line, that is parallel to the X axis.
      while (currentPoint.getY() == nextPoint.getY()) {

        pointsInOneRow.add(
            nextPoint); // add the nextPoint to a list of points, that lies on one line.
        itr.remove(); // delete the second element from the randomListOfPoints .
        currentPoint = nextPoint; // the currentPoint equals to the nextPoint now.
        if (itr.hasNext()) { // if it's not the end of the randomListOfPoints.

          nextPoint = itr.next(); // the second element from the randomListOfPoints.

        } else {

          // the point not from the range of possible Xs and Ys, so we can be sure that its' Y won't
          // be equal to the currentPoints'.
          nextPoint = new MyPoint(-1, -1);
        }
      }

      Collections.sort(
          pointsInOneRow, new XcoordSorterComparator()); // sort the pointsInOneRow by X
      /* add all elements from the pointsInOneRow to the end of the listOfPointsToBeConnected.
       * If the listOfPointsToBeConnected.size == 0 - the first element from the pointsInOneRow will be the start
       * of the broken line, if the listOfPointsToBeConnected.size != 0 - the first element from the
       * pointsInOneRow will be connected with the last element from the listOfPointsToBeConnected*/
      listOfPointsToBeConnected.addAll(listOfPointsToBeConnected.size(), pointsInOneRow);
    }

    System.out.println("\n\nList of connected points:\n" + listOfPointsToBeConnected);
  }
Пример #7
0
  public void reconstruct() {
    elements.clear();
    List stateNames = machine.getStateList();

    ListIterator iterator = stateNames.listIterator(stateNames.size());

    int x = 0;
    int y = 0;
    while (iterator.hasPrevious()) {
      addElement(new GElementFAState((FAState) iterator.previous(), 100 + x * 200, 50 + y * 200));
      x++;
      if (x > 4) {
        y++;
        x = 0;
      }
    }

    List transitions = machine.getTransitions().getTransitions();
    iterator = transitions.listIterator();
    while (iterator.hasNext()) {
      FATransition transition = (FATransition) iterator.next();

      GElementFAState s1 = getState(transition.s1);
      GElementFAState s2 = s1;
      if (transition.s1.equals(transition.s2) == false) s2 = getState(transition.s2);

      GLink link = getLink(s1, s2);
      if (link == null)
        addElement(
            new GLink(
                s1,
                GElementFAState.ANCHOR_CENTER,
                s2,
                GElementFAState.ANCHOR_CENTER,
                GLink.SHAPE_ARC,
                transition.symbol,
                20));
      else link.pattern = Tool.addSymbolToPattern(link.pattern, transition.symbol);
    }
  }
Пример #8
0
  public void paint(Graphics g) {
    // do normal painting first
    super.paint(g);

    // draw polys
    ListIterator<Polygon> II = poly_draw.listIterator(0);
    ListIterator<Color> CC = poly_draw_color.listIterator(0);
    while (II.hasNext()) {
      Polygon P = II.next();
      Color C = CC.next();
      g.setColor(C);
      g.drawPolygon(P);
    }

    // fill polys
    II = poly_fill.listIterator(0);
    CC = poly_fill_color.listIterator(0);
    while (II.hasNext()) {
      Polygon P = II.next();
      Color C = CC.next();
      g.setColor(C);
      g.fillPolygon(P);
    }
  }
Пример #9
0
  private List<TemplatesGroup> fillTemplatesMap(WizardContext context) {

    List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
    if (context.isCreatingNewProject()) {
      builders.add(new EmptyModuleBuilder());
    }
    Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>();
    for (ModuleBuilder builder : builders) {
      BuilderBasedTemplate template = new BuilderBasedTemplate(builder);
      if (builder.isTemplate()) {
        TemplatesGroup group = groupMap.get(builder.getGroupName());
        if (group == null) {
          group = new TemplatesGroup(builder);
        }
        myTemplatesMap.putValue(group, template);
      } else {
        TemplatesGroup group = new TemplatesGroup(builder);
        groupMap.put(group.getName(), group);
        myTemplatesMap.put(group, new ArrayList<ProjectTemplate>());
      }
    }

    MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.getTemplatesMap(context);
    myTemplatesMap.putAllValues(map);

    for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) {
      TemplatesGroup group = new TemplatesGroup(category);
      myTemplatesMap.remove(group);
      myTemplatesMap.put(group, new ArrayList<ProjectTemplate>());
    }

    if (context.isCreatingNewProject()) {
      MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates();
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        myTemplatesMap.putValues(group, localTemplates.get(group.getId()));
      }
    }

    // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593)
    if (PlatformUtils.isIdeaCommunity()) {
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        if (WebModuleTypeBase.WEB_MODULE.equals(group.getId())
            && myTemplatesMap.get(group).isEmpty()) {
          myTemplatesMap.remove(group);
          break;
        }
      }
    }

    List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet());

    // sorting by module type popularity
    final MultiMap<ModuleType, TemplatesGroup> moduleTypes =
        new MultiMap<ModuleType, TemplatesGroup>();
    for (TemplatesGroup group : groups) {
      ModuleType type = getModuleType(group);
      moduleTypes.putValue(type, group);
    }
    Collections.sort(
        groups,
        new Comparator<TemplatesGroup>() {
          @Override
          public int compare(TemplatesGroup o1, TemplatesGroup o2) {
            int i = o2.getWeight() - o1.getWeight();
            if (i != 0) return i;
            int i1 =
                moduleTypes.get(getModuleType(o2)).size()
                    - moduleTypes.get(getModuleType(o1)).size();
            if (i1 != 0) return i1;
            return o1.compareTo(o2);
          }
        });

    Set<String> groupNames =
        ContainerUtil.map2Set(
            groups,
            new Function<TemplatesGroup, String>() {
              @Override
              public String fun(TemplatesGroup group) {
                return group.getParentGroup();
              }
            });

    // move subgroups
    MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>();
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
      TemplatesGroup group = iterator.next();
      String parentGroup = group.getParentGroup();
      if (parentGroup != null
          && groupNames.contains(parentGroup)
          && !group.getName().equals(parentGroup)
          && groupMap.containsKey(parentGroup)) {
        subGroups.putValue(parentGroup, group);
        iterator.remove();
      }
    }
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
      TemplatesGroup group = iterator.next();
      for (TemplatesGroup subGroup : subGroups.get(group.getName())) {
        iterator.add(subGroup);
      }
    }
    return groups;
  }
Пример #10
0
  private void calculateValueLists() {
    sequenceValues = new ArrayList<>();
    timelineValues = new ArrayList<>();

    final Object selectedSequenceColumn = this.sequenceColumnChooser.getSelectedItem();
    if (!(selectedSequenceColumn instanceof ManyValuedAttribute)) {
      return;
    }
    final ManyValuedAttribute sequenceAttribute = (ManyValuedAttribute) selectedSequenceColumn;
    final ManyValuedAttribute timelineAttribute =
        (ManyValuedAttribute) timelineColumnChooser.getSelectedItem();

    for (final FCAElement object : this.context.getObjects()) {
      Value value = this.context.getRelationship(object, sequenceAttribute);
      if (!sequenceValues.contains(value) && value != null) {
        boolean inserted = false;
        final ListIterator<Value> seqIt = sequenceValues.listIterator();
        while (seqIt.hasNext()) {
          final Value curValue = seqIt.next();
          if (value.isLesserThan(curValue)) {
            if (seqIt.hasPrevious()) {
              seqIt.previous();
            }
            seqIt.add(value);
            inserted = true;
            break;
          }
        }
        if (!inserted) {
          seqIt.add(value);
        }
      }
      value = this.context.getRelationship(object, timelineAttribute);
      if (!timelineValues.contains(value) && value != null) {
        boolean inserted = false;
        final ListIterator<Value> tlIt = timelineValues.listIterator();
        while (tlIt.hasNext()) {
          final Value curValue = tlIt.next();
          if (curValue != null && value.isLesserThan(curValue)) {
            if (tlIt.hasPrevious()) {
              tlIt.previous();
            }
            tlIt.add(value);
            inserted = true;
            break;
          }
        }
        if (!inserted) {
          tlIt.add(value);
        }
      }
    }
  }