Ejemplo n.º 1
0
 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
   if (isVisible()) {
     g.drawImage(
         icon.getImage(),
         x,
         y,
         (int) (icon.getIconWidth() * scale),
         (int) (icon.getIconHeight() * scale),
         this);
   }
 }
Ejemplo n.º 2
0
  public void paint(Graphics g) {
    super.paint(g);
    if (thumbnail != null) {
      int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
      int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;
      if (y < 0) {
        y = 0;
      }

      if (x < 5) {
        x = 5;
      }
      thumbnail.paintIcon(this, g, x, y);
    }
  }
Ejemplo n.º 3
0
  /**
   * Sets the icon for the given file.
   *
   * @param file the file to set an icon for
   * @return the byte array containing the thumbnail
   */
  private byte[] getFileThumbnail(File file) {
    byte[] bytes = null;
    if (FileUtils.isImage(file.getName())) {
      try {
        ImageIcon image = new ImageIcon(file.toURI().toURL());
        int width = image.getIconWidth();
        int height = image.getIconHeight();

        if (width > THUMBNAIL_WIDTH) width = THUMBNAIL_WIDTH;
        if (height > THUMBNAIL_HEIGHT) height = THUMBNAIL_HEIGHT;

        bytes = ImageUtils.getScaledInstanceInBytes(image.getImage(), width, height);
      } catch (MalformedURLException e) {
        if (logger.isDebugEnabled()) logger.debug("Could not locate image.", e);
      }
    }
    return bytes;
  }
Ejemplo n.º 4
0
  // Inner class to manage help modal diaglog object.
  class HelpHandler extends JDialog implements ActionListener {
    // Define and initialize AWT container.
    Container c = getContentPane();

    // Define and initialize Swing widgets.
    JButton okButton = new JButton("Check the Java API");
    ImageIcon imageIcon = new ImageIcon("surfing.gif");
    JLabel image = new JLabel(imageIcon);

    // Define and intialize phsyical size dimensions.
    int left = 0;
    int top = 0;
    int buttonWidth = 150;
    int buttonHeight = 25;
    int imageWidth = imageIcon.getIconWidth();
    int imageHeight = imageIcon.getIconHeight();
    int offsetMargin = 20;

    // The dialog width and height are derived from base objects.
    int dialogWidth = imageWidth + offsetMargin;
    int dialogHeight = imageHeight + buttonHeight + (3 * offsetMargin);

    // --------------------------- Constructor -------------------------------/

    // The inner class requires an owning frame and cannot be called from
    // a default constructor.  So, the default constructor is excluded.
    public HelpHandler(Frame owner, boolean modal) {
      super(owner, modal);
      buildDialogBox();
    }

    // -------------------------- Begin Methods ------------------------------/

    // Method to build the dialog box for help.
    private void buildDialogBox() {
      // Set the JDialog window properties.
      setTitle("Learning about Java");
      setResizable(false);
      setSize(dialogWidth, dialogHeight);

      // Define behaviors of container.
      c.setLayout(null);
      c.setBackground(Color.cyan);
      c.add(image);
      c.add(okButton);

      // Set the bounds for the image.
      image.setBounds(
          (dialogWidth / 2) - (imageWidth / 2),
          (top + (offsetMargin / 2)),
          imageWidth,
          imageHeight);

      // Set the behaviors, bounds and action listener for the button.
      okButton.setBounds(
          (dialogWidth / 2) - (buttonWidth / 2),
          (imageHeight + (int) 1.5 * offsetMargin),
          buttonWidth,
          buttonHeight);

      // Set the font to the platform default Font for the object with the
      // properties of bold and font size of 11.
      okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11));

      // Set foreground and background of JButton(s).
      okButton.setForeground(Color.white);
      okButton.setBackground(Color.blue);

      // The class implements the ActionListener interface and therefore
      // provides an implementation of the actionPerformed() method.  When a
      // class implements ActionListener, the instance handler returns an
      // ActionListener.  The ActionListener then performs actionPerformed()
      // method on an ActionEvent.
      okButton.addActionListener(this);

      // Set the screen and display dialog window in relation to screen size.
      dim = tk.getScreenSize();
      setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2));

      // Display the dialog.
      show();
    } // End of buildDialogBox method.

    // --------------------- Window ActionListener ---------------------------/

    // Class listener based on implementing ActionListener.
    public void actionPerformed(ActionEvent e) {
      // Dispose of the help dialog.
      setVisible(false);
      dispose();
    } // End of actionPerformed method.

    // -------------------------- End Methods --------------------------------/

  } // End of HelpHandler inner class.