GP-1359 - Updated the Listing and Byte Viewer to show selection size as the user drags

This commit is contained in:
dragonmacher 2024-08-12 12:04:38 -04:00
parent 5047c00359
commit 4cda642e9c
9 changed files with 175 additions and 117 deletions

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -68,6 +68,11 @@ public class ByteViewerComponent extends FieldPanel implements FieldMouseListene
private ByteViewerHighlighter highlightProvider = new ByteViewerHighlighter();
private int highlightButton = MouseEvent.BUTTON2;
private FieldSelectionListener liveSelectionListener = (selection, trigger) -> {
ByteBlockSelection sel = processFieldSelection(selection);
panel.updateLiveSelection(ByteViewerComponent.this, sel);
};
/**
* Constructor
*
@ -206,12 +211,12 @@ public class ByteViewerComponent extends FieldPanel implements FieldMouseListene
if (blockSet == null || doingRefresh) {
return;
}
ByteBlockSelection sel = processFieldSelection(selection);
// notify panel to update other components
panel.updateSelection(this, sel);
setViewerSelection(sel);
}
/**
@ -339,12 +344,10 @@ public class ByteViewerComponent extends FieldPanel implements FieldMouseListene
return null;
}
/**
* Add listeners.
*/
void addListeners() {
addFieldLocationListener(this);
addFieldSelectionListener(this);
addLiveFieldSelectionListener(liveSelectionListener);
addFieldInputListener(this);
addFieldMouseListener(this);
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -429,6 +429,8 @@ public abstract class ByteViewerComponentProvider extends ComponentProviderAdapt
protected abstract void updateSelection(ByteBlockSelection selection);
protected abstract void updateLiveSelection(ByteBlockSelection selection);
void dispose() {
updateManager.dispose();
updateManager = null;

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -101,9 +101,8 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
height += dim.height;
}
boolean addHeight = true;
for (int i = 0; i < viewList.size(); i++) {
for (ByteViewerComponent c : viewList) {
ByteViewerComponent c = viewList.get(i);
Dimension d = c.getPreferredSize();
width += d.width;
width += 2; // for separator
@ -133,54 +132,47 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
//////////////////////////////////////////////////////////////////////////
void setCurrentCursorColor(Color c) {
currentCursorColor = c;
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent comp = viewList.get(i);
for (ByteViewerComponent comp : viewList) {
comp.setCurrentCursorColor(c);
}
}
void setCurrentCursorLineColor(Color c) {
currentCursorLineColor = c;
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent comp = viewList.get(i);
for (ByteViewerComponent comp : viewList) {
comp.setCurrentCursorLineColor(c);
}
}
void setHighlightButton(int highlightButton) {
this.highlightButton = highlightButton;
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent comp = viewList.get(i);
for (ByteViewerComponent comp : viewList) {
comp.setHighlightButton(highlightButton);
}
}
void setMouseButtonHighlightColor(Color color) {
this.highlightColor = color;
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent comp = viewList.get(i);
for (ByteViewerComponent comp : viewList) {
comp.setMouseButtonHighlightColor(color);
}
}
void setCursorColor(Color c) {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent comp = viewList.get(i);
for (ByteViewerComponent comp : viewList) {
comp.setNonFocusCursorColor(c);
}
}
void setSeparatorColor(Color c) {
indexFactory.setMissingValueColor(c);
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent comp = viewList.get(i);
for (ByteViewerComponent comp : viewList) {
comp.setSeparatorColor(c);
}
}
void setNonFocusCursorColor(Color c) {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent comp = viewList.get(i);
for (ByteViewerComponent comp : viewList) {
comp.setNonFocusCursorColor(c);
}
}
@ -217,13 +209,11 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
// Do the following loop twice - once with update off and then with update on.
// need to do this because all the byte view components must have their models
// updated before any one of them tells their dependents about the change.
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.enableIndexUpdate(false);
c.setIndexMap(indexMap);
}
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.enableIndexUpdate(true);
c.setIndexMap(indexMap);
}
@ -235,8 +225,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
}
void setViewerSelection(ByteBlockSelection selection) {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.setViewerSelection(selection);
}
}
@ -249,8 +238,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
}
void setViewerHighlight(ByteBlockSelection highlight) {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.setViewerHighlight(highlight);
}
}
@ -279,8 +267,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
void setCursorLocation(ByteBlock block, BigInteger index, int column) {
int modelIndex = -1;
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
modelIndex = c.setViewerCursorLocation(block, index, column);
}
if (modelIndex >= 0) {
@ -411,8 +398,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
}
void setEditMode(boolean editMode) {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.setEditMode(editMode);
}
}
@ -428,8 +414,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
* Force the current view to be refreshed.
*/
void refreshView() {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.refreshView();
}
}
@ -469,8 +454,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
* @throws InvalidInputException if a model cannot support the bytesPerLine value
*/
void checkBytesPerLine(int numBytesPerLine) throws InvalidInputException {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
DataFormatModel model = c.getDataModel();
int groupSize = model.getGroupSize();
if (groupSize > 0) {
@ -531,8 +515,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
}
insertionField.setText(locRep);
}
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
if (source == c) {
continue;
}
@ -550,8 +533,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
void updateSelection(ByteViewerComponent source, ByteBlockSelection selection) {
provider.updateSelection(selection);
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
if (source == c) {
continue;
}
@ -559,6 +541,10 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
}
}
void updateLiveSelection(ByteViewerComponent source, ByteBlockSelection selection) {
provider.updateLiveSelection(selection);
}
FontMetrics getCurrentFontMetrics() {
return fontMetrics;
}
@ -589,8 +575,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
BigInteger offset = vp.getOffset();
ViewerPosition vpos = vp.getViewerPosition();
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.returnToView(block, offset, vpos);
}
indexPanel.setViewerPosition(vpos.getIndex(), vpos.getXOffset(), vpos.getYOffset());
@ -625,8 +610,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
void setFontMetrics(FontMetrics fm) {
this.fontMetrics = fm;
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.setFontMetrics(fm);
}
indexFactory = new IndexFieldFactory(fm);
@ -636,8 +620,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
void setEditColor(Color editColor) {
this.editColor = editColor;
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.setEditColor(editColor);
}
}
@ -761,8 +744,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
block = info.getBlock();
offset = info.getOffset();
}
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.setIndexMap(indexMap);
if (info != null) {
c.setViewerCursorLocation(block, offset, info.getColumn());
@ -775,8 +757,7 @@ public class ByteViewerPanel extends JPanel implements LayoutModel, LayoutListen
* Clear the selection.
*/
private void clearSelection() {
for (int i = 0; i < viewList.size(); i++) {
ByteViewerComponent c = viewList.get(i);
for (ByteViewerComponent c : viewList) {
c.clearViewerSelection();
}
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -62,6 +62,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
protected Program program;
protected ProgramSelection currentSelection;
protected ProgramSelection liveSelection;
protected ProgramSelection currentHighlight;
protected ProgramLocation currentLocation;
@ -179,7 +180,9 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
}
protected void setSelection(ProgramSelection selection, boolean notify) {
liveSelection = null;
currentSelection = selection;
updateTitle();
if (selection == null) {
return;
}
@ -258,8 +261,26 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
if (!isConnected()) {
title = "[" + title + "]";
}
setTitle(title);
updateSubTitle();
}
private void updateSubTitle() {
// Note: the Listing has similar code
ProgramSelection selection = liveSelection != null ? liveSelection : currentSelection;
String selectionInfo = null;
if (selection != null && !selection.isEmpty()) {
long n = selection.getNumAddresses();
String nString = Long.toString(n);
if (n == 1) {
selectionInfo = "(1 byte selected)";
}
else {
selectionInfo = '(' + nString + " bytes selected)";
}
}
setSubTitle(selectionInfo);
}
//==================================================================================================
@ -366,7 +387,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
public boolean isVisible() {
return tool.isVisible(this);
}
//==================================================================================================
// End Navigatable interface methods */
//==================================================================================================
@ -583,12 +604,21 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
@Override
protected void updateSelection(ByteBlockSelection selection) {
ProgramSelectionPluginEvent event = blockSet.getPluginEvent(plugin.getName(), selection);
liveSelection = null;
currentSelection = event.getSelection();
plugin.updateSelection(this, event, program);
clipboardProvider.setSelection(currentSelection);
updateTitle();
contextChanged();
}
@Override
protected void updateLiveSelection(ByteBlockSelection selection) {
ProgramSelectionPluginEvent event = blockSet.getPluginEvent(plugin.getName(), selection);
liveSelection = event.getSelection();
updateTitle();
}
@Override
protected void updateLocation(ByteBlock block, BigInteger blockOffset, int column,
boolean export) {