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()); }
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(); } } } } } }
/** * 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()); } } } } }
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()); }
/** * 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; }
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); } }
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(); } } }
@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; } } }
/** * 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; }
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; }
/** * 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); } }
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++; } }