Skip to content

Commit

Permalink
Issue 328 - DualList should be configuable
Browse files Browse the repository at this point in the history
  • Loading branch information
lcaron committed Jun 12, 2021
1 parent 41e3604 commit 86c8a95
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Laurent CARON.
* Copyright (c) 2011-2021 Laurent CARON.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -28,7 +28,7 @@
import org.eclipse.swt.widgets.Shell;

/**
* A simple snipper for the ItemSelector Widget
* A simple snipper for the DualList Widget
*
*/
public class DualListSnippet {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Laurent CARON.
* Copyright (c) 2011-2021 Laurent CARON.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -15,21 +15,34 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.nebula.widgets.opal.commons.SWTGraphicUtil;
import org.eclipse.nebula.widgets.opal.duallist.DLConfiguration;
import org.eclipse.nebula.widgets.opal.duallist.DLItem;
import org.eclipse.nebula.widgets.opal.duallist.DualList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* A simple snipper for the ItemSelector Widget
* A simple snipper for the DualList Widget
*
*/
public class DualListTextSnippet {
private static final String DOUBLE_DOWN_IMAGE = "double_down.png";
private static final String DOUBLE_UP_IMAGE = "double_up.png";
private static final String DOUBLE_LEFT_IMAGE = "double_left.png";
private static final String DOUBLE_RIGHT_IMAGE = "double_right.png";
private static final String ARROW_DOWN_IMAGE = "arrow_down.png";
private static final String ARROW_LEFT_IMAGE = "arrow_left.png";
private static final String ARROW_UP_IMAGE = "arrow_up.png";
private static final String ARROW_RIGHT_IMAGE = "arrow_right.png";
private static DualList dl;

public static void main(final String[] args) {
final Display display = new Display();
Expand All @@ -38,14 +51,38 @@ public static void main(final String[] args) {
shell.setSize(600, 600);
shell.setLayout(new GridLayout(1, false));

final DualList dl = new DualList(shell, SWT.NONE);
dl = new DualList(shell, SWT.NONE);
dl.setItems(createItems(shell));
dl.addListener(SWT.Selection, e -> {
System.out.println("Selection Listener called");
});

dl.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));

GridData gdButtons = new GridData(GridData.END, GridData.FILL, true, false);
gdButtons.widthHint = 150;

Button changeConfiguration = new Button(shell, SWT.PUSH);
changeConfiguration.setText("Change Configuration");
changeConfiguration.setLayoutData(gdButtons);
changeConfiguration.addListener(SWT.Selection, e -> dl.setConfiguration(createConfiguration()));

Button hideButtons = new Button(shell, SWT.PUSH);
hideButtons.setText("Hide buttons");
hideButtons.setLayoutData(gdButtons);
hideButtons.addListener(SWT.Selection, e -> {
DLConfiguration config = new DLConfiguration();
config.setDoubleDownVisible(false).setDoubleUpVisible(false).//
setDoubleRightVisible(false).setDoubleLeftVisible(false).//
setDownVisible(false).setUpVisible(false);
dl.setConfiguration(config);
});

Button resetConfiguration = new Button(shell, SWT.PUSH);
resetConfiguration.setText("Reset Configuration");
resetConfiguration.setLayoutData(gdButtons);
resetConfiguration.addListener(SWT.Selection, e -> dl.setConfiguration(null));

shell.pack();
shell.open();

Expand Down Expand Up @@ -109,4 +146,33 @@ private static List<DLItem> createItems(final Shell shell) {
return list;
}

private static DLConfiguration createConfiguration() {
DLConfiguration config = new DLConfiguration();
Display display = Display.getCurrent();
// Change colors for both panels
config.setItemsBackgroundColor(display.getSystemColor(SWT.COLOR_BLACK)).//
setItemsForegroundColor(display.getSystemColor(SWT.COLOR_WHITE)).//
setItemsOddLinesColor(display.getSystemColor(SWT.COLOR_GRAY));
config.setSelectionBackgroundColor(display.getSystemColor(SWT.COLOR_DARK_GREEN)).//
setSelectionForegroundColor(display.getSystemColor(SWT.COLOR_YELLOW)).//
setSelectionOddLinesColor(display.getSystemColor(SWT.COLOR_RED));

// Change text alignment
config.setItemsTextAlignment(SWT.RIGHT).setSelectionTextAlignment(SWT.CENTER);

// Change buttons
config.setDownImage(createImage(ARROW_DOWN_IMAGE)).setUpImage(createImage(ARROW_UP_IMAGE)).//
setRightImage(createImage(ARROW_RIGHT_IMAGE)).setLeftImage(createImage(ARROW_LEFT_IMAGE)).//
setDoubleDownImage(createImage(DOUBLE_DOWN_IMAGE)).setDoubleUpImage(createImage(DOUBLE_UP_IMAGE)).//
setDoubleLeftImage(createImage(DOUBLE_LEFT_IMAGE)).setDoubleRightImage(createImage(DOUBLE_RIGHT_IMAGE));

return config;
}

private static Image createImage(String fileName) {
Image image = new Image(Display.getCurrent(), //
DualListTextSnippet.class.getResourceAsStream("arrows/" + fileName));
SWTGraphicUtil.addDisposer(dl, image);
return image;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 86c8a95

Please sign in to comment.