home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / edtplug / classes / netscape / plugin / composer / Composer.java next >
Encoding:
Java Source  |  1998-04-08  |  2.7 KB  |  80 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. package netscape.plugin.composer;
  20.  
  21. import java.util.*;
  22.  
  23. /** The Java representation of the Composer
  24.  */
  25. class Composer {
  26.     public static final int PLUGIN_FAIL = 0;
  27.     public static final int PLUGIN_CANCEL = 1;
  28.     public static final int PLUGIN_OK = 2;
  29.     public static final int PLUGIN_NEWTEXT = 3;
  30.     public static final int PLUGIN_EDITURL = 4; /* Must match case 4 in native_netscape_plugin_composer_Composer_mtCallback */
  31.     public Composer(int composerID, int callbackFunc, int mozenv){
  32.         this.composerID = composerID;
  33.         this.callbackFunc = callbackFunc;
  34.         this.mozenv = mozenv;
  35.     }
  36.  
  37.     /** Call from any thread.
  38.     */
  39.     public void pluginFinished(int status, Object arg){
  40.         new ComposerCallback(this, status, arg).enqueue();
  41.     }
  42.  
  43.     /** Call from any thread.
  44.     */
  45.     public void newText(String arg){
  46.         new ComposerCallback(this, PLUGIN_NEWTEXT, arg).enqueue();
  47.     }
  48.  
  49.     public static void editDocument(String url){
  50.         Composer dummy = new Composer(0, 0, 0);
  51.         new ComposerCallback(dummy, PLUGIN_EDITURL, url).enqueue();
  52.     }
  53.  
  54.     /** Only for ComposerCallback to call back in Mozilla thread.
  55.      */
  56.     public void callback(int action, Object arg){
  57.         mtCallback(composerID, callbackFunc, action, arg);
  58.     }
  59.     private native void mtCallback(int context, int callbackFunc, int action, Object arg);
  60.     public final int getMozenv() { return mozenv; }
  61.     private int composerID;
  62.     private int mozenv;
  63.     private int callbackFunc;
  64. }
  65.  
  66. class ComposerCallback extends MozillaCallback {
  67.     public ComposerCallback(Composer composer, int action, Object argument){
  68.         super(composer.getMozenv());
  69.         this.composer = composer;
  70.         this.action = action;
  71.         this.argument = argument;
  72.     }
  73.     protected void perform() {
  74.         composer.callback(action, argument);
  75.     }
  76.     private Composer composer;
  77.     private int action;
  78.     private Object argument;
  79. }
  80.