Commit fe1e44708a89f96e32ee2aa5028495d0221e4e53

Authored by Nathanael Jourdane
1 parent 869d1749
Exists in master

Minor code improvements

src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java
... ... @@ -74,7 +74,7 @@ public final class Queries {
74 74 addJoin.add(param.getKey() + " = " + param.getValue().toString());
75 75 }
76 76 }
77   - String where = "".equals(addJoin.toString()) ? "" : " WHERE " + addJoin;
  77 + String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin;
78 78 return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where;
79 79 }
80 80  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/Dim.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/view/GUIDim.java
... ... @@ -21,7 +21,7 @@ package eu.omp.irap.vespa.epntapclient.view;
21 21 *
22 22 * @author N. Jourdane
23 23 */
24   -public class Dim {
  24 +public class GUIDim {
25 25  
26 26 /** The width of the left panel (services view). */
27 27 public static final int LEFT_PANEL_WIDTH = 400;
... ... @@ -49,6 +49,6 @@ public class Dim {
49 49  
50 50  
51 51 /** Private constructor to hide the implicit public one. */
52   - private Dim() {
  52 + private GUIDim() {
53 53 }
54 54 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
... ... @@ -151,7 +151,7 @@ public abstract class ParamField extends JPanel {
151 151 */
152 152 @Override
153 153 public void update(JTextField textField) {
154   - if ("".equals(textField.getText())) {
  154 + if (textField.getText().isEmpty()) {
155 155 mainView.event(Event.PARAMETER_CHANGED, paramName, null);
156 156 } else {
157 157 mainView.event(Event.PARAMETER_CHANGED, paramName, textField.getText());
... ... @@ -193,7 +193,7 @@ public abstract class ParamField extends JPanel {
193 193 */
194 194 @Override
195 195 public void update(JTextField textField) {
196   - if ("".equals(textField.getText())) {
  196 + if (textField.getText().isEmpty()) {
197 197 textField.setBackground(Color.WHITE);
198 198 mainView.event(Event.PARAMETER_REMOVED, paramName);
199 199 } else {
... ... @@ -259,7 +259,7 @@ public abstract class ParamField extends JPanel {
259 259 @Override
260 260 public void update(JTextField field) {
261 261 DateFormat df = new SimpleDateFormat(ParamField.DATE_FORMAT, Locale.ENGLISH);
262   - if ("".equals(field.getText())) {
  262 + if (field.getText().isEmpty()) {
263 263 field.setBackground(Color.WHITE);
264 264 mainView.event(Event.PARAMETER_REMOVED, paramName + field.getName());
265 265 } else if (field.getText().matches(ParamField.DATE_REGEX)) {
... ... @@ -321,7 +321,7 @@ public abstract class ParamField extends JPanel {
321 321 */
322 322 @Override
323 323 public void update(JTextField field) {
324   - if ("".equals(field.getText())) {
  324 + if (field.getText().isEmpty()) {
325 325 field.setBackground(Color.WHITE);
326 326 mainView.event(Event.PARAMETER_REMOVED, paramName + field.getName());
327 327 } else {
... ... @@ -385,7 +385,7 @@ public abstract class ParamField extends JPanel {
385 385 }
386 386 comboBox.getEditor().setItem(content);
387 387 }
388   - if ("".equals(content)) {
  388 + if (content.isEmpty()) {
389 389 mainView.event(Event.PARAMETER_REMOVED, paramName);
390 390 } else {
391 391 mainView.event(Event.PARAMETER_CHANGED, paramName, content);
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java
... ... @@ -29,7 +29,7 @@ import javax.swing.JButton;
29 29 import javax.swing.JPanel;
30 30 import javax.swing.JTextArea;
31 31  
32   -import eu.omp.irap.vespa.epntapclient.view.Dim;
  32 +import eu.omp.irap.vespa.epntapclient.view.GUIDim;
33 33 import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
34 34 import eu.omp.irap.vespa.epntapclient.view.Event;
35 35 import eu.omp.irap.vespa.epntapclient.view.ParamField;
... ... @@ -43,19 +43,16 @@ import eu.omp.irap.vespa.epntapclient.view.ParamField.TargetNameField;
43 43 *
44 44 * @author N. Jourdane
45 45 */
46   -public class RequestPanel extends JPanel implements ActionListener {
  46 +public class RequestPanel extends JPanel {
47 47  
48 48 /** The serial version UID. */
49 49 private static final long serialVersionUID = 1L;
50 50  
51   - /** The name of the button to send the query. */
52   - private static final String BTN_NAME = "btnSend";
53   -
54 51 /** The main view of the application. */
55   - private EpnTapMainView mainView;
  52 + protected EpnTapMainView mainView;
56 53  
57 54 /** The text area where the user write the query. */
58   - private JTextArea queryArea;
  55 + protected JTextArea queryArea;
59 56  
60 57 /**
61 58 * The parameters fields for the request.
... ... @@ -74,8 +71,8 @@ public class RequestPanel extends JPanel implements ActionListener {
74 71 public RequestPanel(EpnTapMainView mainView) {
75 72 this.mainView = mainView;
76 73 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
77   - setPreferredSize(new Dimension(Dim.RIGHT_PANEL_WIDTH, Dim.TOP_PANEL_HEIGHT));
78   - setMinimumSize(new Dimension(Dim.RIGHT_PANEL_MIN_WIDTH, Dim.TOP_PANEL_MIN_HEIGHT));
  74 + setPreferredSize(new Dimension(GUIDim.RIGHT_PANEL_WIDTH, GUIDim.TOP_PANEL_HEIGHT));
  75 + setMinimumSize(new Dimension(GUIDim.RIGHT_PANEL_MIN_WIDTH, GUIDim.TOP_PANEL_MIN_HEIGHT));
79 76  
80 77 // TODO: Use a JScrollPane.
81 78 // TODO: Get max row number from the GUI
... ... @@ -152,22 +149,16 @@ public class RequestPanel extends JPanel implements ActionListener {
152 149 private JPanel buildButtonPanel() {
153 150 JPanel buttonPanel = new JPanel();
154 151 JButton btnSend = new JButton("Send query");
155   - btnSend.setName(RequestPanel.BTN_NAME);
156   - btnSend.addActionListener(this);
  152 + btnSend.addActionListener(new ActionListener() {
  153 +
  154 + @Override
  155 + public void actionPerformed(ActionEvent e) {
  156 + mainView.event(Event.SEND_BUTTON_CLICKED, queryArea.getText());
  157 + }
  158 + });
157 159 buttonPanel.add(btnSend);
158 160 buttonPanel.setMaximumSize(new Dimension(1000, RequestPanel.BUTTON_PANEL_HEIGHT));
159 161  
160 162 return buttonPanel;
161 163 }
162   -
163   - /**
164   - * This method is called when the user click on the `Send` button.
165   - */
166   - @Override
167   - public void actionPerformed(ActionEvent evt) {
168   - if (((JButton) evt.getSource()).getName() == RequestPanel.BTN_NAME) {
169   - mainView.event(Event.SEND_BUTTON_CLICKED, queryArea.getText());
170   - }
171   - }
172   -
173 164 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ResultsPanel.java
... ... @@ -21,7 +21,7 @@ import java.awt.Dimension;
21 21  
22 22 import javax.swing.JPanel;
23 23  
24   -import eu.omp.irap.vespa.epntapclient.view.Dim;
  24 +import eu.omp.irap.vespa.epntapclient.view.GUIDim;
25 25 import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
26 26 import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
27 27  
... ... @@ -47,9 +47,9 @@ public class ResultsPanel extends JPanel {
47 47 setLayout(new BorderLayout());
48 48 this.add(voTableView);
49 49  
50   - setPreferredSize(new Dimension(Dim.LEFT_PANEL_WIDTH + Dim.RIGHT_PANEL_WIDTH,
51   - Dim.BOTTOM_PANEL_HEIGHT));
52   - setMinimumSize(new Dimension(Dim.LEFT_PANEL_MIN_WIDTH + Dim.RIGHT_PANEL_MIN_WIDTH,
53   - Dim.BOTTOM_PANEL_MIN_HEIGHT));
  50 + setPreferredSize(new Dimension(GUIDim.LEFT_PANEL_WIDTH + GUIDim.RIGHT_PANEL_WIDTH,
  51 + GUIDim.BOTTOM_PANEL_HEIGHT));
  52 + setMinimumSize(new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH + GUIDim.RIGHT_PANEL_MIN_WIDTH,
  53 + GUIDim.BOTTOM_PANEL_MIN_HEIGHT));
54 54 }
55 55 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java
... ... @@ -23,7 +23,7 @@ import javax.swing.JPanel;
23 23 import javax.swing.event.ListSelectionEvent;
24 24 import javax.swing.event.ListSelectionListener;
25 25  
26   -import eu.omp.irap.vespa.epntapclient.view.Dim;
  26 +import eu.omp.irap.vespa.epntapclient.view.GUIDim;
27 27 import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
28 28 import eu.omp.irap.vespa.epntapclient.view.Event;
29 29 import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
... ... @@ -53,8 +53,8 @@ public class ServicesPanel extends JPanel {
53 53 setLayout(new BorderLayout());
54 54 this.add(voTableView);
55 55  
56   - setPreferredSize(new Dimension(Dim.LEFT_PANEL_WIDTH, Dim.TOP_PANEL_HEIGHT));
57   - setMinimumSize(new Dimension(Dim.LEFT_PANEL_MIN_WIDTH, Dim.TOP_PANEL_MIN_HEIGHT));
  56 + setPreferredSize(new Dimension(GUIDim.LEFT_PANEL_WIDTH, GUIDim.TOP_PANEL_HEIGHT));
  57 + setMinimumSize(new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH, GUIDim.TOP_PANEL_MIN_HEIGHT));
58 58  
59 59 // TODO: Support multi-selection
60 60 this.voTableView.getTable().getSelectionModel()
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableConnection.java
... ... @@ -72,7 +72,7 @@ public final class VOTableConnection {
72 72 String uri = targetURL + "/sync";
73 73 String parameters = "REQUEST=doQuery&LANG=" + queryLanguage + "&QUERY=";
74 74 try {
75   - parameters += URLEncoder.encode(query, Const.CHARACTER_SET).replace("+", "%20")
  75 + parameters += URLEncoder.encode(query, Const.ENCODING).replace("+", "%20")
76 76 .replace(".", "%2E").replace("-", "%2D").replace("*", "%2A")
77 77 .replace("_", "%5F");
78 78 } catch (UnsupportedEncodingException e) {
... ... @@ -135,7 +135,6 @@ public final class VOTableConnection {
135 135 while ((inputLine = in.readLine()) != null) {
136 136 response.append(inputLine);
137 137 }
138   - in.close();
139 138 } catch (IOException e1) {
140 139 VOTableConnection.logger.log(Level.WARNING, "Can not get input stream", e1);
141 140 try (BufferedReader in = new BufferedReader(
... ... @@ -143,7 +142,6 @@ public final class VOTableConnection {
143 142 while ((inputLine = in.readLine()) != null) {
144 143 response.append(inputLine);
145 144 }
146   - in.close();
147 145 } catch (IOException e2) {
148 146 throw new CantGetErrorStream(uri, e2);
149 147 }
... ... @@ -162,13 +160,12 @@ public final class VOTableConnection {
162 160 private static void printRequestResult(StringBuilder response, String resultFileName)
163 161 throws IOException {
164 162  
165   - try (PrintWriter writer = new PrintWriter(resultFileName, Const.CHARACTER_SET)) {
  163 + try (PrintWriter writer = new PrintWriter(resultFileName, Const.ENCODING)) {
166 164 writer.println(response);
167   - writer.close();
168 165 } catch (FileNotFoundException e1) {
169 166 throw new IOException("The file " + resultFileName + " is not found.", e1);
170 167 } catch (UnsupportedEncodingException e2) {
171   - throw new IOException("Bad encoding with " + Const.CHARACTER_SET, e2);
  168 + throw new IOException("Bad encoding with " + Const.ENCODING, e2);
172 169 }
173 170 }
174 171 }
175 172 \ No newline at end of file
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Const.java
... ... @@ -24,7 +24,7 @@ package eu.omp.irap.vespa.epntapclient.votable.utils;
24 24 public class Const {
25 25  
26 26 /** The character set used (for http requests, writing in files, etc.). */
27   - public static final String CHARACTER_SET = "UTF-8";
  27 + public static final String ENCODING = "UTF-8";
28 28  
29 29 /** The temporary directory path. */
30 30 public static final String TMP_DIR = System.getProperty("java.io.tmpdir");
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/utils/Utils.java
... ... @@ -59,22 +59,29 @@ public class Utils {
59 59 */
60 60 public StringJoiner(String separator) {
61 61 this.separator = separator;
62   - string = "";
  62 + string = new String();
63 63 }
64 64  
65 65 /**
66   - * add a new word to the joiner.
  66 + * Add a new word to the joiner.
67 67 *
68 68 * @param text The word to add.
69 69 */
70 70 public void add(String text) {
71   - if ("".equals(string)) {
  71 + if (string.isEmpty()) {
72 72 string = text;
73 73 } else {
74 74 string += separator + text;
75 75 }
76 76 }
77 77  
  78 + /**
  79 + * @return true if the string joiner content is empty.
  80 + */
  81 + public boolean isEmpty() {
  82 + return string.isEmpty();
  83 + }
  84 +
78 85 @Override
79 86 public String toString() {
80 87 return string;
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java
... ... @@ -110,6 +110,7 @@ public class VOTableView extends JPanel implements TableModelListener {
110 110 if (e.getType() != TableModelEvent.UPDATE) {
111 111 return;
112 112 }
  113 + // TODO : créer interface VOTableListener
113 114 }
114 115  
115 116 }
... ...