⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thumblabel.java

📁 java写的图片浏览器,类似acds
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    popupMenu.add(convert_item);

    browse_item.addActionListener(
        new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                parentFrame.ChangeThumbNailDirectory(thumb_list[CurrentSelectedIndex].imageFullFileName);
            }
        }
    );

    slide_item.addActionListener(
        new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                parentFrame.ChangeThumbNailDirectory(thumb_list[CurrentSelectedIndex].imageFullFileName);
                parentFrame.Run_Slide_Show_For_Dir();
            }
        }
    );
    dirPopupMenu.add(browse_item);
    dirPopupMenu.add(slide_item);

    browse_link_item.addActionListener(
        new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                parentFrame.ChangeThumbNailDirectory(thumb_list[CurrentSelectedIndex].imageFullFileName);
            }
        }
    );

    slide_link_item.addActionListener(
        new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                parentFrame.ChangeThumbNailDirectory(thumb_list[CurrentSelectedIndex].imageFullFileName);
                parentFrame.Run_Slide_Show_For_Dir();
            }
        }
    );

    linkPopupMenu.add(browse_link_item);
    linkPopupMenu.add(slide_link_item);

    ActionListener actionRename = new ActionListener() {
                                      public void actionPerformed( ActionEvent event ) {
                                          thumb_list[CurrentSelectedIndex].Rename_Thumb();
                                      }
                                  };

    ActionListener actionDelete = new ActionListener() {
                                      public void actionPerformed( ActionEvent event ) {
                                          Delete_Selected_Thumb_by_PopupMenu();
                                      }
                                  };

    rename_item.addActionListener( actionRename );

    rename_dir_item.addActionListener( actionRename );

    delete_item.addActionListener( actionDelete );

    delete_dir_item.addActionListener( actionDelete );

    popupMenu.add(rename_item);
    popupMenu.add(delete_item);
    dirPopupMenu.add(rename_dir_item);
    dirPopupMenu.add(delete_dir_item);

    Quality = quality;

    flowLayout = new FlowLayout();
    flowLayout.setAlignment(15);
    label = new JLabel();
    label.setLayout(flowLayout);
    ImageIcon iIcon;

    folderIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/folder.gif"));
    diskIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/diskThumb.gif"));
    mediaIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/media.PNG"));

    int ThumbAreaWidth = thumb_width + 10;
    int ThumbAreaHeight = thumb_height*full_file_list_length + full_file_list_length*flowLayout.getVgap();

    label.setPreferredSize(new Dimension(ThumbAreaWidth, ThumbAreaHeight));

    addComponentListener(new ComponentListener() {
        public void componentResized( ComponentEvent e ) {
            Resize_View_Area();
        }
        public void componentMoved( ComponentEvent e ) {}
        public void componentShown( ComponentEvent e ) {}
        public void componentHidden( ComponentEvent e ) {}
    });

    this.setViewportView(label);
  } // end ThumbLabel()

  void SelectNextThumb(int nextRelation) {
      CurrentSelectedIndex = CurrentSelectedIndex + nextRelation;
      if (CurrentSelectedIndex < thumb_count && CurrentSelectedIndex >= 0)
          thumb_list[CurrentSelectedIndex].doClick();
  }

  public void run() {
  try {
  // Get thumb size - incase user change option
    Thumb_width = parentFrame.thumb_width;
    Thumb_height = parentFrame.thumb_height;
    Image_thumb_height = Thumb_height - 17;
    // 10 is the alignment for the image within thumbnail
    int Displayed_thumb_width = Thumb_width - 10;
    int Displayed_thumb_height = Image_thumb_height - 10;
  //
    ImageIcon iIcon;

    boolean addThisIcon = true;

    int imageW, imageH;
    float f_imageW, f_imageH, imageScale;
    thumb_count = 0;

    int thumb_added_recently = 0; // only resize thumbnail area when need a new row

    int row = 0,
        col = 0;
    if (!firstTime)
      firstTime = true;
    else
      label.removeAll();

    thumb_list = new JThumbButton[full_file_list_length];

    this.getVerticalScrollBar().setUnitIncrement(Thumb_height + flowLayout.getVgap());

    for (int i = 0; i < full_file_list_length; i++)
    {
        if (full_file_list[i] == null)
            i++;

        parentFrame.SetProgressValue((int)((i + 1)*100/(float)full_file_list.length));
        parentFrame.repaint();
/* testing */
        if (full_file_list[i].isDirectory())
        {
            String unknownString = full_file_list[i].toString();
            if ( unknownString.endsWith(":\\") ) // this is a hard disk (Windows platform)
            {
                thumb_list[thumb_count] = new JThumbButton(". .",
                                                mediaIcon,
                                                unknownString,
                                                true,
                                                i,
                                                true);
            }
            else // directory
            {
                String thumbName = full_file_list[i].getName();
                boolean isLink = false;
                if (i == 0 && parentFrame.getGoUpButtonState()) {
                    thumbName = ". .";
                    isLink = true;
                }
                thumb_list[thumb_count] = new JThumbButton(thumbName,
                                            folderIcon,
                                            unknownString,
                                            true,
                                            i,
                                            isLink);
            }
        }
        else /* not directory */
        {
            String fullfilename = full_file_list[i].toString();
            String filename = full_file_list[i].getName();
            iIcon = parentFrame.Load_Image(fullfilename);

            // calculate image attribute in thumbnail
            imageW = iIcon.getIconWidth();
            imageH = iIcon.getIconHeight();

            if ( (imageW > 0 && imageH > 0) && (imageW > Displayed_thumb_width || imageH > Displayed_thumb_height) )
            {
                imageScale = (float)imageW / imageH;
                if (imageH > imageW)
                {
                    imageH = Displayed_thumb_height;
                    imageW = (int)(imageH * imageScale);
                }
                else
                {
                    imageW = Displayed_thumb_width;
                    imageH = (int) (imageW / imageScale);
                    if (imageH > Displayed_thumb_height)
                    {
                        imageH = Displayed_thumb_height;
                        imageW = (int)(imageH * imageScale);
                    }
                }
                iIcon = new ImageIcon(iIcon.getImage().getScaledInstance(
                                        imageW, imageH, Image.SCALE_DEFAULT));

                //thumb_list[thumb_count] = new JThumbButton(full_file_list[i].getName(), iIcon, full_file_list[i].toString(), false, i, false);
                thumb_list[thumb_count] = new JThumbButton(filename, iIcon, fullfilename, false, i, false);
            }
            else if ( (imageW > 0 && imageH > 0) && (imageW < Thumb_width && imageH < Image_thumb_height) )
            {
                iIcon = new ImageIcon(iIcon.getImage().getScaledInstance(
                                        imageW, imageH, Image.SCALE_DEFAULT));
                //thumb_list[thumb_count] = new JThumbButton(full_file_list[i].getName(), iIcon, full_file_list[i].toString(), false, i, false);
                thumb_list[thumb_count] = new JThumbButton(filename, iIcon, fullfilename, false, i, false);
            }       
            else
            {
                if (filename.endsWith(".mpg") || 
                    filename.endsWith(".mpeg") ||
                    filename.endsWith(".avi") ||
                    filename.endsWith(".mov") ||
                    filename.endsWith(".mp3") ||
                    filename.endsWith(".wav")) 
                {
                    thumb_list[thumb_count] = new JThumbButton(filename,
                                            mediaIcon,
                                            fullfilename,
                                            false,
                                            i,
                                            true);
                } else 
                    addThisIcon = false;
            }
        }

        if (addThisIcon) {
          try {
            label.add(thumb_list[thumb_count]);
            thumb_list[thumb_count].setPreferredSize(new Dimension(Thumb_width, Thumb_height));
            thumb_list[thumb_count].setThumbID(thumb_count);
            thumb_count++;

            // only resize thumbnail area when need a new row
            if (thumb_added_recently == thumbs_on_row) {
              Resize_View_Area();
              thumb_added_recently = 0;
            }
            else
              thumb_added_recently++;

            Thread.sleep(1);

            synchronized(this) {
              while (hold_on) {
                Thread.sleep(1000);
              }
            }

            this.validate();

          } catch (NullPointerException npe) {}
        }
        else
            addThisIcon = true;
    }// end for loop

    int ThumbAreaWidth = Thumb_width + 10;
    int ThumbAreaHeight = Thumb_height*thumb_count + thumb_count*flowLayout.getVgap();

    Resize_View_Area();
    this.setViewportView(label);
    this.validate();
  } catch (InterruptedException ie) {/*continue;*/}
  }// end run()

  public void DisplayImages(File[] file_list) {
      full_file_list = file_list;
      //Added by Neoya 2002-03-06
      if (full_file_list!=null)
        full_file_list_length=full_file_list.length;
      else
        full_file_list_length=0;
      int ThumbAreaWidth = Thumb_width + 10;
      int ThumbAreaHeight = full_file_list_length*(Thumb_height + flowLayout.getVgap());

      label.setPreferredSize(new Dimension(ThumbAreaWidth, ThumbAreaHeight));
  }

  public int getNumberOfThumbsOnRow() {
      return thumbs_on_row;
  }

  public void Resize_View_Area() {
      view_width = getWidth();
      int scrollBar_width = 16;
      thumbs_on_row = (view_width - scrollBar_width)/( Thumb_width + flowLayout.getVgap() );

      thumbs_on_row = (thumbs_on_row == 0)?1:thumbs_on_row;

      int number_of_row = thumb_count / thumbs_on_row;
      if (last_number_of_row != number_of_row) {
          if (thumb_count % thumbs_on_row != 0) {
            number_of_row++;
          }
//          System.out.println(thumb_count + " thumbs, " + thumbs_on_row + "thumbs on row, " + number_of_row + " rows");
          view_height = number_of_row * (Thumb_height + flowLayout.getVgap());
          label.setPreferredSize(new Dimension(Thumb_width + 10, view_height));
      } else {
          last_number_of_row = number_of_row;
      }
  }

  public void Delete_Selected_Thumb_by_PopupMenu() {
      File tempFile = new File(thumb_list[CurrentSelectedIndex].imageFullFileName);
      if (tempFile.delete()) {
          thumb_list[CurrentSelectedIndex].setVisible(false);
          parentFrame.FileRenamed = true;
      }
      else
          JOptionPane.showMessageDialog(null, "Cannot delete " +
                                  tempFile.getName() + " file");
  }

  public void Hide_Selected_Thumb() {
      thumb_list[CurrentSelectedIndex].setVisible(false);
  }

  public void Stop() {
      hold_on = true;
      parentFrame.statusBar.HideProgressBar(true);
  }

  public void Go() {
      hold_on = false;
      parentFrame.statusBar.HideProgressBar(false);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -