Sample

Schnappinger/argoUML/org.argouml.core.propertypanels.ui.LabelledLayout

Human rating uses the original dataset scale.

Human2.9
Lines517

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
24.4Δ 3.3
Scalabrino0.8760–1; higher is more readable
82.5Δ 61.4
Dorn0.0040–1; higher is more readable
14.9Δ 6.3
Mi0.5660–1; higher is more readable
48.8Δ 27.7
LLOC158Logical lines; fewer is more readable
16.8Δ 4.3
DeepSeek V4 Pro14.670–20; mean of three runs
34.8Δ 13.7
GPT-6.1 Sol13.670–20; mean of three runs
12.9Δ 8.3
BTTF0.4490–1; higher is more readable
38.9Δ 17.8
Human2.91–4; original rating
21.1

Views

Source code

/* $Id: LabelledLayout.java 17896 2010-01-12 21:36:11Z linus $ ***************************************************************************** * Copyright (c) 2009 Contributors - see below * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * bobtarling ***************************************************************************** * * Some portions of this file was previously release using the BSD License: */ // Copyright (c) 2008-2009 The Regents of the University of California. All // Rights Reserved. Permission to use, copy, modify, and distribute this // software and its documentation without fee, and without a written // agreement is hereby granted, provided that the above copyright notice // and this paragraph appear in all copies. This software program and // documentation are copyrighted by The Regents of the University of // California. The software program and documentation are supplied "AS // IS", without any accompanying services from The Regents. The Regents // does not warrant that the operation of the program will be // uninterrupted or error-free. The end-user understands that the program // was developed for research purposes and is advised not to rely // exclusively on the program for any reason. IN NO EVENT SHALL THE // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. package org.argouml.core.propertypanels.ui; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Insets; import java.awt.LayoutManager; import java.util.ArrayList; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.UIManager; /** * This layout manager lines up components in 2 columns. All JLabels * are the first column and any component the JLabel is registered * with is in a second column next to the label. <p> * * Components are sized automatically to fill available space in the container * when it is resized. <p> * * All JLabel widths will be the largest of the JLabel preferred widths (unless * the container is too narrow). <p> * * The components will take up any left over width unless they are * restricted themselves by a maximum width. <p> * * The height of each component is either fixed or will resize to use up any * available space in the container. Whether a components height is resizable * is determined by checking whether the preferred height of that component is * greater then its minimum height. This is the case for components such as * JList which would require to expand to show the maximum number or items. <p> * * If a component is not to have its height resized then its preferred * height and minimum height should be the same. This is the case for * components such as JTextField and JComboBox* which should always stay the * same height. <p> * * [There is known bug in JRE5 where the prefered height and minimum height of * a JComboBox can differ. LabelledLayout has coded a workaround for this bug. * See - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6255154 ] <p> * * LabelledLayout can show multiple panels of label/component * pairs. The seperation of these panels is indicated by adding a * Seperator component to the container. Labelled layout starts * a new panel when detecting this Seperator. <p> * * When there are multiple panels, each panel is given equal width. * The width restriction of JLabels and components described above are then * dependent on panel width rather than container width. * * @author Bob Tarling */ class LabelledLayout implements LayoutManager, java.io.Serializable { /** * The class uid */ private static final long serialVersionUID = -5596655602155151443L; /** * This is the horizontal gap (in pixels) which specifies the space * between sections. They can be changed at any time. * This should be a non negative integer. * * @serial * @see #getHgap() * @see #setHgap(int) */ private int hgap; /** * This is the vertical gap (in pixels) which specifies the space * between rows. They can be changed at any time. * This should be a non negative integer. * * @serial * @see #getVgap() * @see #setVgap(int) */ private int vgap; private boolean ignoreSplitters; /** * Construct a new LabelledLayout. */ public LabelledLayout() { ignoreSplitters = false; hgap = 0; vgap = 0; } /** * Construct a new LabelledLayout. */ public LabelledLayout(boolean ignoreSplitters) { this.ignoreSplitters = ignoreSplitters; this.hgap = 0; this.vgap = 0; } /** * Construct a new horizontal LabelledLayout with the specified * cell spacing. * @param hgap The horizontal gap between components * @param vgap The vertical gap between components */ public LabelledLayout(int hgap, int vgap) { this.ignoreSplitters = false; this.hgap = hgap; this.vgap = vgap; } /** * Adds the specified component with the specified name to the * layout. This is included to satisfy the LayoutManager interface * but is not actually used in this layout implementation. * * @param name the name of the component * @param comp the component to be added */ public void addLayoutComponent(String name, Component comp) { } /** * Removes the specified component from * the layout. This is included to satisfy the LayoutManager * interface but is not actually used in this layout * implementation. * * @param comp the component */ public void removeLayoutComponent(Component comp) { } /** * Determines the preferred size of the container argument using * this labelled layout. The preferred size is that all child * components are in one section at their own preferred size with * gaps and border indents. */ public Dimension preferredLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { final Insets insets = parent.getInsets(); int preferredWidth = 0; int preferredHeight = 0; int widestLabel = 0; final int componentCount = parent.getComponentCount(); for (int i = 0; i < componentCount; ++i) { Component childComp = parent.getComponent(i); if (childComp.isVisible() && !(childComp instanceof Seperator)) { int childHeight = getPreferredHeight(childComp); preferredHeight += childHeight + this.vgap; } } preferredWidth += insets.left + widestLabel + insets.right; preferredHeight += insets.top + insets.bottom; return new Dimension( insets.left + widestLabel + preferredWidth + insets.right, preferredHeight); } } /** * Required by LayoutManager. * * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container) */ public Dimension minimumLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { final Insets insets = parent.getInsets(); int minimumHeight = insets.top + insets.bottom; return new Dimension(0, minimumHeight); } } /** * @see java.awt.LayoutManager#layoutContainer(java.awt.Container) */ public void layoutContainer(Container parent) { synchronized (parent.getTreeLock()) { int sectionX = parent.getInsets().left; final ArrayList<Component> components = new ArrayList<Component>(); final int sectionCount = getSectionCount(parent); final int sectionWidth = getSectionWidth(parent, sectionCount); int sectionNo = 0; for (int i = 0; i < parent.getComponentCount(); ++i) { final Component childComp = parent.getComponent(i); if (childComp instanceof Seperator) { if (!this.ignoreSplitters) { layoutSection( parent, sectionX, sectionWidth, components, sectionNo++); sectionX += sectionWidth + this.hgap; components.clear(); } } else { components.add(parent.getComponent(i)); } } layoutSection( parent, sectionX, sectionWidth, components, sectionNo); } } /** Determine the number of sections. There is only ever one * section if oriented vertically. If oriented horizontally the * number of sections is deduced from the number of Splitters in * the parent container. */ private int getSectionCount(Container parent) { int sectionCount = 1; final int componentCount = parent.getComponentCount(); if (!ignoreSplitters) { for (int i = 0; i < componentCount; ++i) { if (parent.getComponent(i) instanceof Seperator) { ++sectionCount; } } } return sectionCount; } /** * Determine the width of each section from the section count. * This is the working width minus the gaps between sections. This * result is then divided equally by the section count. */ private int getSectionWidth(Container parent, int sectionCount) { return (getUsableWidth(parent) - (sectionCount - 1) * this.hgap) / sectionCount; } /** * Determine the usable width of the parent. * This is the full width minus any borders. */ private int getUsableWidth(Container parent) { final Insets insets = parent.getInsets(); return parent.getWidth() - (insets.left + insets.right); } /** * Layout a single section */ private void layoutSection( final Container parent, final int sectionX, final int sectionWidth, final ArrayList components, final int sectionNo) { final ArrayList<Integer> rowHeights = new ArrayList<Integer>(); final int componentCount = components.size(); if (componentCount == 0) { return; } int labelWidth = 0; int unknownHeightCount = 0; int totalHeight = 0; // Build up an array list of the heights of each label/component pair. // Heights of zero indicate a proportional height. for (int i = 0; i < componentCount; ++i) { final Component childComp = (Component) components.get(i); if (childComp instanceof LabelledComponent) { LabelledComponent lc = (LabelledComponent) childComp; final JLabel label = lc.getLabel(); if (label != null) { if (label.getMinimumSize().width > labelWidth) { labelWidth = label.getMinimumSize().width; } } } final int childHeight = getChildHeight(childComp); if (childHeight == 0) { ++unknownHeightCount; } totalHeight += childHeight + this.vgap; rowHeights.add(new Integer(childHeight)); } totalHeight -= this.vgap; final Insets insets = parent.getInsets(); final int parentHeight = parent.getHeight() - (insets.top + insets.bottom); // Set the child components to the heights in the array list // calculating the height of any proportional component on the // fly. int y = insets.top; int row = 0; for (int i = 0; i < componentCount; ++i) { Component childComp = (Component) components.get(i); if (childComp.isVisible()) { if (childComp instanceof LabelledComponent) { final LabelledComponent lc = (LabelledComponent) childComp; final JLabel label = lc.getLabel(); if (label != null) { label.setPreferredSize( new Dimension( labelWidth, label.getPreferredSize().height)); } } int rowHeight; int componentWidth = sectionWidth; int componentX = sectionX; // If the component is a JLabel which has another // component assigned then position/size the label and // calculate the size of the registered component rowHeight = rowHeights.get(row).intValue(); if (rowHeight == 0) { try { rowHeight = calculateHeight( parentHeight, totalHeight, unknownHeightCount--, childComp); } catch (ArithmeticException e) { final String lookAndFeel = UIManager.getLookAndFeel().getClass().getName(); throw new IllegalStateException( "Division by zero laying out " + childComp.getClass().getName() + " on " + parent.getClass().getName() + " in section " + sectionNo + " using " + lookAndFeel, e); } totalHeight += rowHeight; } // Make sure the component width isn't any greater // than its maximum allowed width if (childComp.getMaximumSize() != null && getMaximumWidth(childComp) < componentWidth) { componentWidth = getMaximumWidth(childComp); } childComp.setBounds(componentX, y, componentWidth, rowHeight); y += rowHeight + this.vgap; ++row; } } } /** * @param childComp a component * @return 0 for a resizable component or a positive value for its fixed * height */ private int getChildHeight(Component childComp) { if (isResizable(childComp)) { // If the child component is resizable then // we don't know it's actual size yet. // It will be calculated later as a // proportion of the available left over // space. For now this is flagged as zero. return 0; } else { // If a preferred height is not given or is // the same as the minimum height then fix the // height of this row. return getMinimumHeight(childComp); } } /** * A component is resizable if its minimum size is less than * its preferred size. * There is a workaround here for a bug introduced in JRE5 * where JComboBox minimum and preferred size now differ. * JComboBox is not resizable. * Anything in a JScrollPane is considered resizable * @param comp the component to check for resizability. * @return true if the given component should be resized to take u[p empty * space. */ private boolean isResizable(Component comp) { if (comp == null) { return false; } if (comp instanceof JComboBox) { return false; } if (comp.getPreferredSize() == null) { return false; } if (comp.getMinimumSize() == null) { return false; } return (getMinimumHeight(comp) < getPreferredHeight(comp)); } private final int calculateHeight( final int parentHeight, final int totalHeight, final int unknownHeightsLeft, final Component childComp) { return Math.max( (parentHeight - totalHeight) / unknownHeightsLeft, getMinimumHeight(childComp)); } private int getPreferredHeight(final Component comp) { return (int) comp.getPreferredSize().getHeight(); } private int getPreferredWidth(final Component comp) { return (int) comp.getPreferredSize().getWidth(); } private int getMinimumHeight(final Component comp) { return (int) comp.getMinimumSize().getHeight(); } private int getMaximumWidth(final Component comp) { return (int) comp.getMaximumSize().getWidth(); } /** * Create a new instance of the Separator that splits the layout in columns * @return the separator */ public static Seperator getSeparator() { return new Seperator(); } /** * @return the horizontal gaps between components */ public int getHgap() { return this.hgap; } /** * Set the horizontal gaps between components * @param hgap the horizontal gap */ public void setHgap(int hgap) { this.hgap = hgap; } /** * @return the vertical gaps between components */ public int getVgap() { return this.vgap; } /** * Set the vertical gaps between components * @param vgap the horizontal gap */ public void setVgap(int vgap) { this.vgap = vgap; } } class Seperator extends JPanel { private static final long serialVersionUID = -4143634500959911688L; Seperator() { super.setVisible(false); } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.11664.932−384.943
Source linesThe number of non-empty source lines.517+206.8
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.448−6.672

Intercept 8.87 + feature contributions = -175.945 (log-odds).
Score = sigmoid(-175.945) = 0.

Score0.876

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.518−17.304
Indentation frequencyHow rapidly indentation changes from line to line.333+10.781
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.333−7.22
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.516.913+6.816
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.045+0.503
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.77.72+0.45
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.78.967+0.32

Intercept 0.07 + feature contributions = -5.585 (log-odds).
Score = sigmoid(-5.585) = 0.004.

Score0.566
Score158
Run 1

The code is generally well-structured and readable. It has clear class and method organization, with Javadoc comments explaining the purpose and behavior. The layout logic is broken into helper methods like getSectionCount, getSectionWidth, and layoutSection, which improves readability. However, there are some issues: the variable 'preferredWidth' in preferredLayoutSize is computed but never meaningfully used (dead code), and the typo 'Seperator' instead of 'Separator' is repeated throughout. Some methods like layoutSection are quite long and contain multiple responsibilities. The nesting level is moderate but acceptable. Readability is slightly reduced by the redundant width calculation and lack of a separate data structure for sections, but overall the intent remains clear.

Run 2

The code is generally well-structured with clear class-level documentation and logical method separation. However, readability is hampered by several factors. The class-level Javadoc is excessively long and includes historical details that obscure the core purpose. Methods like layoutSection are very long and combine multiple responsibilities, making them hard to follow. The nested loops and conditionals, especially in layoutSection, contribute to cognitive overhead. Although comments explain some decisions, many inline comments are verbose or restate the obvious. Naming is mostly clear, but typos like 'Seperator' are present. The code mixes multiple actions within loops and conditionals, reducing per-line clarity. While the overall design is understandable, the dense implementation and redundant documentation make it less approachable for new readers. Modern Java features like diamond operator and for-each could improve conciseness.

Run 3

The code is generally well-structured with clear separation of concerns, good documentation, and mostly flat nesting. The class handles a complex layout algorithm but breaks it down into logical private methods. Javadocs explain intent well. However, several issues reduce readability: the preferredLayoutSize method contains a bug where preferredWidth is initialized and added twice, making it unnecessarily confusing. The layoutSection method is quite long and could benefit from further decomposition. Raw types are used for ArrayList parameters (no generics), reducing type safety and clarity. The class name 'Seperator' is misspelled. Some methods like preferredLayoutSize mix concerns by calculating widths that aren't actually used. The overall flow is natural but certain sections like the layoutSection loop could be more clearly structured with better variable naming. The code is readable but has enough rough edges to prevent a higher score.

Run 1

Code Structure: Layout responsibilities are split into reasonably named helpers, but layoutSection combines measurement, sizing, positioning, and error handling. Nesting: Several loops contain multiple conditional levels, especially inside synchronized blocks, making the main algorithm harder to follow. Clarity of intent: Descriptive names and documentation explain the layout purpose, but stale comments, the misspelled Seperator, zero-height sentinel values, and widestLabel never being updated introduce ambiguity. Code length: Extensive boilerplate, repetitive constructors, verbose comments, and unused getPreferredWidth add length without improving understanding. Action granularity: Most lines perform one action, although sectionNo++ and unknownHeightCount-- inside method arguments hide state changes. Reading flow: Consistent formatting and helper methods support navigation, but the long two-pass layoutSection and separate row/component indexing require readers to track substantial mutable state.

Run 2

1. Code Structure: Responsibilities are mostly separated into clearly named helpers, but layoutSection combines measurement, sizing, positioning, and error handling. 2. Nesting: Most methods are shallow; layoutSection and layoutContainer have several nested loops and conditionals that increase reading effort. 3. Clarity of intent: Descriptive names and documentation explain the layout strategy, but outdated comments, the misspelled Seperator, raw collections, and zero-as-resizable conventions introduce ambiguity. 4. Code length: Extensive boilerplate documentation, repeated constructors, and verbose formatting make the class longer than necessary. 5. Action granularity: Statements generally perform one action per line, although counter decrements and increments inside method arguments obscure state changes. 6. Reading flow: Consistent indentation and helper extraction support sequential reading, but two-pass sizing logic, mutable counters, and potentially misleading preferred-size calculations require careful tracing.

Run 3

Code Structure: Responsibilities are reasonably separated into layout, section sizing, and dimension helpers, but layoutSection combines several concerns. Nesting: Most helpers are flat, while layoutSection and layoutContainer contain substantial nested conditionals and loops. Clarity of intent: Descriptive names and documentation explain the layout purpose, but stale comments, the misspelled Seperator class, raw collections, and zero-height sentinel logic introduce ambiguity. Code length: Extensive boilerplate, repetitive constructors, verbose comments, and an unused width helper make the file longer than necessary. Action granularity: Most lines perform one action, although sectionNo++ and unknownHeightCount-- inside method calls obscure state changes. Reading flow: Consistent formatting and a two-pass sizing approach support comprehension, but tracking mutable height counters and row indices across passes requires effort.