List of usage examples for javafx.collections ObservableList size
int size();
From source file:org.beryx.viewreka.fxapp.Viewreka.java
public void openFile(File file) { if (file != null && file.isFile()) { String filePath = file.getAbsolutePath(); ObservableList<Tab> tabs = projectTabPane.getTabs(); if (project != null) { if (file.toURI().normalize().equals(project.getScriptUri().normalize())) { menuTabBindingSourceCode.showTab(); return; }//from w w w. j a va2s .c o m ProjectSettings projectSettings = project.getProjectSettingsManager().getSettings(); List<String> openFiles = getOpenFiles(projectSettings); int index = openFiles.indexOf(filePath); if (index >= 0) { if (index >= tabs.size()) { Dialogs.error("Open File error", "Internal error: invalid index (" + index + ") for already open file."); } else { Tab tab = tabs.get(index); if (!filePath.equals(getData(tab).getFilePath())) { Dialogs.error("Open File error", "Internal error: already open file not found at the expected index " + index + "."); } else { projectTabPane.getSelectionModel().select(index); } } return; } } if (file.length() > MAX_TEXT_FILE_LENGTH) { Dialogs.error("Open File error", "File too big (" + file.length() + " bytes)."); return; } if (isProbablyBinary(file)) { if (!Dialogs.confirmYesNo("Open File", "This seems to be a binary file.", "Are you sure you want to open this file?")) { return; } } try { CodeAreaTab codeAreaTab = CodeAreaTab.fromFile(file); tabs.add(codeAreaTab); projectTabPane.getSelectionModel().select(codeAreaTab); if (project != null) { ProjectSettings projectSettings = project.getProjectSettingsManager().getSettings(); List<String> openFiles = getOpenFiles(projectSettings); openFiles.add(filePath); codeAreaTab.setOnCloseRequest(ev -> { if (!tryClose(codeAreaTab)) ev.consume(); }); } } catch (IOException e) { Dialogs.error("Open File error", "Cannot open file '" + filePath + "'", e); return; } } }
From source file:aajavafx.Schedule1Controller.java
public ObservableList<CustomerProperty> getUnsignedCustomers() throws IOException, JSONException { //Customers customers = new Customers(); EmployeeSchedule mySchedule = new EmployeeSchedule(); singleton = Singleton.getInstance(); Gson gson = new Gson(); ObservableList<CustomerProperty> customerPropertyCustomersSigned = FXCollections.observableArrayList(); ObservableList<CustomerProperty> customerPropertyAllCustomers = this.getCustomer(); JSONObject jo = new JSONObject(); CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("EMPLOYEE", "password"); provider.setCredentials(AuthScope.ANY, credentials); HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build(); HttpGet get = new HttpGet("http://localhost:8080/MainServerREST/api/employeeschedule/date/" + getDate()); HttpResponse response = client.execute(get); System.out.println("RESPONSE IS: " + response); JSONArray jsonArray = new JSONArray( IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8"))); System.out.println("1 " + jsonArray); for (int i = 0; i < jsonArray.length(); i++) { jo = (JSONObject) jsonArray.getJSONObject(i); mySchedule = gson.fromJson(jo.toString(), EmployeeSchedule.class); customerPropertyCustomersSigned.add(new CustomerProperty(mySchedule.getCustomersCuId().getCuId(), mySchedule.getCustomersCuId().getCuFirstname(), mySchedule.getCustomersCuId().getCuLastname(), mySchedule.getCustomersCuId().getCuPersonnummer())); }//from ww w. ja v a 2 s . c om for (int i = 0; i < customerPropertyAllCustomers.size(); i++) { for (int j = 0; j < customerPropertyCustomersSigned.size(); j++) { if (customerPropertyAllCustomers.get(i).getPersonnumer() .equals(customerPropertyCustomersSigned.get(j).getPersonnumer())) { customerPropertyAllCustomers.remove(i); } } } singleton.setList(customerPropertyAllCustomers); return customerPropertyAllCustomers; }
From source file:condorclient.CreateJobDialogController.java
@FXML private void saveJobFired(ActionEvent event) { nrun = Integer.parseInt(sampleNumText.getText().trim()); if (nrun == 0) { return;/* w ww .j a va 2 s . com*/ } int eachrun = 0; // System.out.println("map:" + map.toString()); ObservableList<String> slotname = FXCollections.observableArrayList(); XMLHandler handler = new XMLHandler(); if (allocMthod == 0) {//slot? if (!slotNumIsOk()) { return; } int i = 0; for (String s : map.keySet()) { if (i >= useslotnum) { break; } i = i + map.get(s).size(); if (i <= useslotnum) {//? slotname.addAll(map.get(s)); } else { i = i - map.get(s).size(); for (String rest : map.get(s)) { if (i >= useslotnum) { break; } slotname.add(rest); i++; } } } //slotname //?? // System.out.println("allocMthod:" + allocMthod + "useslotnum:" + useslotnum + "\nslotname:" + slotname.toString()); } else if (allocMthod == 1) {//? if (!nodeNumInputIsOk()) { return; } int i = 0; for (String s : map.keySet()) { if (i >= usenodenum) { break; } i++; //s if (slotname.size() + map.get(s).size() <= nrun) { slotname.addAll(map.get(s)); } else if (slotname.size() < nrun) {//??ip? for (String rs : map.get(s)) { slotname.add(rs); if (slotname.size() == nrun) { break; } } break; } } //System.out.println("allocMthod:" + allocMthod + "usenodenum:" + usenodenum + "\nslotname:" + slotname.toString()); } else if (allocMthod == 2) {//? int i = 0; for (String s : apponitmap.keySet()) { // slotname.addAll(map.get(s));//apponitmap?keylist ///eee if (i >= nrun) { break; } i++; //s if (slotname.size() + map.get(s).size() <= nrun) { slotname.addAll(map.get(s)); } else if (slotname.size() < nrun) {//??machine?slot for (String rs : map.get(s)) { slotname.add(rs); if (slotname.size() == nrun) { break; } } break; } ///eee } if (slotname.size() == 0) { // System.out.println("+++++"+otherError.getText()); otherError.setText("?"); return; } //System.out.println("allocMthod:" + allocMthod + "zhi ding ge shu:" + apponitmap.keySet().size() + "\nslotname:" + slotname.toString()); } else if (allocMthod == 3) {//?? //e int aptNum = 0; if (slotNum <= nrun) {//?? aptNum = slotNum; } else { aptNum = nrun; } for (int i = 0; i < aptNum; i++) {//slotNum slotname.add(""); } //e } eachrun = nrun / slotname.size(); int restrun = nrun - eachrun * slotname.size();//?slot //System.out.println("eachrun" + eachrun + "restrun" + restrun); URL url = null; String scheddStr = handler.getURL("schedd"); try { url = new URL(scheddStr); // url = new URL("http://localhost:9628"); } catch (MalformedURLException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } Schedd schedd = null; try { schedd = new Schedd(url); } catch (ServiceException e2) { } //s String timestamp = (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date()); String resultdirstr = resultFileText.getText().trim() + "\\" + jobNameText.getText().trim() + "\\" + timestamp; System.out.println(resultdirstr); try { FileUtils.forceMkdir(new File(resultdirstr)); } catch (IOException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(timestamp); //? File infoFile = new File(infoFileText.getText().trim()); File expFile = new File(expFileText.getText().trim()); // File testFile = new File("D:\\HTCondor\\test\\2\\inputfile.txt"); File[] transfiles = { infoFile, expFile }; //e Transaction xact = schedd.createTransaction(); try { if (xact != null) { xact.begin(3000); } } catch (RemoteException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int clusterId = 0; try { clusterId = xact.createCluster(); } catch (RemoteException e) { } int j = 0; for (String name : slotname) {//3slot?? j++; int jobId = 0; try { jobId = xact.createJob(clusterId); } catch (RemoteException e) { } //s String jobdirstr = resultdirstr + "\\" + jobId; File jobdir = new File(jobdirstr); try { FileUtils.forceMkdir(jobdir);//?job } catch (IOException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } //??job /* for (File f : transfiles) { try { FileUtils.copyFileToDirectory(f, jobdir); } catch (IOException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } }*/ //e if (j == slotname.size()) { eachrun = eachrun + restrun; } String eachrunstr = "" + eachrun; String argumentsStr = infoFile.getName() + " " + expFile.getName() + " " + eachrunstr;// "" + eachrunstr;// null;//".exl .ixl nrun" String requirementsStr = "Name==\"" + name + "\"";//Name=slot1@Lenovo-PC;String req="Name==\"slot1@Lenovo-PC\""; if (name.equals("")) { requirementsStr = null;//?? } ClassAdStructAttr[] attributes = null;// {new ClassAdStructAttr()}; // ClassAdStructAttr attribute =new ClassAdStructAttr("WhenToTransferOutput",ClassAdAttrType.value3,"ON_EXIT_OR_EVICT"); //attributes[0] = new ClassAdStructAttr("Iwd", ClassAdAttrType.value3, jobdirstr); //JobLeaseDuration // attributes[1] = new ClassAdStructAttr("JobLeaseDuration", ClassAdAttrType.value1,"1200"); String commandStr = handler.getexecutableFile();//? try { xact.submit(clusterId, jobId, "htcondor", UniverseType.VANILLA, commandStr, argumentsStr, requirementsStr, attributes, transfiles); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { xact.holdJob(clusterId, jobId, "");// } catch (RemoteException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } } try { xact.commit(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } String jobName = jobNameText.getText(); handler.addJob(jobName, "" + clusterId, resultdirstr, expFileText.getText().trim(), infoFileText.getText().trim()); // System.out.print("createTransaction succeed haha!!\n"); exeCreate = 1; stage.close(); }
From source file:condorclient.CreateJobDialogController.java
@FXML private void runJobFired(ActionEvent event) { nrun = Integer.parseInt(sampleNumText.getText().trim()); if (nrun == 0) { return;/*from w ww . ja va 2 s .c o m*/ } int eachrun = 0; // System.out.println("map:" + map.toString()); ObservableList<String> slotname = FXCollections.observableArrayList(); XMLHandler handler = new XMLHandler(); if (allocMthod == 0) {//slot? if (!slotNumIsOk()) { return; } int i = 0; for (String s : map.keySet()) { if (i >= useslotnum) { break; } i = i + map.get(s).size(); if (i <= useslotnum) {//? slotname.addAll(map.get(s)); } else { i = i - map.get(s).size(); for (String rest : map.get(s)) { if (i >= useslotnum) { break; } slotname.add(rest); i++; } } } //slotname //?? // System.out.println("allocMthod:" + allocMthod + "useslotnum:" + useslotnum + "\nslotname:" + slotname.toString()); } else if (allocMthod == 1) {//? // if (!nodeNumInputIsOk()) {//??? return; } int i = 0; for (String s : map.keySet()) { if (i >= usenodenum) { break; } i++; if (slotname.size() + map.get(s).size() <= nrun) { slotname.addAll(map.get(s)); } else if (slotname.size() < nrun) {//??ip? for (String rs : map.get(s)) { slotname.add(rs); if (slotname.size() == nrun) { break; } } break; } } //System.out.println("allocMthod:" + allocMthod + "usenodenum:" + usenodenum + "\nslotname:" + slotname.toString()); } else if (allocMthod == 2) {//? int i = 0; for (String s : apponitmap.keySet()) { // slotname.addAll(map.get(s));//apponitmap?keylist if (i >= nrun) { break; } i++; //s if (slotname.size() + map.get(s).size() <= nrun) { slotname.addAll(map.get(s)); } else if (slotname.size() < nrun) {//??machine?slot for (String rs : map.get(s)) { slotname.add(rs); if (slotname.size() == nrun) { break; } } break; } } if (slotname.size() == 0) { //System.out.println("+++++"+otherError.getText()); otherError.setText("?"); return; } //System.out.println("allocMthod:" + allocMthod + "zhi ding ge shu:" + apponitmap.keySet().size() + "\nslotname:" + slotname.toString()); } else if (allocMthod == 3) {//???????? int aptNum = 0; if (slotNum <= nrun) {//?? aptNum = slotNum; } else { aptNum = nrun; } for (int i = 0; i < aptNum; i++) {//slotNum slotname.add(""); } } eachrun = nrun / slotname.size(); int restrun = nrun - eachrun * slotname.size();//?slot //System.out.println("eachrun" + eachrun + "restrun" + restrun); URL url = null; String scheddStr = handler.getURL("schedd"); try { url = new URL(scheddStr); } catch (MalformedURLException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } Schedd schedd = null; try { schedd = new Schedd(url); } catch (ServiceException e2) { } int j = 0; // String timestamp = (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date()); String resultdirstr = resultFileText.getText().trim() + "\\" + jobNameText.getText().trim() + "\\" + timestamp; System.out.println(resultdirstr); try { FileUtils.forceMkdir(new File(resultdirstr)); } catch (IOException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(timestamp); //? File infoFile = new File(infoFileText.getText().trim()); File expFile = new File(expFileText.getText().trim()); File[] transfiles = { infoFile, expFile }; Transaction xact = schedd.createTransaction(); try { xact.begin(30); } catch (RemoteException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int clusterId = 0; try { clusterId = xact.createCluster(); } catch (RemoteException e) { } for (String name : slotname) {//3slot?? j++; int jobId = 0; try { jobId = xact.createJob(clusterId); } catch (RemoteException e) { } String jobdirstr = resultdirstr + "\\" + jobId; File jobdir = new File(jobdirstr); try { FileUtils.forceMkdir(jobdir);//?job } catch (IOException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } //??job /* for (File f : transfiles) { try { FileUtils.copyFileToDirectory(f, jobdir); } catch (IOException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } }*/ if (j == slotname.size()) { eachrun = eachrun + restrun; } String eachrunstr = "" + eachrun; String argumentsStr = infoFile.getName() + " " + expFile.getName() + " " + eachrunstr;// null;//".exl .ixl nrun" String requirementsStr = "Name==\"" + name + "\"";//Name=slot1@Lenovo-PC;String req="Name==\"slot1@Lenovo-PC\""; if (name.equals("")) { requirementsStr = null;//?? } System.out.println("requirementsStr:" + requirementsStr + "eachrunstr:" + eachrunstr); ClassAdStructAttr[] attributes = null;// {new ClassAdStructAttr()}; // ClassAdStructAttr attribute =new ClassAdStructAttr("WhenToTransferOutput",ClassAdAttrType.value3,"ON_EXIT_OR_EVICT"); // attributes[0] = new ClassAdStructAttr("Iwd", ClassAdAttrType.value3, jobdirstr); // attributes[1] = new ClassAdStructAttr("JobLeaseDuration", ClassAdAttrType.value1,"1200"); String commandStr = handler.getexecutableFile();//? try { xact.submit(clusterId, jobId, "htcondor", UniverseType.VANILLA, commandStr, argumentsStr, requirementsStr, attributes, transfiles); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { xact.commit(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { schedd.requestReschedule();// } catch (RemoteException ex) { Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex); } String jobName = jobNameText.getText(); handler.addJob(jobName, "" + clusterId, resultdirstr, expFileText.getText().trim(), infoFileText.getText().trim());//jobItem exeCreate = 1; stage.close(); }
From source file:org.nmrfx.processor.gui.PropertyManager.java
PropertyManager(ProcessorController processorController, final ListView scriptView, PropertySheet propertySheet, ObservableList<String> listItems, TextField opTextField, PopOver popOver) { this.processorController = processorController; this.scriptView = scriptView; this.listItems = listItems; this.opTextField = opTextField; this.propertySheet = propertySheet; this.popOver = popOver; doubleListener = new ChangeListener<Number>() { @Override/*from w w w. j a v a 2s . com*/ public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) { updateOp((PropertySheet.Item) observableValue); } }; intListener = new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) { updateOp((PropertySheet.Item) observableValue); } }; boolListener = new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observableValue, Boolean bool, Boolean bool2) { updateOp((PropertySheet.Item) observableValue); } }; stringListener = new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observableValue, String string, String string2) { updateOp((PropertySheet.Item) observableValue); } }; complexListener = new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observableValue, String c1, String c2) { updateOp((PropertySheet.Item) observableValue); } }; listListener = new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observableValue, String c1, String c2) { updateOp((PropertySheet.Item) observableValue); } }; ChangeListener<Number> scriptOpListener = new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number number, Number number2) { int scriptIndex = (Integer) number2; try { if ((listItems.size() == 1) && (scriptIndex == -1)) { //there is a single item in the Cells -- Don't unselect scriptIndex = 0; } else if (scriptIndex != -1) { String selOp = (String) scriptView.getItems().get(scriptIndex); setPropSheet(scriptIndex, selOp); } else { setPropSheet(scriptIndex, ""); } } catch (Exception e) { System.out.println(e.getMessage()); } finally { currentIndex = scriptIndex; } } }; scriptView.getSelectionModel().selectedIndexProperty().addListener(scriptOpListener); propertySheet.setPropertyEditorFactory(new NvFxPropertyEditorFactory(processorController)); propertySheet.setMode(PropertySheet.Mode.NAME); propertySheet.setModeSwitcherVisible(false); propertySheet.setSearchBoxVisible(false); }
From source file:de.bayern.gdi.gui.Controller.java
private void setCrsAndExtent(WFSMeta.Feature feature) { wmsWfsMapHandler.setExtend(feature.getBBox()); ArrayList<String> list = new ArrayList<>(); list.add(feature.getDefaultCRS());//from w w w .j a va 2s.c o m list.addAll(feature.getOtherCRSs()); ObservableList<CRSModel> crsList = FXCollections.observableArrayList(); for (String crsStr : list) { try { String newcrsStr = crsStr; String seperator = null; if (newcrsStr.contains("::")) { seperator = "::"; } else if (newcrsStr.contains("/")) { seperator = "/"; } if (seperator != null) { newcrsStr = "EPSG:" + newcrsStr.substring(newcrsStr.lastIndexOf(seperator) + seperator.length(), newcrsStr.length()); } CoordinateReferenceSystem crs = CRS.decode(newcrsStr); CRSModel crsm = new CRSModel(crs); crsm.setOldName(crsStr); crsList.add(crsm); } catch (FactoryException e) { log.error(e.getMessage(), e); } } if (!crsList.isEmpty()) { this.referenceSystemChooser.setItems(crsList); CRSModel crsm = crsList.get(0); try { CoordinateReferenceSystem initCRS = CRS.decode(INITIAL_CRS_DISPLAY); CRSModel initCRSM = new CRSModel(initCRS); for (int i = 0; i < crsList.size(); i++) { if (crsList.get(i).equals(initCRSM)) { crsm = crsList.get(i); break; } } } catch (FactoryException e) { log.error(e.getMessage(), e); } this.referenceSystemChooser.setValue(crsm); } }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
@FXML private void onActionButtonRemovePositionTransmittanceMap(ActionEvent event) { ObservableList<Point3d> selectedItems = listViewTransmittanceMapSensorPositions.getSelectionModel() .getSelectedItems();//from w w w. j a v a2 s . com if (selectedItems.size() == listViewTransmittanceMapSensorPositions.getItems().size()) { listViewTransmittanceMapSensorPositions.getItems().clear(); } else { listViewTransmittanceMapSensorPositions.getItems().removeAll(selectedItems); } }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
public void setStage(final Stage stage) { this.stage = stage; stage.setOnShown(new EventHandler<WindowEvent>() { @Override//from w w w . j av a 2 s . c o m public void handle(WindowEvent event) { ObservableList<Screen> screens = Screen.getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); if (screens != null && screens.size() > 0) { SCREEN_WIDTH = screens.get(0).getBounds().getWidth(); SCREEN_HEIGHT = screens.get(0).getBounds().getHeight(); } } }); viewer3DPanelController.setStage(stage); }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
private void editVoxelSpace(final File voxelFile) { if (editingFrameOpened) { return;/*from w w w . j a va 2 s . c o m*/ } editingFrameOpened = true; voxelsToRemove.clear(); final String attributeToView = "PadBVTotal"; //window size ObservableList<Screen> screens = Screen.getScreens(); if (screens != null && screens.size() > 0) { SCREEN_WIDTH = screens.get(0).getBounds().getWidth(); SCREEN_HEIGHT = screens.get(0).getBounds().getHeight(); } try { Service s = new Service() { @Override protected Task createTask() { return new Task() { @Override protected Object call() throws Exception { SimpleViewer viewer3D = new SimpleViewer((int) (SCREEN_WIDTH / 4.0d), (int) (SCREEN_HEIGHT / 4.0d), (int) (SCREEN_WIDTH / 1.5d), (int) (SCREEN_HEIGHT / 2.0d), voxelFile.toString()); fr.amap.viewer3d.object.scene.Scene scene = viewer3D.getScene(); /** * *VOXEL SPACE** */ updateMessage("Loading voxel space: " + voxelFile.getAbsolutePath()); final VoxelSpaceSceneObject voxelSpace = new VoxelSpaceSceneObject(voxelFile); voxelSpace.setMousePickable(true); voxelSpace.addVoxelSpaceListener(new VoxelSpaceAdapter() { @Override public void voxelSpaceCreationProgress(int progress) { updateProgress(progress, 100); } }); voxelSpace.loadVoxels(); float voxelResolution = voxelSpace.data.getVoxelSpaceInfos().getResolution(); VoxelFileReader reader = new VoxelFileReader(voxelFile); VoxelSpaceInfos infos = reader.getVoxelSpaceInfos(); final SceneObject boundingBox = new SimpleSceneObject(); boundingBox.setMesh(GLMeshFactory.createBoundingBox((float) infos.getMinCorner().x, (float) infos.getMinCorner().y, (float) infos.getMinCorner().z, (float) infos.getMaxCorner().x, (float) infos.getMaxCorner().y, (float) infos.getMaxCorner().z)); SimpleShader s = new SimpleShader(); s.setColor(new Vec3F(1, 0, 0)); boundingBox.setShader(s); boundingBox.setDrawType(GLMesh.DrawType.LINES); scene.addSceneObject(boundingBox); /* * Voxel information */ StringToImage stringToImage = new StringToImage(1024, 1024); stringToImage.setAdaptableFontSize(true); stringToImage.setBackgroundColor(new Color(255, 255, 255, 127)); stringToImage.setTextColor(new Color(0, 0, 0, 255)); BufferedImage image = new BufferedImage(1024, 1024, BufferedImage.TYPE_INT_ARGB); Texture texture = new Texture(image); int pickingInfoObjectWidth = viewer3D.getWidth() / 5; int pickingInfoObjectHeight = viewer3D.getHeight() / 5; SceneObject pickingInfoObject = SceneObjectFactory.createTexturedPlane( new Vec3F(viewer3D.getWidth() - pickingInfoObjectWidth, viewer3D.getHeight() - pickingInfoObjectHeight, 0), pickingInfoObjectWidth, pickingInfoObjectHeight, texture); pickingInfoObject.setShader(new TextureShader()); pickingInfoObject.setDrawType(GLMesh.DrawType.TRIANGLES); SceneObject sceneObjectSelectedVox = new SimpleSceneObject( GLMeshFactory.createBoundingBox(-voxelResolution / 2.0f, -voxelResolution / 2.0f, -voxelResolution / 2.0f, voxelResolution / 2.0f, voxelResolution / 2.0f, voxelResolution / 2.0f), false); SimpleShader simpleShader = new SimpleShader(); simpleShader.setColor(new Vec3F(1, 0, 0)); sceneObjectSelectedVox.setVisible(false); sceneObjectSelectedVox.setShader(simpleShader); sceneObjectSelectedVox.setDrawType(GLMesh.DrawType.LINES); viewer3D.getScene().addSceneObject(sceneObjectSelectedVox); final SimpleObjectProperty<VoxelObject> selectedVoxel = new SimpleObjectProperty<>(); SceneObjectListener listener = new SceneObjectListener() { @Override public void clicked(SceneObject sceneObject, MousePicker mousePicker, Point3D intersection) { Vec3F camLocation = viewer3D.getScene().getCamera().getLocation(); selectedVoxel.set(voxelSpace.doPicking(mousePicker)); if (selectedVoxel.get() != null) { String[][] lines = new String[voxelSpace.getColumnsNames().length][2]; for (int i = 0; i < voxelSpace.getColumnsNames().length; i++) { lines[i][0] = voxelSpace.getColumnsNames()[i]; float attribut = selectedVoxel.get().getAttributs()[i]; if (Float.isNaN(attribut)) { lines[i][1] = "NaN"; } else { lines[i][1] = String .valueOf(Math.round(attribut * 1000.0f) / 1000.0f); } } arrangeText(lines); String text = ""; for (int i = 0; i < voxelSpace.getColumnsNames().length; i++) { String attribut = lines[i][0] + " " + lines[i][1]; text += attribut + "\n"; } stringToImage.setText(text, 0, 0); texture.setBufferedImage(stringToImage.buildImage()); Point3f voxelPosition = voxelSpace.getVoxelPosition(selectedVoxel.get().$i, selectedVoxel.get().$j, selectedVoxel.get().$k); sceneObjectSelectedVox.setPosition( new Point3F(voxelPosition.x, voxelPosition.y, voxelPosition.z)); sceneObjectSelectedVox.setVisible(true); pickingInfoObject.setVisible(true); } else { sceneObjectSelectedVox.setVisible(false); pickingInfoObject.setVisible(false); } } }; final SimpleIntegerProperty currentZCropIndex = new SimpleIntegerProperty(0); viewer3D.addEventListener(new EventManager(null, new InputKeyListener()) { @Override public void updateEvents() { if (this.keyboard.isKeyClicked(KeyEvent.VK_DELETE)) { if (selectedVoxel.get() != null) { selectedVoxel.get().setAlpha(0); selectedVoxel.get().isHidden = true; voxelSpace.updateVao(); sceneObjectSelectedVox.setVisible(false); pickingInfoObject.setVisible(false); voxelsToRemove.add(new Point3i(selectedVoxel.get().$i, selectedVoxel.get().$j, selectedVoxel.get().$k)); } } } }); voxelSpace.addSceneObjectListener(listener); voxelSpace.changeCurrentAttribut(attributeToView); voxelSpace.setShader(new InstanceLightedShader()); voxelSpace.setDrawType(GLMesh.DrawType.TRIANGLES); scene.addSceneObject(voxelSpace); scene.addSceneObjectAsHud(pickingInfoObject); /** * *scale** */ updateMessage("Generating scale"); final Texture scaleTexture = new Texture(ScaleGradient.createColorScaleBufferedImage( voxelSpace.getGradient(), voxelSpace.getAttributValueMin(), voxelSpace.getAttributValueMax(), viewer3D.getWidth() - 80, (int) (viewer3D.getHeight() / 20), ScaleGradient.Orientation.HORIZONTAL, 5, 8)); SceneObject scalePlane = SceneObjectFactory.createTexturedPlane(new Vec3F(40, 20, 0), (int) (viewer3D.getWidth() - 80), (int) (viewer3D.getHeight() / 20), scaleTexture); scalePlane.setShader(new TextureShader()); scalePlane.setDrawType(GLMesh.DrawType.TRIANGLES); scene.addSceneObjectAsHud(scalePlane); voxelSpace.addPropertyChangeListener("gradientUpdated", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { BufferedImage image = ScaleGradient.createColorScaleBufferedImage( voxelSpace.getGradient(), voxelSpace.getAttributValueMin(), voxelSpace.getAttributValueMax(), viewer3D.getWidth() - 80, (int) (viewer3D.getHeight() / 20), ScaleGradient.Orientation.HORIZONTAL, 5, 8); scaleTexture.setBufferedImage(image); } }); /** * *light** */ scene.setLightPosition( new Point3F(voxelSpace.getGravityCenter().x, voxelSpace.getGravityCenter().y, voxelSpace.getGravityCenter().z + voxelSpace.widthZ + 100)); /** * *camera** */ TrackballCamera trackballCamera = new TrackballCamera(); trackballCamera.setPivot(voxelSpace); trackballCamera .setLocation(new Vec3F(voxelSpace.getGravityCenter().x + voxelSpace.widthX, voxelSpace.getGravityCenter().y + voxelSpace.widthY, voxelSpace.getGravityCenter().z + voxelSpace.widthZ)); viewer3D.getScene().setCamera(trackballCamera); Platform.runLater(new Runnable() { @Override public void run() { final Stage toolBarFrameStage = new Stage(); final FXMLLoader loader = new FXMLLoader( getClass().getResource("/fxml/ToolBoxFrame.fxml")); try { stage.setAlwaysOnTop(false); Parent root = loader.load(); toolBarFrameStage.setScene(new Scene(root)); toolBarFrameStage.initStyle(StageStyle.UNDECORATED); toolBarFrameStage.setAlwaysOnTop(true); ToolBoxFrameController toolBarFrameController = loader.getController(); toolBarFrameController.setStage(toolBarFrameStage); toolBarFrameStage.setX(viewer3D.getPosition().getX()); toolBarFrameStage.setY(viewer3D.getPosition().getY()); toolBarFrameController.setJoglListener(viewer3D.getJoglContext()); toolBarFrameController.setAttributes(attributeToView, voxelSpace.data.getVoxelSpaceInfos().getColumnNames()); toolBarFrameStage.focusedProperty() .addListener(new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (newValue) { toolBarFrameStage.setAlwaysOnTop(true); toolBarFrameStage.setX(viewer3D.getPosition().getX()); toolBarFrameStage.setY(viewer3D.getPosition().getY()); } else if (!viewer3D.isFocused()) { toolBarFrameStage.setAlwaysOnTop(false); } } }); toolBarFrameController.initContent(voxelSpace); toolBarFrameStage.setAlwaysOnTop(true); toolBarFrameStage.show(); double maxToolBoxHeight = toolBarFrameStage.getHeight(); viewer3D.getJoglContext().setStartX((int) toolBarFrameStage.getWidth()); viewer3D.getRenderFrame().addWindowListener(new WindowAdapter() { @Override public void windowResized(com.jogamp.newt.event.WindowEvent we) { Window window = (Window) we.getSource(); final double height = window.getHeight(); Platform.runLater(new Runnable() { @Override public void run() { if (height < maxToolBoxHeight) { toolBarFrameStage.setHeight(height); } else { toolBarFrameStage.setHeight(maxToolBoxHeight); } toolBarFrameStage.setX(viewer3D.getPosition().getX()); toolBarFrameStage.setY(viewer3D.getPosition().getY()); } }); } @Override public void windowMoved(com.jogamp.newt.event.WindowEvent we) { Platform.runLater(new Runnable() { @Override public void run() { toolBarFrameStage.setX(viewer3D.getPosition().getX()); toolBarFrameStage.setY(viewer3D.getPosition().getY()); } }); } @Override public void windowDestroyed(com.jogamp.newt.event.WindowEvent we) { Platform.runLater(new Runnable() { @Override public void run() { toolBarFrameStage.close(); if (fcSaveVoxelFileForAreaExtracting == null) { fcSaveVoxelFileForAreaExtracting = new FileChooserContext(); if (fcOpenVoxelFileForAreaExtracting != null) { fcSaveVoxelFileForAreaExtracting.fc .setInitialDirectory( fcOpenVoxelFileForAreaExtracting.lastSelectedFile .getParentFile()); } } File selectedFile = fcSaveVoxelFileForAreaExtracting .showSaveDialog(stage); if (selectedFile != null) { VoxelFileReader reader; BufferedWriter writer = null; try { reader = new VoxelFileReader(voxelFile, true); VoxelSpaceInfos infos = reader.getVoxelSpaceInfos(); writer = new BufferedWriter( new FileWriter(selectedFile)); writer.write(infos.toString() + "\n"); Iterator<Voxel> iterator = reader.iterator(); while (iterator.hasNext()) { Voxel voxel = iterator.next(); if (voxelsToRemove.contains(new Point3i( voxel.$i, voxel.$j, voxel.$k))) { voxel.PadBVTotal = 0; voxel.nbEchos = 0; voxel.transmittance = 1; voxel.bvIntercepted = 0; } writer.write(voxel + "\n"); } writer.close(); addFileToProductsList(selectedFile); } catch (Exception ex) { showErrorDialog(ex); } finally { try { if (writer != null) { writer.close(); } } catch (IOException ex) { showErrorDialog(ex); } } } editingFrameOpened = false; } }); } @Override public void windowGainedFocus(com.jogamp.newt.event.WindowEvent we) { viewer3D.setIsFocused(true); Platform.runLater(new Runnable() { @Override public void run() { if (!toolBarFrameStage.isShowing()) { toolBarFrameStage.toFront(); } toolBarFrameStage.setIconified(false); toolBarFrameStage.setAlwaysOnTop(true); toolBarFrameStage.setX(viewer3D.getPosition().getX()); toolBarFrameStage.setY(viewer3D.getPosition().getY()); } }); } @Override public void windowLostFocus(com.jogamp.newt.event.WindowEvent e) { viewer3D.setIsFocused(false); Platform.runLater(new Runnable() { @Override public void run() { if (!toolBarFrameStage.focusedProperty().get()) { toolBarFrameStage.setIconified(true); toolBarFrameStage.setAlwaysOnTop(false); } } }); } }); viewer3D.show(); toolBarFrameStage.setAlwaysOnTop(true); } catch (IOException e) { showErrorDialog(new Exception("Loading ToolBarFrame.fxml failed", e)); } catch (Exception e) { showErrorDialog(new Exception("Error occured during toolbar init", e)); } } }); return null; } }; } }; ProgressDialog d = new ProgressDialog(s); d.show(); s.start(); } catch (Exception ex) { showErrorDialog(new Exception("Cannot launch 3d view", ex)); } }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param iNumZone numro de la zone/*w w w .jav a2s .c o m*/ * @param points liste de points du polygone * @return ancres du polygone */ private static ObservableList<AncreForme> olCreeAncresPourPolygone(int iNumZone, final ObservableList<Double> points) { ObservableList<AncreForme> olAnchors = FXCollections.observableArrayList(); for (int i = 0; i < points.size(); i += 2) { final int idx = i; DoubleProperty xProperty = new SimpleDoubleProperty(points.get(i)); DoubleProperty yProperty = new SimpleDoubleProperty(points.get(i + 1)); xProperty.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> { points.set(idx, (double) x); String chaine = ""; chaine = points.stream().map((point) -> point.toString() + ",").reduce(chaine, String::concat); chaine = chaine.substring(0, chaine.length() - 1); zones[iNumZone].setStrCoordonneesZone(chaine); }); yProperty.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> { points.set(idx + 1, (double) y); String chaine = ""; chaine = points.stream().map((point) -> point.toString() + ",").reduce(chaine, String::concat); chaine = chaine.substring(0, chaine.length() - 1); zones[iNumZone].setStrCoordonneesZone(chaine); }); olAnchors.add(new AncreForme(Color.GOLD, xProperty, yProperty)); } return olAnchors; }