Commit a6dc855e6d94a7cebce9d1d0bff8a19400e05145

Authored by Nathanael Jourdane
1 parent d470f971
Exists in master

Add tabs (draft)

src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java
... ... @@ -17,6 +17,7 @@
17 17 package eu.omp.irap.vespa.epntapclient.gui.mainpanel;
18 18  
19 19 import java.awt.Cursor;
  20 +import java.io.File;
20 21 import java.util.logging.Level;
21 22 import java.util.logging.Logger;
22 23  
... ... @@ -177,7 +178,8 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener
177 178 @Override
178 179 protected void done() {
179 180 if (!isCancelled()) {
180   - resultsPanelCtrl.getView().fillTable(resultsPanelCtrl.getVOTableData());
  181 + String fName = new File(resultsPanelCtrl.getVOTablePath()).getName();
  182 + resultsPanelCtrl.getView().addTable(fName, resultsPanelCtrl.getVOTableData());
181 183 }
182 184 view.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
183 185 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java
... ... @@ -52,6 +52,17 @@ public class ResultPanelCtrl extends VOTableCtrl implements ResultPanelListener
52 52 view = new ResultPanelView(this);
53 53 }
54 54  
  55 + /** Download and parse a VOTable, then add the result to the current tab in the result panel. */
  56 + @Override
  57 + public void appendVOTable(String newTargetURL, String newQuery) {
  58 + try {
  59 + super.appendVOTable(newTargetURL, newQuery);
  60 + } catch (VOTableException e) {
  61 + listener.displayError("Can not update the VOTable.", e);
  62 + }
  63 + view.updateTable(voTableData);
  64 + }
  65 +
55 66 @Override
56 67 public void displayInfo(String shortMessage, String detailledMessage) {
57 68 super.displayInfo(shortMessage, detailledMessage);
... ... @@ -78,14 +89,4 @@ public class ResultPanelCtrl extends VOTableCtrl implements ResultPanelListener
78 89 public void onRowsSelected() {
79 90 LOGGER.info("Selected row: " + StringJoiner.join(view.getSelectedRows()));
80 91 }
81   -
82   - @Override
83   - public void appendVOTable(String newTargetURL, String newQuery) {
84   - try {
85   - super.appendVOTable(newTargetURL, newQuery);
86   - } catch (VOTableException e) {
87   - listener.displayError("Can not update the VOTable.", e);
88   - }
89   - view.fillTable(voTableData);
90   - }
91 92 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java
... ... @@ -19,34 +19,43 @@ package eu.omp.irap.vespa.epntapclient.gui.resultpanel;
19 19 import java.awt.BorderLayout;
20 20 import java.awt.event.ActionEvent;
21 21 import java.awt.event.ActionListener;
  22 +import java.util.ArrayList;
  23 +import java.util.List;
22 24  
23 25 import javax.swing.JButton;
24 26 import javax.swing.JFileChooser;
25 27 import javax.swing.JLabel;
26 28 import javax.swing.JPanel;
  29 +import javax.swing.JTabbedPane;
27 30  
  31 +import eu.omp.irap.vespa.votable.gui.VOTablePanelListener;
28 32 import eu.omp.irap.vespa.votable.gui.VOTablePanelView;
  33 +import eu.omp.irap.vespa.votable.votabledata.VOTableData;
29 34  
30 35 /**
31 36 * @author N. Jourdane
32 37 */
33   -public class ResultPanelView extends VOTablePanelView {
  38 +public class ResultPanelView extends JPanel implements VOTablePanelListener {
34 39  
35 40 /** The serial version UID. */
36 41 private static final long serialVersionUID = 1L;
37 42  
  43 + /** The JPanel containing the buttons. */
  44 + private JPanel buttonsPanel;
  45 +
38 46 /** The GUI element of the button to save the result of the query. */
39 47 private JButton fileButton;
40 48  
41 49 /** A status bar, to display several informative messages. */
42 50 private JLabel statusBar;
43 51  
  52 + private JTabbedPane tabbedPane;
  53 +
  54 + private List<VOTablePanelView> tablePanels;
  55 +
44 56 /** The listener of the result panel. */
45 57 ResultPanelListener listener;
46 58  
47   - /** The JPanel containing the buttons. */
48   - private JPanel buttonsPanel;
49   -
50 59  
51 60 /**
52 61 * Method constructor which customize the result panel, but don't build it from scratch since
... ... @@ -55,24 +64,55 @@ public class ResultPanelView extends VOTablePanelView {
55 64 * @param listener The listener of the result view.
56 65 */
57 66 public ResultPanelView(ResultPanelListener listener) {
58   - super(listener);
59 67 this.listener = listener;
  68 + tablePanels = new ArrayList<>();
60 69 buildResultPanel();
61 70 }
62 71  
63 72 /**
  73 + * Create a new tab and add a new VOTable into it.
  74 + *
  75 + * @param voTableData The VOTable data to add in a new tab.
  76 + */
  77 + public void addTable(String title, VOTableData voTableData) {
  78 + VOTablePanelView voTablePanel = new VOTablePanelView(this);
  79 + voTablePanel.fillTable(voTableData);
  80 + tablePanels.add(voTablePanel);
  81 + tabbedPane.add(title, voTablePanel);
  82 + }
  83 +
  84 + /**
64 85 * Build the panel and add graphical elements to it.
65 86 */
66 87 public void buildResultPanel() {
  88 + tabbedPane = new JTabbedPane();
67 89 JPanel bottomBar = new JPanel();
68 90 bottomBar.setLayout(new BorderLayout());
69 91 bottomBar.add(getStatusBar(), BorderLayout.CENTER);
70 92 bottomBar.add(getButtonsPanel(), BorderLayout.EAST);
71 93  
  94 + add(tabbedPane, BorderLayout.CENTER);
72 95 add(bottomBar, BorderLayout.SOUTH);
73 96 }
74 97  
75 98 /**
  99 + * Create if necessary the buttons panel, then return it.
  100 + *
  101 + * @return the buttons panel.
  102 + */
  103 + public JPanel getButtonsPanel() {
  104 + if (buttonsPanel == null) {
  105 + buttonsPanel = new JPanel();
  106 + buttonsPanel.add(getFileButton());
  107 + }
  108 + return buttonsPanel;
  109 + }
  110 +
  111 + public VOTablePanelView getCurrentTablePanel() {
  112 + return tablePanels.get(getSelectedTab());
  113 + }
  114 +
  115 + /**
76 116 * Returns the button to save the VOTable, create it if doesn't exist.
77 117 *
78 118 * @return The button to save the VOTable.
... ... @@ -94,6 +134,20 @@ public class ResultPanelView extends VOTablePanelView {
94 134 }
95 135  
96 136 /**
  137 + * @return The index of the selected tab.
  138 + */
  139 + public List<Integer> getSelectedRows() {
  140 + return getCurrentTablePanel().getSelectedRows();
  141 + }
  142 +
  143 + /**
  144 + * @return The index of the selected tab.
  145 + */
  146 + public int getSelectedTab() {
  147 + return tabbedPane.getSelectedIndex();
  148 + }
  149 +
  150 + /**
97 151 * Returns the status bar, create it if doesn't exist.
98 152 *
99 153 * @return The status bar.
... ... @@ -105,6 +159,11 @@ public class ResultPanelView extends VOTablePanelView {
105 159 return statusBar;
106 160 }
107 161  
  162 + @Override
  163 + public void onRowsSelected() {
  164 + // Do nothing yet when a row is selected.
  165 + }
  166 +
108 167 /**
109 168 * @param infoText The text to display in the status-bar, which will override the old one.
110 169 */
... ... @@ -113,15 +172,11 @@ public class ResultPanelView extends VOTablePanelView {
113 172 }
114 173  
115 174 /**
116   - * Create if necessary the buttons panel, then return it.
  175 + * Append data to the current tab.
117 176 *
118   - * @return the buttons panel.
  177 + * @param voTableData The VOTable data to add in the current tab.
119 178 */
120   - public JPanel getButtonsPanel() {
121   - if (buttonsPanel == null) {
122   - buttonsPanel = new JPanel();
123   - buttonsPanel.add(getFileButton());
124   - }
125   - return buttonsPanel;
  179 + public void updateTable(VOTableData voTableData) {
  180 + getCurrentTablePanel().fillTable(voTableData);
126 181 }
127 182 }
... ...