/** * Description of loadDate()) Constructs a person bean from each line of text from the input file * and adds it to an observable list. */ private void loadData() { try { // System.out.println(Paths.get("mydata.txt").toAbsolutePath()); // List<String> lines = Files.readAllLines(Paths.get("build/resource/mydata.txt"), // Charset.defaultCharset()); BufferedReader br = new BufferedReader(new FileReader("build/resource/mydata.txt")); String line; String data[] = new String[4]; while (true) { line = br.readLine(); if (line == null) { break; } else { data = line.split(","); System.out.println(data); PersonBean p = new PersonBean(data[0], data[1], data[2], new Integer(data[3])); personData.add(p); } } // *****End for br.close(); System.out.println("Loaded " + data.length + " rows of data."); } catch (Exception e) { System.out.println("There was a problem loading the file:" + e.getMessage()); e.printStackTrace(); } }
@FXML private void Ok_click(ActionEvent event) { logger.entry(); LogEntry log = new LogEntry("6.16", "Local Delete Object Instance service"); try { ObjectInstanceHandle instanceHandle = rtiAmb .getObjectInstanceHandleFactory() .decode( ByteBuffer.allocate(4) .putInt(Integer.parseInt(ObjectInstanceDesignator.getText())) .array(), 0); log.getSuppliedArguments() .add( new ClassValuePair( "Object instance designator", ObjectInstanceHandle.class, instanceHandle.toString())); rtiAmb.localDeleteObjectInstance(instanceHandle); log.setDescription("Local Object instance deleted successfully"); log.setLogType(LogEntryType.REQUEST); } catch (FederateNotExecutionMember | NotConnected | NumberFormatException | CouldNotDecode | RTIinternalError | OwnershipAcquisitionPending | FederateOwnsAttributes | ObjectInstanceNotKnown | SaveInProgress | RestoreInProgress ex) { log.setException(ex); log.setLogType(LogEntryType.ERROR); logger.log(Level.ERROR, ex.getMessage(), ex); } catch (Exception ex) { log.setException(ex); log.setLogType(LogEntryType.FATAL); logger.log(Level.FATAL, ex.getMessage(), ex); } logEntries.add(log); ((Stage) OkButton.getScene().getWindow()).close(); logger.exit(); }
/** Writes the data to file. */ private void writeIt() { try { // FileWriter writer = new FileWriter("build/resource/mydata.txt"); BufferedWriter writer = new BufferedWriter(new FileWriter("build/resource/mydata.txt")); Iterator<PersonBean> it = personData.iterator(); while (it.hasNext()) { String x; PersonBean p = it.next(); writer.write( p.getFirstAndLastName() + "," + p.getEmail() + "," + p.getGender() + "," + p.getAge()); if (it.hasNext()) { writer.newLine(); } System.out.println("First and last: " + p.getFirstAndLastName()); } writer.close(); } catch (Exception e) { System.out.println("There was a problem saving the file:" + e.getMessage()); } }
@FXML private void OK_click(ActionEvent event) { logger.entry(); FederateHandle federateHandle; LogEntry log = new LogEntry("4.9", "Join Federation Execution service"); try { if (!FederateName.getText().isEmpty()) { log.getSuppliedArguments() .add(new ClassValuePair("Federate Name", String.class, FederateName.getText())); } log.getSuppliedArguments() .add(new ClassValuePair("Federate Type", String.class, FederateType.getText())); log.getSuppliedArguments() .add( new ClassValuePair( "Federation Execution Name", String.class, FederationExecutionName.getText())); List<URL> foms = new ArrayList<>(); int i = 1; for (File file : FomModuleDesignators.getFiles()) { foms.add(file.toURI().toURL()); log.getSuppliedArguments() .add( new ClassValuePair( "FOM Module Deisgnator " + i++, URL.class, file.toURI().toURL().toString())); } if (FederateName.getText().isEmpty() && FomModuleDesignators.getFileNames().isEmpty()) { federateHandle = rtiAmb.joinFederationExecution( FederateType.getText(), FederationExecutionName.getText()); } else if (FomModuleDesignators.getFileNames().isEmpty()) { federateHandle = rtiAmb.joinFederationExecution( FederateName.getText(), FederateType.getText(), FederationExecutionName.getText()); } else if (FederateName.getText().isEmpty()) { federateHandle = rtiAmb.joinFederationExecution( FederateType.getText(), FederationExecutionName.getText(), foms.toArray(new URL[foms.size()])); } else { federateHandle = rtiAmb.joinFederationExecution( FederateName.getText(), FederateType.getText(), FederationExecutionName.getText(), foms.toArray(new URL[foms.size()])); } log.getReturnedArguments() .add( new ClassValuePair( "Federate Handle", FederateHandle.class, federateHandle.toString())); log.setDescription("Federate joined federation execution successfully"); log.setLogType(LogEntryType.REQUEST); logicalTimeFactory = rtiAmb.getTimeFactory(); currentLogicalTime = logicalTimeFactory.makeInitial(); // subscribe to HLAcurrentFDD to retrieve FDD ObjectClassHandle FederationHandle = rtiAmb.getObjectClassHandle("HLAobjectRoot.HLAmanager.HLAfederation"); currentFDDHandle = rtiAmb.getAttributeHandle(FederationHandle, "HLAcurrentFDD"); AttributeHandleSet set = rtiAmb.getAttributeHandleSetFactory().create(); set.add(currentFDDHandle); rtiAmb.subscribeObjectClassAttributes(FederationHandle, set); rtiAmb.requestAttributeValueUpdate(FederationHandle, set, null); // In case of HLA_EVOKED we require this line to receive the FDD rtiAmb.evokeMultipleCallbacks( .05, 1); // evoke one callback will not be enough because the reflect attribute is the second // one } catch (CouldNotCreateLogicalTimeFactory | CallNotAllowedFromWithinCallback | CouldNotOpenFDD | ErrorReadingFDD | InconsistentFDD | FederateNameAlreadyInUse | FederateAlreadyExecutionMember | FederationExecutionDoesNotExist | SaveInProgress | RestoreInProgress | NotConnected | RTIinternalError ex) { log.setException(ex); log.setLogType(LogEntryType.ERROR); logger.log(Level.ERROR, ex.getMessage(), ex); } catch (Exception ex) { log.setException(ex); log.setLogType(LogEntryType.FATAL); logger.log(Level.FATAL, ex.getMessage(), ex); } logEntries.add(log); ((Stage) FederationExecutionName.getScene().getWindow()).close(); logger.exit(); }