Skip to content

Commit

Permalink
GP-1359 - Updated the Listing and Byte Viewer to show selection size …
Browse files Browse the repository at this point in the history
…as the user drags
  • Loading branch information
dragonmacher committed Aug 12, 2024
1 parent 5047c00 commit 4cda642
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -105,7 +105,10 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
private CoordinatedListingPanelListener coordinatedListingPanelListener;
private FormatManager formatMgr;
private FieldPanelCoordinator coordinator;

private ProgramSelectionListener liveProgramSelectionListener = (selection, trigger) -> {
liveSelection = selection;
updateSubTitle();
};
private FocusingMouseListener focusingMouseListener;

private CodeBrowserClipboardProvider codeViewerClipboardProvider;
Expand All @@ -116,6 +119,7 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
private CloneCodeViewerAction cloneCodeViewerAction;

private ProgramSelection currentSelection;
private ProgramSelection liveSelection;
private ProgramSelection currentHighlight;
private String currentStringSelection;

Expand Down Expand Up @@ -163,6 +167,7 @@ public CodeViewerProvider(CodeBrowserPluginInterface plugin, FormatManager forma
createActions();
listingPanel.setProgramLocationListener(this);
listingPanel.setProgramSelectionListener(this);
listingPanel.setLiveProgramSelectionListener(liveProgramSelectionListener);
listingPanel.setStringSelectionListener(this);
listingPanel.addIndexMapChangeListener(this);

Expand Down Expand Up @@ -542,11 +547,18 @@ public void setSelection(ProgramSelection selection) {

private void doSetSelection(ProgramSelection selection) {

liveSelection = null;
currentSelection = selection;
codeViewerClipboardProvider.setSelection(currentSelection);
listingPanel.setSelection(currentSelection);
plugin.selectionChanged(this, currentSelection);
contextChanged();
updateSubTitle();
}

private void updateSubTitle() {

ProgramSelection selection = liveSelection != null ? liveSelection : currentSelection;
String selectionInfo = null;
if (!selection.isEmpty()) {
long n = selection.getNumAddresses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -345,10 +345,8 @@ public ProgramSelection getProgramSelection(FieldSelection selection) {
return ps;
}
}
Program program = model.getProgram();
addrSet = model.adjustAddressSetToCodeUnitBoundaries(addrSet);
AddressFactory factory = program == null ? null : program.getAddressFactory();
return new ProgramSelection(factory, addrSet);
return new ProgramSelection(null, addrSet);
}

// this methods does NOT work for structures inside of unions, but handles structures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -63,7 +63,19 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc

private ProgramLocationListener programLocationListener;
private ProgramSelectionListener programSelectionListener;
private ProgramSelectionListener liveProgramSelectionListener;
private StringSelectionListener stringSelectionListener;
private FieldSelectionListener fieldPanelLiveSelectionListener = (selection, trigger) -> {

if (liveProgramSelectionListener == null) {
return;
}

ProgramSelection ps = layoutModel.getProgramSelection(selection);
if (ps != null) {
liveProgramSelectionListener.programSelectionChanged(ps, trigger);
}
};

private ListingModel listingModel;
private FieldHeader headerPanel;
Expand Down Expand Up @@ -106,6 +118,7 @@ public ListingPanel(FormatManager manager) {
fieldPanel.addFieldMouseListener(this);
fieldPanel.addFieldLocationListener(this);
fieldPanel.addFieldSelectionListener(this);
fieldPanel.addLiveFieldSelectionListener(fieldPanelLiveSelectionListener);
fieldPanel.addLayoutListener(this);
propertyBasedColorModel = new PropertyBasedBackgroundColorModel();
fieldPanel.setBackgroundColorModel(propertyBasedColorModel);
Expand Down Expand Up @@ -207,6 +220,16 @@ public void setProgramSelectionListener(ProgramSelectionListener listener) {
programSelectionListener = listener;
}

/**
* Sets the ProgramSelectionListener for selection changes while dragging. Only one listener is
* supported
*
* @param listener the ProgramSelectionListener to use.
*/
public void setLiveProgramSelectionListener(ProgramSelectionListener listener) {
liveProgramSelectionListener = listener;
}

public void setStringSelectionListener(StringSelectionListener listener) {
stringSelectionListener = listener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -32,15 +32,6 @@ public class ProgramSelection implements AddressSetView {
* Construct a new empty ProgramSelection.
*/
public ProgramSelection() {
this((AddressFactory) null);
}

/**
* Construct a new empty ProgramSelection.
* @param addressFactory the address factory for the address set
* associated with this program selection.
*/
public ProgramSelection(AddressFactory addressFactory) {
addressSet = new AddressSet();
}

Expand All @@ -50,18 +41,6 @@ public ProgramSelection(AddressFactory addressFactory) {
* @param to the end of the selection
*/
public ProgramSelection(Address from, Address to) {
this(null, from, to);
}

/**
* Constructor.
* @param addressFactory the address factory for the address set
* associated with this program selection.
* @param from the start of the selection
* @param to the end of the selection
*/
public ProgramSelection(AddressFactory addressFactory, Address from, Address to) {
this(addressFactory);
if (to.compareTo(from) < 0) {
Address temp = to;
to = from;
Expand All @@ -75,36 +54,59 @@ public ProgramSelection(AddressFactory addressFactory, Address from, Address to)
* @param setView address set for the selection
*/
public ProgramSelection(AddressSetView setView) {
this(null, setView);
}

/**
* Construct a new ProgramSelection
* @param addressFactory the address factory for the address set
* associated with this program selection.
* @param setView address set for the selection
*/
public ProgramSelection(AddressFactory addressFactory, AddressSetView setView) {
addressSet = new AddressSet(setView);
}

/**
* Construct a new ProgramSelection from the indicated interior selection.
* @param addressFactory the address factory for the address set
* associated with this program selection.
* @param sel the interior selection
*/
public ProgramSelection(AddressFactory addressFactory, InteriorSelection sel) {
this(addressFactory, sel.getStartAddress(), sel.getEndAddress());
public ProgramSelection(InteriorSelection sel) {
this(sel.getStartAddress(), sel.getEndAddress());
interiorSelection = sel;
}

/**
* Construct a new empty ProgramSelection.
* @param addressFactory NOT USED
* @deprecated use {@link #ProgramSelection()}
*/
@Deprecated(since = "11.2", forRemoval = true)
public ProgramSelection(AddressFactory addressFactory) {
this();
}

/**
* Constructor.
* @param addressFactory NOT USED
* @param from the start of the selection
* @param to the end of the selection
*/
@Deprecated(since = "11.2", forRemoval = true)
public ProgramSelection(AddressFactory addressFactory, Address from, Address to) {
this(from, to);
}

/**
* Construct a new ProgramSelection
* @param addressFactory NOT USED
* @param setView address set for the selection
* @deprecated use {@link #ProgramSelection(AddressSetView)}
*/
@Deprecated(since = "11.2", forRemoval = true)
public ProgramSelection(AddressFactory addressFactory, AddressSetView setView) {
this(setView);
}

/**
* Construct a new ProgramSelection from the indicated interior selection.
* @param addressFactory NOT USED
* @param sel the interior selection
* @deprecated use {@link #ProgramSelection(InteriorSelection)}s
*/
public ProgramSelection(InteriorSelection sel) {
this(null, sel);
@Deprecated(since = "11.2", forRemoval = true)
public ProgramSelection(AddressFactory addressFactory, InteriorSelection sel) {
this(sel);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -206,12 +211,12 @@ public void selectionChanged(FieldSelection selection, EventTrigger trigger) {
if (blockSet == null || doingRefresh) {
return;
}

ByteBlockSelection sel = processFieldSelection(selection);

// notify panel to update other components
panel.updateSelection(this, sel);
setViewerSelection(sel);

}

/**
Expand Down Expand Up @@ -339,12 +344,10 @@ private byte[] getByteValue(ByteBlock block, BigInteger offset) {
return null;
}

/**
* Add listeners.
*/
void addListeners() {
addFieldLocationListener(this);
addFieldSelectionListener(this);
addLiveFieldSelectionListener(liveSelectionListener);
addFieldInputListener(this);
addFieldMouseListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -429,6 +429,8 @@ protected abstract void updateLocation(ByteBlock block, BigInteger blockOffset,

protected abstract void updateSelection(ByteBlockSelection selection);

protected abstract void updateLiveSelection(ByteBlockSelection selection);

void dispose() {
updateManager.dispose();
updateManager = null;
Expand Down
Loading

0 comments on commit 4cda642

Please sign in to comment.