List of usage examples for java.beans PropertyChangeListener PropertyChangeListener
PropertyChangeListener
From source file:org.gtdfree.GTDFree.java
private JCheckBoxMenuItem getShowTrayIconMenuItem() { if (showTrayIcon == null) { showTrayIcon = new JCheckBoxMenuItem(getActionMap().get(GlobalProperties.SHOW_TRAY_ICON)); showTrayIcon.setSelected(getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_TRAY_ICON)); getEngine().getGlobalProperties().addPropertyChangeListener(GlobalProperties.SHOW_TRAY_ICON, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { showTrayIcon.setSelected( getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_TRAY_ICON)); }/*from w w w .j a v a 2 s. c o m*/ }); } return showTrayIcon; }
From source file:org.jspresso.framework.model.component.basic.AbstractComponentInvocationHandler.java
private PropertyChangeListener createOrGetFakePcl() { if (fakePcl == null) { fakePcl = new PropertyChangeListener() { @Override/* w w w . j a v a 2 s . c o m*/ public void propertyChange(PropertyChangeEvent evt) { // It's fake } }; } return fakePcl; }
From source file:de.bfs.radon.omsimulation.gui.OMPanelSimulation.java
/** * Initialises the interface of the simulation panel. *///from w w w . j ava 2 s.c o m protected void initialize() { setLayout(null); btnStart = new JButton("Start"); btnStart.addActionListener(this); btnStart.setBounds(616, 326, 124, 23); btnStart.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(btnStart); progressBarSimulation = new JProgressBar(); progressBarSimulation.setBounds(10, 475, 730, 23); progressBarSimulation.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); progressBarSimulation.setVisible(false); add(progressBarSimulation); lblSelectOmbfile = new JLabel("Open OMB-File"); lblSelectOmbfile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectOmbfile.setBounds(10, 36, 132, 14); add(lblSelectOmbfile); lblOmsFile = new JLabel("Save OMS-File"); lblOmsFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblOmsFile.setBounds(174, 272, 120, 14); add(lblOmsFile); txtOmsFile = new JTextField(); txtOmsFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmsFile(txtOmsFile.getText()); } }); txtOmsFile.setBounds(304, 269, 302, 20); txtOmsFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(txtOmsFile); txtOmsFile.setColumns(10); btnBrowseOms = new JButton("Browse"); btnBrowseOms.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.oms", "oms")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String oms; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("oms")) { oms = ""; } else { oms = ".oms"; } txtOmsFile.setText(file.getAbsolutePath() + oms); setOmsFile(file.getAbsolutePath() + oms); } } }); btnBrowseOms.setBounds(616, 268, 124, 23); btnBrowseOms.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(btnBrowseOms); lblWarning = new JLabel("This could take a while, grab a coffee!"); lblWarning.setBounds(421, 94, 319, 15); lblWarning.setForeground(new Color(255, 0, 0, 255)); lblWarning.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblWarning); lblSelectProject = new JLabel("Select Project"); lblSelectProject.setBounds(10, 65, 132, 14); lblSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblSelectProject); lblSimulationType = new JLabel("Simulation Type"); lblSimulationType.setBounds(10, 94, 132, 14); lblSimulationType.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblSimulationType); lblCampaigns = new JLabel("campaigns"); lblCampaigns.setBounds(421, 122, 185, 14); lblCampaigns.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblCampaigns); lblRatio = new JLabel("Ratio"); lblRatio.setBounds(174, 152, 44, 14); lblRatio.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblRatio); lblPercent = new JLabel("%"); lblPercent.setBounds(246, 302, 360, 14); lblPercent.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(lblPercent); spnrRandomCampaigns = new JSpinner(); spnrRandomCampaigns.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { setRandomCampaigns((Integer) spnrRandomCampaigns.getValue()); } }); spnrRandomCampaigns.setModel(new SpinnerNumberModel(10000, 10, 100000, 1)); spnrRandomCampaigns.setBounds(304, 119, 107, 22); spnrRandomCampaigns.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRandomCampaigns); spnrRatio3 = new JSpinner(); spnrRatio3.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio3.isSelected()) { setRatio3((Integer) spnrRatio3.getValue()); } else { setRatio3(0); spnrRatio3.setEnabled(false); } } }); spnrRatio3.setModel(new SpinnerNumberModel(2, 0, 10000, 1)); spnrRatio3.setBounds(330, 149, 81, 22); spnrRatio3.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio3); spnrRatio4 = new JSpinner(); spnrRatio4.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio4.isSelected()) { setRatio4((Integer) spnrRatio4.getValue()); } else { setRatio4(0); spnrRatio4.setEnabled(false); } } }); spnrRatio4.setModel(new SpinnerNumberModel(5, 0, 10000, 1)); spnrRatio4.setBounds(330, 179, 81, 22); spnrRatio4.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio4); spnrRatio5 = new JSpinner(); spnrRatio5.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio5.isSelected()) { setRatio5((Integer) spnrRatio5.getValue()); } else { setRatio5(0); spnrRatio5.setEnabled(false); } } }); spnrRatio5.setModel(new SpinnerNumberModel(20, 0, 10000, 1)); spnrRatio5.setBounds(330, 209, 81, 22); spnrRatio5.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio5); spnrRatio6 = new JSpinner(); spnrRatio6.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRatio6.isSelected()) { setRatio6((Integer) spnrRatio6.getValue()); } else { setRatio6(0); spnrRatio6.setEnabled(false); } } }); spnrRatio6.setModel(new SpinnerNumberModel(73, 0, 10000, 1)); spnrRatio6.setBounds(330, 239, 81, 22); spnrRatio6.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRatio6); spnrRandomNoise = new JSpinner(); spnrRandomNoise.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (chckbxRandomNoise.isSelected()) { setRandomNoise((Integer) spnrRandomNoise.getValue()); } else { setRandomNoise(0); spnrRandomNoise.setEnabled(false); } } }); spnrRandomNoise.setModel(new SpinnerNumberModel(5, 0, 20, 1)); spnrRandomNoise.setBounds(153, 299, 83, 22); spnrRandomNoise.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(spnrRandomNoise); chckbxRatio3 = new JCheckBox("3 of 6"); chckbxRatio3.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio3.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio3.setEnabled(true); } } else { setRatio3(0); spnrRatio3.setEnabled(false); } } }); chckbxRatio3.setBounds(237, 149, 80, 23); chckbxRatio3.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio3); chckbxRatio4 = new JCheckBox("4 of 6"); chckbxRatio4.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio4.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio4.setEnabled(true); } } else { setRatio4(0); spnrRatio4.setEnabled(false); } } }); chckbxRatio4.setBounds(237, 179, 80, 23); chckbxRatio4.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio4); chckbxRatio5 = new JCheckBox("5 of 6"); chckbxRatio5.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio5.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio5.setEnabled(true); } } else { setRatio5(0); spnrRatio5.setEnabled(false); } } }); chckbxRatio5.setBounds(237, 209, 80, 23); chckbxRatio5.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio5); chckbxRatio6 = new JCheckBox("6 of 6"); chckbxRatio6.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRatio6.isSelected()) { if (rdbtnRandom.isSelected()) { spnrRatio6.setEnabled(true); } } else { setRatio6(0); spnrRatio6.setEnabled(false); } } }); chckbxRatio6.setBounds(237, 239, 80, 23); chckbxRatio6.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRatio6); chckbxRandomNoise = new JCheckBox("Random noise"); chckbxRandomNoise.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (chckbxRandomNoise.isSelected()) { if (chckbxRandomNoise.isEnabled()) { spnrRandomNoise.setEnabled(true); } } else { setRandomNoise(0); spnrRandomNoise.setEnabled(false); } } }); chckbxRandomNoise.setBounds(10, 299, 137, 23); chckbxRandomNoise.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(chckbxRandomNoise); btnRefresh = new JButton("Load"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("") && !txtOmbFile.getText().equals(" ")) { txtOmbFile.setBackground(Color.WHITE); String ombPath = txtOmbFile.getText(); String omb; String[] tmpFileName = ombPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(ombPath + omb); setOmbFile(ombPath + omb); File ombFile = new File(ombPath + omb); if (ombFile.exists()) { txtOmbFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxSelectProject.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); progressBarSimulation.setVisible(true); progressBarSimulation.setStringPainted(true); progressBarSimulation.setIndeterminate(true); refreshTask = new Refresh(); refreshTask.execute(); } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); btnRefresh.setBounds(616, 61, 124, 23); btnRefresh.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(btnRefresh); lblHelp = new JLabel( "Select an OMB-Object file to run simulations. Limited random simulations can be saved as OMS-Simulation files used for analysis."); lblHelp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblHelp.setForeground(Color.GRAY); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); txtOmbFile = new JTextField(); txtOmbFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); txtOmbFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmbFile(txtOmbFile.getText()); } }); txtOmbFile.setBounds(152, 33, 454, 20); add(txtOmbFile); txtOmbFile.setColumns(10); btnBrowseOmb = new JButton("Browse"); btnBrowseOmb.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnBrowseOmb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String omb; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(file.getAbsolutePath() + omb); setOmbFile(file.getAbsolutePath() + omb); } } }); btnBrowseOmb.setBounds(616, 32, 124, 23); add(btnBrowseOmb); rdbtnSystematic = new JRadioButton("Systematic all campaigns"); rdbtnSystematic.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (rdbtnSystematic.isSelected()) { setSystematic(true); rdbtnRandom.setSelected(false); chckbxRatio6.setEnabled(false); chckbxRatio5.setEnabled(false); chckbxRatio4.setEnabled(false); chckbxRatio3.setEnabled(false); spnrRatio6.setEnabled(false); spnrRatio5.setEnabled(false); spnrRatio4.setEnabled(false); spnrRatio3.setEnabled(false); spnrRandomCampaigns.setEnabled(false); lblRatio.setEnabled(false); lblCampaigns.setEnabled(false); lblOmsFile.setEnabled(false); lblWarning.setVisible(true); txtOmsFile.setEnabled(false); btnBrowseOms.setEnabled(false); } else { setSystematic(false); rdbtnRandom.setSelected(true); } } }); rdbtnSystematic.setBounds(152, 90, 259, 23); rdbtnSystematic.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(rdbtnSystematic); rdbtnRandom = new JRadioButton("Random"); rdbtnRandom.setSelected(true); rdbtnRandom.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (rdbtnRandom.isSelected()) { setSystematic(false); rdbtnSystematic.setSelected(false); chckbxRatio6.setEnabled(true); chckbxRatio5.setEnabled(true); chckbxRatio4.setEnabled(true); chckbxRatio3.setEnabled(true); spnrRandomCampaigns.setEnabled(true); lblRatio.setEnabled(true); lblCampaigns.setEnabled(true); lblOmsFile.setEnabled(true); lblWarning.setVisible(false); txtOmsFile.setEnabled(true); btnBrowseOms.setEnabled(true); } else { setSystematic(true); rdbtnSystematic.setSelected(true); } } }); rdbtnRandom.setBounds(152, 119, 142, 23); rdbtnRandom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(rdbtnRandom); comboBoxSelectProject = new JComboBox<OMBuilding>(); comboBoxSelectProject.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { boolean b = false; if (comboBoxSelectProject.isEnabled()) { if (comboBoxSelectProject.getSelectedItem() != null) { b = true; setSelectedObject((OMBuilding) comboBoxSelectProject.getSelectedItem()); setProjectName(getSelectedObject().getName()); } else { b = false; } } else { b = false; } progressBarSimulation.setEnabled(b); btnStart.setEnabled(b); chckbxRandomNoise.setEnabled(b); rdbtnRandom.setEnabled(b); rdbtnSystematic.setEnabled(b); lblPercent.setEnabled(b); lblRatio.setEnabled(b); lblSimulationType.setEnabled(b); lblCampaigns.setEnabled(b); } }); comboBoxSelectProject.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { boolean b = false; if (comboBoxSelectProject.isEnabled()) { if (comboBoxSelectProject.getSelectedItem() != null) { b = true; setSelectedObject((OMBuilding) comboBoxSelectProject.getSelectedItem()); setProjectName(getSelectedObject().getName()); } else { b = false; } } else { b = false; } progressBarSimulation.setEnabled(b); btnStart.setEnabled(b); chckbxRandomNoise.setEnabled(b); rdbtnRandom.setEnabled(b); rdbtnSystematic.setEnabled(b); lblPercent.setEnabled(b); lblRatio.setEnabled(b); lblSimulationType.setEnabled(b); lblCampaigns.setEnabled(b); } }); comboBoxSelectProject.setBounds(152, 61, 454, 22); comboBoxSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); add(comboBoxSelectProject); btnStart.setEnabled(false); chckbxRandomNoise.setEnabled(false); chckbxRatio6.setEnabled(false); chckbxRatio5.setEnabled(false); chckbxRatio4.setEnabled(false); chckbxRatio3.setEnabled(false); spnrRandomNoise.setEnabled(false); spnrRatio6.setEnabled(false); spnrRatio5.setEnabled(false); spnrRatio4.setEnabled(false); spnrRatio3.setEnabled(false); spnrRandomCampaigns.setEnabled(false); rdbtnRandom.setEnabled(false); rdbtnSystematic.setEnabled(false); lblPercent.setEnabled(false); lblRatio.setEnabled(false); lblSimulationType.setEnabled(false); lblCampaigns.setEnabled(false); lblOmsFile.setEnabled(false); txtOmsFile.setEnabled(false); btnBrowseOms.setEnabled(false); spnrRatio6.setValue(73); spnrRatio5.setValue(20); spnrRatio4.setValue(5); spnrRatio3.setValue(2); spnrRandomNoise.setValue(5); lblWarning.setVisible(false); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewerComponent.java
/** * Implemented as specified by the {@link TreeViewer} interface. * @see TreeViewer#handleSplitImage(Map, Object, int) *//*from w ww.jav a 2 s . c om*/ public void handleSplitImage(ImageCheckerResult result, final Object action, ImageCheckerType index) { if (!CollectionUtils.isEmpty(result.getMifResults())) { //Indicate what do depending on the index. MIFNotificationDialog dialog = new MIFNotificationDialog(view, result.getMifResults(), action, index, TreeViewerAgent.getAvailableUserGroups()); dialog.addPropertyChangeListener(new PropertyChangeListener() { /** * Moves the data. */ public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (MIFNotificationDialog.MOVE_ALL_PROPERTY.equals(name)) { moveObject((ChgrpObject) evt.getNewValue()); } } }); UIUtilities.centerAndShow(dialog); return; } // show a warning if the images to be deleted are linked to multiple datasets: if (ImageCheckerType.DELETE.equals(index) && !result.getMultiLinkedImages().isEmpty()) { LinkNotificationDialog dialog = new LinkNotificationDialog(view, result); dialog.addPropertyChangeListener(new PropertyChangeListener() { /** * Removes the data */ public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (LinkNotificationDialog.DELETE_PROPERTY.equals(name)) { delete((List) action); } } }); UIUtilities.centerAndShow(dialog); return; } if (ImageCheckerType.DELETE.equals(index)) { delete((List) action); } else if (ImageCheckerType.CHGRP.equals(index)) { moveObject((ChgrpObject) action); } }
From source file:edu.ku.brc.specify.dbsupport.SpecifySchemaUpdateService.java
/** * Changes all the contents of the Geography 'Name' field from the geonames 'name' to 'acsiiname' to * get rid of the unprintable ascii characters. *///from w w w. j a v a2s . c o m public void updateGeographyNames() { final String FIXED_GEO = "FIXED.GEOGRAPHY"; if (AppPreferences.getGlobalPrefs().getBoolean(FIXED_GEO, false)) { //return; } String sql = String.format( "SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = 'geoname'", DBConnection.getInstance().getDatabaseName()); if (BasicSQLUtils.getCount(sql) == 0) { AppPreferences.getGlobalPrefs().putBoolean(FIXED_GEO, true); return; } final int numRecs = BasicSQLUtils.getCountAsInt( "SELECT COUNT(*) FROM geoname ge INNER JOIN geography g ON ge.name = g.Name WHERE ge.Name <> ge.asciiname"); if (BasicSQLUtils.getCount(sql) == 0) { AppPreferences.getGlobalPrefs().putBoolean(FIXED_GEO, true); return; } final ProgressFrame prefProgFrame = new ProgressFrame(getResourceString("UPDATE_SCHEMA_TITLE")); prefProgFrame.adjustProgressFrame(); prefProgFrame.getCloseBtn().setVisible(false); prefProgFrame.getProcessProgress().setIndeterminate(true); prefProgFrame.setDesc(UIRegistry.getLocalizedMessage("UPDATE_GEO")); UIHelper.centerAndShow(prefProgFrame); prefProgFrame.setProcess(0, 100); SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() { @Override protected Boolean doInBackground() throws Exception { Statement stmt = null; PreparedStatement pStmt = null; try { Connection currDBConn = DBConnection.getInstance().getConnection(); pStmt = currDBConn.prepareStatement("UPDATE geography SET Name=? WHERE GeographyID=?"); stmt = currDBConn.createStatement(); int cnt = 0; String sqlStr = "SELECT ge.asciiname, g.GeographyID FROM geoname ge INNER JOIN geography g ON ge.name = g.Name WHERE ge.Name <> ge.asciiname"; ResultSet rs = stmt.executeQuery(sqlStr); while (rs.next()) { pStmt.setString(1, rs.getString(1)); pStmt.setInt(2, rs.getInt(2)); if (pStmt.executeUpdate() != 1) { } cnt++; if (prefProgFrame != null && cnt % 100 == 0) { setProgress((int) (cnt / numRecs * 100.0)); } } rs.close(); if (prefProgFrame != null) { prefProgFrame.setProcess(numRecs); } AppPreferences.getGlobalPrefs().putBoolean(FIXED_GEO, true); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BuildFromGeonames.class, ex); } finally { try { if (stmt != null) { stmt.close(); } if (pStmt != null) { pStmt.close(); } } catch (Exception ex) { ex.printStackTrace(); } } return true; } /* (non-Javadoc) * @see javax.swing.SwingWorker#done() */ @Override protected void done() { super.done(); prefProgFrame.setVisible(false); prefProgFrame.dispose(); } }; worker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { prefProgFrame.setProcess((Integer) evt.getNewValue()); } } }); worker.execute(); }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
private void editVoxelSpace(final File voxelFile) { if (editingFrameOpened) { return;/* ww w . j a v a2 s.c om*/ } 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)); } }