From 63b51efa6142800df5c87721ccc72a2ef2c771ce Mon Sep 17 00:00:00 2001 From: "ekaterina.itsenko" Date: Tue, 6 May 2025 12:12:49 +0000 Subject: [PATCH] [pycharm] PY-80835 Debugger: add cursor position + pixel value as text label Merge-request: IJ-MR-162076 Merged-by: Ekaterina Itsenko (cherry picked from commit 6a6fbbcb1d823041f9c2c3e62d6b98728b5cac3e) GitOrigin-RevId: f9be66fa39892b081dd08c26edcbc5daa6111db7 --- .../messages/ImagesBundle.properties | 4 +- .../images/editor/impl/ImageEditorUI.java | 50 +++++++++++++++++-- .../scientific/utils/ScientificUtils.kt | 3 +- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/images/resources/messages/ImagesBundle.properties b/images/resources/messages/ImagesBundle.properties index 2d33c0c4913f..7d133c0f190c 100644 --- a/images/resources/messages/ImagesBundle.properties +++ b/images/resources/messages/ImagesBundle.properties @@ -98,4 +98,6 @@ image.binarize.dialog.title=Set Binarization Threshold image.channels.mode.channel.1=Channel 1 image.channels.mode.channel.2=Channel 2 image.channels.mode.channel.3=Channel 3 -image.color.mode.configure.actions=Binarization\u2026 \ No newline at end of file +image.color.mode.configure.actions=Binarization\u2026 +scientific.cursor.position=(x = {0}, y = {1}); +scientific.pixel.value=value = ({0}, {1}, {2}) \ No newline at end of file diff --git a/images/src/org/intellij/images/editor/impl/ImageEditorUI.java b/images/src/org/intellij/images/editor/impl/ImageEditorUI.java index b7a12a7a420d..b030c980721a 100644 --- a/images/src/org/intellij/images/editor/impl/ImageEditorUI.java +++ b/images/src/org/intellij/images/editor/impl/ImageEditorUI.java @@ -57,6 +57,7 @@ import org.intellij.images.thumbnail.actionSystem.ThumbnailViewActions; import org.intellij.images.thumbnail.actions.ShowBorderAction; import org.intellij.images.ui.ImageComponent; import org.intellij.images.ui.ImageComponentDecorator; +import org.intellij.images.scientific.utils.ScientificUtils; import org.intellij.images.vfs.IfsUtil; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NonNls; @@ -174,15 +175,58 @@ public final class ImageEditorUI extends JPanel implements UiDataProvider, CopyP contentPanel.add(errorPanel, ERROR_PANEL); JPanel topPanel = new NonOpaquePanel(new BorderLayout()); + JPanel bottomPanel = new NonOpaquePanel(new BorderLayout()); + + infoLabel = new JLabel((String)null, SwingConstants.RIGHT); + infoLabel.setBorder(JBUI.Borders.emptyRight(2)); + + boolean isScientificMode = editor != null && editor.getFile().getUserData(ScientificUtils.SCIENTIFIC_MODE_KEY) != null; if (!isEmbedded) { topPanel.add(toolbarPanel, BorderLayout.WEST); - infoLabel = new JLabel((String)null, SwingConstants.RIGHT); - infoLabel.setBorder(JBUI.Borders.emptyRight(2)); - topPanel.add(infoLabel, BorderLayout.EAST); + if (isScientificMode) { + JPanel scientificInfoPanel = new NonOpaquePanel(new FlowLayout(FlowLayout.LEFT, 2, 0)); + JLabel positionLabel = new JLabel(ImagesBundle.message("scientific.cursor.position", 0, 0)); + JLabel valueLabel = new JLabel(ImagesBundle.message("scientific.pixel.value", 0, 0, 0)); + scientificInfoPanel.add(positionLabel); + scientificInfoPanel.add(valueLabel); + + imageComponent.addMouseMotionListener(new MouseMotionAdapter() { + @Override + public void mouseMoved(MouseEvent e) { + BufferedImage image = imageComponent.getDocument().getValue(); + if (image != null) { + double zoom = imageComponent.getZoomFactor(); + + int x = (int)((e.getX() - ImageComponent.IMAGE_INSETS) / zoom); + int y = (int)((e.getY() - ImageComponent.IMAGE_INSETS) / zoom); + + if (x >= 0 && x < image.getWidth() && y >= 0 && y < image.getHeight()) { + int pixel = image.getRGB(x, y); + int r = (pixel >> 16) & 0xFF; + int g = (pixel >> 8) & 0xFF; + int b = pixel & 0xFF; + positionLabel.setText(ImagesBundle.message("scientific.cursor.position", x, y)); + valueLabel.setText(ImagesBundle.message("scientific.pixel.value", r, g, b)); + } + else { + positionLabel.setText(ImagesBundle.message("scientific.cursor.position", 0, 0)); + valueLabel.setText(ImagesBundle.message("scientific.pixel.value", 0, 0, 0)); + } + } + } + }); + + bottomPanel.add(scientificInfoPanel, BorderLayout.WEST); + bottomPanel.add(infoLabel, BorderLayout.EAST); + } + else { + topPanel.add(infoLabel, BorderLayout.EAST); + } } add(topPanel, BorderLayout.NORTH); add(contentPanel, BorderLayout.CENTER); + add(bottomPanel, BorderLayout.SOUTH); myScrollPane.addComponentListener(new ComponentAdapter() { @Override diff --git a/images/src/org/intellij/images/scientific/utils/ScientificUtils.kt b/images/src/org/intellij/images/scientific/utils/ScientificUtils.kt index 8a364957a026..c28f98315bd5 100644 --- a/images/src/org/intellij/images/scientific/utils/ScientificUtils.kt +++ b/images/src/org/intellij/images/scientific/utils/ScientificUtils.kt @@ -14,7 +14,8 @@ import java.awt.geom.AffineTransform object ScientificUtils { - val SCIENTIFIC_MODE_KEY: Key = Key("SCIENTIFIC_MODE") + @JvmField + var SCIENTIFIC_MODE_KEY: Key = Key("SCIENTIFIC_MODE") val ORIGINAL_IMAGE_KEY: Key = Key("ORIGINAL_IMAGE") val ROTATION_ANGLE_KEY: Key = Key.create("IMAGE_ROTATION_ANGLE") const val DEFAULT_IMAGE_FORMAT: String = "png"