Merge remote-tracking branch 'origin/patch'

Conflicts:
	Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/BitFieldPlacementComponent.java
This commit is contained in:
ghidra1 2019-12-20 17:29:11 -05:00
commit 0f09cedffd
5 changed files with 51 additions and 26 deletions

View File

@ -1319,6 +1319,9 @@
<P><B>Field Name</B> - (optional) specifies the structure component name to be assigned to
the bitfield. This entry utilizes a simple text entry field.</P>
<P><B>Comment</B> - (optional) specifies the structure component comment to be assigned to
the bitfield. This entry utilizes a simple text entry field.</P>
<P><IMG alt="Tip:" src="../../shared/tip.png"> The bitfield offset and size may be fully
specified by using the mouse. Clicking and dragging over the visual bit-range where the bitfield

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -60,6 +60,7 @@ public class BitFieldEditorPanel extends JPanel {
private DataTypeSelectionEditor dtChoiceEditor;
private JTextField fieldNameTextField;
private JTextField fieldCommentTextField;
private SpinnerNumberModel allocSizeModel;
private JSpinnerWithMouseWheel allocSizeInput;
private SpinnerNumberModel bitOffsetModel;
@ -156,6 +157,9 @@ public class BitFieldEditorPanel extends JPanel {
fieldNameTextField = new JTextField(20);
fieldNameTextField.setFocusable(true);
fieldCommentTextField = new JTextField(20);
fieldCommentTextField.setFocusable(true);
allocSizeModel = new SpinnerNumberModel(Long.valueOf(4), Long.valueOf(1), Long.valueOf(16),
Long.valueOf(1));
allocSizeInput = new JSpinnerWithMouseWheel(allocSizeModel);
@ -189,8 +193,8 @@ public class BitFieldEditorPanel extends JPanel {
entryPanel.add(new JLabel("Bit Size:"));
entryPanel.add(bitSizeInput);
entryPanel.add(new JPanel());
entryPanel.add(new JPanel());
entryPanel.add(new JLabel("Comment:"));
entryPanel.add(fieldCommentTextField);
entryPanel.add(new JLabel("Bit Offset:"));
entryPanel.add(bitOffsetInput);
@ -389,7 +393,7 @@ public class BitFieldEditorPanel extends JPanel {
: initialBaseDataType.getLength();
placementComponent.updateAllocation((int) allocationSize, allocationOffset);
placementComponent.initAdd(1, bitOffset);
initControls(null, initialBaseDataType, 1);
initControls(null, null, initialBaseDataType, 1);
enableControls(true);
}
@ -403,6 +407,7 @@ public class BitFieldEditorPanel extends JPanel {
void initEdit(DataTypeComponent bitfieldDtc, int allocationOffset,
boolean useExistingAllocationSize) {
String initialFieldName = null;
String initialComment = null;
DataType initialBaseDataType = null;
int allocationSize = -1;
if (useExistingAllocationSize) {
@ -413,6 +418,7 @@ public class BitFieldEditorPanel extends JPanel {
throw new IllegalArgumentException("unsupport data type component");
}
initialFieldName = bitfieldDtc.getFieldName();
initialComment = bitfieldDtc.getComment();
BitFieldDataType bitfieldDt = (BitFieldDataType) bitfieldDtc.getDataType();
initialBaseDataType = bitfieldDt.getBaseDataType();
if (allocationSize < 1) {
@ -429,7 +435,8 @@ public class BitFieldEditorPanel extends JPanel {
placementComponent.updateAllocation(allocationSize, allocationOffset);
placementComponent.init(bitfieldDtc);
BitFieldAllocation bitFieldAllocation = placementComponent.getBitFieldAllocation(); // get updated instance
initControls(initialFieldName, initialBaseDataType, bitFieldAllocation.getBitSize());
initControls(initialFieldName, initialComment, initialBaseDataType,
bitFieldAllocation.getBitSize());
enableControls(bitfieldDtc != null);
}
@ -437,13 +444,14 @@ public class BitFieldEditorPanel extends JPanel {
placementComponent.componentDeleted(ordinal);
}
private void initControls(String initialFieldName, DataType initialBaseDataType,
int initialBitSize) {
private void initControls(String initialFieldName, String initialComment,
DataType initialBaseDataType, int initialBitSize) {
updating = true;
try {
baseDataType = initialBaseDataType;
dtChoiceEditor.setCellEditorValue(initialBaseDataType);
fieldNameTextField.setText(initialFieldName);
fieldCommentTextField.setText(initialComment);
// Use current placementComponent to obtain initial values
allocSizeModel.setValue((long) placementComponent.getAllocationByteSize());
@ -513,7 +521,7 @@ public class BitFieldEditorPanel extends JPanel {
deleteConflicts = (option == OptionDialog.OPTION_ONE);
}
placementComponent.applyBitField(baseDataType, fieldNameTextField.getText().trim(),
deleteConflicts, listener);
fieldCommentTextField.getText().trim(), deleteConflicts, listener);
enableControls(false);
return true;
}
@ -522,6 +530,7 @@ public class BitFieldEditorPanel extends JPanel {
dtChoiceEditor.getBrowseButton().setEnabled(enable);
dtChoiceEditor.getDropDownTextField().setEnabled(enable);
fieldNameTextField.setEnabled(enable);
fieldCommentTextField.setEnabled(enable);
allocSizeInput.setEnabled(enable);
bitSizeInput.setEnabled(enable);
bitOffsetInput.setEnabled(enable);
@ -529,6 +538,8 @@ public class BitFieldEditorPanel extends JPanel {
// TODO: set placementComponent mode to NONE
dtChoiceEditor.getDropDownTextField().setText("");
fieldNameTextField.setText(null);
fieldCommentTextField.setText(null);
;
bitOffsetModel.setValue(0L);
bitSizeModel.setValue(1L);
}

View File

@ -48,7 +48,7 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
private static final Color ACTIVE_BITFIELD_BITS_COLOR = Color.green;
private static final Color CONFLICT_BITS_COLOR = Color.yellow;
private static final Color BITFIELD_COMPONENT_COLOR = new Color(0xbfbfff);
private static final Color NON_BITFIELD_COMPONENT_COLOR = new Color(0xa4a4ff);
private static final Color NON_BITFIELD_COMPONENT_COLOR = new Color(0xa0a0ff);
private static final Color INTERIOR_LINE_COLOR = new Color(0xd4d4d4);
private int bitWidth = 10;
@ -418,8 +418,8 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
repaint();
}
void applyBitField(DataType baseDataType, String fieldName, boolean deleteConflicts,
CompositeChangeListener listener) {
void applyBitField(DataType baseDataType, String fieldName, String fieldComment,
boolean deleteConflicts, CompositeChangeListener listener) {
if (!editUseEnabled) {
throw new IllegalStateException("component not constructed for edit use");
}
@ -458,18 +458,21 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
try {
String name = (fieldName != null && fieldName.length() != 0) ? fieldName : null;
String comment =
(fieldComment != null && fieldComment.length() != 0) ? fieldComment : null;
DataTypeComponent dtc;
if (composite instanceof Union) {
throw new UnsupportedOperationException(
"Union modification not currently supported");
// dtc = composite.insertBitField(ordinal, allocationByteSize,
// bitFieldAllocation.bitOffset, baseDataType, bitFieldAllocation.bitSize, name,
// null);
// comment);
}
// else {
Structure struct = (Structure) composite;
dtc = struct.insertBitFieldAt(allocationByteOffset, allocationByteSize,
bitFieldAllocation.bitOffset, baseDataType, bitFieldAllocation.bitSize, name, null);
bitFieldAllocation.bitOffset, baseDataType, bitFieldAllocation.bitSize, name,
comment);
// }
if (listener != null) {
listener.componentChanged(dtc.getOrdinal());
@ -588,8 +591,6 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
@Override
public void paintComponent(Graphics g) {
//super.paintComponent(g);
int height = getHeight();
int width = getWidth();
@ -620,10 +621,11 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
int byteSize = allocationByteSize;
int x = BYTE_SEPARATOR_THICKNESS;
// start close to the left clip bounds
Rectangle clipBounds = g.getClipBounds();
int maxX = clipBounds.x + clipBounds.width - 1;
int startIndex = clipBounds.x / byteWidth;
// start close to the left visible edge
JViewport viewPort = (JViewport) getParent();
Rectangle bounds = viewPort.getViewRect();
int maxX = bounds.x + bounds.width - 1;
int startIndex = bounds.x / byteWidth;
x += startIndex * byteWidth;
for (int i = startIndex; i < byteSize; i++) {
@ -686,11 +688,14 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
DataTypeComponent prevDtc = null;
BitAttributes prevAttrs = null;
// start close to the left clip bounds
Rectangle clipBounds = g.getClipBounds();
int maxX = clipBounds.x + clipBounds.width - 1;
// Limit rendered bits to those contained within the visible view port
// of this scrolled component.
JViewport viewPort = (JViewport) getParent();
Rectangle bounds = viewPort.getViewRect();
int maxX = bounds.x + bounds.width - 1;
int width = bitAttributes[0].rectangle.width;
int startIndex = (clipBounds.x / (bitAttributes[0].rectangle.width)) -
int startIndex = (bounds.x / (bitAttributes[0].rectangle.width)) -
(8 * bitFieldAllocation.leftChopBytes);
x += startIndex * width;
@ -698,7 +703,7 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
for (bitIndex = startIndex; bitIndex < bitAttributes.length; bitIndex++) {
BitAttributes attrs = bitAttributes[bitIndex];
if (x > maxX) {
break; // right clip - return early
break; // right visible edge exceeded - return early
}
boolean paintRightLine = bitIndex != (bitAttributes.length - 1);
attrs.paint(g, prevAttrs, paintRightLine);
@ -708,12 +713,14 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
paintComponentLabel(g, prevDtc, dtcRectangle);
prevDtc = null;
}
Rectangle visibleBitRect = attrs.rectangle.intersection(bounds);
if (prevDtc == null) {
prevDtc = dtc;
dtcRectangle = new Rectangle(attrs.rectangle.intersection(clipBounds));
dtcRectangle = visibleBitRect;
}
else {
dtcRectangle.add(visibleBitRect);
}
dtcRectangle.add(attrs.rectangle.intersection(clipBounds));
if (attrs.unallocated) {
paintDit(g, attrs.rectangle);
}
@ -768,6 +775,7 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
int textY = r.y + (r.height + fontMetrics.getMaxAscent() - BYTE_SEPARATOR_THICKNESS) / 2;
int textX = r.x + (r.width - BYTE_SEPARATOR_THICKNESS - strWidth) / 2;
g.drawString(name, textX, textY);
g.setColor(curColor);

View File

@ -81,6 +81,9 @@ abstract public class CompositeEditorTableAction extends DockingAction implement
}
protected void requestTableFocus() {
if (provider == null) {
return; // must have been disposed
}
JTable table = ((CompositeEditorPanel) provider.getComponent()).getTable();
if (table.isEditing()) {
table.getEditorComponent().requestFocus();