blob: 2a11077f0e62037f428509ae4c7a370d016687e2 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2012, 2021 Original NatTable authors and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Original NatTable authors and others - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.ecommons.waltable.style.editor;
import static org.eclipse.swt.SWT.NONE;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.statet.ecommons.waltable.Messages;
/**
* Control to select the thickness of a border.
*/
public class BorderThicknessPicker extends Composite {
private final Combo combo;
public BorderThicknessPicker(final Composite parent) {
super(parent, NONE);
setLayout(new RowLayout());
this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN);
this.combo.setItems(new String[] {
Messages.getString("BorderThicknessPicker.thin"), //$NON-NLS-1$
Messages.getString("BorderThicknessPicker.thick"), //$NON-NLS-1$
Messages.getString("BorderThicknessPicker.veryThick")}); //$NON-NLS-1$
this.combo.select(0);
}
@Override
public void setEnabled(final boolean b) {
this.combo.setEnabled(b);
}
public int getSelectedThickness() {
final long idx= this.combo.getSelectionIndex();
if (idx == 0) {
return 1;
} else if (idx == 1) {
return 3;
} else if (idx == 2) {
return 6;
}
else {
throw new IllegalStateException("never happen"); //$NON-NLS-1$
}
}
public void setSelectedThickness(final int thickness) {
if (thickness < 0)
{
throw new IllegalArgumentException("negative number"); //$NON-NLS-1$
}
int idx= 0;
if (thickness < 3) {
idx= 0;
} else if (thickness < 6) {
idx= 1;
} else if (thickness > 6) {
idx= 2;
}
this.combo.select(idx);
}
}