@Override protected void onUpdate(double progress) { if (progress > 1) { progress = 1; } model.setX((int) Math.round(progress * targetX + (1 - progress) * model.getX())); model.setY((int) Math.round(progress * targetY + (1 - progress) * model.getY())); model.notifyUpdate(); }
private void initialise(double width, double height, double percentage) { this.percentage = percentage; updateValueBox(percentage); initHandlers(); double tick = height / 7.0; double y = tick * 3; int cR = (int) Math.round(tick * 2); int cX = (int) Math.round((width - (2 * cR)) * (percentage - min) / (max - min)) + cR; int cY = (int) Math.round(height / 2.0); this.pin = new SliderPin(cX, cY, cR); this.bar = new SliderBar(tick, y, cR); this.draw(); }
@Override public void addMatches(ArrayList<FindResult> findResults) { int matchesToAdd = Math.min(findResults.size(), MAX_COUNT - matchCount_); if (matchesToAdd > 0) { matchCount_ += matchesToAdd; table_.addItems(findResults.subList(0, matchesToAdd), false); } if (matchesToAdd != findResults.size()) showOverflow(); }
public Rectangle getPositionBounds(InputEditorPosition position) { Renderer renderer = widget_.getEditor().getRenderer(); Position pos = ((AceInputEditorPosition) position).getValue(); ScreenCoordinates start = renderer.textToScreenCoordinates(pos.getRow(), pos.getColumn()); return new Rectangle( start.getPageX(), start.getPageY(), (int) Math.round(renderer.getCharacterWidth()), (int) (renderer.getLineHeight() * 0.8)); }
public void setValue(double value) { if (value < min) { value = min; } else if (value > max) { value = max; } int cX = (int) (Math.round( (this.canvas.getOffsetWidth() - (2 * this.pin.r)) * (value - min) / (max - min)) + this.pin.r); Point pos = new Point(cX, this.pin.pos.y); this.pin.setNewPos(pos); this.draw(); checkPinMoved(); }
private void updateTitleFromFileTable() { // User edited the title field. We have no business here if (userEditedTitle) { return; } List<String> names = files.getFileNames(); if (names.size() == 0) { setTitleText(""); } else { Iterator<String> iterator = names.iterator(); String longestPrefix = iterator.next(); while (iterator.hasNext()) { String next = iterator.next(); for (int i = 0; i < Math.min(longestPrefix.length(), next.length()); i++) { if (next.charAt(i) != longestPrefix.charAt(i)) { longestPrefix = longestPrefix.substring(0, i); break; } } } // The users like to name files with underscores separating different fields. // If we detect more than 1 underscore, we will try to remove everything beyond the last // underscore // That takes care of test_S1, test_S2, test_S3 or test_Inj1, test_Inj2 type of repeats, // resulting // with just "test". // If there is just one underscore, we remove it if it is the last one. int numUnderscores = longestPrefix.length() - longestPrefix.replaceAll("_", "").length(); if (numUnderscores <= 1) { longestPrefix = longestPrefix.replaceAll("_$", ""); } else { longestPrefix = longestPrefix.replaceAll("_[^_]*$", ""); } setTitleText(longestPrefix + paramsEditor.getTitleSuffix()); } updateOutputLocation(); }
@Override public void highlightDebugLocation( SourcePosition startPosition, SourcePosition endPosition, boolean executing) { int firstRow = widget_.getEditor().getFirstVisibleRow(); int lastRow = widget_.getEditor().getLastVisibleRow(); // if the expression is large, let's just try to land in the middle int debugRow = (int) Math.floor( startPosition.getRow() + (endPosition.getRow() - startPosition.getRow()) / 2); // if the row at which the debugging occurs is inside a fold, unfold it getSession().unfold(debugRow, true); // if the line to be debugged is past or near the edges of the screen, // scroll it into view. allow some lines of context. if (debugRow <= (firstRow + DEBUG_CONTEXT_LINES) || debugRow >= (lastRow - DEBUG_CONTEXT_LINES)) { widget_.getEditor().scrollToLine(debugRow, true); } applyDebugLineHighlight(startPosition.asPosition(), endPosition.asPosition(), executing); }
public int getCharacterWidth() { // create width checker label and add it to the root panel Label widthChecker = new Label(); widthChecker.setStylePrimaryName(styles_.console()); FontSizer.applyNormalFontSize(widthChecker); RootPanel.get().add(widthChecker, -1000, -1000); // put the text into the label, measure it, and remove it String text = new String("abcdefghijklmnopqrstuvwzyz0123456789"); widthChecker.setText(text); int labelWidth = widthChecker.getOffsetWidth(); RootPanel.get().remove(widthChecker); // compute the points per character int pointsPerCharacter = labelWidth / text.length(); // compute client width int clientWidth = getElement().getClientWidth(); int offsetWidth = getOffsetWidth(); if (clientWidth == offsetWidth) { // if the two widths are the same then there are no scrollbars. // however, we know there will eventually be a scrollbar so we // should offset by an estimated amount // (is there a more accurate way to estimate this?) final int ESTIMATED_SCROLLBAR_WIDTH = 19; clientWidth -= ESTIMATED_SCROLLBAR_WIDTH; } // compute character width (add pad so characters aren't flush to right) final int RIGHT_CHARACTER_PAD = 2; int width = (clientWidth / pointsPerCharacter) - RIGHT_CHARACTER_PAD; // enforce a minimum width final int MINIMUM_WIDTH = 30; return Math.max(width, MINIMUM_WIDTH); }
private double getPercentageFromPinPosition() { int x = this.pin.pos.x - (int) this.pin.r; double w = this.canvas.getOffsetWidth() - 2 * this.pin.r; return Math.round(((x * (max - min) / w) + min) * 100) / 100.0; }
@Override public void moveCursorNearTop(int rowOffset) { int screenRow = getSession().documentToScreenRow(getCursorPosition()); widget_.getEditor().scrollToRow(Math.max(0, screenRow - rowOffset)); }
/** Limits value to [min, max], so that min <= value <= max. */ private static int limit(int min, int value, int max) { return Math.min(Math.max(min, value), max); }