From 58a466aacc6cdb7a12c15448c37e5387ee53b42c Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Tue, 17 May 2016 16:21:31 +0200 Subject: [PATCH] Use ResultPanelCtrl to manage the result view. --- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelCtrl.java | 46 ++++++++++++++-------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelView.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/ViewListener.java | 36 ------------------------------------ src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java | 39 ++++++++++++++++++++++++++++++++++++++- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java | 1 + src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java | 5 ++--- 6 files changed, 56 insertions(+), 73 deletions(-) delete mode 100644 src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/ViewListener.java diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelCtrl.java index 0ee3bda..2e2f2f5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelCtrl.java @@ -16,10 +16,6 @@ package eu.omp.irap.vespa.epntapclient.gui.mainPanel; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.logging.Level; import java.util.logging.Logger; @@ -27,14 +23,14 @@ import javax.swing.JOptionPane; import eu.omp.irap.vespa.epntapclient.EpnTapController; import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl; +import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelCtrl; import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelCtrl; import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; -import eu.omp.irap.vespa.votable.controller.VOTableController; /** * @author N. Jourdane */ -public class MainPanelCtrl extends EpnTapController implements ViewListener { +public class MainPanelCtrl extends EpnTapController { /** The logger for the class GUIController. */ private static final Logger logger = Logger.getLogger(MainPanelCtrl.class.getName()); @@ -43,22 +39,18 @@ public class MainPanelCtrl extends EpnTapController implements ViewListener { private ServicesPanelCtrl servicesPanelCtrl; - private VOTableController resultPanelCtrl; + private ResultPanelCtrl resultPanelCtrl; - private MainPanelView mainView; - - private String voTablePath; - - // TODO: à déplacer dans ServicePanelCtrl + private MainPanelView view; private int nbMaxResult = 10; public MainPanelCtrl() { servicesPanelCtrl = new ServicesPanelCtrl(this); - resultPanelCtrl = new VOTableController(); + resultPanelCtrl = new ResultPanelCtrl(this); requestPanelCtrl = new RequestPanelCtrl(this); - mainView = new MainPanelView(this); + view = new MainPanelView(this); } @Override @@ -68,7 +60,7 @@ public class MainPanelCtrl extends EpnTapController implements ViewListener { } catch (CantGetVOTableException e) { displayError("Can not get services.", e); } - mainView.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); + view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); } public void sendQuery(String query) { @@ -76,8 +68,7 @@ public class MainPanelCtrl extends EpnTapController implements ViewListener { logger.info("Sending query: " + query + " on " + serviceURL); try { resultPanelCtrl.updateVOTable(serviceURL, query); - voTablePath = resultPanelCtrl.getVOTablePath(); - mainView.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData()); + view.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData()); } catch (CantGetVOTableException e) { displayError("Can not send the query.", e); MainPanelCtrl.logger.log(Level.WARNING, "Can not send query.", e); @@ -92,27 +83,18 @@ public class MainPanelCtrl extends EpnTapController implements ViewListener { return servicesPanelCtrl; } + public ResultPanelCtrl getResultPanelCtrl() { + return resultPanelCtrl; + } + public MainPanelView getView() { - return mainView; + return view; } @Override public void displayError(String message, Exception e) { logger.log(Level.SEVERE, message, e); - JOptionPane.showMessageDialog(mainView, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); - } - - /** Copy the VOTable to a specified location. */ - @Override - public void onDownloadButtonClicked(File outputFile) { - try { - Files.copy(Paths.get(voTablePath), Paths.get(outputFile.getAbsolutePath())); - } catch (IOException e) { - // TODO create exception - mainView.displayError("Can not save the file.", - "Check that you can write on the specified directory."); - MainPanelCtrl.logger.log(Level.WARNING, "Can not save the file.", e); - } + JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); } /** diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelView.java index b0d1ca1..e438b3a 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelView.java @@ -56,7 +56,7 @@ public class MainPanelView extends JPanel { public MainPanelView(MainPanelCtrl mainPanelCtrl) { servicesPanel = mainPanelCtrl.getServicePanelCtrl().getView(); - resultPanel = new ResultPanelView(mainPanelCtrl); + resultPanel = mainPanelCtrl.getResultPanelCtrl().getView(); requestPanel = mainPanelCtrl.getRequestPanelCtrl().getView(); buildMainView(); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/ViewListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/ViewListener.java deleted file mode 100644 index 9e7befa..0000000 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/ViewListener.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is a part of EpnTAPClient. - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. - * - * This program is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of - * the GNU General Public License along with this program. If not, see - * . - */ - -package eu.omp.irap.vespa.epntapclient.gui.mainPanel; - -import java.io.File; - -/** - * The interface for the main view listener, which listen for GUI events in the view, implemented by - * the controller. - * - * @author N. Jourdane - */ -public interface ViewListener { - - /** - * When the `Download VOTable` button is clicked. - * - * @param outputFile The file to copy the VOTable. - */ - void onDownloadButtonClicked(File outputFile); - -} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java index 86c2e0d..40127a5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java @@ -16,13 +16,50 @@ package eu.omp.irap.vespa.epntapclient.gui.resultpanel; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.logging.Level; import java.util.logging.Logger; +import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; +import eu.omp.irap.vespa.votable.controller.VOTableController; + /** * @author N. Jourdane */ -public class ResultPanelCtrl { +public class ResultPanelCtrl extends VOTableController implements ResultPanelListener { /** The logger for the class ResultPanelCtrl. */ private static final Logger logger = Logger.getLogger(ResultPanelCtrl.class.getName()); + + private MainPanelCtrl mainPanelCtrl; + + private ResultPanelView view; + + + public ResultPanelCtrl(MainPanelCtrl mainPanelCtrl) { + this.mainPanelCtrl = mainPanelCtrl; + view = new ResultPanelView(this); + } + + /* + * @see + * eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelListener#onDownloadButtonClicked( + * java.io.File) + */ + @Override + public void onDownloadButtonClicked(File file) { + try { + Files.copy(Paths.get(voTablePath), Paths.get(file.getAbsolutePath())); + } catch (IOException e) { + mainPanelCtrl.displayError("Can not save the file.", e); + logger.log(Level.WARNING, "Can not save the file.", e); + } + } + + public ResultPanelView getView() { + return view; + } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java index 82c92f0..4fa13b5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java @@ -23,5 +23,6 @@ import java.io.File; */ public interface ResultPanelListener { + /** Copy the VOTable to a specified location. */ public void onDownloadButtonClicked(File file); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java index c9e1ab9..575d715 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java @@ -25,7 +25,6 @@ import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.ViewListener; import eu.omp.irap.vespa.votable.view.VOTableView; /** @@ -36,7 +35,7 @@ public class ResultPanelView extends VOTableView { /** The serial version UID. */ private static final long serialVersionUID = 1L; - ViewListener viewListener; + ResultPanelListener viewListener; /** A label to display several informations (aka. status bar). */ private JLabel infoLabel; @@ -51,7 +50,7 @@ public class ResultPanelView extends VOTableView { * @param mainView The main view of the application. * @param voTableView The generic view of the VOTable panel. */ - public ResultPanelView(ViewListener viewListener) { + public ResultPanelView(ResultPanelListener viewListener) { super(); this.viewListener = viewListener; buildResultPanel(); -- libgit2 0.21.2