Question / Possible idea for Swing GUI Intentions
Hello,
There are several patterns in Java Swing development.
Is there a way to generate this code automatically in IDEA, or are these good ideas for Intentions?
* Anonymous/Inner Adapter/Listener classes*
Swing uses callbacks to notify when a button is pressed, an item is selected, focus is lost, etc. One strategy is to have your GUI panel implement the listener class, but I don't like this because you have to advertise the callbacks as public methods of your class which pollutes your class interface. So, I usually just use anonymous classes. Here is some example code:
It would be nice to have an intention when the caret is at:
with choices like "Create inline anonymous class implementing ListSelectionListener" or "Create named anonymous class implementing ListSelectionListener". This could be shortened to just "Create inline ListSelectionListener" and "Create named ListSelectionListner".
Create inline ListSelectionListener *
Create named ListSelectionListener *
This intention could be applied to any class which has a constructor with Zero arguments. (A requirement of anonymous classes)
请先登录再写评论。
But can't you just use the built in Implement methods assistant to stub out
all the methods for you?
--
Duane Fields
Deep Magic Software and Consulting
http://www.deepmagic.com
"Alex" <itnadmin@jetbrains.com> wrote in message
news:27068031.1054834818580.JavaMail.jrun@is.intellij.net...
>
good ideas for Intentions?
>
selected, focus is lost, etc. One strategy is to have your GUI panel
implement the listener class, but I don't like this because you have to
advertise the callbacks as public methods of your class which pollutes your
class interface. So, I usually just use anonymous classes. Here is some
example code:
ListSelectionListener" or "Create named anonymous class implementing
ListSelectionListener". This could be shortened to just "Create inline
ListSelectionListener" and "Create named ListSelectionListner".
>
>
Zero arguments. (A requirement of anonymous classes)
Alex,
ChangeListener viewportListener = new |
Ctrl+Space
result in:
ChangeListener viewportListener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
}
};
then (if you need) Refactor->Convert Anonimous to Inner
--
Dmitry Skavish
-
Boston, MA, USA
tel. +1 781 910-3810
http://www.jzox.com
http://www.flashgap.com
Thanks! That is exactly what I wanted.
But I had to hit "new |<CTRLSHIFTSpace>" (Code->Complete Code->SmartType). If I just hit "new |<CTRL+Space>" it just pops up a list of all class names.
This is in IDEA 818.
-Alex