public void testContextIsJAppletWhenJAppletIsShown() {
   JApplet applet = new JApplet();
   JButton button = new JButton();
   applet.getContentPane().add(button);
   windowContext.setActiveWindow(applet);
   assertSame(applet, windowContext.activeWindow());
 }
  private void initPanel(Object f, Method method) {
    try {

      JApplet _applet = (JApplet) f;
      String panelClassName = (String) getValue(method, _applet, "panelClassName");
      Class panelClass = Class.forName(panelClassName);
      _applet.getContentPane().setLayout(new BorderLayout());
      Object panelInstance = panelClass.newInstance();
      JComponent panel = (JComponent) panelInstance;
      _applet.getContentPane().removeAll();
      _applet.getContentPane().setLayout(new BorderLayout());
      _applet.getContentPane().add(panel, BorderLayout.CENTER);
      SwingUtilities.updateComponentTreeUI(_applet);

    } catch (Exception e) {
      throw new RuntimeException(e.getMessage(), e);
    }
  }
 public void testContextIsJAppletWhenACompentInItHasFocus() {
   Frame frame = new Frame();
   JApplet applet = new JApplet();
   JButton button = new JButton();
   frame.add(applet);
   applet.getContentPane().add(button);
   setFocusManager(button);
   windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, button));
   assertSame(applet, windowContext.activeWindow());
 }
Example #4
0
  /**
   * Call this method to initialize an applet from your launcher class <code>MyAppletLauncher.init()
   * </code> method.
   *
   * @param sClass class name in form "MyClass" for default package or "com.abc.MyClass" for class
   *     in some package
   * @param appletParent parent applet from a launcher.
   * @throws Throwable wrapper for many exceptions thrown while applet instantiation and calling
   *     init() method.
   */
  public void initApplet(String sClass, final JApplet appletParent) throws Throwable {
    Class<?> clazz = loadClass(sClass);
    logInfo(
        LogArea.CONFIG, "initApplet() --> %s.init(); Loader: %s", sClass, clazz.getClassLoader());
    applet = (JApplet) clazz.newInstance();
    applet.setStub(
        new AppletStub() {
          @Override
          public boolean isActive() {
            return appletParent.isActive();
          }

          @Override
          public URL getDocumentBase() {
            return appletParent.getDocumentBase();
          }

          @Override
          public URL getCodeBase() {
            return appletParent.getCodeBase();
          }

          @Override
          public String getParameter(String name) {
            return appletParent.getParameter(name);
          }

          @Override
          public AppletContext getAppletContext() {
            return appletParent.getAppletContext();
          }

          @Override
          public void appletResize(int width, int height) {
            appletParent.resize(width, height);
          }
        });
    applet.init();
    appletParent.setContentPane(applet.getContentPane());
  }
  /** Inits the layout. */
  private void initLayout() {
    self = this;
    window = JSObject.getWindow(self);
    // fileLocation.setEditable(false);
    fileNameField = new JTextField(25);
    fileNameField.setEditable(false);
    fileNameField.setBackground(Color.WHITE);

    chooseBtn = new JButton();
    chooseBtn.setText(getMessage(MessageCode.FTP_FILE_CHOOSE));

    uploadBtn = new JButton();
    uploadBtn.setText(getMessage(MessageCode.FTP_FILE_UPLOAD));
    uploadBtn.setEnabled(false);

    fileChooser = new JFileChooser();
    fileChooser.setDialogTitle(getMessage(MessageCode.FTP_FILECHOOSER_TITLE));
    fileChooser.setAcceptAllFileFilterUsed(false);

    final boolean filterTypes = StringUtils.isNotBlank(allowTypes);
    final boolean filterMaxSize = maxSize > 0;

    if (filterTypes || filterMaxSize) {
      fileChooser.setFileFilter(
          new FileFilter() {
            @Override
            public String getDescription() {
              return filterTypes
                  ? getMessage(MessageCode.ALLOW_ALL_FILE)
                  : getMessage(MessageCode.ALLOW_SOME_FILE) + allowTypes;
            }

            @Override
            public boolean accept(File f) {

              if (f.isDirectory()) {
                return true;
              }

              boolean flag = true;
              if (filterTypes) {
                flag = false;
                String ext = FilenameUtils.getExtension(f.getName());
                String[] types = StringUtils.split(allowTypes, ",");
                for (String t : types) {
                  if (StringUtils.equalsIgnoreCase(t, ext)) {
                    flag = true;
                    break;
                  }
                }
              }

              if (flag && filterMaxSize) {
                flag = FileUtils.sizeOf(f) <= maxSize;
              }

              return flag;
            }
          });
    }

    progressInfo = new JLabel(getMessage(MessageCode.FTP_UPLOAD_PROGRESS));

    progressBar = new JProgressBar(0, 100);
    progressBar.setPreferredSize(new Dimension(380, 20));
    // progressBar.setString("请选择文件");
    progressBar.setStringPainted(true);
    progressBar.setBorderPainted(true);
    // progressBar.setBackground(Color.gray);
    // progressBar.setForeground(Color.blue);

    progressPanel = new JPanel();
    progressPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    progressPanel.add(progressInfo);
    progressPanel.add(progressBar);
    progressPanel.setBackground(Color.WHITE);
    progressPanel.setVisible(false);

    // main.add(fileLocation);
    selectPanel = new JPanel();
    selectPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    selectPanel.add(fileNameField);
    selectPanel.add(chooseBtn);
    selectPanel.add(uploadBtn);
    selectPanel.setBackground(Color.WHITE);

    GridLayout layout = new GridLayout(2, 1);
    Container container = self.getContentPane();
    container.setLayout(layout);
    container.add(selectPanel);
    container.add(progressPanel);
    container.setBackground(Color.WHITE);
  }