1 11 package org.eclipse.debug.internal.ui.views.memory.renderings; 12 13 import java.math.BigInteger ; 14 15 import org.eclipse.debug.internal.ui.DebugUIMessages; 16 import org.eclipse.debug.internal.ui.DebugUIPlugin; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Button; 22 import org.eclipse.swt.widgets.Combo; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Text; 26 import org.eclipse.ui.PlatformUI; 27 28 public class GoToAddressComposite { 29 30 private Text fExpression; 31 private Button fOKButton; 32 private Button fCancelButton; 33 private Composite fComposite; 34 private Combo fGoToCombo; 35 private Button fHexButton; 36 37 41 public Control createControl(Composite parent) 42 { 43 fComposite = new Composite(parent, SWT.NONE); 44 PlatformUI.getWorkbench().getHelpSystem().setHelp(fComposite, DebugUIPlugin.getUniqueIdentifier() + ".GoToAddressComposite_context"); GridLayout layout = new GridLayout(); 46 layout.numColumns = 6; 47 layout.makeColumnsEqualWidth = false; 48 layout.marginHeight = 0; 49 layout.marginLeft = 0; 50 fComposite.setLayout(layout); 51 52 fGoToCombo = new Combo(fComposite, SWT.READ_ONLY); 53 fGoToCombo.add(DebugUIMessages.GoToAddressComposite_0); 54 fGoToCombo.add(DebugUIMessages.GoToAddressComposite_4); 55 fGoToCombo.add(DebugUIMessages.GoToAddressComposite_5); 56 fGoToCombo.select(0); 57 58 fExpression = new Text(fComposite, SWT.SINGLE | SWT.BORDER); 59 fExpression.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 60 61 fHexButton = new Button(fComposite, SWT.CHECK); 62 fHexButton.setText(DebugUIMessages.GoToAddressComposite_6); 63 fHexButton.setSelection(true); 64 65 fOKButton = new Button(fComposite, SWT.NONE); 66 fOKButton.setText(DebugUIMessages.GoToAddressComposite_1); 67 68 fCancelButton = new Button(fComposite, SWT.NONE); 69 fCancelButton.setText(DebugUIMessages.GoToAddressComposite_2); 70 71 return fComposite; 72 } 73 74 public int getHeight() 75 { 76 int height = fComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; 77 return height; 78 } 79 80 public Button getButton(int id) 81 { 82 if (id == IDialogConstants.OK_ID) 83 return fOKButton; 84 else if (id == IDialogConstants.CANCEL_ID) 85 return fCancelButton; 86 return null; 87 } 88 89 public String getExpressionText() 90 { 91 return fExpression.getText(); 92 } 93 94 public Text getExpressionWidget() 95 { 96 return fExpression; 97 } 98 99 public boolean isGoToAddress() 100 { 101 return fGoToCombo.getSelectionIndex() == 0; 102 } 103 104 public boolean isOffset() 105 { 106 return fGoToCombo.getSelectionIndex() == 1; 107 } 108 109 public boolean isJump() 110 { 111 return fGoToCombo.getSelectionIndex() == 2; 112 } 113 114 public boolean isHex() 115 { 116 return fHexButton.getSelection(); 117 } 118 119 public BigInteger getGoToAddress(BigInteger baseAddress, BigInteger selectedAddress) throws NumberFormatException 120 { 121 boolean add = true; 122 String expression = getExpressionText(); 123 boolean hex = isHex(); 124 int radix = hex?16:10; 125 126 expression = expression.trim(); 127 128 if (isGoToAddress()) 129 { 130 expression = expression.toUpperCase(); 131 if (expression.startsWith("0X")) { 133 expression = expression.substring(2); 134 radix = 16; 135 } 136 137 return new BigInteger (expression, radix); 138 } 139 140 if (expression.startsWith("+")) { 142 expression = expression.substring(1); 143 } 144 else if (expression.startsWith("-")) { 146 expression = expression.substring(1); 147 add = false; 148 } 149 150 expression = expression.toUpperCase(); 151 if (expression.startsWith("0X")) { 153 expression = expression.substring(2); 154 radix = 16; 155 } 156 157 BigInteger gotoAddress = new BigInteger (expression, radix); 158 159 BigInteger address = baseAddress; 160 if (isJump()) 161 address = selectedAddress; 162 163 if (address == null) 164 throw new NumberFormatException (DebugUIMessages.GoToAddressComposite_7); 165 166 if (add) 167 gotoAddress = address.add(gotoAddress); 168 else 169 gotoAddress = address.subtract(gotoAddress); 170 171 return gotoAddress; 172 } 173 174 } 175 | Popular Tags |