Mercurial Hosting > junotu
changeset 43:0fa52bdb0673
TabColumns: Now able to remove columns via middle click.
author | Fox |
---|---|
date | Sun, 30 Oct 2022 02:06:02 +0200 |
parents | a5bc0a1f173c |
children | 5aa3c7e36ff1 |
files | src/junotu/TabColumns.java |
diffstat | 1 files changed, 26 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/TabColumns.java Sun Oct 30 01:40:43 2022 +0200 +++ b/src/junotu/TabColumns.java Sun Oct 30 02:06:02 2022 +0200 @@ -42,7 +42,7 @@ import junotu.Window.Tab; import junotu.Card; -public class TabColumns extends JPanel { +public class TabColumns extends JPanel implements MouseListener { final static int COLUMN_CONTENT_WIDTH = 256; final static int COLUMN_WIDTH = COLUMN_CONTENT_WIDTH+16; @@ -68,6 +68,7 @@ constraints.anchor = GridBagConstraints.NORTHWEST; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; + constraints.weighty = 0.0; constraints.gridx = 0; constraints.gridy = 0; @@ -118,8 +119,7 @@ cardWidget.addMouseListener(this); /* TODO: Check if works properly. */ cards.add( cardWidget, at ); - cards.validate(); - this.validate(); /* Without this, first inserted card doesn't show up. */ + cards.revalidate(); } public void actionPerformed( ActionEvent e ) @@ -133,13 +133,11 @@ 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? */ + if( e.getSource() instanceof ColumnCardWidget ) { + if( e.getButton() == MouseEvent.BUTTON2 ) { + cards.remove( (ColumnCardWidget)e.getSource() ); + cards.revalidate(); + } } } @@ -239,8 +237,26 @@ { ColumnWidget column = new ColumnWidget(); column.titleSet("New column"); + column.addMouseListener(this); columns.add( Box.createHorizontalStrut(16) ); columns.add(column); } + + public void mouseClicked( MouseEvent e ) + { + if( e.getButton() == MouseEvent.BUTTON2 ) { + if( !(e.getSource() instanceof ColumnWidget) ) + return; + + columns.remove( (ColumnWidget)e.getSource() ); + /* TODO: FIXME: One of the columns is frequently (visually) not removed (until layout is manually refreshed). */ + columns.revalidate(); + } + } + + public void mouseEntered( MouseEvent e ) {} + public void mouseExited( MouseEvent e ) {} + public void mousePressed( MouseEvent e ) {} + public void mouseReleased( MouseEvent e ) {} }