Mercurial Hosting > junotu
changeset 42:a5bc0a1f173c
TabColumns: Now able to remove cards by middle clicking them
author | Fox |
---|---|
date | Sun, 30 Oct 2022 01:40:43 +0200 |
parents | 101ad0b0ab6f |
children | 0fa52bdb0673 |
files | src/junotu/TabColumns.java |
diffstat | 1 files changed, 36 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/TabColumns.java Sun Oct 30 00:29:20 2022 +0200 +++ b/src/junotu/TabColumns.java Sun Oct 30 01:40:43 2022 +0200 @@ -9,8 +9,11 @@ import java.awt.GridBagConstraints; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseListener; +import java.awt.event.MouseAdapter; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; @@ -24,6 +27,7 @@ import java.awt.GridBagLayout; import javax.swing.BoxLayout; +import java.awt.Component; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextArea; @@ -43,7 +47,7 @@ final static int COLUMN_CONTENT_WIDTH = 256; final static int COLUMN_WIDTH = COLUMN_CONTENT_WIDTH+16; - private class ColumnWidget extends JPanel implements ActionListener { + private class ColumnWidget extends JPanel implements ActionListener, MouseListener { JLabel title; JTextField titleEdit; Box cards; @@ -111,6 +115,7 @@ at = cards.getComponentCount(); } ColumnCardWidget cardWidget = new ColumnCardWidget( card ); + cardWidget.addMouseListener(this); /* TODO: Check if works properly. */ cards.add( cardWidget, at ); cards.validate(); @@ -125,6 +130,24 @@ insertCard( newCard, -1 ); } } + + public void mouseClicked( MouseEvent e ) + { + if( e.getButton() == MouseEvent.BUTTON2 ) { + if( !(e.getSource() instanceof ColumnCardWidget) ) + return; + + cards.remove( (ColumnCardWidget)e.getSource() ); + cards.validate(); + this.validate(); /* Doesn't properly update if this is not used. Is there some sort of invalidate all? */ + } + } + + public void mouseEntered( MouseEvent e ) {} + public void mouseExited( MouseEvent e ) {} + public void mousePressed( MouseEvent e ) {} + public void mouseReleased( MouseEvent e ) {} + } private class ColumnCardWidget extends JPanel { @@ -153,6 +176,18 @@ title.setOpaque( false ); this.add( title, BorderLayout.CENTER ); + + MouseAdapter mouseListener = new MouseAdapter() + { + @Override + public void mouseClicked( MouseEvent e ) + { + e.setSource(ColumnCardWidget.this); + processMouseEvent(e); + } + }; + + title.addMouseListener( mouseListener ); }