com.diffplug.common.swt.widgets.LinkBtn Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of durian-swt Show documentation
Show all versions of durian-swt Show documentation
DurianSwt - Reactive utilities and fluent builders for SWT
The newest version!
/*
* Copyright 2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.common.swt.widgets;
import com.diffplug.common.base.Preconditions;
import com.diffplug.common.swt.ControlWrapper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
/** Added a control that uses an SWT Link to implement the standard Button interface. */
public class LinkBtn extends ControlWrapper.AroundControl {
public LinkBtn(Composite parent, int style) {
super(new Link(parent, SWT.NONE));
Preconditions.checkArgument(style == SWT.PUSH, "LinkBtn only supports SWT.PUSH");
}
public void setText(String text) {
wrapped.setText("" + text + "");
}
/** Returns the text. */
public String getText() {
String txt = wrapped.getText();
return txt.substring("".length(), txt.length() - "".length());
}
/** Adds a listener. */
public void addListener(int eventType, Listener listener) {
wrapped.addListener(eventType, listener);
}
/** Removes a listener. */
public void removeListener(int eventType, Listener listener) {
wrapped.removeListener(eventType, listener);
}
/** Determines whether this FlatBtn is enabled or not. */
public void setEnabled(boolean enabled) {
wrapped.setEnabled(enabled);
}
/** Quick method to create a LinkBtn. */
public static LinkBtn create(Composite parent, String txt, Runnable action) {
LinkBtn btn = new LinkBtn(parent, SWT.PUSH);
btn.setText(txt);
btn.addListener(SWT.Selection, e -> action.run());
return btn;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy