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