コード例 #1
1
  private void updateText() {
    StringBuilder sb = new StringBuilder();

    if (myShowSettingsBeforeRunCheckBox.isSelected()) {
      sb.append(ExecutionBundle.message("configuration.edit.before.run")).append(", ");
    }

    List<BeforeRunTask> tasks = myModel.getItems();
    if (!tasks.isEmpty()) {
      LinkedHashMap<BeforeRunTaskProvider, Integer> counter =
          new LinkedHashMap<BeforeRunTaskProvider, Integer>();
      for (BeforeRunTask task : tasks) {
        BeforeRunTaskProvider<BeforeRunTask> provider =
            BeforeRunTaskProvider.getProvider(
                myRunConfiguration.getProject(), task.getProviderId());
        if (provider != null) {
          Integer count = counter.get(provider);
          if (count == null) {
            count = task.getItemsCount();
          } else {
            count += task.getItemsCount();
          }
          counter.put(provider, count);
        }
      }
      for (Iterator<Map.Entry<BeforeRunTaskProvider, Integer>> iterator =
              counter.entrySet().iterator();
          iterator.hasNext(); ) {
        Map.Entry<BeforeRunTaskProvider, Integer> entry = iterator.next();
        BeforeRunTaskProvider provider = entry.getKey();
        String name = provider.getName();
        if (name.startsWith("Run ")) {
          name = name.substring(4);
        }
        sb.append(name);
        if (entry.getValue() > 1) {
          sb.append(" (").append(entry.getValue().intValue()).append(")");
        }
        if (iterator.hasNext()) sb.append(", ");
      }
    }
    if (sb.length() > 0) {
      sb.insert(0, ": ");
    }
    sb.insert(0, ExecutionBundle.message("before.launch.panel.title"));
    myListener.titleChanged(sb.toString());
  }
コード例 #2
0
  @NotNull
  private static FontInfo doGetFontAbleToDisplay(
      int codePoint, int size, @JdkConstants.FontStyle int style) {
    synchronized (lock) {
      if (ourUndisplayableChars.contains(codePoint)) return ourSharedDefaultFont;

      final Collection<FontInfo> descriptors = ourUsedFonts.values();
      for (FontInfo font : descriptors) {
        if (font.getSize() == size && font.getStyle() == style && font.canDisplay(codePoint)) {
          return font;
        }
      }

      for (int i = 0; i < ourFontNames.size(); i++) {
        String name = ourFontNames.get(i);
        FontInfo font = new FontInfo(name, size, style);
        if (font.canDisplay(codePoint)) {
          ourUsedFonts.put(new FontKey(name, size, style), font);
          ourFontNames.remove(i);
          return font;
        }
      }

      ourUndisplayableChars.add(codePoint);

      return ourSharedDefaultFont;
    }
  }
コード例 #3
0
ファイル: PageText.java プロジェクト: svn2github/icepdf
 public void clearSelected() {
   if (pageLines != null) {
     for (LineText lineText : pageLines) {
       lineText.clearSelected();
     }
   }
   if (sortedPageLines != null) {
     for (LineText lineText : sortedPageLines) {
       lineText.clearSelected();
     }
   }
   // check optional content.
   if (optionalPageLines != null) {
     // iterate over optional content keys and extract text from visible groups
     Set<OptionalContents> keys = optionalPageLines.keySet();
     ArrayList<LineText> optionalLines;
     for (OptionalContents key : keys) {
       if (key != null) {
         optionalLines = optionalPageLines.get(key).getAllPageLines();
         if (optionalLines != null) {
           for (LineText lineText : optionalLines) {
             lineText.clearSelected();
           }
         }
       }
     }
   }
 }
コード例 #4
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
 /**
  * Updates the map of colors used for rendering. This creates the alternating colors based on the
  * full stream status, which should only be changed when new data is set.
  */
 private void makeColors() {
   colors.clear();
   Iterator<Entry<Long, StreamInfoHistoryItem>> it = history.entrySet().iterator();
   String prevStatus = null;
   Color currentColor = FIRST_COLOR;
   while (it.hasNext()) {
     Entry<Long, StreamInfoHistoryItem> entry = it.next();
     long time = entry.getKey();
     StreamInfoHistoryItem item = entry.getValue();
     String newStatus = item.getStatusAndGame();
     // Only change color if neither the previous nor the new status
     // are null (offline) and the previous and new status are not equal.
     if (prevStatus != null && newStatus != null && !prevStatus.equals(newStatus)) {
       // Change color
       if (currentColor == FIRST_COLOR) {
         currentColor = SECOND_COLOR;
       } else {
         currentColor = FIRST_COLOR;
       }
     }
     colors.put(time, currentColor);
     // Save this status as previous status, but only if it's not
     // offline.
     if (newStatus != null) {
       prevStatus = newStatus;
     }
   }
 }
コード例 #5
0
ファイル: PageText.java プロジェクト: svn2github/icepdf
 protected void addOptionalPageLines(OptionalContents optionalContent, GlyphText sprite) {
   if (optionalPageLines == null) {
     optionalPageLines = new LinkedHashMap<OptionalContents, PageText>(10);
   }
   PageText pageText = optionalPageLines.get(optionalContent);
   if (pageText == null) {
     // create a text object add the glyph.
     pageText = new PageText();
     pageText.addGlyph(sprite);
     optionalPageLines.put(optionalContent, pageText);
   } else {
     pageText.addGlyph(sprite);
   }
 }
コード例 #6
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
 /**
  * Finds the key (time) of the currently hovered entry, or -1 if none is hovered.
  *
  * @param p The current position of the mouse.
  * @return
  */
 private long findHoverEntry(Point p) {
   double smallestDistance = HOVER_RADIUS;
   long foundHoverEntry = -1;
   for (Point point : locations.keySet()) {
     double distance = p.distance(point);
     if (distance < HOVER_RADIUS) {
       if (distance < smallestDistance) {
         foundHoverEntry = locations.get(point);
         smallestDistance = distance;
       }
     }
   }
   return foundHoverEntry;
 }
コード例 #7
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
 /**
  * Update the hoverEntry with the currently hovered entry, or none if none is hovered. Repaints
  * and informs listeners if something has changed.
  *
  * @param p Where the mouse is currently.
  */
 private void updateHoverEntry(Point p) {
   long hoverEntryBefore = hoverEntry;
   hoverEntry = findHoverEntry(p);
   // If something has changed, then redraw.
   if (hoverEntry != hoverEntryBefore) {
     repaint();
     if (listener != null) {
       if (hoverEntry == -1) {
         listener.noItemSelected();
       } else {
         StreamInfoHistoryItem item = history.get(hoverEntry);
         if (item == null) {
           /**
            * This shouldn't happen, because the hover entry is set just before and selected from
            * the current data (and it should all be in the EDT), but apparently it still happens
            * on rare occasions.
            */
           LOGGER.warning("Hovered Entry " + hoverEntry + " was null");
           hoverEntry = -1;
         } else {
           listener.itemSelected(item.getViewers(), item.getTitle(), item.getGame());
         }
       }
     }
   }
 }
コード例 #8
0
ファイル: AssertFocused.java プロジェクト: jexp/idea2
  private void doAssert(Map<String, String> expected, PlaybackRunner.StatusCallback cb)
      throws AssertionError {
    final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

    if (owner == null) {
      throw new AssertionError("No component focused");
    }

    Component eachParent = owner;
    final LinkedHashMap<String, String> actual = new LinkedHashMap<String, String>();
    while (eachParent != null) {
      if (eachParent instanceof TestableUi) {
        ((TestableUi) eachParent).putInfo(actual);
      }

      eachParent = eachParent.getParent();
    }

    Set testedKeys = new LinkedHashSet<String>();
    for (String eachKey : expected.keySet()) {
      testedKeys.add(eachKey);

      final String actualValue = actual.get(eachKey);
      final String expectedValue = expected.get(eachKey);

      if (!expectedValue.equals(actualValue)) {
        throw new AssertionError(
            eachKey + " expected: " + expectedValue + " but was: " + actualValue);
      }
    }

    Map<String, String> untested = new HashMap<String, String>();
    for (String eachKey : actual.keySet()) {
      if (testedKeys.contains(eachKey)) continue;
      untested.put(eachKey, actual.get(eachKey));
    }

    StringBuffer untestedText = new StringBuffer();
    for (String each : untested.keySet()) {
      if (untestedText.length() > 0) {
        untestedText.append(",");
      }
      untestedText.append(each).append("=").append(untested.get(each));
    }

    cb.message("Untested info: " + untestedText.toString(), getLine());
  }
コード例 #9
0
ファイル: PageText.java プロジェクト: svn2github/icepdf
 public void newLine(LinkedList<OptionalContents> oCGs) {
   if (oCGs != null && oCGs.size() > 0) {
     if (optionalPageLines == null) {
       optionalPageLines = new LinkedHashMap<OptionalContents, PageText>(10);
     }
     OptionalContents optionalContent = oCGs.peek();
     PageText pageText = optionalPageLines.get(optionalContent);
     if (pageText == null) {
       // create a text object add the glyph.
       pageText = new PageText();
       pageText.newLine();
       optionalPageLines.put(optionalContent, pageText);
     } else {
       pageText.newLine();
     }
   }
 }
コード例 #10
0
  @Nullable
  private static FontInfo doGetFontAbleToDisplay(
      int codePoint,
      int size,
      @JdkConstants.FontStyle int originalStyle,
      @NotNull String defaultFontFamily) {
    synchronized (lock) {
      @JdkConstants.FontStyle int style = originalStyle;
      if (Patches.JDK_MAC_FONT_STYLE_DETECTION_WORKAROUND && style > 0 && style < 4) {
        Pair<String, Integer>[] replacement = ourStyledFontMap.get(defaultFontFamily);
        if (replacement != null) {
          defaultFontFamily = replacement[style].first;
          style = replacement[style].second;
        }
      }
      if (ourSharedKeyInstance.mySize == size
          && ourSharedKeyInstance.myStyle == style
          && ourSharedKeyInstance.myFamilyName != null
          && ourSharedKeyInstance.myFamilyName.equals(defaultFontFamily)
          && ourSharedDefaultFont != null
          && (codePoint < 128 || ourSharedDefaultFont.canDisplay(codePoint))) {
        return ourSharedDefaultFont;
      }

      ourSharedKeyInstance.myFamilyName = defaultFontFamily;
      ourSharedKeyInstance.mySize = size;
      ourSharedKeyInstance.myStyle = style;

      FontInfo defaultFont = ourUsedFonts.get(ourSharedKeyInstance);
      if (defaultFont == null) {
        defaultFont = new FontInfo(defaultFontFamily, size, style, originalStyle);
        ourUsedFonts.put(ourSharedKeyInstance, defaultFont);
        ourSharedKeyInstance = new FontKey("", 0, 0);
      }

      ourSharedDefaultFont = defaultFont;
      if (codePoint < 128 || defaultFont.canDisplay(codePoint)) {
        return defaultFont;
      } else {
        return null;
      }
    }
  }
コード例 #11
0
ファイル: PageText.java プロジェクト: svn2github/icepdf
 private ArrayList<LineText> getAllPageLines() {
   ArrayList<LineText> visiblePageLines = new ArrayList<LineText>(pageLines);
   // add optional content text that is visible.
   // check optional content.
   if (optionalPageLines != null) {
     // iterate over optional content keys and extract text from visible groups
     Set<OptionalContents> keys = optionalPageLines.keySet();
     LineText currentLine = new LineText();
     visiblePageLines.add(currentLine);
     for (OptionalContents key : keys) {
       if (key != null) {
         ArrayList<LineText> pageLines = optionalPageLines.get(key).getVisiblePageLines(true);
         for (LineText lineText : pageLines) {
           currentLine.addAll(lineText.getWords());
         }
       }
     }
     // recalculate the bounds.
     currentLine.getBounds();
   }
   return visiblePageLines;
 }
コード例 #12
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
  /**
   * Update the start/end/duration/min/max variables which can be changed when the data changes as
   * well when the displayed range changes.
   */
  private void updateVars() {
    long startAt = getStartAt(currentRange);
    long endAt = getEndAt();
    int max = 0;
    int min = -1;
    long start = -1;
    long end = -1;
    for (Long time : history.keySet()) {
      if (time < startAt) {
        continue;
      }
      if (endAt > startAt && time > endAt) {
        continue;
      }
      // Start/End time
      if (start == -1) {
        start = time;
      }
      end = time;
      // Max/min value
      StreamInfoHistoryItem historyObj = history.get(time);
      int viewerCount = historyObj.getViewers();
      if (viewerCount < min || min == -1) {
        min = viewerCount;
      }
      if (viewerCount == -1) {
        min = 0;
      }
      if (viewerCount > max) {
        max = viewerCount;
      }
    }

    maxValue = max;
    minValue = min;
    startTime = start;
    endTime = end;
    duration = end - start;
  }
コード例 #13
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
 /**
  * Sets a new history dataset, update the variables needed for rendering and repaints the display.
  *
  * @param stream
  * @param newHistory
  */
 public void setHistory(String stream, LinkedHashMap<Long, StreamInfoHistoryItem> newHistory) {
   manageChannelSpecificVars(stream);
   // Make a copy so changes are not reflected in this
   history = newHistory;
   // Only update variables when the history contains something, else
   // set to null so nothing is rendered that isn't supposed to
   if (history != null && !history.isEmpty()) {
     updateVars();
     checkVars();
     makeColors();
   } else {
     history = null;
   }
   repaint();
 }
コード例 #14
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
 /**
  * Gets the starting time for the displayed range. If there is a fixed starting time, use that,
  * otherwise check if there is a range and calculate the starting time from that. Otherwise return
  * 0, meaning the data is displayed from the start.
  *
  * @param range The time in milliseconds that the data should be displayed, going backwards,
  *     starting from the very end.
  * @return The start of the data displaying range in milliseconds.
  */
 private long getStartAt(long range) {
   if (fixedStartTime > 0) {
     return fixedStartTime;
   }
   if (range <= 0) {
     return 0;
   }
   long end = -1;
   for (long time : history.keySet()) {
     end = time;
   }
   long startAt = end - range;
   if (startAt < 0) {
     startAt = 0;
   }
   return startAt;
 }
コード例 #15
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
  public ViewerHistory() {
    // Test data
    if (Chatty.DEBUG) {
      history = new LinkedHashMap<>();
      history.put(
          (long) 1000 * 1000,
          new StreamInfoHistoryItem(5, "Leveling Battlemage", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1120 * 1000,
          new StreamInfoHistoryItem(4, "Leveling Battlemage", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1240 * 1000,
          new StreamInfoHistoryItem(4, "Leveling Battlemage", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1360 * 1000,
          new StreamInfoHistoryItem(6, "Leveling Battlemage", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1480 * 1000,
          new StreamInfoHistoryItem(8, "Leveling Battlemage", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1600 * 1000, new StreamInfoHistoryItem(8, "Pause", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1720 * 1000,
          new StreamInfoHistoryItem(10, "Pause", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1840 * 1000,
          new StreamInfoHistoryItem(12, "Pause", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 1960 * 1000,
          new StreamInfoHistoryItem(12, "Diebesgilde", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 2080 * 1000,
          new StreamInfoHistoryItem(18, "Diebesgilde", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 2200 * 1000,
          new StreamInfoHistoryItem(20, "Diebesgilde", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 2320 * 1000,
          new StreamInfoHistoryItem(22, "Diebesgilde", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 2440 * 1000,
          new StreamInfoHistoryItem(1000, "Diebesgilde", "The Elder Scrolls V: Skyrim"));
      history.put(
          (long) 2560 * 1000,
          new StreamInfoHistoryItem(2500, "Diebesgilde", "The Elder Scrolls V: Skyrim"));
      // history.put((long) 2680*1000, new StreamInfoHistoryItem());
      // history.put((long) 2800*1000, new StreamInfoHistoryItem());
      // history.put((long) 2920*1000, new StreamInfoHistoryItem());

      // history.put((long) 1000 * 1000, 40);
      // history.put((long) 1300 * 1000, 290);
      //        history.put((long)1600*1000,400);
      //        history.put((long)2200*1000,90);
      //        history.put((long)3000*1000,123);
      //        history.put((long)3300*1000,-1);
      //        history.put((long)3600*1000,0);
      setHistory("", history);
    }
    MyMouseListener mouseListener = new MyMouseListener();
    addMouseListener(mouseListener);
    addMouseMotionListener(mouseListener);
    contextMenu.addContextMenuListener(new MyContextMenuListener());
  }
コード例 #16
0
ファイル: SVGConstants.java プロジェクト: ilyessou/jhotdraw
  static {
    LinkedHashMap<String, Color> map = new LinkedHashMap<String, Color>();

    // SVG 1.2 Tiny colors
    map.put("black", new Color(0, 0, 0));
    map.put("green", new Color(0, 128, 0));
    map.put("silver", new Color(192, 192, 192));
    map.put("lime", new Color(0, 255, 0));
    map.put("gray", new Color(128, 128, 128));
    map.put("olive", new Color(128, 128, 0));
    map.put("white", new Color(255, 255, 255));
    map.put("yellow", new Color(255, 255, 0));
    map.put("maroon", new Color(128, 0, 0));
    map.put("navy", new Color(0, 0, 128));
    map.put("red", new Color(255, 0, 0));
    map.put("blue", new Color(0, 0, 255));
    map.put("purple", new Color(128, 0, 128));
    map.put("teal", new Color(0, 128, 128));
    map.put("fuchsia", new Color(255, 0, 255));
    map.put("aqua", new Color(0, 255, 255));

    // SVG 1.1 colors
    map.put("aliceblue", new Color(240, 248, 255));
    map.put("antiquewhite", new Color(250, 235, 215));
    map.put("aqua", new Color(0, 255, 255));
    map.put("aquamarine", new Color(127, 255, 212));
    map.put("azure", new Color(240, 255, 255));
    map.put("beige", new Color(245, 245, 220));
    map.put("bisque", new Color(255, 228, 196));
    map.put("black", new Color(0, 0, 0));
    map.put("blanchedalmond", new Color(255, 235, 205));
    map.put("blue", new Color(0, 0, 255));
    map.put("blueviolet", new Color(138, 43, 226));
    map.put("brown", new Color(165, 42, 42));
    map.put("burlywood", new Color(222, 184, 135));
    map.put("cadetblue", new Color(95, 158, 160));
    map.put("chartreuse", new Color(127, 255, 0));
    map.put("chocolate", new Color(210, 105, 30));
    map.put("coral", new Color(255, 127, 80));
    map.put("cornflowerblue", new Color(100, 149, 237));
    map.put("cornsilk", new Color(255, 248, 220));
    map.put("crimson", new Color(220, 20, 60));
    map.put("cyan", new Color(0, 255, 255));
    map.put("darkblue", new Color(0, 0, 139));
    map.put("darkcyan", new Color(0, 139, 139));
    map.put("darkgoldenrod", new Color(184, 134, 11));
    map.put("darkgray", new Color(169, 169, 169));
    map.put("darkgreen", new Color(0, 100, 0));
    map.put("darkgrey", new Color(169, 169, 169));
    map.put("darkkhaki", new Color(189, 183, 107));
    map.put("darkmagenta", new Color(139, 0, 139));
    map.put("darkolivegreen", new Color(85, 107, 47));
    map.put("darkorange", new Color(255, 140, 0));
    map.put("darkorchid", new Color(153, 50, 204));
    map.put("darkred", new Color(139, 0, 0));
    map.put("darksalmon", new Color(233, 150, 122));
    map.put("darkseagreen", new Color(143, 188, 143));
    map.put("darkslateblue", new Color(72, 61, 139));
    map.put("darkslategray", new Color(47, 79, 79));
    map.put("darkslategrey", new Color(47, 79, 79));
    map.put("darkturquoise", new Color(0, 206, 209));
    map.put("darkviolet", new Color(148, 0, 211));
    map.put("deeppink", new Color(255, 20, 147));
    map.put("deepskyblue", new Color(0, 191, 255));
    map.put("dimgray", new Color(105, 105, 105));
    map.put("dimgrey", new Color(105, 105, 105));
    map.put("dodgerblue", new Color(30, 144, 255));
    map.put("firebrick", new Color(178, 34, 34));
    map.put("floralwhite", new Color(255, 250, 240));
    map.put("forestgreen", new Color(34, 139, 34));
    map.put("fuchsia", new Color(255, 0, 255));
    map.put("gainsboro", new Color(220, 220, 220));
    map.put("ghostwhite", new Color(248, 248, 255));
    map.put("gold", new Color(255, 215, 0));
    map.put("goldenrod", new Color(218, 165, 32));
    map.put("gray", new Color(128, 128, 128));
    map.put("grey", new Color(128, 128, 128));
    map.put("green", new Color(0, 128, 0));
    map.put("greenyellow", new Color(173, 255, 47));
    map.put("honeydew", new Color(240, 255, 240));
    map.put("hotpink", new Color(255, 105, 180));
    map.put("indianred", new Color(205, 92, 92));
    map.put("indigo", new Color(75, 0, 130));
    map.put("ivory", new Color(255, 255, 240));
    map.put("khaki", new Color(240, 230, 140));
    map.put("lavender", new Color(230, 230, 250));
    map.put("lavenderblush", new Color(255, 240, 245));
    map.put("lawngreen", new Color(124, 252, 0));
    map.put("lemonchiffon", new Color(255, 250, 205));
    map.put("lightblue", new Color(173, 216, 230));
    map.put("lightcoral", new Color(240, 128, 128));
    map.put("lightcyan", new Color(224, 255, 255));
    map.put("lightgoldenrodyellow", new Color(250, 250, 210));
    map.put("lightgray", new Color(211, 211, 211));
    map.put("lightgreen", new Color(144, 238, 144));
    map.put("lightgrey", new Color(211, 211, 211));
    map.put("lightpink", new Color(255, 182, 193));
    map.put("lightsalmon", new Color(255, 160, 122));
    map.put("lightseagreen", new Color(32, 178, 170));
    map.put("lightskyblue", new Color(135, 206, 250));
    map.put("lightslategray", new Color(119, 136, 153));
    map.put("lightslategrey", new Color(119, 136, 153));
    map.put("lightsteelblue", new Color(176, 196, 222));
    map.put("lightyellow", new Color(255, 255, 224));
    map.put("lime", new Color(0, 255, 0));
    map.put("limegreen", new Color(50, 205, 50));
    map.put("linen", new Color(250, 240, 230));
    map.put("magenta", new Color(255, 0, 255));
    map.put("maroon", new Color(128, 0, 0));
    map.put("mediumaquamarine", new Color(102, 205, 170));
    map.put("mediumblue", new Color(0, 0, 205));
    map.put("mediumorchid", new Color(186, 85, 211));
    map.put("mediumpurple", new Color(147, 112, 219));
    map.put("mediumseagreen", new Color(60, 179, 113));
    map.put("mediumslateblue", new Color(123, 104, 238));
    map.put("mediumspringgreen", new Color(0, 250, 154));
    map.put("mediumturquoise", new Color(72, 209, 204));
    map.put("mediumvioletred", new Color(199, 21, 133));
    map.put("midnightblue", new Color(25, 25, 112));
    map.put("mintcream", new Color(245, 255, 250));
    map.put("mistyrose", new Color(255, 228, 225));
    map.put("moccasin", new Color(255, 228, 181));
    map.put("navajowhite", new Color(255, 222, 173));
    map.put("navy", new Color(0, 0, 128));
    map.put("oldlace", new Color(253, 245, 230));
    map.put("olive", new Color(128, 128, 0));
    map.put("olivedrab", new Color(107, 142, 35));
    map.put("orange", new Color(255, 165, 0));
    map.put("orangered", new Color(255, 69, 0));
    map.put("orchid", new Color(218, 112, 214));
    map.put("palegoldenrod", new Color(238, 232, 170));
    map.put("palegreen", new Color(152, 251, 152));
    map.put("paleturquoise", new Color(175, 238, 238));
    map.put("palevioletred", new Color(219, 112, 147));
    map.put("papayawhip", new Color(255, 239, 213));
    map.put("peachpuff", new Color(255, 218, 185));
    map.put("peru", new Color(205, 133, 63));
    map.put("pink", new Color(255, 192, 203));
    map.put("plum", new Color(221, 160, 221));
    map.put("powderblue", new Color(176, 224, 230));
    map.put("purple", new Color(128, 0, 128));
    map.put("red", new Color(255, 0, 0));
    map.put("rosybrown", new Color(188, 143, 143));
    map.put("royalblue", new Color(65, 105, 225));
    map.put("saddlebrown", new Color(139, 69, 19));
    map.put("salmon", new Color(250, 128, 114));
    map.put("sandybrown", new Color(244, 164, 96));
    map.put("seagreen", new Color(46, 139, 87));
    map.put("seashell", new Color(255, 245, 238));
    map.put("sienna", new Color(160, 82, 45));
    map.put("silver", new Color(192, 192, 192));
    map.put("skyblue", new Color(135, 206, 235));
    map.put("slateblue", new Color(106, 90, 205));
    map.put("slategray", new Color(112, 128, 144));
    map.put("slategrey", new Color(112, 128, 144));
    map.put("snow", new Color(255, 250, 250));
    map.put("springgreen", new Color(0, 255, 127));
    map.put("steelblue", new Color(70, 130, 180));
    map.put("tan", new Color(210, 180, 140));
    map.put("teal", new Color(0, 128, 128));
    map.put("thistle", new Color(216, 191, 216));
    map.put("tomato", new Color(255, 99, 71));
    map.put("turquoise", new Color(64, 224, 208));
    map.put("violet", new Color(238, 130, 238));
    map.put("wheat", new Color(245, 222, 179));
    map.put("white", new Color(255, 255, 255));
    map.put("whitesmoke", new Color(245, 245, 245));
    map.put("yellow", new Color(255, 255, 0));
    map.put("yellowgreen", new Color(154, 205, 50));

    // SVG 1.2 Tiny system colors
    map.put("activeborder", UIManager.getColor("activeCaptionBorder"));
    map.put("activecaption", UIManager.getColor("activeCaption"));
    map.put("appworkspace", UIManager.getColor("window"));
    map.put("background", UIManager.getColor("desktop"));
    map.put("buttonface", UIManager.getColor("control"));
    map.put("buttonhighlight", UIManager.getColor("controlHighlight"));
    map.put("buttonshadow", UIManager.getColor("controlShadow"));
    map.put("buttontext", UIManager.getColor("controlText"));
    map.put("captiontext", UIManager.getColor("activeCaptionText"));
    map.put("graytext", UIManager.getColor("textInactiveText"));
    map.put("highlight", UIManager.getColor("textHighlight"));
    map.put("highlighttext", UIManager.getColor("textHighlightText"));
    map.put("inactiveborder", UIManager.getColor("inactiveCaptionBorder"));
    map.put("inactivecaption", UIManager.getColor("inactiveCaption"));
    map.put("inactivecaptiontext", UIManager.getColor("inactiveCaptionText"));
    map.put("infobackground", UIManager.getColor("info"));
    map.put("infotext", UIManager.getColor("infoText"));
    map.put("menu", UIManager.getColor("menu"));
    map.put("menutext", UIManager.getColor("menuText"));
    map.put("scrollbar", UIManager.getColor("scrollbar"));
    map.put("threeddarkshadow", UIManager.getColor("controlDkShadow"));
    map.put("threedface", UIManager.getColor("control"));
    map.put("threedhighlight", UIManager.getColor("controlHighlight"));
    map.put("threedlightshadow", UIManager.getColor("controlLtHighlight"));
    map.put("threedshadow", UIManager.getColor("controlShadow"));
    map.put("window", UIManager.getColor("window"));
    map.put("windowframe", UIManager.getColor("windowBorder"));
    map.put("windowtext", UIManager.getColor("windowText"));

    SVG_COLORS = Collections.unmodifiableMap(map);
  }
コード例 #17
0
  public void drawSequence(
      Graphics2D g,
      Sequence seq,
      int start,
      int end,
      int x1,
      int y1,
      double width,
      int height,
      boolean showScores,
      boolean displayBoxes,
      boolean displayText,
      Vector pid,
      int seqnum,
      AlignViewport av,
      Hashtable props,
      int intpid[][]) {
    LinkedHashMap conf = av.getGFFConfig();
    boolean confchanged = false;
    int length = seq.getLength();

    Color currentColor = Color.white;

    g.setColor(Color.black);

    int prevx = -1;
    int prevy = -1;

    int prevpixel = 0;

    if (!(seq instanceof GFF)) {
      return;
    }
    height -= 2;

    GFF gff = (GFF) seq;

    double minscore = gff.getMinScore();
    double maxscore = gff.getMaxScore();

    minscore = (int) (minscore - (maxscore - minscore + 1) * 0.1);
    maxscore = (int) (maxscore + (maxscore - minscore + 1) * 0.1);

    if (gff.getType().equals("Patient_Flow")) {
      minscore = 1600;
    }
    // System.out.println("Min/Max " + minscore + " " + maxscore);
    Vector feat = gff.overlaps(start, end);

    // System.out.println("Got features " + feat.size());

    int prev = -1;
    for (int i = 0; i < feat.size(); i++) {

      SequenceFeature sftmp = (SequenceFeature) feat.elementAt(i);

      int coord = sftmp.getStart();

      if (coord >= minscore) {
        Color c = Color.black;

        String key = sftmp.getType();
        if (key.indexOf("::") > 0) {
          key = key.substring(0, key.indexOf("::"));
          sftmp.setType(key);
        }
        if (conf != null && conf.containsKey(sftmp.getType())) {
          c = (Color) (conf.get(sftmp.getType()));
          g.setColor(c);
        } else {

          // c = new
          // Color((int)(Math.random()*200+50),(int)(Math.random()*200+50),(int)(Math.random()*200+50));
          c = Color.black;
          conf.put(sftmp.getType(), c);
          g.setColor(c);
          confchanged = true;
        }

        Vector tmpf = new Vector();

        if (sftmp.getFeatures() != null) {
          tmpf = sftmp.getFeatures();
        } else {
          tmpf.addElement(sftmp);
        }

        int tmpheight = height;
        double score = sftmp.getScore();

        tmpheight = (int) ((score - minscore + 1) * (height) / (maxscore - minscore + 1));

        int tmpx = x1 + (int) ((coord - start) * width) + 1;
        int tmpy = y1 + height - tmpheight + 1;

        if (prevx == -1) {
          prevx = tmpx;
          prevy = tmpy;
        }

        if (tmpx - prevx <= 2) {
          g.drawLine(prevx, prevy, tmpx, tmpy);
        }

        prevx = tmpx;
        prevy = tmpy;
      }
      i++;
    }
  }
コード例 #18
0
ファイル: ViewerHistory.java プロジェクト: chhe/chatty
  /**
   * Draw the text and graph.
   *
   * @param g
   */
  @Override
  public void paintComponent(Graphics g) {
    locations.clear();

    // Background
    g.setColor(background_color);
    g.fillRect(0, 0, getWidth(), getHeight());

    // This color is used for everything until drawing the points
    g.setColor(foreground_color);

    // Anti-Aliasing
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Font
    FontMetrics fontMetrics = g.getFontMetrics(FONT);
    int fontHeight = fontMetrics.getHeight();
    g.setFont(FONT);

    int topTextY = fontMetrics.getAscent();

    // Margins
    int vMargin = fontHeight + MARGIN;
    int hMargin = MARGIN;

    // Calculate actual usable size
    double width = getWidth() - hMargin * 2;
    double height = getHeight() - vMargin * 2;

    boolean drawLowerLine = height > -vMargin;

    // If there is any data and no hovered entry is shown, draw current
    // viewercount
    int nowTextX = 0;
    if (history != null && hoverEntry == -1) {
      Integer viewers = history.get(endTime).getViewers();
      long ago = System.currentTimeMillis() - endTime;
      String text;
      if (ago > CONSIDERED_AS_NOW) {
        text = "latest: " + Helper.formatViewerCount(viewers);
      } else {
        text = "now: " + Helper.formatViewerCount(viewers);
      }
      if (viewers == -1) {
        text = "Stream offline";
      }
      nowTextX = getWidth() - fontMetrics.stringWidth(text);
      g.drawString(text, nowTextX, topTextY);
    }

    // Default text when no data is present
    if (history == null || history.size() < 2) {
      String text = "No viewer history yet";
      int textWidth = fontMetrics.stringWidth(text);
      int y = getHeight() / 2 + fontMetrics.getDescent();
      int x = (getWidth() - textWidth) / 2;
      boolean drawInfoText = false;
      if (history != null && y < topTextY + fontHeight + 4 && x + textWidth + 7 > nowTextX) {
        if (drawLowerLine || nowTextX > textWidth + 5) {
          if (drawLowerLine) {
            y = getHeight() - 2;
          } else {
            y = topTextY;
          }
          x = 0;
          drawInfoText = true;
        }
      } else {
        drawInfoText = true;
      }
      if (drawInfoText) {
        g.drawString(text, x, y);
      }
      return;
    }

    // ----------
    // From here only when actual data is to be rendered

    // Show info on hovered entry
    String maxValueText = "max: " + Helper.formatViewerCount(maxValue);
    int maxValueEnd = fontMetrics.stringWidth(maxValueText);
    boolean displayMaxValue = true;

    if (hoverEntry != -1) {
      Integer viewers = history.get(hoverEntry).getViewers();
      Date d = new Date(hoverEntry);
      String text = "Viewers: " + Helper.formatViewerCount(viewers) + " (" + sdf.format(d) + ")";
      if (viewers == -1) {
        text = "Stream offline (" + sdf.format(d) + ")";
      }
      int x = getWidth() - fontMetrics.stringWidth(text);
      if (maxValueEnd > x) {
        displayMaxValue = false;
      }
      g.drawString(text, x, topTextY);
    }

    String minText = "min: " + Helper.formatViewerCount(minValue);
    int minTextWidth = fontMetrics.stringWidth(minText);

    // Draw Times
    if (drawLowerLine) {
      String timeText = makeTimesText(startTime, endTime);
      int timeTextWidth = fontMetrics.stringWidth(timeText);
      int textX = getWidth() - timeTextWidth;
      g.drawString(timeText, textX, getHeight() - 1);

      if (minValue >= 1000 && timeTextWidth + minTextWidth > width) {
        minText = "min: " + minValue / 1000 + "k";
      }
    }

    // Draw min/max if necessary
    if (isShowingInfo()) {
      if (displayMaxValue) {
        g.drawString(maxValueText, 0, topTextY);
      }
      if (drawLowerLine) {
        g.drawString(minText, 0, getHeight() - 1);
      } else if (maxValueEnd + minTextWidth + 29 < nowTextX) {
        g.drawString(minText, maxValueEnd + 10, topTextY);
      }
    }

    // If height available for the graph is too small, don't draw graph
    if (height < 5) {
      return;
    }

    // Calculation factors for calculating the points location
    int range = maxValue - minValue;
    if (showFullRange) {
      range = maxValue;
    }
    if (range == 0) {
      // Prevent division by zero
      range = 1;
    }
    double pixelPerViewer = height / range;
    double pixelPerTime = width / duration;

    // Go through all entries and calculate positions

    int prevX = -1;
    int prevY = -1;
    Iterator<Entry<Long, StreamInfoHistoryItem>> it = history.entrySet().iterator();
    while (it.hasNext()) {
      Entry<Long, StreamInfoHistoryItem> entry = it.next();

      // Get time and value to draw next
      long time = entry.getKey();
      if (time < startTime || time > endTime) {
        continue;
      }
      long offsetTime = time - startTime;

      int viewers = entry.getValue().getViewers();
      if (viewers == -1) {
        viewers = 0;
      }

      // Calculate point location
      int x = (int) (hMargin + offsetTime * pixelPerTime);
      int y;
      if (showFullRange) {
        y = (int) (-vMargin + getHeight() - (viewers) * pixelPerViewer);
      } else {
        y = (int) (-vMargin + getHeight() - (viewers - minValue) * pixelPerViewer);
      }

      // Draw connecting line
      if (prevX != -1) {
        g.drawLine(x, y, prevX, prevY);
      }

      // Save point coordinates to be able to draw the line next loop
      prevX = x;
      prevY = y;

      // Save point locations to draw points and to find entries on hover
      locations.put(new Point(x, y), time);
    }

    // Draw points (after lines, so they are in front)
    for (Point point : locations.keySet()) {
      int x = point.x;
      int y = point.y;
      long seconds = locations.get(point);

      StreamInfoHistoryItem historyObject = history.get(seconds);

      // Highlight hovered entry
      if (seconds == hoverEntry) {
        g.setColor(HOVER_COLOR);
      } else {
        // Draw offline points differently
        if (!historyObject.isOnline()) {
          g.setColor(OFFLINE_COLOR);
        } else {
          g.setColor(colors.get(seconds));
        }
      }
      g.fillOval(x - POINT_SIZE / 2, y - POINT_SIZE / 2, POINT_SIZE, POINT_SIZE);
    }
  }