~ubuntu-branches/ubuntu/trusty/libswingx-java/trusty

« back to all changes in this revision

Viewing changes to src/java/org/jdesktop/swingx/plaf/basic/BasicMultiThumbSliderUI.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2008-03-08 16:18:24 UTC
  • Revision ID: james.westby@ubuntu.com-20080308161824-wsahvl9pwzjcea3g
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
 
3
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
package org.jdesktop.swingx.plaf.basic;
 
21
 
 
22
import java.awt.Color;
 
23
import java.awt.Dimension;
 
24
import java.awt.Graphics;
 
25
import java.awt.Polygon;
 
26
 
 
27
import javax.swing.JComponent;
 
28
import javax.swing.plaf.ComponentUI;
 
29
 
 
30
import org.jdesktop.swingx.JXMultiThumbSlider;
 
31
import org.jdesktop.swingx.multislider.ThumbRenderer;
 
32
import org.jdesktop.swingx.multislider.TrackRenderer;
 
33
import org.jdesktop.swingx.plaf.MultiThumbSliderUI;
 
34
 
 
35
/**
 
36
 *
 
37
 * @author Joshua Marinacci
 
38
 */
 
39
public class BasicMultiThumbSliderUI extends MultiThumbSliderUI {
 
40
    
 
41
    protected JXMultiThumbSlider slider;
 
42
    
 
43
    public static ComponentUI createUI(JComponent c) {
 
44
        return new BasicMultiThumbSliderUI();
 
45
    }
 
46
    
 
47
    public void installUI(JComponent c) {
 
48
        slider = (JXMultiThumbSlider)c;
 
49
        slider.setThumbRenderer(new BasicThumbRenderer());
 
50
        slider.setTrackRenderer(new BasicTrackRenderer());        
 
51
    }
 
52
    public void uninstallUI(JComponent c) {
 
53
        slider = null;
 
54
    }
 
55
 
 
56
    private class BasicThumbRenderer extends JComponent implements ThumbRenderer {
 
57
        public BasicThumbRenderer() {
 
58
            setPreferredSize(new Dimension(14,14));
 
59
        }
 
60
 
 
61
        protected void paintComponent(Graphics g) {
 
62
            g.setColor(Color.green);
 
63
            Polygon poly = new Polygon();
 
64
            JComponent thumb = this;
 
65
            poly.addPoint(thumb.getWidth()/2,0);
 
66
            poly.addPoint(0,thumb.getHeight()/2);
 
67
            poly.addPoint(thumb.getWidth()/2,thumb.getHeight());
 
68
            poly.addPoint(thumb.getWidth(),thumb.getHeight()/2);
 
69
            g.fillPolygon(poly);
 
70
        }
 
71
 
 
72
        public JComponent getThumbRendererComponent(JXMultiThumbSlider slider, int index, boolean selected) {
 
73
            return this;
 
74
        }
 
75
    }
 
76
 
 
77
    private class BasicTrackRenderer extends JComponent implements TrackRenderer {
 
78
        private JXMultiThumbSlider slider;
 
79
        public void paintComponent(Graphics g) {
 
80
            g.setColor(slider.getBackground());
 
81
            g.fillRect(0, 0, slider.getWidth(), slider.getHeight());
 
82
            g.setColor(Color.black);
 
83
            g.drawLine(0,slider.getHeight()/2,slider.getWidth(),slider.getHeight()/2);
 
84
            g.drawLine(0,slider.getHeight()/2+1,slider.getWidth(),slider.getHeight()/2+1);
 
85
        }
 
86
 
 
87
        public JComponent getRendererComponent(JXMultiThumbSlider slider) {
 
88
            this.slider = slider;
 
89
            return this;
 
90
        }
 
91
    }
 
92
}