class MyListCellRenderer extends JPanel implements ListCellRenderer { private JLabel iconLabel = new JLabel(); private JLabel titleLabel = new JLabel(); private JXHyperlink descriptionLabel = new JXHyperlink(); private JPanel centerPanel; private Border lineBorder = new HeaderSeparatorBorder(new Color(230, 230, 230)); MyListCellRenderer() { setLayout(new BorderLayout()); centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout()); centerPanel.add(titleLabel, BorderLayout.NORTH); centerPanel.add(descriptionLabel, BorderLayout.CENTER); add(iconLabel, BorderLayout.WEST); add(centerPanel, BorderLayout.CENTER); setBorder(BorderFactory.createCompoundBorder(lineBorder, BorderFactory.createEmptyBorder(2, 2, 2, 2))); iconLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 8)); centerPanel.setOpaque(false); setOpaque(true); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } ISearchResult result = (ISearchResult) value; titleLabel.setText(result.getTitle()); iconLabel.setIcon(ImageLoader.getSmallIcon(IconKeys.USER)); descriptionLabel.setText(result.getDescription()); return this; } } class HeaderSeparatorBorder extends AbstractBorder { protected Color color; public HeaderSeparatorBorder(Color color) { super(); this.color = color; } /** * Paints the border for the specified component with the specified * position and size. * * @param c * the component for which this border is being painted * @param g * the paint graphics * @param x * the x position of the painted border * @param y * the y position of the painted border * @param width * the width of the painted border * @param height * the height of the painted border */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); g.setColor(color); g.drawLine(x, y + height - 1, x + width - 1, y + height - 1); g.setColor(oldColor); } /** * Returns the insets of the border. * * @param c * the component for which this border insets value applies */ public Insets getBorderInsets(Component c) { return new Insets(0, 0, 1, 0); } /** * Reinitialize the insets parameter with this Border's current Insets. * * @param c * the component for which this border insets value applies * @param insets * the object to be reinitialized */ public Insets getBorderInsets(Component c, Insets insets) { insets.left = insets.top = insets.right = insets.bottom = 1; return insets; } }
class MyListCellRenderer extends JPanel implements ListCellRenderer { private JLabel iconLabel = new JLabel(); private JLabel titleLabel = new JLabel(); private JXHyperlink descriptionLabel = new JXHyperlink(); private JPanel centerPanel; private Border lineBorder = new HeaderSeparatorBorder(new Color(230, 230, 230)); MyListCellRenderer() { setLayout(new BorderLayout()); centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout()); centerPanel.add(titleLabel, BorderLayout.NORTH); centerPanel.add(descriptionLabel, BorderLayout.CENTER); add(iconLabel, BorderLayout.WEST); add(centerPanel, BorderLayout.CENTER); setBorder(BorderFactory.createCompoundBorder(lineBorder, BorderFactory.createEmptyBorder(2, 2, 2, 2))); iconLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4)); centerPanel.setOpaque(false); setOpaque(true); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } IContactModelPartial result = (IContactModelPartial) value; titleLabel.setText(result.getName()); iconLabel.setIcon(ImageLoader.getSmallIcon(IconKeys.USER)); descriptionLabel.setText(result.getAddress()); return this; } } class HeaderSeparatorBorder extends AbstractBorder { protected Color color; public HeaderSeparatorBorder(Color color) { super(); this.color = color; } /** * Paints the border for the specified component with the specified * position and size. * * @param c * the component for which this border is being painted * @param g * the paint graphics * @param x * the x position of the painted border * @param y * the y position of the painted border * @param width * the width of the painted border * @param height * the height of the painted border */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); g.setColor(color); g.drawLine(x, y + height - 1, x + width - 1, y + height - 1); g.setColor(oldColor); } /** * Returns the insets of the border. * * @param c * the component for which this border insets value applies */ public Insets getBorderInsets(Component c) { return new Insets(0, 0, 1, 0); } /** * Reinitialize the insets parameter with this Border's current Insets. * * @param c * the component for which this border insets value applies * @param insets * the object to be reinitialized */ public Insets getBorderInsets(Component c, Insets insets) { insets.left = insets.top = insets.right = insets.bottom = 1; return insets; } }
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/contact/src/main/java/org/columba/addressbook/gui/search/SearchResultList.java File path: /columba-1.4-src/contact/src/main/java/org/columba/contact/gui/box/ContactList.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
class MyListCellRenderer extends JPanel implements ListCellRenderer {
1
class MyListCellRenderer extends JPanel implements ListCellRenderer {
2
		private JLabel iconLabel = new JLabel();
2
		private JLabel iconLabel = new JLabel();
3
		private JLabel titleLabel = new JLabel();
3
		private JLabel titleLabel = new JLabel();
4
		private JXHyperlink descriptionLabel = new JXHyperlink();
4
		private JXHyperlink descriptionLabel = new JXHyperlink();
5
		private JPanel centerPanel;
5
		private JPanel centerPanel;
6
		private Border lineBorder = new HeaderSeparatorBorder(new Color(230,
6
		private Border lineBorder = new HeaderSeparatorBorder(new Color(230,
7
				230, 230));
7
				230, 230));
8
		MyListCellRenderer() {
8
		MyListCellRenderer() {
9
			setLayout(new BorderLayout());
9
			setLayout(new BorderLayout());
10
			centerPanel = new JPanel();
10
			centerPanel = new JPanel();
11
			centerPanel.setLayout(new BorderLayout());
11
			centerPanel.setLayout(new BorderLayout());
12
			centerPanel.add(titleLabel, BorderLayout.NORTH);
12
			centerPanel.add(titleLabel, BorderLayout.NORTH);
13
			centerPanel.add(descriptionLabel, BorderLayout.CENTER);
13
			centerPanel.add(descriptionLabel, BorderLayout.CENTER);
14
			add(iconLabel, BorderLayout.WEST);
14
			add(iconLabel, BorderLayout.WEST);
15
			add(centerPanel, BorderLayout.CENTER);
15
			add(centerPanel, BorderLayout.CENTER);
16
			setBorder(BorderFactory.createCompoundBorder(lineBorder,
16
			setBorder(BorderFactory.createCompoundBorder(lineBorder,
17
					BorderFactory.createEmptyBorder(2, 2, 2, 2)));
17
					BorderFactory.createEmptyBorder(2, 2, 2, 2)));
18
			iconLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 8));
18
			iconLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
19
			centerPanel.setOpaque(false);
19
			centerPanel.setOpaque(false);
20
			setOpaque(true);
20
			setOpaque(true);
21
		}
21
		}
22
		public Component getListCellRendererComponent(JList list, Object value,
22
		public Component getListCellRendererComponent(JList list, Object value,
23
				int index, boolean isSelected, boolean cellHasFocus) {
23
				int index, boolean isSelected, boolean cellHasFocus) {
24
			if (isSelected) {
24
			if (isSelected) {
25
				 setBackground(list.getSelectionBackground());
25
				setBackground(list.getSelectionBackground());
26
				 setForeground(list.getSelectionForeground());
26
				setForeground(list.getSelectionForeground());
27
			} else {
27
			} else {
28
				setBackground(list.getBackground());
28
				setBackground(list.getBackground());
29
				setForeground(list.getForeground());
29
				setForeground(list.getForeground());
30
			}
30
			}
31
			ISearchResult result = (ISearchResult) value;
31
			IContactModelPartial result = (IContactModelPartial) value;
32
			titleLabel.setText(result.getTitle());
32
			titleLabel.setText(result.getName());
33
			iconLabel.setIcon(ImageLoader.getSmallIcon(IconKeys.USER));
33
			iconLabel.setIcon(ImageLoader.getSmallIcon(IconKeys.USER));
34
			descriptionLabel.setText(result.getDescription());
34
			descriptionLabel.setText(result.getAddress());
35
			return this;
35
			return this;
36
		}
36
		}
37
	}
37
	}
38
	class HeaderSeparatorBorder extends AbstractBorder {
38
	class HeaderSeparatorBorder extends AbstractBorder {
39
		protected Color color;
39
		protected Color color;
40
		public HeaderSeparatorBorder(Color color) {
40
		public HeaderSeparatorBorder(Color color) {
41
			super();
41
			super();
42
			this.color = color;
42
			this.color = color;
43
		}
43
		}
44
		/**
44
		/**
45
		 * Paints the border for the specified component with the specified
45
		 * Paints the border for the specified component with the specified
46
		 * position and size.
46
		 * position and size.
47
		 * 
47
		 * 
48
		 * @param c
48
		 * @param c
49
		 *            the component for which this border is being painted
49
		 *            the component for which this border is being painted
50
		 * @param g
50
		 * @param g
51
		 *            the paint graphics
51
		 *            the paint graphics
52
		 * @param x
52
		 * @param x
53
		 *            the x position of the painted border
53
		 *            the x position of the painted border
54
		 * @param y
54
		 * @param y
55
		 *            the y position of the painted border
55
		 *            the y position of the painted border
56
		 * @param width
56
		 * @param width
57
		 *            the width of the painted border
57
		 *            the width of the painted border
58
		 * @param height
58
		 * @param height
59
		 *            the height of the painted border
59
		 *            the height of the painted border
60
		 */
60
		 */
61
		public void paintBorder(Component c, Graphics g, int x, int y,
61
		public void paintBorder(Component c, Graphics g, int x, int y,
62
				int width, int height) {
62
				int width, int height) {
63
			Color oldColor = g.getColor();
63
			Color oldColor = g.getColor();
64
			g.setColor(color);
64
			g.setColor(color);
65
			g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
65
			g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
66
			g.setColor(oldColor);
66
			g.setColor(oldColor);
67
		}
67
		}
68
		/**
68
		/**
69
		 * Returns the insets of the border.
69
		 * Returns the insets of the border.
70
		 * 
70
		 * 
71
		 * @param c
71
		 * @param c
72
		 *            the component for which this border insets value applies
72
		 *            the component for which this border insets value applies
73
		 */
73
		 */
74
		public Insets getBorderInsets(Component c) {
74
		public Insets getBorderInsets(Component c) {
75
			return new Insets(0, 0, 1, 0);
75
			return new Insets(0, 0, 1, 0);
76
		}
76
		}
77
		/**
77
		/**
78
		 * Reinitialize the insets parameter with this Border's current Insets.
78
		 * Reinitialize the insets parameter with this Border's current Insets.
79
		 * 
79
		 * 
80
		 * @param c
80
		 * @param c
81
		 *            the component for which this border insets value applies
81
		 *            the component for which this border insets value applies
82
		 * @param insets
82
		 * @param insets
83
		 *            the object to be reinitialized
83
		 *            the object to be reinitialized
84
		 */
84
		 */
85
		public Insets getBorderInsets(Component c, Insets insets) {
85
		public Insets getBorderInsets(Component c, Insets insets) {
86
			insets.left = insets.top = insets.right = insets.bottom = 1;
86
			insets.left = insets.top = insets.right = insets.bottom = 1;
87
			return insets;
87
			return insets;
88
		}
88
		}
89
	}
89
	}
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0