JAL-2316 Added UrlProvider factories. Tidied up labelling.
[jalview.git] / src / jalview / urls / UrlLinkDisplay.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21
22 package jalview.urls;
23
24 import jalview.util.MessageManager;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 /**
30  * UrlLink table row definition
31  * 
32  * @author $author$
33  * @version $Revision$
34  */
35
36 public class UrlLinkDisplay
37 {
38   private String id; // id is not supplied to display, but used to identify
39                      // entries when saved
40
41   private String name;
42
43   private String url;
44
45   private boolean isDefault;
46
47   private boolean isSelected;
48
49   // Headers for columns in table
50   private final static List<String> colNames = new ArrayList<String>()
51   {
52     {
53       add(MessageManager.formatMessage("label.name"));
54       add(MessageManager.formatMessage("label.url"));
55       add(MessageManager.formatMessage("label.inmenu"));
56       add(MessageManager.formatMessage("label.default"));
57       add(MessageManager.formatMessage("label.id"));
58     }
59   };
60
61   // column positions
62   public final static int NAME = 0;
63
64   public final static int URL = 1;
65
66   public final static int SELECTED = 2;
67
68   public final static int DEFAULT = 3;
69
70   public final static int ID = 4;
71
72   public UrlLinkDisplay(String rowId, String rowName, String rowUrl,
73           boolean rowSelected, boolean rowDefault)
74   {
75     id = rowId;
76     name = rowName;
77     url = rowUrl;
78     isDefault = rowDefault;
79     isSelected = rowSelected;
80   }
81
82   // getters/setters
83   public String getId()
84   {
85     return id;
86   }
87
88   public String getName()
89   {
90     return name;
91   }
92
93   public String getUrl()
94   {
95     return url;
96   }
97
98   public boolean getIsDefault()
99   {
100     return isDefault;
101   }
102
103   public boolean getIsSelected()
104   {
105     return isSelected;
106   }
107
108   public void setUrl(String rowUrl)
109   {
110     url = rowUrl;
111   }
112
113   public void setIsDefault(boolean rowDefault)
114   {
115     isDefault = rowDefault;
116   }
117
118   public void setIsSelected(boolean rowSelected)
119   {
120     isSelected = rowSelected;
121   }
122
123   public Object getValue(int index)
124   {
125     switch (index)
126     {
127     case ID:
128       return id;
129     case URL:
130       return url;
131     case DEFAULT:
132       return isDefault;
133     case SELECTED:
134       return isSelected;
135     case NAME:
136       return name;
137     default:
138       return null;
139     }
140   }
141
142   public void setValue(int index, Object value)
143   {
144     switch (index)
145     {
146     case ID:
147       id = (String) value;
148       break;
149     case URL:
150       url = (String) value;
151       break;
152     case DEFAULT:
153       isDefault = (boolean) value;
154       break;
155     case SELECTED:
156       isSelected = (boolean) value;
157       break;
158     case NAME:
159       name = (String) value;
160       break;
161     default:
162       // do nothing
163     }
164   }
165
166   /**
167    * Identify editable columns
168    * 
169    * @param index
170    *          index of column
171    * @return whether column can be edited in table
172    */
173   public boolean isEditable(int index)
174   {
175     return ((index == DEFAULT) || (index == SELECTED));
176   }
177
178   /**
179    * Get list of column names to display in UI
180    * 
181    * @return column names
182    */
183   public static List<String> getDisplayColumnNames()
184   {
185     // Display names between NAME and ID (excludes ID)
186     return colNames.subList(NAME, ID);
187   }
188 }