Revision 12438 trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/imagenavigator/ImageNavigator.java
ImageNavigator.java | ||
---|---|---|
35 | 35 |
import java.awt.event.MouseWheelEvent; |
36 | 36 |
import java.awt.event.MouseWheelListener; |
37 | 37 |
|
38 |
import javax.swing.ImageIcon; |
|
38 | 39 |
import javax.swing.JComponent; |
39 | 40 |
/** |
40 | 41 |
* <code>ImageNavigator</code> es un componente que representa un manejador |
... | ... | |
55 | 56 |
* |
56 | 57 |
* @version 04/05/2007 |
57 | 58 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
58 |
* |
|
59 | 59 |
*/ |
60 | 60 |
public class ImageNavigator extends JComponent implements KeyListener, MouseMotionListener, MouseListener, MouseWheelListener { |
61 | 61 |
private static final long serialVersionUID = 1164788214432359272L; |
62 |
private IClientImageNavigator iClient = null; |
|
62 |
private IClientImageNavigator iClient = null;
|
|
63 | 63 |
|
64 |
private Image image = null;
|
|
65 |
private Graphics2D widgetGraphics = null;
|
|
66 |
private Image imageCache = null;
|
|
67 |
private Graphics2D cacheGraphics = null;
|
|
64 |
private Image image = null;
|
|
65 |
private Graphics2D widgetGraphics = null;
|
|
66 |
private Image imageCache = null;
|
|
67 |
private Graphics2D cacheGraphics = null;
|
|
68 | 68 |
|
69 |
private double zoom = 1.0; |
|
70 |
private double x1 = 0.0; |
|
71 |
private double y1 = 0.0; |
|
72 |
private boolean yInverted = false; |
|
73 |
private boolean xInverted = false; |
|
74 |
private int width = 0, height = 0; |
|
75 |
private boolean showHelp = false; |
|
69 |
private double zoom = 1.0; |
|
70 |
private double x1 = 0.0; |
|
71 |
private double y1 = 0.0; |
|
72 |
private boolean yInverted = false; |
|
73 |
private boolean xInverted = false; |
|
74 |
private int width = 0; |
|
75 |
private int height = 0; |
|
76 |
private boolean showHelp = false; |
|
77 |
ImageIcon imageIconClose; |
|
78 |
ImageIcon imageIconHelp; |
|
76 | 79 |
|
77 | 80 |
/** |
78 | 81 |
* Crea un <code>ImageNavigator</code> especificandole quien pintara el |
79 | 82 |
* componente |
80 |
* |
|
81 | 83 |
* @param iClient |
82 | 84 |
*/ |
83 | 85 |
public ImageNavigator(IClientImageNavigator iClient) { |
... | ... | |
88 | 90 |
this.addMouseMotionListener(this); |
89 | 91 |
this.addMouseListener(this); |
90 | 92 |
this.addMouseWheelListener(this); |
91 |
this.setCursor(new Cursor(Cursor.MOVE_CURSOR)); |
|
92 | 93 |
} |
93 | 94 |
|
94 | 95 |
double initX1 = 0.0; |
... | ... | |
261 | 262 |
*/ |
262 | 263 |
private void callShowHelp() { |
263 | 264 |
showHelp = !showHelp; |
264 |
if (showHelp) |
|
265 |
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
266 |
else |
|
267 |
this.setCursor(new Cursor(Cursor.MOVE_CURSOR)); |
|
268 | 265 |
updateImageCache(true); |
269 | 266 |
refreshImage(0, 0); |
270 | 267 |
} |
... | ... | |
279 | 276 |
case 'H': |
280 | 277 |
callShowHelp(); |
281 | 278 |
break; |
282 |
} |
|
283 |
|
|
284 |
if (showHelp) |
|
285 |
return; |
|
286 |
|
|
287 |
switch (e.getKeyChar()) { |
|
288 | 279 |
case '+': |
289 | 280 |
ZoomIn(width / 2.0, height / 2.0); |
290 | 281 |
autoAdjusted = false; |
... | ... | |
428 | 419 |
getWidgetGraphics().fillRect(0, 0, width, height); |
429 | 420 |
|
430 | 421 |
getWidgetGraphics().drawImage(imageCache, x, y, null); |
422 |
|
|
423 |
if (showHelp) |
|
424 |
paintHelp((Graphics2D) getWidgetGraphics()); |
|
425 |
else |
|
426 |
getWidgetGraphics().drawImage(getIconHelp().getImage(), width - getIconHelp().getIconWidth() - 4, 3, null); |
|
431 | 427 |
} |
432 | 428 |
|
433 | 429 |
/* |
... | ... | |
448 | 444 |
if (image != null) |
449 | 445 |
g.drawImage(image, 0, 0, this); |
450 | 446 |
|
451 |
paintHelp((Graphics2D) g); |
|
447 |
// paintHelp((Graphics2D) g);
|
|
452 | 448 |
} |
453 | 449 |
|
454 | 450 |
/** |
... | ... | |
467 | 463 |
if (image != null) |
468 | 464 |
getGraphics().drawImage(image, 0, 0, this); |
469 | 465 |
|
470 |
paintHelp((Graphics2D) getGraphics()); |
|
466 |
// paintHelp((Graphics2D) getGraphics());
|
|
471 | 467 |
} |
472 | 468 |
|
469 |
/** |
|
470 |
* Devuelve el icono de cerrar |
|
471 |
* @return |
|
472 |
*/ |
|
473 |
private ImageIcon getIconClose() { |
|
474 |
if (imageIconClose == null) { |
|
475 |
imageIconClose = new ImageIcon(getClass().getResource("images/close.png")); |
|
476 |
} |
|
477 |
return imageIconClose; |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Devuelve el icono ayuda |
|
482 |
* @return |
|
483 |
*/ |
|
484 |
private ImageIcon getIconHelp() { |
|
485 |
if (imageIconHelp == null) { |
|
486 |
imageIconHelp = new ImageIcon(getClass().getResource("images/help.png")); |
|
487 |
} |
|
488 |
return imageIconHelp; |
|
489 |
} |
|
490 |
|
|
473 | 491 |
private void paintHelp(Graphics2D g) { |
474 |
if (!showHelp) |
|
475 |
return; |
|
476 |
|
|
477 | 492 |
int sep = 13; |
478 | 493 |
int pos = sep + 1; |
479 | 494 |
|
... | ... | |
516 | 531 |
graphics2.setColor(new Color(185, 185, 185)); |
517 | 532 |
graphics2.drawLine(0, alto, width, alto); |
518 | 533 |
|
519 |
AlphaComposite myAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f); |
|
534 |
graphics2.drawImage(getIconClose().getImage(), width - getIconClose().getIconWidth() - 4, 3, null); |
|
535 |
|
|
536 |
AlphaComposite myAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f); |
|
520 | 537 |
g.setComposite(myAlpha); |
521 | 538 |
|
522 | 539 |
g.drawImage(image2, 0, 0, this); |
540 |
|
|
541 |
myAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f); |
|
542 |
g.setComposite(myAlpha); |
|
523 | 543 |
} |
524 | 544 |
|
525 | 545 |
Point mouse = null; |
... | ... | |
528 | 548 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
529 | 549 |
*/ |
530 | 550 |
public void mousePressed(MouseEvent e) { |
531 |
if (showHelp) return; |
|
551 |
if ((e.getX() > (width - 20)) && (e.getY() < 20)) { |
|
552 |
callShowHelp(); |
|
553 |
return; |
|
554 |
} |
|
555 |
|
|
532 | 556 |
requestFocus(); |
533 | 557 |
if ((e.getButton() != MouseEvent.BUTTON1) && (e.getButton() != MouseEvent.BUTTON2)) |
534 | 558 |
return; |
... | ... | |
549 | 573 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) |
550 | 574 |
*/ |
551 | 575 |
public void mouseDragged(MouseEvent e) { |
552 |
if (showHelp) return; |
|
553 | 576 |
changePos(e.getX(), e.getY()); |
554 | 577 |
} |
555 | 578 |
|
... | ... | |
558 | 581 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
559 | 582 |
*/ |
560 | 583 |
public void mouseReleased(MouseEvent e) { |
561 |
if (showHelp) return; |
|
562 | 584 |
if (mouse != null) { |
563 | 585 |
x1 = x1 - ((e.getX() - mouse.getX())/zoom); |
564 | 586 |
y1 = y1 - ((e.getY() - mouse.getY())/zoom); |
... | ... | |
578 | 600 |
* del puntero. |
579 | 601 |
*/ |
580 | 602 |
public void mouseWheelMoved(MouseWheelEvent e) { |
581 |
if (showHelp) return; |
|
582 | 603 |
if (e.getWheelRotation() > 0) { |
583 | 604 |
ZoomOut(isXInverted() ? this.getWidth() - e.getX() : e.getX(), isYInverted() ? this.getHeight() - e.getY() : e.getY()); |
584 | 605 |
autoAdjusted = false; |
... | ... | |
605 | 626 |
return xInverted; |
606 | 627 |
} |
607 | 628 |
|
629 |
/* |
|
630 |
* (non-Javadoc) |
|
631 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent) |
|
632 |
*/ |
|
633 |
public void mouseMoved(MouseEvent e) { |
|
634 |
if ((e.getX() > (width - 20)) && (e.getY() < 20)) { |
|
635 |
setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
636 |
} else { |
|
637 |
setCursor(new Cursor(Cursor.MOVE_CURSOR)); |
|
638 |
} |
|
639 |
} |
|
640 |
|
|
608 | 641 |
public void keyReleased(KeyEvent e) {} |
609 | 642 |
public void keyTyped(KeyEvent e) {} |
610 |
public void mouseMoved(MouseEvent e) {} |
|
611 | 643 |
public void mouseClicked(MouseEvent e) {} |
612 | 644 |
public void mouseEntered(MouseEvent e) {} |
613 | 645 |
public void mouseExited(MouseEvent e) {} |
Also available in: Unified diff