Changeset 27 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui/drawers
- Timestamp:
- 07/30/2017 11:31:11 AM (9 years ago)
- Location:
- trunk/src/scriptbuilder/gui/drawers
- Files:
-
- 2 edited
-
RangeSlider.java (modified) (2 diffs)
-
RangeSliderUI.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/gui/drawers/RangeSlider.java
r26 r27 26 26 THE SOFTWARE. 27 27 */ 28 29 28 /** 30 29 * An extension of JSlider to select a range of values using two thumb controls. … … 104 103 int oldExtent = getExtent(); 105 104 int newValue = Math.min(Math.max(getMinimum(), value), oldValue + oldExtent); 106 int newExtent = oldExtent + oldValue - newValue; 105 // Hacked to not change the extent (move the entire slider) 106 //int newExtent = oldExtent + oldValue - newValue; 107 107 108 // Set new value and extent, andfire a single change event.109 getModel().setRangeProperties(newValue, newExtent, getMinimum(),108 // Set new value and fire a single change event. 109 getModel().setRangeProperties(newValue, oldExtent, getMinimum(), 110 110 getMaximum(), getValueIsAdjusting()); 111 111 } -
trunk/src/scriptbuilder/gui/drawers/RangeSliderUI.java
r26 r27 15 15 import javax.swing.JComponent; 16 16 import javax.swing.JMenuItem; 17 import javax.swing.JOptionPane; 17 18 import javax.swing.JPopupMenu; 18 19 import javax.swing.JSlider; … … 48 49 * UI delegate for the RangeSlider component. RangeSliderUI paints two thumbs, 49 50 * one for the lower value and one for the upper value. 51 * 52 * Hacked to display and drag only the lower thumb by jdalbey 50 53 */ 51 54 class RangeSliderUI extends BasicSliderUI … … 127 130 128 131 /** 129 * Updates the locations for both thumbs. 132 * Updates the locations for both thumbs if the value change is not caused 133 * by dragging a thumb. 130 134 */ 131 135 @Override … … 342 346 private void paintUpperThumb(Graphics g) 343 347 { 344 Rectangle knobBounds = upperThumbRect; 345 int w = knobBounds.width; 346 int h = knobBounds.height; 347 348 // Create graphics copy. 349 Graphics2D g2d = (Graphics2D) g.create(); 350 351 // Create default thumb shape. 352 Shape thumbShape = createThumbShape(w - 1, h - 1); 353 354 // Draw thumb. 355 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 356 RenderingHints.VALUE_ANTIALIAS_ON); 357 g2d.translate(knobBounds.x, knobBounds.y); 358 359 g2d.setColor(Color.PINK); 360 g2d.fill(thumbShape); 361 362 g2d.setColor(Color.RED); 363 g2d.draw(thumbShape); 364 365 // Dispose graphics. 366 g2d.dispose(); 348 // Remove drawing of upper thumb - jdalbey 349 // Rectangle knobBounds = upperThumbRect; 350 // int w = knobBounds.width; 351 // int h = knobBounds.height; 352 // 353 // // Create graphics copy. 354 // Graphics2D g2d = (Graphics2D) g.create(); 355 // 356 // // Create default thumb shape. 357 // Shape thumbShape = createThumbShape(w - 1, h - 1); 358 // 359 // // Draw thumb. 360 // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 361 // RenderingHints.VALUE_ANTIALIAS_ON); 362 // g2d.translate(knobBounds.x, knobBounds.y); 363 // 364 // g2d.setColor(Color.PINK); 365 // g2d.fill(thumbShape); 366 // 367 // g2d.setColor(Color.RED); 368 // g2d.draw(thumbShape); 369 // 370 // // Dispose graphics. 371 // g2d.dispose(); 367 372 } 368 373 … … 493 498 public void actionPerformed(ActionEvent e) 494 499 { 495 System.out.println(e.getActionCommand() + " will be handled here.");500 JOptionPane.showMessageDialog(null, e.getActionCommand() + " will be handled here."); 496 501 } 497 502 } … … 533 538 if (upperThumbRect.contains(currentMouseX, currentMouseY)) 534 539 { 535 upperPressed = true;540 //upperPressed = true; 536 541 } 537 542 else if (thumbRect.contains(currentMouseX, currentMouseY)) … … 548 553 else if (upperThumbRect.contains(currentMouseX, currentMouseY)) 549 554 { 550 upperPressed = true;555 //upperPressed = true; 551 556 } 552 557 } … … 566 571 upperThumbSelected = false; 567 572 lowerDragging = true; 573 // ALERT: Return from middle of method 568 574 return; 569 575 } … … 584 590 upperThumbSelected = true; 585 591 upperDragging = true; 592 // ALERT: Return from middle of method 586 593 return; 587 594 } … … 613 620 slider.setValueIsAdjusting(true); 614 621 moveLowerThumb(); 615 622 syncUpperThumb(); 616 623 } 617 624 else if (upperDragging) … … 657 664 thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight); 658 665 659 setThumbLocation(thumbRect.x, thumbTop); 666 setThumbLocation(thumbRect.x, thumbTop); // repaint 660 667 661 668 // Update slider value. … … 683 690 thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth); 684 691 685 setThumbLocation(thumbLeft, thumbRect.y); 692 setThumbLocation(thumbLeft, thumbRect.y); //repaint 686 693 687 694 // Update slider value. 688 695 thumbMiddle = thumbLeft + halfThumbWidth; 689 696 slider.setValue(valueForXPosition(thumbMiddle)); 697 break; 698 699 default: 700 return; 701 } 702 } 703 704 /** 705 * Moves the location of the upper thumb to be in sync with the lower 706 * thumb so that the extent is unchanged. 707 * 708 * @author jdalbey 709 */ 710 private void syncUpperThumb() 711 { 712 int thumbMiddle = 0; 713 714 switch (slider.getOrientation()) 715 { 716 case JSlider.HORIZONTAL: 717 int halfThumbWidth = thumbRect.width / 2; 718 int sliderLength = xPositionForValue(slider.getExtent()); 719 int thumbLeft = currentMouseX - offset + sliderLength; 720 int trackLeft = trackRect.x; 721 int trackRight = trackRect.x + (trackRect.width - 1); 722 int hMin = xPositionForValue(slider.getValue()); 723 724 // Handle backwards (inverted) slider 725 if (drawInverted()) 726 { 727 trackRight = hMin; 728 } 729 else 730 { 731 trackLeft = hMin; 732 } 733 // Apply bounds to thumb position. 734 thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth); 735 thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth); 736 737 setUpperThumbLocation(thumbLeft, thumbRect.y); // repaint slider 738 739 // Don't Update slider extent. 690 740 break; 691 741
Note: See TracChangeset
for help on using the changeset viewer.
