Mercurial Hosting > junotu
changeset 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 |
parents | 9d3256f86803 |
children | 66d3fdffc3d2 |
files | src/junotu/Database.java src/junotu/Main.java src/junotu/TabEdit.java src/junotu/Window.java |
diffstat | 4 files changed, 55 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/Database.java Fri Apr 08 11:48:17 2022 +0200 +++ b/src/junotu/Database.java Fri Apr 08 12:09:57 2022 +0200 @@ -60,11 +60,11 @@ /* Find highest unique identifier. */ TopDocs topDocuments = luceneSearcher.search( - new MatchAllDocsQuery(), - null, - 1, - new Sort( new SortField( TAG_IDENTIFIER, SortField.LONG, true ) ) - ); + new MatchAllDocsQuery(), + null, + 1, + new Sort( new SortField( TAG_IDENTIFIER, SortField.LONG, true ) ) + ); if( topDocuments.scoreDocs.length == 0 ) { highestIdentifier = 0;
--- a/src/junotu/Main.java Fri Apr 08 11:48:17 2022 +0200 +++ b/src/junotu/Main.java Fri Apr 08 12:09:57 2022 +0200 @@ -69,16 +69,16 @@ public static void actionCardCreate() { Window active = windowGetActive(); + active.tabSwitch( Tab.EDIT ); active.tabEdit.cardCreate(); - active.tabSwitch( Tab.EDIT ); } public static void actionCardEdit( long identifier ) throws Exception { Window active = windowGetActive(); Card card = database.cardGetByIdentifier( identifier ); + active.tabSwitch( Tab.EDIT ); active.tabEdit.cardEdit( card ); - active.tabSwitch( Tab.EDIT ); } }
--- 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() {
--- a/src/junotu/Window.java Fri Apr 08 11:48:17 2022 +0200 +++ b/src/junotu/Window.java Fri Apr 08 12:09:57 2022 +0200 @@ -66,7 +66,12 @@ { tabsLayout.show(tabs, TAB_NAMES[tab.ordinal()]); activeTab = tab; - this.setTitle(preferredTitle()); + this.setTitle(preferredTitle(TAB_NAMES[activeTab.ordinal()])); + } + + public String preferredTitle( String tabStatus ) + { + return Main.PROGRAM_NAME+" - "+tabStatus; } private void panelsCreate() @@ -86,9 +91,4 @@ } - private String preferredTitle() - { - return Main.PROGRAM_NAME+" - "+TAB_NAMES[activeTab.ordinal()]; - } - }