|
|
@ -1,22 +1,25 @@ |
|
|
|
package com.fr.design.mainframe.alphafine.preview; |
|
|
|
package com.fr.design.mainframe.alphafine.preview; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
import javax.swing.*; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.*; |
|
|
|
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by XiaXiang on 2017/5/2. |
|
|
|
* Created by XiaXiang on 2017/5/2. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FilePreviewPane extends JPanel { |
|
|
|
public class FilePreviewPane extends JPanel { |
|
|
|
|
|
|
|
|
|
|
|
public FilePreviewPane(Image image) { |
|
|
|
public FilePreviewPane(BufferedImage image) { |
|
|
|
|
|
|
|
setLayout(new BorderLayout()); |
|
|
|
UILabel label = new UILabel(); |
|
|
|
UILabel label = new UILabel(); |
|
|
|
label.setOpaque(true); |
|
|
|
float widthScale = (AlphaFineConstants.RIGHT_WIDTH) / (float) image.getWidth(); |
|
|
|
label.setBackground(Color.white); |
|
|
|
float heightScale = (AlphaFineConstants.CONTENT_HEIGHT) / (float) image.getHeight(); |
|
|
|
float scale = image.getWidth(null) / 380; |
|
|
|
Image showImage; |
|
|
|
image = image.getScaledInstance(380, (int) (image.getHeight(null) / scale), Image.SCALE_SMOOTH); |
|
|
|
showImage = widthScale > heightScale? image.getScaledInstance((int) (image.getWidth() * heightScale), AlphaFineConstants.CONTENT_HEIGHT, Image.SCALE_SMOOTH) : image.getScaledInstance(AlphaFineConstants.RIGHT_WIDTH, (int) (image.getWidth() * widthScale), Image.SCALE_SMOOTH); |
|
|
|
label.setIcon(new ImageIcon(image)); |
|
|
|
label.setIcon(new ImageIcon(showImage)); |
|
|
|
add(label); |
|
|
|
add(label); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|