Fixed issue with reading from TreeBase
[jalview.git] / forester / java / src / org / forester / archaeopteryx / NodeFrame.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
9 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // All rights reserved
11 //
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 //
26 // Contact: phylosoft @ gmail . com
27 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
28
29 package org.forester.archaeopteryx;
30
31 import java.awt.BorderLayout;
32 import java.awt.Container;
33 import java.awt.event.WindowAdapter;
34 import java.awt.event.WindowEvent;
35
36 import org.forester.phylogeny.Phylogeny;
37 import org.forester.phylogeny.PhylogenyNode;
38 import org.forester.util.ForesterUtil;
39
40 final class NodeFrame extends javax.swing.JFrame {
41
42     private static final long serialVersionUID = -6943510233968557246L;
43     private final TreePanel   _reepanel;
44     private int               _index           = -1;
45
46     NodeFrame( final PhylogenyNode n, final Phylogeny tree, final TreePanel tp, final int x ) {
47         super( "Node " + ( ForesterUtil.isEmpty( n.getName() ) ? n.getId() : n.getName() ) );
48         _reepanel = tp;
49         setSize( AptxConstants.NODE_FRAME_SIZE );
50         _index = x;
51         final Container contentPane = getContentPane();
52         final NodePanel nodepanel = new NodePanel( n );
53         contentPane.add( nodepanel, BorderLayout.CENTER );
54         addWindowListener( new WindowAdapter() {
55
56             @Override
57             public void windowClosing( final WindowEvent e ) {
58                 remove(); // to release slot in array
59                 dispose();
60             }
61         } );
62         setResizable( false );
63         nodepanel.setVisible( true );
64         setVisible( true );
65     }
66
67     NodeFrame( final PhylogenyNode n, final Phylogeny tree, final TreePanel tp, final int x, final String dummy ) {
68         super( "Editable Node " + ( ForesterUtil.isEmpty( n.getName() ) ? n.getId() : n.getName() ) );
69         _reepanel = tp;
70         setSize( AptxConstants.NODE_FRAME_SIZE );
71         _index = x;
72         final Container contentPane = getContentPane();
73         final NodeEditPanel nodepanel = new NodeEditPanel( n, tp );
74         contentPane.add( nodepanel, BorderLayout.CENTER );
75         addWindowListener( new WindowAdapter() {
76
77             @Override
78             public void windowClosing( final WindowEvent e ) {
79                 try {
80                     nodepanel.writeAll();
81                 }
82                 catch ( final Exception ex ) {
83                     // Do nothing.
84                 }
85                 remove(); // to release slot in array
86                 dispose();
87             }
88         } );
89         setResizable( false );
90         nodepanel.setVisible( true );
91         setVisible( true );
92     }
93
94     TreePanel getTreePanel() {
95         return _reepanel;
96     }
97
98     void remove() {
99         if ( _index > -1 ) {
100             _reepanel.removeEditNodeFrame( _index ); // to release slot in array
101         }
102     }
103 }