Commit 2e9b554957d10fa1ebf9b808b74038f59a5d34cc

Authored by Nathanael Jourdane
1 parent 17e4ebd9
Exists in master

Add the VOTable view.

src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java 0 → 100644
... ... @@ -0,0 +1,88 @@
  1 +/**
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.votable.view;
  18 +
  19 +import java.awt.BorderLayout;
  20 +import java.awt.Dimension;
  21 +import java.util.List;
  22 +
  23 +import javax.swing.JOptionPane;
  24 +import javax.swing.JPanel;
  25 +import javax.swing.JScrollPane;
  26 +import javax.swing.JTable;
  27 +import javax.swing.ScrollPaneConstants;
  28 +
  29 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController;
  30 +
  31 +/**
  32 + * The main class of the View of the application.
  33 + *
  34 + * @author N. Jourdane
  35 + */
  36 +public class VOTableView extends JPanel {
  37 +
  38 + /** The serial version UID (affected with a random number). */
  39 + private static final long serialVersionUID = -1233290271099283814L;
  40 +
  41 + /** The controller of the VOTable */
  42 + private VOTableController controller;
  43 +
  44 + /**
  45 + * The constructor of the view.
  46 + *
  47 + * @param controller The Controller of the application.
  48 + */
  49 + public VOTableView(VOTableController controller) {
  50 + this.controller = controller;
  51 + }
  52 +
  53 + /**
  54 + * Build and fill the GUI.
  55 + *
  56 + * @param keys The name of each column of the VOTable data.
  57 + * @param values A list of arrays, representing the rows of the VOTable data. In each row,
  58 + * elements are in the same order as `keys`.
  59 + */
  60 + public void buildArray(String[] keys, List<Object[]> values) {
  61 + setLayout(new BorderLayout());
  62 +
  63 + Object valuesArray[][] = values.toArray(new Object[values.size()][]);
  64 + JTable table = new JTable(valuesArray, keys);
  65 +
  66 + setLayout(new BorderLayout());
  67 +
  68 + JScrollPane scrollPane = new JScrollPane(table);
  69 + scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  70 + scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  71 + scrollPane.setBounds(50, 30, 300, 50);
  72 +
  73 + setPreferredSize(new Dimension(500, 400));
  74 +
  75 + add(scrollPane, BorderLayout.CENTER);
  76 + }
  77 +
  78 + /**
  79 + * Display an error.
  80 + *
  81 + * @param title The title of the error.
  82 + * @param message The message of the error.
  83 + */
  84 + public void displayError(String title, String message) {
  85 + JOptionPane.showMessageDialog(this, message, title, JOptionPane.ERROR_MESSAGE);
  86 + }
  87 +
  88 +}
... ...