xy.reflect.ui.control.swing.MethodControl Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (C) 2018 OTK Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* The GNU General Public License allows you also to freely redistribute
* the libraries under the same license, if you provide the terms of the
* GNU General Public License with them and add the following
* copyright notice at the appropriate place (with a link to
* http://javacollection.net/reflectionui/ web site when possible).
******************************************************************************/
package xy.reflect.ui.control.swing;
import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import xy.reflect.ui.control.IMethodControlData;
import xy.reflect.ui.control.IMethodControlInput;
import xy.reflect.ui.control.swing.renderer.SwingRenderer;
import xy.reflect.ui.util.ReflectionUIUtils;
import xy.reflect.ui.util.SwingRendererUtils;
import xy.reflect.ui.util.component.AbstractControlButton;
public class MethodControl extends AbstractControlButton implements ActionListener {
protected static final long serialVersionUID = 1L;
protected SwingRenderer swingRenderer;
protected IMethodControlInput input;
protected IMethodControlData data;
public MethodControl(SwingRenderer swingRenderer, IMethodControlInput input) {
this.swingRenderer = swingRenderer;
this.input = input;
this.data = input.getControlData();
addActionListener(this);
}
@Override
public SwingRenderer getSwingRenderer() {
return swingRenderer;
}
@Override
public Color retrieveBackgroundColor() {
if (data.getBackgroundColor() == null) {
return null;
} else {
return SwingRendererUtils.getColor(data.getBackgroundColor());
}
}
@Override
public Color retrieveForegroundColor() {
if (data.getForegroundColor() == null) {
return null;
} else {
return SwingRendererUtils.getColor(data.getForegroundColor());
}
}
@Override
public Image retrieveBackgroundImage() {
if (data.getBackgroundImagePath() == null) {
return null;
} else {
return SwingRendererUtils.loadImageThroughcache(data.getBackgroundImagePath(),
ReflectionUIUtils.getErrorLogListener(swingRenderer.getReflectionUI()));
}
}
@Override
public String retrieveCaption() {
return ReflectionUIUtils.formatMethodControlCaption(data.getCaption(), data.getParameters());
}
@Override
public String retrieveToolTipText() {
return ReflectionUIUtils.formatMethodControlTooltipText(data.getCaption(), data.getOnlineHelp(),
data.getParameters());
}
@Override
public Icon retrieveIcon() {
return swingRenderer.getMethodIcon(data);
}
@Override
public void actionPerformed(final ActionEvent e) {
MethodAction action = swingRenderer.createMethodAction(input);
action.actionPerformed(e);
}
@Override
public String toString() {
return "MethodControl [data=" + data + "]";
}
}