Mercurial > hg > release > thermostat-1.6
changeset 1980:f1aa6970ef55
Fix strange use of clone() in TreeMapComponent
PR3059
Reviewed-by: jkang
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-June/019844.html
Original-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-September/016419.html
author | James Aziz <jaziz@redhat.com> |
---|---|
date | Wed, 29 Jun 2016 12:23:02 -0400 |
parents | e5259653d335 |
children | d45a7d554e2e |
files | client/swing/src/main/java/com/redhat/thermostat/client/swing/components/experimental/TreeMapComponent.java |
diffstat | 1 files changed, 17 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/experimental/TreeMapComponent.java Wed Jun 29 12:23:01 2016 -0400 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/experimental/TreeMapComponent.java Wed Jun 29 12:23:02 2016 -0400 @@ -276,7 +276,7 @@ return null; } - Comp comp = (Comp) mainComp.clone(); + Comp comp = new Comp(mainComp); comp.setBounds(node.getRectangle().getBounds()); return comp; @@ -304,7 +304,7 @@ // if the container is greater than the label, add it to the container if (componentW > fontArea.width && componentH > fontArea.height) { - Label label = (Label) cachedLabel.clone(); + Label label = new Label(cachedLabel); label.setBounds(5, 1, cont.getWidth(), fontArea.height); label.setText(s); cont.add(label); @@ -598,12 +598,8 @@ return lastClicked; } - /** - * This class provides an extension of {@link JLabel} which main - * characteristic is to implement the {@link Cloneable} interface in order - * to make his creation faster then JLabel class. - */ - class Label extends JLabel implements Cloneable { + class Label extends JLabel { + private static final long serialVersionUID = 1L; public Label(String s) { @@ -612,26 +608,20 @@ setBounds(0, 0, getPreferredSize().width, FONT_SIZE); } - @Override - protected JLabel clone() { - Label clone = new Label(""); - clone.setFont(getFont()); - clone.setText(getText()); - clone.setBackground(getBackground()); - clone.setBounds(getBounds()); - clone.setBorder(getBorder()); - return clone; + protected Label(Label other) { + this.setFont(other.getFont()); + this.setText(other.getText()); + this.setBackground(other.getBackground()); + this.setBounds(other.getBounds()); + this.setBorder(other.getBorder()); } } /** - * This class provides an extension of {@link JComponent} which main - * characteristic is to implement {@link Cloneable} interface in order to - * make his creation faster. <br> - * It also provides some action listeners that allow to select it, performing + * This class provides some action listeners that allow to select it, performing * zoom operations for the treemap. */ - class Comp extends JComponent implements Cloneable { + class Comp extends JComponent { private static final long serialVersionUID = 1L; @@ -657,14 +647,11 @@ addMouseListener(this); } - @Override - public Comp clone() { - Comp clone = new Comp(); - clone.setBounds(getBounds()); - clone.setBorder(getBorder()); - clone.setLayout(getLayout()); - clone.setOpaque(true); - return clone; + public Comp(Comp other) { + this.setBounds(other.getBounds()); + this.setBorder(other.getBorder()); + this.setLayout(other.getLayout()); + this.setOpaque(true); } public void setNode(TreeMapNode node) {