Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test UI behavior #7

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ repositories {
dependencies {
implementation(libs.slf4j.api)
testImplementation(libs.junit4)
testImplementation(libs.assertj.swing.junit)
testRuntimeOnly(libs.logback)
}

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
slf4j = { strictly = "[2.0.7, 2.1[", prefer = "2.0.7" }
junit = "4.13.2"
logback = "1.4.12"
assertj = "3.17.1"

[libraries]
slf4j-api = {group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j"}
junit4 = {group = "junit", name = "junit", version.ref = "junit"}
logback = {group = "ch.qos.logback", name = "logback-classic", version.ref = "logback"}
assertj-swing-junit = {group = "org.assertj", name = "assertj-swing-junit", version.ref = "assertj"}

[plugins]
nexus-publish = {id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0-rc-1"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void init(Dockable dockable, int zone) {
DockKey key = dockable.getDockKey();
this.dockable = dockable;
this.key = key;

setName("AutoHideButton");
int oldZone = this.zone;
this.zone = zone;
firePropertyChange("autohide.zone", oldZone, zone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public class AutoHideButtonPanel extends JPanel {
public static final String uiClassID = "AutoHideButtonPanelUI";

/** <=> Zone */
private int border;
private final int border;

/** highlight effect (rollover) on the contained buttons */
private ButtonHighlighter buttonHighlighter = new ButtonHighlighter();
private final ButtonHighlighter buttonHighlighter = new ButtonHighlighter();

/** expansion management */
private AutoHideExpandPanel expandPanel;
private final AutoHideExpandPanel expandPanel;

/**
* Constructs a new AutoHideButtonPanel, with a shared expandPanel, and for a specified border zone.
Expand All @@ -59,6 +59,7 @@ public AutoHideButtonPanel(AutoHideExpandPanel expandPanel, int border) {
boolean isHorizontal = (border == DockingConstants.INT_HIDE_TOP)
|| (border == DockingConstants.INT_HIDE_BOTTOM);
setLayout(new AutoHideBorderLayout(isHorizontal));
setName("AutoHideButtonPanel");

firePropertyChange("borderzone", -1, border);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class AutoHideExpandPanel extends JPanel implements SingleDockableContain
private boolean isExpanding = false;
// true during animation phase, will be used to avoid concurrent animations (@todo)

private HashMap<Component, Dimension> savedDimensions = new HashMap(); // Component/Dimension
private final HashMap<Component, Dimension> savedDimensions = new HashMap(); // Component/Dimension

ExpandControler controler = new ExpandControler(); // hide event listener

Expand All @@ -87,7 +87,7 @@ public class AutoHideExpandPanel extends JPanel implements SingleDockableContain

private JPanel lastDragger; // last used dragger

private JPanel content = new JPanel(new BorderLayout()); // content displayed (user component)
private final JPanel content = new JPanel(new BorderLayout()); // content displayed (user component)

private Panel heavyPanel; // used only when mixing lightweight and heavyweight components

Expand All @@ -109,14 +109,14 @@ public class AutoHideExpandPanel extends JPanel implements SingleDockableContain
/** Used by the collapse timer */
private long lastTimeMouseWasIn = 0;

private boolean canUseMouseInfo = DockingUtilities.canUseMouseInfo();
private final boolean canUseMouseInfo = DockingUtilities.canUseMouseInfo();

private FocusCollapser collapser = new FocusCollapser(); // 2006/12/19
private final FocusCollapser collapser = new FocusCollapser(); // 2006/12/19

/**
* Timer used to collapse the expand panel (when mouse is out of bounds). (only for java > 1.5)
*/
private javax.swing.Timer collapseTimer // 2005/11/01
private final javax.swing.Timer collapseTimer // 2005/11/01
= new javax.swing.Timer(250, new ActionListener() {

// timer used to hide the expanded panel when mouse is out too long
Expand Down Expand Up @@ -158,7 +158,7 @@ public void actionPerformed(ActionEvent actionEvent) {

public AutoHideExpandPanel() {
super(new BorderLayout());

setName("AutoHideExpandPanel");
if (!DockingPreferences.isLightWeightUsageEnabled()) {
this.heavyPanel = new Panel(new BorderLayout());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class CompoundDockingPanel extends JPanel implements DockDropReceiver {
public CompoundDockingPanel(CompoundDockable dockable) {
setLayout(new BorderLayout());
this.dockable = dockable;
setName("CompoundDockingPanel");
}

/** act the same as a splitContainer : allow drop on the borders */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public DockTabbedPane() {
int tabPlacement = UIManager.getInt("TabbedDockableContainer.tabPlacement");
setTabLayoutPolicy(WRAP_TAB_LAYOUT);
setTabPlacement(tabPlacement);

setName("DockTabbedPane");
addMouseListener(new MouseAdapter() {

// depending on the platform, pop-up is triggered either by mousePressed or mouseReleased
Expand Down Expand Up @@ -1104,4 +1104,5 @@ public Container getDockableContainer() {
public void endDragComponent(boolean dropped) {
// nothing more to do
}

}
11 changes: 6 additions & 5 deletions src/main/java/com/vlsolutions/swing/docking/DockView.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public void propertyChange(PropertyChangeEvent e) {
* A {@link #setDockable(Dockable)} call is requiered for this constructor to be usefull.
*/
public DockView() {
super(new BorderLayout());
add(title, BorderLayout.NORTH);
this(null);
}

/**
Expand All @@ -115,8 +114,7 @@ public DockView() {
* the dockable to show
*/
public DockView(Dockable dockable) {
this();
setDockable(dockable);
this(dockable, true);
}

/**
Expand All @@ -128,10 +126,13 @@ public DockView(Dockable dockable) {
public DockView(Dockable dockable, boolean showTitle) {
super(new BorderLayout());
add(title, BorderLayout.NORTH);
setName("DockView");
if (dockable != null) {
setDockable(dockable);
}
if (!showTitle) {
title.setVisible(false);
}
setDockable(dockable);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ public DockViewTitleBar() {
public DockViewTitleBar(Dockable dockable) {
setDockable(dockable);

setName("DockViewTitleBar");
titleLabel.setName("TitleLabel");

closeButton.setName("CloseButton");
dockButton.setName("DockButton");
maximizeButton.setName("MaximizeButton");
floatButton.setName("FloatButton");
closeButton.setText("");
dockButton.setText("");
maximizeButton.setText("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public DockablePanel(Component contained, DockKey key) {
setLayout(new BorderLayout());
add(contained, BorderLayout.CENTER);
this.key = key;
setName("DockablePanel");
}

public DockKey getDockKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public class DockableStoreButton extends JButton implements DockDropReceiver, Do
public DockableStoreButton(String emptyText) {
super(emptyText);
this.emptyText = emptyText;
setName("DockableStoreButton");
updateButtonText();
}

public DockableStoreButton() {
setName("DockableStoreButton");
updateButtonText();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class DockingPanel extends JPanel implements DockDropReceiver {
/** Javabeans constructor */
public DockingPanel() {
super(new BorderLayout());
setName("DockingPanel");
}

/** act the same as a splitContainer : allow drop on the borders */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public DockingSelectorDialog(Dialog owner) {
super(owner, true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle(TITLE);
setName("DockingSelectorDialog");
init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public FloatingDialog(Dialog parent) {
public FloatingDialog(Frame parent) {
super(parent);
// setIconImage(parent.getIconImage());
setName("FloatingDialog");
init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MaximizedDockView extends DockView {

public MaximizedDockView(Dockable dockable) {
super(dockable, true);
setName("MaximizedDockView");
}

/** maximized dockable don't support drag and drop */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.vlsolutions.swing.docking;

import com.vlsolutions.swing.sample.MySplitDockApp;
import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.data.TableCell;
import org.assertj.swing.edt.GuiActionRunner;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
import org.junit.Test;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.Dimension;

public class DockingSplitDesktopTest extends AssertJSwingJUnitTestCase {

protected FrameFixture window;
protected MySplitDockApp application;

@Override
protected void onSetUp() {
application = GuiActionRunner.execute(() -> {
MySplitDockApp frame = new MySplitDockApp();
frame.setPreferredSize(new Dimension(800, 600));
frame.setMinimumSize(new Dimension(800, 600));
frame.validate();
return frame;
});
window = new FrameFixture(robot(), application);
window.show();
}

@Test
public void testDockableSplitDesktop() {
SwingUtilities.invokeLater(() -> application.setVisible(true));
window.panel("myJTablePanel").requireVisible();
window.panel("myTreePanel").requireVisible();
window.panel("myTextEditorPanel").requireVisible();
window.panel("myGridOfButtonsPanel").requireVisible();
window.panel("myGridOfButtonsPanel").button("myGridOfButtonsButton0").requireText("btn0");
window.panel("myJTablePanel").table().requireCellValue(TableCell.row(0).column(0), "");
window.panel("myJTablePanel").table().requireColumnCount(5);

window.panel("DockingPanel").panel(new PanelMatcher("DockView", 0)).panel("DockViewTitleBar")
.label("TitleLabel").requireText("The tree");
window.panel("DockingPanel").panel(new PanelMatcher("DockView", 1)).panel("DockViewTitleBar")
.label("TitleLabel").requireText("The Grid of Buttons");
window.panel("DockingPanel").panel(new PanelMatcher("DockView", 2)).panel("DockViewTitleBar")
.label("TitleLabel").requireText("The table");

window.panel("DockingPanel").panel(new PanelMatcher("DockView", 2)).panel("DockViewTitleBar")
.button("DockButton").click();
window.panel("AutoHideButtonPanel").label(new AutoHideButtonMatcher("AutoHideButton", 0)).click();
window.panel("AutoHideExpandPanel").panel("DockViewTitleBar").label("TitleLabel")
.requireText("The table");
window.panel("AutoHideExpandPanel").panel("DockViewTitleBar").button("DockButton").click();
}

private static class AutoHideButtonMatcher extends GenericTypeMatcher<JLabel> {
private final String name;
private final int index;
private int count = 0;

public AutoHideButtonMatcher(String name, int index) {
super(JLabel.class);
this.name = name;
this.index = index;
}

@Override
protected boolean isMatching(JLabel button) {
return name.equals(button.getName()) && count++ == index;
}
}

private static class PanelMatcher extends GenericTypeMatcher<JPanel> {
private final String name;
private final int index;
private int count = 0;

public PanelMatcher(String name, int index) {
super(JPanel.class);
this.name = name;
this.index = index;
}

@Override
protected boolean isMatching(JPanel jPanel) {
return name.equals(jPanel.getName()) && count++ == index;
}
}
}
41 changes: 41 additions & 0 deletions src/test/java/com/vlsolutions/swing/sample/MyGridOfButtons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.vlsolutions.swing.sample;

import com.vlsolutions.swing.docking.DockKey;
import com.vlsolutions.swing.docking.Dockable;

import javax.swing.*;
import java.awt.*;

public class MyGridOfButtons extends JPanel implements Dockable {

DockKey key = new DockKey("gridOfButtons");

public MyGridOfButtons() {
setName("myGridOfButtonsPanel");
setLayout(new FlowLayout(FlowLayout.TRAILING, 3, 3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int number = i * 3 + j;
JButton btn = new JButton("btn" + number);
btn.setName("myGridOfButtonsButton" + number);
add(btn);
}
}
setPreferredSize(new Dimension(200, 300));
key.setName("The Grid of Buttons");
key.setCloseEnabled(false);
key.setFloatEnabled(true);
key.setMaximizeEnabled(false);
key.setAutoHideEnabled(false);
}

@Override
public DockKey getDockKey() {
return key;
}

@Override
public Component getComponent() {
return this;
}
}
Loading