Mercurial Hosting > junotu
changeset 44:5aa3c7e36ff1
TabEdit: Simplify action listeners
author | Fox |
---|---|
date | Sun, 30 Oct 2022 02:31:03 +0200 |
parents | 0fa52bdb0673 |
children | 1cad42247892 |
files | src/junotu/TabEdit.java |
diffstat | 1 files changed, 35 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/TabEdit.java Sun Oct 30 02:06:02 2022 +0200 +++ b/src/junotu/TabEdit.java Sun Oct 30 02:31:03 2022 +0200 @@ -32,9 +32,9 @@ import junotu.GUIToolbox; import junotu.Card; -public class TabEdit extends JPanel { +public class TabEdit extends JPanel implements ActionListener { - private class TagWidget extends JButton { + private class TagWidget extends JButton implements ActionListener { public String tag; public Object value; @@ -43,20 +43,10 @@ super(); this.tag = tag; this.value = value; - TagWidget ref = this; + + addActionListener(this); - addActionListener( - new ActionListener() { - @Override - public void actionPerformed( ActionEvent e ) - { - tagEdit( ref ); - } - } - ); - update(); - } public void update() @@ -67,6 +57,11 @@ setText( tag ); } } + + public void actionPerformed( ActionEvent e ) + { + tagEdit( this ); + } } @@ -83,7 +78,10 @@ private JPanel tags; private JButton addTag; + private JButton back; private JButton delete; + private JButton save; + public TabEdit() { @@ -97,10 +95,10 @@ editedTagField = new JTextField(); addTag = new JButton("+"); - Box bottom = Box.createHorizontalBox(); - JButton back = new JButton("Cancel"); - delete = new JButton("Delete"); - JButton save = new JButton("Save"); + Box bottom = Box.createHorizontalBox(); + back = new JButton("Cancel"); + delete = new JButton("Delete"); + save = new JButton("Save"); tags.setLayout( new FlowLayout() ); @@ -131,46 +129,10 @@ //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - back.addActionListener( - new ActionListener() { - @Override - public void actionPerformed( ActionEvent e ) - { - buttonClickedBack(); - } - } - ); - - delete.addActionListener( - new ActionListener() { - @Override - public void actionPerformed( ActionEvent e ) - { - buttonClickedDelete(); - } - } - ); - - save.addActionListener( - new ActionListener() { - @Override - public void actionPerformed( ActionEvent e ) - { - boolean noSwitch = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; - buttonClickedSave( noSwitch ); - } - } - ); - - addTag.addActionListener( - new ActionListener() { - @Override - public void actionPerformed( ActionEvent e ) - { - tagAdd(); - } - } - ); + back.addActionListener(this); + delete.addActionListener(this); + save.addActionListener(this); + addTag.addActionListener(this); editedTagField.addFocusListener( new FocusListener() @@ -533,5 +495,20 @@ window.tabSwitch( Tab.SEARCH ); } } + + public void actionPerformed( ActionEvent e ) + { + Object source = e.getSource(); + if( source == back ) { + buttonClickedBack(); + } else if( source == delete ) { + buttonClickedDelete(); + } else if( source == save ) { + boolean noSwitch = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; + buttonClickedSave( noSwitch ); + } else if( source == addTag ) { + tagAdd(); + } + } }