@Override public String trace() { String s = ""; for (int i = 0; i < functions.size(); i++) { s += functions.getValue(i).trace(); } return s; }
@Override public void compile() { Debugger debugContext = DinaCompiler.getDebugger(); int variablesWithValue = 0; int variablesAmount = getVariablesAmount(); for (int variableIndex = 0; variableIndex < variablesAmount; variableIndex++) { Variable variable = getVariable(variableIndex); if (variable.getValue() != null) { if (constructor == null) { constructor = new Function(ParserConstants.CONSTRUCTOR); constructor.setStatement(new Block()); constructor.getStatement().setFunction(constructor); } Assignment assignment = new Assignment(variable, variable.getValue()); constructor.getStatement().insertNode(assignment, variablesWithValue); variablesWithValue++; } } if (constructor != null) { Output.writeSystemInformation(Constants.BEGIN_FUNCTION); constructor.compile(); if (Debugger.DEVELOPMENT_MODE) { debugContext.putFunction("<constructor>", constructor.getAddress()); } Output.writeSystemInformation(Constants.END_FUNCTION); } int functionsAmount = functions.size(); for (int functionIndex = 0; functionIndex < functionsAmount; functionIndex++) { Function function = functions.getValue(functionIndex); Output.writeSystemInformation(Constants.BEGIN_FUNCTION); function.compile(); if (Debugger.DEVELOPMENT_MODE) { debugContext.putFunction( function.getSignatureLabel() + function.getNodeType().getSignature(), function.getAddress()); } Output.writeSystemInformation(Constants.END_FUNCTION); } if (destructor != null) { Output.writeSystemInformation(Constants.BEGIN_FUNCTION); destructor.compile(); if (Debugger.DEVELOPMENT_MODE) { debugContext.putFunction("<destructor>", destructor.getAddress()); } Output.writeSystemInformation(Constants.END_FUNCTION); } }
private void deleteSelectedSet() { MessageBox mb = new MessageBox(getShell(), SWT.YES | SWT.NO); mb.setText("Удаление пачки"); mb.setMessage("Вы уверены?"); if (SWT.YES == mb.open()) { selectedSetData.delete(); tableSet.deleteCurrent(); } }
public void addFunction(Function function) { String functionSignature = function.getSignatureLabel(); if (functions.getValue(functionSignature) != null) { throw new DinaException( "Функция '" + function.getSignature().toString() + "' уже существует", DinaException.COMPILATION_ERROR); } if (Function.getNativeFunctionsTable().getValue(functionSignature) != null) { error(function); } InternalFunctionContainer functionContainer = InternalFunctions.getFunctionContainer(function.getName()); if (functionContainer != null) { if (functionContainer.check(function.getArguments())) { error(function); } } functions.put(functionSignature, function); }
public void checkFunctions() { Enumeration<Function> en = functions.elements(); while (en.hasMoreElements()) { Function function = (Function) en.nextElement(); if (function.isForward()) { if (!function.isCompleted()) { throw new DinaException( "Неопределенная функция '" + function.getSignature() + "'", DinaException.COMPILATION_ERROR); } } } }
private void generate() { Calendar calendar = Calendar.getInstance(); calendar.set(dtFrom.getYear(), dtFrom.getMonth(), dtFrom.getDay()); Date dateFrom = calendar.getTime(); calendar.set(dtTo.getYear(), dtTo.getMonth(), dtTo.getDay()); Date dateTo = calendar.getTime(); setData = new SetData(new Date(), textComment.getText(), dateFrom, dateTo); tableSet.setValues(setData); final int octet = spinnerOctet.getSelection(); final String octetValue = textOctet.getText(); final int keys = spinnerCount.getSelection(); try { new ProgressMonitorDialog(getShell()) .run( true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Генерация ключей…", keys); for (int i = 0; i < keys; ++i) { String key; do { if (monitor.isCanceled()) { throw new InterruptedException(); } key = KeyGenerator.generateKey(octetValue, octet); } while (setData.isKeyExists(key)); setData.addKey(key, true); monitor.worked(1); } } }); } catch (InvocationTargetException e) { throw new KeyException("Ошибка при генерации ключей", e.getCause()); } catch (InterruptedException e) { } tableKey.setValues(setData.getKeys()); }
public int getFunctionsAmount() { int value = functions.size(); value += constructor == null ? 0 : 1; value += destructor == null ? 0 : 1; return value; }
public Function getFunction(String signature) { return functions.getValue(signature); }
public void selectRemove() { SetTable.rmSelected(this); }
/* Add self to selected cards vector if selected*/ public void selectAdd() { SetTable.addSelected(this); }
public EditComposite(Composite parent, int style) { super(parent, style); setLayout(new GridLayout(2, false)); Group groupFilter = new Group(this, SWT.NONE); groupFilter.setText("Поиск ключей"); groupFilter.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); groupFilter.setLayout(new GridLayout(2, false)); textFilter = new Text(groupFilter, SWT.BORDER); textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Button button = new Button(groupFilter, SWT.PUSH); button.setImage( new Image(getShell().getDisplay(), getClass().getResourceAsStream("/search.gif"))); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { filter(); } }); button = new Button(this, SWT.PUSH); button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); button.setText("Показать все"); button.setImage( new Image(getShell().getDisplay(), getClass().getResourceAsStream("/refresh.gif"))); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { refresh(); } }); SashForm sash = new SashForm(this, SWT.VERTICAL); sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); tableSet = new SetTable(sash, true); tableSet.addSelectionListener( new SetTable.SetSelectionListener() { @Override public void selected(SetData setData) { selectedSetData = setData; List<KeyData> keys = null; if (null != setData) { keys = setData.getKeys(); } tableKey.setValues(keys); buttonExport.setEnabled((keys != null) && !keys.isEmpty()); buttonDeleteSet.setEnabled(keys != null); } }); Composite keyComposite = new Composite(sash, SWT.NONE); GridLayout gl = new GridLayout(2, false); gl.marginWidth = 0; keyComposite.setLayout(gl); tableKey = new KeyTable(keyComposite); tableKey.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4)); tableKey.addSelectionListener( new KeyTable.KeySelectionListener() { @Override public void selected(KeyData keyData) { selectedKeyData = keyData; boolean isKeySelected = (keyData != null); buttonDeleteKey.setEnabled(isKeySelected); buttonActivateKey.setEnabled(isKeySelected); } }); buttonDeleteSet = new Button(keyComposite, SWT.PUSH); buttonDeleteSet.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false)); buttonDeleteSet.setText("Удаление пачки"); buttonDeleteSet.setImage( new Image(getShell().getDisplay(), getClass().getResourceAsStream("/delete.gif"))); buttonDeleteSet.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { deleteSelectedSet(); } }); buttonDeleteSet.setEnabled(false); buttonActivateKey = new Button(keyComposite, SWT.PUSH); buttonActivateKey.setText("Блокировать/активировать ключ"); buttonActivateKey.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false)); // buttonActivateKey.setImage(new Image(getShell().getDisplay(), // getClass().getResourceAsStream("/delete.gif"))); buttonActivateKey.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { activateSelectedKey(); } }); buttonActivateKey.setEnabled(false); buttonDeleteKey = new Button(keyComposite, SWT.PUSH); buttonDeleteKey.setText("Удаление ключа"); buttonDeleteKey.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false)); buttonDeleteKey.setImage( new Image(getShell().getDisplay(), getClass().getResourceAsStream("/delete.gif"))); buttonDeleteKey.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { deleteSelectedKey(); } }); buttonDeleteKey.setEnabled(false); buttonExport = new Button(keyComposite, SWT.PUSH); buttonExport.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false)); buttonExport.setText("Экспорт пачки…"); buttonExport.setImage( new Image(getShell().getDisplay(), getClass().getResourceAsStream("/saveas.gif"))); buttonExport.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { export(); } }); buttonExport.setEnabled(false); }
private void refresh() { tableSet.reset(); for (SetData setData : SetData.listAll()) { tableSet.setValues(setData); } }
private void filter() { tableSet.reset(); for (SetData setData : SetData.listFilter(textFilter.getText())) { tableSet.setValues(setData); } }
public NewComposite(Composite parent, int style) { super(parent, style); setLayout(new GridLayout(2, false)); GridData gd = new GridData(SWT.NONE, SWT.NONE, false, false); new Label(this, SWT.NONE).setText("Количество октетов:"); spinnerOctet = new Spinner(this, SWT.BORDER); spinnerOctet.setLayoutData(gd); spinnerOctet.setMinimum(2); spinnerOctet.setMaximum(8); new Label(this, SWT.NONE).setText("Количество ключей:"); spinnerCount = new Spinner(this, SWT.BORDER); spinnerCount.setLayoutData(gd); spinnerCount.setMinimum(1); spinnerCount.setMaximum(20000); new Label(this, SWT.NONE).setText("Настраиваемый октет:"); textOctet = new Text(this, SWT.BORDER); textOctet.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); textOctet.addVerifyListener( new VerifyListener() { @Override public void verifyText(VerifyEvent event) { int len = event.text.length(); if (len > 0) { int allowed = CUSTOM_OCTET_LENGTH - ((Text) event.widget).getText().length(); if (len > allowed) { event.text = event.text.substring(0, allowed); } if (!PATTERN_ALPHANUM.matcher(event.text).matches()) { event.doit = false; } else { event.text = event.text.toUpperCase(); } } } }); new Label(this, SWT.NONE).setText("Комментарий:"); textComment = new Text(this, SWT.BORDER); textComment.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); new Label(this, SWT.NONE).setText("Начало действия ключа:"); dtFrom = new DateTime(this, SWT.BORDER | SWT.DATE); Calendar calendar = Calendar.getInstance(); dtFrom.setDate( calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); new Label(this, SWT.NONE).setText("Окончание действия ключа:"); dtTo = new DateTime(this, SWT.BORDER | SWT.DATE); calendar.add(Calendar.YEAR, 1); dtTo.setDate( calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); Button button = new Button(this, SWT.PUSH); button.setImage(new Image(getShell().getDisplay(), getClass().getResourceAsStream("/new.gif"))); GridData buttonGridData = new GridData(SWT.NONE, SWT.NONE, false, false, 2, 1); button.setLayoutData(buttonGridData); button.setText("Создать"); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { generate(); buttonSave.setEnabled(true); } }); tableSet = new SetTable(this, false); tableSet.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1)); tableKey = new KeyTable(this); GridData gdKeyTable = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); gdKeyTable.heightHint = 50; tableKey.setLayoutData(gdKeyTable); buttonSave = new Button(this, SWT.PUSH); buttonSave.setLayoutData(buttonGridData); buttonSave.setText("Сохранить"); buttonSave.setImage( new Image(getShell().getDisplay(), getClass().getResourceAsStream("/export.gif"))); buttonSave.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { save(); buttonSave.setEnabled(false); } }); buttonSave.setEnabled(false); }
private void save() { setData.save(); tableSet.setValues(setData); }