src/solaris/classes/sun/awt/X11/XTrayIconPeer.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2013, 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


 484             handleEvent(e);
 485         }
 486         public void mousePressed(MouseEvent e) {
 487             handleEvent(e);
 488         }
 489         public void mouseReleased(MouseEvent e) {
 490             handleEvent(e);
 491         }
 492         public void mouseDragged(MouseEvent e) {
 493             handleEvent(e);
 494         }
 495         public void mouseMoved(MouseEvent e) {
 496             handleEvent(e);
 497         }
 498     }
 499 
 500     // ***************************************
 501     // Special embedded frame for tray icon
 502     // ***************************************
 503 

 504     private static class XTrayIconEmbeddedFrame extends XEmbeddedFrame {
 505         public XTrayIconEmbeddedFrame(){
 506             super(XToolkit.getDefaultRootWindow(), true, true);
 507         }
 508 
 509         public boolean isUndecorated() {
 510             return true;
 511         }
 512 
 513         public boolean isResizable() {
 514             return false;
 515         }
 516 
 517         // embedded frame for tray icon shouldn't be disposed by anyone except tray icon
 518         public void dispose(){
 519         }
 520 
 521         public void realDispose(){
 522             super.dispose();
 523         }
 524     };
 525 
 526     // ***************************************
 527     // Classes for painting an image on canvas
 528     // ***************************************
 529 

 530     static class TrayIconCanvas extends IconCanvas {
 531         TrayIcon target;
 532         boolean autosize;
 533 
 534         TrayIconCanvas(TrayIcon target, int width, int height) {
 535             super(width, height);
 536             this.target = target;
 537         }
 538 
 539         // Invoke on EDT.
 540         protected void repaintImage(boolean doClear) {
 541             boolean old_autosize = autosize;
 542             autosize = target.isImageAutoSize();
 543 
 544             curW = autosize ? width : image.getWidth(observer);
 545             curH = autosize ? height : image.getHeight(observer);
 546 
 547             super.repaintImage(doClear || (old_autosize != autosize));
 548         }
 549     }
 550 

 551     public static class IconCanvas extends Canvas {
 552         volatile Image image;
 553         IconObserver observer;
 554         int width, height;
 555         int curW, curH;
 556 
 557         IconCanvas(int width, int height) {
 558             this.width = curW = width;
 559             this.height = curH = height;
 560         }
 561 
 562         // Invoke on EDT.
 563         public void updateImage(Image image) {
 564             this.image = image;
 565             if (observer == null) {
 566                 observer = new IconObserver();
 567             }
 568             repaintImage(true);
 569         }
 570 


   1 /*
   2  * Copyright (c) 2005, 2014, 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


 484             handleEvent(e);
 485         }
 486         public void mousePressed(MouseEvent e) {
 487             handleEvent(e);
 488         }
 489         public void mouseReleased(MouseEvent e) {
 490             handleEvent(e);
 491         }
 492         public void mouseDragged(MouseEvent e) {
 493             handleEvent(e);
 494         }
 495         public void mouseMoved(MouseEvent e) {
 496             handleEvent(e);
 497         }
 498     }
 499 
 500     // ***************************************
 501     // Special embedded frame for tray icon
 502     // ***************************************
 503 
 504     @SuppressWarnings("serial") // JDK-implementation class
 505     private static class XTrayIconEmbeddedFrame extends XEmbeddedFrame {
 506         public XTrayIconEmbeddedFrame(){
 507             super(XToolkit.getDefaultRootWindow(), true, true);
 508         }
 509 
 510         public boolean isUndecorated() {
 511             return true;
 512         }
 513 
 514         public boolean isResizable() {
 515             return false;
 516         }
 517 
 518         // embedded frame for tray icon shouldn't be disposed by anyone except tray icon
 519         public void dispose(){
 520         }
 521 
 522         public void realDispose(){
 523             super.dispose();
 524         }
 525     };
 526 
 527     // ***************************************
 528     // Classes for painting an image on canvas
 529     // ***************************************
 530 
 531     @SuppressWarnings("serial") // JDK-implementation class
 532     static class TrayIconCanvas extends IconCanvas {
 533         TrayIcon target;
 534         boolean autosize;
 535 
 536         TrayIconCanvas(TrayIcon target, int width, int height) {
 537             super(width, height);
 538             this.target = target;
 539         }
 540 
 541         // Invoke on EDT.
 542         protected void repaintImage(boolean doClear) {
 543             boolean old_autosize = autosize;
 544             autosize = target.isImageAutoSize();
 545 
 546             curW = autosize ? width : image.getWidth(observer);
 547             curH = autosize ? height : image.getHeight(observer);
 548 
 549             super.repaintImage(doClear || (old_autosize != autosize));
 550         }
 551     }
 552 
 553     @SuppressWarnings("serial") // JDK-implementation class
 554     public static class IconCanvas extends Canvas {
 555         volatile Image image;
 556         IconObserver observer;
 557         int width, height;
 558         int curW, curH;
 559 
 560         IconCanvas(int width, int height) {
 561             this.width = curW = width;
 562             this.height = curH = height;
 563         }
 564 
 565         // Invoke on EDT.
 566         public void updateImage(Image image) {
 567             this.image = image;
 568             if (observer == null) {
 569                 observer = new IconObserver();
 570             }
 571             repaintImage(true);
 572         }
 573