@Test public void logSaveCorrectInputData() { setInputData(); viewModel.focusWasChanged(Boolean.FALSE); String message = viewModel.getLog().get(0); assertTrue( message.matches( ".*" + viewModel.seg1Point1XProperty().get() + ".*" + viewModel.seg1Point1YProperty().get() + ".*" + viewModel.seg1Point2XProperty().get() + ".*" + viewModel.seg1Point2YProperty().get() + ".*" + viewModel.seg2Point1XProperty().get() + ".*" + viewModel.seg2Point1YProperty().get() + ".*" + viewModel.seg2Point2XProperty().get() + ".*" + viewModel.seg2Point2YProperty().get() + ".*")); }
@Test public void canDoXorOperation() { viewModel.setOperation(Operation.XOR); initArraysForOperations(); viewModel.doOperation(); assertNotNull(viewModel.getResultBitArray()); }
@Test public void changeOperationAddsMessageChangeOperation() { viewModel.setOperation(Operation.XOR); String message = viewModel.getLog().get(viewModel.getLog().size() - 1); assertTrue(message.matches(".*" + ViewModel.LogMessages.OPERATION_CHANGED + ".*")); }
private JComponent createTabForSession(MemoryLogModel memoryLogModel) { ViewModel viewModel = new ViewModel(memoryLogModel); JComponent rawTable = createRawMessageTable(viewModel); JComponent crackedTable = createCrackedMessageTable(viewModel); JSplitPane messageView = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); messageView.setBorder(null); messageView.setLeftComponent(new JScrollPane(rawTable)); messageView.setRightComponent(new JScrollPane(crackedTable)); JSplitPane messageAndEventView = new JSplitPane(JSplitPane.VERTICAL_SPLIT); messageAndEventView.setResizeWeight(.66); messageAndEventView.setLeftComponent(messageView); messageAndEventView.setRightComponent(new JScrollPane(createEventMessageTable(viewModel))); messageAndEventView.setBorder(null); JPanel mainView = new JPanel(new BorderLayout()); mainView.add(messageAndEventView, BorderLayout.CENTER); // @todo - wrap the filter component in a "view builder". This will eliminate // the cast and provide the ability to change the layout without junking up // builder. JTextField filterField = new MessageSearchField(); FilterList<LogMessage> messages = ((GlazedListsMemoryLogModel) memoryLogModel).getMessages(); EventList matchers = new BasicEventList(); TextComponentMatcherEditor<LogMessage> liveSearchMatcherEditor = new TextComponentMatcherEditor<LogMessage>(filterField, new MessageFilterator()); matchers.add(liveSearchMatcherEditor); MatcherEditor matcherEditor = new CompositeMatcherEditor(matchers); messages.setMatcherEditor(matcherEditor); JPanel sortPanel = new JPanel(); ((FlowLayout) sortPanel.getLayout()).setAlignment(FlowLayout.LEFT); JCheckBox sortCheckbox = new JCheckBox("Keep New Messages At The Top"); sortPanel.add(sortCheckbox); sortCheckbox.addActionListener(viewModel.getSortByMessageIndexActionListener()); JCheckBox hideHeartbeats = new JCheckBox("Hide Heartbeats"); sortPanel.add(hideHeartbeats); hideHeartbeats.addActionListener(viewModel.getHideHeartbeatsActionListener()); JPanel filterPanel = new JPanel(); ((FlowLayout) filterPanel.getLayout()).setAlignment(FlowLayout.RIGHT); filterPanel.add(new JLabel("Search:")); filterPanel.add(filterField); JPanel northPanel = new JPanel(new BorderLayout()); northPanel.add(sortPanel, BorderLayout.WEST); northPanel.add(filterPanel, BorderLayout.EAST); mainView.add(northPanel, BorderLayout.NORTH); return mainView; }
@Test public void isFirstBitArrayNotNullWhenInitArray() { viewModel.setArraySize("5"); viewModel.initializeArray(); assertNotNull(viewModel.gitFirstBitArray()); }
@Test public void initArrayAddsMessageToLog() { viewModel.setArraySize("5"); viewModel.initializeArray(); assertFalse(viewModel.getLog().isEmpty()); }
@Test public void isFirstBitArraySizeEquals5WhenInputSize5() { viewModel.setArraySize("5"); viewModel.initializeArray(); assertEquals(viewModel.gitFirstBitArray().getSize(), 5); }
@Test public void canDoOrOperation() { initArraysForOperations(); viewModel.doOperation(); assertNotNull(viewModel.getResultBitArray()); }
@Test public void doesLogContainProperMessageAfterCalculation() { setInputData(); viewModel.calculate(); String logMessage = viewModel.getLog().get(0); assertTrue(logMessage.matches(".*" + LogMessages.CALCULATE_WAS_PRESSED + ".*")); }
@Test public void isDoOperationEnabledWhenInitArrays() { viewModel.setArraySize("5"); viewModel.initializeArray(); assertTrue(viewModel.isDoOperationEnabled()); }
@Test public void doesLogContainProperMessageAfterChangingInputData() { viewModel.seg2Point1XProperty().set("1"); viewModel.focusWasChanged(Boolean.FALSE); String logMessage = viewModel.getLog().get(0); assertTrue(logMessage.matches(".*" + LogMessages.EDITING_FINISHED + ".*")); }
@Test public void logCanHaveSeveralMessages() { viewModel.seg2Point1XProperty().set("1"); viewModel.focusWasChanged(Boolean.FALSE); viewModel.seg2Point1YProperty().set("5"); viewModel.focusWasChanged(Boolean.FALSE); assertEquals(2, viewModel.getLog().size()); }
@Test public void initArrayAddsMessageInitArrayWithSize() { viewModel.setArraySize("5"); viewModel.initializeArray(); String message = viewModel.getLog().get(viewModel.getLog().size() - 1); assertTrue(message.matches(".*" + ViewModel.LogMessages.INIT_ARRAY_WITH_SIZE + ".*")); }
@Test public void updatedSecondBitArrayAddsMessageUpdatedSecondBitArray() { initArraysForOperations(); viewModel.logUpdatedSecondBitArray(); String message = viewModel.getLog().get(viewModel.getLog().size() - 1); assertTrue(message.matches(".*" + ViewModel.LogMessages.UPDATE_SECOND_BIT_ARRAY + ".*")); }
@Test public void doNotAddLogMessageWhenSameParameterWasInput() { viewModel.seg1Point1XProperty().set("1"); viewModel.focusWasChanged(Boolean.FALSE); viewModel.seg1Point1XProperty().set("1"); viewModel.focusWasChanged(Boolean.FALSE); assertEquals(1, viewModel.getLog().size()); }
@Test public void setSizeArrayAddsMessageToLog() { viewModel.setArraySize("5"); viewModel.logUpdatedSize(); String message = viewModel.getLog().get(viewModel.getLog().size() - 1); assertTrue(message.matches(".*" + ViewModel.LogMessages.UPDATE_ARRAY_SIZE + ".*")); }
@Test public void doOperationAddsMessageToLog() { viewModel.setOperation(Operation.XOR); initArraysForOperations(); viewModel.doOperation(); assertFalse(viewModel.getLog().isEmpty()); }
@Test public void addLogMessageAfterDeletingInputData() { viewModel.seg1Point1XProperty().set("1"); viewModel.focusWasChanged(Boolean.FALSE); viewModel.seg1Point1XProperty().set(""); viewModel.focusWasChanged(Boolean.FALSE); assertEquals(2, viewModel.getLog().size()); }
@Test public void changeOperationNotAddsMessageToLogWithSameOperation() { viewModel.setOperation(Operation.XOR); int sizeFirst = viewModel.getLog().size(); viewModel.setOperation(Operation.XOR); assertEquals(viewModel.getLog().size(), sizeFirst); }
@Test public void doOperationAddsMessageDidOperation() { viewModel.setOperation(Operation.XOR); initArraysForOperations(); viewModel.doOperation(); String message = viewModel.getLog().get(viewModel.getLog().size() - 1); assertTrue(message.matches(".*" + ViewModel.LogMessages.OPERATION_DID + ".*")); }
private JComponent createRawMessageTable(ViewModel viewModel) { JTable table = new JTable(viewModel.getRawMessagesTableModel()); table.setSelectionModel(viewModel.getRawMessagesSelectionModel()); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); Enumeration<TableColumn> columns = table.getColumnModel().getColumns(); while (columns.hasMoreElements()) { TableColumn tableColumn = columns.nextElement(); tableColumn.setCellRenderer(viewModel.getRawMessagesTableCellRenderer()); } table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); return table; }
protected void bindGUI(DataBindingContext dbc) { // Since we're using a JFace Viewer, we do first wrap our Table... TableViewer peopleViewer = new TableViewer(duckFamily); peopleViewer.addFilter( new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return element != UNKNOWN; } }); ViewerSupport.bind( peopleViewer, viewModel.getPeople(), BeanProperties.values( Person.class, new String[] { "name", "mother.name", "father.name", "mother.mother.name", "mother.father.name", "father.mother.name", "father.father.name" })); IObservableValue masterSelection = ViewerProperties.singleSelection().observe(peopleViewer); dbc.bindValue( WidgetProperties.text(SWT.Modify).observe(nameText), BeanProperties.value(Person.class, "name").observeDetail(masterSelection)); ComboViewer mothercomboViewer = new ComboViewer(motherCombo); ViewerSupport.bind( mothercomboViewer, viewModel.getPeople(), BeanProperties.value(Person.class, "name")); dbc.bindValue( ViewerProperties.singleSelection().observe(mothercomboViewer), BeanProperties.value(Person.class, "mother").observeDetail(masterSelection)); ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); ViewerSupport.bind( fatherComboViewer, viewModel.getPeople(), BeanProperties.value(Person.class, "name")); dbc.bindValue( ViewerProperties.singleSelection().observe(fatherComboViewer), BeanProperties.value(Person.class, "father").observeDetail(masterSelection)); }
private JComponent createCrackedMessageTable(ViewModel viewModel) { TreeTableModel model = viewModel.getAdminMessagesCrackedModel(); JXTreeTable table = new JXTreeTable(model); // stupid JXTreeTable uses different row values... table.setRowHeight(16); table.setRowMargin(1); table.setColumnMargin(1); table.setShowGrid(true); table.setShowHorizontalLines(true); table.setShowVerticalLines(true); table.setRootVisible(false); table.setShowsRootHandles(true); table.setClosedIcon(null); table.setOpenIcon(null); table.setLeafIcon(null); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); HighlighterPipeline pipeline = new HighlighterPipeline(); pipeline.addHighlighter(new FieldHighlighter()); table.setHighlighters(pipeline); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); return table; }
private void setInputData() { viewModel.seg1Point1XProperty().set("1"); viewModel.seg1Point1YProperty().set("5"); viewModel.seg1Point2XProperty().set("5"); viewModel.seg1Point2YProperty().set("5"); viewModel.seg2Point1XProperty().set("2"); viewModel.seg2Point1YProperty().set("5"); viewModel.seg2Point2XProperty().set("10"); viewModel.seg2Point2YProperty().set("5"); }
public void playAll() { Objects.requireNonNull(this.model); try { for (int beat = 0; beat < model.getLength(); beat++) { this.playNotes(beat); } } catch (InvalidMidiDataException e) { } this.receiver.close(); }
protected void bindGUI(DataBindingContext bindingContext) { // Since we're using a JFace Viewer, we do first wrap our Table... TableViewer peopleViewer = new TableViewer(duckFamily); peopleViewer.addFilter( new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return element != UNKNOWN; } }); // Bind viewers to model ViewerSupport.bind( peopleViewer, viewModel.getPeople(), BeanProperties.values( new String[] {"name", "mother.name", "father.name", "mother.mother.name"})); // Bind viewer selection to detail fields IObservableValue selection = ViewersObservables.observeSingleSelection(peopleViewer); bindingContext.bindValue( WidgetProperties.text().observe(nameText), BeanProperties.value((Class) selection.getValueType(), "name", String.class) .observeDetail(selection)); ComboViewer mothercomboViewer = new ComboViewer(motherCombo); ViewerSupport.bind(mothercomboViewer, viewModel.getPeople(), BeanProperties.value("name")); bindingContext.bindValue( ViewersObservables.observeSingleSelection(mothercomboViewer), BeanProperties.value((Class) selection.getValueType(), "mother", Person.class) .observeDetail(selection)); ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); ViewerSupport.bind(fatherComboViewer, viewModel.getPeople(), BeanProperties.value("name")); bindingContext.bindValue( ViewersObservables.observeSingleSelection(fatherComboViewer), BeanProperties.value((Class) selection.getValueType(), "father", Person.class) .observeDetail(selection)); }
/** Renders the MidiView based on the given model, by playing all of the notes in the model */ private void playNotes(int beat) throws InvalidMidiDataException { for (Playable p : this.model.getNotes(beat)) { if (p.getStartBeat() == beat) { MidiMessage start = new ShortMessage( ShortMessage.NOTE_ON, p.getInstrumentID() - 1, Pitch.getMidi(p.getPitch(), p.getOctave()), 100); this.receiver.send(start, p.getStartBeat() * (60000000 / model.getTempo())); } if (p.getStartBeat() + p.getDuration() == beat + 1) { MidiMessage stop = new ShortMessage( ShortMessage.NOTE_OFF, p.getInstrumentID() - 1, Pitch.getMidi(p.getPitch(), p.getOctave()), 100); this.receiver.send( stop, (p.getStartBeat() + p.getDuration()) * (60000000 / model.getTempo())); } } }
public void quit(SwingController controller, JFrame viewer, Properties properties) { if (controller != null && viewer != null) { // save width & height Rectangle sz = viewer.getBounds(); getProperties().setInt("application.x", sz.x); getProperties().setInt("application.y", sz.y); getProperties().setInt("application.height", sz.height); getProperties().setInt("application.width", sz.width); if (properties != null) { getProperties() .set( PropertiesManager.PROPERTY_DEFAULT_PAGEFIT, properties.getProperty(PropertiesManager.PROPERTY_DEFAULT_PAGEFIT)); getProperties().set("document.viewtype", properties.getProperty("document.viewtype")); } getProperties().setDefaultFilePath(ViewModel.getDefaultFilePath()); getProperties().setDefaultURL(ViewModel.getDefaultURL()); } // save all the rest, cookies, bookmarks, etc. getProperties().saveAndEnd(); // make sure all the controllers have been disposed. for (int i = 0; i < controllers.size(); i++) { SwingController c = controllers.get(i); if (c == null) continue; c.dispose(); } /* CUCFL : don't exit the program, just dispose the viewer and return to th emain program... */ // System.exit(0); if (viewer != null) { viewer.setVisible(false); viewer.dispose(); } }
private void initArraysForOperations() { viewModel.setArraySize("5"); viewModel.initializeArray(); BitArray firstBitArray = viewModel.getFirstBitArray(); BitArray secondBitArray = viewModel.getSecondBitArray(); firstBitArray.setAll(true); secondBitArray.setAll(false); viewModel.setFirstBitArray(firstBitArray); viewModel.setSecondBitArray(secondBitArray); }
@Override public void render(double timestamp) { Objects.requireNonNull(this.model); try { int beatNum = (int) Math.round((timestamp / 60.0) * model.getTempo()); for (Link link : model.getLinks(beatNum)) { if (link.getPlayIteration() == model.getIteration()) { model.setCurrentTime(link.getLinkedBeat() * 60.0 / model.getTempo()); model.setIteration(model.getIteration() + 1); return; } } if (beatNum != this.lastBeat) { this.playNotes(beatNum); this.lastBeat = beatNum; } } catch (InvalidMidiDataException e) { } }