@Override
 public void actionPerformed(ActionEvent e) {
   // If figure icon matches the the button selected's icon - insert figure into board
   Icon icon = ((JButton) e.getSource()).getIcon();
   if (icon.equals(rook.getFigureIcon())) {
     location.setFigure(rook);
   } else if (icon.equals(knight.getFigureIcon())) {
     location.setFigure(knight);
   } else if (icon.equals(bishop.getFigureIcon())) {
     location.setFigure(bishop);
   } else if (icon.equals(queen.getFigureIcon())) {
     location.setFigure(queen);
   }
   // Delete frame when clicked
   dispose();
 }
Пример #2
0
 /** Sanity: icons updated on LF change. */
 public void testTreeIconsUpdateUI() {
   JXTree tree = new JXTree();
   DefaultTreeRenderer renderer = new DefaultTreeRenderer();
   tree.setCellRenderer(renderer);
   WrappingIconPanel before =
       (WrappingIconPanel)
           renderer.getTreeCellRendererComponent(tree, "", false, false, true, -1, false);
   Icon leaf = before.getIcon();
   assertNotNull("sanity", leaf);
   assertEquals("sanity", UIManager.getIcon("Tree.leafIcon"), leaf);
   String lf = UIManager.getLookAndFeel().getName();
   setSystemLF(!defaultToSystemLF);
   if (lf.equals(UIManager.getLookAndFeel().getName())) {
     LOG.info("cannot run test - equal LF" + lf);
     return;
   }
   SwingUtilities.updateComponentTreeUI(tree);
   WrappingIconPanel after =
       (WrappingIconPanel)
           renderer.getTreeCellRendererComponent(tree, "", false, false, true, -1, false);
   Icon leafAfter = after.getIcon();
   assertNotNull("sanity", leafAfter);
   assertFalse("sanity", leaf.equals(leafAfter));
   assertEquals("icon must be updated", UIManager.getIcon("Tree.leafIcon"), leafAfter);
 }
 private void setIcon(Icon i) {
   if (icon.getParent() != null) {
     if (i != null && i.equals(icon.getIcon())) {
       return;
     }
     remove(icon);
   }
   if (i != null) {
     icon = new LinkLabel("", i, this, null);
     add(icon, 0);
   }
 }
 /** Test tracks tree cell renderer. */
 public final void testTracksTreeCellRenderer() {
   TracksTreeCellRenderer ad = new TracksTreeCellRenderer();
   assertNotNull(ad);
   Icon icon = ad.getIcon();
   // make sure we have a different icon after each call
   assertNotNull(
       ad.getTreeCellRendererComponent(
           new JTree(), new GenreNode(getGenre()), true, true, true, 1, true));
   assertFalse(ad.getIcon().equals(icon));
   icon = ad.getIcon();
   assertNotNull(
       ad.getTreeCellRendererComponent(
           new JTree(), new ArtistNode(getArtist()), true, true, true, 1, true));
   assertFalse(icon.equals(ad.getIcon()));
   icon = ad.getIcon();
   assertNotNull(
       ad.getTreeCellRendererComponent(
           new JTree(), new YearNode(getYear()), true, true, true, 1, true));
   assertFalse(icon.equals(ad.getIcon()));
   icon = ad.getIcon();
   assertNotNull(
       ad.getTreeCellRendererComponent(
           new JTree(), new AlbumNode(getAlbum()), true, true, true, 1, true));
   assertFalse(icon.equals(ad.getIcon()));
   icon = ad.getIcon();
   assertNotNull(
       ad.getTreeCellRendererComponent(
           new JTree(), new TrackNode(getTrack()), true, true, true, 1, true));
   assertFalse(icon.equals(ad.getIcon()));
   icon = ad.getIcon();
   assertNotNull(
       ad.getTreeCellRendererComponent(
           new JTree(), new DiscoveryDateNode("str"), true, true, true, 1, true));
   assertFalse(icon.equals(ad.getIcon()));
   icon = ad.getIcon();
   assertNotNull(
       ad.getTreeCellRendererComponent(new JTree(), "unknown object", true, true, true, 1, true));
   assertFalse(icon.equals(ad.getIcon()));
   icon = ad.getIcon();
 }