Changeset 27 in tmcsimulator-scriptbuilder for trunk


Ignore:
Timestamp:
07/30/2017 11:31:11 AM (9 years ago)
Author:
jdalbey
Message:

RangeSliderUI.java: Hacked so only lower thumb is displayed and dragging it adjusts the entire slider (as we would want an incident to do).

Location:
trunk/src/scriptbuilder/gui/drawers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/drawers/RangeSlider.java

    r26 r27  
    2626THE SOFTWARE. 
    2727 */ 
    28  
    2928/** 
    3029 * An extension of JSlider to select a range of values using two thumb controls. 
     
    104103        int oldExtent = getExtent(); 
    105104        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; 
    107107 
    108         // Set new value and extent, and fire 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(), 
    110110                getMaximum(), getValueIsAdjusting()); 
    111111    } 
  • trunk/src/scriptbuilder/gui/drawers/RangeSliderUI.java

    r26 r27  
    1515import javax.swing.JComponent; 
    1616import javax.swing.JMenuItem; 
     17import javax.swing.JOptionPane; 
    1718import javax.swing.JPopupMenu; 
    1819import javax.swing.JSlider; 
     
    4849 * UI delegate for the RangeSlider component. RangeSliderUI paints two thumbs, 
    4950 * one for the lower value and one for the upper value. 
     51 * 
     52 * Hacked to display and drag only the lower thumb by jdalbey 
    5053 */ 
    5154class RangeSliderUI extends BasicSliderUI 
     
    127130 
    128131    /** 
    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. 
    130134     */ 
    131135    @Override 
     
    342346    private void paintUpperThumb(Graphics g) 
    343347    { 
    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(); 
    367372    } 
    368373 
     
    493498        public void actionPerformed(ActionEvent e) 
    494499        { 
    495             System.out.println(e.getActionCommand() + " will be handled here."); 
     500            JOptionPane.showMessageDialog(null, e.getActionCommand() + " will be handled here."); 
    496501        } 
    497502    } 
     
    533538                if (upperThumbRect.contains(currentMouseX, currentMouseY)) 
    534539                { 
    535                     upperPressed = true; 
     540                    //upperPressed = true; 
    536541                } 
    537542                else if (thumbRect.contains(currentMouseX, currentMouseY)) 
     
    548553                else if (upperThumbRect.contains(currentMouseX, currentMouseY)) 
    549554                { 
    550                     upperPressed = true; 
     555                    //upperPressed = true; 
    551556                } 
    552557            } 
     
    566571                upperThumbSelected = false; 
    567572                lowerDragging = true; 
     573                // ALERT: Return from middle of method 
    568574                return; 
    569575            } 
     
    584590                upperThumbSelected = true; 
    585591                upperDragging = true; 
     592                // ALERT: Return from middle of method 
    586593                return; 
    587594            } 
     
    613620                slider.setValueIsAdjusting(true); 
    614621                moveLowerThumb(); 
    615  
     622                syncUpperThumb(); 
    616623            } 
    617624            else if (upperDragging) 
     
    657664                    thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight); 
    658665 
    659                     setThumbLocation(thumbRect.x, thumbTop); 
     666                    setThumbLocation(thumbRect.x, thumbTop); // repaint 
    660667 
    661668                    // Update slider value. 
     
    683690                    thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth); 
    684691 
    685                     setThumbLocation(thumbLeft, thumbRect.y); 
     692                    setThumbLocation(thumbLeft, thumbRect.y); //repaint 
    686693 
    687694                    // Update slider value. 
    688695                    thumbMiddle = thumbLeft + halfThumbWidth; 
    689696                    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. 
    690740                    break; 
    691741 
Note: See TracChangeset for help on using the changeset viewer.