1 /*
2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.X11;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import java.awt.peer.TrayIconPeer;
31 import sun.awt.*;
32 import java.awt.image.*;
33 import java.security.AccessController;
34 import java.security.PrivilegedAction;
35 import java.lang.reflect.InvocationTargetException;
36 import sun.util.logging.PlatformLogger;
37
38 public class XTrayIconPeer implements TrayIconPeer,
39 InfoWindow.Balloon.LiveArguments,
40 InfoWindow.Tooltip.LiveArguments
41 {
42 private static final PlatformLogger ctrLog = PlatformLogger.getLogger("sun.awt.X11.XTrayIconPeer.centering");
43
44 TrayIcon target;
45 TrayIconEventProxy eventProxy;
46 XTrayIconEmbeddedFrame eframe;
47 TrayIconCanvas canvas;
48 InfoWindow.Balloon balloon;
49 InfoWindow.Tooltip tooltip;
50 PopupMenu popup;
51 String tooltipString;
52 boolean isTrayIconDisplayed;
53 long eframeParentID;
54 final XEventDispatcher parentXED, eframeXED;
55
56 static final XEventDispatcher dummyXED = new XEventDispatcher() {
532 return false;
533 }
534
535 // embedded frame for tray icon shouldn't be disposed by anyone except tray icon
536 public void dispose(){
537 }
538
539 public void realDispose(){
540 super.dispose();
541 }
542 };
543
544 // ***************************************
545 // Classes for painting an image on canvas
546 // ***************************************
547
548 @SuppressWarnings("serial") // JDK-implementation class
549 static class TrayIconCanvas extends IconCanvas {
550 TrayIcon target;
551 boolean autosize;
552
553 TrayIconCanvas(TrayIcon target, int width, int height) {
554 super(width, height);
555 this.target = target;
556 }
557
558 // Invoke on EDT.
559 protected void repaintImage(boolean doClear) {
560 boolean old_autosize = autosize;
561 autosize = target.isImageAutoSize();
562
563 curW = autosize ? width : image.getWidth(observer);
564 curH = autosize ? height : image.getHeight(observer);
565
566 super.repaintImage(doClear || (old_autosize != autosize));
567 }
568
569 public void dispose() {
570 super.dispose();
571 target = null;
572 }
573 }
574
575 @SuppressWarnings("serial") // JDK-implementation class
576 public static class IconCanvas extends Canvas {
577 volatile Image image;
578 IconObserver observer;
579 int width, height;
580 int curW, curH;
581
582 IconCanvas(int width, int height) {
583 this.width = curW = width;
584 this.height = curH = height;
585 }
586
587 // Invoke on EDT.
588 public void updateImage(Image image) {
589 this.image = image;
590 if (observer == null) {
591 observer = new IconObserver();
592 }
593 repaintImage(true);
594 }
595
596 public void dispose() {
597 observer = null;
598 }
599
600 // Invoke on EDT.
601 protected void repaintImage(boolean doClear) {
602 Graphics g = getGraphics();
603 if (g != null) {
604 try {
|
1 /*
2 * Copyright (c) 2005, 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.X11;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import java.awt.peer.TrayIconPeer;
31 import sun.awt.*;
32 import java.awt.image.*;
33 import java.security.AccessController;
34 import java.security.PrivilegedAction;
35 import java.lang.reflect.InvocationTargetException;
36 import sun.util.logging.PlatformLogger;
37 import java.awt.geom.AffineTransform;
38 import sun.java2d.pipe.Region;
39
40 public class XTrayIconPeer implements TrayIconPeer,
41 InfoWindow.Balloon.LiveArguments,
42 InfoWindow.Tooltip.LiveArguments
43 {
44 private static final PlatformLogger ctrLog = PlatformLogger.getLogger("sun.awt.X11.XTrayIconPeer.centering");
45
46 TrayIcon target;
47 TrayIconEventProxy eventProxy;
48 XTrayIconEmbeddedFrame eframe;
49 TrayIconCanvas canvas;
50 InfoWindow.Balloon balloon;
51 InfoWindow.Tooltip tooltip;
52 PopupMenu popup;
53 String tooltipString;
54 boolean isTrayIconDisplayed;
55 long eframeParentID;
56 final XEventDispatcher parentXED, eframeXED;
57
58 static final XEventDispatcher dummyXED = new XEventDispatcher() {
534 return false;
535 }
536
537 // embedded frame for tray icon shouldn't be disposed by anyone except tray icon
538 public void dispose(){
539 }
540
541 public void realDispose(){
542 super.dispose();
543 }
544 };
545
546 // ***************************************
547 // Classes for painting an image on canvas
548 // ***************************************
549
550 @SuppressWarnings("serial") // JDK-implementation class
551 static class TrayIconCanvas extends IconCanvas {
552 TrayIcon target;
553 boolean autosize;
554 final int width, height;
555
556 TrayIconCanvas(TrayIcon target, int width, int height) {
557 super(width, height);
558 this.target = target;
559 this.width = width;
560 this.height = height;
561 }
562
563 // Invoke on EDT.
564 protected void repaintImage(boolean doClear) {
565 boolean old_autosize = autosize;
566 int old_curW = curW, old_curH = curH;
567 autosize = target.isImageAutoSize();
568 AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
569 getDefaultScreenDevice().getDefaultConfiguration().
570 getDefaultTransform();
571 int w = Region.clipScale(width, tx.getScaleX());
572 int h = Region.clipScale(height, tx.getScaleY());
573 int imgWidth = Region.clipScale(image.getWidth(observer), tx.getScaleX());
574 int imgHeight = Region.clipScale(image.getHeight(observer), tx.getScaleY());
575
576 curW = autosize ? w : imgWidth;
577 curH = autosize ? h : imgHeight;
578
579 // update the size before repainting
580 super.updateSize(curW, curH);
581 super.repaintImage(doClear || (old_autosize != autosize) ||
582 (old_curW != curW || old_curH != curH));
583 }
584
585 public void dispose() {
586 super.dispose();
587 target = null;
588 }
589 }
590
591 @SuppressWarnings("serial") // JDK-implementation class
592 public static class IconCanvas extends Canvas {
593 volatile Image image;
594 IconObserver observer;
595 int curW, curH;
596
597 IconCanvas(int width, int height) {
598 curW = width;
599 curH = height;
600 }
601
602 public void updateSize(int width, int height) {
603 curW = width;
604 curH = height;
605 }
606
607 // Invoke on EDT.
608 public void updateImage(Image image) {
609 this.image = image;
610 if (observer == null) {
611 observer = new IconObserver();
612 }
613 repaintImage(true);
614 }
615
616 public void dispose() {
617 observer = null;
618 }
619
620 // Invoke on EDT.
621 protected void repaintImage(boolean doClear) {
622 Graphics g = getGraphics();
623 if (g != null) {
624 try {
|