package osp.ui; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.Point2D; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import jsky.catalog.QueryResult; import jsky.catalog.gui.CatalogNavigator; import jsky.catalog.gui.CatalogQueryPanel; import jsky.catalog.gui.CatalogTreeControlPanel; import jsky.catalog.skycat.SkycatTable; import jsky.catalog.vo.VoTable; import jsky.coords.Coordinates; import jsky.navigator.NavigatorQueryTool; /** * Catalog windows To choose some images, some objects to display in the visu * field. * */ public class OSPE_NavigatorFrame extends JDialog { private static final long serialVersionUID = 1L; private VisuPanelNavigatorInterface visuPanel; private JPanel contentPane; private CatalogNavigator naviPanel; private JPanel buttonsPanel; private JButton buttonAddClose; private JButton buttonCancel; public enum TypeNavigator {IMAGE, OBJECT}; private TypeNavigator typeNavigator = null; /** * * @param owner * @param v * @param i * i=1 for Object Menu i=0 for Image Menu */ public OSPE_NavigatorFrame(JFrame owner, VisuPanelNavigatorInterface v) { super(owner); this.visuPanel = v; this.buttonsPanel = new JPanel(); buttonsPanel.add(getCancelButton()); buttonsPanel.add(getAddAndCloseButton()); contentPane = new JPanel(new BorderLayout()); contentPane.add(getCatalogNavigator(), BorderLayout.CENTER); contentPane.add(buttonsPanel, BorderLayout.SOUTH); setTypeNavigator(TypeNavigator.IMAGE); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setContentPane(contentPane); pack(); // setModal(true); setVisible(true); } /** * */ private JButton getAddAndCloseButton() { if (buttonAddClose == null) { buttonAddClose = new JButton("Add and Close"); setAlwaysOnTop(true); buttonAddClose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (typeNavigator == TypeNavigator.IMAGE) { addImage(); } else if (typeNavigator == TypeNavigator.OBJECT) { addObjectAndClose(); } } }); } return buttonAddClose; } /** * */ protected void addImage() { QueryResult qResult = naviPanel.getQueryResult(); if (qResult != null) { boolean test = false; do { try { Thread.sleep(100); } catch (InterruptedException e1) { e1.printStackTrace(); } test = naviPanel.getQueryComponent() instanceof NavigatorQueryTool; } while (!test); NavigatorQueryTool naviQTool = (NavigatorQueryTool) naviPanel.getQueryComponent(); // naviQTool.setFromImage(true,false); /* * Outils a utiliser * * * // set the values in the query panel * CatalogQueryPanel catalogQueryPanel = * getCatalogQueryPanel(); QueryArgs queryArgs = * catalogQueryPanel.getQueryArgs(); * * if (mag != null) { * queryArgs.setParamValueRange("mag", mag[0], * mag[1]); } * catalogQueryPanel.setQueryArgs(queryArgs); */ CatalogQueryPanel catQueryPanel =naviQTool.getCatalogQueryPanel(); // QueryArgs qArgs=catQueryPanel.getQueryArgs(); //System.out.println("Query Args : "+qArgs); JComponent compImage=catQueryPanel.getComponentForLabel("Object"); JTextField compImName= (JTextField) compImage; String catImage= catQueryPanel.getCatalog().getName(); visuPanel.setNewImageCatalog(catImage); visuPanel.setNewImageName(compImName.getText()); /* * JSplitPane spliP1=(JSplitPane) * naviPanel.getComponent(0); * System.out.println(i++); queryComponents(spliP1); * JSplitPane spliP2=(JSplitPane) * spliP1.getComponent(0); System.out.println(i++); * queryComponents(spliP2); JPanel jlP=(JPanel) * spliP1.getComponent(1); System.out.println(i++); * queryComponents(jlP); JPanel jlP2=(JPanel) * jlP.getComponent(0); System.out.println(i++); * queryComponents(jlP2); */ visuPanel.addImageFromServerToProject(); } dispose(); } /** * */ private JButton getCancelButton() { if (buttonCancel == null) { buttonCancel = new JButton("Cancel"); buttonCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { naviPanel.unplot(); dispose(); } }); } return buttonCancel; } /** * @return */ private CatalogNavigator getCatalogNavigator() { if (naviPanel == null) { naviPanel = visuPanel.getNavigator(); naviPanel.clear(); naviPanel.clearQueryList(); } return naviPanel; } /** * Add the objects on the project */ protected void addObjectAndClose() { final QueryResult queryResult = naviPanel.getQueryResult(); int nbCat = visuPanel.getOspeControl().getNbLoadCat(); nbCat++; String [] tab = new String[5]; visuPanel.getOspeControl().setNbLoadCat(nbCat); if (queryResult instanceof SkycatTable) { SkycatTable theSkyCatTable = ((SkycatTable)naviPanel.getQueryResult()); Point2D.Double pos = new Point2D.Double(); int nbrSkyObject = theSkyCatTable.getRowCount(); int prior=0; for (int i = 0; i < nbrSkyObject; i++) { Coordinates coordinates = theSkyCatTable.getCoordinates(i); pos.x = coordinates.getX(); pos.y = coordinates.getY(); String catName=theSkyCatTable.getCatalog().getName(); String numObj=String.valueOf(i); // visuPanel.addObject(i,nbCat, catName, pos, prior); visuPanel.addObject(numObj,nbCat, catName, pos, prior); } } else if (queryResult instanceof VoTable) { VoTable theSkyCatTable = ((VoTable) queryResult); Point2D.Double pos = new Point2D.Double(); int nbrSkyObject = theSkyCatTable.getRowCount(); int prior=0; for (int i = 0; i < nbrSkyObject; i++) { Coordinates coordinates = theSkyCatTable.getCoordinates(i); pos.x = coordinates.getX(); pos.y = coordinates.getY(); String catName=theSkyCatTable.getCatalog().getName(); // visuPanel.addObject(i,nbCat,catName, pos,prior); String numObj=String.valueOf(i); // visuPanel.addObject(i,nbCat, catName, pos, prior); visuPanel.addObject(numObj,nbCat, catName, pos, prior); } } naviPanel.unplot(); dispose(); } /** * @return the typeNavigator */ public TypeNavigator getTypeNavigator() { return typeNavigator; } /** * @param typeNavigator the typeNavigator to set */ public void setTypeNavigator(TypeNavigator typeNavigator) { this.typeNavigator = typeNavigator; if (typeNavigator == TypeNavigator.IMAGE) { setTitle("Load Image from Server"); buttonAddClose.setText("Add Image and Close"); selectOnlyImage(); } else if (typeNavigator == TypeNavigator.OBJECT){ setTitle("Add Objects from Catalog"); buttonAddClose.setText("Add Objects and Close"); selectOnlyObjects(); } } /** * Select only image catalog */ public void selectOnlyImage() { CatalogTreeControlPanel catalogTreeControlPanel = naviPanel.getCatalogTree().getControlPanel(); if (catalogTreeControlPanel.getCatalogButton().isSelected()){ catalogTreeControlPanel.getCatalogButton().doClick(); } if (!catalogTreeControlPanel.getImageServerButton().isSelected()){ catalogTreeControlPanel.getImageServerButton().doClick(); } if (catalogTreeControlPanel.getArchiveButton().isSelected()){ catalogTreeControlPanel.getArchiveButton().doClick(); } if (catalogTreeControlPanel.getNameServerButton().isSelected()){ catalogTreeControlPanel.getNameServerButton().doClick(); } } public void selectOnlyObjects() { CatalogTreeControlPanel catalogTreeControlPanel = naviPanel.getCatalogTree().getControlPanel(); if (!catalogTreeControlPanel.getCatalogButton().isSelected()){ catalogTreeControlPanel.getCatalogButton().doClick(); } if (catalogTreeControlPanel.getImageServerButton().isSelected()){ catalogTreeControlPanel.getImageServerButton().doClick(); } if (catalogTreeControlPanel.getArchiveButton().isSelected()){ catalogTreeControlPanel.getArchiveButton().doClick(); } if (catalogTreeControlPanel.getNameServerButton().isSelected()){ catalogTreeControlPanel.getNameServerButton().doClick(); } } }