JAL-2805 JAL-281 JAL-2847 set tree file made public as well (heh)
[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, this );
53         contentPane.add( nodepanel );
54         addWindowListener( new WindowAdapter() {
55
56             @Override
57             public void windowClosing( final WindowEvent e ) {
58                 close();
59             }
60         } );
61         this.setLocationRelativeTo( tp );
62         setResizable( true );
63         nodepanel.setVisible( true );
64         setVisible( true );
65     }
66
67     
68     void close() {
69         remove(); // to release slot in array
70         dispose();
71     }
72     
73     NodeFrame( final PhylogenyNode n, final Phylogeny tree, final TreePanel tp, final int x, final String dummy ) {
74         super( "Editable Node " + ( ForesterUtil.isEmpty( n.getName() ) ? n.getId() : n.getName() ) );
75         _reepanel = tp;
76         setSize( AptxConstants.NODE_FRAME_SIZE );
77         _index = x;
78         final Container contentPane = getContentPane();
79         final NodeEditPanel nodepanel = new NodeEditPanel( n, tp, this );
80         contentPane.add( nodepanel, BorderLayout.CENTER );
81         addWindowListener( new WindowAdapter() {
82
83             @Override
84             public void windowClosing( final WindowEvent e ) {
85                 try {
86                     nodepanel.writeAll();
87                 }
88                 catch ( final Exception ex ) {
89                     // Do nothing.
90                 }
91                 remove(); // to release slot in array
92                 dispose();
93             }
94         } );
95         this.setLocationRelativeTo( tp );
96         setResizable( false );
97         nodepanel.setVisible( true );
98         setVisible( true );
99     }
100
101     TreePanel getTreePanel() {
102         return _reepanel;
103     }
104
105     void remove() {
106         if ( _index > -1 ) {
107             _reepanel.removeEditNodeFrame( _index ); // to release slot in array
108         }
109     }
110 }