net.vectorpublish.desktop.vp.ToolbarImpl Maven / Gradle / Ivy
/*
* Copyright (c) 2016, Peter Rader. All rights reserved.
* ___ ___ __ ______ __ __ __ __
* | | |.-----..----.| |_ .-----..----.| __ \.--.--.| |--.| ||__|.-----.| |--.
* | | || -__|| __|| _|| _ || _|| __/| | || _ || || ||__ --|| |
* \_____/ |_____||____||____||_____||__| |___| |_____||_____||__||__||_____||__|__|
*
* http://www.gnu.org/licenses/gpl-3.0.html
*/
package net.vectorpublish.desktop.vp;
import java.awt.Component;
import java.awt.event.ActionListener;
import javax.inject.Inject;
import javax.inject.Named;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.KeyStroke;
import net.vectorpublish.desktop.vp.api.ui.ToolBar;
import net.vectorpublish.desktop.vp.log.Log;
@Named
public class ToolbarImpl extends ToolBar {
@Inject
private final Log log = null;
public ToolbarImpl() {
super();
}
@Override
public JButton add(Action action) {
final JButton add = super.add(action);
add.setHideActionText(true);
return add;
}
@Override
public void moveToTheRight(Action still, Action toMove) {
final Component[] components = getComponents();
int stillIndex = -1, toMoveIndex = -1;
for (int componentIndex = 0; componentIndex < components.length; componentIndex++) {
final Component b = components[componentIndex];
if (b instanceof AbstractButton) {
final AbstractButton ab = (AbstractButton) b;
if (ab.getAction() == still) {
stillIndex = componentIndex;
}
if (ab.getAction() == toMove) {
toMoveIndex = componentIndex;
}
}
}
if (toMoveIndex == -1) {
log.voteEnlargeLogging();
throw new RuntimeException(toMove + " not found.");
}
if (stillIndex == -1) {
log.voteEnlargeLogging();
throw new RuntimeException(still + " not found.");
}
setComponentZOrder(getComponent(toMoveIndex), stillIndex + 1);
log.voteShortenLogging();
}
@Override
public void registerKeyboardAction(ActionListener action, KeyStroke aKeyStroke, int aCondition) {
super.registerKeyboardAction(action, "", aKeyStroke, aCondition);
}
}