forked from fanruan/design
Browse Source
Merge in DESIGN/design from ~KERRY/design_10.0:feature/x to feature/x * commit '427fb1aa96942d417238b8cb65ee794cab6e4f1e': REPORT-62398 【接触点优化】筛选面板存在时,上下滑动鼠标显示异常 REPORT-62970【接触点优化】筛选动效问题,交互看下 REPORT-62926 && REPORT-62920 && REPORT-62967 && REPORT-62964feature/x
kerry
3 years ago
7 changed files with 123 additions and 55 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