]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/PixxMenuBar.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / gui / pixx / PixxMenuBar.java
1 /*****************************************************/
2 /*          This java file is a part of the          */
3 /*                                                   */
4 /*           -  Plouf's Java IRC Client  -           */
5 /*                                                   */
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */
7 /*                                                   */
8 /*         All contacts : theplouf@yahoo.com         */
9 /*                                                   */
10 /*  PJIRC is free software; you can redistribute     */
11 /*  it and/or modify it under the terms of the GNU   */
12 /*  General Public License as published by the       */
13 /*  Free Software Foundation; version 2 or later of  */
14 /*  the License.                                     */
15 /*                                                   */
16 /*  PJIRC is distributed in the hope that it will    */
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */
18 /*  even the implied warranty of MERCHANTABILITY or  */
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */
20 /*  General Public License for more details.         */
21 /*                                                   */
22 /*  You should have received a copy of the GNU       */
23 /*  General Public License along with PJIRC; if      */
24 /*  not, write to the Free Software Foundation,      */
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */
26 /*  MA  02111-1307  USA                              */
27 /*                                                   */
28 /*****************************************************/
29
30 package irc.gui.pixx;
31
32 import irc.IRCConfiguration;
33 import irc.ListenerGroup;
34 import irc.StyleContext;
35 import irc.style.DecodedLine;
36 import irc.style.DrawResult;
37 import irc.style.FormattedStringDrawer;
38 import irc.style.FormattedStringDrawerListener;
39
40 import java.awt.Color;
41 import java.awt.Cursor;
42 import java.awt.Dimension;
43 import java.awt.Font;
44 import java.awt.Graphics;
45 import java.awt.Image;
46 import java.awt.event.MouseEvent;
47 import java.awt.event.MouseListener;
48 import java.awt.event.MouseMotionListener;
49
50 /**
51  * The menu bar.
52  */
53 public class PixxMenuBar extends PixxPanel implements MouseListener, MouseMotionListener, Runnable,
54                 FormattedStringDrawerListener {
55
56         private int _pressedIndex;
57         private boolean _closePressed;
58         private boolean _dockPressed;
59         private ListenerGroup _listeners;
60         private boolean _connected;
61         private boolean _title;
62         private Image _buffer;
63         private FormattedStringDrawer _drawer;
64         private String _titleString;
65         private DecodedLine _decodedTitle;
66         private int _connectIndex;
67         private int _chanlistIndex;
68         private int _aboutIndex;
69         private int _helpIndex;
70         private int _titleLeft;
71         private int _mouseDownX;
72         private boolean _mouseScroll;
73         private DrawResult _drawResult;
74         private boolean _terminated;
75         private boolean _redrawTitle;
76         private Thread _scrollThread;
77         private Object _scrollLock;
78         private boolean _freeze;
79         private int _scrollDelay;
80
81         /**
82          * Create a new PixxMenuBar without title displayed.
83          * 
84          * @param config
85          *          the global irc configuration.
86          */
87         public PixxMenuBar(PixxConfiguration config) {
88                 this(config, false);
89         }
90
91         /**
92          * Create a new PixxMenuBar.
93          * 
94          * @param config
95          *          the global irc configuration.
96          * @param title
97          *          true if this menu bar should display its own title, false
98          *          otherwise.
99          */
100         public PixxMenuBar(PixxConfiguration config, boolean title) {
101                 super(config);
102                 _titleLeft = 0;
103                 _title = title;
104                 _mouseScroll = false;
105                 _titleString = "";
106                 IRCConfiguration _ircConfiguration = config.getIRCConfiguration();
107                 _drawer = new FormattedStringDrawer(_ircConfiguration, _ircConfiguration.getDefaultStyleContext(), this);
108                 _decodedTitle = _drawer.decodeLine(_titleString);
109                 _connected = false;
110                 _pressedIndex = -1;
111                 _closePressed = false;
112                 _dockPressed = false;
113                 _listeners = new ListenerGroup();
114                 int currentIndex = 0;
115                 if (config.getB("showconnect"))
116                         _connectIndex = currentIndex++;
117                 if (config.getB("showchanlist"))
118                         _chanlistIndex = currentIndex++;
119                 if (config.getB("showabout"))
120                         _aboutIndex = currentIndex++;
121                 if (config.getB("showhelp"))
122                         _helpIndex = currentIndex++;
123                 _scrollDelay = config.getI("scrollspeed");
124                 if (_scrollDelay != 0)
125                         _scrollDelay = 1000 / _scrollDelay;
126                 _drawResult = new DrawResult();
127                 addMouseListener(this);
128                 addMouseMotionListener(this);
129                 _terminated = false;
130                 _redrawTitle = false;
131                 _scrollLock = new Object();
132                 if (_scrollDelay > 0) {
133                         _scrollThread = new Thread(this);
134                         _scrollThread.start();
135                 }
136         }
137
138         @Override
139         public void release() {
140                 removeMouseListener(this);
141                 removeMouseMotionListener(this);
142                 super.release();
143         }
144
145         /**
146          * Set title.
147          * 
148          * @param title
149          *          title string.
150          * @param context
151          *          title style context.
152          */
153         public void setTitle(String title, StyleContext context) {
154                 _drawer.setStyleContext(context);
155                 _titleString = title;
156                 _decodedTitle = _drawer.decodeLine(_titleString);
157                 _buffer = null;
158                 repaint();
159         }
160
161         /**
162          * Add listener.
163          * 
164          * @param lis
165          *          listener to add.
166          */
167         public void addPixxMenuBarListener(PixxMenuBarListener lis) {
168                 _listeners.addListener(lis);
169         }
170
171         /**
172          * Remove listener.
173          * 
174          * @param lis
175          *          listener to remove.
176          */
177         public void removePixxMenuBarListener(PixxMenuBarListener lis) {
178                 _listeners.removeListener(lis);
179         }
180
181         /**
182          * Set the connected flag.
183          * 
184          * @param b
185          *          true if application is connected to the server, false otherwise.
186          */
187         public void setConnected(boolean b) {
188                 _connected = b;
189                 _buffer = null;
190                 repaint();
191         }
192
193         @Override
194         public Dimension getPreferredSize() {
195                 if (_title)
196                         return new Dimension(16, getItemHeight() + getTitleHeight() + 4);
197                 return new Dimension(16, getItemHeight() + 4);
198         }
199
200         private int getClosePositionX() {
201                 int w = getSize().width;
202                 return w - 18;
203         }
204
205         private int getClosePositionY() {
206                 return getY(0) + 1;
207         }
208
209         private int getDockPositionX() {
210                 int w = getSize().width;
211                 if (!_pixxConfiguration.getB("showclose"))
212                         return w - 18;
213                 return w - 18 - 18;
214         }
215
216         private int getDockPositionY() {
217                 return getY(0) + 1;
218         }
219
220         private boolean isClosePressed(int x, int y) {
221                 if (!_pixxConfiguration.getB("showclose"))
222                         return false;
223                 x -= getClosePositionX();
224                 if (x < 0)
225                         return false;
226                 if (x >= 16)
227                         return false;
228                 y -= getClosePositionY();
229                 if (y < 0)
230                         return false;
231                 if (y >= 16)
232                         return false;
233                 return true;
234         }
235
236         private boolean isDockPressed(int x, int y) {
237                 if (!_pixxConfiguration.getB("showdock"))
238                         return false;
239                 x -= getDockPositionX();
240                 if (x < 0)
241                         return false;
242                 if (x >= 16)
243                         return false;
244                 y -= getDockPositionY();
245                 if (y < 0)
246                         return false;
247                 if (y >= 16)
248                         return false;
249                 return true;
250         }
251
252         private int getItemWidth() {
253                 return 100;
254         }
255
256         private int getItemHeight() {
257                 return 17;
258         }
259
260         private int getIconWidth() {
261                 return 16;
262         }
263
264         private int getIconHeight() {
265                 return getItemHeight() - 4;
266         }
267
268         private int getX(int pos) {
269                 return pos * (getItemWidth() + 8) + 2;
270         }
271
272         private int getPos(int x) {
273                 return (x - 2) / (getItemWidth() + 8);
274         }
275
276         private int getY(int pos) {
277                 if (!_title)
278                         return 2;
279                 return 2 + getTitleHeight() * 0;
280         }
281
282         private int getTitleY() {
283                 // return 0;
284                 return getItemHeight() + 4;
285         }
286
287         private int getTitleHeight() {
288                 return 18;
289         }
290
291         private int getIndex(int x) {
292                 int pos = getPos(x);
293                 if (pos < 0)
294                         return -1;
295                 if (pos > 4)
296                         return -1;
297                 x -= getX(pos);
298                 if (x >= getItemWidth())
299                         return -1;
300                 return pos;
301         }
302
303         private int getIndex(int x, int y) {
304                 if (y < getY(0))
305                         return -1;
306                 y -= getY(0);
307                 if (y >= getItemHeight())
308                         return -1;
309                 return getIndex(x);
310         }
311
312         private void drawTitle(Graphics g, int y) {
313                 int w = getSize().width;
314
315                 g.setColor(_drawer.getColor(0));
316                 g.fillRect(0, y, w, getTitleHeight());
317                 g.setClip(0, y, w, getTitleHeight());
318                 _drawer.draw(_decodedTitle, g, 5 + _titleLeft, w - 5 + _titleLeft, y + getTitleHeight() - 2, 0, w - 1, false,
319                                 false, _drawResult);
320                 g.setClip(0, 0, getSize().width, getSize().height);
321
322                 drawSeparator(g, 0, y, w, getTitleHeight());
323         }
324
325         private void drawDisconnectIcon(Graphics g, int x, int y) {
326                 int w = getIconWidth();
327                 int h = getIconHeight();
328                 g.setColor(new Color(0xEFEFEF));
329                 g.fillRect(x, y, w, h);
330
331                 g.setColor(new Color(0xAFAFAF));
332                 g.drawLine(x, y + h / 2 - 1, x + 5, y + h / 2 - 1);
333                 g.drawLine(x + w - 1, y + h / 2 - 1, x + w - 5, y + h / 2 - 1);
334                 g.setColor(Color.black);
335                 g.drawLine(x, y + h / 2, x + 4, y + h / 2);
336                 g.drawLine(x + w - 1, y + h / 2, x + w - 6, y + h / 2);
337
338                 g.drawLine(x + 4, y + h / 2 + 1, x + 7, y + h / 2 - 2);
339                 g.drawLine(x + 8, y + h / 2 + 1, x + 11, y + h / 2 - 2);
340         }
341
342         private void drawConnectIcon(Graphics g, int x, int y) {
343                 int w = getIconWidth();
344                 int h = getIconHeight();
345                 g.setColor(new Color(0xEFEFEF));
346                 g.fillRect(x, y, w, h);
347
348                 g.setColor(new Color(0xA2A2A2));
349                 g.drawLine(x, y + h / 2 - 1, x + w - 1, y + h / 2 - 1);
350                 g.setColor(Color.black);
351                 g.drawLine(x, y + h / 2, x + w - 1, y + h / 2);
352
353                 g.setColor(new Color(0x960000));
354                 g.drawLine(x + 2, y + 2, x + 14, y + 2);
355                 g.drawLine(x + 12, y, x + 14, y + 2);
356                 g.drawLine(x + 12, y + 4, x + 14, y + 2);
357
358                 g.setColor(new Color(0x2A5B90));
359                 g.drawLine(x + 2, y + 9, x + 14, y + 9);
360                 g.drawLine(x + 2, y + 9, x + 4, y + 7);
361                 g.drawLine(x + 2, y + 9, x + 4, y + 11);
362         }
363
364         private void drawChanListIcon(Graphics g, int x, int y) {
365                 int w = getIconWidth();
366                 int h = getIconHeight();
367                 g.setColor(new Color(0xEFEFEF));
368                 g.fillRect(x, y, w, h);
369                 g.setColor(Color.black);
370                 x++;
371                 g.drawLine(x, y + 1, x + 9, y + 1);
372                 g.drawLine(x, y + 3, x + 5, y + 3);
373                 g.drawLine(x, y + 5, x + 12, y + 5);
374                 g.drawLine(x, y + 7, x + 11, y + 7);
375                 g.drawLine(x, y + 9, x + 9, y + 9);
376                 g.drawLine(x, y + 11, x + 13, y + 11);
377         }
378
379         private void drawHelpIcon(Graphics g, int x, int y) {
380                 int w = getIconWidth();
381                 int h = getIconHeight();
382                 g.setColor(new Color(0xEFEFEF));
383                 g.fillRect(x, y, w, h);
384                 g.setColor(Color.black);
385                 x += 4;
386                 y++;
387                 g.fillRect(x + 0, y + 0, 2, 3);
388                 g.fillRect(x + 2, y + 0, 4, 2);
389                 g.fillRect(x + 6, y + 0, 2, 6);
390                 g.fillRect(x + 3, y + 4, 3, 2);
391                 g.fillRect(x + 3, y + 6, 2, 2);
392                 g.fillRect(x + 3, y + 9, 2, 2);
393         }
394
395         private void drawAboutIcon(Graphics g, int x, int y) {
396                 int w = getIconWidth();
397                 int h = getIconHeight();
398                 g.setColor(new Color(0xEFEFEF));
399                 g.fillRect(x, y, w, h);
400                 g.setColor(Color.black);
401                 g.drawLine(x + 5, y + 4, x + 8, y + 4);
402                 g.drawLine(x + 5, y + 11, x + 10, y + 11);
403                 g.fillRect(x + 7, y + 4, 2, 7);
404                 g.fillRect(x + 7, y + 1, 2, 2);
405         }
406
407         private void drawCloseButtonCross(Graphics g, int x, int y) {
408                 int w = 13;
409                 int h = 11;
410                 g.setColor(getColor(COLOR_CLOSE));
411                 g.fillRect(x, y, w, h);
412                 g.setColor(getColor(COLOR_BLACK));
413                 for (int i = 0; i < 4; i++) {
414                         g.drawLine(x + 3 + i, y + 2 + i, x + 4 + i, y + 2 + i);
415                         g.drawLine(x + 9 - i, y + 2 + i, x + 10 - i, y + 2 + i);
416
417                         g.drawLine(x + 3 + i, y + 8 - i, x + 4 + i, y + 8 - i);
418                         g.drawLine(x + 9 - i, y + 8 - i, x + 10 - i, y + 8 - i);
419                 }
420         }
421
422         private void drawDockButtonInternal(Graphics g, int x, int y) {
423                 int w = 13;
424                 int h = 11;
425                 g.setColor(getColor(COLOR_CLOSE));
426                 g.fillRect(x, y, w, h);
427                 g.setColor(getColor(COLOR_BLACK));
428                 int ox = 4;
429                 int oy = 1;
430                 g.drawRect(x + ox, y + oy, 6, 5);
431                 g.drawLine(x + ox + 1, y + oy + 1, x + ox + 6, y + oy + 1);
432                 ox = 2;
433                 oy = 4;
434                 g.setColor(getColor(COLOR_BLACK));
435                 g.drawRect(x + ox, y + oy, 6, 5);
436                 g.drawLine(x + ox + 1, y + oy + 1, x + ox + 6, y + oy + 1);
437                 g.setColor(getColor(COLOR_CLOSE));
438                 g.fillRect(x + ox + 1, y + oy + 2, 5, 3);
439         }
440
441         private void drawItem(Graphics g, int x, int y, boolean selected, String s) {
442                 int w = getItemWidth();
443                 int h = getItemHeight();
444                 int iw = getIconWidth();
445                 g.setColor(getColor(COLOR_FRONT));
446                 if (selected)
447                         g.setColor(getColor(COLOR_SELECTED));
448                 g.fillRect(x, y, w, h);
449                 g.setColor(getColor(COLOR_BLACK));
450                 g.drawRect(x, y, w - 1, h - 1);
451                 g.setColor(getColor(COLOR_WHITE));
452                 g.drawRect(x + 1, y + 1, w - 3, h - 3);
453                 g.drawLine(x + iw + 2, y + 1, x + iw + 2, y + h - 2);
454                 int sw = g.getFontMetrics().stringWidth(s);
455                 w -= (5 + iw);
456                 g.drawString(s, x + iw + 3 + (w - sw) / 2, y + h - 4);
457         }
458
459         private void drawDisconnectItem(Graphics g, int x, int y, boolean pressed) {
460                 drawItem(g, x, y, pressed, getText(PixxTextProvider.GUI_DISCONNECT));
461                 drawDisconnectIcon(g, x + 2, y + 2);
462         }
463
464         private void drawConnectItem(Graphics g, int x, int y, boolean pressed) {
465                 drawItem(g, x, y, pressed, getText(PixxTextProvider.GUI_CONNECT));
466                 drawConnectIcon(g, x + 2, y + 2);
467         }
468
469         private void drawChanListItem(Graphics g, int x, int y, boolean pressed) {
470                 drawItem(g, x, y, pressed, getText(PixxTextProvider.GUI_CHANNELS));
471                 drawChanListIcon(g, x + 2, y + 2);
472         }
473
474         private void drawAboutItem(Graphics g, int x, int y, boolean pressed) {
475                 drawItem(g, x, y, pressed, getText(PixxTextProvider.GUI_ABOUT));
476                 drawAboutIcon(g, x + 2, y + 2);
477         }
478
479         private void drawHelpItem(Graphics g, int x, int y, boolean pressed) {
480                 drawItem(g, x, y, pressed, getText(PixxTextProvider.GUI_HELP));
481                 drawHelpIcon(g, x + 2, y + 2);
482         }
483
484         private void drawSmallButton(Graphics g, int x, int y, boolean pressed) {
485                 int w = 16;
486                 int h = 16;
487                 if (!pressed) {
488                         g.setColor(getColor(COLOR_WHITE));
489                         g.drawLine(x + 0, y + 1, x + w - 2, y + 1);
490                         g.drawLine(x + 0, y + 1, x + 0, y + h - 2);
491                         g.setColor(getColor(COLOR_BLACK));
492                         g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + 1);
493                         g.drawLine(x + w - 1, y + h - 2, x + 0, y + h - 2);
494                         g.setColor(getColor(COLOR_DARK_GRAY));
495                         g.drawLine(x + w - 2, y + h - 3, x + w - 2, y + 2);
496                         g.drawLine(x + w - 2, y + h - 3, x + 1, y + h - 3);
497                 } else {
498                         g.setColor(getColor(COLOR_BLACK));
499                         g.drawLine(x + 0, y + 1, x + w - 2, y + 1);
500                         g.drawLine(x + 0, y + 1, x + 0, y + h - 2);
501                         g.setColor(getColor(COLOR_WHITE));
502                         g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + 1);
503                         g.drawLine(x + w - 1, y + h - 2, x + 0, y + h - 2);
504                         g.setColor(getColor(COLOR_DARK_GRAY));
505                         g.drawLine(x + 1, y + 2, x + 1, y + h - 3);
506                         g.drawLine(x + 1, y + 2, x + w - 2, y + 2);
507                 }
508         }
509
510         private void drawCloseButtonItem(Graphics g, int x, int y, boolean pressed) {
511                 drawSmallButton(g, x, y, pressed);
512                 if (!pressed)
513                         drawCloseButtonCross(g, x + 1, y + 2);
514                 else
515                         drawCloseButtonCross(g, x + 2, y + 3);
516         }
517
518         private void drawDockButtonItem(Graphics g, int x, int y, boolean pressed) {
519                 drawSmallButton(g, x, y, pressed);
520                 if (!pressed)
521                         drawDockButtonInternal(g, x + 1, y + 2);
522                 else
523                         drawDockButtonInternal(g, x + 2, y + 3);
524         }
525
526         @Override
527         public void paint(Graphics g) {
528                 update(g);
529         }
530
531         @Override
532         public void update(Graphics ug) {
533                 int w = getSize().width;
534                 int h = getSize().height;
535
536                 if (_buffer != null) {
537                         if ((_buffer.getWidth(this) != w) || (_buffer.getHeight(this) != h))
538                                 _buffer = null;
539                 }
540
541                 if (_buffer == null) {
542                         Graphics g;
543                         try {
544                                 _buffer = createImage(w, h);
545                                 g = _buffer.getGraphics();
546                         } catch (Throwable e) {
547                                 return;
548                         }
549
550                         g.setFont(new Font("", Font.PLAIN, 12));
551
552                         // g.setColor(new Color(0x084079));
553                         g.setColor(getColor(COLOR_BACK));
554                         g.fillRect(0, 0, w, h);
555
556                         // drawSeparator(g,0,0,w,getItemHeight()+4);
557
558                         if (_pixxConfiguration.getB("showconnect")) {
559                                 if (!_connected)
560                                         drawConnectItem(g, getX(_connectIndex), getY(0), _pressedIndex == _connectIndex);
561                                 else
562                                         drawDisconnectItem(g, getX(_connectIndex), getY(0), _pressedIndex == _connectIndex);
563                         }
564                         if (_pixxConfiguration.getB("showchanlist"))
565                                 drawChanListItem(g, getX(_chanlistIndex), getY(0), _pressedIndex == _chanlistIndex);
566                         if (_pixxConfiguration.getB("showabout"))
567                                 drawAboutItem(g, getX(_aboutIndex), getY(0), _pressedIndex == _aboutIndex);
568                         if (_pixxConfiguration.getB("showhelp"))
569                                 drawHelpItem(g, getX(_helpIndex), getY(0), _pressedIndex == _helpIndex);
570
571                         if (_pixxConfiguration.getB("showclose"))
572                                 drawCloseButtonItem(g, getClosePositionX(), getClosePositionY(), _closePressed);
573                         if (_pixxConfiguration.getB("showdock"))
574                                 drawDockButtonItem(g, getDockPositionX(), getDockPositionY(), _dockPressed);
575
576                         if (_title)
577                                 drawTitle(g, getTitleY());
578
579                 } else {
580                         Graphics g = _buffer.getGraphics();
581                         if (_redrawTitle)
582                                 drawTitle(g, getTitleY());
583                 }
584
585                 _redrawTitle = false;
586
587                 if (_buffer != null)
588                         ug.drawImage(_buffer, 0, 0, this);
589
590         }
591
592         @Override
593         public void mouseClicked(MouseEvent e) {
594         }
595
596         @Override
597         public void mouseEntered(MouseEvent e) {
598         }
599
600         @Override
601         public void mouseExited(MouseEvent e) {
602         }
603
604         @Override
605         public void mousePressed(MouseEvent e) {
606                 _pressedIndex = getIndex(e.getX(), e.getY());
607                 _closePressed = isClosePressed(e.getX(), e.getY());
608                 _dockPressed = isDockPressed(e.getX(), e.getY());
609                 _buffer = null;
610                 if (_title && (e.getY() >= getTitleY())) {
611                         _mouseDownX = e.getX();
612                         _mouseScroll = true;
613                 }
614                 repaint();
615         }
616
617         @Override
618         public void mouseReleased(MouseEvent e) {
619                 _mouseScroll = false;
620                 int index = getIndex(e.getX(), e.getY());
621                 boolean close = isClosePressed(e.getX(), e.getY());
622                 boolean dock = isDockPressed(e.getX(), e.getY());
623                 if (index == _connectIndex)
624                         if (_pixxConfiguration.getB("showconnect"))
625                                 _listeners.sendEventAsync("connectionClicked", this);
626                 if (index == _chanlistIndex)
627                         if (_pixxConfiguration.getB("showchanlist"))
628                                 _listeners.sendEventAsync("chanListClicked", this);
629                 if (index == _aboutIndex)
630                         if (_pixxConfiguration.getB("showabout"))
631                                 _listeners.sendEventAsync("aboutClicked", this);
632                 if (index == _helpIndex)
633                         if (_pixxConfiguration.getB("showhelp"))
634                                 _listeners.sendEventAsync("helpClicked", this);
635                 if (close)
636                         _listeners.sendEventAsync("closeClicked", this);
637                 if (dock)
638                         _listeners.sendEventAsync("dockClicked", this);
639                 _closePressed = false;
640                 _dockPressed = false;
641                 _pressedIndex = -1;
642                 _buffer = null;
643                 repaint();
644         }
645
646         @Override
647         public void mouseMoved(MouseEvent e) {
648                 if (_title && (e.getY() >= getTitleY())) {
649                         if (!getCursor().equals(new Cursor(Cursor.E_RESIZE_CURSOR)))
650                                 setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
651                 } else {
652                         if (!getCursor().equals(new Cursor(Cursor.DEFAULT_CURSOR)))
653                                 setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
654                 }
655         }
656
657         /**
658          * Release any ressources used by this component.
659          */
660         public void dispose() {
661                 _terminated = true;
662         }
663
664         private void scrollTitle(int deltaX) {
665                 synchronized (_scrollLock) {
666
667                         if (_drawResult.rectangle == null)
668                                 return;
669                         _titleLeft -= deltaX;
670                         /** --- WRAP BEHAVIOUR --- **/
671                         int min = -_drawResult.rectangle.width;
672                         int max = getSize().width;
673                         if (_titleLeft > max)
674                                 _titleLeft = min;
675                         if (_titleLeft < min)
676                                 _titleLeft = max;
677
678                         /** --- CLAMP BEHAVIOUR --- **/
679                         /*
680                          * int min=-_drawResult.rectangle.width; int max=0; if(_titleLeft>max)
681                          * _titleLeft=max; if(_titleLeft<min) _titleLeft=min;
682                          */
683
684                         _redrawTitle = true;
685                         repaint();
686                 }
687         }
688
689         @Override
690         public void mouseDragged(MouseEvent e) {
691                 if (!_mouseScroll)
692                         return;
693                 if (_drawResult.rectangle == null)
694                         return;
695                 int deltaX = _mouseDownX - e.getX();
696                 scrollTitle(deltaX);
697                 _freeze = true;
698                 _mouseDownX = e.getX();
699         }
700
701         @Override
702         public void run() {
703                 while (!_terminated) {
704                         if (!_freeze)
705                                 scrollTitle(4);
706                         try {
707                                 if (_freeze) {
708                                         Thread.sleep(2000);
709                                         _freeze = false;
710                                 } else
711                                         Thread.sleep(_scrollDelay);
712                         } catch (InterruptedException ex) {
713                         }
714                 }
715         }
716
717         @Override
718         public Boolean displayUpdated(Object handle, Integer what) {
719                 if (_drawResult == null)
720                         return Boolean.FALSE;
721                 for (int i = 0; i < _drawResult.updateHandles.size(); i++) {
722                         if (_drawResult.updateHandles.elementAt(i) == handle) {
723                                 _redrawTitle = true;
724                                 repaint();
725                                 return Boolean.TRUE;
726                         }
727                 }
728                 return Boolean.FALSE;
729         }
730 }