/** Initialise the frame to show the current photo */ private void initFrame() { _frame.setVisible(false); Photo photo = _app.getTrackInfo().getCurrentPhoto(); _frame.setTitle(photo.getName()); _label.setText( "'" + photo.getName() + "' (" + photo.getWidth() + " x " + photo.getHeight() + ")"); _photoThumb.setPhoto(photo); }
/** * Run method, for loading image in separate thread * * @see java.lang.Runnable#run() */ public void run() { if (_inPanel) { // use either exif thumbnail or photo scaled down to sensible size if (_photo.getExifThumbnail() != null) { // Use exif thumbnail Image image = new ImageIcon(_photo.getExifThumbnail()).getImage(); _thumbnail = ImageUtils.createScaledImage(image, image.getWidth(null), image.getHeight(null)); image = null; } else { // no exif thumbnail available, going to have to read whole thing int picWidth = _photo.getWidth(); int picHeight = _photo.getHeight(); if (picWidth > -1 && picHeight > -1) { // Just set a "reasonable" thumbnail size for now final int DEFAULT_THUMB_SIZE = 400; // calculate maximum thumbnail size Dimension thumbSize = ImageUtils.getThumbnailSize( picWidth, picHeight, DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE); // Make icon to load image into Image image = _photo.createImageIcon().getImage(); // save scaled, smoothed thumbnail for reuse _thumbnail = ImageUtils.createScaledImage(image, thumbSize.width, thumbSize.height); image = null; } else _loadFailed = true; } } else { _thumbnail = _photo.createImageIcon().getImage(); } _loadingImage = false; repaint(); }
/** * Override paint method * * @see javax.swing.JComponent#paint(java.awt.Graphics) */ public void paint(Graphics inG) { super.paint(inG); if (_photo != null) { // read thumbnail in separate thread if (_thumbnail == null && !_loadingImage && !_loadFailed) { _loadingImage = true; new Thread(this).start(); } // if loading, display message if (_loadingImage) { inG.setColor(Color.BLACK); inG.drawString(LOADING_STRING, 10, 30); } else if (_thumbnail != null && !_loadFailed) { // Copy scaled, smoothed (and rotated) image into scaled int usableWidth = getParent().getWidth() - 10; int usableHeight = (_inPanel ? usableWidth : getHeight() - 10); Image scaled = ImageUtils.rotateImage( _thumbnail, usableWidth, usableHeight, _photo.getRotationDegrees()); int scaleWidth = scaled.getWidth(null); int scaleHeight = scaled.getHeight(null); // Draw scaled / rotated image to component int horizOffset = (getWidth() - scaleWidth) / 2; int vertOffset = (getHeight() - scaleHeight) / 2; inG.drawImage(scaled, horizOffset, vertOffset, scaleWidth, scaleHeight, null); // Special resize behaviour when locked inside details panel if (_inPanel && (getHeight() < getWidth() || getHeight() > usableWidth)) { Dimension newsize = new Dimension(usableWidth, usableWidth); setPreferredSize(newsize); setSize(newsize); invalidate(); // Schedule a relayout because the size has changed SwingUtilities.invokeLater( new Runnable() { public void run() { try { Thread.sleep(200); } catch (InterruptedException e) { } getParent().getParent().getParent().validate(); } }); } } } }