1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2010 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
24 |
|
|
25 |
import java.awt.AlphaComposite; |
import java.awt.AlphaComposite; |
26 |
import java.awt.Color; |
import java.awt.Color; |
27 |
|
import java.awt.Component; |
28 |
import java.awt.Dimension; |
import java.awt.Dimension; |
29 |
import java.awt.GradientPaint; |
import java.awt.GradientPaint; |
30 |
import java.awt.Graphics; |
import java.awt.Graphics; |
32 |
import java.awt.RenderingHints; |
import java.awt.RenderingHints; |
33 |
|
|
34 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
35 |
|
import java.awt.event.MouseListener; |
36 |
|
import java.awt.event.MouseMotionListener; |
37 |
|
|
38 |
import java.awt.geom.Arc2D; |
import java.awt.geom.Arc2D; |
39 |
import java.awt.geom.Line2D; |
import java.awt.geom.Line2D; |
49 |
|
|
50 |
import javax.swing.plaf.basic.BasicSliderUI; |
import javax.swing.plaf.basic.BasicSliderUI; |
51 |
|
|
|
import org.jvnet.substance.utils.RolloverControlListener; |
|
|
import org.jvnet.substance.utils.Trackable; |
|
|
|
|
52 |
/** |
/** |
53 |
* |
* |
54 |
* @author Grigor Iliev |
* @author Grigor Iliev |
371 |
new Dimension(27, 20) : new Dimension(17, 27); |
new Dimension(27, 20) : new Dimension(17, 27); |
372 |
} |
} |
373 |
} |
} |
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
/* |
378 |
|
* Copyright (c) 2005-2009 Substance Kirill Grouchnikov. All Rights Reserved. |
379 |
|
* |
380 |
|
* Redistribution and use in source and binary forms, with or without |
381 |
|
* modification, are permitted provided that the following conditions are met: |
382 |
|
* |
383 |
|
* o Redistributions of source code must retain the above copyright notice, |
384 |
|
* this list of conditions and the following disclaimer. |
385 |
|
* |
386 |
|
* o Redistributions in binary form must reproduce the above copyright notice, |
387 |
|
* this list of conditions and the following disclaimer in the documentation |
388 |
|
* and/or other materials provided with the distribution. |
389 |
|
* |
390 |
|
* o Neither the name of Substance Kirill Grouchnikov nor the names of |
391 |
|
* its contributors may be used to endorse or promote products derived |
392 |
|
* from this software without specific prior written permission. |
393 |
|
* |
394 |
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
395 |
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
396 |
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
397 |
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
398 |
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
399 |
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
400 |
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
401 |
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
402 |
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
403 |
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
404 |
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
405 |
|
*/ |
406 |
|
|
407 |
|
/** @author Kirill Grouchnikov */ |
408 |
|
interface Trackable { public boolean isInside(MouseEvent me); } |
409 |
|
|
410 |
|
/** |
411 |
|
* Control listener for rollover effects. Tracks the mouse motion interaction |
412 |
|
* for the associated {@link org.jvnet.substance.utils.Trackable} control. This |
413 |
|
* class is <b>for internal use only</b>. |
414 |
|
* |
415 |
|
* @author Kirill Grouchnikov |
416 |
|
*/ |
417 |
|
class RolloverControlListener implements MouseListener, |
418 |
|
MouseMotionListener { |
419 |
|
/** |
420 |
|
* If the mouse pointer is currently inside the designated area (fetched |
421 |
|
* from the associated {@link #trackableUI}), <code>this</code> flag is |
422 |
|
* <code>true</code>. |
423 |
|
*/ |
424 |
|
private boolean isMouseInside; |
425 |
|
|
426 |
|
/** |
427 |
|
* Surrogate model for tracking control status. |
428 |
|
*/ |
429 |
|
private ButtonModel model; |
430 |
|
|
431 |
|
/** |
432 |
|
* Object that is queried for mouse events. This object is responsible for |
433 |
|
* handling the designated (hot-spot) area of the associated control. |
434 |
|
*/ |
435 |
|
private Trackable trackableUI; |
436 |
|
|
437 |
|
/** |
438 |
|
* Simple constructor. |
439 |
|
* |
440 |
|
* @param trackableUI |
441 |
|
* Object that is queried for mouse events. |
442 |
|
* @param model |
443 |
|
* Surrogate model for tracking control status. |
444 |
|
*/ |
445 |
|
public RolloverControlListener(Trackable trackableUI, ButtonModel model) { |
446 |
|
this.trackableUI = trackableUI; |
447 |
|
this.model = model; |
448 |
|
this.isMouseInside = false; |
449 |
|
} |
450 |
|
|
451 |
|
/* |
452 |
|
* (non-Javadoc) |
453 |
|
* |
454 |
|
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) |
455 |
|
*/ |
456 |
|
public void mouseEntered(MouseEvent e) { |
457 |
|
Component component = (Component) e.getSource(); |
458 |
|
if (!component.isEnabled()) |
459 |
|
return; |
460 |
|
boolean isInside = this.trackableUI.isInside(e); |
461 |
|
// boolean isInsideChanged = (this.isMouseInside != isInside); |
462 |
|
this.isMouseInside = isInside; |
463 |
|
this.model.setRollover(isInside); |
464 |
|
this.model.setEnabled(component.isEnabled()); |
465 |
|
} |
466 |
|
|
467 |
|
/* |
468 |
|
* (non-Javadoc) |
469 |
|
* |
470 |
|
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) |
471 |
|
*/ |
472 |
|
public void mouseExited(MouseEvent e) { |
473 |
|
Component component = (Component) e.getSource(); |
474 |
|
if (!component.isEnabled()) |
475 |
|
return; |
476 |
|
// boolean isInsideChanged = (this.isMouseInside != false); |
477 |
|
this.isMouseInside = false; |
478 |
|
this.model.setRollover(false); |
479 |
|
this.model.setEnabled(component.isEnabled()); |
480 |
|
} |
481 |
|
|
482 |
|
/* |
483 |
|
* (non-Javadoc) |
484 |
|
* |
485 |
|
* @see |
486 |
|
* java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
487 |
|
*/ |
488 |
|
public void mouseReleased(MouseEvent e) { |
489 |
|
// System.out.println("mouse released [" + e.getX() + ":" + e.getY() + |
490 |
|
// "]"); |
491 |
|
Component component = (Component) e.getSource(); |
492 |
|
if (!component.isEnabled()) |
493 |
|
return; |
494 |
|
boolean isInside = this.trackableUI.isInside(e); |
495 |
|
// boolean isInsideChanged = (this.isMouseInside != isInside); |
496 |
|
this.isMouseInside = isInside; |
497 |
|
this.model.setRollover(this.isMouseInside); |
498 |
|
this.model.setPressed(false); |
499 |
|
this.model.setArmed(false); |
500 |
|
this.model.setSelected(false); |
501 |
|
this.model.setEnabled(component.isEnabled()); |
502 |
|
} |
503 |
|
|
504 |
|
/* |
505 |
|
* (non-Javadoc) |
506 |
|
* |
507 |
|
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
508 |
|
*/ |
509 |
|
public void mousePressed(MouseEvent e) { |
510 |
|
// System.out.println("mouse pressed [" + e.getX() + ":" + e.getY() + |
511 |
|
// "]"); |
512 |
|
Component component = (Component) e.getSource(); |
513 |
|
if (!component.isEnabled()) |
514 |
|
return; |
515 |
|
boolean isInside = this.trackableUI.isInside(e); |
516 |
|
// boolean isInsideChanged = (this.isMouseInside != isInside); |
517 |
|
this.isMouseInside = isInside; |
518 |
|
this.model.setRollover(this.isMouseInside); |
519 |
|
if (this.isMouseInside) { |
520 |
|
this.model.setPressed(true); |
521 |
|
this.model.setArmed(true); |
522 |
|
this.model.setSelected(true); |
523 |
|
} |
524 |
|
this.model.setEnabled(component.isEnabled()); |
525 |
|
} |
526 |
|
|
527 |
|
/* |
528 |
|
* (non-Javadoc) |
529 |
|
* |
530 |
|
* @see |
531 |
|
* java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent |
532 |
|
* ) |
533 |
|
*/ |
534 |
|
public void mouseDragged(MouseEvent e) { |
535 |
|
// System.out.println("mouse dragged [" + e.getX() + ":" + e.getY() + |
536 |
|
// "]"); |
537 |
|
Component component = (Component) e.getSource(); |
538 |
|
if (!component.isEnabled()) |
539 |
|
return; |
540 |
|
boolean isInside = this.trackableUI.isInside(e); |
541 |
|
// boolean isInsideChanged = (this.isMouseInside != isInside); |
542 |
|
this.isMouseInside = isInside; |
543 |
|
this.model.setEnabled(component.isEnabled()); |
544 |
|
} |
545 |
|
|
546 |
|
/* |
547 |
|
* (non-Javadoc) |
548 |
|
* |
549 |
|
* @see |
550 |
|
* java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent) |
551 |
|
*/ |
552 |
|
public void mouseMoved(MouseEvent e) { |
553 |
|
// System.out.println("mouse moved [" + e.getX() + ":" + e.getY() + |
554 |
|
// "]"); |
555 |
|
Component component = (Component) e.getSource(); |
556 |
|
if (!component.isEnabled()) |
557 |
|
return; |
558 |
|
boolean isInside = this.trackableUI.isInside(e); |
559 |
|
// System.out.println("inside"); |
560 |
|
// boolean isInsideChanged = (this.isMouseInside != isInside); |
561 |
|
this.isMouseInside = isInside; |
562 |
|
this.model.setRollover(isInside); |
563 |
|
this.model.setEnabled(component.isEnabled()); |
564 |
|
} |
565 |
|
|
566 |
|
/* |
567 |
|
* (non-Javadoc) |
568 |
|
* |
569 |
|
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) |
570 |
|
*/ |
571 |
|
public void mouseClicked(MouseEvent e) { |
572 |
|
} |
573 |
|
} |