diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/HexEditor.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/HexEditor.java index 727a8aefb..e5f8787c2 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/HexEditor.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/HexEditor.java @@ -28,7 +28,6 @@ public class HexEditor extends JComponent implements Scrollable { public static final Color COLOR_DIVIDER_FOREGROUND = UIColor.named("HexEditor.dividerForeground"); public static final Color COLOR_DIVIDER_SELECTION_FOREGROUND = UIColor.named("HexEditor.dividerSelectionForeground"); - private HexModel model; private HexCaret caret; private Font boldFont; @@ -220,6 +219,11 @@ public int getRowCount() { } } + public int getPreferredRowLength(int width) { + final BorderLayout layout = (BorderLayout) getLayout(); + return Math.max(1, (width - rowsPanel.getWidth() - layout.getHgap() * 2) / (mainPanel.getColumnWidth() + textPanel.getColumnWidth())); + } + @Override public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanel.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanel.java index 671de8465..828f88fee 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanel.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanel.java @@ -42,11 +42,6 @@ protected void paintComponent(Graphics g) { final Rectangle bounds = g.getClipBounds(); final int startIndex = getClosestIndexAt(bounds.x, bounds.y); final int endIndex = getClosestIndexAt(bounds.x + bounds.width, bounds.y + bounds.height); - - if (startIndex == endIndex) { - return; - } - final Graphics2D g2 = (Graphics2D) g.create(); try { @@ -153,7 +148,7 @@ public void stateChanged(ChangeEvent e) { repaint(rect.x, rect.y, rect.width, rect.height); } - protected int getColumnWidth() { + public int getColumnWidth() { return editor.getColumnWidth(); } diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanelColumns.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanelColumns.java index 7147eb44a..fe79c7cc0 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanelColumns.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/controls/hex/panel/HexPanelColumns.java @@ -23,7 +23,7 @@ protected void doPaint(@NotNull Graphics2D g, int startIndex, int endIndex) { } @Override - protected int getColumnWidth() { + public int getColumnWidth() { return editor.getMainPanel().getColumnWidth() + editor.getTextPanel().getColumnWidth(); } diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewerPanel.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewerPanel.java index 937ac97ba..033d64381 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewerPanel.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewerPanel.java @@ -7,6 +7,7 @@ import com.shade.platform.model.Disposable; import com.shade.platform.model.util.BufferUtils; import com.shade.platform.model.util.IOUtils; +import com.shade.platform.ui.UIColor; import com.shade.platform.ui.util.UIUtils; import com.shade.util.NotNull; import com.shade.util.Nullable; @@ -15,6 +16,8 @@ import javax.swing.table.AbstractTableModel; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; @@ -25,7 +28,7 @@ public class BinaryViewerPanel extends JPanel implements Disposable { private static final Inspector[] INSPECTORS = { - new NumberInspector<>("Binary", ByteBuffer::get, x -> "0b%8s".formatted(Integer.toBinaryString(x & 0xff)).replace(' ', '0'), Byte.BYTES), + new NumberInspector<>("Binary", ByteBuffer::get, x -> "%8s".formatted(Integer.toBinaryString(x & 0xff)).replace(' ', '0'), Byte.BYTES), new NumberInspector<>("UInt8", ByteBuffer::get, x -> String.valueOf(x & 0xff), Byte.BYTES), new NumberInspector<>("Int8", ByteBuffer::get, String::valueOf, Byte.BYTES), new NumberInspector<>("UInt16", ByteBuffer::getShort, x -> String.valueOf(x & 0xffff), Short.BYTES), @@ -48,12 +51,26 @@ public BinaryViewerPanel() { final JScrollPane editorPane = UIUtils.createBorderlessScrollPane(editor); editorPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + editorPane.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + editor.setRowLength(editor.getPreferredRowLength(editorPane.getViewport().getWidth())); + } + }); final InspectorTableModel inspectorTableModel = new InspectorTableModel(); final JTable inspectorTable = new JTable(inspectorTableModel); inspectorTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - - final JScrollPane inspectorPane = UIUtils.createBorderlessScrollPane(inspectorTable); + inspectorTable.getColumnModel().getColumn(0).setPreferredWidth(70); + inspectorTable.getColumnModel().getColumn(0).setMaxWidth(70); + + final JScrollPane inspectorPane = new JScrollPane(inspectorTable) { + @Override + public void updateUI() { + super.updateUI(); + setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIColor.SHADOW)); + } + }; inspectorPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); final JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);