kerry
3 years ago
6 changed files with 95 additions and 49 deletions
@ -0,0 +1,41 @@
|
||||
package com.fr.design.mainframe.share.ui.online; |
||||
|
||||
import com.fr.general.IOUtils; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.Dimension; |
||||
import java.awt.Graphics; |
||||
import java.awt.Image; |
||||
import java.awt.Toolkit; |
||||
|
||||
/** |
||||
* Created by kerry on 2021/11/19 |
||||
*/ |
||||
public class PreviewImagePane extends JPanel { |
||||
private static final Image DEFAULT_IMAGE = IOUtils.readImage("com/fr/base/images/share/component_error.png"); |
||||
private static final int PREVIEW_IMAGE_WIDTH = OnlineWidgetPopupPreviewPane.POPUP_WIDTH - 20; |
||||
private static final int STANDARD_DPI = 128; |
||||
|
||||
private Image previewImage; |
||||
|
||||
public void setPreviewImage(Image previewImage) { |
||||
this.previewImage = previewImage; |
||||
if (this.previewImage == null) { |
||||
this.previewImage = DEFAULT_IMAGE; |
||||
} |
||||
|
||||
int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); |
||||
int imageWidth = this.previewImage.getWidth(null); |
||||
int imageHeight = this.previewImage.getHeight(null); |
||||
|
||||
double imageAspectRatio = (double) imageWidth / imageHeight; |
||||
int width = (PREVIEW_IMAGE_WIDTH * dpi) / STANDARD_DPI; |
||||
int height = (int) (width / imageAspectRatio); |
||||
setPreferredSize(new Dimension(width, height)); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
g.drawImage(this.previewImage, 0, 0, getWidth(), getHeight(), null); |
||||
} |
||||
} |
Loading…
Reference in new issue