📄 speedscaleshell.java
字号:
return; } Point mousePos = display.getCursorLocation(); if (e.y > HEIGHT - SCALER_HEIGHT) { bMouseDown = true; setValue(getValueFromMousePos(e.x)); } } public void mouseDoubleClick(MouseEvent e) { } }); composite.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { int x = (int)(WIDTH_NO_PADDING * value / maxValue); if (x < 0) { x = 0; } else if (x > WIDTH_NO_PADDING) { x = WIDTH_NO_PADDING; } int startX = (int)(WIDTH_NO_PADDING * startValue / maxValue); if (startX < 0) { startX = 0; } else if (startX > WIDTH_NO_PADDING) { startX = WIDTH_NO_PADDING; } int baseLinePos = getBaselinePos(); try { e.gc.setAdvanced(true); e.gc.setAntialias(SWT.ON); } catch (Exception ex) { // aw } e.gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); // left e.gc.drawLine(PADDING_X0, baseLinePos - 6, PADDING_X0, baseLinePos + 6); // right e.gc.drawLine(PADDING_X0 + WIDTH_NO_PADDING, baseLinePos - 6, PADDING_X0 + WIDTH_NO_PADDING, baseLinePos + 6); // baseline e.gc.drawLine(PADDING_X0, baseLinePos, PADDING_X0 + WIDTH_NO_PADDING, baseLinePos); e.gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); e.gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); // start value marker e.gc.drawLine(PADDING_X0 + startX, baseLinePos - 5, PADDING_X0 + startX, baseLinePos + 5); // current value marker e.gc.fillRoundRectangle(PADDING_X0 + x - 2, baseLinePos - 5, 5, 10, 10, 10); // Current Value Text e.gc.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); e.gc.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); e.gc.fillRectangle(0, 0, WIDTH, TEXT_HEIGHT); GCStringPrinter.printString(e.gc,title+"\n"+ _getStringValue(), new Rectangle(0, 0, WIDTH, HEIGHT), true, false, SWT.CENTER | SWT.TOP | SWT.WRAP); e.gc.drawLine(0, TEXT_HEIGHT - 1, WIDTH, TEXT_HEIGHT - 1); // options list int y = TEXT_HEIGHT; Point mousePos = composite.toControl(display.getCursorLocation()); for (Iterator iter = mapOptions.keySet().iterator(); iter.hasNext();) { long value = (Long) iter.next(); String text = (String) mapOptions.get(value); Rectangle area = new Rectangle(0, y, WIDTH, OPTION_HEIGHT); Color bg; if (area.contains(mousePos)) { bg = display.getSystemColor(SWT.COLOR_LIST_SELECTION); e.gc.setBackground(bg); e.gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT)); e.gc.fillRectangle(area); } else { bg = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); e.gc.setBackground(bg); e.gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); } int ovalSize = OPTION_HEIGHT - 6; if (getValue() == value) { Color saveColor = e.gc.getBackground(); e.gc.setBackground(e.gc.getForeground()); e.gc.fillOval(4, y + 5, ovalSize - 3, ovalSize - 3); e.gc.setBackground(saveColor); } if (JMConstants.isLinux) { // Hack: on linux, drawing oval seems to draw a line from last pos // to start of oval.. drawing a point (anywhere) seems to clear the // path Color saveColor = e.gc.getForeground(); e.gc.setForeground(bg); e.gc.drawPoint(2, y + 3); e.gc.setForeground(saveColor); } e.gc.drawOval(2, y + 3, ovalSize, ovalSize); GCStringPrinter.printString(e.gc, text, new Rectangle(OPTION_HEIGHT, y, WIDTH - OPTION_HEIGHT, OPTION_HEIGHT), true, false, SWT.LEFT); y += OPTION_HEIGHT; } // typed value if (sValue.length() > 0) { Point extent = e.gc.textExtent(sValue); if (extent.x > WIDTH - 10) { extent.x = WIDTH - 10; } Rectangle rect = new Rectangle(WIDTH - 8 - extent.x, 14, extent.x + 5, extent.y + 4 + 14 > TEXT_HEIGHT ? TEXT_HEIGHT - 15 : extent.y + 4); e.gc.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); e.gc.fillRectangle(rect); try { e.gc.setAlpha(TYPED_TEXT_ALPHA); } catch (Exception ex) { } e.gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); e.gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); //e.gc.drawRectangle(rect); GCStringPrinter.printString(e.gc, sValue , new Rectangle(rect.x + 2, rect.y + 2, WIDTH - 5, OPTION_HEIGHT), true, false, SWT.LEFT | SWT.BOTTOM); } } }); Point location = display.getCursorLocation(); location.y -= getBaselinePos(); int x = (int) (WIDTH_NO_PADDING * (value > maxValue ? 1 : (double) value / maxValue)); location.x -= PADDING_X0 + x; Rectangle bounds = new Rectangle(location.x, location.y, WIDTH, HEIGHT); Monitor mouseMonitor = shell.getMonitor(); Monitor[] monitors = display.getMonitors(); for (int i = 0; i < monitors.length; i++) { Monitor monitor = monitors[i]; if (monitor.getBounds().contains(location)) { mouseMonitor = monitor; break; } } Rectangle monitorBounds = mouseMonitor.getBounds(); Rectangle intersection = monitorBounds.intersection(bounds); if (intersection.width != bounds.width) { bounds.x = monitorBounds.x + monitorBounds.width - WIDTH; bounds.width = WIDTH; } if (intersection.height != bounds.height) { bounds.y = monitorBounds.y + monitorBounds.height - HEIGHT; bounds.height = HEIGHT; } shell.setBounds(bounds); if (!bounds.contains(firstMousePos)) { // should never happen, which means it probably will, so handle it badly shell.setLocation(firstMousePos.x - (bounds.width / 2), firstMousePos.y - bounds.height + 2); } shell.open(); // must be after, for OSX composite.setFocus(); try { while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } catch (Throwable t) { } return !cancelled; } /** * @param x * @return * * @since 3.0.1.7 */ protected long getValueFromMousePos(int x) { int x0 = x + 1; if (x < PADDING_X0) { x0 = PADDING_X0; } else if (x > PADDING_X0 + WIDTH_NO_PADDING) { x0 = PADDING_X0 + WIDTH_NO_PADDING; } return (x0 - PADDING_X0) * maxValue / WIDTH_NO_PADDING; } public long getValue() { return value; } public boolean isCancelled() { return cancelled; } public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } public long getMinValue() { return minValue; } public void setMinValue(long minValue) { this.minValue = minValue; } public long getMaxValue() { return maxValue; } public void setMaxValue(long maxValue) { this.maxValue = maxValue; } public void setValue(long value) { //System.out.println("sv " + value + ";" + Debug.getCompressedStackTrace()); if (value > maxValue) { value = maxValue; } else if (value < minValue) { value = minValue; } this.value = value; if (composite != null && !composite.isDisposed()) { composite.redraw(); } } public String _getStringValue() { String name = (String) mapOptions.get(new Long(value)); return getStringValue(value, name); } public String getStringValue(long value, String sValue) { if (sValue != null) { return sValue + ""; } return SpeedFormatter.formatByteCountToKiBEtcPerSec(value * 1024,true); } private int getBaselinePos() { return HEIGHT - (SCALER_HEIGHT / 2); } public void addOption(String id, long value) { mapOptions.put(new Long(value), id); HEIGHT += OPTION_HEIGHT; } public long getMaxTextValue() { return maxTextValue; } public void setMaxTextValue(long maxTextValue) { this.maxTextValue = maxTextValue; } public boolean wasMenuChosen() { return menuChosen; } public void setMenuChosen(boolean menuChosen) { this.menuChosen = menuChosen; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -