X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FTextFrame.java;h=b2a35ea8867c4d4a4018b91daaebc7a868d563af;hb=693353f5ea85d3e50a77f9b1cd9d87711d23412b;hp=54c6f800f70a11a99cb6494c6926dbe9c46d8b50;hpb=ccf4c584032d16ed0ed8d0678f01305887724f96;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/TextFrame.java b/forester/java/src/org/forester/archaeopteryx/TextFrame.java index 54c6f80..b2a35ea 100644 --- a/forester/java/src/org/forester/archaeopteryx/TextFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/TextFrame.java @@ -8,7 +8,7 @@ // and Howard Hughes Medical Institute // Copyright (C) 2003-2007 Ethalinda K.S. Cannon // All rights reserved -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -18,16 +18,17 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx; +import java.awt.AWTPermission; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; @@ -41,6 +42,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.LinkedList; import javax.swing.JButton; import javax.swing.JFrame; @@ -51,35 +53,36 @@ import javax.swing.JTextArea; final class TextFrame extends JFrame implements ActionListener, ClipboardOwner { /** - * + * */ - private static final long serialVersionUID = -5012834229705518363L; - private static Color ta_text_color = new Color( 0, 0, 0 ), + private static final long serialVersionUID = -5012834229705518363L; + private static Color ta_text_color = new Color( 0, 0, 0 ), ta_background_color = new Color( 240, 240, 240 ), background_color = new Color( 215, 215, 215 ), button_background_color = new Color( 215, 215, 215 ), button_text_color = new Color( 0, 0, 0 ); - private final static Font button_font = new Font( "Helvetica", Font.PLAIN, 10 ), + private final static Font button_font = new Font( "Helvetica", Font.PLAIN, 10 ), ta_font = new Font( "Helvetica", Font.PLAIN, 10 ); - private boolean can_use_clipboard; - private final String text; - private final JTextArea jtextarea; - private final JButton close_button; - private JButton copy_button; - private final JPanel buttonjpanel; - private final Container contentpane; + private boolean can_use_clipboard; + private final String text; + private final JTextArea jtextarea; + private final JButton close_button; + private JButton copy_button; + private final JPanel buttonjpanel; + private final Container contentpane; + private final LinkedList _tframes; - private TextFrame( final String s ) { + private TextFrame( final String s, final String title, final LinkedList tframes ) { // first things first - setTitle( Constants.PRG_NAME ); + setTitle( title ); text = s; + _tframes = tframes; // check to see if we have permission to use the clipboard: can_use_clipboard = true; final SecurityManager sm = System.getSecurityManager(); if ( sm != null ) { try { - sm.checkSystemClipboardAccess(); + sm.checkPermission( new AWTPermission( "accessClipboard" ) ); } catch ( final Exception e ) { - //nope! can_use_clipboard = false; } } @@ -118,25 +121,25 @@ final class TextFrame extends JFrame implements ActionListener, ClipboardOwner { @Override public void windowClosing( final WindowEvent e ) { - close(); + removeMe(); } } ); setVisible( true ); } + @Override public void actionPerformed( final ActionEvent e ) { final Object o = e.getSource(); if ( o == close_button ) { - close(); + removeMe(); } else if ( o == copy_button ) { copy(); } } - void close() { - setVisible( false ); - dispose(); + @Override + public void lostOwnership( final Clipboard clipboard, final Transferable contents ) { } private void copy() { @@ -149,10 +152,20 @@ final class TextFrame extends JFrame implements ActionListener, ClipboardOwner { sys_clipboard.setContents( contents, this ); } - public void lostOwnership( final Clipboard clipboard, final Transferable contents ) { + void close() { + setVisible( false ); + dispose(); + } + + void removeMe() { + final int i = _tframes.indexOf( this ); + if ( i >= 0 ) { + _tframes.remove( i ); + } + close(); } - static TextFrame instantiate( final String s ) { - return new TextFrame( s ); + static TextFrame instantiate( final String s, final String title, final LinkedList tframes ) { + return new TextFrame( s, title, tframes ); } }