Priority
Normal
Type
Feature 
State
Open 
Assignee
Anna Kozlova 
Subsystem
Refactoring 
Affected versions
Fix for
  • Submitted by   Dave Yost
    3 years ago (22 Jan 2007 05:07)
  • Updated by   Dave Yost
    5 months ago (27 Feb 2010 23:08)
  • Jira: IDEA-36434
    (history, comments)
IDEA-36434 New refactoring: Introduce class...
1
With code like this

layeredPane = new JLayeredPane();
layeredPane.setPreferredSize(new Dimension(300, 310));
layeredPane.setBorder(BorderFactory.createTitledBorder(
"Move the Mouse to Move Duke"));
layeredPane.addMouseMotionListener(this);
....
}
}

you should be able to point at layeredPane and ask IDEA to introduce a new class to encapsulate code relating to it.

layeredPane = new OurLayeredPane(this);
....
}
}

class OurLayeredPane extends JLayeredPane {
OurLayeredPane(MouseMotionListener listener) {
setPreferredSize(new Dimension(300, 310));
setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));
addMouseMotionListener(listener);
}
}

IDEA should do its best to drag along as much code as possible into the new class,
soliciting confirmation on code you might not want to move.

The above extract is from the Java Tutorial LayeredPaneDemo.
This tarball contains the original, my refactoring,
and IDEA project and module files.
http://Yost.com/computers/java/LayeredPaneDemo/LayeredPaneDemoRefactored.tgz
Comments (4)
 
History
 
Linked Issues (0)
 
Dave Yost
  Dave Yost
22 Jan 2007 05:40
(3 years ago)
In this same tutorial file, there is this code:

private JLabel createColoredLabel(String text, Color color, Point origin) {
JLabel label = new JLabel(text);
label.setVerticalAlignment(JLabel.TOP);
label.setHorizontalAlignment(JLabel.CENTER);
label.setOpaque(true);
label.setBackground(color);
label.setForeground(Color.black);
label.setBorder(BorderFactory.createLineBorder(Color.black));
label.setBounds(origin.x, origin.y, 140, 140);
return label;
}

If I could point IDEA at this label variable an introduce a new ColoredLabel class, then the next thing I would do would be to inline this method. It would be extra cool if IDEA would incorporate both steps in one.

Just to have this ability to introduce a class would be great, but knowing you guys, you'll also take on all the really hard work of managing interconnections between the new class and the code that uses it, introducing fields, constructor arguments, accessors, etc., to make it really awesome.

Also, maximally reducing the specificity of the type of the variable that refers to an instance of the introduced class would also be nice.

If you can make IDEA able to do most of the work I did in this LayeredPaneDemo file, you will have made an important addition to IDEA's refactoring abilities.

Please remember to give us flexibility to make the introduced class either an inner class, a class in the same file, or a standalone class.
Dave Yost
  Dave Yost
12 May 2007 11:18
(3 years ago)
I've made a web page that talks about this.
http://yost.com/computers/java/java-spaghetti/
Dave Yost
  Dave Yost
05 Oct 2008 21:55
(21 months ago)
Anything happening with this?
Dave Yost
  Dave Yost
27 Feb 2010 23:08
(5 months ago)
This feature should probably offer to create the new class either with inheritance or with delegation. If delegation is selected, then I may or may not want the new class to implement relevant interface(s). If not, then by default, I would want to implement and delegate only the methods actually used by the surrounding code.