List of usage examples for java.awt Point getY
public double getY()
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Translates a panel (component) location to a Java2D point. * // w w w.j a v a2 s.c o m * @param screenPoint * the screen location (<code>null</code> not permitted). * * @return The Java2D coordinates. */ @Override public Point2D translateScreenToJava2D(Point screenPoint) { Insets insets = getInsets(); double x = (screenPoint.getX() - insets.left) / this.scaleX; double y = (screenPoint.getY() - insets.top) / this.scaleY; return new Point2D.Double(x, y); }
From source file:org.pmedv.blackboard.components.BoardEditor.java
/** * Setup the listeners/* w ww. ja v a 2 s . c om*/ */ private void initListeners() { addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { handleMouseDragged(e); } @Override public void mouseMoved(MouseEvent e) { Point p = e.getPoint(); p = BoardUtil.mirrorTransform(p, zoomLayer, e); if (editorMode.equals(EditorMode.CHECK_CONNECTIONS)) { mouseOverLine = EditorUtils.findMouseOverLine(e, BoardEditor.this); } else { mouseOverPin = EditorUtils.findPin(e.getX(), e.getY(), BoardEditor.this); } win.getCustomLabel().setText("x : " + e.getX() + " y : " + e.getY()); if (mouseOverPin != null) { tooltipBuffer.delete(0, tooltipBuffer.length()); tooltipBuffer.append(mouseOverPin.getNum()); if (mouseOverPin.getName() != null) { tooltipBuffer.append(" " + mouseOverPin.getName()); } BoardEditor.this.setToolTipText(tooltipBuffer.toString()); ToolTipManager.sharedInstance() .mouseMoved(new MouseEvent(BoardEditor.this, 0, 0, 0, (int) p.getX(), (int) p.getY(), // X-Y of the mouse for the tool tip 0, false)); } else if (mouseOverLine != null) { tooltipBuffer.delete(0, tooltipBuffer.length()); tooltipBuffer.append("net : " + mouseOverLine.getNetIndex()); BoardEditor.this.setToolTipText(tooltipBuffer.toString()); ToolTipManager.sharedInstance() .mouseMoved(new MouseEvent(BoardEditor.this, 0, 0, 0, (int) p.getX(), (int) p.getY(), // X-Y of the mouse for the tool tip 0, false)); } else { BoardEditor.this.setToolTipText(null); } } }); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { handleMousePressed(e); } @Override public void mouseReleased(MouseEvent e) { handleMouseReleased(e); } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { Boolean invertMouse = (Boolean) Preferences.values .get("org.pmedv.blackboard.BoardDesignerPerspective.invertMouse"); if (invertMouse) { if (currentZoomIndex - e.getWheelRotation() < zoomLevels.length && currentZoomIndex - e.getWheelRotation() > 0) { currentZoomIndex -= e.getWheelRotation(); } } else { if (currentZoomIndex + e.getWheelRotation() < zoomLevels.length && currentZoomIndex + e.getWheelRotation() > 0) { currentZoomIndex += e.getWheelRotation(); } } JXLayer<?> layer = getZoomLayer(); TransformUI ui = (TransformUI) (Object) layer.getUI(); DefaultTransformModel model = (DefaultTransformModel) ui.getModel(); model.setScale(zoomLevels[currentZoomIndex]); ctx.getBean(ApplicationWindow.class).getZoomCombo().setSelectedItem(zoomLevels[currentZoomIndex]); } }); addMouseMotionListener(AppContext.getContext().getBean(AddTextCommand.class)); }
From source file:com.redsqirl.workflow.server.Workflow.java
public String aggregateElements(List<String> componentIds, String subworkflowName, Map<String, Entry<String, String>> inputs, Map<String, Entry<String, String>> outputs) throws RemoteException { String error = null;/*from www. j a v a2s .c om*/ Workflow copy = null; // Replace elements by the subworkflow Point positionSuperAction = new Point(0, 0); try { copy = (Workflow) clone(); } catch (Exception e) { error = "Fail to clone the workflow"; logger.error(error, e); return error; } // Remove elements that are in the SuperAction logger.debug("Elements before aggregating: " + getComponentIds()); try { Iterator<String> itToDel = componentIds.iterator(); while (itToDel.hasNext()) { String id = itToDel.next(); positionSuperAction.move((int) positionSuperAction.getX() + getElement(id).getX(), (int) positionSuperAction.getY() + getElement(id).getY()); removeElement(id); } } catch (Exception e) { error = "Fail to remove an element"; logger.error(error, e); return error; } // Calculate the position of the new SuperAction positionSuperAction.move((int) positionSuperAction.getX() / componentIds.size(), (int) positionSuperAction.getY() / componentIds.size()); // Add the new element String idSA = null; try { idSA = addElement(subworkflowName); } catch (Exception e) { error = "Fail to create the super action " + subworkflowName; logger.error(error, e); return error; } // Add the new input links DataFlowElement newSA = getElement(idSA); newSA.setPosition((int) positionSuperAction.getX(), (int) positionSuperAction.getY()); logger.debug("Elements after aggregating: " + getComponentIds()); Iterator<String> entries = inputs.keySet().iterator(); while (entries.hasNext() && error == null) { String inputName = entries.next(); if (logger.isDebugEnabled()) { logger.debug("link " + inputs.get(inputName).getKey() + "," + inputs.get(inputName).getValue() + "->" + inputName + "," + idSA); } error = addLink(inputs.get(inputName).getValue(), inputs.get(inputName).getKey(), inputName, idSA); } // Add the new output links logger.debug("Old elements: " + copy.getComponentIds()); entries = outputs.keySet().iterator(); while (entries.hasNext() && error == null) { String outputName = entries.next(); logger.debug( "Get element " + outputs.get(outputName).getKey() + "," + outputs.get(outputName).getValue()); Map<String, List<DataFlowElement>> outEls = copy.getElement(outputs.get(outputName).getKey()) .getOutputComponent(); if (outEls != null && outEls.containsKey(outputs.get(outputName).getValue()) && outEls.get(outputs.get(outputName).getValue()) != null) { Iterator<DataFlowElement> it = outEls.get(outputs.get(outputName).getValue()).iterator(); while (it.hasNext()) { DataFlowElement curEl = it.next(); if (getElement(curEl.getComponentId()) != null) { if (logger.isDebugEnabled()) { logger.debug("link " + outputName + "," + idSA + "->" + copy.getElement(outputs.get(outputName).getKey()).getInputNamePerOutput() .get(outputs.get(outputName).getValue()).get(curEl.getComponentId()) + "," + curEl.getComponentId()); } error = addLink(outputName, idSA, copy.getElement(outputs.get(outputName).getKey()).getInputNamePerOutput() .get(outputs.get(outputName).getValue()).get(curEl.getComponentId()), curEl.getComponentId()); if (error == null) { String newAlias = getElement(curEl.getComponentId()).getAliasesPerComponentInput() .get(idSA).getKey(); String oldAlias = curEl.getAliasesPerComponentInput() .get(outputs.get(outputName).getKey()).getKey(); getElement(curEl.getComponentId()).replaceInAllInteraction( "([_ \\W]|^)(" + Pattern.quote(oldAlias) + ")([_ \\W]|$)", "$1" + newAlias + "$3", true); } } } } } { //Generate name for all the outputs Map<String, DFEOutput> mapOutput = newSA.getDFEOutput(); Iterator<String> outputNameIt = mapOutput.keySet().iterator(); while (outputNameIt.hasNext()) { String dataName = outputNameIt.next(); if (mapOutput.get(dataName).getSavingState() != SavingState.RECORDED && (mapOutput.get(dataName).getPath() == null || !mapOutput.get(dataName).isPathAutoGeneratedForUser(idSA, dataName))) { mapOutput.get(dataName).generatePath(idSA, dataName); } } } if (error != null) { this.element = copy.element; } return error; }
From source file:unikn.dbis.univis.navigation.tree.VTree.java
/** * TODO: document me!!!/* w w w.java 2 s .c o m*/ * * @param p */ public void showPopupMenu(Point p) { // Remove all items from popup menu. popupMenu.removeAll(); Object o = getLastSelectedPathComponent(); if (o instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) o; Object userObject = node.getUserObject(); if (userObject instanceof VDimension) { VDimension dimension = (VDimension) userObject; try { Point p2 = new Point(p); SwingUtilities.convertPointToScreen(p2, this); final FilterItemContainer container = createFilterContainer(dimension, p2); if (!container.isEmpty()) { /* JLabel header = new JLabel(MessageResolver.getMessage("data_reference." + dimension.getI18nKey())); Font font = header.getFont(); header.setFont(new Font(font.getFontName(), Font.BOLD, font.getSize() + 2)); popupMenu.add(header); popupMenu.add(new JPopupMenu.Separator()); */ popupMenu = new FilterPopupMenu( MessageResolver.getMessage("data_reference." + dimension.getI18nKey())); final JCheckBox button = new JCheckBox("Check/Uncheck all"); button.setSelected(container.isAllChecked()); button.addActionListener(new ActionListener() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { for (Component c : container.getComponents()) { if (c instanceof VBidirectionalBrowsingItem) { ((VBidirectionalBrowsingItem) c).getCheckBox() .setChecked(button.isSelected()); } } } }); popupMenu.add(button); popupMenu.add(new JPopupMenu.Separator()); popupMenu.add(container); JButton view = new JButton(MessageResolver.getMessage("filtering"), VIcons.FILTER); view.addActionListener(new ActionListener() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { popupMenu.setVisible(false); } }); popupMenu.add(new JPopupMenu.Separator()); popupMenu.add(view); popupMenu.show(VTree.this, (int) p.getX(), (int) p.getY()); } else { JOptionPane.showMessageDialog(VTree.this.getParent().getParent().getParent(), MessageResolver.getMessage("no_items_found"), MessageResolver.getMessage("error_message"), JOptionPane.ERROR_MESSAGE); } } catch (SQLException sqle) { VExplorer.publishException(sqle); if (LOG.isErrorEnabled()) { LOG.error(sqle.getMessage(), sqle); } } } } }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private boolean endDragOfElement(final DraggedElement draggedElement, final AbstractElement destination) { final AbstractElement dragged = draggedElement.getElement(); final Point dropPoint = draggedElement.getPosition(); final boolean ignore = dragged.getModel() == destination.getModel() || dragged.getBounds().contains(dropPoint) || destination.getModel().hasAncestor(dragged.getModel()); if (ignore) { return false; }// w w w . j a v a 2 s . c o m boolean changed = true; final AbstractElement destParent = destination.getParent(); if (draggedElement.getModifier() == DraggedElement.Modifier.MAKE_JUMP) { // make link return this.controller.processDropTopicToAnotherTopic(this, dropPoint, dragged.getModel(), destination.getModel()); } final int pos = calcDropPosition(destination, dropPoint); switch (pos) { case DRAG_POSITION_TOP: case DRAG_POSITION_BOTTOM: { dragged.getModel().moveToNewParent(destParent.getModel()); if (pos == DRAG_POSITION_TOP) { dragged.getModel().moveBefore(destination.getModel()); } else { dragged.getModel().moveAfter(destination.getModel()); } if (destination.getClass() == ElementLevelFirst.class) { AbstractCollapsableElement.makeTopicLeftSided(dragged.getModel(), destination.isLeftDirection()); } else { AbstractCollapsableElement.makeTopicLeftSided(dragged.getModel(), false); } } break; case DRAG_POSITION_RIGHT: case DRAG_POSITION_LEFT: { if (dragged.getParent() == destination) { // the same parent if (destination.getClass() == ElementRoot.class) { // process only for the root, just update direction if (dragged instanceof AbstractCollapsableElement) { ((AbstractCollapsableElement) dragged).setLeftDirection(pos == DRAG_POSITION_LEFT); } } } else { dragged.getModel().moveToNewParent(destination.getModel()); if (destination instanceof AbstractCollapsableElement && destination.isCollapsed() && (controller == null ? true : controller.isUnfoldCollapsedTopicDropTarget(this))) { //NOI18N ((AbstractCollapsableElement) destination).setCollapse(false); } if (dropPoint.getY() < destination.getBounds().getY()) { dragged.getModel().makeFirst(); } else { dragged.getModel().makeLast(); } if (destination.getClass() == ElementRoot.class) { AbstractCollapsableElement.makeTopicLeftSided(dragged.getModel(), pos == DRAG_POSITION_LEFT); } else { AbstractCollapsableElement.makeTopicLeftSided(dragged.getModel(), false); } } } break; default: break; } dragged.getModel().setPayload(null); return changed; }
From source file:com.redsqirl.workflow.server.Workflow.java
public SubDataFlow createSA(List<String> componentIds, String subworkflowName, String subworkflowComment, Map<String, Entry<String, String>> inputs, Map<String, Entry<String, String>> outputs) throws Exception { logger.debug("To aggregate: " + componentIds); int posIncr = 150; String error = null;//from w w w . j av a2s. co m // Create subworkflow object SubWorkflow sw = new SubWorkflow(subworkflowName); DataFlowCoordinatorVariables subWfVars = new WfCoordVariables(); // Copy Elements Workflow copy = null; try { copy = (Workflow) clone(); } catch (Exception e) { error = "Fail to clone the workflow"; logger.error(error, e); } if (error == null) { Iterator<String> idIt = copy.getComponentIds().iterator(); try { while (idIt.hasNext()) { String cur = idIt.next(); if (!componentIds.contains(cur)) { logger.debug("To remove: " + cur); copy.removeElement(cur); } else { DataFlowElement curEl = getElement(cur); curEl.cleanDataOut(); //curEl.setPosition(curEl.getX() + posIncr, curEl.getY()); Set<String> varRequired = curEl.getRequiredVariables(); if (varRequired != null && !varRequired.isEmpty()) { DataFlowCoordinatorVariables coordVars = copy.getCoordinator(curEl.getCoordinatorName()) .getVariables(); Iterator<String> varIt = varRequired.iterator(); while (varIt.hasNext()) { String varCur = varIt.next(); subWfVars.addVariable(coordVars.getVariable(varCur)); } } } } } catch (Exception e) { error = "Fail to remove an element"; logger.error(error, e); } } if (error == null) { String coordinatorName = null; Iterator<String> idIt = componentIds.iterator(); while (idIt.hasNext()) { String cur = idIt.next(); DataFlowElement newEl = copy.getElement(cur); logger.debug("To copy: " + cur); if (coordinatorName == null) { coordinatorName = newEl.getCoordinatorName(); } sw.addElement(newEl, coordinatorName); } DataFlowCoordinator coordinatorSW = sw.getCoordinator(coordinatorName); try { // Create Action inputs Iterator<String> entries = inputs.keySet().iterator(); Map<String, DFEOutput> inputsForHelp = new HashMap<String, DFEOutput>(); while (entries.hasNext() && error == null) { String inputName = entries.next(); // Get the DFEOutput from which we copy the constraint DFEOutput constraint = this.getElement(inputs.get(inputName).getKey()).getDFEOutput() .get(inputs.get(inputName).getValue()); inputsForHelp.put(inputName, constraint); sw.addElement((new SubWorkflowInput()).getName(), inputName, coordinatorSW); if (error == null) { // Update Data Type SubWorkflowInput input = (SubWorkflowInput) sw.getElement(inputName); input.update(input.getInteraction(Source.key_datatype)); Tree<String> dataTypeTree = input.getInteraction(Source.key_datatype).getTree(); dataTypeTree.getFirstChild("list").getFirstChild("output").add(constraint.getBrowserName()); logger.debug("Update Data Type"); // Update Data SubType input.update(input.getInteraction(Source.key_datasubtype)); ((ListInteraction) input.getInteraction(Source.key_datasubtype)) .setValue(constraint.getTypeName()); logger.debug("Update Data SubType"); if (PathType.MATERIALIZED.equals(constraint.getPathType())) { List<String> vals = new LinkedList<String>(); vals.add(LanguageManagerWF.getText("superactioninput.allow_materialized")); ((AppendListInteraction) input.getInteraction(SubWorkflowInput.key_materialized)) .setValues(vals); } // Update header input.update(input.getInteraction(SubWorkflowInput.key_headerInt)); InputInteraction header = (InputInteraction) input .getInteraction(SubWorkflowInput.key_headerInt); header.setValue(constraint.getFields().mountStringHeader()); input.update(input.getInteraction(SubWorkflowInput.key_fieldDefInt)); input.updateOut(); logger.debug("Update Out"); Iterator<DataFlowElement> toLinkIt = this.getElement(inputs.get(inputName).getKey()) .getOutputComponent().get(inputs.get(inputName).getValue()).iterator(); Point positionSuperActionInput = new Point(0, 0); int numberOfInput = 0; while (toLinkIt.hasNext()) { DataFlowElement curEl = toLinkIt.next(); if (componentIds.contains(curEl.getComponentId())) { // Create link sw.addLink(SubWorkflowInput.out_name, inputName, getElement(inputs.get(inputName).getKey()).getInputNamePerOutput() .get(inputs.get(inputName).getValue()).get(curEl.getComponentId()), curEl.getComponentId()); String newAlias = sw.getElement(curEl.getComponentId()) .getAliasesPerComponentInput().get(inputName).getKey(); String oldAlias = curEl.getAliasesPerComponentInput() .get(inputs.get(inputName).getKey()).getKey(); sw.getElement(curEl.getComponentId()).replaceInAllInteraction( "([_ \\W]|^)(" + Pattern.quote(oldAlias) + ")([_ \\W]|$)", "$1" + newAlias + "$3", true); positionSuperActionInput.move((int) positionSuperActionInput.getX() + curEl.getX(), (int) positionSuperActionInput.getY() + curEl.getY()); ++numberOfInput; } } input.setPosition((int) (positionSuperActionInput.getX() / numberOfInput) - posIncr, (int) (positionSuperActionInput.getY() / numberOfInput)); } } logger.debug("Create Action"); // Create Action outputs entries = outputs.keySet().iterator(); Map<String, DFEOutput> outputsForHelp = new HashMap<String, DFEOutput>(); while (entries.hasNext() && error == null) { String outputName = entries.next(); sw.addElement((new SubWorkflowOutput()).getName(), outputName, coordinatorSW); if (error == null) { sw.addLink(outputs.get(outputName).getValue(), outputs.get(outputName).getKey(), SubWorkflowOutput.input_name, outputName); DataFlowElement in = sw.getElement(outputs.get(outputName).getKey()); sw.getElement(outputName).setPosition(in.getX() + posIncr, in.getY()); outputsForHelp.put(outputName, in.getDFEOutput().get(outputs.get(outputName).getValue())); } } logger.debug("createSA " + error); sw.getCoordinator(coordinatorName).getVariables().addAll(subWfVars); sw.setComment(generateHelp(RedSqirlModel.getModelAndSW(subworkflowName)[1], subworkflowComment, inputsForHelp, outputsForHelp, subWfVars)); } catch (Exception e) { error = "Fail to create an input or output super action"; logger.error(error, e); } } if (error != null) { throw new Exception(error); } sw.moveToTopRightCorner(50, 50); return sw; }
From source file:op.care.nursingprocess.DlgNursingProcess.java
private void tblPlanungMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPlanungMousePressed if (!SwingUtilities.isRightMouseButton(evt)) { return;//from w ww .j a v a 2s .co m } Point p = evt.getPoint(); ListSelectionModel lsm = tblPlanung.getSelectionModel(); int row = tblPlanung.rowAtPoint(p); if (lsm.isSelectionEmpty() || (lsm.getMinSelectionIndex() == lsm.getMaxSelectionIndex())) { lsm.setSelectionInterval(row, row); } menu = new JPopupMenu(); /*** * _ _ ____ ____ _ _ * (_) |_ ___ _ __ ___ | _ \ ___ _ __ _ _ _ __ | _ \ ___| | ___| |_ ___ * | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \| | | |/ _ \ |/ _ \ __/ _ \ * | | || __/ | | | | | __/ (_) | |_) | |_| | |_) | |_| | __/ | __/ || __/ * |_|\__\___|_| |_| |_|_| \___/| .__/ \__,_| .__/|____/ \___|_|\___|\__\___| * |_| |_| */ JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"), SYSConst.icon22delete); itemPopupDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { for (int row : tblPlanung.getSelectedRows()) { listInterventionSchedule2Remove .add(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row)); nursingProcess.getInterventionSchedule() .remove(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row)); } ((TMPlan) tblPlanung.getModel()).fireTableDataChanged(); } }); menu.add(itemPopupDelete); /*** * _ _ ____ ____ _ _ _ * (_) |_ ___ _ __ ___ | _ \ ___ _ __ _ _ _ __/ ___| ___| |__ ___ __| |_ _| | ___ * | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \___ \ / __| '_ \ / _ \/ _` | | | | |/ _ \ * | | || __/ | | | | | __/ (_) | |_) | |_| | |_) |__) | (__| | | | __/ (_| | |_| | | __/ * |_|\__\___|_| |_| |_|_| \___/| .__/ \__,_| .__/____/ \___|_| |_|\___|\__,_|\__,_|_|\___| * |_| |_| */ final JMenuItem itemPopupSchedule = new JMenuItem(SYSTools.xx("misc.commands.editsheduling"), SYSConst.icon22clock); itemPopupSchedule.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { final JidePopup popup = new JidePopup(); /** * This routine uses the <b>first</b> element of the selection as the template for editing * the schedule. After the edit it clones this "template", removes the original * InterventionSchedules (copying the apropriate Intervention of every single * Schedule first) and finally creates new schedules and adds them to * the CareProcess in question. */ int row = tblPlanung.getSelectedRows()[0]; InterventionSchedule firstInterventionScheduleWillBeTemplate = ((TMPlan) tblPlanung.getModel()) .getInterventionSchedule(row); JPanel dlg = new PnlSchedule(firstInterventionScheduleWillBeTemplate, new Closure() { @Override public void execute(Object o) { if (o != null) { InterventionSchedule template = (InterventionSchedule) o; ArrayList<InterventionSchedule> listInterventionSchedule2Add = new ArrayList(); for (int row : tblPlanung.getSelectedRows()) { InterventionSchedule oldTermin = ((TMPlan) tblPlanung.getModel()) .getInterventionSchedule(row); InterventionSchedule newTermin = template.clone(); newTermin.setIntervention(oldTermin.getIntervention()); listInterventionSchedule2Remove.add(oldTermin); listInterventionSchedule2Add.add(newTermin); } nursingProcess.getInterventionSchedule().removeAll(listInterventionSchedule2Remove); nursingProcess.getInterventionSchedule().addAll(listInterventionSchedule2Add); popup.hidePopup(); Collections.sort(nursingProcess.getInterventionSchedule()); ((TMPlan) tblPlanung.getModel()).fireTableDataChanged(); } } }); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.getContentPane().add(dlg); popup.setOwner(jspPlanung); popup.removeExcludedComponent(jspPlanung); popup.setDefaultFocusComponent(dlg); GUITools.showPopup(popup, SwingConstants.SOUTH_WEST); } }); menu.add(itemPopupSchedule); menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY()); }
From source file:op.care.sysfiles.PnlFiles.java
private void tblFilesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFilesMousePressed Point p = evt.getPoint(); ListSelectionModel lsm = tblFiles.getSelectionModel(); Point p2 = evt.getPoint();//from w w w. j a v a2 s .c om SwingUtilities.convertPointToScreen(p2, tblFiles); final Point screenposition = p2; boolean singleRowSelected = lsm.getMaxSelectionIndex() == lsm.getMinSelectionIndex(); final int row = tblFiles.rowAtPoint(p); final int col = tblFiles.columnAtPoint(p); if (singleRowSelected) { lsm.setSelectionInterval(row, row); } final TMSYSFiles tm = (TMSYSFiles) tblFiles.getModel(); final SYSFiles sysfile = tm.getRow(tblFiles.convertRowIndexToModel(row)); if (SwingUtilities.isRightMouseButton(evt)) { SYSTools.unregisterListeners(menu); menu = new JPopupMenu(); // SELECT JMenuItem itemPopupShow = new JMenuItem(SYSTools.xx("misc.commands.show"), SYSConst.icon22magnify1); itemPopupShow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN); } }); menu.add(itemPopupShow); if (col == TMSYSFiles.COL_DESCRIPTION && OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { final JMenuItem itemPopupEdit = new JMenuItem(SYSTools.xx("misc.commands.edit"), SYSConst.icon22edit3); itemPopupEdit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { final JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane() .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); final JComponent editor = new JTextArea(sysfile.getBeschreibung(), 10, 40); ((JTextArea) editor).setLineWrap(true); ((JTextArea) editor).setWrapStyleWord(true); ((JTextArea) editor).setEditable(true); popup.getContentPane().add(new JScrollPane(editor)); final JButton saveButton = new JButton(SYSConst.icon22apply); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); popup.hidePopup(); SYSFiles mySysfile = em.merge(sysfile); mySysfile.setBeschreibung(((JTextArea) editor).getText().trim()); em.getTransaction().commit(); tm.setSYSFile(tblFiles.convertRowIndexToModel(row), mySysfile); } catch (Exception e) { em.getTransaction().rollback(); OPDE.fatal(e); } finally { em.close(); } } }); saveButton.setHorizontalAlignment(SwingConstants.RIGHT); JPanel pnl = new JPanel(new BorderLayout(10, 10)); JScrollPane pnlEditor = new JScrollPane(editor); pnl.add(pnlEditor, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.add(saveButton); pnl.setBorder(new EmptyBorder(10, 10, 10, 10)); pnl.add(buttonPanel, BorderLayout.SOUTH); popup.setOwner(tblFiles); popup.removeExcludedComponent(tblFiles); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(editor); popup.showPopup(screenposition.x, screenposition.y); } }); menu.add(itemPopupEdit); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) { JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"), SYSConst.icon22delete); itemPopupDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { new DlgYesNo( SYSTools.xx("misc.questions.delete1") + "<br/><b>" + sysfile.getFilename() + "</b><br/>" + SYSTools.xx("misc.questions.delete2"), new ImageIcon(getClass().getResource("/artwork/48x48/bw/trashcan_empty.png")), new Closure() { @Override public void execute(Object o) { if (o.equals(JOptionPane.YES_OPTION)) { SYSFilesTools.deleteFile(sysfile); reloadTable(); } } }); } }); menu.add(itemPopupDelete); itemPopupDelete.setEnabled(singleRowSelected); } menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY()); } else if (evt.getClickCount() == 2) { SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN); } }
From source file:oct.analysis.application.comp.EZWorker.java
@Override protected EZEdgeCoord doInBackground() throws Exception { int foveaCenterXPosition = analysisManager.getFoveaCenterXPosition(); /*/*from www . j a va 2 s. c om*/ first get a sharpened version of the OCT and use that to obtain the segmentation of the Bruch's membrane. Use a Loess interpolation algorithm to smooth out imperfetions in the segmentation line. */ UnivariateInterpolator interpolator = new LoessInterpolator(0.1, 0); ArrayList<Point> rawBrmPoints = new ArrayList<>(analysisManager .getSegmentation(new SharpenOperation(15, 0.5F)).getSegment(Segmentation.BrM_SEGMENT)); double[][] brmSeg = Util.getXYArraysFromPoints(rawBrmPoints); UnivariateFunction brmInterp = interpolator.interpolate(brmSeg[0], brmSeg[1]); BufferedImage sharpOCT = analysisManager.getSharpenedOctImage(8.5D, 1.0F); setProgress(10); /* Starting from the identified location of the fovea search northward in the image until the most northern pixels northward (in a 3x3 matrix of pixels arround the the search point (X,Y) ) are black (ie. the search matrix is has found that the search point isn't totally surrounded by white pixels). Then a recursive search algorithm determines if the black area signifies the seperation between bands or simply represents a closed (a black blob entirely surrounded by white pixels) black band. It will continue searching northward in the image until it can find an open region of all blak pixels. Once this is found it will find the contour of the edge between the black and white pixels along the width of the image. */ int searchY = (int) Math.round(brmInterp.value(foveaCenterXPosition)) + 1; do { searchY--; } while (Util.calculateGrayScaleValue(sharpOCT.getRGB(foveaCenterXPosition, searchY)) > 0 || !isContrastPoint(foveaCenterXPosition, searchY, sharpOCT)); LinkedList<Point> contour = new LinkedList<>(); Point startPoint = new Point(foveaCenterXPosition, searchY); //find contour by searching for white pixel boundary to te right of the fovea contour.add(findContourRight(startPoint, Cardinality.SOUTH, startPoint, Cardinality.SOUTH, contour, sharpOCT, 0)); //search until open black area found (ie. if the search algorithm arrives back at //the starting pixel keep moving north to next black area to search) while (contour.get(0).equals(startPoint)) { contour = new LinkedList<>(); do { searchY--; } while (Util.calculateGrayScaleValue(sharpOCT.getRGB(foveaCenterXPosition, searchY)) == 0); do { searchY--; } while (Util.calculateGrayScaleValue(sharpOCT.getRGB(foveaCenterXPosition, searchY)) > 0 || isSurroundedByWhite(foveaCenterXPosition, searchY, sharpOCT)); startPoint = new Point(foveaCenterXPosition, searchY); contour.add(findContourRight(startPoint, Cardinality.SOUTH, startPoint, Cardinality.SOUTH, contour, sharpOCT, 0)); } setProgress(20); //open balck space found, complete contour to left of fovea contour.add( findContourLeft(startPoint, Cardinality.SOUTH, startPoint, Cardinality.SOUTH, contour, sharpOCT)); analysisManager.getImgPanel().setDrawPoint(new Point(foveaCenterXPosition, searchY)); setProgress(30); /* since the contour can snake around due to aberations and low image density we need to create a single line (represented by points) from left to right to represent the countour. This is easily done by building a line of points consisting of the point with the largest Y value (furthest from the top of the image) at each X value. This eliminates overhangs from the contour line. */ Map<Double, List<Point>> grouped = contour.stream().collect(Collectors.groupingBy(Point::getX)); List<Point> refinedEZContour = grouped.values().stream().map((List<Point> points) -> { int maxY = points.stream().mapToInt((Point p) -> p.y).min().getAsInt(); return new Point(points.get(0).x, maxY); }).sorted((Point p1, Point p2) -> Integer.compare(p1.x, p2.x)).collect(Collectors.toList()); setProgress(35); /* Starting from the identified location of the fovea search southward in the image until the most southern pixels (in a 3x3 matrix of pixels arround the the search point (X,Y) ) are black (ie. the search matrix has found that the search point isn't totally surrounded by white pixels). Then a recursive search algorithm determines if the black area signifies the bottom of the Bruch's membrane or simply represents a closed (a black blob entirely surrounded by white pixels) black band. It will continue searching southward in the image until it can find an open region of all black pixels. Once this is found it will find the contour of the edge between the black and white pixels, along the width of the image, of the bottom of the Bruch's membrane. */ // sharpOCT = getSharpenedOctImage(5D, 1.0F); searchY = (int) Math.round(brmInterp.value(foveaCenterXPosition)); do { searchY++; } while (Util.calculateGrayScaleValue(sharpOCT.getRGB(foveaCenterXPosition, searchY)) > 0 || isSurroundedByWhite(foveaCenterXPosition, searchY, sharpOCT)); contour = new LinkedList<>(); startPoint = new Point(foveaCenterXPosition, searchY); /* Find contour by searching for white pixel boundary to te right of the fovea. Sometimes the crap below the Bruchs membrane causes too much interferance for the algorithm to work properly so we must tweak some of the parameters of the sharpening performed on the image until the algorithm succedes or we can no longer tweak parameters. In the case of the later event we can use the raw segmented Bruchs membrane as a substitute to keep the method from failing. */ contour.add(findContourRight(startPoint, Cardinality.NORTH, startPoint, Cardinality.NORTH, contour, sharpOCT, 0)); double filtValue = 8.5D; boolean tweakFailed = false; while (contour.contains(null)) { contour = new LinkedList<>(); filtValue -= 0.5D; System.out.println("Reducing sigma to " + filtValue); if (filtValue <= 0D) { tweakFailed = true; break; } sharpOCT = analysisManager.getSharpenedOctImage(8.5D, 1.0F); contour.add(findContourRight(startPoint, Cardinality.NORTH, startPoint, Cardinality.NORTH, contour, sharpOCT, 0)); } if (tweakFailed) { contour = new LinkedList<>(rawBrmPoints); } else { //search until open black area found (ie. if the search algorithm arrives back at //the starting pixel keep moving south to next black area to search) while (contour.get(0).equals(startPoint)) { contour = new LinkedList<>(); do { searchY++; } while (Util.calculateGrayScaleValue(sharpOCT.getRGB(foveaCenterXPosition, searchY)) == 0); do { searchY++; } while (Util.calculateGrayScaleValue(sharpOCT.getRGB(foveaCenterXPosition, searchY)) > 0 || isSurroundedByWhite(foveaCenterXPosition, searchY, sharpOCT)); startPoint = new Point(foveaCenterXPosition, searchY); contour.add(findContourRight(startPoint, Cardinality.NORTH, startPoint, Cardinality.NORTH, contour, sharpOCT, 0)); } setProgress(45); //open balck space found, complete contour to left of fovea contour.add(findContourLeft(startPoint, Cardinality.NORTH, startPoint, Cardinality.NORTH, contour, sharpOCT)); } setProgress(55); /* since the contour can snake around due to aberations and low image density we need to create a single line (represented by points) from left to right to represent the countour. This is easily done by building a line of points consisting of the point with the smallest Y value (closest to the top of the image) at each X value. This eliminates overhangs from the contour line. */ grouped = contour.stream().collect(Collectors.groupingBy(Point::getX)); List<Point> refinedBruchsMembraneContour = grouped.values().stream().map((List<Point> points) -> { int minY = points.stream().mapToInt((Point p) -> p.y).min().getAsInt(); return new Point(points.get(0).x, minY); }).sorted((Point p1, Point p2) -> Integer.compare(p1.x, p2.x)).collect(Collectors.toList()); setProgress(70); /* use a Loess interpolator again to smooth the new contours of the EZ and Bruch's Membrane */ double[][] refinedContourPoints = Util.getXYArraysFromPoints(refinedEZContour); UnivariateFunction interpEZContour = interpolator.interpolate(refinedContourPoints[0], refinedContourPoints[1]); refinedContourPoints = Util.getXYArraysFromPoints(refinedBruchsMembraneContour); UnivariateFunction interpBruchsContour = interpolator.interpolate(refinedContourPoints[0], refinedContourPoints[1]); /* find the average difference in the distance in the Y between the 10 pixels at each end of the Bruch's Membrane contour and the contour created along the top of the EZ. */ //since the lines are sorted on X position it is easy to align the lines //based on the tails of each line int minX = refinedEZContour.get(0).x; int maxX; //the interpolator can shorten the range of the X values from the original supplied //so we need to test where the end of the range occurs since it isn't directly accessible for (maxX = refinedEZContour.get(refinedEZContour.size() - 1).x; maxX > minX; maxX--) { try { double tmp = interpEZContour.value(maxX) - interpBruchsContour.value(maxX); //if this break is reached we have found the max value the interpolators will allow break; } catch (OutOfRangeException oe) { //do nothing but let loop continue } } double avgDif = Stream .concat(IntStream.range(minX + 30, minX + 50).boxed(), IntStream.range(maxX - 49, maxX - 28).boxed()) .mapToDouble(x -> interpBruchsContour.value(x) - interpEZContour.value(x)).average().getAsDouble(); int height = sharpOCT.getHeight();//make to use in lambda expression List<LinePoint> ezLine = IntStream.rangeClosed(minX, maxX) .mapToObj(x -> new LinePoint(x, height - interpEZContour.value(x) - avgDif)) .collect(Collectors.toList()); List<LinePoint> bmLine = IntStream.rangeClosed(minX, maxX) .mapToObj(x -> new LinePoint(x, height - interpBruchsContour.value(x))) .collect(Collectors.toList()); List<LinePoint> bmUnfiltLine = refinedBruchsMembraneContour.stream() .map((Point p) -> new LinePoint(p.x, height - p.getY())).collect(Collectors.toList()); Util.graphPoints(ezLine, bmLine, bmUnfiltLine); analysisManager.getImgPanel().setDrawnLines( IntStream.rangeClosed(minX, maxX).mapToObj(x -> new LinePoint(x, interpEZContour.value(x))) .collect(Collectors.toList()), IntStream.rangeClosed(minX, maxX).mapToObj(x -> new LinePoint(x, interpBruchsContour.value(x))) .collect(Collectors.toList())); /* Find the difference between the two contours (Bruch's membrane and the EZ + Bruch's membrane) and use this to determine where the edge of the EZ is */ List<LinePoint> diffLine = findDiffWithAdjustment(interpBruchsContour, 0D, interpEZContour, avgDif, minX, maxX); setProgress(90); // List<LinePoint> peaks = Util.findPeaksAndVallies(diffLine); // Util.graphPoints(diffLine, peaks); /* Find the first zero crossings of the difference line on both sides of the fovea. If a zero crossing can't be found then search for the first crossing of a value of 1, then 2, then 3, etc. until an X coordinate of a crossing is found on each side of the fovea. */ OptionalInt ezLeftEdge; double crossingThreshold = 0.25D; do { double filtThresh = crossingThreshold; System.out.println("Crossing threshold = " + crossingThreshold); ezLeftEdge = diffLine.stream().filter(lp -> lp.getY() <= filtThresh && lp.getX() < foveaCenterXPosition) .mapToInt(LinePoint::getX).max(); crossingThreshold += 0.25D; } while (!ezLeftEdge.isPresent()); OptionalInt ezRightEdge; crossingThreshold = 0.25D; do { double filtThresh = crossingThreshold; System.out.println("Crossing threshold = " + crossingThreshold); ezRightEdge = diffLine.stream() .filter(lp -> lp.getY() <= filtThresh && lp.getX() > foveaCenterXPosition) .mapToInt(LinePoint::getX).min(); crossingThreshold += 0.25D; } while (!ezRightEdge.isPresent()); //return findings return new EZEdgeCoord(ezLeftEdge.getAsInt(), ezRightEdge.getAsInt()); }