synchronized (parent.getTreeLock()) { update(parent); int ncomponents = parent.getComponentCount(); if (ncomponents == 0) { return; } // Pass 1: compute preferred row heights / column widths int total_height = 0; for (int r = 0, i = 0; r < nrows; r++) { for (int c = 0; c < ncols; c++, i++) { if (i < ncomponents) { Dimension d = parent.getComponent(i).getPreferredSize(); row_heights[r] = Math.max(row_heights[r], d.height); col_widths[c] = Math.max(col_widths[c], d.width); } else { break; } } total_height += row_heights[r]; } int total_width = 0; for (int c = 0; c < ncols; c++) { total_width += col_widths[c]; } // Pass 2: redistribute free space Dimension parent_size = parent.getSize(); Insets insets = parent.getInsets(); int free_height = parent_size.height - insets.top - insets.bottom - (nrows - 1) * vgap; int free_width = parent_size.width - insets.left - insets.right - (ncols - 1) * hgap; if (total_height != free_height) { double dy = (double)free_height / (double)total_height; for (int r = 0; r < nrows; r++) { row_heights[r] = (int) ((double)row_heights[r] * dy); } } if (total_width != free_width) { double dx = ((double)free_width) / ((double)total_width); for (int c = 0; c < ncols; c++) { col_widths[c] = (int) ((double)col_widths[c] * dx); } } // Pass 3: layout components for (int r = 0, y = insets.top, i = 0; r < nrows; y += row_heights[r] + vgap, r++) { for (int c = 0, x = insets.left; c < ncols; x += col_widths[c] + hgap, c++, i++) { if (i < ncomponents) { parent.getComponent(i).setBounds(x, y, col_widths[c], row_heights[r]); } } } }
synchronized (parent.getTreeLock()) { update(parent); int ncomponents = parent.getComponentCount(); if (ncomponents == 0) { return; } // Pass 1: compute preferred row heights / column widths int total_height = 0; for (int r = 0, i = 0; r < nrows; r++) { for (int c = 0; c < ncols; c++, i++) { if (i < ncomponents) { Dimension d = parent.getComponent(i).getPreferredSize(); row_heights[r] = Math.max(row_heights[r], d.height); col_widths[c] = Math.max(col_widths[c], d.width); } else { break; } } total_height += row_heights[r]; } int total_width = 0; for (int c = 0; c < ncols; c++) { total_width += col_widths[c]; } // Pass 2: redistribute free space Dimension parent_size = parent.getSize(); Insets insets = parent.getInsets(); int free_height = parent_size.height - insets.top - insets.bottom - (nrows - 1) * vgap; int free_width = parent_size.width - insets.left - insets.right - (ncols - 1) * hgap; if (total_height != free_height) { double dy = (double)free_height / (double)total_height; for (int r = 0; r < nrows; r++) { row_heights[r] = (int) ((double)row_heights[r] * dy); } } if (total_width != free_width) { double dx = ((double)free_width) / ((double)total_width); for (int c = 0; c < ncols; c++) { col_widths[c] = (int) ((double)col_widths[c] * dx); } } // Pass 3: layout components for (int r = 0, y = insets.top, i = 0; r < nrows; y += row_heights[r] + vgap, r++) { for (int c = 0, x = insets.left; c < ncols; x += col_widths[c] + hgap, c++, i++) { if (i < ncomponents) { parent.getComponent(i).setBounds(x, y, col_widths[c], row_heights[r]); } } } }
Clone fragments detected by clone detection tool
File path: /jEdit-4.2/src/org/gjt/sp/jedit/gui/VariableGridLayout.java File path: /jEdit-4.2/src/installer/VariableGridLayout.java
Method name: void layoutContainer(Container) Method name: void layoutContainer(Container)
Number of AST nodes: 33 Number of AST nodes: 33
1
synchronized (parent.getTreeLock()) {
1
synchronized (parent.getTreeLock()) {
2
			update(parent);
2
			update(parent);
3
			int ncomponents = parent.getComponentCount();
3
			int ncomponents = parent.getComponentCount();
4
			if (ncomponents == 0) {
4
			if (ncomponents == 0) {
5
				return;
5
				return;
6
			}
6
			}
7
			// Pass 1: compute preferred row heights / column widths
7
			// Pass 1: compute preferred row heights / column widths
8
			int total_height = 0;
8
			int total_height = 0;
9
			for (int r = 0, i = 0; r < nrows; r++) {
9
			for (int r = 0, i = 0; r < nrows; r++) {
10
				for (int c = 0; c < ncols; c++, i++) {
10
				for (int c = 0; c < ncols; c++, i++) {
11
					if (i < ncomponents) {
11
					if (i < ncomponents) {
12
						Dimension d = parent.getComponent(i).getPreferredSize();
12
						Dimension d = parent.getComponent(i).getPreferredSize();
13
						row_heights[r] = Math.max(row_heights[r], d.height);
13
						row_heights[r] = Math.max(row_heights[r], d.height);
14
						col_widths[c] = Math.max(col_widths[c], d.width);
14
						col_widths[c] = Math.max(col_widths[c], d.width);
15
					} else {
15
					} else {
16
						break;
16
						break;
17
					}
17
					}
18
				}
18
				}
19
				total_height += row_heights[r];
19
				total_height += row_heights[r];
20
			}
20
			}
21
			int total_width = 0;
21
			int total_width = 0;
22
			for (int c = 0; c < ncols; c++) {
22
			for (int c = 0; c < ncols; c++) {
23
				total_width += col_widths[c];
23
				total_width += col_widths[c];
24
			}
24
			}
25
			// Pass 2: redistribute free space
25
			// Pass 2: redistribute free space
26
			Dimension parent_size = parent.getSize();
26
			Dimension parent_size = parent.getSize();
27
			Insets insets = parent.getInsets();
27
			Insets insets = parent.getInsets();
28
			int free_height = parent_size.height - insets.top - insets.bottom - (nrows - 1) * vgap;
28
			int free_height = parent_size.height - insets.top - insets.bottom - (nrows - 1) * vgap;
29
			int free_width = parent_size.width - insets.left - insets.right - (ncols - 1) * hgap;
29
			int free_width = parent_size.width - insets.left - insets.right - (ncols - 1) * hgap;
30
			if (total_height != free_height) {
30
			if (total_height != free_height) {
31
				double dy = (double)free_height / (double)total_height;
31
				double dy = (double)free_height / (double)total_height;
32
				for (int r = 0; r < nrows; r++) {
32
				for (int r = 0; r < nrows; r++) {
33
					row_heights[r] = (int) ((double)row_heights[r] * dy);
33
					row_heights[r] = (int) ((double)row_heights[r] * dy);
34
				}
34
				}
35
			}
35
			}
36
			if (total_width != free_width) {
36
			if (total_width != free_width) {
37
				double dx = ((double)free_width) / ((double)total_width);
37
				double dx = ((double)free_width) / ((double)total_width);
38
				for (int c = 0; c < ncols; c++) {
38
				for (int c = 0; c < ncols; c++) {
39
					col_widths[c] = (int) ((double)col_widths[c] * dx);
39
					col_widths[c] = (int) ((double)col_widths[c] * dx);
40
				}
40
				}
41
			}
41
			}
42
			// Pass 3: layout components
42
			// Pass 3: layout components
43
			for (int r = 0, y = insets.top, i = 0; r < nrows; y += row_heights[r] + vgap, r++) {
43
			for (int r = 0, y = insets.top, i = 0; r < nrows; y += row_heights[r] + vgap, r++) {
44
				for (int c = 0, x = insets.left; c < ncols; x += col_widths[c] + hgap, c++, i++) {
44
				for (int c = 0, x = insets.left; c < ncols; x += col_widths[c] + hgap, c++, i++) {
45
					if (i < ncomponents) {
45
					if (i < ncomponents) {
46
						parent.getComponent(i).setBounds(x, y, col_widths[c], row_heights[r]);
46
						parent.getComponent(i).setBounds(x, y, col_widths[c], row_heights[r]);
47
					}
47
					}
48
				}
48
				}
49
			}
49
			}
50
		}
50
		}
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)9.7
Clones locationClones are in different classes
Number of node comparisons190
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements33
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)45.3
    Clone typeType 1
    Mapped Statements
    ID Statement ID Statement
    1
    synchronized (parent.getTreeLock())
    1
    synchronized (parent.getTreeLock())
    2
    update(parent);
    2
    update(parent);
    3
    int ncomponents = parent.getComponentCount();
    3
    int ncomponents = parent.getComponentCount();
    4
    if (ncomponents == 0)
    4
    if (ncomponents == 0)
    5
    return;
    5
    return;
    6
    int total_height = 0;
    6
    int total_height = 0;
    7
    for (int r = 0, i = 0; r < nrows; r++)
    7
    for (int r = 0, i = 0; r < nrows; r++)
    8
    for (int c = 0; c < ncols; c++, i++)
    8
    for (int c = 0; c < ncols; c++, i++)
    9
    if (i < ncomponents)
    9
    if (i < ncomponents)
    10
    Dimension d = parent.getComponent(i).getPreferredSize();
    10
    Dimension d = parent.getComponent(i).getPreferredSize();
    11
    row_heights[r] = Math.max(row_heights[r], d.height);
    11
    row_heights[r] = Math.max(row_heights[r], d.height);
    12
    col_widths[c] = Math.max(col_widths[c], d.width);
    12
    col_widths[c] = Math.max(col_widths[c], d.width);
    else
    else
    13
    break;
    13
    break;
    14
    total_height += row_heights[r];
    14
    total_height += row_heights[r];
    15
    int total_width = 0;
    15
    int total_width = 0;
    16
    for (int c = 0; c < ncols; c++)
    16
    for (int c = 0; c < ncols; c++)
    17
    total_width += col_widths[c];
    17
    total_width += col_widths[c];
    18
    Dimension parent_size = parent.getSize();
    18
    Dimension parent_size = parent.getSize();
    19
    Insets insets = parent.getInsets();
    19
    Insets insets = parent.getInsets();
    20
    int free_height = parent_size.height - insets.top - insets.bottom - (nrows - 1) * vgap;
    20
    int free_height = parent_size.height - insets.top - insets.bottom - (nrows - 1) * vgap;
    21
    int free_width = parent_size.width - insets.left - insets.right - (ncols - 1) * hgap;
    21
    int free_width = parent_size.width - insets.left - insets.right - (ncols - 1) * hgap;
    22
    if (total_height != free_height)
    22
    if (total_height != free_height)
    23
    double dy = (double)free_height / (double)total_height;
    23
    double dy = (double)free_height / (double)total_height;
    24
    for (int r = 0; r < nrows; r++)
    24
    for (int r = 0; r < nrows; r++)
    25
    row_heights[r] = (int)((double)row_heights[r] * dy);
    25
    row_heights[r] = (int)((double)row_heights[r] * dy);
    26
    if (total_width != free_width)
    26
    if (total_width != free_width)
    27
    double dx = ((double)free_width) / ((double)total_width);
    27
    double dx = ((double)free_width) / ((double)total_width);
    28
    for (int c = 0; c < ncols; c++)
    28
    for (int c = 0; c < ncols; c++)
    29
    col_widths[c] = (int)((double)col_widths[c] * dx);
    29
    col_widths[c] = (int)((double)col_widths[c] * dx);
    30
    for (int r = 0, y = insets.top, i = 0; r < nrows; y += row_heights[r] + vgap, r++)
    30
    for (int r = 0, y = insets.top, i = 0; r < nrows; y += row_heights[r] + vgap, r++)
    31
    for (int c = 0, x = insets.left; c < ncols; x += col_widths[c] + hgap, c++, i++)
    31
    for (int c = 0, x = insets.left; c < ncols; x += col_widths[c] + hgap, c++, i++)
    32
    if (i < ncomponents)
    32
    if (i < ncomponents)
    33
    parent.getComponent(i).setBounds(x, y, col_widths[c], row_heights[r]);
    33
    parent.getComponent(i).setBounds(x, y, col_widths[c], row_heights[r]);
    Precondition Violations (0)
    Row Violation