use of brunonova.drmips.simulator.Component in project drmips by brunonova.
the class DlgChangeLatency method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
Bundle args = getArguments();
DrMIPSActivity activity = (DrMIPSActivity) getActivity();
Component component = activity.getCPU().getComponent(args.getString("id", ""));
txtLatency = new EditText(getActivity());
txtLatency.setHint(R.string.latency);
txtLatency.setInputType(InputType.TYPE_CLASS_NUMBER);
if (savedInstanceState != null && savedInstanceState.containsKey("latency")) {
txtLatency.setText(savedInstanceState.getString("latency"));
} else {
if (component != null)
txtLatency.setText("" + component.getLatency());
}
return new AlertDialog.Builder(getActivity()).setTitle(getResources().getString(R.string.latency_of_x).replace("#1", args.getString("id", ""))).setView(txtLatency).setPositiveButton(android.R.string.ok, this).setNegativeButton(android.R.string.cancel, this).create();
}
use of brunonova.drmips.simulator.Component in project drmips by brunonova.
the class DlgChangeLatency method onClick.
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case // OK
AlertDialog.BUTTON_POSITIVE:
try {
Bundle args = getArguments();
DrMIPSActivity activity = (DrMIPSActivity) getActivity();
Component component = activity.getCPU().getComponent(args.getString("id", ""));
int lat = Integer.parseInt(txtLatency.getText().toString());
if (lat >= 0 && component != null) {
component.setLatency(lat);
activity.getCPU().calculatePerformance();
activity.getDatapath().refresh();
activity.getDatapath().invalidate();
} else {
Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
}
} catch (NumberFormatException ex) {
Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
}
break;
case // Cancel
AlertDialog.BUTTON_NEGATIVE:
dismiss();
break;
}
}
Aggregations