Skip to content

Commit

Permalink
Merge pull request #85 from ezweave/master
Browse files Browse the repository at this point in the history
SquareButtonGrouppo
  • Loading branch information
ezweave committed Jan 27, 2014
2 parents 302e954 + dccdaba commit 0c80a43
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.readytalk.examples.swt.SwtBlingExample;
import com.readytalk.swt.util.ColorFactory;
import com.readytalk.swt.widgets.buttons.SquareButton;
import com.readytalk.swt.widgets.buttons.SquareButtonGroup;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void run(Display display, final Shell shell) {
.setHoverColors(BUTTON_HOVER_COLOR_GROUP)
.setDefaultColors(BUTTON_DEFAULT_COLOR_GROUP)
.setClickedColors(FUN_BUTTON_CLICK_COLOR_GROUP)
.setDefaultMouseClickAndReturnKeyHandler(new SquareButton.DefaultButtonClickHandler() {
.setDefaultMouseClickAndReturnKeyHandler(new SquareButton.ButtonClickHandler() {
@Override
public void clicked() {
openTestDialog(shell);
Expand Down Expand Up @@ -168,7 +169,7 @@ public void clicked() {
.setDefaultColors(FUN_BUTTON_DEFAULT_COLOR_GROUP)
.setSelectedColors(FUN_BUTTON_SELECTED_COLOR_GROUP)
.setClickedColors(FUN_BUTTON_CLICK_COLOR_GROUP)
.setDefaultMouseClickAndReturnKeyHandler(new SquareButton.DefaultButtonClickHandler() {
.setDefaultMouseClickAndReturnKeyHandler(new SquareButton.ButtonClickHandler() {
@Override
public void clicked() {
openTestDialog(shell);
Expand All @@ -190,7 +191,7 @@ public void clicked() {
.setDefaultColors(MORE_FUN_BUTTON_DEFAULT_COLOR_GROUP)
.setClickedColors(FUN_BUTTON_CLICK_COLOR_GROUP)
.setSelectedColors(MORE_FUN_BUTTON_SELECTED_COLOR_GROUP)
.setDefaultMouseClickAndReturnKeyHandler(new SquareButton.DefaultButtonClickHandler() {
.setDefaultMouseClickAndReturnKeyHandler(new SquareButton.ButtonClickHandler() {
@Override
public void clicked() {
openTestDialog(shell);
Expand Down Expand Up @@ -260,60 +261,7 @@ public void clicked() {
formData.right = new FormAttachment(90);
bigButtonTwo.setLayoutData(formData);

bigButtonOne.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
if(bigButtonTwo.isToggled()) {
bigButtonTwo.setToggled(false);
}
}
});

bigButtonOne.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent keyEvent) {
switch (keyEvent.character) {
case ' ':
case '\r':
case '\n':
if(bigButtonTwo.isToggled()) {
bigButtonTwo.setToggled(false);
}
break;
default:
break;
}
}
});

bigButtonTwo.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
if(bigButtonOne.isToggled()) {
bigButtonOne.setToggled(false);
}
}
});

bigButtonTwo.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent keyEvent) {
switch (keyEvent.character) {
case ' ':
case '\r':
case '\n':
if(bigButtonOne.isToggled()) {
bigButtonOne.setToggled(false);
}
break;
default:
break;
}
}
});

bigButtonOne.setToggled(true);
// shell.setSize(1200, 200);
new SquareButtonGroup(bigButtonOne, bigButtonTwo);

topGroup.pack();
leftComposite.pack();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.readytalk.swt.widgets.buttons;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class SquareButtonGroupIntegTest {

private Display display;
private Shell shell;

private SquareButton toggleOne, toggleTwo, toggleThree, nonToggled;

private SquareButtonGroup group;

@Before
public void setUp() {
display = Display.getDefault();
shell = new Shell(display);
shell.setLayout(new FillLayout());


SquareButton.SquareButtonBuilder builder = new SquareButton.SquareButtonBuilder();
builder.setParent(shell)
.setText("one")
.setToggleable(true);
toggleOne = builder.build();

builder = new SquareButton.SquareButtonBuilder();
builder.setParent(shell)
.setText("two")
.setToggleable(true);
toggleTwo = builder.build();

builder = new SquareButton.SquareButtonBuilder();
builder.setParent(shell)
.setText("three")
.setToggleable(true);
toggleThree = builder.build();

builder = new SquareButton.SquareButtonBuilder();
builder.setParent(shell)
.setText("non toggle");
nonToggled = builder.build();

group = new SquareButtonGroup(toggleOne, toggleTwo, toggleThree, nonToggled);

shell.open();
}

@Test
public void testDefaultToggle() {
Assert.assertTrue(toggleOne.isToggled());
Assert.assertFalse(toggleTwo.isToggled());
Assert.assertFalse(toggleThree.isToggled());
Assert.assertFalse(nonToggled.isToggled());
}

@Test
public void testBasicToggle() {
toggleTwo.notifyListeners(SWT.MouseUp, new Event());
Assert.assertFalse(toggleOne.isToggled());
Assert.assertTrue(toggleTwo.isToggled());
Assert.assertFalse(toggleThree.isToggled());
Assert.assertFalse(nonToggled.isToggled());
}

@Test
public void testDoubleToggle() {
toggleTwo.notifyListeners(SWT.MouseUp, new Event());
Assert.assertFalse(toggleOne.isToggled());
Assert.assertTrue(toggleTwo.isToggled());
Assert.assertFalse(toggleThree.isToggled());
Assert.assertFalse(nonToggled.isToggled());

toggleTwo.notifyListeners(SWT.MouseUp, new Event());
Assert.assertFalse(toggleOne.isToggled());
Assert.assertTrue(toggleTwo.isToggled());
Assert.assertFalse(toggleThree.isToggled());
Assert.assertFalse(nonToggled.isToggled());
}

@Test
public void testForcedSelection() {
group.setCurrentlyToggledButton(toggleThree);
Assert.assertFalse(toggleOne.isToggled());
Assert.assertFalse(toggleTwo.isToggled());
Assert.assertTrue(toggleThree.isToggled());
Assert.assertFalse(nonToggled.isToggled());
}

@After
public void tearDown() {
shell.close();
display.dispose();
}
}
Loading

0 comments on commit 0c80a43

Please sign in to comment.