Sample

Schnappinger/argoUML/org.argouml.ui.ZoomSliderButton

Human rating uses the original dataset scale.

Human3.01
Lines369

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
25.4Δ 4.6
Scalabrino0.8050–1; higher is more readable
64.0Δ 34.0
Dorn0.0370–1; higher is more readable
26.4Δ 3.6
Mi0.5880–1; higher is more readable
57.1Δ 27.1
LLOC109Logical lines; fewer is more readable
22.4Δ 7.6
DeepSeek V4 Pro13.670–20; mean of three runs
26.9Δ 3.1
GPT-6.1 Sol160–20; mean of three runs
38.9Δ 8.9
BTTF0.3780–1; higher is more readable
32.0Δ 2.0
Human3.011–4; original rating
30.0

Views

Source code

/* $Id: ZoomSliderButton.java 19907 2012-12-30 13:06:01Z closettop_nightlybuild $ ***************************************************************************** * Copyright (c) 2009-2012 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: * tfmorris ***************************************************************************** * * Some portions of this file was previously release using the BSD License: */ // Copyright (c) 2003-2008 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.ui; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.MouseEvent; import java.util.Enumeration; import javax.swing.AbstractAction; import javax.swing.Icon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.MouseInputAdapter; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; import org.argouml.application.helpers.ResourceLoaderWrapper; import org.argouml.i18n.Translator; import org.tigris.gef.base.Editor; import org.tigris.gef.base.Globals; import org.tigris.swidgets.PopupButton; /** * A button that can be used to change the zoom magnification of the current * diagram. When the user presses the button, a popup is displayed which * contains a vertical slider representing the range of zoom magnifications. * Dragging the slider changes the zoom magnification for the current diagram. * * @author Jeremy Jones */ public class ZoomSliderButton extends PopupButton { /** * Used for loading the zoom icon from the Zoom Reset action. */ private static final String RESOURCE_NAME = "Zoom Reset"; /** * Font used for the slider tick labels and for the current magnification * value label. */ private static final Font LABEL_FONT = new Font("Dialog", Font.PLAIN, 10); /** * The minimum zoom slider value (as percentage). */ public static final int MINIMUM_ZOOM = 25; /** * The maximum zoom slider value (as percentage). */ public static final int MAXIMUM_ZOOM = 300; /** * The preferred height of the slider component. */ private static final int SLIDER_HEIGHT = 250; /** * The slider component. */ private JSlider slider = null; /** * The text field which shows the current zoom magnification value. */ private JTextField currentValue = null; /** * Used to enable/disable the popup button. */ private boolean popupButtonIsActive = true; /** * Indicates whether the popupmenu is showing or not. */ private boolean popupMenuIsShowing = false; /** * Indicates whether the mouse is over the popup button or not. */ private boolean mouseIsOverPopupButton = false; /** * Constructs a new ZoomSliderButton. */ public ZoomSliderButton() { super(); setAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { /* If action comes in with *no* modifiers, it is a pure * keyboard event (e.g. spacebar), so do it. Anything else * is probably a mouse event, so ignore it. Mouse events are * dealt with by mousePressed() instead (see bottom of page). */ if (e.getModifiers() == 0) { showPopup(); } } }); Icon icon = ResourceLoaderWrapper.lookupIcon(RESOURCE_NAME); MyMouseListener myMouseListener = new MyMouseListener(); addMouseMotionListener(myMouseListener); addMouseListener(myMouseListener); setIcon(icon); setToolTipText(Translator.localize("button.zoom")); } /** * Creates the slider popup component. */ private void createPopupComponent() { slider = new JSlider( JSlider.VERTICAL, MINIMUM_ZOOM, MAXIMUM_ZOOM, MINIMUM_ZOOM); slider.setInverted(true); slider.setMajorTickSpacing(25); slider.setMinorTickSpacing(5); slider.setPaintTicks(true); slider.setPaintTrack(true); int sliderBaseWidth = slider.getPreferredSize().width; slider.setPaintLabels(true); for (Enumeration components = slider.getLabelTable().elements(); components.hasMoreElements();) { ((Component) components.nextElement()).setFont(LABEL_FONT); } slider.setToolTipText(Translator.localize( "button.zoom.slider-tooltip")); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { handleSliderValueChange(); } }); int labelWidth = slider.getFontMetrics(LABEL_FONT).stringWidth( String.valueOf(MAXIMUM_ZOOM)) + 6; slider.setPreferredSize(new Dimension( sliderBaseWidth + labelWidth, SLIDER_HEIGHT)); currentValue = new JTextField(5); currentValue.setHorizontalAlignment(JLabel.CENTER); currentValue.setFont(LABEL_FONT); currentValue.setToolTipText(Translator.localize( "button.zoom.current-zoom-magnification")); updateCurrentValueLabel(); currentValue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleTextEntry(); } }); currentValue.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { handleTextEntry(); } }); JPanel currentValuePanel = new JPanel(new FlowLayout( FlowLayout.CENTER, 0, 0)); currentValuePanel.add(currentValue); JPanel zoomPanel = new JPanel(new BorderLayout(0, 0)); zoomPanel.add(slider, BorderLayout.CENTER); zoomPanel.add(currentValuePanel, BorderLayout.NORTH); setPopupComponent(zoomPanel); } /** * Update the slider value every time the popup is shown. */ @Override protected void showPopup() { if (slider == null) { createPopupComponent(); } Editor ed = Globals.curEditor(); if (ed != null) { slider.setValue((int) (ed.getScale() * 100d)); } if ( popupButtonIsActive ) { super.showPopup(); JPopupMenu pm = (JPopupMenu) this.getPopupComponent().getParent(); PopupMenuListener pml = new MyPopupMenuListener(); pm.addPopupMenuListener(pml); popupMenuIsShowing = true; } slider.requestFocus(); } /** * Called when the slider value changes. */ private void handleSliderValueChange() { updateCurrentValueLabel(); //if (!source.getValueIsAdjusting()) { double zoomPercentage = slider.getValue() / 100d; Editor ed = Globals.curEditor(); if (ed == null || zoomPercentage <= 0.0) { return; } if (zoomPercentage != ed.getScale()) { ed.setScale(zoomPercentage); ed.damageAll(); } //} } /** * Called when the text field value changes. */ private void handleTextEntry() { String value = currentValue.getText(); if (value.endsWith("%")) { value = value.substring(0, value.length() - 1); } try { int newZoom = Integer.parseInt(value); if (newZoom < MINIMUM_ZOOM || newZoom > MAXIMUM_ZOOM) { throw new NumberFormatException(); } slider.setValue(newZoom); } catch (NumberFormatException ex) { updateCurrentValueLabel(); } } /** * Sets the current value label's text to the current slider value. */ private void updateCurrentValueLabel() { currentValue.setText(String.valueOf(slider.getValue()) + '%'); } private class MyPopupMenuListener extends AbstractAction implements PopupMenuListener { /** * Empty method to satisfy interface. */ public void actionPerformed(ActionEvent e) { } /** * Method gets fired when the popup dies. * Conditionally re-enable the button depending on where the pointer * is. */ public void popupMenuCanceled(PopupMenuEvent e) { if (mouseIsOverPopupButton) { popupButtonIsActive = false; } else { popupButtonIsActive = true; } popupMenuIsShowing = false; } public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } public void popupMenuWillBecomeVisible(PopupMenuEvent e) { } } private class MyMouseListener extends MouseInputAdapter { /** * Keeps track of mouseover status. */ @Override public void mouseEntered(MouseEvent me) { mouseIsOverPopupButton = true; } /** * Keeps track of mouseover status, and renables button if necessary. */ @Override public void mouseExited(MouseEvent me) { mouseIsOverPopupButton = false; if (!popupButtonIsActive && !popupMenuIsShowing) { popupButtonIsActive = true; } } /** * Catch the down stroke of mouse click to make the popup appear a tiny * bit earlier. */ @Override public void mousePressed(MouseEvent me) { if (popupButtonIsActive) { showPopup(); } else if ( !popupMenuIsShowing ) { popupButtonIsActive = true; } } } }

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.9269.92−305.907
Source linesThe number of non-empty source lines.369+147.6
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.794−7.19

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

Score0.805

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.370−12.064
Indentation frequencyHow rapidly indentation changes from line to line.275+8.775
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.275−5.89
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.368.976+4.748
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.78.395+0.46
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.055+0.408
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.80.954+0.236

Intercept 0.07 + feature contributions = -3.257 (log-odds).
Score = sigmoid(-3.257) = 0.037.

Score0.588
Score109
Run 1

The code has good structure with clear class organization, but readability is significantly hampered by several issues. The license headers occupy excessive space before the actual code, hurting reading flow. The constructor's anonymous AbstractAction contains a verbose comment explaining keyboard vs mouse event handling, which could be simplified. Methods like showPopup() and handleSliderValueChange() contain magic numbers and inline calculations without explanatory comments. The MyPopupMenuListener class has inconsistent indentation and extends AbstractAction unnecessarily for just one empty method. Several commented-out lines remain (e.g., '//if (!source.getValueIsAdjusting())'), adding confusion. The class has many instance variables with unclear state management between popupButtonIsActive, popupMenuIsShowing, and mouseIsOverPopupButton, making the control flow difficult to trace. Nesting is relatively flat, but some methods mix concerns. Overall, the code is functional but requires careful reading to understand the interactive popup behavior, reducing its readability score.

Run 2

The code is generally well-structured with clear separation of concerns across methods and inner classes. Naming is descriptive and the overall intent is understandable. However, readability is hindered by tight coupling between the popup button state logic and mouse events, scattered boolean flags, and some methods that perform multiple actions (e.g., showPopup manipulates slider, editor, and popup state). The presence of an empty actionPerformed method and commented-out code adds noise. Long class length and several boilerplate interface implementations further reduce clarity.

Run 3

The code is well-structured and readable. It uses clear naming conventions, constants, and Javadoc comments that explain purpose. The methods are logically organized, each performing a single responsibility (e.g. creating popup, handling slider, parsing text). Nesting is shallow, action granularity is strong, and reading flow is natural. Minor issues: some conditional formatting is slightly inconsistent (e.g. space before parenthesis in `if ( popupButtonIsActive )`), and a few listener methods are empty, which adds visual clutter. Overall, very maintainable and easy to follow.

Run 1

Code Structure: Responsibilities are separated into focused methods and listener classes, though popup state management is distributed across several handlers. Nesting: Mostly shallow conditionals and early returns keep control flow manageable; anonymous listeners add modest nesting. Clarity of intent: Descriptive constants, method names, and documentation explain zoom behavior well, but generic listener names, abbreviated locals, and interacting boolean flags obscure some details. Code length: Reasonable for a Swing component, although repetitive comments, empty listener methods, commented-out code, and verbose setup increase reading effort. Action granularity: Statements generally perform one action per line, making changes easy to follow. Reading flow: Construction, popup setup, updates, and event handling follow a logical sequence, but inconsistent indentation, brace placement, spacing, and line wrapping disrupt visual consistency.

Run 2

Code Structure: Responsibilities are sensibly divided among setup, zoom updates, text validation, and listener classes, though popup behavior spans several state flags and callbacks. Nesting: Mostly shallow, with guard clauses and short conditionals; anonymous listeners add modest nesting. Clarity of intent: Descriptive constants, method names, and documentation explain the zoom control well, but generic names such as ed, pm, and MyMouseListener weaken clarity. Code length: Functional methods are reasonably concise, but extensive boilerplate, repetitive comments, commented-out code, and a verbose boolean assignment add clutter. Action granularity: Statements generally perform one action per line, making changes easy to follow. Reading flow: The progression from construction through setup and event handling is logical, but inconsistent indentation, brace placement, and line wrapping interrupt it. Understanding popup activation requires tracing interactions across multiple listeners.

Run 3

Code Structure: Responsibilities are logically separated into initialization, zoom updates, text handling, and listener classes, though popup behavior depends on several interacting flags. Nesting: Mostly shallow, with guard clauses keeping event handlers easy to follow; anonymous listeners add some nesting. Clarity of intent: Descriptive constants, method names, and documentation clearly explain the zoom control, but abbreviated variables and generic listener names weaken clarity. Code length: Generally reasonable for a Swing component, although repetitive comments, verbose listener boilerplate, an unnecessary AbstractAction superclass, and commented-out code add clutter. Action granularity: Statements generally perform one action per line, making changes straightforward to trace. Reading flow: The progression from construction through setup to event handling is natural, but inconsistent indentation, brace placement, and line wrapping interrupt readability. Overall, the code is readable and well organized, with minor verbosity and formatting issues and moderately complex popup-state coordination.