class RangePanel extends javax.swing.JPanel {

    private final JQuickHistogram histogram;
    //Info
    private Object[] values;
    private RangeFilter filter;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel histogramPanel;
    private javax.swing.JPanel rangeSliderPanel;
    // End of variables declaration//GEN-END:variables

    public RangePanel() {
        initComponents();
        histogram = new JQuickHistogram();
        histogramPanel.add(histogram.getPanel());
        histogram.setConstraintHeight(30);
    }

    public void setup(final RangeFilter rangeFilter) {
        this.filter = rangeFilter;
        final Range range = (Range) rangeFilter.getRangeProperty().getValue();
        if (range == null) {
            //Do nothing
        } else {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    final JRangeSliderPanel rangeSlider = (JRangeSliderPanel) rangeSliderPanel;
                    values = range.getValues();

                    rangeSlider.addPropertyChangeListener(new PropertyChangeListener() {

                        @Override
                        public void propertyChange(PropertyChangeEvent evt) {<FILL_FUNCTION_BODY>}
                    });

                    SwingUtilities.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            rangeSlider.setRange(
                                JRangeSliderPanel.Range.build(
                                    rangeSlider, range.getMinimum(), range.getMaximum(), range.getLowerBound(),
                                    range.getUpperBound()
                                )
                            );
                        }
                    });
                    setupHistogram(rangeFilter, range);
                }
            }).start();
        }


        //Tooltip
        /*
         * histogram.getPanel().addMouseListener(new MouseAdapter() {
         *
         * RichTooltip richTooltip;
         *
         * @Override public void mouseEntered(MouseEvent e) { new Thread(new
         * Runnable() {
         *
         * public void run() { richTooltip = buildTooltip();
         *
         * SwingUtilities.invokeLater(new Runnable() {
         *
         * public void run() { if (richTooltip != null) {
         * richTooltip.showTooltip(histogram.getPanel()); } } }); } }).start();
         * }
         *
         * @Override public void mouseExited(MouseEvent e) { if (richTooltip !=
         * null) { richTooltip.hideTooltip(); richTooltip = null; } } });
         */
    }

    private void setupHistogram(final RangeFilter rangeFilter, final Range range) {
        histogram.clear();
        for (Object value : values) {
            histogram.addData(value);
        }
        histogram.sortData();
        double rangeLowerBound = 0.0;
        double rangeUpperBound = 0.0;
        if (range.getRangeType().equals(Integer.class)) {
            rangeLowerBound = range.getLowerBound().doubleValue();
            rangeUpperBound = range.getUpperBound().doubleValue();
        } else if (range.getRangeType().equals(Float.class)) {
            rangeLowerBound = range.getLowerBound().doubleValue();
            rangeUpperBound = range.getUpperBound().doubleValue();
        } else if (range.getRangeType().equals(Double.class)) {
            rangeLowerBound = ((Double) range.getLowerBound());
            rangeUpperBound = ((Double) range.getUpperBound());
        } else if (range.getRangeType().equals(Long.class)) {
            rangeLowerBound = range.getLowerBound().doubleValue();
            rangeUpperBound = range.getUpperBound().doubleValue();
        }
        histogram.setLowerBound(rangeLowerBound);
        histogram.setUpperBound(rangeUpperBound);

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                revalidate();
                repaint();
            }
        });
    }

    private RichTooltip buildTooltip() {
        if (histogram.countValues() == 0) {
            return null;
        }
        NumberFormat formatter = DecimalFormat.getNumberInstance();
        formatter.setMaximumFractionDigits(3);
        String average = formatter.format(histogram.getAverage());
        String averageInRange = formatter.format(histogram.getAverageInRange());
        RichTooltip richTooltip = new RichTooltip();
        richTooltip.setTitle("Statistics (In-Range)");
        richTooltip.addDescriptionSection(
            "<html><b># of Values:</b> " + histogram.countValues() + " (" + histogram.countInRange() + ")");
        richTooltip.addDescriptionSection("<html><b>Average:</b> " + average + " (" + averageInRange + ")");
        richTooltip.addDescriptionSection(
            "<html><b>Median:</b> " + histogram.getMedian() + " (" + histogram.getMedianInRange() + ")");
        return richTooltip;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rangeSliderPanel = new JRangeSliderPanel();
        histogramPanel = new javax.swing.JPanel();

        setOpaque(false);
        setLayout(new java.awt.BorderLayout());

        rangeSliderPanel.setOpaque(false);
        add(rangeSliderPanel, java.awt.BorderLayout.CENTER);

        histogramPanel.setOpaque(false);
        histogramPanel.setLayout(new java.awt.BorderLayout());
        add(histogramPanel, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents
}

                            try {
                                if (evt.getPropertyName().equals(JRangeSliderPanel.LOWER_BOUND)) {
                                    Range oldRange = (Range) filter.getRangeProperty().getValue();
                                    final Range newRange = new Range(rangeSlider.getRange().getLowerBound(),
                                        rangeSlider.getRange().getUpperBound(), oldRange.getMinimum(),
                                        oldRange.getMaximum(), oldRange.getValues());
                                    if (!oldRange.equals(newRange)) {
                                        filter.getRangeProperty().setValue(newRange);
                                        new Thread(new Runnable() {

                                            @Override
                                            public void run() {
                                                setupHistogram(filter, newRange);
                                            }
                                        }).start();
                                    }
                                } else if (evt.getPropertyName().equals(JRangeSliderPanel.UPPER_BOUND)) {
                                    final Range oldRange = (Range) filter.getRangeProperty().getValue();
                                    final Range newRange = new Range(rangeSlider.getRange().getLowerBound(),
                                        rangeSlider.getRange().getUpperBound(), oldRange.getMinimum(),
                                        oldRange.getMaximum(), oldRange.getValues());
                                    if (!oldRange.equals(newRange)) {
                                        filter.getRangeProperty().setValue(newRange);
                                        new Thread(new Runnable() {

                                            @Override
                                            public void run() {
                                                setupHistogram(filter, newRange);
                                            }
                                        }).start();
                                    }
                                }
                            } catch (Exception e) {
                                Logger.getLogger("").log(Level.SEVERE, "Error with range slider", e);
                            }
                        
<methods>public void <init>() ,public void <init>(java.awt.LayoutManager) ,public void <init>(boolean) ,public void <init>(java.awt.LayoutManager, boolean) ,public javax.accessibility.AccessibleContext getAccessibleContext() ,public javax.swing.plaf.PanelUI getUI() ,public java.lang.String getUIClassID() ,public void setUI(javax.swing.plaf.PanelUI) ,public void updateUI() <variables>private static final java.lang.String uiClassID