Пример #1
0
  /**
   * Starts accessing the native graphics in the underlying OS, when accessing the native graphics
   * Codename One shouldn't be used! The native graphics is unclipped and untranslated by default
   * and its the responsibility of the caller to clip/translate appropriately.
   *
   * <p>When finished with the native graphics it is essential to <b>invoke
   * endNativeGraphicsAccess</b>
   *
   * @return an instance of the underlying native graphics object
   */
  public Object beginNativeGraphicsAccess() {
    if (nativeGraphicsState != null) {
      throw new IllegalStateException("beginNativeGraphicsAccess invoked twice in a row");
    }
    Boolean a = Boolean.FALSE, b = Boolean.FALSE;
    if (isAntiAliasedText()) {
      b = Boolean.TRUE;
    }
    if (isAntiAliased()) {
      a = Boolean.TRUE;
    }

    nativeGraphicsState =
        new Object[] {
          new Integer(getTranslateX()),
          new Integer(getTranslateY()),
          new Integer(getColor()),
          new Integer(getAlpha()),
          new Integer(getClipX()),
          new Integer(getClipY()),
          new Integer(getClipWidth()),
          new Integer(getClipHeight()),
          a,
          b
        };
    translate(-getTranslateX(), -getTranslateY());
    setAlpha(255);
    setClip(
        0, 0, Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
    return nativeGraphics;
  }
Пример #2
0
 private HashMap<Dimension, Object> getScaleCache() {
   if (scaleCache == null) {
     HashMap<Dimension, Object> h = new HashMap<Dimension, Object>();
     scaleCache = Display.getInstance().createSoftWeakRef(h);
     return h;
   }
   HashMap<Dimension, Object> h =
       (HashMap<Dimension, Object>) Display.getInstance().extractHardRef(scaleCache);
   if (h == null) {
     h = new HashMap<Dimension, Object>();
     scaleCache = Display.getInstance().createSoftWeakRef(h);
   }
   return h;
 }
Пример #3
0
 int[] getRGBCache() {
   if (rgbCache != null) {
     int[] rgb = (int[]) Display.getInstance().extractHardRef(rgbCache);
     return rgb;
   }
   return null;
 }
Пример #4
0
 /**
  * Returns the content of this image as a newly created ARGB array or a cached instance if
  * possible. Note that cached instances may be garbage collected.
  *
  * @return array instance containing the ARGB data within this image
  */
 public int[] getRGBCached() {
   int[] r = getRGBCache();
   if (r == null) {
     r = getRGBImpl();
     rgbCache = Display.getInstance().createSoftWeakRef(r);
   }
   return r;
 }
Пример #5
0
 public com.codename1.ui.Label findLabel() {
   com.codename1.ui.Label cmp =
       (com.codename1.ui.Label) findByName("Label", Display.getInstance().getCurrent());
   if (cmp == null && aboutToShowThisContainer != null) {
     cmp = (com.codename1.ui.Label) findByName("Label", aboutToShowThisContainer);
   }
   return cmp;
 }
Пример #6
0
 public com.codename1.ui.Container findContainer() {
   com.codename1.ui.Container cmp =
       (com.codename1.ui.Container) findByName("Container", Display.getInstance().getCurrent());
   if (cmp == null && aboutToShowThisContainer != null) {
     cmp = (com.codename1.ui.Container) findByName("Container", aboutToShowThisContainer);
   }
   return cmp;
 }
Пример #7
0
 public com.codename1.ui.Button findButton() {
   com.codename1.ui.Button cmp =
       (com.codename1.ui.Button) findByName("Button", Display.getInstance().getCurrent());
   if (cmp == null && aboutToShowThisContainer != null) {
     cmp = (com.codename1.ui.Button) findByName("Button", aboutToShowThisContainer);
   }
   return cmp;
 }
Пример #8
0
 public com.codename1.ui.TextArea findTextArea() {
   com.codename1.ui.TextArea cmp =
       (com.codename1.ui.TextArea) findByName("TextArea", Display.getInstance().getCurrent());
   if (cmp == null && aboutToShowThisContainer != null) {
     cmp = (com.codename1.ui.TextArea) findByName("TextArea", aboutToShowThisContainer);
   }
   return cmp;
 }
Пример #9
0
 public com.codename1.ui.Tabs findTabs1() {
   com.codename1.ui.Tabs cmp =
       (com.codename1.ui.Tabs) findByName("Tabs1", Display.getInstance().getCurrent());
   if (cmp == null && aboutToShowThisContainer != null) {
     cmp = (com.codename1.ui.Tabs) findByName("Tabs1", aboutToShowThisContainer);
   }
   return cmp;
 }
Пример #10
0
 public com.codename1.maps.MapComponent findMapComponent() {
   com.codename1.maps.MapComponent cmp =
       (com.codename1.maps.MapComponent)
           findByName("MapComponent", Display.getInstance().getCurrent());
   if (cmp == null && aboutToShowThisContainer != null) {
     cmp = (com.codename1.maps.MapComponent) findByName("MapComponent", aboutToShowThisContainer);
   }
   return cmp;
 }
Пример #11
0
 public com.codename1.components.MultiButton findMultiButton3() {
   com.codename1.components.MultiButton cmp =
       (com.codename1.components.MultiButton)
           findByName("MultiButton3", Display.getInstance().getCurrent());
   if (cmp == null && aboutToShowThisContainer != null) {
     cmp =
         (com.codename1.components.MultiButton)
             findByName("MultiButton3", aboutToShowThisContainer);
   }
   return cmp;
 }
Пример #12
0
 public void actionPerformed(ActionEvent evt) {
   if (adapter != null) {
     try {
       byte[] d;
       InputStream is;
       if (storageFile != null) {
         d = new byte[Storage.getInstance().entrySize(storageFile + IMAGE_SUFFIX)];
         is = Storage.getInstance().createInputStream(storageFile + IMAGE_SUFFIX);
       } else {
         d =
             new byte
                 [(int)
                     FileSystemStorage.getInstance().getLength(fileSystemFile + IMAGE_SUFFIX)];
         is = FileSystemStorage.getInstance().openInputStream(fileSystemFile + IMAGE_SUFFIX);
       }
       Util.readFully(is, d);
       EncodedImage img = EncodedImage.create(d);
       EncodedImage adapted;
       if (adapter.isAsyncAdapter()) {
         adapt = img;
         Display.getInstance().invokeAndBlock(this);
         adapted = adaptedIns;
         adaptedIns = null;
         adapt = null;
       } else {
         adapted = adapter.adaptImage(img, placeholder);
       }
       if (storageFile != null) {
         OutputStream o = Storage.getInstance().createOutputStream(storageFile);
         o.write(adapted.getImageData());
         o.close();
         Storage.getInstance().deleteStorageFile(storageFile + IMAGE_SUFFIX);
       } else {
         OutputStream o = FileSystemStorage.getInstance().openOutputStream(fileSystemFile);
         o.write(adapted.getImageData());
         o.close();
         FileSystemStorage.getInstance().delete(fileSystemFile + IMAGE_SUFFIX);
       }
     } catch (IOException ex) {
       ex.printStackTrace();
       return;
     }
   }
   fetching = false;
   // invoke fetch again to load the local files
   fetch();
 }
Пример #13
0
  boolean scaleArray(
      int srcWidth,
      int srcHeight,
      int height,
      int width,
      int[] currentArray,
      int[] destinationArray) {
    // Horizontal Resize
    int yRatio = (srcHeight << 16) / height;
    int xRatio = (srcWidth << 16) / width;
    int xPos = xRatio / 2;
    int yPos = yRatio / 2;

    // if there is more than 16bit color there is no point in using mutable
    // images since they won't save any memory
    boolean testOpaque = Display.getInstance().numColors() <= 65536 && (!opaqueTested);
    boolean currentOpaque = true;
    for (int y = 0; y < height; y++) {
      int srcY = yPos >> 16;
      getRGB(currentArray, 0, 0, srcY, srcWidth, 1);
      for (int x = 0; x < width; x++) {
        int srcX = xPos >> 16;
        int destPixel = x + y * width;
        if ((destPixel >= 0 && destPixel < destinationArray.length)
            && (srcX < currentArray.length)) {
          destinationArray[destPixel] = currentArray[srcX];

          // if all the pixels have an opaque alpha channel then the image is opaque
          currentOpaque =
              testOpaque && currentOpaque && (currentArray[srcX] & 0xff000000) == 0xff000000;
        }
        xPos += xRatio;
      }
      yPos += yRatio;
      xPos = xRatio / 2;
    }
    if (testOpaque) {
      this.opaque = currentOpaque;
    }
    return opaque;
  }
Пример #14
0
 private static void repaint() {
   Display display = Display.getInstance();
   if (display != null) {
     display.repaint();
   }
 }
Пример #15
0
 /**
  * Returns a cached scaled image
  *
  * @param size the size of the cached image
  * @return cached image
  */
 Image getCachedImage(Dimension size) {
   Object w = getScaleCache().get(size);
   return (Image) Display.getInstance().extractHardRef(w);
 }
Пример #16
0
 /**
  * Returns a cached scaled image
  *
  * @param size the size of the cached image
  * @return cached image
  */
 void cacheImage(Dimension size, Image i) {
   Object w = Display.getInstance().createSoftWeakRef(i);
   getScaleCache().put(size, w);
 }