/**
   * Sets the row data.
   *
   * @param list the list data to convert to row data
   */
  public void setRowData(List<TopicUserCluster> list) {
    removeAllRow();
    for (int row = 0; row < list.size(); row++) {
      TopicUserCluster topicUser = (TopicUserCluster) list.get(row);
      Vector<Object> rowData = new Vector<Object>();

      // user profile image
      ImageIcon profileImage = null;
      try {
        profileImage = new ImageIcon(new URL(topicUser.getUserProfileImage()));
        System.out.println("profile image == " + profileImage.getDescription());
      } catch (Exception ex) {
        ex.printStackTrace();
      }

      rowData.add(row + 1);
      rowData.add(topicUser.getWebsiteId());
      rowData.add(topicUser.getTopicId());
      rowData.add(topicUser.getUserId());
      rowData.add(topicUser.getUserName());
      if (profileImage == null) rowData.add("");
      else rowData.add(profileImage);
      rowData.add(topicUser.getUserUrl());
      rowData.add(topicUser.isTopicUser());
      rowData.add(topicUser.getCluster());
      rowData.add(convertScale(topicUser.getAuthority(), 2));
      rowData.add(convertScale(topicUser.getTopicScore(), 2));
      rowData.add(convertScale(topicUser.getAuthorityTopicScore(), 2));
      tableModel.insertRow(row, rowData);
    }
  }
Пример #2
0
 protected void setValue(Object value) {
   if (value instanceof ImageIcon) {
     ImageIcon ico = (ImageIcon) value;
     setIcon(ico);
     setText(ico.getDescription());
   } else {
     setIcon(null);
     super.setValue(value);
   }
 }
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (isSelected) {
      setBackground(list.getSelectionBackground());
      setForeground(list.getSelectionForeground());
    } else {
      setBackground(list.getBackground());
      setForeground(list.getForeground());
    }

    ImageIcon icon = (ImageIcon) value;
    setText(icon.getDescription());
    setIcon(icon);
    return this;
  }
  void scaleImages(String nameOfChangedImage) {

    if (SnapshotGallery.sharedInstance().isEmpty()) {
      return;
    }

    if (EventQueue.isDispatchThread()) setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    float w = 0, h = 0;
    Insets insets = getInsets();
    int w1 = insets.left + insets.right;
    int h1 = insets.top + insets.bottom + IMAGE_HEIGHT;
    int n = SnapshotGallery.sharedInstance().size();
    String name = null;
    ImageIcon icon = null;
    Image image = null;
    float r = 1;
    for (int i = n - 1; i >= 0; i--) {
      name = SnapshotGallery.sharedInstance().getImageName(i);
      image = SnapshotGallery.sharedInstance().getThumbnail(i);
      if (image == null || name.equals(nameOfChangedImage)) {
        icon = SnapshotGallery.sharedInstance().loadAnnotatedImage(i);
        w = icon.getIconWidth();
        h = icon.getIconHeight();
        r = IMAGE_HEIGHT / h;
        w *= r;
        // This scaling method causes out-of-memory error:
        // icon.getImage().getScaledInstance((int) w, IMAGE_HEIGHT, Image.SCALE_SMOOTH);
        image = ModelerUtilities.scale((BufferedImage) icon.getImage(), r, r);
        SnapshotGallery.sharedInstance().putThumbnail(icon.getDescription(), image);
        image.flush();
        icon.getImage().flush();
      } else {
        w = image.getWidth(this);
        h = image.getHeight(this);
      }
      if (getLayout() instanceof FlowLayout) {
        w1 += (int) w + ((FlowLayout) getLayout()).getHgap();
      } else {
        w1 += (int) w + IMAGE_GAP;
      }
    }
    setPreferredSize(new Dimension(w1, h1));
    if (EventQueue.isDispatchThread()) setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }
Пример #5
0
 /**
  * Returns the value currently selected.
  *
  * @return the value currently selected
  */
 public E getValue() {
   ImageIcon icon = (ImageIcon) getSelectedItem();
   return E.valueOf(enumeration, icon.getDescription());
 }
  @Test
  public void testThatRendererRendersDifferentTypes() {
    final JTree jTree = new JTree();
    CatalogTreeUtils.addCellRenderer(jTree);
    final TreeCellRenderer dapCellRenderer = jTree.getCellRenderer();

    final OpendapLeaf opendapLeaf =
        new OpendapLeaf("This is A dap Node", new InvDataset(null, "") {});
    opendapLeaf.setDapAccess(true);
    final OpendapLeaf fileLeaf =
        new OpendapLeaf("This is A File Node", new InvDataset(null, "") {});
    fileLeaf.setFileAccess(true);
    final Object dapNode = new DefaultMutableTreeNode(opendapLeaf);
    final Object fileNode = new DefaultMutableTreeNode(fileLeaf);
    final Object noDapNode = new DefaultMutableTreeNode("otherNode");

    final Component component =
        dapCellRenderer.getTreeCellRendererComponent(
            jTree, noDapNode, false, false, true, 0, false);

    assertEquals(true, component instanceof DefaultTreeCellRenderer);
    final DefaultTreeCellRenderer tcr1 = (DefaultTreeCellRenderer) component;
    assertEquals("otherNode", tcr1.getText());
    assertEquals(true, tcr1.getIcon() instanceof ImageIcon);

    final Color foreground = tcr1.getForeground();
    final Color background = tcr1.getBackground();
    final Font font = tcr1.getFont();

    final Component component2 =
        dapCellRenderer.getTreeCellRendererComponent(jTree, dapNode, false, false, true, 0, false);

    assertSame(component, component2);

    assertEquals(true, component2 instanceof DefaultTreeCellRenderer);
    final DefaultTreeCellRenderer tcr2 = (DefaultTreeCellRenderer) component2;
    assertEquals("This is A dap Node", tcr2.getText());
    assertEquals(true, tcr2.getIcon() instanceof ImageIcon);
    final ImageIcon icon2 = (ImageIcon) tcr2.getIcon();
    // todo change the expected icon to a realistic icon
    assertEquals(
        "/DRsProduct16.png",
        icon2.getDescription().substring(icon2.getDescription().lastIndexOf("/")));

    assertEquals(foreground, tcr2.getForeground());
    assertEquals(background, tcr2.getBackground());
    assertEquals(font, tcr2.getFont());

    final Component component3 =
        dapCellRenderer.getTreeCellRendererComponent(jTree, fileNode, false, false, true, 0, false);

    assertSame(component, component3);

    assertEquals(true, component3 instanceof DefaultTreeCellRenderer);
    final DefaultTreeCellRenderer tcr3 = (DefaultTreeCellRenderer) component3;
    assertEquals("This is A File Node", tcr3.getText());
    assertEquals(true, tcr3.getIcon() instanceof ImageIcon);
    final ImageIcon icon3 = (ImageIcon) tcr3.getIcon();
    // todo change the expected icon to a realistic icon
    assertEquals(
        "/FRsProduct16.png",
        icon3.getDescription().substring(icon3.getDescription().lastIndexOf("/")));

    assertEquals(foreground, tcr3.getForeground());
    assertEquals(background, tcr3.getBackground());
    assertEquals(font, tcr3.getFont());
  }
  /**
   * Returns list cell renderer component.
   *
   * @param list tree
   * @param value cell value
   * @param index cell index
   * @param isSelected whether cell is selected or not
   * @param cellHasFocus whether cell has focus or not
   * @return cell renderer component
   */
  @Override
  public Component getListCellRendererComponent(
      final JList list,
      final Object value,
      final int index,
      final boolean isSelected,
      final boolean cellHasFocus) {
    super.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus);

    final FileElement element = (FileElement) value;
    final File file = element.getFile();

    // Proper margin
    setMargin(isTilesView() ? tileCellMargin : iconCellMargin);

    // Renderer icon
    String imageSize = null;
    if (iconLabel.isEnabled()) {
      // Thumbnail loading
      synchronized (thumbnailsLock) {
        if (!element.isThumbnailQueued() && !element.isDisabledThumbnailQueued()) {
          queueThumbnailLoad(element, false);
        }
      }

      // Image thumbnail
      final ImageIcon thumbnail = element.getEnabledThumbnail();
      iconLabel.setIcon(thumbnail);

      // Image description
      if (thumbnail != null) {
        imageSize = thumbnail.getDescription();
      }
    } else {
      // Disabled thumbnail loading
      synchronized (thumbnailsLock) {
        if (!element.isDisabledThumbnailQueued()) {
          queueThumbnailLoad(element, true);
        }
      }

      // Image disabled thumbnail
      iconLabel.setDisabledIcon(element.getDisabledThumbnail());
    }

    // Updating file description elements
    if (fileList.getEditedCell() != index) {
      // Settings description
      final FileDescription fileDescription = FileUtils.getFileDescription(file, imageSize);
      nameLabel.setText(fileDescription.getName());

      // Updating tile view additional description
      if (isTilesView()) {
        descriptionLabel.setText(fileDescription.getDescription());

        // Updating size label
        if (fileDescription.getSize() != null) {
          sizeLabel.setText(fileDescription.getSize());
        } else {
          sizeLabel.setText(null);
        }
      } else {
        descriptionLabel.setText(null);
        sizeLabel.setText(null);
      }
    } else {
      nameLabel.setText(null);
      descriptionLabel.setText(null);
      sizeLabel.setText(null);
    }

    return this;
  }