OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
17 ilm 5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 /*
15
 * Created on 26 mai 2005
16
 *
17
 * To change the template for this generated file go to Window>Preferences>Java>Code
18
 * Generation>Code and Comments
19
 */
20
package org.openconcerto.laf;
21
 
22
import java.awt.Color;
23
import java.awt.Dimension;
24
import java.awt.Graphics;
25
import java.awt.Image;
26
import java.awt.Rectangle;
27
import java.awt.event.MouseEvent;
28
 
29
import javax.swing.ImageIcon;
30
import javax.swing.JButton;
31
import javax.swing.JComponent;
32
import javax.swing.JScrollBar;
33
import javax.swing.plaf.ComponentUI;
34
import javax.swing.plaf.basic.BasicScrollBarUI;
35
 
36
public class IScrollBarUI extends BasicScrollBarUI {
37
 
38
    private static final Color COLOR_DARK = new Color(140, 141, 121);
39
 
40
    /**
41
     * The scrollbar's highlight color.
42
     */
43
    private static Color highlightColor;
44
 
45
    /**
46
     * The scrollbar's dark shadow color.
47
     */
48
    private static Color darkShadowColor;
49
 
50
    /**
51
     * The thumb's shadow color.
52
     */
53
    private static Color thumbShadow;
54
 
55
    /**
56
     * The thumb's highlight color.
57
     */
58
    private static Color thumbHighlightColor;
59
 
60
    /** true if thumb is in rollover state */
61
    protected boolean isRollover = false;
62
 
63
    /** true if thumb was in rollover state */
64
    protected boolean wasRollover = false;
65
 
66
    /**
67
     * The free standing property of this scrollbar UI delegate.
68
     */
69
    private boolean freeStanding = false;
70
 
71
    int scrollBarWidth;
72
 
73
    Image h, b;
74
 
75
    public IScrollBarUI() {
76
    }
77
 
78
    /**
79
     * Installs some default values. Initializes the metouia dots used for the thumb.
80
     */
81
    protected void installDefaults() {
82
        scrollBarWidth = 13;
83
        super.installDefaults();
84
        scrollbar.setBorder(null);
80 ilm 85
        this.h = new ImageIcon(IScrollBarUI.class.getResource("scrollHaut.png")).getImage();
86
        this.b = new ImageIcon(IScrollBarUI.class.getResource("scrollBas.png")).getImage();
17 ilm 87
 
88
    }
89
 
90
    /**
91
     * Creates the UI delegate for the given component.
92
     *
93
     * @param c The component to create its UI delegate.
94
     * @return The UI delegate for the given component.
95
     */
96
    public static ComponentUI createUI(JComponent c) {
97
        return new IScrollBarUI();
98
    }
99
 
100
    JButton decreaseButton, increaseButton;
101
 
102
    /**
103
     * Creates the decrease button of the scrollbar.
104
     *
105
     * @param orientation The button's orientation.
106
     * @return The created button.
107
     */
108
    protected JButton createDecreaseButton(int orientation) {
109
 
110
        if (orientation == NORTH) {
111
            this.decreaseButton = new JButton(new ImageIcon(getClass().getResource("up.png")));
112
        } else {
113
            this.decreaseButton = new JButton(new ImageIcon(getClass().getResource("left.png")));
114
        }
115
        this.decreaseButton.setBorder(null);
116
        // decreaseButton = new IScrollBarUI(orientation, scrollBarWidth,
117
        // freeStanding);
118
        return this.decreaseButton;
119
    }
120
 
121
    /**
122
     * Creates the increase button of the scrollbar.
123
     *
124
     * @param orientation The button's orientation.
125
     * @return The created button.
126
     */
127
    protected JButton createIncreaseButton(int orientation) {
128
 
129
        if (orientation == SOUTH) {
130
            this.increaseButton = new JButton(new ImageIcon(getClass().getResource("down.png")));
131
        } else {
132
            this.increaseButton = new JButton(new ImageIcon(getClass().getResource("right.png")));
133
        }
134
 
135
        this.increaseButton.setBorder(null);
136
        // increaseButton = new XPScrollButton(orientation, scrollBarWidth,
137
        // freeStanding);
138
        return this.increaseButton;
139
    }
140
 
141
    // / From MetalUI
142
 
143
    public Dimension getPreferredSize(JComponent c) {
144
        if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
145
            return new Dimension(scrollBarWidth, scrollBarWidth * 3 + 10);
146
        } else // Horizontal
147
        {
148
            return new Dimension(scrollBarWidth * 3 + 10, scrollBarWidth);
149
        }
150
 
151
    }
152
 
153
    public void paint(Graphics g, JComponent c) {
154
        Rectangle trackBounds = getTrackBounds();
155
        g.setColor(new Color(255, 0, 0));
156
        drawFond(g, 0, trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
157
 
158
        Rectangle thumbBounds = getThumbBounds();
159
 
160
        // int index = skinThumbIndexModel.getIndexForState(c.isEnabled(),
161
        // isRollover, isDragging);
162
        /*
163
         * getSkinThumb().draw(g, index, thumbBounds.x, thumbBounds.y, thumbBounds.width,
164
         * thumbBounds.height);
165
         *
166
         * getSkinGripper().drawCentered(g, index, thumbBounds.x, thumbBounds.y, thumbBounds.width,
167
         * thumbBounds.height);
168
         */
169
        drawThumb(g, thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height);
170
    }
171
 
172
    private void drawThumb(Graphics g, int x, int y, int width, int height) {
173
 
174
        x++;
175
        y++;
176
        width -= 3;
177
        height -= 2;
178
 
179
        g.setColor(new Color(244, 244, 240));
180
        g.fillRect(x, y, width, height);
181
        // Tour
182
        g.setColor(COLOR_DARK);
183
        g.drawRect(x, y, width + 1, height);
184
        // gauche
185
        g.setColor(new Color(252, 252, 251));
186
        g.drawLine(x + 1, y + 1, x + 1, y + height - 5);
187
        // droite 225,225,214
188
        g.setColor(new Color(225, 225, 214));
189
        g.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 5);
190
        // droite-1237,237,231
191
        g.setColor(new Color(237, 237, 231));
192
        g.drawLine(x + width - 2, y + 1, x + width - 2, y + height - 5);
193
 
194
        // milieu 244,244,240
195
        //haut
196
        g.drawImage(h, x  + width -8, y + 1, null);
197
        //bas
198
        g.drawImage(b, x  + width - 8, y + height - 5, null);
199
 
200
        g.setColor(COLOR_DARK);
201
 
202
        // Scroll vertical
203
        if(height>width) {
204
            int yindex = y + height / 2;
205
            g.drawLine(x + 4, yindex - 3, x + width - 4, yindex - 3);
206
            g.drawLine(x + 4, yindex, x + width - 4, yindex);
207
            g.drawLine(x + 4, yindex + 3, x + width - 4, yindex + 3);
208
        }else {
209
            int xindex = x + width / 2;
210
 
211
            g.drawLine(xindex-3,y+4, xindex-3, y+height-4);
212
            g.drawLine(xindex,y+4, xindex, y+height-4);
213
            g.drawLine(xindex+3,y+4, xindex+3, y+height-4);
214
 
215
 
216
        }
217
    }
218
 
219
    private void drawFond(Graphics g, int i, int x, int y, int width, int height) {
220
        g.setColor(new Color(239, 235, 231));
221
        g.fillRect(x, y, width, height);
222
 
223
    }
224
 
225
    public boolean isThumbVisible() {
226
        if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
227
            if (getThumbBounds().height == 0)
228
                return false;
229
            else
230
                return true;
231
        } else {
232
            if (getThumbBounds().width == 0)
233
                return false;
234
            else
235
                return true;
236
        }
237
    }
238
 
239
    // From BasicUI
240
    protected TrackListener createTrackListener() {
241
        return new MyTrackListener();
242
    }
243
 
244
    /**
245
     * Basically does BasicScrollBarUI.TrackListener the right job, it just needs an additional
246
     * repaint and rollover management
247
     */
248
    protected class MyTrackListener extends BasicScrollBarUI.TrackListener {
249
        public void mouseReleased(MouseEvent e) {
250
            super.mouseReleased(e);
251
            scrollbar.repaint();
252
        }
253
 
254
        public void mousePressed(MouseEvent e) {
255
            super.mousePressed(e);
256
            scrollbar.repaint();
257
        }
258
 
259
        public void mouseEntered(MouseEvent e) {
260
            isRollover = false;
261
            wasRollover = false;
262
            if (getThumbBounds().contains(e.getX(), e.getY())) {
263
                isRollover = true;
264
            }
265
        }
266
 
267
        public void mouseExited(MouseEvent e) {
268
            isRollover = false;
269
            if (isRollover != wasRollover) {
270
                scrollbar.repaint();
271
                wasRollover = isRollover;
272
            }
273
        }
274
 
275
        public void mouseDragged(MouseEvent e) {
276
            if (getThumbBounds().contains(e.getX(), e.getY())) {
277
                isRollover = true;
278
            }
279
            super.mouseDragged(e);
280
        }
281
 
282
        public void mouseMoved(MouseEvent e) {
283
            if (getThumbBounds().contains(e.getX(), e.getY())) {
284
                isRollover = true;
285
                if (isRollover != wasRollover) {
286
                    scrollbar.repaint();
287
                    wasRollover = isRollover;
288
                }
289
            } else {
290
                isRollover = false;
291
                if (isRollover != wasRollover) {
292
                    scrollbar.repaint();
293
                    wasRollover = isRollover;
294
                }
295
            }
296
        }
297
    }
298
 
299
}