source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/AutoAdjustingSplitPane.java@ 11772

Last change on this file since 11772 was 11772, checked in by Don-vip, 7 years ago

fix #14475 - Deadlock while starting unit tests: remove the need to construct a CombinePrimitiveDialog to detect conflicts

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import java.awt.event.HierarchyBoundsListener;
5import java.awt.event.HierarchyEvent;
6import java.beans.PropertyChangeEvent;
7import java.beans.PropertyChangeListener;
8
9import javax.swing.JSplitPane;
10
11/**
12 * Auto adjusting split pane when parent is resized.
13 * @since 11772 (extracted from {@code CombinePrimitiveResolverDialog})
14 */
15public class AutoAdjustingSplitPane extends JSplitPane implements PropertyChangeListener, HierarchyBoundsListener {
16 private double dividerLocation;
17
18 /**
19 * Constructs a new {@code AutoAdjustingSplitPane}.
20 * @param newOrientation {@code JSplitPane.HORIZONTAL_SPLIT} or {@code JSplitPane.VERTICAL_SPLIT}
21 */
22 public AutoAdjustingSplitPane(int newOrientation) {
23 super(newOrientation);
24 addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, this);
25 addHierarchyBoundsListener(this);
26 }
27
28 @Override
29 public void ancestorResized(HierarchyEvent e) {
30 setDividerLocation((int) (dividerLocation * getHeight()));
31 }
32
33 @Override
34 public void ancestorMoved(HierarchyEvent e) {
35 // do nothing
36 }
37
38 @Override
39 public void propertyChange(PropertyChangeEvent evt) {
40 if (JSplitPane.DIVIDER_LOCATION_PROPERTY.equals(evt.getPropertyName())) {
41 int newVal = (Integer) evt.getNewValue();
42 if (getHeight() != 0) {
43 dividerLocation = (double) newVal / (double) getHeight();
44 }
45 }
46 }
47}
Note: See TracBrowser for help on using the repository browser.