//use a monospaced font for a better layout
Font font = new Font(compositeHolder.getDisplay(), "Courier", 10, SWT.NORMAL);
hexText.setFont(font);
asciiText.setFont(font);
final ScrollBar hexScrollBar = hexText.getVerticalBar();
final ScrollBar asciiScrollBar = asciiText.getVerticalBar();
//create a sub composite to contain all the buttons
final Composite buttonComposite = toolkit.createComposite(localComposite, SWT.NONE);
layout = new GridLayout(7, false);
layout.marginWidth = 0;
buttonComposite.setLayout(layout);
buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
_firstButton = toolkit.createButton(buttonComposite, "<<", SWT.PUSH);
GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
layoutData.widthHint = 40;
_firstButton.setLayoutData(layoutData);
_firstButton.setToolTipText("See the first n bytes");
_previousButton = toolkit.createButton(buttonComposite, "<", SWT.PUSH);
layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
layoutData.widthHint = 40;
_previousButton.setLayoutData(layoutData);
_previousButton.setToolTipText("See the previous n bytes");
_previousButton.setEnabled(false);
_hexNumTextToStart = toolkit.createText(buttonComposite, "0");
layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
layoutData.widthHint = 40;
_hexNumTextToStart.setLayoutData(layoutData);
_hexNumTextToStart.setEditable(false);
final Text hexNumText = toolkit.createText(buttonComposite, "" + startContentSize);
layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
layoutData.widthHint = 40;
hexNumText.setLayoutData(layoutData);
_hexNumTextToEnd = toolkit.createText(buttonComposite, "" + (byteArray.length - startContentSize));
layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
layoutData.widthHint = 40;
_hexNumTextToEnd.setLayoutData(layoutData);
_hexNumTextToEnd.setEditable(false);
_nextButton = toolkit.createButton(buttonComposite, ">", SWT.PUSH);
layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
layoutData.widthHint = 40;
_nextButton.setLayoutData(layoutData);
_nextButton.setToolTipText("See the next n bytes");
_nextButton.setEnabled(true);
_lastButton = toolkit.createButton(buttonComposite, ">>", SWT.PUSH);
layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
layoutData.widthHint = 40;
_lastButton.setToolTipText("See the last n bytes");
_lastButton.setLayoutData(layoutData);
SelectionListener listener = new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
if (e.widget instanceof Button)
{
String numOfBytes = hexNumText.getText();
try
{
int n = Integer.parseInt(numOfBytes);
//Reset range display if user requests a large value
if (n > byteArray.length)
{
n = (byteArray.length > DEFAULT_CONTENT_SIZE) ? DEFAULT_CONTENT_SIZE : byteArray.length;
hexNumText.setText("" + n);
}
//rest if the user requests 0
if (n < 1)
{
n = DEFAULT_CONTENT_SIZE;
hexNumText.setText("" + n);
}
Button button = (Button) e.widget;
hexText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding,
button.getText(), true));
asciiText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding,
button.getText(), false));
}
catch (NumberFormatException exp)
{
popupErrorMessage("Error", "Please input the number of bytes you wish to look at");
}
}
if (e.widget instanceof ScrollBar)
{
//synchronize the movements of the two scrollbars
ScrollBar sb = (ScrollBar) e.widget;
if (sb.getParent().equals(hexText))
{
asciiScrollBar.setIncrement(sb.getIncrement());
asciiScrollBar.setSelection(sb.getSelection());
}
else if (sb.getParent().equals(asciiText))
{
hexScrollBar.setSelection(sb.getSelection());
hexScrollBar.setIncrement(sb.getIncrement());
}
}
}
};
localComposite.addControlListener(new ControlAdapter()