فهرست منبع

漏点图更改

17491 2 روز پیش
والد
کامیت
3b5f47be80
3فایلهای تغییر یافته به همراه49 افزوده شده و 8 حذف شده
  1. BIN
      image/bg/zl.png
  2. 47 3
      src/com/mes/ui/ImagePanel.java
  3. 2 5
      src/com/mes/ui/MesClient.java

BIN
image/bg/zl.png


+ 47 - 3
src/com/mes/ui/ImagePanel.java

@@ -2,12 +2,16 @@ package com.mes.ui;
 
 import javax.swing.ImageIcon;
 import javax.swing.JPanel;
+import javax.swing.Scrollable;
 import java.awt.Dimension;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
 
-/** Displays an image at its native size so engineering annotations remain readable. */
-public class ImagePanel extends JPanel {
+/** Displays an image scaled proportionally to the available viewport. */
+public class ImagePanel extends JPanel implements Scrollable {
     private final Image image;
 
     public ImagePanel(String resourcePath) {
@@ -18,6 +22,46 @@ public class ImagePanel extends JPanel {
     @Override
     protected void paintComponent(Graphics graphics) {
         super.paintComponent(graphics);
-        graphics.drawImage(image, 0, 0, this);
+        int imageWidth = image.getWidth(this);
+        int imageHeight = image.getHeight(this);
+        if (imageWidth <= 0 || imageHeight <= 0) {
+            return;
+        }
+
+        double scale = Math.min((double) getWidth() / imageWidth, (double) getHeight() / imageHeight);
+        int drawWidth = Math.max(1, (int) Math.round(imageWidth * scale));
+        int drawHeight = Math.max(1, (int) Math.round(imageHeight * scale));
+        int x = (getWidth() - drawWidth) / 2;
+        int y = (getHeight() - drawHeight) / 2;
+
+        Graphics2D graphics2D = (Graphics2D) graphics.create();
+        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+        graphics2D.drawImage(image, x, y, drawWidth, drawHeight, this);
+        graphics2D.dispose();
+    }
+
+    @Override
+    public Dimension getPreferredScrollableViewportSize() {
+        return getPreferredSize();
+    }
+
+    @Override
+    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
+        return 24;
+    }
+
+    @Override
+    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
+        return orientation == javax.swing.SwingConstants.VERTICAL ? visibleRect.height : visibleRect.width;
+    }
+
+    @Override
+    public boolean getScrollableTracksViewportWidth() {
+        return true;
+    }
+
+    @Override
+    public boolean getScrollableTracksViewportHeight() {
+        return true;
     }
 }

+ 2 - 5
src/com/mes/ui/MesClient.java

@@ -1143,13 +1143,10 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);
 
-        // 漏点位置图:保持原图尺寸,通过滚动条查看完整工程图
+        // 漏点位置图:按可视区域等比例缩放,尽量利用显示空间
         ImagePanel hfPanel = new ImagePanel("/bg/zl.png");
         hfPanel.setBackground(Color.WHITE);
-        JPanel imageContainer = new JPanel(new GridBagLayout());
-        imageContainer.setBackground(Color.WHITE);
-        imageContainer.add(hfPanel);
-        JScrollPane hfScrollPane = new JScrollPane(imageContainer);
+        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, "查看漏点图片");