/**
   * Returns the drag icon used to represent a cell in all drag operations.
   *
   * @param tree the parent tree object
   * @param dragObject the dragged object
   * @param index the index of the dragged object in the tree
   * @return the drag icon
   */
  public Icon getDragIcon(JTree tree, Object dragObject, int index) {
    ContactListTreeCellRenderer dragC =
        (ContactListTreeCellRenderer)
            getTreeCellRendererComponent(
                tree,
                dragObject,
                false, // is selected
                false, // is expanded
                true, // is leaf
                index,
                true // has focus
                );

    // We should explicitly set the bounds of all components in order that
    // they're correctly painted by paintIcon afterwards. This fixes empty
    // drag component in contact list!
    dragC.setBounds(0, 0, dragC.getIconWidth(), dragC.getIconHeight());

    Icon rightLabelIcon = rightLabel.getIcon();
    int imageHeight = 0;
    int imageWidth = 0;
    if (rightLabelIcon != null) {
      imageWidth = rightLabelIcon.getIconWidth();
      imageHeight = rightLabelIcon.getIconHeight();
      dragC.rightLabel.setBounds(tree.getWidth() - imageWidth, 0, imageWidth, imageHeight);
    }

    dragC.statusLabel.setBounds(0, 0, statusLabel.getWidth(), statusLabel.getHeight());

    dragC.nameLabel.setBounds(
        statusLabel.getWidth(), 0, tree.getWidth() - imageWidth - 5, nameLabel.getHeight());

    dragC.displayDetailsLabel.setBounds(
        displayDetailsLabel.getX(),
        nameLabel.getHeight(),
        displayDetailsLabel.getWidth(),
        displayDetailsLabel.getHeight());

    return dragC;
  }
Пример #2
0
  void displayWifiPassword() {
    Config config = Config.instance();
    config.setEmail(emailField.getText());
    config.setRememberPassword(rememberPasswordCheckbox.getState());
    config.setPassword(passField.getText());

    config.updateConfig();

    if (Config.instance().getQRImage() == null || Config.instance().getWifiPassword().isEmpty()) {
      if (Config.instance().getWifiPassword().isEmpty()) {
        wifiPasswordField.setText("");
      }

      hintLabel.setText("QRCode has not been generated");
      qrCodeLabel.setIcon(idleIcon);
      return;
    }

    try {

      wifiPasswordField.setText(Config.instance().getWifiPassword());

      BufferedImage qrImage = Config.instance().getQRImage();

      int width = qrCodeLabel.getWidth();
      int height = qrCodeLabel.getHeight();

      // make a square image
      int length = width < height ? width : height;

      ImageIcon imgIcon = new ImageIcon();
      imgIcon.setImage(qrImage.getScaledInstance(length, length, Image.SCALE_AREA_AVERAGING));

      hintLabel.setText("Scan QRCode with mobile client to login clear-guest!");
      wifiPasswordField.setText(Config.instance().getWifiPassword());
      qrCodeLabel.setIcon(imgIcon);
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          mainPanel,
          "Failed to generate QR Image, please try again",
          "QRCode Generation Failed",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace();
    }
  }