2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.appletgui;
\r
21 import jalview.datamodel.*;
\r
24 import java.awt.event.*;
\r
27 public class FeatureSettings extends Panel implements ItemListener,
\r
28 MouseListener, MouseMotionListener, ActionListener, AdjustmentListener
\r
35 Panel featurePanel = new Panel();
\r
36 ScrollPane scrollPane;
\r
37 boolean alignmentHasFeatures = false;
\r
39 Scrollbar transparency ;
\r
41 public FeatureSettings(AlignViewport av, final AlignmentPanel ap)
\r
45 fr = ap.seqPanel.seqCanvas.getFeatureRenderer();
\r
47 transparency = new Scrollbar(Scrollbar.HORIZONTAL,
\r
48 100 - (int)(fr.transparency*100), 1, 1, 100);
\r
50 if(fr.transparencySetter!=null)
\r
52 transparency.addAdjustmentListener(this);
\r
55 transparency.setEnabled(false);
\r
57 java.net.URL url = getClass().getResource("/images/link.gif");
\r
60 linkImage = java.awt.Toolkit.getDefaultToolkit().getImage(url);
\r
64 if(av.featuresDisplayed==null)
\r
65 fr.findAllFeatures();
\r
69 this.setLayout(new BorderLayout());
\r
70 scrollPane = new ScrollPane();
\r
71 scrollPane.add(featurePanel);
\r
72 if (alignmentHasFeatures)
\r
73 add(scrollPane, BorderLayout.CENTER);
\r
75 Button invert = new Button("Invert Selection");
\r
76 invert.addActionListener(this);
\r
78 Panel lowerPanel = new Panel(new GridLayout(2,1,5,10));
\r
79 lowerPanel.add(invert);
\r
81 Panel tPanel = new Panel(new BorderLayout());
\r
83 if(fr.transparencySetter!=null)
\r
85 tPanel.add(transparency, BorderLayout.CENTER);
\r
86 tPanel.add(new Label("Transparency"), BorderLayout.EAST);
\r
89 tPanel.add(new Label("Transparency not available in this web browser"), BorderLayout.CENTER);
\r
91 lowerPanel.add(tPanel, BorderLayout.SOUTH);
\r
93 add(lowerPanel, BorderLayout.SOUTH);
\r
97 if(groupPanel!=null)
\r
99 groupPanel.setLayout(
\r
100 new GridLayout( fr.featureGroups.size() / 4 + 1, 4));
\r
101 groupPanel.validate();
\r
103 add(groupPanel, BorderLayout.NORTH);
\r
105 frame = new Frame();
\r
107 int height = featurePanel.getComponentCount()*50 +60;
\r
110 height = Math.max(200, height);
\r
111 height = Math.min(400, height);
\r
113 jalview.bin.JalviewLite.addFrame(frame, "Feature Settings", 280,
\r
117 public void paint(Graphics g)
\r
119 g.setColor(Color.black);
\r
120 g.drawString("No Features added to this alignment!!", 10, 20);
\r
121 g.drawString("(Features can be added from searches or", 10, 40);
\r
122 g.drawString("from Jalview / GFF features files)", 10, 60);
\r
125 void setTableData()
\r
127 alignmentHasFeatures = false;
\r
129 if(fr.featureGroups==null)
\r
130 fr.featureGroups = new Hashtable();
\r
132 Vector allFeatures = new Vector();
\r
133 Vector allGroups = new Vector();
\r
134 SequenceFeature[] tmpfeatures;
\r
138 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
140 if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
\r
143 alignmentHasFeatures = true;
\r
145 tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
\r
147 while (index < tmpfeatures.length)
\r
149 if(tmpfeatures[index].getFeatureGroup()!=null)
\r
151 group = tmpfeatures[index].featureGroup;
\r
152 if(!allGroups.contains(group))
\r
154 allGroups.addElement(group);
\r
156 boolean visible = true;
\r
157 if (fr.featureGroups.containsKey(group))
\r
159 visible = ( (Boolean) fr.featureGroups.get(group)).booleanValue();
\r
162 fr.featureGroups.put(group, new Boolean(visible));
\r
164 if (groupPanel == null)
\r
166 groupPanel = new Panel();
\r
169 Checkbox check = new MyCheckbox(
\r
172 (fr.featureLinks!=null && fr.featureLinks.containsKey(group))
\r
176 check.addMouseListener(this);
\r
177 check.setFont(new Font("Serif", Font.BOLD, 12));
\r
178 check.addItemListener(this);
\r
179 groupPanel.add(check);
\r
183 if (!allFeatures.contains(tmpfeatures[index].getType()))
\r
185 allFeatures.addElement(tmpfeatures[index].getType());
\r
194 //This routine adds and removes checkboxes depending on
\r
195 //Group selection states
\r
196 void resetTable(boolean groupsChanged)
\r
198 SequenceFeature [] tmpfeatures;
\r
199 String group=null, type;
\r
200 Vector visibleChecks = new Vector();
\r
202 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
204 if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
\r
207 tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
\r
209 while (index < tmpfeatures.length)
\r
211 group = tmpfeatures[index].featureGroup;
\r
213 if (group==null || fr.featureGroups.get(group)==null ||
\r
214 ((Boolean) fr.featureGroups.get(group)).booleanValue())
\r
216 type = tmpfeatures[index].getType();
\r
217 if(!visibleChecks.contains(type) )
\r
219 visibleChecks.addElement(type);
\r
227 int cSize = featurePanel.getComponentCount();
\r
229 //This will remove any checkboxes which shouldn't be
\r
231 for (int i = 0; i < cSize; i++)
\r
233 comps = featurePanel.getComponents();
\r
234 check = (Checkbox) comps[i];
\r
235 if (!visibleChecks.contains(check.getLabel()))
\r
237 featurePanel.remove(i);
\r
243 if(fr.renderOrder!=null)
\r
245 //First add the checks in the previous render order,
\r
246 //in case the window has been closed and reopened
\r
247 for(int ro=fr.renderOrder.length-1; ro>-1; ro--)
\r
249 String item = fr.renderOrder[ro];
\r
251 if(!visibleChecks.contains(item))
\r
254 visibleChecks.removeElement(item);
\r
256 addCheck(false, item);
\r
260 // now add checkboxes which should be visible,
\r
261 // if they have not already been added
\r
262 Enumeration en = visibleChecks.elements();
\r
264 while(en.hasMoreElements())
\r
266 addCheck(groupsChanged, en.nextElement().toString());
\r
270 featurePanel.setLayout(new GridLayout(featurePanel.getComponentCount(), 1, 10,5));
\r
271 featurePanel.validate();
\r
274 if(scrollPane!=null)
\r
275 scrollPane.validate();
\r
277 itemStateChanged(null);
\r
280 void addCheck(boolean groupsChanged, String type)
\r
283 Component [] comps = featurePanel.getComponents();
\r
286 for (int i = 0; i < featurePanel.getComponentCount(); i++)
\r
288 check = (Checkbox) comps[i];
\r
289 if (check.getLabel().equals(type))
\r
298 boolean selected = false;
\r
299 if (groupsChanged || av.featuresDisplayed.containsKey(type))
\r
304 check = new MyCheckbox(type,
\r
306 (fr.featureLinks!=null && fr.featureLinks.containsKey(type))
\r
309 check.addMouseListener(this);
\r
310 check.addMouseMotionListener(this);
\r
311 check.setBackground(fr.getColour(type));
\r
312 check.addItemListener(this);
\r
313 featurePanel.add(check);
\r
317 public void actionPerformed(ActionEvent evt)
\r
319 for(int i=0; i<featurePanel.getComponentCount(); i++)
\r
321 Checkbox check = (Checkbox)featurePanel.getComponent(i);
\r
322 check.setState(!check.getState());
\r
324 selectionChanged();
\r
327 public void itemStateChanged(ItemEvent evt)
\r
331 //Is the source a top level featureGroup?
\r
332 Checkbox source = (Checkbox) evt.getSource();
\r
333 if (fr.featureGroups.containsKey(source.getLabel()))
\r
335 fr.featureGroups.put(source.getLabel(), new Boolean(source.getState()));
\r
336 ap.seqPanel.seqCanvas.repaint();
\r
337 if (ap.overviewPanel != null)
\r
338 ap.overviewPanel.updateOverviewImage();
\r
344 selectionChanged();
\r
347 void selectionChanged()
\r
349 Component[] comps = featurePanel.getComponents();
\r
350 int cSize = comps.length;
\r
352 Object[][] tmp = new Object[cSize][3];
\r
354 for (int i = 0; i < cSize; i++)
\r
356 Checkbox check = (Checkbox) comps[i];
\r
357 tmp[tmpSize][0] = check.getLabel();
\r
358 tmp[tmpSize][1] = fr.getColour(check.getLabel());
\r
359 tmp[tmpSize][2] = new Boolean(check.getState());
\r
363 Object[][]data = new Object[tmpSize][3];
\r
364 System.arraycopy(tmp, 0, data,0, tmpSize);
\r
366 fr.setFeaturePriority(data);
\r
367 ap.seqPanel.seqCanvas.repaint();
\r
368 if (ap.overviewPanel != null)
\r
369 ap.overviewPanel.updateOverviewImage();
\r
372 MyCheckbox selectedCheck;
\r
373 boolean dragging = false;
\r
375 public void mousePressed(MouseEvent evt)
\r
378 selectedCheck = (MyCheckbox)evt.getSource();
\r
380 if(fr.featureLinks!=null
\r
381 && fr.featureLinks.containsKey(selectedCheck.getLabel() )
\r
384 if(evt.getX()>selectedCheck.stringWidth+20)
\r
392 public void mouseDragged(MouseEvent evt)
\r
394 if(((Component)evt.getSource()).getParent()!=featurePanel)
\r
399 public void mouseReleased(MouseEvent evt)
\r
401 if(((Component)evt.getSource()).getParent()!=featurePanel)
\r
404 Component comp = null;
\r
405 Checkbox target = null;
\r
407 int height = evt.getY()+evt.getComponent().getLocation().y;
\r
409 if(height > featurePanel.getSize().height)
\r
412 comp = featurePanel.getComponent(featurePanel.getComponentCount()-1);
\r
414 else if(height < 0)
\r
416 comp = featurePanel.getComponent(0);
\r
420 comp = featurePanel.getComponentAt(evt.getX(),
\r
422 evt.getComponent().getLocation().y);
\r
425 if(comp!=null && comp instanceof Checkbox)
\r
426 target = (Checkbox)comp;
\r
428 if ( selectedCheck != null
\r
430 && selectedCheck != target)
\r
432 int targetIndex = -1;
\r
433 for(int i=0; i<featurePanel.getComponentCount(); i++)
\r
435 if(target==featurePanel.getComponent(i))
\r
436 { targetIndex = i; break; }
\r
439 featurePanel.remove(selectedCheck);
\r
440 featurePanel.add(selectedCheck, targetIndex);
\r
441 featurePanel.validate();
\r
442 itemStateChanged(null);
\r
446 public void setUserColour(String feature, Color col)
\r
448 fr.setColour(feature, col);
\r
449 featurePanel.removeAll();
\r
454 public void mouseEntered(MouseEvent evt){}
\r
455 public void mouseExited(MouseEvent evt){}
\r
456 public void mouseClicked(MouseEvent evt)
\r
458 MyCheckbox check = (MyCheckbox) evt.getSource();
\r
460 if (fr.featureLinks!=null
\r
461 && fr.featureLinks.containsKey(check.getLabel()))
\r
463 if (evt.getX() > check.stringWidth + 20)
\r
466 String link = fr.featureLinks.get(check.getLabel()).toString();
\r
467 ap.alignFrame.showURL(link.substring(link.indexOf("|") + 1),
\r
468 link.substring(0, link.indexOf("|")));
\r
472 if(check.getParent()!=featurePanel)
\r
475 if(evt.getClickCount()>1)
\r
477 new UserDefinedColours(this, check.getLabel(),
\r
478 fr.getColour(check.getLabel()));
\r
481 public void mouseMoved(MouseEvent evt){}
\r
483 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
485 fr.transparency = ( (float) (100 - transparency.getValue()) / 100f);
\r
486 ap.seqPanel.seqCanvas.repaint();
\r
490 class MyCheckbox extends Checkbox
\r
492 public int stringWidth;
\r
494 public MyCheckbox(String label, boolean checked, boolean haslink)
\r
496 super(label, checked);
\r
498 FontMetrics fm = av.nullFrame.getFontMetrics(av.nullFrame.getFont());
\r
499 stringWidth = fm.stringWidth(label);
\r
500 this.hasLink = haslink;
\r
503 public void paint(Graphics g)
\r
506 g.drawImage(linkImage, stringWidth + 25,(
\r
507 getSize().height-linkImage.getHeight(this))/2,
\r