Mercurial Hosting > junotu
changeset 68:c6b1b4def7c1
Allowing to edit and create cards in a new window..
and adjusted search refreshes to work better with multiple windows.
To edit a card in a new window, click the card or the new card button while holding the SHIFT key.
author | Fox |
---|---|
date | Sat, 24 Dec 2022 01:49:57 +0100 |
parents | 3f0b4e44c6ef |
children | 6019854233a7 |
files | src/junotu/CardWidget.java src/junotu/Main.java src/junotu/TabBoard.java src/junotu/TabEdit.java src/junotu/TabSimpleSearch.java src/junotu/Window.java |
diffstat | 6 files changed, 79 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/CardWidget.java Sat Dec 24 01:27:22 2022 +0100 +++ b/src/junotu/CardWidget.java Sat Dec 24 01:49:57 2022 +0100 @@ -4,6 +4,7 @@ import java.awt.Dimension; import java.awt.GridBagConstraints; import javax.swing.BorderFactory; +import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -17,6 +18,7 @@ import junotu.Main; import junotu.Card; import junotu.Window; +import junotu.Window.Tab; public class CardWidget extends JPanel { @@ -65,7 +67,12 @@ switch( e.getButton() ) { case MouseEvent.BUTTON1: { - Main.actionCardEdit( (Window)getTopLevelAncestor(), identifier ); + boolean newWindow = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; + if( newWindow ) { + Main.actionCardEdit( Main.windowAdd( Tab.EDIT ), identifier ); + } else { + Main.actionCardEdit( (Window)getTopLevelAncestor(), identifier ); + } } }
--- a/src/junotu/Main.java Sat Dec 24 01:27:22 2022 +0100 +++ b/src/junotu/Main.java Sat Dec 24 01:49:57 2022 +0100 @@ -30,15 +30,16 @@ ); } - public static void windowAdd( Tab tab ) + public static Window windowAdd( Tab tab ) { for( int i = 0; i < windows.length; i++ ) { if( windows[i] == null ) { windows[i] = new Window( tab ); - return; + return windows[i]; } } - return; + System.out.print("Reached window limit! (Maximum "+Integer.toString(MAX_WINDOWS)+" windows.)\n"); + return null; } public static void windowClose( Window window ) @@ -46,6 +47,7 @@ int openWindowCount = 0; for( int i = 0; i < windows.length; i++ ) { if( windows[i] == window ) { + System.out.print( "Closing window slot "+Integer.toString(i)+": '"+window.getTitle()+"'.\n" ); window.dispose(); windows[i] = null; } @@ -70,6 +72,19 @@ return null; } + public static void refreshSearches() + { + for( int i = 0; i < windows.length; i++ ) { + if( windows[i] != null ) { + Window window = windows[i]; + window.tabSearch.dirty = true; + if( window.tabCurrent() == Tab.SEARCH ) { + window.tabSearch.refreshSearch(); + } + } + } + } + public static void actionCardCreate( Window window ) { //window = windowGetActive();
--- a/src/junotu/TabBoard.java Sat Dec 24 01:27:22 2022 +0100 +++ b/src/junotu/TabBoard.java Sat Dec 24 01:49:57 2022 +0100 @@ -615,8 +615,9 @@ card.tagRemove( Card.TAG_BOARD ); card.tagRemove( Card.TAG_BOARD_COLUMNS ); } - + Main.database.cardUpdate(card); + Main.refreshSearches(); return card; @@ -687,7 +688,6 @@ boardSave(); boardReset(); Window window = (Window)this.getTopLevelAncestor(); - window.tabSearch.search(); window.tabSwitch( Tab.SEARCH ); }
--- a/src/junotu/TabEdit.java Sat Dec 24 01:27:22 2022 +0100 +++ b/src/junotu/TabEdit.java Sat Dec 24 01:49:57 2022 +0100 @@ -446,7 +446,7 @@ Main.database.cardDeleteByIdentifier( card.identifierGet() ); Window window = (Window)this.getTopLevelAncestor(); - window.tabSearch.search(); + Main.refreshSearches(); reset(); window.tabSwitch( Tab.SEARCH ); @@ -474,14 +474,14 @@ Main.database.cardUpdate( card ); } - Window window = (Window)this.getTopLevelAncestor(); - window.tabSearch.search(); + Main.refreshSearches(); if( noSwitch ) { if( newCard ) { cardEdit( this.card ); } } else { + Window window = (Window)this.getTopLevelAncestor(); reset(); window.tabSwitch( Tab.SEARCH ); }
--- a/src/junotu/TabSimpleSearch.java Sat Dec 24 01:27:22 2022 +0100 +++ b/src/junotu/TabSimpleSearch.java Sat Dec 24 01:49:57 2022 +0100 @@ -26,21 +26,25 @@ import junotu.Main; import junotu.Window.Tab; +import junotu.Window.TabInterface; import junotu.Card; import junotu.CardWidget; -public class TabSimpleSearch extends JPanel implements ActionListener { +public class TabSimpleSearch extends JPanel implements ActionListener, TabInterface { + public boolean dirty; + private final String KEY_ACTION_COMMIT = "commit"; - + private JTextField field; private JButton create; private Box results; - - JScrollPane scroll; + private JScrollPane scroll; public TabSimpleSearch() { + dirty = true; + this.setLayout( new BorderLayout() ); JPanel top = new JPanel( new BorderLayout() ); @@ -94,12 +98,10 @@ field.setToolTipText("Search query."); create.setToolTipText("Create new card."); - - search(); } - public void search() { + private void search() { if( !javax.swing.SwingUtilities.isEventDispatchThread() ) { SwingUtilities.invokeLater( @@ -146,6 +148,12 @@ ); } + public void refreshSearch() + { + search(); + dirty = false; + } + private void scrollTop() { JScrollBar scrollbar = scroll.getVerticalScrollBar(); @@ -166,10 +174,14 @@ } - private void buttonClickedCreate() + private void buttonClickedCreate( boolean newWindow ) { - Window window = (Window)this.getTopLevelAncestor(); - Main.actionCardCreate( window ); + if( newWindow ) { + Main.actionCardCreate( Main.windowAdd( Tab.EDIT ) ); + } else { + Window window = (Window)this.getTopLevelAncestor(); + Main.actionCardCreate( window ); + } } public void actionPerformed( ActionEvent e ) @@ -185,7 +197,15 @@ } } else if( source == create ) { - buttonClickedCreate(); + boolean newWindow = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; + buttonClickedCreate( newWindow ); + } + } + + public void onSwitchedTo() { + if( dirty ) { + refreshSearch(); + dirty = false; } }
--- a/src/junotu/Window.java Sat Dec 24 01:27:22 2022 +0100 +++ b/src/junotu/Window.java Sat Dec 24 01:49:57 2022 +0100 @@ -23,6 +23,10 @@ public class Window extends JFrame { + public static interface TabInterface { + void onSwitchedTo(); + } + public enum Tab { SEARCH, EDIT, @@ -68,11 +72,24 @@ public void tabSwitch( Tab tab ) { + if( tab == activeTab ) { + return; + } tabsLayout.show(tabs, TAB_NAMES[tab.ordinal()]); + Object tabObject = tabs.getComponent(tab.ordinal()); + if( tabObject instanceof TabInterface ) { + TabInterface tabInterface = (TabInterface)tabObject; + tabInterface.onSwitchedTo(); + } activeTab = tab; this.setTitle(preferredTitle(TAB_NAMES[activeTab.ordinal()])); } + public Tab tabCurrent() + { + return activeTab; + } + public String preferredTitle( String tabStatus ) { return Main.PROGRAM_NAME+" - "+tabStatus;