예제 #1
0
 public void addNotify() {
   synchronized (getTreeLock()) {
     if (getPeer() == null) {
       setPeer(new NullEmbeddedFramePeer());
     }
     super.addNotify();
   }
 }
예제 #2
0
  /**
   * Creates a new <code>java.awt.Frame</code>. This frame is the root for the AWT components that
   * will be embedded within the composite. In order for the embedding to succeed, the composite
   * must have been created with the SWT.EMBEDDED style.
   *
   * <p>IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. When a
   * lightweight component is added as a child of the embedded frame, the cursor does not change. In
   * order to work around both these problems, it is strongly recommended that a heavyweight
   * component such as <code>java.awt.Panel</code> be added to the frame as the root of all
   * components.
   *
   * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code>
   * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *       <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style
   *     </ul>
   *
   * @since 3.0
   */
  public static Frame new_Frame(final Composite parent) {
    if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if ((parent.getStyle() & SWT.EMBEDDED) == 0) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }

    final int /*long*/ handle = parent.view.id;

    Class clazz = null;
    try {
      String className =
          embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame";
      if (embeddedFrameClass == null) {
        clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader());
      } else {
        clazz = Class.forName(className);
      }
    } catch (ClassNotFoundException cne) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cne);
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_UNSPECIFIED, e, " [Error while starting AWT]");
    }

    initializeSwing();
    Object value = null;
    Constructor constructor = null;
    try {
      constructor = clazz.getConstructor(new Class[] {long.class});
      value = constructor.newInstance(new Object[] {new Long(handle)});
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e);
    }
    final Frame frame = (Frame) value;
    frame.addNotify();

    parent.setData(EMBEDDED_FRAME_KEY, frame);

    /* Forward the iconify and deiconify events */
    final Listener shellListener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Deiconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_DEICONIFIED));
                      }
                    });
                break;
              case SWT.Iconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));
                      }
                    });
                break;
            }
          }
        };
    Shell shell = parent.getShell();
    shell.addListener(SWT.Deiconify, shellListener);
    shell.addListener(SWT.Iconify, shellListener);

    /*
     * Generate the appropriate events to activate and deactivate
     * the embedded frame. This is needed in order to make keyboard
     * focus work properly for lightweights.
     */
    Listener listener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Dispose:
                Shell shell = parent.getShell();
                shell.removeListener(SWT.Deiconify, shellListener);
                shell.removeListener(SWT.Iconify, shellListener);
                parent.setVisible(false);
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        try {
                          frame.dispose();
                        } catch (Throwable e) {
                        }
                      }
                    });
                break;
              case SWT.FocusIn:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(true)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
              case SWT.Deactivate:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (!frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(false)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
            }
          }
        };

    parent.addListener(SWT.FocusIn, listener);
    parent.addListener(SWT.Deactivate, listener);
    parent.addListener(SWT.Dispose, listener);

    parent
        .getDisplay()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (parent.isDisposed()) return;
                final Rectangle clientArea = parent.getClientArea();
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.setSize(clientArea.width, clientArea.height);
                        frame.validate();

                        // Bug in Cocoa AWT? For some reason the frame isn't showing up on first
                        // draw.
                        // Toggling visibility seems to be the only thing that works.
                        frame.setVisible(false);
                        frame.setVisible(true);
                      }
                    });
              }
            });

    return frame;
  }
예제 #3
0
파일: MessageBox.java 프로젝트: elecnix/jmf
 public void addNotify() {
   super.addNotify();
   pack();
 }
예제 #4
0
  /**
   * Procesos para ambos metodos de HTTP GET y POST.Creara la imagen del Espectro. Se recogeran los
   * datos de los carbonos y con esta imformacion pintaremos el Espectro. Despues transformaremos el
   * objeto donde pintamos en una imagen jpg, que es lo que devuelve el servlet.
   *
   * @param req peticion servlet
   * @param res respuesta servlet
   * @exception ServletException Si no se puede manejar la peticion
   * @exception IOException Si se produce un error de lectura/escritura durante el manejo de la
   *     peticion
   */
  protected void processRequest(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, java.io.IOException {

    String ref = req.getParameter("referencia");
    int id = (Integer.valueOf(ref)).intValue();
    ServletOutputStream bufferSalida = res.getOutputStream();
    Frame ventanaMarco = new Frame();
    ventanaMarco.addNotify();
    Graphics contextoGrafico = null;
    try {
      Object[] molecula = null;
      molecula = Moleculas.obtenerMolecula(id);
      Object[][] carbonos = null;
      carbonos = Moleculas.obtenerCarbonos(id);
      int altura = 0;
      int xDesplBottom = 710;
      int yDesplBottom = 0;
      int xDesplTop = 710;
      int yDesplTop = 0;
      int xLineIni = 0;
      int yLineIni = 0;
      int xLineEnd = 0;
      int yLineEnd = 0;

      // Construct a matching-size off screen graphics context
      int w = 600;
      int h = 450;
      Image offscreen = ventanaMarco.createImage(w, h);
      contextoGrafico = offscreen.getGraphics();
      contextoGrafico.setFont(new Font("Arial", Font.ITALIC, 11));

      Color rojo = new Color(255, 0, 0);
      Color negro = new Color(0, 0, 0);
      Color gris = new Color(210, 210, 210);
      Font fuente = new Font(null, 0, 12);

      Font fuenteCursiva = new Font("Arial", Font.ITALIC, 12);
      Font fuenteNormal = new Font("Arial", 0, 12);
      Font fuenteNegrita = new Font("Arial", Font.BOLD, 12);

      // Dibujamos la malla
      contextoGrafico = Grafica.malla(contextoGrafico, w, h);

      contextoGrafico.setColor(negro);

      contextoGrafico.setFont(fuenteNormal);
      contextoGrafico.drawString("Nombre: ", 10, 175);

      contextoGrafico.setFont(fuenteNegrita);
      contextoGrafico.drawString(molecula[1].toString(), 70, 175);

      contextoGrafico.setFont(fuenteNormal);
      contextoGrafico.drawString("Disolvente: ", 335, 175);

      contextoGrafico.setFont(fuenteNegrita);
      contextoGrafico.drawString(Transformar.disolvente(molecula[14].toString()), 405, 175);

      contextoGrafico.setFont(new Font("Arial", Font.ITALIC, 11));

      // Dibujamos la escala
      contextoGrafico = Grafica.escalauno(contextoGrafico);

      int temp = 0;
      int contador = 0;
      contextoGrafico.setColor(rojo);
      for (int t = 0; t < carbonos.length; t++) {
        temp = t + 1;
        contador = 1;
        while (temp < carbonos.length) {
          if (((carbonos[temp][3]).toString()).equals((carbonos[t][3]).toString())
              && ((carbonos[temp][2]).toString()).equals((carbonos[t][2]).toString())) contador++;

          temp++;
        }
        if (contador > 3) contador = 3;
        if (!carbonos[t][2].equals("C")) {
          if (carbonos[t][2].equals("CH")) {
            altura = 260 - (24 * contador);
            contextoGrafico.setColor(rojo);
          } else if (carbonos[t][2].equals("CH2")) {
            altura = 260 + (24 * contador);
            contextoGrafico.setColor(verde);
          } else if (carbonos[t][2].equals("CH3")) {
            altura = 260 - (24 * contador);
            contextoGrafico.setColor(violeta);
          }
          if ((Double.parseDouble(carbonos[t][3].toString())) <= 220.0) {
            int numero = ((Transformar.redondea(carbonos[t][3].toString()) * 25) / 10) + 25;
            contextoGrafico.drawLine(600 - numero, 260, 600 - numero, altura);

            String desplazamiento = carbonos[t][3].toString();
            //				System.out.println("desplazamiento: "+desplazamiento);
            Integer despl = Transformar.redondea(desplazamiento);
            /**/
            //			System.out.println("despl: "+despl);
            contextoGrafico.setFont(new Font("Arial", Font.PLAIN, 9));
            if (despl > 0) {
              //					System.out.println("pinto: "+ despl);
              desplazamiento = despl.toString();

              if (altura <= 260) {
                // Pintamos el valor del desplazamiento
                xDesplTop = xDesplTop - 25; // separacion horizontal entre cada valor
                yDesplTop = 180;
                contextoGrafico.drawString(desplazamiento, xDesplTop, yDesplTop);

                // dibujamos una linea vertical desde el desplazamiento
                xLineIni = xDesplTop + 5;
                yLineIni = 180;
                xLineEnd = xLineIni;
                yLineEnd = 198;
                contextoGrafico.drawLine(xLineIni, yLineIni, xLineEnd, yLineEnd);

                // Dibujamos una linea desde el fin de la vertical hasta la linea de Espectro
                xLineIni = xLineEnd;
                yLineIni = yLineEnd;
                xLineEnd = 600 - numero;
                yLineEnd = altura - 8;
                contextoGrafico.drawLine(xLineIni, yLineIni, xLineEnd, yLineEnd);
              } else {
                // Pintamos el valor del desplazamiento
                xDesplBottom = xDesplBottom - 17; // separacion horizontal entre cada valor
                yDesplBottom = 300;
                contextoGrafico.drawString(desplazamiento, xDesplBottom, yDesplBottom);

                // dibujamos una linea vertical desde el desplazamiento
                xLineIni = xDesplBottom + 5;
                yLineIni = 290;
                xLineEnd = xLineIni;
                yLineEnd = 280;
                contextoGrafico.drawLine(xLineIni, yLineIni, xLineEnd, yLineEnd);

                // Dibujamos una linea desde el fin de la vertical hasta la linea de Espectro
                xLineIni = xLineEnd;
                yLineIni = yLineEnd;
                xLineEnd = 600 - numero;
                yLineEnd = altura + 3;
                contextoGrafico.drawLine(xLineIni, yLineIni, xLineEnd, yLineEnd);
              }
            } // if(despl > 0)
          }
        }
      }

      // Dibujamos la escala
      contextoGrafico = Grafica.escalados(contextoGrafico);
      contextoGrafico.setColor(rojo);
      for (int z = 0; z < carbonos.length; z++) {
        temp = z + 1;
        contador = 1;
        while (temp < carbonos.length) {
          if (((carbonos[temp][3]).toString()).equals((carbonos[z][3]).toString())
              && ((carbonos[temp][2]).toString()).equals((carbonos[z][2]).toString())) contador++;
          temp++;
        }
        if (contador > 3) contador = 3;
        if (carbonos[z][2].equals("CH")) {
          if ((Double.parseDouble(carbonos[z][3].toString())) <= 220.0) {
            contextoGrafico.setColor(rojo);
            altura = 340 - (24 * contador);
            int numero = ((Transformar.redondea(carbonos[z][3].toString()) * 25) / 10) + 25;
            contextoGrafico.drawLine(600 - numero, altura, 600 - numero, 340);
          }
        }
      }

      // Dibujamos la escala
      contextoGrafico = Grafica.escalatres(contextoGrafico);
      contextoGrafico.setColor(rojo);
      for (int y = 0; y < carbonos.length; y++) {
        temp = y + 1;
        contador = 1;
        while (temp < carbonos.length) {
          if (((carbonos[temp][3]).toString()).equals((carbonos[y][3]).toString())
              && ((carbonos[temp][2]).toString()).equals((carbonos[y][2]).toString())) contador++;
          temp++;
        }
        if (contador > 3) contador = 3;
        if (carbonos[y][2].equals("C")) {
          altura = 420 - (16 * contador);
          contextoGrafico.setColor(azul);
        } else if (carbonos[y][2].equals("CH")) {
          altura = 420 - (24 * contador);
          contextoGrafico.setColor(rojo);
        } else if (carbonos[y][2].equals("CH2")) {
          altura = 420 - (24 * contador);
          contextoGrafico.setColor(verde);
        } else if (carbonos[y][2].equals("CH3")) {
          altura = 420 - (24 * contador);
          contextoGrafico.setColor(violeta);
        }
        if ((Double.parseDouble(carbonos[y][3].toString())) <= 220.0) {
          int numero = ((Transformar.redondea(carbonos[y][3].toString()) * 25) / 10) + 25;
          contextoGrafico.drawLine(600 - numero, altura, 600 - numero, 420);
        }
      }

      Grafica.disolventetres(contextoGrafico, molecula[14].toString());

      contextoGrafico = Grafica.numerar(contextoGrafico);
      // Encode the off screen graphics into a GIF and send it to the client
      res.setContentType("image/gif");
      GifEncoder encoder = new GifEncoder(offscreen, bufferSalida);
      encoder.encode();
      bufferSalida.flush();
      bufferSalida.close();
    } finally {
      if (contextoGrafico != null) contextoGrafico.dispose();
    }
  }