forked from LupusNobilis/java-org.hwo
JToolButtonBar: Neues Steuerelement
parent
5697de63b1
commit
5f1204a770
|
@ -0,0 +1,74 @@
|
|||
package org.hwo.ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
import org.hwo.ui.toolbar.UITool;
|
||||
|
||||
public class JToolButtonBar extends JPanel {
|
||||
|
||||
LinkedList<UITool> tools;
|
||||
LinkedList<JToggleButton> buttons;
|
||||
|
||||
UITool selectedTool;
|
||||
|
||||
|
||||
public JToolButtonBar() {
|
||||
tools = new LinkedList<UITool>();
|
||||
buttons = new LinkedList<JToggleButton>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addTool(final UITool tool){
|
||||
tools.add(tool);
|
||||
|
||||
JToggleButton button = new JToggleButton();
|
||||
button.setSize(32, 32);
|
||||
button.setText( tool.getLabel() );
|
||||
button.setToolTipText(tool.getHelp());
|
||||
|
||||
button.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
selectTool(tool);
|
||||
}
|
||||
});
|
||||
|
||||
buttons.add(button);
|
||||
|
||||
add(button);
|
||||
}
|
||||
|
||||
public void selectTool(UITool tool){
|
||||
if (selectedTool != null) {
|
||||
selectedTool.unselect();
|
||||
int idx = tools.indexOf(selectedTool);
|
||||
if (idx != -1){
|
||||
buttons.get(idx).setSelected(false);
|
||||
}
|
||||
selectedTool = null;
|
||||
}
|
||||
|
||||
if (tool != null){
|
||||
int idx = tools.indexOf(tool);
|
||||
if (idx != -1){
|
||||
buttons.get(idx).setSelected(true);
|
||||
}
|
||||
tool.select();
|
||||
selectedTool = tool;
|
||||
}
|
||||
}
|
||||
|
||||
public UITool getSelectedTool() {
|
||||
return selectedTool;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package org.hwo.ui.toolbar;
|
||||
|
||||
import java.awt.Image;
|
||||
|
||||
|
||||
public class UITool {
|
||||
|
||||
private Object tool;
|
||||
private String label;
|
||||
private String help;
|
||||
private Image image;
|
||||
|
||||
private boolean selected;
|
||||
|
||||
public UITool(){
|
||||
|
||||
}
|
||||
|
||||
public Object getTool() {
|
||||
return tool;
|
||||
}
|
||||
public void setTool(Object tool) {
|
||||
this.tool = tool;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return help;
|
||||
}
|
||||
public void setHelp(String help) {
|
||||
this.help = help;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
public void setImage(Image image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
|
||||
public void select(){
|
||||
this.selected = true;
|
||||
}
|
||||
public void unselect(){
|
||||
this.selected = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue