< prev index next >

src/java.desktop/share/classes/sun/print/ServiceNotifier.java

Print this page




   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.print;
  27 
  28 import sun.misc.ManagedLocalsThread;
  29 
  30 import java.util.Vector;
  31 
  32 import javax.print.PrintService;
  33 import javax.print.attribute.PrintServiceAttributeSet;
  34 import javax.print.attribute.HashPrintServiceAttributeSet;
  35 import javax.print.event.PrintServiceAttributeEvent;
  36 import javax.print.event.PrintServiceAttributeListener;
  37 
  38 /*
  39  * A utility class usable by all print services for managing listeners
  40  * The services create an instance and delegate the listener callback
  41  * management to this class. The ServiceNotifier calls back to the service
  42  * to obtain the state of the attributes and notifies the listeners of
  43  * any changes.
  44  */
  45 class ServiceNotifier extends ManagedLocalsThread {
  46 
  47     private PrintService service;
  48     private Vector<PrintServiceAttributeListener> listeners;
  49     private boolean stop = false;
  50     private PrintServiceAttributeSet lastSet;
  51 




  52     ServiceNotifier(PrintService service) {
  53         super(service.getName() + " notifier");
  54         this.service = service;
  55         listeners = new Vector<>();
  56         try {
  57               setPriority(Thread.NORM_PRIORITY-1);
  58               setDaemon(true);
  59               start();
  60         } catch (SecurityException e) {
  61         }
  62     }
  63 
  64     void addListener(PrintServiceAttributeListener listener) {
  65         synchronized (this) {
  66             if (listener == null || listeners == null) {
  67                 return;
  68             }
  69             listeners.add(listener);
  70         }
  71     }
  72 
  73     void removeListener(PrintServiceAttributeListener listener) {




   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.print;
  27 


  28 import java.util.Vector;
  29 
  30 import javax.print.PrintService;
  31 import javax.print.attribute.PrintServiceAttributeSet;
  32 import javax.print.attribute.HashPrintServiceAttributeSet;
  33 import javax.print.event.PrintServiceAttributeEvent;
  34 import javax.print.event.PrintServiceAttributeListener;
  35 
  36 /*
  37  * A utility class usable by all print services for managing listeners
  38  * The services create an instance and delegate the listener callback
  39  * management to this class. The ServiceNotifier calls back to the service
  40  * to obtain the state of the attributes and notifies the listeners of
  41  * any changes.
  42  */
  43 class ServiceNotifier extends Thread {
  44 
  45     private PrintService service;
  46     private Vector<PrintServiceAttributeListener> listeners;
  47     private boolean stop = false;
  48     private PrintServiceAttributeSet lastSet;
  49 
  50     /*
  51      * If adding any other constructors, always call the 5-args
  52      * super-class constructor passing "false" for inherit-locals.
  53      */
  54     ServiceNotifier(PrintService service) {
  55         super(null, null, service.getName() + " notifier", 0, false);
  56         this.service = service;
  57         listeners = new Vector<>();
  58         try {
  59               setPriority(Thread.NORM_PRIORITY-1);
  60               setDaemon(true);
  61               start();
  62         } catch (SecurityException e) {
  63         }
  64     }
  65 
  66     void addListener(PrintServiceAttributeListener listener) {
  67         synchronized (this) {
  68             if (listener == null || listeners == null) {
  69                 return;
  70             }
  71             listeners.add(listener);
  72         }
  73     }
  74 
  75    void removeListener(PrintServiceAttributeListener listener) {


< prev index next >