|
|
@@ -816,9 +816,11 @@ public class MesClient extends JFrame {
|
|
|
// 设置背景色(可选,比如设置为白色或灰色背景)
|
|
|
hfPanel.setBackground(Color.WHITE);
|
|
|
|
|
|
- // 添加到 TabbedPane
|
|
|
- // 第二个参数是图标,这里复用了 menu_data_preprocess.png,您也可以换成其他图标
|
|
|
- tabbedPane.addTab("查看漏点", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), hfPanel, "查看漏点图片");
|
|
|
+ // 保持原图尺寸显示,窗口不足时通过滚动条查看,避免工程图被强制缩小。
|
|
|
+ JScrollPane hfScrollPane = new JScrollPane(hfPanel);
|
|
|
+ hfScrollPane.getVerticalScrollBar().setUnitIncrement(24);
|
|
|
+ hfScrollPane.getHorizontalScrollBar().setUnitIncrement(24);
|
|
|
+ tabbedPane.addTab("查看漏点", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), hfScrollPane, "查看漏点图片");
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -1044,7 +1046,7 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 自定义面板,用于同比例缩放显示图片
|
|
|
+ // 工程图面板:默认按原始尺寸显示,避免文字和细线因缩小而失真。
|
|
|
public class ImagePanel extends JPanel {
|
|
|
private Image image;
|
|
|
|
|
|
@@ -1071,10 +1073,10 @@ public class MesClient extends JFrame {
|
|
|
int imageHeight = image.getHeight(this);
|
|
|
|
|
|
if (imageWidth > 0 && imageHeight > 0) {
|
|
|
- // 计算缩放比例,保持长宽比
|
|
|
double widthRatio = (double) panelWidth / imageWidth;
|
|
|
double heightRatio = (double) panelHeight / imageHeight;
|
|
|
- double ratio = Math.min(widthRatio, heightRatio);
|
|
|
+ // 只有面板比图片小才缩小;放大窗口时不放大图片。
|
|
|
+ double ratio = Math.min(1.0, Math.min(widthRatio, heightRatio));
|
|
|
|
|
|
// 计算新的绘制宽高
|
|
|
int newWidth = (int) (imageWidth * ratio);
|
|
|
@@ -1084,11 +1086,30 @@ public class MesClient extends JFrame {
|
|
|
int x = (panelWidth - newWidth) / 2;
|
|
|
int y = (panelHeight - newHeight) / 2;
|
|
|
|
|
|
- // 绘制缩放后的图片
|
|
|
- g.drawImage(image, x, y, newWidth, newHeight, this);
|
|
|
+ Graphics2D g2 = (Graphics2D) g.create();
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
|
|
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING,
|
|
|
+ RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
|
|
+ RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ g2.drawImage(image, x, y, newWidth, newHeight, this);
|
|
|
+ g2.dispose();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Dimension getPreferredSize() {
|
|
|
+ if (image != null) {
|
|
|
+ int width = image.getWidth(this);
|
|
|
+ int height = image.getHeight(this);
|
|
|
+ if (width > 0 && height > 0) {
|
|
|
+ return new Dimension(width, height);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.getPreferredSize();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|