Skip to content

Commit

Permalink
feat: add UI test case
Browse files Browse the repository at this point in the history
- add sample app using vldocking
- give default names of components
  • Loading branch information
miurahr committed Mar 31, 2024
1 parent 333fbd9 commit dc3ba88
Show file tree
Hide file tree
Showing 19 changed files with 316 additions and 20 deletions.
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 @@ -273,7 +273,14 @@ 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,9 +45,10 @@ public DockablePanel(Component contained, DockKey key) {
setLayout(new BorderLayout());
add(contained, BorderLayout.CENTER);
this.key = key;
setName("DockablePanel");
}

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

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

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

/**
* when a dockable is dragged above this button, the button stores it as its new target dockable.
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;
}
}
}
42 changes: 42 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,42 @@
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;
}
}
39 changes: 39 additions & 0 deletions src/test/java/com/vlsolutions/swing/sample/MyJTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.vlsolutions.swing.sample;

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

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


class MyJTable extends JPanel implements Dockable {
JTable table = new JTable();
DockKey key = new DockKey("table");

public MyJTable() {
setName("myJTablePanel");
setLayout(new BorderLayout());
table.setModel(new DefaultTableModel(5, 5));
table.setName("myJTableTable");
JScrollPane jsp = new JScrollPane(table);
jsp.setName("myJTableScrollPane");
jsp.setPreferredSize(new Dimension(200, 200));
add(jsp, BorderLayout.CENTER);
key.setName("The table");
key.setAutoHideEnabled(true);
key.setCloseEnabled(false);
key.setMaximizeEnabled(false);
}

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

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

0 comments on commit dc3ba88

Please sign in to comment.