package osp.ui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.File; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Observable; import java.util.Observer; import javax.media.jai.PlanarImage; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JProgressBar; import javax.swing.JSlider; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.border.LineBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.omg.CosNaming._NamingContextImplBase; import nom.tam.fits.FitsException; import jsky.catalog.gui.CatalogNavigator; import jsky.coords.DMS; import jsky.coords.HMS; import jsky.coords.WorldCoords; import jsky.graphics.CanvasFigure; import jsky.image.graphics.DivaImageGraphics; import jsky.image.gui.ImageColorbar; import jsky.image.gui.ImageCoordinateConverter; import jsky.image.gui.ImageDisplayMenuBar; import jsky.image.gui.ImagePanner; import jsky.image.gui.ImageZoom; import jsky.util.gui.ExampleFileFilter; import osp.Detector; import osp.FieldOfView; import osp.Image; import osp.InstrumentParameters; import osp.Mask; import osp.MaskHistoryEntry; import osp.SkyObject; import osp.Slit; import osp.Writer; import osp.utils.CustomJDialog; import osp.utils.FileUtil; import osp.utils.SearchWindow; import osp.utils.TableurModel; import osp.utils.TableurPanel; /** * Right panel of MainFrame. Use to visualize image, choosing the reference * objects, positioning the mask and evaluating the slits positions. * */ public class OSPE_VisuPanel extends JPanel implements Observer, VisuPanelNavigatorInterface, OSPE_VisuPanelInterface { private static final long serialVersionUID = 1L; private StatusInterface statusInterface; private JLabel projectLabel; private JPanel selectionSlitPanel; private ImagePanner imagePanner; private ImageZoom imageZoom; private JButton jButtonUnUn; private JButton jButtonZoomPlus; private JButton jButtonZoomMoins; public JComboBox slitCombo; private JButton jButtonMoveZoom; public JSlider slide_position; public JSlider slide_aperture; private OSPE_SlitPropPanel slitPropertiesPanel; private JPanel imagePanel; private OSPE_NavigatorImageDisplay navigatorImageDisplay; private DivaImageGraphics divaImageGraphics; private OSPE_ImageCutLevelsDialog imCutDialog; private OSPE_ImageColorsDialog imColorsDialog; private ImageColorbar imColorBar; private JLabel jLabelDisplay; public JLabel jLabelFovSize; public JButton searchButton; public JButton validateButton; public JButton writeButton; public JProgressBar jpgb; protected FieldOfView fov; private JSpinner spinZoom; private OspeControl ospeControl; private TableurModel tablMod; private JPopupMenu mouseObjectPopupMenu; private JPopupMenu mouseGeneralPopupMenu; private Point2D.Double originPointer = new Point2D.Double(); // def ds mouseMove - remonte ici pour garder la position de la souris en screen coord private Point2D.Double pointerPosDble = new Point2D.Double(); // screen position of the mouse private Point2D.Double mousePosition = new Point2D.Double(); private MouseEvent evtMouse; /** Image characteristics */ private Image currentImage; /** Image center in (screen/canvas)? coord */ private Point2D.Double centerImage = new Point2D.Double(); private int selectImage; private String newImageName=null; private String newImageCatalog="Local File"; /** Image needed parameters for display */ private double imResol; private double imWidth; private double imHeight; private float imScale; private Point2D.Double imCenter; /** Mask characteristics */ private Mask currentMask; private double originAngle; /** display needed parameters */ private Point2D.Double maskDisplayCenter = new Point2D.Double(); private Point2D.Double maskDisplayLeftCorner = new Point2D.Double(); public boolean isMaskDisplayed = false; /** Picking Objects*/ public OSPE_PickObjectFrame pickObjFrame; private boolean isPickObjFrame; int objectId = -1; /** Windows Size of search for the near object in ??. */ private static final int N_WIN = 20; protected ImageCoordinateConverter icc; private CanvasFigure canevasD = null; private CanvasFigure[] canevasH = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure[] canevasMH = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure[] canevasMB = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure[] canevasB = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure[] canevasHS = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure[] canevasMHS = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure[] canevasMBS = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure[] canevasBS = new CanvasFigure[Mask._NBRSLITS_]; private CanvasFigure canevasT1 = null; private CanvasFigure canevasT2 = null; private CanvasFigure canevasT3 = null; private CanvasFigure canevasT4 = null; private CanvasFigure canevasM = null; private CanvasFigure[] canevasSpectre = new CanvasFigure[Mask._NBRSLITS_]; private AffineTransform at = new AffineTransform(); private AffineTransform at2 = new AffineTransform(); public boolean isFromSlitComboBox = false; private List listCanvasObjects1; private List listCanvasObjects2; private List listCanvasObjects3; private List listCanvasObjects4; private CanvasFigure canvasBary; public float lWidth=1; Color[] colorTab={Color.RED, Color.ORANGE, Color.PINK, Color.MAGENTA, Color.LIGHT_GRAY}; int nbColor=0; Color objColor=colorTab[nbColor]; final Color red = Color.RED; final Color green = Color.GREEN; final Color greenTrans = new Color(0, 255, 0, 100); final Color blue = new Color(58, 163, 197); final Color blueTrans = new Color(58, 163, 197, 100); final Color trans = new Color(0, 0, 255, 0); final Color yellow = Color.YELLOW; final Color salmon = new Color(255, 128, 128); final int SMALL_DISPLAY_WIDTH = 80; private Writer theWriter; private JPanel smallDisplayPanel; private TableurPanel tableurPanel; private int colTab =0; private int lineTab = 0; private AccessMenuInterface accessMenuInterface; /** * Constructor of the OSPE_VisuPanel, the visualization panel. * * @param p * : Main frame Define the interface construction and the * functionalities * @param fov * @param theWriter * @param tableurPanel */ public OSPE_VisuPanel(StatusInterface statusInterface, AccessMenuInterface accessMenuInterface, FieldOfView fov, Writer theWriter, TableurPanel tableurPanel) { super(new BorderLayout()); this.statusInterface = statusInterface; this.accessMenuInterface = accessMenuInterface; this.fov = fov; this.theWriter = theWriter; this.tableurPanel = tableurPanel; this.divaImageGraphics = new DivaImageGraphics(getNavigatorImageDisplay()); this.icc = new ImageCoordinateConverter(getNavigatorImageDisplay()); this.isPickObjFrame = false; add(getProjectLabel(), BorderLayout.NORTH); add(getSelectionSlitPanel(), BorderLayout.WEST); add(getImagePanel(), BorderLayout.CENTER); buildMouseObjectPopupMenu(); buildMouseGeneralPopupMenu(); fov.addObserver(this); selectImage = -1; listCanvasObjects1 = new ArrayList(); listCanvasObjects2 = new ArrayList(); listCanvasObjects3 = new ArrayList(); listCanvasObjects4 = new ArrayList(); } /** * */ protected OSPE_ImageCutLevelsDialog getImageCutDialog() { if (imCutDialog == null){ this.imCutDialog = new OSPE_ImageCutLevelsDialog(getNavigatorImageDisplay()); } return imCutDialog; } /** * */ public OSPE_ImageColorsDialog getImageColorsDialog() { if (imColorsDialog == null){ imColorsDialog = new OSPE_ImageColorsDialog(getNavigatorImageDisplay()); } return imColorsDialog; } public void setControl(OspeControl ospeControl){ this.ospeControl = ospeControl; } public void setWriter(Writer wi){ this.theWriter = wi; } private JPanel getImagePanel() { if (imagePanel == null) { // add the panel for image manipulation (right) imagePanel = new JPanel(new BorderLayout()); // Panel for the display (inside de imagePanel) JPanel displayPanel = new JPanel(new BorderLayout()); displayPanel.setBorder(BorderFactory.createEtchedBorder()); displayPanel.add(getNavigatorImageDisplay(), BorderLayout.CENTER); displayPanel.add(getImageColorBar(), BorderLayout.EAST); // add the different informations for the image JPanel jPanelLabels = new JPanel(new BorderLayout()); displayPanel.add(jPanelLabels, BorderLayout.SOUTH); jPanelLabels.add(getDisplayLabel(), BorderLayout.WEST); jPanelLabels.add(getFovSizeLabel(), BorderLayout.EAST); imagePanel.add(displayPanel, BorderLayout.CENTER); // Definition of the used buttons to : JPanel buttonsAutomsPanel = new JPanel(new FlowLayout()); buttonsAutomsPanel.add(getSearchButton()); buttonsAutomsPanel.add(getValidateButton()); buttonsAutomsPanel.add(getGenerateButton()); imagePanel.add(buttonsAutomsPanel, BorderLayout.SOUTH); } return imagePanel; } // /** * Size of what is seen in the win visu. * * @return */ private JLabel getFovSizeLabel() { if (jLabelFovSize == null) { jLabelFovSize = new JLabel("Fov size : x-y"); } return jLabelFovSize; } /** * // Pointer world coordinates in image. * * @return */ private JLabel getDisplayLabel() { if (jLabelDisplay == null) { jLabelDisplay = new JLabel("RA - DEC"); } return jLabelDisplay; } /** * To calculate the optimized mask */ private JButton getSearchButton() { if (searchButton == null) { searchButton = new JButton("Search"); searchButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (fov.getNbObjectsOfCurrentImage() <= 0) { new CustomJDialog("You need to add objects first.", CustomJDialog._ERROR_, CustomJDialog._CLOSE_BUTTON_, OSPE_VisuPanel.this); return; } final Point2D.Double pt=new Point2D.Double(0,0); if ((isMaskDisplayed) && (currentMask!= null)) pt.setLocation(currentMask.getCenter()); //pt.setLocation(maskDisplayCenter); else pt.setLocation(currentImage.getCenter()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new SearchWindow(OSPE_VisuPanel.this,pt); } }); } }); searchButton.setEnabled(false); } return searchButton; } /** * To validate the current mask */ private JButton getValidateButton() { if (validateButton == null) { validateButton = new JButton("Validate"); validateButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onValidateButtonAction(); } }); validateButton.setEnabled(false); } return validateButton; } /** * */ private void onValidateButtonAction() { final Mask currentMask = fov.getCurrentMaskOfCurrentImage(); boolean isCurrentMaskValidate = currentMask.validated; CustomJDialog dialog; if (!isCurrentMaskValidate) { // test if there are enougth reference objects to define the mask position. if (testRefObjects()) { // If there are enough reference objects currentMask.validated = true; currentMask.update(); dialog = new CustomJDialog("The mask is validated. Do you want to write it ?", CustomJDialog._QUESTION_, CustomJDialog._YESNOCANCEL_BUTTON_, OSPE_VisuPanel.this); if (dialog.getValue() == JOptionPane.YES_OPTION) { onWriteButtonAction(); } validateButton.setText("Unvalidate"); } else { dialog = new CustomJDialog("You don't have enough reference objects for the mask validation.", CustomJDialog._ERROR_, CustomJDialog._CLOSE_BUTTON_, OSPE_VisuPanel.this); } } else { dialog = new CustomJDialog("You are going to cancel the mask validation.", CustomJDialog._WARNING_, CustomJDialog._YESNOCANCEL_BUTTON_, OSPE_VisuPanel.this); if (dialog.getValue() == JOptionPane.YES_OPTION) { currentMask.validated = false; currentMask.update(); validateButton.setText("Validate"); } } } /** * To generate the xml file with all the mask informations. */ private JButton getGenerateButton() { if (writeButton == null) { writeButton = new JButton("Write"); writeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onWriteButtonAction(); } }); writeButton.setEnabled(false); } return writeButton; } /** * */ private void onWriteButtonAction() { boolean noError=false; JFileChooser fileChooser = new JFileChooser(fov.getPath()); final Mask currentMask = fov.getCurrentMaskOfCurrentImage(); if (currentMask.getRefObjectsList().size()== 0) { if (! testRefObjects()) { new CustomJDialog( "You don't have enough reference objects to save the mask.", CustomJDialog._ERROR_, CustomJDialog._CLOSE_BUTTON_, OSPE_VisuPanel.this); return; } } currentMask.setM_uuid(); fileChooser.setDialogTitle("Save Mask Configuration File"); ExampleFileFilter filter = new ExampleFileFilter(); filter.addExtension("xml"); fileChooser.setFileFilter(filter); String fileMask=""; int returnVal = fileChooser.showDialog(OSPE_VisuPanel.this, "Save as"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); if (file != null) { fileMask=file.getAbsolutePath(); int lgF=fileMask.length(); String fileName = file.getName(); int length = fileName.length(); if ((length>4) && ((fileName.substring(length - 4, length)).equals(".xml"))) { fileMask=fileMask.substring(0,lgF - 4); theWriter.writeMask(currentMask, file.getAbsolutePath()); } else { theWriter.writeMask(currentMask,file.getAbsolutePath() + ".xml"); } } String [][] slitsArray = ospeControl.getSlitsdetector(currentMask); double angleOffset=InstrumentParameters._OFFSET_IPA; noError = theWriter.writeMaskConfiguration(fileMask, currentMask); noError = theWriter.writeSlitsLocation(fileMask, slitsArray, currentMask, angleOffset); } } // End on_write_button /** * Add a color bar on the right side */ private ImageColorbar getImageColorBar() { if (imColorBar == null) { imColorBar = new ImageColorbar(navigatorImageDisplay); imColorBar.setOrient(SwingConstants.VERTICAL); imColorBar.setPreferredSize(new Dimension(20, 450)); imColorBar.setBorder(BorderFactory.createEtchedBorder()); imColorBar.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { imColorBar.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); } @Override public void mouseReleased(MouseEvent e) { imColorBar.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) navigatorImageDisplay.editColors(); } }); } return imColorBar; } /** * */ private JLabel getProjectLabel() { if (projectLabel == null) { projectLabel = new JLabel("No selected image - No selected mask"); projectLabel.setBorder(BorderFactory.createLineBorder(Color.black)); projectLabel.setHorizontalAlignment(SwingConstants.CENTER); projectLabel.setHorizontalTextPosition(SwingConstants.CENTER); } return projectLabel; } /** * Build the slits characteristics panel with the zooming function */ private JPanel getSelectionSlitPanel() { if (selectionSlitPanel == null) { selectionSlitPanel = new JPanel(); selectionSlitPanel.setLayout(new BorderLayout()); JPanel upSlitPanel = new JPanel(); upSlitPanel.setLayout(new BoxLayout(upSlitPanel, BoxLayout.Y_AXIS)); smallDisplayPanel = new JPanel(new FlowLayout()); smallDisplayPanel.add(getImagePanner()); smallDisplayPanel.add(getZoom()); upSlitPanel.add(smallDisplayPanel); JPanel buttonsZoomPanel = new JPanel(new FlowLayout()); buttonsZoomPanel.add(getUnUnButton()); buttonsZoomPanel.add(getZoomPlusButton()); buttonsZoomPanel.add(getZoomMoinsButton()); upSlitPanel.add(buttonsZoomPanel); JPanel selectSlitPanel = new JPanel(new FlowLayout()); selectSlitPanel.add(getSlitComboBox()); // selectSlitPanel.add(getMoveZoomButton()); // selectSlitPanel.add(getZoomSpin()); upSlitPanel.add(selectSlitPanel); JPanel labelsPanel = new JPanel(new GridLayout(0, 2)); labelsPanel.add(new JLabel("Position (arcsec)")); labelsPanel.add(new JLabel("Width (arcsec)")); upSlitPanel.add(labelsPanel); selectionSlitPanel.add(upSlitPanel, BorderLayout.NORTH); JPanel slitsSlidePanel = new JPanel(new GridLayout(0, 2)); slitsSlidePanel.add(getPositionSlide()); slitsSlidePanel.add(getApertureSlide()); selectionSlitPanel.add(slitsSlidePanel, BorderLayout.CENTER); selectionSlitPanel.add(getSlitPropertiesPanel(), BorderLayout.SOUTH); } return selectionSlitPanel; } /** * Set the slit sky coordinates. * @param currentMask * @param i : slit id * @param X : X coord of slit start in canvas coord * @param Y : Y coord of slit start in canvas coord */ private void setSlitSkyCoord(Mask currentMask, int i, double X, double Y) { Point2D.Double mPoint = new Point2D.Double(X,Y); // set the new slit's coordinates //icc.ImageToCanvasCoords(mPoint, false); WorldCoords wc = getWorldCoords(mPoint.getX(), mPoint.getY()); //System.out.println("visu:setSlitGal- 541 "+ i+" "+wc.getRA().toString()+" : "+wc.getDec().toString()); currentMask.getSlit(i).setSkyPosition(wc.getRA(), wc.getDec()); } private OSPE_SlitPropPanel getSlitPropertiesPanel() { if (slitPropertiesPanel == null) { slitPropertiesPanel = new OSPE_SlitPropPanel(this, fov, statusInterface); slitPropertiesPanel.getJComponent(OSPE_SlitPropPanel.posit).setEnabled(false); slitPropertiesPanel.getJComponent(OSPE_SlitPropPanel.aperture).setEnabled(false); } return slitPropertiesPanel; } private JSlider getApertureSlide() { if (slide_aperture == null) { slide_aperture = new JSlider(SwingConstants.VERTICAL); slide_aperture.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider)e.getSource(); //System.out.println("Visu 542 getApSlid flag "+ isFromSlitComboBox); if (!isFromSlitComboBox) { Slit currentSlit = fov.getCurrentImage().getCurrentMask().getCurrentSlit(); double apeOri = currentSlit.getAperture(); //System.out.print("Visu 544 getApSlid "+apeOri+" Source val : "+source.getValue()); if (!slide_aperture.getValueIsAdjusting()) { //System.out.print(" - adjust Aper: Source val : "+source.getValue()); adjustSlitAperture(slide_aperture.getValue(), currentSlit, apeOri); } fov.getCurrentImage().getCurrentMask().draggingSlides = slide_aperture .getValueIsAdjusting(); // currentSlit.update(); fov.getCurrentImage().getCurrentMask().update(); } //System.out.println(" A "); } }); slide_aperture.setMajorTickSpacing(5); slide_aperture.setPaintTicks(true); slide_aperture.setEnabled(false); } return slide_aperture; } /** * */ private JSlider getPositionSlide() { if (slide_position == null) { slide_position = new JSlider(SwingConstants.VERTICAL); slide_position.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider)e.getSource(); //System.out.println("Visu 542 getPosSlid flag"+isFromSlitComboBox); if (!isFromSlitComboBox) { Slit currentSlit = fov.getCurrentImage().getCurrentMask().getCurrentSlit(); double posOri = currentSlit.getPosition(); //System.out.print("Visu 544 getPosSlid Source val : "+ source.getValue() +" "+slide_position.getValue()); //if (!slide_position.getValueIsAdjusting()) { if (!source.getValueIsAdjusting()) { //System.out.print(" - adjust Pos: "); //adjustSlitPosition(slide_position.getValue(), currentSlit, posOri); adjustSlitPosition(source.getValue(), currentSlit, posOri); } //fov.getCurrentImage().getCurrentMask().draggingSlides = slide_position.getValueIsAdjusting(); fov.getCurrentImage().getCurrentMask().draggingSlides = source.getValueIsAdjusting(); currentSlit.update(); fov.getCurrentImage().getCurrentMask().update(); } //System.out.println(" Out of listener P "); } }); slide_position.setMajorTickSpacing(20); slide_position.setPaintTicks(true); slide_position.setEnabled(false); } return slide_position; } /** * @return */ private JSpinner getZoomSpin() { if (spinZoom == null) { spinZoom = new JSpinner(new SpinnerNumberModel(10, 1, 20, 1)); } return spinZoom; } /** * @return */ private JButton getMoveZoomButton() { if (jButtonMoveZoom == null) { jButtonMoveZoom = new JButton(); jButtonMoveZoom.setText("Go & Zoom x"); jButtonMoveZoom.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //moveToSlit(slitCombo.getSelectedIndex()); zoomSet(Float.valueOf(getZoomSpin().getValue().toString()).floatValue()); } }); jButtonMoveZoom.setEnabled(false); } return jButtonMoveZoom; } /** * */ private JComboBox getSlitComboBox() { if (slitCombo == null) { slitCombo = new JComboBox(); for (int i = 0; i < Mask._NBRSLITS_; i++) { String texte = new String(); texte = "Slit " + (i+1); slitCombo.addItem(texte); } slitCombo.setEnabled(false); slitCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //System.out.print("Visu 645 - slitCombo Action listener flag true"); isFromSlitComboBox = true; if (slitCombo.getSelectedIndex() < 0) return; final Mask currentMask = fov.getCurrentImage().getCurrentMask(); final Slit currentSlit = currentMask.getCurrentSlit(); currentSlit.deleteObservers(); currentMask.setCurrentSlit(slitCombo.getSelectedIndex()); currentSlit.addObserver(OSPE_VisuPanel.this); slide_position.setValue((int) currentSlit.getPosition()); slide_aperture.setValue((int) currentSlit.getAperture()); currentSlit.update(); isFromSlitComboBox = false; //System.out.println(" Visu 660 - slitCombo Action listener flag false"); } }); } return slitCombo; } /** * */ private JButton getZoomMoinsButton() { if (jButtonZoomMoins == null) { jButtonZoomMoins = new JButton(); jButtonZoomMoins.setText("-"); jButtonZoomMoins.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { zoomOut(); } }); jButtonZoomMoins.setEnabled(false); } return jButtonZoomMoins; } /** * */ private JButton getZoomPlusButton() { if (jButtonZoomPlus == null) { jButtonZoomPlus = new JButton(); jButtonZoomPlus.setText("+"); jButtonZoomPlus.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { zoomIn(); } }); jButtonZoomPlus.setEnabled(false); } return jButtonZoomPlus; } /** * */ private JButton getUnUnButton() { if (jButtonUnUn == null) { jButtonUnUn = new JButton(); jButtonUnUn.setText("1:1"); jButtonUnUn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (fov.getCurrentImage().getSelectedMask() >= 0) { fov.getCurrentImage().getCurrentMask().init2Display(); } zoomSet(1.0F); } }); jButtonUnUn.setEnabled(false); } return jButtonUnUn; } /** * */ private ImagePanner getImagePanner() { if (imagePanner == null) { imagePanner = new ImagePanner(navigatorImageDisplay, SMALL_DISPLAY_WIDTH, SMALL_DISPLAY_WIDTH); imagePanner.setBorder(new LineBorder(navigatorImageDisplay.getBackground(), 1)); } return imagePanner; } /** * */ private ImageZoom getZoom() { if (imageZoom == null) { imageZoom = new ImageZoom(navigatorImageDisplay, SMALL_DISPLAY_WIDTH, SMALL_DISPLAY_WIDTH, 4); imageZoom.setPropagateScale(true); imageZoom.setBorder(new LineBorder(navigatorImageDisplay.getBackground(), 1)); } return imageZoom; } /** * Creation of the mousePopUp menu which can permit : To set an object * Referenced To remove an object To assign it to a slit To recalculate the * centroid. */ public void buildMouseObjectPopupMenu() { mouseObjectPopupMenu = new JPopupMenu(); mouseObjectPopupMenu.add(getRefCheckBoxMenuItem()); mouseObjectPopupMenu.addSeparator(); mouseObjectPopupMenu.add(getPlotSectrumMenuItem()); mouseObjectPopupMenu.addSeparator(); if (!isPickObjFrame) { mouseObjectPopupMenu.add(getRemoveObjectMenuItem()); mouseObjectPopupMenu.addSeparator(); } mouseObjectPopupMenu.add(getAssignToSlitMenuItem()); mouseObjectPopupMenu.addSeparator(); mouseObjectPopupMenu.add(getRecalculateCentroidMenuItem()); mouseObjectPopupMenu.addSeparator(); mouseObjectPopupMenu.add(revertCentroidMenuItem()); /* mouseObjectPopupMenu.addSeparator(); mouseObjectPopupMenu.add(addMaskAtPositionMenuItem()); mouseObjectPopupMenu.addSeparator(); mouseObjectPopupMenu.add(searchAtPositionMenuItem()); */ mouseObjectPopupMenu.setVisible(false); } /** Menu Option - Revert calculation of the centroid * @return */ private JMenuItem revertCentroidMenuItem() { JMenuItem revertCentroidMenuItem = new JMenuItem("Revert centroid value"); revertCentroidMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { int numObj = fov.getCurrentImage().getActiveObject(); if (numObj> -1) { SkyObject sk = fov.getCurrentImage().getListObjects().get(numObj); sk.setPosPixRecalc(null); sk.setColorWithPriority(sk.getPriority()); // String src=sk.getSrc().replace(" (R)", ""); // sk.setSrc(src); updateByHand(); //updateByHand("V revert cent"); ospeControl.getActionControl().setSaveNeeded(true); mouseObjectPopupMenu.setVisible(false); } } }); return revertCentroidMenuItem; } /** Menu Option - Recalculation of the centroid * @return */ private JMenuItem getRecalculateCentroidMenuItem() { JMenuItem recalcCentroidMenuItem = new JMenuItem("recalculate centroid"); recalcCentroidMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { int numObj = fov.getCurrentImage().getActiveObject(); if (numObj> -1) { SkyObject currentObject = fov.getCurrentImage().getListObjects().get(numObj); // mess = "DEBUG - MouseMenu num Obj: " + numObj + " centre : " // + pCenter.x + " - " + pCenter.y; // System.out.println(mess); mouseObjectPopupMenu.setVisible(false); recalculateCentroid(currentObject); updateByHand(); ospeControl.getActionControl().setSaveNeeded(true); } } }); return recalcCentroidMenuItem; } /** Menu option : assigning a slit to the pointed object * @return */ private JMenuItem getAssignToSlitMenuItem() { JMenuItem assignSlitMenuItem = new JMenuItem("assign to Slit"); assignSlitMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { int refIdObj = fov.getCurrentImage().getActiveObject(); if (refIdObj> -1) { associateObjectToSlit(refIdObj, fov .getCurrentImage().getCurrentMask()); mouseObjectPopupMenu.setVisible(false); updateByHand(); //updateByHand("V Asign slit menu"); ospeControl.getActionControl().setSaveNeeded(true); } } }); return assignSlitMenuItem; } /** Menu option : Removing the pointed object * @return */ private JMenuItem getRemoveObjectMenuItem() { JMenuItem removeMenuItem = new JMenuItem("remove Object"); removeMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { int refIdObj = fov.getCurrentImage().getActiveObject(); if (refIdObj> -1) { fov.getCurrentImage().removeObject(refIdObj); mouseObjectPopupMenu.setVisible(false); navigatorImageDisplay.updateImage(); updateByHand(); //updateByHand("V del obj menu"); ospeControl.getActionControl().setSaveNeeded(true); } } }); return removeMenuItem; } /** Menu option : Plot the spectrum of the pointed object in the slit. * @return */ private JMenuItem getPlotSectrumMenuItem() { JMenuItem plotSpectrumMenuItem = new JMenuItem("plot spectrum"); plotSpectrumMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { Mask currentMask = fov.getCurrentImage().getCurrentMask(); int refIdObj = fov.getCurrentImage().getActiveObject(); if (refIdObj>-1) { int slitNum = searchAffectedSlitToObject(refIdObj); if (currentMask.getPlotSpectrum(slitNum)) currentMask.setPlotSpectrum(slitNum, false); else currentMask.setPlotSpectrum(slitNum, true); accessMenuInterface.clickOnMenuDisplayPlotSelectedSpectra(); mouseObjectPopupMenu.setVisible(false); } } }); return plotSpectrumMenuItem; } /** * @return */ private JCheckBoxMenuItem getRefCheckBoxMenuItem() { JCheckBoxMenuItem setRefCheckBoxMenuItem = new JCheckBoxMenuItem("is Reference"); setRefCheckBoxMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { /** Set/unset the object reference propriety */ final Image currentImage = fov.getCurrentImage(); int refIdObj = currentImage.getActiveObject(); if (refIdObj> -1) { SkyObject skyObject = currentImage.getListObjects().get(refIdObj); if (skyObject.isRef()) { skyObject.setRef(false); if (currentImage.refObjNb > 0) currentImage.refObjNb--; else currentImage.refObjNb = 0; } else { skyObject.setRef(true); currentImage.refObjNb++; } mouseObjectPopupMenu.setVisible(false); updateByHand(); } //updateByHand("V Get ref check box menu"); } }); return setRefCheckBoxMenuItem; } /** * Mouse menu when the pointed star is not an object */ public void buildMouseGeneralPopupMenu() { mouseGeneralPopupMenu = new JPopupMenu(); mouseGeneralPopupMenu.add(addObjectMenuItem()); //mouseGeneralPopupMenu.add(addObjectMenuItemMan()); mouseGeneralPopupMenu.addSeparator(); mouseGeneralPopupMenu.add(setNewCenterImageItem()); /* mouseGeneralPopupMenu.addSeparator(); mouseGeneralPopupMenu.add(addMaskAtPositionMenuItem()); mouseGeneralPopupMenu.addSeparator(); mouseGeneralPopupMenu.add(searchAtPositionMenuItem()); */ mouseGeneralPopupMenu.setVisible(false); } /** Menu option : Add objects menu item * @return */ private JMenuItem addObjectMenuItem() { JMenuItem addObjectMenuItem = new JMenuItem("Add Objects"); addObjectMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { setPickObjectFrame(); mouseGeneralPopupMenu.setVisible(false); } }); return addObjectMenuItem; } /** * Centering image at the mouse position * @return */ private JMenuItem setNewCenterImageItem() { JMenuItem newCenterImageItem = new JMenuItem("Center image at this position"); newCenterImageItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { mouseGeneralPopupMenu.setVisible(false); icc.screenToCanvasCoords(mousePosition, false); fov.getCurrentImage().setCenter(mousePosition); fov.getCurrentImage().update(); } }); return newCenterImageItem; } /** Menu option : add a new mask on image * @return */ private JMenuItem addMaskAtPositionMenuItem() { JMenuItem addMaskItem = new JMenuItem("Add Masks at this position"); addMaskItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { //System.out.println("visu:setMaskWithCenter"); //int x=(int) (mousePosition.x); //int y=(int)(mousePosition.y); //printTheMousePosition(x, y); icc.screenToCanvasCoords(mousePosition, false); ospeControl.addMask(mousePosition); mouseGeneralPopupMenu.setVisible(false); } }); return addMaskItem; } /** Menu option : add a new mask on image * @return */ private JMenuItem searchAtPositionMenuItem() { JMenuItem searchItem = new JMenuItem("Search masks at this position"); searchItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { mouseGeneralPopupMenu.setVisible(false); icc.screenToCanvasCoords(mousePosition, false); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new SearchWindow(OSPE_VisuPanel.this,mousePosition); } }); } }); return searchItem; } public void setPickObjectFrame() { if (!isPickObjFrame) { isPickObjFrame = true; pickObjFrame = new OSPE_PickObjectFrame(this); Cursor cursor = new Cursor(Cursor.DEFAULT_CURSOR); navigatorImageDisplay.setCursor(cursor); searchButton.setEnabled(false); validateButton.setEnabled(false); writeButton.setEnabled(false); accessMenuInterface.enableButtonsForPicObject(false); updateByHand(); //updateByHand("V pick obj"); } } /** * Add object manually * with the recalculation centroid proced */ // public void addObjectManual(Point2D.Double mPos) // { // Point2D.Double pos= new Point2D.Double (mPos.x,mPos.y); // // this.icc.screenToCanvasCoords(pos, false); // // /* Get the nearest object from the click position // */ // pos=positonCalcul(pos); // // /* pass the object to the recalculation procedure */ // // addObject(-1,-1," ", pos,0); // updateByHand(); // System.out.println("Visu - addObjMan "); // } /** * Get the display of the visualization * * @return display : OSPE_NavigatorImageDisplay */ @Override public OSPE_NavigatorImageDisplay getNavigatorImageDisplay() { if (navigatorImageDisplay == null) { navigatorImageDisplay = new OSPE_NavigatorImageDisplay(); navigatorImageDisplay.setPreferredSize(new Dimension(450, 450)); navigatorImageDisplay.setAutoCenterImage(false); navigatorImageDisplay.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { onNavigatorImageDisplayMousePressed(e); } @Override public void mouseReleased(MouseEvent e) { onNavigatorImageDisplayMouseReleased(); } @Override public void mouseClicked(MouseEvent e) { onNavigatorImageDisplayMouseClicked(e); } }); navigatorImageDisplay.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { onNavigatorImageDisplayMouseMoved(e.getX(), e.getY()); } @Override public void mouseDragged(MouseEvent e) { onNavigatorImageDisplayMouseDragged(e); } }); navigatorImageDisplay.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { onNavigatorImageDisplayMouseWheelMoved(e); } }); navigatorImageDisplay.clear(); } return navigatorImageDisplay; } /** * The mouse click :
* Left is used :
  • to change the image part you see in the field. *
  • to move or turn a mask.
  • to pick, select an object or select a * slit.
  • Right:
    * if there is no mask :
  • Add objects.
  • * * if there is a mask :
  • To set reference object.
  • To * de-select an object.
  • To assign the pointed object with a slit.
  • To * recalculate the object centroid. * */ private void onNavigatorImageDisplayMouseClicked(MouseEvent e) { statusInterface.setStatusBarText(""); removePopup(); // get the screen mouse position mousePosition=new Point2D.Double(e.getX(),e.getY()); if (fov.getSelectedImage() >= 0 && ! isPickObjFrame) { // final Image currentImage = fov.getCurrentImage(); // final Mask currentMask = currentImage.getCurrentMask(); if (SwingUtilities.isLeftMouseButton(e)) { //System.out.println(("Visu:mouse clic")); //printTheMousePosition(e.getX(),e.getY()); if (currentImage.getSelectedMask() >= 0) { onNavigatorImageDisplayleftMouseClick(e, currentImage, currentMask); } } else if (SwingUtilities.isRightMouseButton(e)) { // int objectId = getTheNearObjectid(currentImage); int objectId = getNearObjectid(currentImage); rigthMouseClick(e, currentImage, currentMask, objectId); } } } /** * Get the nearest object id of the mouse position * Calculation with canvas coord. */ private int getNearObjectid(Image currentImage) { boolean find = false; objectId=-1; List tempList = currentImage.getListObjects(); Point2D.Double tmpPoint = new Point2D.Double(mousePosition.x,mousePosition.y); icc.screenToCanvasCoords(tmpPoint, false); double testPtMinX=tmpPoint.getX()-10; double testPtMinY=tmpPoint.getY()-10; double testPtMaxX=tmpPoint.getX()+10; double testPtMaxY=tmpPoint.getY()+10; for (int i = 0; i < tempList.size() && !find; i++) { WorldCoords tmpObj = new WorldCoords(tempList.get(i).getObjWorldCenter().getX(),tempList.get(i).getObjWorldCenter().getY()); Point2D.Double tmpWc = new Point2D.Double(tmpObj.getX(),tmpObj.getY()); icc.worldToCanvasCoords(tmpWc, false); if ((testPtMinX < tmpWc.getX()) && (testPtMaxX > tmpWc.getX()) && (testPtMinY < tmpWc.getY()) && (testPtMaxY > tmpWc.getY()) ) { // The pointed object is found. currentImage.setActiveObject(i); objectId = i; tableurPanel.selectCorrespondingRow(objectId); find = true; } else { currentImage.setActiveObject(-1); } } return objectId; } /** * Remove popup menus */ private void removePopup() { if (mouseObjectPopupMenu.isVisible()) { mouseObjectPopupMenu.setVisible(false); } if (mouseGeneralPopupMenu.isVisible()) {// || (isPickObjFrame) ) mouseGeneralPopupMenu.setVisible(false); } } /** * When rolling the mouse wheel, zoom in or zoom out. * @param e : mouse event */ private void onNavigatorImageDisplayMouseWheelMoved(MouseWheelEvent e) { if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL && fov.getSelectedImage() >= 0) { if (e.getWheelRotation() > 0){ zoomIn(); } else{ zoomOut(); } } } /** * */ private void onNavigatorImageDisplayMouseReleased() { navigatorImageDisplay.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); if ((fov.getSelectedImage() >= 0) && (fov.getCurrentImage().getSelectedMask() >= 0)) { Mask currentMask = fov.getCurrentImage().getCurrentMask(); maskDisplayCenter.x = fov.getCurrentImage().getCurrentMask().getCenter().getX(); maskDisplayCenter.y = fov.getCurrentImage().getCurrentMask().getCenter().getY(); Point2D.Double pt=new Point2D.Double(maskDisplayCenter.x,maskDisplayCenter.y); Point2D.Double ptL=new Point2D.Double(currentMask.getLeftCornerPix().getX(),currentMask.getLeftCornerPix().getY()); //System.out.println("Visu M relsed Mlx: "+pt.x+" "+pt.y); //icc.screenToWorldCoords(ptL, false); // icc.canvasToWorldCoords(pt, false); // // icc.userToWorldCoords(pt, false); // currentMask.setCenterDeg(pt); // currentMask.setCenterWc(pt.getX(), pt.getY()); if (currentMask.moveEnable && !currentMask.turnEnable) { currentMask.moving = false; MaskHistoryEntry lastHistoryEntry = currentMask.getHistory().getLastEntry(); if (currentMask.getCenter().equals(lastHistoryEntry.getValue("setCenter"))) lastHistoryEntry.deleteAction("setCenter"); if (currentMask.getCenter().equals(lastHistoryEntry.getValue("setCenterDeg"))) lastHistoryEntry.deleteAction("setCenterDeg"); if (currentMask.getAlpha().equals(lastHistoryEntry.getValue("setAlpha"))) lastHistoryEntry.deleteAction("setAplha"); if (currentMask.getDelta().equals(lastHistoryEntry.getValue("setDelta"))) lastHistoryEntry.deleteAction("setDelta"); if (lastHistoryEntry.isEmpty()) currentMask.getHistory().deleteLastEntry(); } else if (!currentMask.moveEnable && currentMask.turnEnable) { currentMask.turning = false; Double historyOmega = (Double) currentMask.getHistory().getLastEntry().getValue("setOmega"); if (historyOmega == currentMask.getOmega()) currentMask.getHistory().deleteLastEntry(); } } evtMouse = null; } /** * @param e */ private void onNavigatorImageDisplayMousePressed(MouseEvent e) { if ((fov.getSelectedImage() >= 0) && (fov.getCurrentImage().getSelectedMask() >= 0)) { currentMask = fov.getCurrentImage().getCurrentMask(); if (currentMask.moveEnable) { moveCurrentMask(currentMask); } else if (currentMask.turnEnable) { turnCurrentMask(e, currentMask); } } originPointer.setLocation(e.getX(), e.getY()); //** used for later traitement *// if (fov.getSelectedImage() >= 0) { centerImage.x = fov.getCurrentImage().getCenter().getX(); centerImage.y = fov.getCurrentImage().getCenter().getY(); if (fov.getCurrentImage().getSelectedMask() >= 0) { // Set the new display coord of the mask - User Coord maskDisplayCenter.x = fov.getCurrentImage().getCurrentMask().getCenter().getX(); maskDisplayCenter.y = fov.getCurrentImage().getCurrentMask().getCenter().getY(); } } } /** * @param e * @param currentMask */ private void turnCurrentMask(MouseEvent e, Mask currentMask) { currentMask.turning = true; navigatorImageDisplay.setCursor(Cursor .getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); evtMouse = e; // eraseMask(); // displayMask(); originAngle = currentMask.getOmega(); Double oldOmega = new Double(currentMask.getOmega()); currentMask.getHistory().addEntry("Rotate mask"); currentMask.getHistory().addAction("setOmega", oldOmega); ospeControl.getMainFrame().updateButtons(); } /** * @param currentMask */ private void moveCurrentMask(Mask currentMask) { currentMask.moving = true; navigatorImageDisplay.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); Point2D.Double oldCenter = new Point2D.Double(currentMask.getCenter().x, currentMask.getCenter().y); Point2D.Double oldCenterDeg = new Point2D.Double( currentMask.getCenterDeg().x, currentMask.getCenterDeg().y); Point2D.Double oldCenterWc = new Point2D.Double( currentMask.getMaskCenterWordlCoord().getRaDeg(), currentMask.getMaskCenterWordlCoord().getDecDeg()); HMS oldAlpha = new HMS(currentMask.getAlpha()); DMS oldDelta = new DMS(currentMask.getDelta()); currentMask.getHistory().addEntry("Move mask"); currentMask.getHistory().addAction("setCenter", oldCenter); currentMask.getHistory().addAction("setCenterDeg", oldCenterDeg); currentMask.getHistory().addAction("setCenterWc", oldCenterWc); ospeControl.getMainFrame().updateButtons(); // currentMask.getHistory().addAction("setAlpha", oldAlpha); // currentMask.getHistory().addAction("setDelta", oldDelta); } /** * Definition of the update function */ @Override public void updateByHand() { setProjectLabel(); eraseSpectra(); eraseMask(); eraseAllObjects(); eraseBary(); eraseTableur(); checkSelectedImage(); if (fov.getSelectedImage() >= 0) { displayImage(); setLabelFovSize(); if (fov.getCurrentImage().getSelectedMask() >= 0 && !isPickObjFrame) { enableCompo(true); displayMask(); isMaskDisplayed = true; } else { enableCompo(false); isMaskDisplayed = false; if (isPickObjFrame) { displayMask(); isMaskDisplayed = true; } } plotAllObjects(); displayTableur(); } else { int imNb = fov.getNbrImages(); if (imNb > 0) { fov.setSelectedImage((imNb - 1)); } } updateSlitProp(); this.repaint(); //System.out.println("Visu 1532 -End updateByHand"); } /** * @param enabled */ private void enableCompo(final boolean enabled) { slitCombo.setEnabled(enabled); // jButtonMoveZoom.setEnabled(enabled); slide_position.setEnabled(enabled); slide_aperture.setEnabled(enabled); slitPropertiesPanel.getJComponent(OSPE_SlitPropPanel.posit).setEnabled(enabled); slitPropertiesPanel.getJComponent(OSPE_SlitPropPanel.aperture).setEnabled(enabled); } /** * */ private void checkSelectedImage() { if (selectImage != fov.getSelectedImage()) { selectImage = fov.getSelectedImage(); eraseImage(); if (fov.getSelectedImage() >= 0) { //navigatorImageDisplay.setImage(fov.getCurrentImage().getFitsImage()); navigatorImageDisplay.setFilename(fov.getCurrentImage().getAbsPath()); int val= fov.getSelectedImage(); updateCutLevels(val); updateColors(val); updateOfImageNavigatorDisplay(); jButtonUnUn.setEnabled(true); jButtonZoomPlus.setEnabled(true); jButtonZoomMoins.setEnabled(true); // jButtonMoveZoom.setEnabled(true); } } } /** * Called when Observer event. * */ @Override public void update(Observable changed, Object arg) { updateByHand(); } /** * Update the slits properties when changes are validated. */ private void updateSlitProp() { slitPropertiesPanel.setValue(0, ""); slitPropertiesPanel.setValue(1, ""); if (fov.getSelectedImage() >= 0) { final Image currentImage = fov.getCurrentImage(); if (currentImage.getSelectedMask() >= 0) { final Mask currentMask = currentImage.getCurrentMask(); final Slit currentSlit = currentMask.getCurrentSlit(); slitPropertiesPanel.setValue(0, currentSlit.getPosition()); slitPropertiesPanel.setValue(1, currentSlit.getAperture()); // imageZoom.setActive(true); Point2D.Double tmp = new Point2D.Double(); at2.transform(currentSlit.getPosXY(), tmp); // imageZoom.zoom((int) tmp.getX(), (int) tmp.getY(), false); // imageZoom.setActive(false); } } } /** * Update the slides properties */ @Override public void updateSlides() { isFromSlitComboBox = true; //System.out.print(" Visu 1296 - UpdateSlide flag true "); Slit currentSlit = fov.getCurrentImage().getCurrentMask().getCurrentSlit(); int maxPos = (int) currentSlit.PosMax; int minPos = (int) currentSlit.PosMin; int midPos = 0; int valPos = (int) currentSlit.getPosition(); //System.out.print(" val : "+valPos+" "); slide_position.setMaximum(maxPos); slide_position.setMinimum(minPos); slide_position.setValue(valPos); Hashtable labelTablePos = new Hashtable(); labelTablePos.put(new Integer(minPos), new JLabel(String.valueOf(minPos))); labelTablePos.put(new Integer(midPos), new JLabel(String.valueOf(midPos))); labelTablePos.put(new Integer(maxPos), new JLabel(String.valueOf(maxPos))); slide_position.setLabelTable(labelTablePos); slide_position.setPaintLabels(true); int maxApe = (int) currentSlit.ApeMax; int minApe = (int) currentSlit.ApeMin; int valApe = (int) currentSlit.getAperture(); slide_aperture.setMaximum(maxApe); slide_aperture.setMinimum(minApe); slide_aperture.setValue(valApe); Hashtable labelTableApe = new Hashtable(); labelTableApe.put(new Integer(minApe), new JLabel(String.valueOf(minApe))); labelTableApe.put(new Integer(maxApe), new JLabel(String.valueOf(maxApe))); slide_aperture.setLabelTable(labelTableApe); slide_aperture.setPaintLabels(true); //System.out.println("Visu 1316 - end updSlides flag false"); isFromSlitComboBox = false; } /** * Display the image and mask names in the title of the display. */ public void setProjectLabel() { String texte = null; if (fov.getSelectedImage() >= 0) { texte = "Selected image : " + fov.getCurrentImage().getProjImName(); if (fov.getCurrentImage().getSelectedMask() >= 0) { texte = texte + " - Selected mask : " + fov.getCurrentImage().getCurrentMask().getName(); } else { texte = texte + "- No selected mask"; } } else { texte = "No image - No mask"; } projectLabel.setText(texte); } /** * Erase the current image. */ public void eraseImage() { if (navigatorImageDisplay.getImage() != null){ navigatorImageDisplay.clear(); } jLabelDisplay.setText(" - "); jLabelFovSize.setText(" - "); jButtonUnUn.setEnabled(false); jButtonZoomPlus.setEnabled(false); jButtonZoomMoins.setEnabled(false); } /** * This function is used to plot the image on the display.
    *
    * If an image is selected, the following events occur : *
      *
    • Set the scale of the display to the current image scale. *
    • Compute the new origin in X and Y direction to keep the center of the * display unchanged :
      * NewOrigin.X = (ImageCenter.X * ImageScale) - (Display.Width / 2.0) *
      * NewOrigin.Y = (ImageCenter.Y * ImageScale) - (Display.Height / * 2.0) *
    • Set the origin of the display to this shift. *
    • Display the image. *
    • Enable the access to the "Catalogue" menu. *
    • Enable the access to the "Fov->Remove Image" sub-menu. *
    * Else nothing appends. */ private void displayImage() { if (fov.getSelectedImage() >= 0){ currentImage = fov.getCurrentImage(); getImageDisplayParameters(currentImage); if ((currentImage.getAlpha()== null) || (currentImage.getDelta()==null)) { WorldCoords imCenter=getWorldCoords(currentImage.getCenter().getX(), currentImage.getCenter().getY()); currentImage.setAlpha(imCenter.getRA()); currentImage.setDelta(imCenter.getDec()); } //navigatorImageDisplay.setScale(currentImage.getScale()); navigatorImageDisplay.setScale(imScale); Point2D.Double newOrig = new Point2D.Double(); // newOrig.x = currentImage.getCenter().getX() * currentImage.getScale() // - navigatorImageDisplay.getWidth() / 2.0; // newOrig.y = currentImage.getCenter().getY() * currentImage.getScale() // - navigatorImageDisplay.getHeight() / 2.0; newOrig.x = imCenter.getX() * imScale - navigatorImageDisplay.getWidth() / 2.0; newOrig.y = imCenter.getY() * imScale - navigatorImageDisplay.getHeight() / 2.0; navigatorImageDisplay.setOrigin(newOrig); navigatorImageDisplay.updateImage(); ospeControl.getMainFrame().setTitle("OSP EDITOR - " + ospeControl.projectCompletePath ); this.validate(); } } /** * Set the size of the field of view symbolized by the display window. * */ private void setLabelFovSize() { // Print the image size. DecimalFormat df = new DecimalFormat("########.00"); double Wf = navigatorImageDisplay.getWidth() * fov.getCurrentImage().getResol() / fov.getCurrentImage().getScale(); double Hf = navigatorImageDisplay.getHeight() * fov.getCurrentImage().getResol() / fov.getCurrentImage().getScale(); jLabelFovSize.setText("Fov Size : " + df.format(Wf) + " x " + df.format(Hf) + " arcsec."); } /** * When displaying an image with a mask with the positionned slits, the * slits affected on objects are displayed in an array. This function tests * if there is a slit affected to the object. * * @param numObj * : id of the object * @return slit id : slit id if found / else return (-1) */ private int searchAffectedSlitToObject(int numObj) { if (fov.getSelectedImage() < 0 || fov.getCurrentImage().getSelectedMask() < 0) return -1; for (int i = 1; i < ((Mask._NBRSLITS_)-1); i++) { if (fov.getCurrentImage().getCurrentMask().getSlit(i).getAffectedObject() == numObj) return i; } return -1; } /** * Reinit the slits array. */ private void eraseTableur() { tablMod = tableurPanel.getModel(); colTab = tablMod.getColumnCount() + 1; lineTab = 0; Object[][] tableData = new Object[lineTab][colTab]; tableurPanel.getModel().fillTableModelPerso(tableData); tableurPanel.updateByHand(); } /** * Display the array with the slits affected to an object */ private void displayTableur() { colTab = tablMod.getColumnCount(); final Image currentImage = fov.getCurrentImage(); lineTab = currentImage.getListObjects().size(); int nbIm=currentImage.getId(); Object[][] tableData = new Object[lineTab][colTab]; for (int i = 0; i < lineTab; i++) { int j; for (j = 0; j < (colTab); j++) { tableData[i][j] = getObjectProp(i, j); } } for (int i = 0; i < currentImage.getListObjects().size(); i++) { if (currentImage.getSelectedMask() >= 0) { int affectedSlit = searchAffectedSlitToObject(i); if (affectedSlit <= 0) tableData[i][4] = "none"; else tableData[i][4] = String.valueOf(affectedSlit + 1); } else tableData[i][5] = "none"; } tableurPanel.getModel().fillTableModelPerso(tableData); //tableurPanel.getModel().setnewData(currentImage.getListObjects()); tableurPanel.updateByHand(); } /** * Get the properties of an object for the tableur * * @param objNum * The number of the object * @param propNum * The property to retrieve * @return The property corresponding to the given number. */ public Object getObjectProp(int objNum, int propNum) { SkyObject sk = fov.getCurrentImage().getListObjects().get(objNum); int idSlit=-1; switch (propNum) { case 0 : // return the object num in project / on Image return sk.getNum(); case 1: // return the object id return sk.getTargetId(); case 2: // Flag if is a reference return sk.isRef(); case 3: // return the object priority return sk.getPriority(); case 4: if (fov.getCurrentMaskOfCurrentImage() != null) { idSlit=getAffectedSlit(objNum); } // return the slit number if selected return idSlit; case 5: // get the object source type String txt3; if (sk.getGroup() == -1) txt3=" "; else txt3=String.valueOf(sk.getGroup()); return txt3; case 6: case 7: // object world coordinates WorldCoords coords; boolean recalc=false; if (sk.isCenterRecalc()) { coords=sk.getObjWorldRecalc(); recalc=true; } else coords=sk.getObjWorldCenter(); if (propNum == 6) { String txt1=coords.getRA().toString(); if (recalc) txt1=txt1+" (R)"; return txt1; } else { String txt2=coords.getDec().toString(); if (recalc) txt2=txt2+" (R)"; return txt2; } case 8: // return the object source catalog name return sk.getProperty(); default: return null; } } private int getAffectedSlit(int numObj) { // TODO Auto-generated method stub int idSlit=-1; Mask m=fov.getCurrentMaskOfCurrentImage(); for (int i=0; i<55;i++) { Slit s=m.getSlit(i); int affObj=s.getAffectedObject(); if (affObj==numObj) idSlit=i; } return idSlit; } /** * Erase the current mask. */ public void eraseMask() { eraseSpectra(); if (canevasD != null) divaImageGraphics.remove(canevasD); for (int i = 0; i < Mask._NBRSLITS_; i++) { if (canevasH[i] != null) divaImageGraphics.remove(canevasH[i]); if (canevasMH[i] != null) divaImageGraphics.remove(canevasMH[i]); if (canevasMB[i] != null) divaImageGraphics.remove(canevasMB[i]); if (canevasB[i] != null) divaImageGraphics.remove(canevasB[i]); if (canevasHS[i] != null) divaImageGraphics.remove(canevasHS[i]); if (canevasMHS[i] != null) divaImageGraphics.remove(canevasMHS[i]); if (canevasMBS[i] != null) divaImageGraphics.remove(canevasMBS[i]); if (canevasBS[i] != null) divaImageGraphics.remove(canevasBS[i]); } if (canevasT1 != null) divaImageGraphics.remove(canevasT1); if (canevasT2 != null) divaImageGraphics.remove(canevasT2); if (canevasT3 != null) divaImageGraphics.remove(canevasT3); if (canevasT4 != null) divaImageGraphics.remove(canevasT4); if (canevasM != null) divaImageGraphics.remove(canevasM); } /** * Erase the spectra affected to the mask to be erased. */ public void eraseSpectra() { for (int i = 0; i < Mask._NBRSLITS_; i++) { if (canevasSpectre[i] != null) divaImageGraphics.remove(canevasSpectre[i]); } } /** * Display the mask */ public void displayMask() { if (fov.getSelectedImage() < 0) currentImage = fov.getCurrentImage(); if (currentImage.getSelectedMask() < 0) return; currentMask = currentImage.getCurrentMask(); double mCenterX = currentMask.getCenter().getX(); double mCenterY = currentMask.getCenter().getY(); // maskDisplayCenter.x = currentMask.getCenter().getX(); // maskDisplayCenter.y = currentMask.getCenter().getY(); double resol = currentImage.getResol(); if (accessMenuInterface.isMenuDisplayPlotDetectorSelected()) { displayDetector(mCenterX, mCenterY, resol); } if (accessMenuInterface.isMenuDisplayPlotMaskSelected()) { displayPlotMask(currentMask, mCenterX, mCenterY, resol); } getTransformOfMask(currentMask); divaImageGraphics.repaint(); this.validate(); } /** * @param currentMask **/ private void getTransformOfMask(Mask currentMask) { at = navigatorImageDisplay.getAffineTransform(); at2.setToRotation(-currentMask.getOmega() * Math.PI / 180.0, currentMask.getCenter().getX(), currentMask.getCenter().getY()); at2.preConcatenate(at); divaImageGraphics.transform(at2); } /** * Drawing the mask on image. * @param currentMask * @param mkCenterX in canvas coord * @param mkCenterY * @param resol : image resolution */ private void displayPlotMask(Mask currentMask, double mkCenterX, double mkCenterY, double resol) { double l = currentMask.getlSlit2Display(); /** Get mask Canvas dimensions */ double width = currentMask.getWidth2Display(); double height = currentMask.getHeight2Display(); /** Get mask bottom left top corner coordinates in . coord */ /** Get mask left top corner coordinates in screen coord */ double maskStartX = mkCenterX - (width / 2.0); double maskStartY = mkCenterY - (height / 2.0); /** If the mask left bottom corner is not defined when displaying, fill it */ double maskStartYl = mkCenterY + (height / 2.0); //System.out.println("Visu Plot M X "+mkCenterX+" "+mkCenterY); Point2D.Double tmpCorner = new Point2D.Double(maskStartX, maskStartYl); currentMask.setLeftCornerPix(tmpCorner); displaySlits(currentMask, resol, l, height, maskStartX, maskStartY); displayAssociatedSlits(currentMask, resol, l, height, maskStartX, maskStartY); if ((accessMenuInterface.isMenuDisplayPlotMaskCenterSelected()) && (!currentMask.moveEnable) && (!currentMask.turnEnable)) { drawCross(mkCenterX, mkCenterY, Color.orange); } if (currentMask.moveEnable) { displayMovedMask(mkCenterX, mkCenterY, width, height, maskStartX, maskStartY); } if (currentMask.turnEnable) { displayTurnMask(currentMask); } isMaskDisplayed = true; } /** * Drawing the mask when turning. * @param currentMask */ private void displayTurnMask(Mask currentMask) { Point2D.Double tmp = new Point2D.Double(); // add to test - EB Point2D.Double mkCenter=new Point2D.Double(currentMask.getCenter().x,currentMask.getCenter().y); tmp=mkCenter; // end add //at2.transform(currentMask.getCenter(), tmp); Ellipse2D.Double ellipseH = new Ellipse2D.Double(tmp.x - 50, tmp.y - 50, 100, 100); canevasT1 = divaImageGraphics.makeEllipse(ellipseH, 1, trans, red, 5, null); divaImageGraphics.add(canevasT1); drawCross(tmp.x, tmp.y,red); if (evtMouse != null) { canevasT2 = divaImageGraphics.makeFigure(new Line2D.Double(tmp.x, tmp.y, evtMouse.getX(), evtMouse.getY()), red, red, lWidth); divaImageGraphics.add(canevasT2); } } /** Drawing the mask when moving. * @param mkCenterX (in canvas coord) * @param mkCenterY * @param width * @param height * @param maskDebutX * @param maskDebutY */ private void displayMovedMask(double mkCenterX, double mkCenterY, double width, double height, double maskDebutX, double maskDebutY) { Rectangle2D.Double peri = new Rectangle2D.Double(maskDebutX, maskDebutY, width, height); canevasM = divaImageGraphics.makeRectangle(peri, 1, trans, red, lWidth, null); divaImageGraphics.add(canevasM); drawCross(mkCenterX, mkCenterY, red); } /** * To draw a cross at the given coordinates . * (used for mask center) * @param x : x coordinate of the cross center * @param y : y coordinate of the cross center * @param co : drawing color * lWidth : line thickness */ private void drawCross(double x, double y, Color co) { canevasT3 = divaImageGraphics.makeFigure(new Line2D.Double(x - 10, y, x + 10, y), co, co, lWidth+1); divaImageGraphics.add(canevasT3); canevasT4 = divaImageGraphics.makeFigure(new Line2D.Double(x, y - 10, x, y + 10), co, co, lWidth+1); divaImageGraphics.add(canevasT4); } /** * Displaying joined slits when selected (TBC) * @param currentMask : displayed mask * @param resol : image resolution * @param l : mask length * @param height : mask height * @param maskStartX : x start mask coordinate * @param maskStartY : y start mask coordinate */ private void displayAssociatedSlits(Mask currentMask, double resol, double l, double height, double maskStartX, double maskStartY) { int selectedSlit = currentMask.getSelectedSlit(); int associatedMinSlit = currentMask.getAssociatedMinSlit(selectedSlit); int associatedMaxSlit = currentMask.getAssociatedMaxSlit(selectedSlit); if (associatedMinSlit < 0) associatedMinSlit = selectedSlit; if (associatedMaxSlit < 0) associatedMaxSlit = selectedSlit; for (int k = associatedMinSlit; k <= associatedMaxSlit; k++) { double X1 = maskStartX + l * k; double Y1 = maskStartY; double W1 = l; double SP = (currentMask.getSlit(k).PosMax + currentMask.getSlit(k).getPosition()) / resol; double SW = (currentMask.getSlit(k).getAperture()) / resol; double H1 = height - SP - (SW / 2.0); Rectangle2D.Double rect1 = new Rectangle2D.Double(X1, Y1, W1, H1); double X2 = maskStartX + l * k; double Y2 = maskStartY + H1 + SW; double W2 = l; double H2 = SP - (SW / 2.0); Rectangle2D.Double rect2 = new Rectangle2D.Double(X2, Y2, W2, H2); double X3 = X1; double Y3 = Y1 + H1; double W3 = l; double H3 = SW; Rectangle2D.Double rect3 = new Rectangle2D.Double(X3, Y3, W3, 0); Rectangle2D.Double rect4 = new Rectangle2D.Double(X3, Y3 + H3, W3, 0); canevasHS[k] = divaImageGraphics.makeRectangle(rect1, 1, greenTrans, green, lWidth, null); canevasBS[k] = divaImageGraphics.makeRectangle(rect2, 1, greenTrans, green, lWidth, null); canevasMHS[k] = divaImageGraphics.makeRectangle(rect3, 1, trans, yellow, lWidth, null); canevasMBS[k] = divaImageGraphics.makeRectangle(rect4, 1, trans, yellow, lWidth, null); divaImageGraphics.add(canevasHS[k]); divaImageGraphics.add(canevasBS[k]); divaImageGraphics.add(canevasMHS[k]); divaImageGraphics.add(canevasMBS[k]); // Non pas correct. // currentMask.getSlit(k).setPosXY((X2 + currentMask.getlSlit2Display() / 2.0), // (Y2 - SW / 2.0)); // double x, y; // x=X3+(W3/2); // y=Y3+(-H3/2); // Slit s=currentMask.getSlit(k); // System.out.println("Visu displAssSlit "+k+" "+X3+" "+Y3); } } /** * Displaying the mask slits @param currentMask : displayed mask * @param resol : image resolution * @param lg : mask length * @param height : mask height * @param maskStartX : x start mask coordinate * @param maskStartY : y start mask coordinate */ private void displaySlits(Mask currentMask, double resol, double lg, double height, double maskStartX, double maskStartY) { for (int i = 0; i < Mask.get_NBRSLITS_(); i++) { double X1 = maskStartX + lg * i; double Y1 = maskStartY; double W1 = lg; /** SW aperture size */ /** l : slit length */ double SP = (currentMask.getSlit(i).PosMax + currentMask.getSlit(i).getPosition()) / resol; double SW = (currentMask.getSlit(i).getAperture()) / resol; double H1 = height - SP - (SW / 2.0); Rectangle2D.Double rect1 = new Rectangle2D.Double(X1, Y1, W1, H1); double X2 = maskStartX + i * lg; double Y2 = maskStartY + H1 + SW; double W2 = lg; double H2 = SP - (SW / 2.0); Rectangle2D.Double rect2 = new Rectangle2D.Double(X2, Y2, W2, H2); double X3 = X1; double Y3 = Y1 + H1; double W3 = lg; double H3 = SW; Rectangle2D.Double rect3 = new Rectangle2D.Double(X3, Y3, W3, 0); Rectangle2D.Double rect4 = new Rectangle2D.Double(X3, Y3 + H3, W3, 0); double slitX; double slitY; double omg=currentMask.getOmega(); if (omg == 0.0) { slitX=X3+(lg/2.0); slitY=Y3+(H3/2.0); } else { slitX=X3+(Math.pow((Math.pow(lg,2)+Math.pow(SW,2)),(1/2))*(Math.cos(omg+Math.atan(SW/lg)))); slitY=Y3+(Math.pow((Math.pow(lg,2)+Math.pow(SW,2)),(1/2))*(Math.sin(omg+Math.atan(SW/lg))));; } // setSlitSkyCoord(currentMask, i, slitX, slitY); canevasH[i] = divaImageGraphics.makeRectangle(rect1, 1, blueTrans, blue, lWidth, null); canevasB[i] = divaImageGraphics.makeRectangle(rect2, 1, blueTrans, blue, lWidth, null); canevasMH[i] = divaImageGraphics.makeRectangle(rect3, 1, trans, yellow, lWidth, null); canevasMB[i] = divaImageGraphics.makeRectangle(rect4, 1, trans, yellow, lWidth, null); divaImageGraphics.add(canevasH[i]); divaImageGraphics.add(canevasB[i]); divaImageGraphics.add(canevasMH[i]); divaImageGraphics.add(canevasMB[i]); if (fov.getPlotSpectra() == FieldOfView._PLOTALL_ || currentMask.getPlotSpectrum(i) && fov.getPlotSpectra() != FieldOfView._PLOTNONE_) displaySpectra(i, X3, Y3, W3, H3); } } /** * Display Detector : the frame of the mask * @param mCenterX maskCenter * @param mCenterY * @param resol */ private void displayDetector(double mCenterX, double mCenterY, double resol) { double detectWidth = Detector._WIDTH_ / resol; double detectHeight = Detector._HEIGHT_ / resol; double detecDebutX = mCenterX - (detectWidth / 2.0); double detecDebutY = mCenterY - (detectHeight / 2.0); Rectangle2D.Double detector = new Rectangle2D.Double(detecDebutX, detecDebutY, detectWidth, detectHeight); canevasD = divaImageGraphics.makeRectangle(detector, 1, trans, salmon, lWidth, null); divaImageGraphics.add(canevasD); } /** * Display the spectrum to the selected slit which coordinates are in * parameters * * @param i * : slit id ?? * @param X * : X slit coordinate * @param Y * : Y slit coordinate * @param W * : slit Width * @param H * : slit Height */ public void displaySpectra(int i, double X, double Y, double W, double H) { if (fov.getCurrentImage().getCurrentMask().getSlit(i).getAffectedObject() < 0) return; Color orange = new Color(255, 128, 64); Color orangeTrans = new Color(255, 128, 64, 100); Rectangle2D.Double peri = new Rectangle2D.Double(X, (Y - H / 2.0) - 100, W, 200); canevasSpectre[i] = divaImageGraphics.makeRectangle(peri, 1, orangeTrans, orange, lWidth, null); divaImageGraphics.add(canevasSpectre[i]); } public void recalculateCentroid(SkyObject sk) { Image currentImage = fov.getCurrentImage(); Point2D.Double pos = new Point2D.Double(0.0,0.0); pos = positonCalcul(sk.getPosition()); sk.setPosPixRecalc(pos); sk.setColor(Color.GREEN); icc.imageToCanvasCoords(pos, false); sk.setObjWorldRecalc(getWorldCoords(pos.getX(), pos.getY())); /** * Information that the object center has been recalculated */ // String src=""; // if (!sk.getSrc().isEmpty()) src=sk.getSrc(); // // if (!sk.getSrc().endsWith("(R)")) // { // sk.setSrc(src + " (R)"); // } // /** * Update object position in the image associated List, when affected to a slit. */ for (int maskNum = 0; maskNum < currentImage.getNbrMasks(); maskNum++) { for (int slitNum = 0; slitNum < Mask.get_NBRSLITS_(); slitNum++) { if (currentImage.getMask(maskNum).getSlit(slitNum).getAffectedObject() == sk .getNum()) { currentImage.getMask(maskNum).getSlit(slitNum).setAffectedObject(-1); if (getSelectedSlit(pos.x, pos.y, currentImage.getMask(maskNum), false) == slitNum) associateObjectToSlit(sk.getNum(), currentImage.getMask(maskNum)); break; } } } } /** * Calculation of object position * @param skPos : object position * @return pos : new position after recalculation. */ private Point2D.Double positonCalcul( Point2D.Double skPos) { boolean isCentered = false; /** * While the center position is not good, calculate. */ Double compX=skPos.getX(); Double compY=skPos.getY(); Point2D.Double pos=new Point2D.Double(0.0,0.0); int i=0; while (!isCentered) { pos = computeCentroid(skPos, 10); i++; float resX=(float) (pos.getX()-compX); float resY=(float) (pos.getY()-compY); //if (pos.getX()!=compX) if (Math.abs( resX) > 0.5) { isCentered=false; compX=pos.getX(); skPos=pos; } else if (Math.abs( resY) > 0.5) { isCentered=false; compY=pos.getY(); skPos=pos; } else { isCentered=true; } if (i==6) break; } return pos; } /** * * @param pointer * : Point2D mouse position * @param n_win * : window dimensions to calculate the new centroid position * @return new centroid */ private Point2D.Double computeCentroid(Point2D.Double point, int n_win) { Point2D.Double pointer = new Point2D.Double(point.x, point.y); int ix = (int) Math.ceil(pointer.getX()); int iy = (int) Math.ceil(pointer.getY()); icc.imageToUserCoords(pointer, false); float value = navigatorImageDisplay.getPixelValue(pointer, 0); icc.userToImageCoords(pointer, false); double v_min = value * 9 / 10; double v_max = value * 3; int npixels = (int) Math.ceil(fov.getCurrentImage().getWidth()); int nlines = (int) Math.ceil(fov.getCurrentImage().getHeight()); int nca = (int) Math.ceil(n_win / 2.0); double sum = 0.0, xc = 0.0, yc = 0.0; int imin = ix - nca; if (imin < 1) imin = 1; int imax = ix + nca; if (imax > npixels) imax = npixels; int jmin = iy - nca; if (jmin < 1) jmin = 1; int jmax = iy + nca; if (jmax > nlines) jmax = nlines; for (int i = imin; i <= imax; i++) { for (int j = jmin; j <= jmax; j++) { pointer.setLocation(i, j); icc.imageToUserCoords(pointer, false); value = navigatorImageDisplay.getPixelValue(pointer, 0); icc.userToImageCoords(pointer, false); if (value >= v_min && value <= v_max) { xc += (value * i); yc += (value * j); sum += value; } } } if (sum > 0.0) { xc = xc / sum; yc = yc / sum; } else { xc = ix; yc = iy; } return new Point2D.Double(xc, yc); } /** * Erase all objects selected on the current image */ public void eraseAllObjects() { divaImageGraphics.getGraphicsPane().repaint(); for (int i = listCanvasObjects1.size() - 1; i >= 0; i--) { eraseObject(i); } } /** * Erase the object selected. * * @param i * : Object id */ public void eraseObject(int i) { divaImageGraphics.remove(listCanvasObjects1.get(i)); listCanvasObjects1.remove(i); divaImageGraphics.remove(listCanvasObjects2.get(i)); listCanvasObjects2.remove(i); divaImageGraphics.remove(listCanvasObjects3.get(i)); listCanvasObjects3.remove(i); divaImageGraphics.remove(listCanvasObjects4.get(i)); listCanvasObjects4.remove(i); } /** * Plot the pointed object * * @param i : Object id * Plot it with a cross, * */ public void plotObject(int i) { SkyObject sk = fov.getCurrentImage().getListObjects().get(i); //System.out.print(("visu Plot Obj"+sk.getNum()+" -")); SkyObject tempObject = new SkyObject(-1, sk.isRef(), sk.getPosPix(), sk.getPosPixRecalc(),sk.getColor()); //SkyObject tempObject = new SkyObject(-1, sk.isRef(), sk.getSrc(), sk.getCatLibFrom(), sk.getPosPix(), // sk.getObjWorldCenter(), sk.getPosPixRecalc(), sk.getPriority()); if (icc.isWCS()) { icc.imageToScreenCoords(tempObject.getPosition(), false); WorldCoords tempPosition=getWorldCoords(tempObject.getPosition().getX(), tempObject.getPosition().getY()); tempObject.setObjWorldCenter(tempPosition); } if (tempObject.isRef()) { drawCrossOnObject(i,tempObject); } else { drawSquareAroundObject(i, tempObject); } } /** * Draw a blue square around the object * @param i : id object * @param tempObject : object. */ private void drawSquareAroundObject(int i, SkyObject tempObject) { Color cl=tempObject.getColor(); //System.out.println("Visu DrawSqObj - "+i+" color "+cl.toString()); listCanvasObjects1.add(divaImageGraphics.makeFigure( new Line2D.Double(tempObject.getPosition().x - 5, tempObject.getPosition().y - 5, tempObject.getPosition().x + 5, tempObject.getPosition().y - 5), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects1.get(i)); listCanvasObjects2.add(divaImageGraphics.makeFigure( new Line2D.Double(tempObject.getPosition().x + 5, tempObject.getPosition().y - 5, tempObject.getPosition().x + 5, tempObject.getPosition().y + 5), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects2.get(i)); listCanvasObjects3.add(divaImageGraphics.makeFigure( new Line2D.Double(tempObject.getPosition().x + 5, tempObject.getPosition().y + 5, tempObject.getPosition().x - 5, tempObject.getPosition().y + 5), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects3.get(i)); listCanvasObjects4.add(divaImageGraphics.makeFigure( new Line2D.Double(tempObject.getPosition().x - 5, tempObject.getPosition().y + 5, tempObject.getPosition().x - 5, tempObject.getPosition().y - 5), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects4.get(i)); } /** * Draw cross on the object * @param i : id object * @param sk : Sky object * @param tempObject : object */ private void drawCrossOnObject(int i, SkyObject tempObject) { Point2D.Double pt = new Point2D.Double(); Color cl=tempObject.getColor(); pt = tempObject.getPosition(); // c = new Color(255, 0, 0); listCanvasObjects1.add(divaImageGraphics.makeFigure(new Line2D.Double(pt.x, pt.y - 10, pt.x, pt.y + 10), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects1.get(i)); listCanvasObjects2.add(divaImageGraphics.makeFigure(new Line2D.Double(pt.x - 10, pt.y, pt.x + 10, pt.y), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects2.get(i)); listCanvasObjects3.add(divaImageGraphics.makeFigure(new Line2D.Double(pt.x, pt.y - 10, pt.x, pt.y + 10), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects3.get(i)); listCanvasObjects4.add(divaImageGraphics.makeFigure(new Line2D.Double(pt.x - 10, pt.y, pt.x + 10, pt.y), cl, cl, lWidth)); divaImageGraphics.add(listCanvasObjects4.get(i)); } /** * When the objects are download from a server, they are displayed all * selected. */ public void plotAllObjects() { if (fov.getCurrentImage().getListObjects().size() <= 0) return; if (! accessMenuInterface.isMenuDisplayPlotObjectsSelected()) return; for (int i = 0; i < fov.getCurrentImage().getListObjects().size(); i++) { plotObject(i); } //System.out.println(""); plotBary(fov.getTheBrain().getBary()); } /** * Erase the barycenter */ public void eraseBary() { if (canvasBary != null) divaImageGraphics.remove(canvasBary); } /** * Plot the barycenter of all objects selected. * * @param b * : point to display. */ public void plotBary(Point2D.Double b) { accessMenuInterface.isMenuDisplayPlotObjectsSelected(); if (! accessMenuInterface.isMenuDisplayPlotObjectsSelected()) return; Point2D.Double temp = new Point2D.Double(b.getX(), b.getY()); eraseBary(); if (icc.isWCS()) icc.imageToScreenCoords(temp, false); // else // { // icc.imageToCanvasCoords(temp, false); // // temp.x = display.getWidth()/2.0 + ( temp.getX() // - fov.getCurrentImage().getCenter().getX() // ) * fov.getCurrentImage().getScale(); // temp.y = display.getHeight()/2.0 + ( temp.getY() // - fov.getCurrentImage().getCenter().getY() // ) * fov.getCurrentImage().getScale(); // } Ellipse2D.Double ellipse = new Ellipse2D.Double(temp.getX() - 3, temp.getY() - 3, 6, 6); canvasBary = divaImageGraphics.makeEllipse(ellipse, 1, red, red, 5, null); divaImageGraphics.add(canvasBary); divaImageGraphics.repaint(); } /** * Add an object on image * * @param type : type of the object (if it came from catalog, local cat or manually) * @param props : Libelle of where it comes from (catalog name, ...) or properties when it come from local catalog * @param c : coordinates of the object in image coordinates.
    * For the objects from catalog or from local import, * the position is converted from world to image. * @param priority : object priority, when it's set. * Set object world coordinates. * * Int id -> String id */ // public void addObject(int id, int type,String fromLib, Point2D.Double c, int priority) { public void addObject(String id, int type,String props, Point2D.Double c, int priority) { this.icc = new ImageCoordinateConverter(getNavigatorImageDisplay()); WorldCoords wcoord; //System.out.println("Visu addObj Ty "+type+" Pos "+c.x+","+c.y); if (type >-1) { /** From servers or local catalogs */ wcoord=new WorldCoords(c.x,c.y); icc.worldToImageCoords(c, false); } else { /** Choosen manually */ //System.out.print ("Visu Addobj else "); Point2D.Double tmpo=new Point2D.Double(c.x,c.y); icc.imageToCanvasCoords(tmpo,false); wcoord= getWorldCoords(tmpo.x,tmpo.y); } /** A verifier il peut y avoir des objets souhaités non visibles **/ // if (type > -1) // { // // if (navigatorImageDisplay.getPixelValue(c, 0) == 0) // { // System.out.println("Visu addObj not display"); // return; // } // } Image im=fov.getCurrentImage(); //System.out.print ("Visu Addobj "+ im.getNbrObjects() ); fov.getCurrentImage().addObject(id,false, type, props, c, wcoord, priority); fov.getCurrentImage().getLastObject().setObjWorldCenter(wcoord); fov.getTheBrain().computeBary(fov.getCurrentImage().getListObjects()); //System.out.println(" "+ im.getListObjects().size() ); updateByHand(); ospeControl.getActionControl().setSaveNeeded(true); ospeControl.getMainFrame().updateButtons(); } /** * Remove selected object * * @param i * : object id. */ public void removeObject(int i) { fov.getCurrentImage().removeObject(i); int idSlit=getAffectedSlit(i); if (idSlit>0) fov.getCurrentMaskOfCurrentImage().getSlit(idSlit).setAffectedObject(-1); fov.getTheBrain().computeBary(fov.getCurrentImage().getListObjects()); updateByHand(); } /** * Associate all the objects to a slit. * * @param theMask * : current mask. */ public void associateAllObjectsToSlits(Mask theMask) { List tempList = fov.getCurrentImage().getListObjects(); for (int i = 0; i < tempList.size(); i++) { associateObjectToSlit(i, theMask); } } /** * Set a slit to an object. * * @param numObject * : object id. * @param theMask * : current mask. * */ public void associateObjectToSlit(int numObject, Mask theMask) { SkyObject obj = fov.getCurrentImage().getListObjects().get(numObject); // Point2D.Double posObject = new Point2D.Double(obj.getPosition().getX(), obj.getPosition().getY()); Point2D.Double posObject=new Point2D.Double(obj.getObjWorldCenter().getX(), obj.getObjWorldCenter().getY()); // icc.imageToScreenCoords(posObject, false); icc.worldToScreenCoords(posObject, false); int slitNum = getSelectedSlit(posObject.x, posObject.y, theMask, true); if ((slitNum > 0) && (slitNum < 54)) { // System.out.println("DEBUG: VisuPanel::associateObjectToSlit : " // + "Associate Object(" + numObject + ") with Slit(" + (slitNum+1) // + // ")."); Integer affectedObjectNum = new Integer(theMask.getSlit(slitNum).getAffectedObject()); theMask.getHistory().addAction("setAffectedObject " + slitNum, affectedObjectNum); theMask.getSlit(slitNum).setAffectedObject(numObject); double oldAperture= theMask.getSlit(slitNum).getAperture(); theMask.getSlit(slitNum).setToDefaultAperture(); theMask.getHistory().addEntry("Change width of slit"); theMask.getHistory().addAction("setAperture " + slitNum, oldAperture); theMask.update(); } } /** * Select the slit to associate to an object. * Testing what slit the coordinates objects can be in. * * @param ex : object x coordinate * @param ey : object y coordinate * @param mask : the mask to search slits on * @param associate : true/false if the slit will be associated or no with the object. * @return slit id. : Slit number */ public int getSelectedSlit(double ex, double ey, Mask mask, boolean associate) { // distSrc : Distance between object coord and display center in display canvas values. Point2D.Double distSrc = new Point2D.Double(ex - (navigatorImageDisplay.getWidth() / 2.0), ey - (navigatorImageDisplay.getHeight() / 2.0)); // distDst : Distance after scale transformation Point2D.Double distDst = new Point2D.Double(); at.deltaTransform(distSrc, distDst); // Overwrite of distDst with rotation transformation double hyp = Math.sqrt((distDst.x * distDst.x) + (distDst.y * distDst.y)); double ang = (Math.acos(distDst.x / hyp) * 180.0 / Math.PI) % 180.0; if (distDst.y > 0) ang = (360.0 - ang) % 360.0; distDst.x = hyp * Math.cos((ang - mask.getOmega()) * Math.PI / 180.0); distDst.y = -hyp * Math.sin((ang - mask.getOmega()) * Math.PI / 180.0); // Compute distance between mask center and image center double dx2 = (mask.getCenter().getX() - fov.getCurrentImage().getCenter().getX()) * fov.getCurrentImage().getScale(); double dy2 = (mask.getCenter().getY() - fov.getCurrentImage().getCenter().getY()) * fov.getCurrentImage().getScale(); double hyp2 = Math.sqrt((dx2 * dx2) + (dy2 * dy2)); if (hyp2 != 0.0) { double ang2 = (Math.acos(dx2 / hyp2) * 180.0 / Math.PI) % 180.0; if (dy2 > 0) ang2 = (360.0 - ang2) % 360.0; dx2 = hyp2 * Math.cos((ang2 - mask.getOmega()) * Math.PI / 180.0); dy2 = -hyp2 * Math.sin((ang2 - mask.getOmega()) * Math.PI / 180.0); } double dx = (distDst.x / fov.getCurrentImage().getScale() - dx2); double dy = (distDst.y / fov.getCurrentImage().getScale() - dy2); double epY = mask.getHeight2Display() / 2.0 * fov.getCurrentImage().getScale(); if (Math.abs(dy) < epY) { if (Mask._NBRSLITS_ % 2 == 1) { dx = dx - (mask.getlSlit2Display() / 2.0 * fov.getCurrentImage().getScale()); } dx = dx / (mask.getlSlit2Display() * fov.getCurrentImage().getScale()); int selSlit = (int) Math.ceil(Mask._NBRSLITS_ / 2) + (int) Math.ceil(dx); if (selSlit > 0 && selSlit < ((Mask._NBRSLITS_)-1)) { /** If associated with an object */ if (associate) { double posY = mask.getSlit(selSlit).PosDef - (dy * fov.getCurrentImage().getResol()) / fov.getCurrentImage().getScale(); Double oldPosition = new Double(mask.getSlit(selSlit).getPosition()); mask.getHistory().addEntry("Affect object to slit"); mask.getHistory().addAction("setPosition " + selSlit, oldPosition); mask.getSlit(selSlit).setPosition(posY); // Point2D.Double p=new Point2D.Double(); // p.y=currentMask.getCenterDeg().getY()+posY; // p.x=currentMask.getCenterDeg().getX()+dx; // mask.getSlit(selSlit).setPosCenter(p); Point2D.Double p2=new Point2D.Double(); // p2=calculSlitCenterSkyPosition(currentMask, posY, selSlit); p2=testCalculSlitPos(currentMask, posY, selSlit); mask.getSlit(selSlit).setWcPosCenter(p2); Slit s= mask.getSlit(selSlit); //System.out.println("visu getSelSlit "+selSlit+" P2 "+p2.x+" "+p2.y+" "+s.getWcPosCenter().getRA()+" "+s.getWcPosCenter().getDec()); if (!mask.isAssigned) mask.isAssigned=true; if (selSlit == mask.getSelectedSlit() && !fov.getCurrentImage().searching) slide_position.setValue((int) Math.floor(posY)); ospeControl.getToolBar().getButtonUndoToolBar().setEnabled(true); } return selSlit; } } return -1; } private Point2D.Double testCalculSlitPos(Mask currentMask, double posY, int selSlit) { // TODO Auto-generated method stub Point2D.Double pt= new Point2D.Double(0.0,0.0); double lgSlit=6.5454; // in arcsec Point2D.Double cMk = currentMask.getCenterDeg(); double unitConv=0.00027777777777778; // convertir arc sec en degre int f=0; if (selSlit>27) { f=selSlit-27; } else { f=27-selSlit; } double py=0.0; double px=0.0; if (currentMask.getOmega()==0.0) { py=cMk.getY()+(posY* unitConv); px=cMk.getX()+(lgSlit*f* unitConv); } else { } //System.out.println("visu test Slit "+selSlit+" px "+px+" "+py); pt.setLocation(px, py); return pt; } /** * @param source * @param currentSlit * @param apeOri */ private void adjustSlitAperture(double value, Slit currentSlit, double apeOri) { if (apeOri >= 0) apeOri = apeOri - Math.floor(apeOri); else apeOri = apeOri - Math.ceil(apeOri); Double oldAperture = new Double(currentSlit.getAperture()); //System.out.print("Visu 2401 - fct adjAper : "+oldAperture+" val "+value+" ori "+apeOri); if (oldAperture.doubleValue() != value + apeOri) { //System.out.print("-> eff. "); fov.getCurrentImage().getCurrentMask().getHistory() .addEntry("Change width of slit"); fov.getCurrentImage().getCurrentMask().getHistory() .addAction("setAperture " + currentSlit.getId(), oldAperture); ospeControl.getToolBar().getButtonUndoToolBar().setEnabled(true); } //System.out.println(); currentSlit.setAperture(value + apeOri); fov.getCurrentImage().getCurrentMask().update(); //updateByHand(); modif pour voir. } /** * @param source * @param currentSlit * @param posOri */ private void adjustSlitPosition(double value, Slit currentSlit, double posOri) { posOri = posOri - Math.floor(posOri); Double oldPosition = new Double(currentSlit.getPosition()); //System.out.print("Visu 2425 - adjSlitPos - 1: "+oldPosition+" val "+value+" ori:"+posOri); if (oldPosition.doubleValue() != value + posOri) { //System.out.print(" -> eff. "); fov.getCurrentImage().getCurrentMask().getHistory() .addEntry("Change position of slit"); fov.getCurrentImage().getCurrentMask().getHistory() .addAction("setPosition " + currentSlit.getId(), oldPosition); ospeControl.getToolBar().getButtonUndoToolBar().setEnabled(true); } //System.out.println(); currentSlit.setPosition(value + posOri); updateByHand(); } /** * Action when mouse left button clic on image with a mask * @param e : mouse event * @param currentImage * @param currentMask */ private void onNavigatorImageDisplayleftMouseClick(MouseEvent e, final Image currentImage, final Mask currentMask) { //System.out.print(("Visu mouse left clic ")); //printTheMousePosition(e.getX(),e.getY()); Point2D.Double p=new Point2D.Double(e.getX(),e.getY()); this.icc.screenToCanvasCoords(p, false); Point2D.Double p2=new Point2D.Double(0.0,0.0); // distSrc : Distance between mouse click and display center in display pixels values. Point2D.Double distSrc = new Point2D.Double( e.getX() - (navigatorImageDisplay.getWidth() / 2.0), e.getY() - (navigatorImageDisplay.getHeight() / 2.0)); // distDst : Distance after scale transformation Point2D.Double distDst = new Point2D.Double(); at.deltaTransform(distSrc, distDst); // Overwrite of distDst with rotation transformation double hyp = Math.sqrt((distDst.x * distDst.x) + (distDst.y * distDst.y)); double ang = (Math.acos(distDst.x / hyp) * 180.0 / Math.PI) % 180.0; if (distDst.y > 0){ ang = (360.0 - ang) % 360.0; } distDst.x = hyp * Math.cos((ang - currentMask.getOmega()) * Math.PI / 180.0); distDst.y = -hyp * Math.sin((ang - currentMask.getOmega()) * Math.PI / 180.0); // Compute distance between mask center and image center double dx2 = (currentMask.getCenter().getX() - currentImage.getCenter().getX()) * currentImage.getScale(); double dy2 = (currentMask.getCenter().getY() - currentImage.getCenter().getY()) * currentImage.getScale(); double hyp2 = Math.sqrt((dx2 * dx2) + (dy2 * dy2)); if (hyp2 != 0.0) { double ang2 = (Math.acos(dx2 / hyp2) * 180.0 / Math.PI) % 180.0; if (dy2 > 0) ang2 = (360.0 - ang2) % 360.0; dx2 = hyp2 * Math.cos((ang2 - currentMask.getOmega()) * Math.PI / 180.0); dy2 = -hyp2 * Math.sin((ang2 - currentMask.getOmega()) * Math.PI / 180.0); } double dx = (distDst.x / currentImage.getScale() - dx2); double dy = (distDst.y / currentImage.getScale() - dy2); double epY = currentMask.getHeight2Display() / 2.0 * currentImage.getScale(); if (Math.abs(dy) < epY) { if (Mask._NBRSLITS_ % 2 == 1) { dx = dx - (currentMask.getlSlit2Display() / 2.0 * currentImage.getScale()); } dx = dx / (currentMask.getlSlit2Display() * currentImage.getScale()); int selSlit = (int) Math.ceil(Mask._NBRSLITS_ / 2) + (int) Math.ceil(dx); if (selSlit >= 0 && selSlit < Mask._NBRSLITS_) { if (e.isControlDown()) { displayJoinSlitDialog(currentMask, selSlit); } else { if (e.getClickCount() >= 2) { double posY = currentMask.getCurrentSlit().PosDef - (dy * currentImage.getResol()) / currentImage.getScale(); slide_position.setValue((int) Math.floor(posY)); Slit s=currentMask.getCurrentSlit(); double oldSlitPos=s.getPosition(); if (oldSlitPos != posY) { s.setAffectedObject(-1); } s.setPosition(posY); s.setToDefaultAperture(); // s.setPosCenter(p); // mouse position int is=s.getId(); p2=calculSlitCenterSkyPosition(currentMask, posY, is); // Set slit center coordinates. s.setWcPosCenter(p2); //System.out.println("visu Clic2 "+is+" P2 "+p2.x+" "+p2.y+" "+s.getWcPosCenter().getRA()+" "+s.getWcPosCenter().getDec()); currentMask.update(); } slitCombo.setSelectedIndex(selSlit); //updateSlides(); } } } } /** * Calculation Slit center Sky position * @param currentMask : current mask * @param posY : slit position on mask * @param idSlit : slit id */ public Point2D.Double calculSlitCenterSkyPosition(final Mask currentMask, double posY, int idSlit) { Point2D.Double p2=new Point2D.Double(0.0,0.0); double raDeg = currentMask.getCenterDeg().getX(); double decDeg= currentMask.getCenterDeg().getY(); double raMk=raDeg*Math.PI/180.0; double decMk=decDeg*Math.PI/180.0; p2.y=currentMask.getCenterDeg().getY()+(posY/3600.0); double om=currentMask.getOmega()*Math.PI/180.0; double fv=400.0; double hs=fv/currentMask._NBRSLITS_; double hsr=hs*Math.PI/180.0/3600.0; double nbslit=(double)27-(idSlit); double x0=(nbslit*hsr); double n0=posY*Math.PI/180.0/3600.0; double xi=x0*Math.cos(om)+n0*Math.sin(om); double ni=-x0*Math.sin(om)+n0*Math.cos(om); double rai=raMk+ Math.atan(xi/(Math.cos(decMk)-ni*Math.sin(raMk))); double dai=Math.asin((Math.sin(decMk)+ ni*Math.cos(decMk))/(Math.sqrt(1+Math.pow(ni, 2)+Math.pow(xi, 2) ))); p2.x=rai; //p2.y=dai; p2.x=rai*180/Math.PI; //p2.y=dai*180/Math.PI; return p2; } /** * @param currentMask * @param selSlit */ private void displayJoinSlitDialog(final Mask currentMask, int selSlit) { int n1 = currentMask.getSelectedSlit(); int n2 = selSlit; if (n2 < n1) { int temp = n1; n1 = n2; n2 = temp; } new OSPE_QuickJoinSlitsPanel(currentMask,ospeControl, n1, n2); } /** What happens on rigth Mouse Click : * @param e : mouse event * @param currentImage * @param currentMask : if there is a current mask * @param objectId : if the click is on an object, get its id. */ private void rigthMouseClick(MouseEvent e, final Image currentImage, final Mask currentMask, int objectId) { // If a mask is moving or turning int mMaskFlag = ospeControl.getMaskControl().getmMaskFlag(); if ((mMaskFlag == 1) || (mMaskFlag == 2)) { // stop the moves accessMenuInterface.clickOnMaskStop(); Mask m=fov.getCurrentMaskOfCurrentImage(); isMaskDisplayed = true; updateMaskCoords(m); } else { // if the mask is displayed or not if (!isMaskDisplayed) { // Turn off the "assign to slit" option mouseObjectPopupMenu.getComponent(5).setVisible(false); mouseObjectPopupMenu.getComponent(6).setVisible(false); } else { // Turn on the "assign to slit" option mouseObjectPopupMenu.getComponent(5).setVisible(true); mouseObjectPopupMenu.getComponent(6).setVisible(true); } final Point locationOnScreen = navigatorImageDisplay.getLocationOnScreen(); /** * If there is an object designed */ if (objectId >= 0) { // Checkbox if the object id referenced if (currentImage.getListObjects().get(objectId).isRef()) ((JCheckBoxMenuItem) mouseObjectPopupMenu.getComponent(0)).setSelected(true); else ((JCheckBoxMenuItem) mouseObjectPopupMenu.getComponent(0)).setSelected(false); int affectedSlitNum = searchAffectedSlitToObject(objectId); if (affectedSlitNum >= 0) { mouseObjectPopupMenu.getComponent(1).setVisible(true); mouseObjectPopupMenu.getComponent(2).setVisible(true); if (currentMask.getPlotSpectrum(affectedSlitNum)) ((JMenuItem) mouseObjectPopupMenu.getComponent(2)).setText("unplot spectrum"); else ((JMenuItem) mouseObjectPopupMenu.getComponent(2)).setText("plot spectrum"); } else { mouseObjectPopupMenu.getComponent(1).setVisible(false); mouseObjectPopupMenu.getComponent(2).setVisible(false); } if (currentImage.getListObjects().get(objectId).isCenterRecalc()) { mouseObjectPopupMenu.getComponent(9).setVisible(true); mouseObjectPopupMenu.getComponent(10).setVisible(true); } else { mouseObjectPopupMenu.getComponent(9).setVisible(false); mouseObjectPopupMenu.getComponent(10).setVisible(false); } // Display the popup menu at the pointer position? Point p = new Point((int) locationOnScreen.getX() + e.getX(), (int) locationOnScreen.getY() + e.getY()); mouseObjectPopupMenu.setLocation(p); mouseObjectPopupMenu.setVisible(true); } else { if (!isPickObjFrame) { // Add objects manually ? Point p = new Point((int) locationOnScreen.getX() + e.getX(), (int) locationOnScreen.getY() + e.getY()); mouseGeneralPopupMenu.setLocation(p); mouseGeneralPopupMenu.setVisible(true); } } } } /** * Update mask center world coordinates * @param m : current mask * Called when stop moving. */ public void updateMaskCoords(Mask m) { // TODO Auto-generated method stub Point2D.Double pt=new Point2D.Double(m.getCenter().getX(), m.getCenter().getY()); // System.out.println(" MaskCenter x: "+pt.x+" y: "+pt.y); icc.userToImageCoords(pt, false); // System.out.print(" U2Im x: "+pt.x+" y: "+pt.y); icc.imageToWorldCoords(pt, false); // WorldCoords wc = new WorldCoords(pt.x,pt.y); m.setCenterWc(pt.x,pt.y); // System.out.println(" I2Wc x: "+m.getMaskCenterWordlCoord().getRA()+" y: "+m.getMaskCenterWordlCoord().getDec()); } /** * Change point coordinates from canvas to world Coordinates. * @param x * @param y * @return : Word coordinates */ public WorldCoords getWorldCoords(double x, double y) { Point2D.Double coordInSky = new Point2D.Double(x, y); icc.canvasToWorldCoords(coordInSky, false); return new WorldCoords(coordInSky.getX(), coordInSky.getY()); } /** What mouse motion can do in navigator image display * @param x : x mouse position on screen * @param y : y mouse position on screen */ private void onNavigatorImageDisplayMouseMoved(final int x, final int y) { if (fov.getSelectedImage() < 0) return; // final PlanarImage image = navigatorImageDisplay.getImage(); Image image = fov.getCurrentImage(); if (image != null) { if (icc.isWCS() == true) { boolean isOnImage = isOnImage(x, y, image); // Then Get them and print them. if (isOnImage == true) { icc.screenToCanvasCoords(pointerPosDble, false); jLabelDisplay.setText(getWorldCoords(pointerPosDble.getX(), pointerPosDble.getY()).toString()); } //else System.out.print("."); setLabelFovSize(); } else { jLabelDisplay.setText("WARNING: World Coordinates Convertion" + " is not available !"); } } } /** * Test if the mouse is on image * @param x * @param y * @param image * @return */ private boolean isOnImage(final int x, final int y, Image image) { boolean isOnImage = false; /** * Get the image navigator screen coordinates * to test if the pointer is on the image screen location */ // Point left top image corner min Point2D.Double coordImMin = new Point2D.Double(); // point right bottom image corner Max Point2D.Double coordImMax = new Point2D.Double(); /** Image Limits */ coordImMin.setLocation(0, 0); coordImMax.setLocation(image.getWidth(), image.getHeight()); // Point left top image corner // min in screen Point2D.Double coordInScreenMin = new Point2D.Double(); // point right bottom image corner // Max in screen Point2D.Double coordInScreenMax = new Point2D.Double(); // Convert those coordinates in screen coord. icc.imageToScreenCoords(coordImMin, false); icc.imageToScreenCoords(coordImMax, false); /** Set the min and the max on screen coord */ double valx1, valx2,valy1, valy2; if (coordImMin.getX() < coordImMax.getX()) { valx1=coordImMin.getX(); valx2=coordImMax.getX(); } else { valx1=coordImMax.getX(); valx2=coordImMin.getX(); } if (coordImMin.getY() < coordImMax.getY()) { valy1=coordImMin.getY(); valy2=coordImMax.getY(); } else { valy1=coordImMax.getY(); valy2=coordImMin.getY(); } coordInScreenMin.setLocation(valx1, valy1); coordInScreenMax.setLocation(valx2, valy2); // Get the mouse position in screen coord. pointerPosDble = new Point2D.Double(x, y); // set the mouse position in screen coord mousePosition=new Point2D.Double(x, y); // Test if pointer is on Image if (pointerPosDble.x > coordInScreenMin.getX() && pointerPosDble.x < coordInScreenMax.getX() && pointerPosDble.y > coordInScreenMin.getY() && pointerPosDble.y < coordInScreenMax.getY()) isOnImage = true; return isOnImage; } /** * To go to the specify slit * * @param numSlit336251362621055E */ public void moveToSlit(int numSlit) { AffineTransform at3 = new AffineTransform(); final Mask currentMask = fov.getCurrentImage().getCurrentMask(); at3.setToRotation(-currentMask.getOmega() * Math.PI / 180.0, currentMask.getCenter().getX(), currentMask.getCenter().getY()); Point2D.Double tmp = new Point2D.Double(); at3.transform(currentMask.getSlit(numSlit).getPosXY(), tmp); fov.getCurrentImage().setCenter(tmp); } /** * Sets the image zoom. * * @param echelleNew * : new field displaying scale. */ public void zoomSet(float echelleNew) { navigatorImageDisplay.setScale(echelleNew); navigatorImageDisplay.updateImage(); fov.setScale(echelleNew); statusInterface.setStatusBarText(Color.blue, "INFO: Image scale is reset to "+ echelleNew); } /** * To zoom the screen field of the image. * */ private void zoomIn() { zoom(true); } /** * To zoom out the display. */ private void zoomOut() { zoom(false); } protected void zoom(boolean in) { float zoomFactor = navigatorImageDisplay.getScale(); if (in) { if (zoomFactor < 1.0) { int i = Math.round(1.0F / zoomFactor) - 1; zoomFactor = 1.0F / i; } else { zoomFactor += 1; } } else { if (zoomFactor <= 1.0) { int i = Math.round(1.0F / zoomFactor) + 1; zoomFactor = 1.0F / i; } else { zoomFactor -= 1; } } if (zoomFactor < ImageDisplayMenuBar.MIN_SCALE || zoomFactor > ImageDisplayMenuBar.MAX_SCALE) { return; } navigatorImageDisplay.setScale(zoomFactor); navigatorImageDisplay.updateImage(); fov.setScale(zoomFactor); setLabelFovSize(); if (!in){ statusInterface.setStatusBarText(Color.blue, "INFO: Image scale is decreased !"); } else { statusInterface.setStatusBarText(Color.blue, "INFO: Image scale is increased !"); } } /** * Test if there are reference objects before writing or validating the mask * * @return true if there are at least 4 reference objects on the mask */ public boolean testRefObjects() { List refObjectsList = new ArrayList(); if (fov.getCurrentImage().getCurrentMask().getRefObjectsList().size()== 0 ) { refObjectsList = fov.getCurrentImage().getCurrentMask().getRefObjects(); return refObjectsList != null && refObjectsList.size() >= 3; } else return true; } @Override public CatalogNavigator getNavigator() { return getNavigatorImageDisplay().getNavigator(); } public Object getImageProcessor() { return getNavigatorImageDisplay().getImageProcessor(); } public FieldOfView getFov() { return fov; } /** * Updates the cut levels and sets them to those of the * kth image. * * @param k * Image number. */ @Override public void updateCutLevels(int k) { double hi, lo; // High/Low cut levels values for the image. //System.out.println("visu 2694 num:"+ k+" hi "+fov.getImage(k).getHighCut()+" lo "+fov.getImage(k).getLowCut()); hi = fov.getImage(k).getHighCut(); lo = fov.getImage(k).getLowCut(); getNavigatorImageDisplay().getImageProcessor().setDefaultColormap(); getNavigatorImageDisplay().getImageProcessor().setCutLevels(lo, hi); getImageCutDialog().updateCutLevels(lo, hi); getNavigatorImageDisplay().getImageProcessor().update(); } @Override public void updateColors(int k) { String cmap; String cIntens; int cAlg; cmap = fov.getImage(k).getColorMap(); cIntens = fov.getImage(k).getColorIntensity(); cAlg = fov.getImage(k).getColorAlgorithm(); if (cmap != null) { getNavigatorImageDisplay().getImageProcessor().setColorLookupTable(cmap); } if (cIntens != null) { getNavigatorImageDisplay().getImageProcessor().setIntensityLookupTable(cIntens); } getNavigatorImageDisplay().getImageProcessor().setScaleAlgorithm(cAlg); // if ((cmap != null) || (cIntens != null) || (cAlg>0)) // visuPanel.imColorsPanel.imageColors.updateColors(fov.getImage(k)); } @Override public void updateOfImageNavigatorDisplay() { // Add test getNavigatorImageDisplay().getImageProcessor().update(); //getNavigatorImageDisplay().updateImage(); } @Override public void enableValidateAndGenerateButton(boolean maskValidated) { if (maskValidated) { validateButton.setText("Unvalidate"); } else { validateButton.setText("Validate"); } if (!validateButton.isEnabled()) validateButton.setEnabled(true); if (!writeButton.isEnabled()) writeButton.setEnabled(true); } public OspeControl getOspeControl() { return ospeControl; } public ImageCoordinateConverter getIcc() { return icc; } /** * @param e */ private void onNavigatorImageDisplayMouseDragged(MouseEvent e) { if (e.getModifiers() != InputEvent.BUTTON1_MASK) // left button return; evtMouse = e; double scale = navigatorImageDisplay.getScale(); // if (fov.getSelectedImage() >= 0) // scale = fov.getCurrentImage().getScale(); double dX = (originPointer.getX() - e.getX()) / scale; double dY = (originPointer.getY() - e.getY()) / scale; if (fov.getSelectedImage() >= 0) { if (fov.getCurrentImage().getSelectedMask() >= 0) { final Mask currentMask = fov.getCurrentMaskOfCurrentImage(); if (currentMask.moveEnable && !currentMask.turnEnable) { // System.out.println("visu move enable "); // Move the mask Point2D.Double tmpMask = new Point2D.Double(); // get the new mask's coordinates tmpMask.setLocation(maskDisplayCenter.getX() - dX, maskDisplayCenter.getY() - dY); currentMask.setCenter(tmpMask); // set the new mask's coordinates WorldCoords wc = getWorldCoords(tmpMask.getX(), tmpMask.getY()); currentMask.setCenterWc(wc.getRaDeg(), wc.getDecDeg()); // icc.canvasToWorldCoords(tmpMask, false); // icc.userToWorldCoords(tmpMask, false); // Point2D.Double tmp = new Point2D.Double(); // tmp.x = wc.getRaDeg(); // tmp.y = wc.getDecDeg(); // currentMask.setCenterDeg(tmpMask); // // // set the new mask's Corner left coordinates // double width = currentMask.getWidth2Display(); // double height = currentMask.getHeight2Display(); // double maskDebutX = tmpMask.getX() - (width / 2.0); // double maskDebutY = tmpMask.getY() - (height / 2.0); // // Point2D.Double tmpCorner = new Point2D.Double(); // tmpCorner.setLocation(maskDebutX, maskDebutY); // currentMask.setLeftDownCornerPix(tmpCorner); // // wc = getWorldCoords(tmpCorner.getX(), tmpCorner.getY()); //// currentMask.setAlphaCorner(wc.getRA()); //// currentMask.setDeltaCorner(wc.getDec()); // currentMask.setLeftCornerWc(wc.getRaDeg(), wc.getDecDeg()); // // // Point2D.Double tmpC = new Point2D.Double(); // tmpC.x = wc.getRaDeg(); // tmpC.y = wc.getDecDeg(); // currentMask.setLeftDownCornerDeg(tmpC); currentMask.update(); return; } if (!currentMask.moveEnable && currentMask.turnEnable) { // Turn the mask double Xopt = (originPointer.getX() - maskDisplayCenter.getX()); double Yopt = -(originPointer.getY() - maskDisplayCenter.getY()); double Xevt = (evtMouse.getX() - maskDisplayCenter.getX()); double Yevt = -(evtMouse.getY() - maskDisplayCenter.getY()); if ((Xopt == 0.0 || Yopt == 0.0) || (Xevt == 0.0 || Yevt == 0.0)) return; double A_originPointer = Math.atan(Yopt / Xopt); A_originPointer = A_originPointer * 180.0 / Math.PI; if (Xopt > 0.0 && Yopt < 0.0) A_originPointer = 360.0 + A_originPointer; if (Xopt < 0.0 && Yopt < 0.0) A_originPointer = 180.0 + A_originPointer; if (Xopt < 0.0 && Yopt > 0.0) A_originPointer = 180.0 + A_originPointer; double A_evtMouse = Math.atan(Yevt / Xevt); A_evtMouse = A_evtMouse * 180.0 / Math.PI; if (Xevt > 0.0 && Yevt < 0.0) A_evtMouse = 360.0 + A_evtMouse; if (Xevt < 0.0 && Yevt < 0.0) A_evtMouse = 180.0 + A_evtMouse; if (Xevt < 0.0 && Yevt > 0.0) A_evtMouse = 180.0 + A_evtMouse; double dAngle = A_evtMouse - A_originPointer; double angle = (originAngle + dAngle) % 360.0; currentMask.setOmega(angle); currentMask.update(); return; } }// Fi a mask is on the image and move or turn activated. /**Calculate the new position of the image center in screen coord. */ Point2D.Double tmpImage = new Point2D.Double(); tmpImage.setLocation(centerImage.getX() + dX, centerImage.getY() + dY); if (tmpImage.x < 0.0) tmpImage.x = 0.0; if (tmpImage.x > fov.getCurrentImage().getWidth()) tmpImage.x = fov.getCurrentImage().getWidth() - 1; if (tmpImage.y < 0.0) tmpImage.y = 0.0; if (tmpImage.y > fov.getCurrentImage().getHeight()) tmpImage.y = fov.getCurrentImage().getHeight() - 1; fov.getCurrentImage().setCenter(tmpImage); fov.getCurrentImage().update(); } else { originPointer.setLocation(originPointer.x - dX, originPointer.y - dY); Point2D.Double tmpImage = new Point2D.Double(); tmpImage.setLocation(navigatorImageDisplay.getOrigin().x + dX, navigatorImageDisplay.getOrigin().y + dY); navigatorImageDisplay.setOrigin(tmpImage); navigatorImageDisplay.updateImage(); } // imagePanner.update(imagePanner.getGraphics()); } public void closePickObjFrame() { isPickObjFrame = false; accessMenuInterface.enableButtonsForPicObject(true); getFov().update(); } @Override public void addImageFromServerToProject() { // Copy the remote file on project's directory final String filename = getNavigatorImageDisplay().getFilename(); String pathOfFitsFile = new String(filename); if (filename != null){ final File source = new File(pathOfFitsFile); final File destination = new File(fov.getPath() + File.separator + source.getName()); if (!FileUtil.copyTo(source, destination)) { new CustomJDialog("Impossible to copy the image in the workspace !", CustomJDialog._ERROR_, CustomJDialog._CLOSE_BUTTON_, this); return; } try { ospeControl.addImageToProject(destination); } catch (IOException | FitsException e) { e.printStackTrace(); } currentImage=fov.getCurrentImage(); } } /** * testing the mouse position and the various conversions * @param x : X screen coord * @param y : Y screen coord */ private void printTheMousePosition(int x, int y) { Image image = fov.getCurrentImage(); // Point left top image corner // min in screen Point2D.Double coordInScreenMin = new Point2D.Double(); // point right bottom image corner // Max in screen Point2D.Double coordInScreenMax = new Point2D.Double(); /** This coords are in canvas coord */ coordInScreenMin.setLocation(0, 0); coordInScreenMax.setLocation(image.getWidth(), image.getHeight()); //System.out.println("w "+image.getWidth()+" H "+image.getHeight()); icc.imageToScreenCoords(coordInScreenMax, false); icc.imageToScreenCoords(coordInScreenMin, false); System.out.println("Visu:printMousePos screen x: "+x+" y: "+y+" "+ isOnImage(x, y, image)); Point2D.Double ptTmp = new Point2D.Double(x,y); Point2D.Double ptTmp2 = new Point2D.Double(x,y); Point2D.Double ptTmp3 = new Point2D.Double(x,y); Point2D.Double ptTmp4 = new Point2D.Double(x,y); icc.screenToImageCoords(ptTmp2, false); System.out.print(" Image x: "+ptTmp2.x+" y: "+ptTmp2.y); icc.screenToUserCoords(ptTmp4, false); System.out.print(" User x: "+ptTmp4.x+" y: "+ptTmp4.y); icc.screenToCanvasCoords(ptTmp, false); System.out.println(" Canva x: "+ptTmp.x+" y: "+ptTmp.y); //System.out.println("Im Screen Min "+coordInScreenMin.getX()+","+ coordInScreenMin.getY()+" Max "+coordInScreenMax.getX()+","+ coordInScreenMax.getY()); icc.screenToWorldCoords(ptTmp3, false); WorldCoords wcTmp= getWorldCoords(ptTmp.getX(),ptTmp.getY()); //System.out.print(" xdeg: "+wcTmp.getRaDeg()+" ydeg: "+wcTmp.getDecDeg()); System.out.println(" x: "+wcTmp.getRA()+" y: "+wcTmp.getDec()+" x: "+wcTmp.getRaDeg()+" y: "+wcTmp.getDecDeg()); //Mask m=fov.getCurrentMaskOfCurrentImage(); //System.out.println(" mask Om : "+m.getOmega()); } @Override public String setNewImageCatalog(String cat) { newImageCatalog=cat; return null; } public String getNewImageCatalog() { return newImageCatalog; } @Override public String setNewImageName(String imName) { newImageName=imName; return null; } public String getNewImageName() { return newImageName; } public void getImageDisplayParameters(Image currIm) { imResol=currIm.getResol(); imWidth=currIm.getWidth(); imHeight=currIm.getHeight(); imScale=currIm.getScale(); imCenter=currIm.getCenter(); } public void getMaskDisplayParameters(Mask mk) { maskDisplayCenter=mk.getCenter(); maskDisplayLeftCorner=mk.getLeftCornerPix(); } public Point2D.Double setNewMaskCenter(Point2D.Double pt) { Point2D.Double tmpPoint=new Point2D.Double(pt.x,pt.y); icc.worldToUserCoords(tmpPoint, false); Point2D.Double newMaskCenter=new Point2D.Double(tmpPoint.x,tmpPoint.y); return newMaskCenter; } }