Mercurial Hosting > junotu
diff src/junotu/TabEdit.java @ 9:dd51276f95a2
Dynamically change window title on card edit tab to reflect card title
author | Fox |
---|---|
date | Fri, 08 Apr 2022 12:09:57 +0200 (2022-04-08) |
parents | 9d3256f86803 |
children | 587b69a38915 |
line wrap: on
line diff
--- a/src/junotu/TabEdit.java Fri Apr 08 11:48:17 2022 +0200 +++ b/src/junotu/TabEdit.java Fri Apr 08 12:09:57 2022 +0200 @@ -5,6 +5,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.event.DocumentListener; +import javax.swing.event.DocumentEvent; + import javax.swing.JPanel; import java.awt.BorderLayout; @@ -59,7 +62,7 @@ bottom.add( save ); //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - + back.addActionListener( new ActionListener() { @Override @@ -79,6 +82,27 @@ } } ); + + title.getDocument().addDocumentListener( + new DocumentListener() + { + @Override + public void changedUpdate( DocumentEvent e ) + { + updateTitle(); + } + @Override + public void removeUpdate( DocumentEvent e ) + { + updateTitle(); + } + @Override + public void insertUpdate( DocumentEvent e ) + { + updateTitle(); + } + } + ); } @@ -86,6 +110,7 @@ { newCard = true; identifier = -1; + updateTitle(); } public void cardEdit( Card card ) @@ -94,6 +119,7 @@ identifier = card.identifier; title.setText( card.title ); content.setText( card.content ); + updateTitle(); } private void clearWidgets() @@ -101,6 +127,21 @@ title.setText(""); content.setText(""); } + + private void updateTitle() + { + Window window = (Window)this.getTopLevelAncestor(); + + String text = title.getText(); + String action = newCard ? "Create" : "Edit"; + + if( text.length() > 0 ) { + window.setTitle( window.preferredTitle( action+": "+text ) ); + } else { + window.setTitle( window.preferredTitle( action ) ); + } + + } private void buttonClickedBack() {