Ejemplo n.º 1
0
 private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) {
   RescaleOp op =
       new RescaleOp(new float[] {1.2f, 1.2f, 1.2f, 1f}, new float[] {0f, 0f, 0f, 0f}, null);
   BufferedImage img =
       new BufferedImage(
           srcIcon.getIconWidth(), srcIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics g = img.getGraphics();
   // g.drawImage(srcIcon.getImage(), 0, 0, null);
   srcIcon.paintIcon(null, g, 0, 0);
   g.dispose();
   return new ImageIcon(op.filter(img, null));
 }
Ejemplo n.º 2
0
 private static ImageIcon scale(ImageIcon src) {
   // System.out.println(scaleFactor);
   if (scaleFactor > 1) {
     int w = (int) (scaleFactor * src.getIconWidth());
     int h = (int) (scaleFactor * src.getIconHeight());
     int type = BufferedImage.TYPE_INT_ARGB;
     BufferedImage dst = new BufferedImage(w, h, type);
     Graphics2D g2 = dst.createGraphics();
     g2.drawImage(src.getImage(), 0, 0, w, h, null);
     g2.dispose();
     return new ImageIcon(dst);
   } else return src;
 }
Ejemplo n.º 3
0
  public MainPanel() {
    super(new BorderLayout());
    ActionListener al =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JComponent c = (JComponent) e.getSource();
            if (ra.equals(c)) {
              label.setIcon(iia);
            } else if (rb.equals(c)) {
              label.setIcon(iib);
            } else {
              label.setIcon(new ImageIcon(createImage(source)));
            }
          }
        };
    JPanel p = new JPanel();
    ButtonGroup bg = new ButtonGroup();
    for (JRadioButton r : Arrays.asList(ra, rb, rr)) {
      r.addActionListener(al);
      bg.add(r);
      p.add(r);
    }
    ra.setSelected(true);
    add(label);
    add(p, BorderLayout.SOUTH);

    int w = iia.getIconWidth();
    int h = iia.getIconHeight();
    int[] pixelsA = getData(iia, w, h);
    int[] pixelsB = getData(iib, w, h);
    source = new MemoryImageSource(w, h, pixelsA, 0, w);
    for (int i = 0; i < pixelsA.length; i++) {
      if (pixelsA[i] == pixelsB[i]) {
        pixelsA[i] = pixelsA[i] & 0x44FFFFFF;
      }
    }

    setPreferredSize(new Dimension(320, 240));
  }
Ejemplo n.º 4
0
  private JLabel makeLabelIcon() {
    ImageIcon i = new ImageIcon(getClass().getResource("duke.gif"));
    Dimension d = new Dimension(i.getIconWidth(), i.getIconHeight());
    final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.createGraphics();
    i.paintIcon(null, g, 0, 0);
    g.dispose();
    final JLabel icon =
        new JLabel(i) {
          @Override
          public boolean contains(int x, int y) {
            return super.contains(x, y) && ((image.getRGB(x, y) >> 24) & 0xff) != 0;
          }
        };
    icon.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    MouseAdapter l =
        new MouseAdapter() {
          private final transient Point start = new Point();
          private Point loc;

          @Override
          public void mousePressed(MouseEvent me) {
            start.setLocation(me.getPoint());
          }

          @Override
          public void mouseDragged(MouseEvent me) {
            loc = icon.getLocation(loc);
            int x = loc.x - start.x + me.getX();
            int y = loc.y - start.y + me.getY();
            icon.setLocation(x, y);
          }
        };
    icon.addMouseListener(l);
    icon.addMouseMotionListener(l);
    icon.setBounds(new Rectangle(22, 22, d.width, d.height));
    return icon;
  }