Menu

#150 ToolBar

unplanned
open
5
2007-10-09
2007-06-27
No

what about implementing the TooBar interface of the mail demo in the package thinwire.ui with the funcionality/design of the windows general Toolbars? that would be nice. Thanks in advance.

Discussion

  • Joshua Gertzen

    Joshua Gertzen - 2007-10-09
    • milestone: --> unplanned
     
  • Nobody/Anonymous

    Implementation toolbar

    public class ToolBar extends Panel {
    private List<Object> items = new ArrayList<Object>();
    private ActionListener listener;

    @Override
    public Panel addActionListener(String action, ActionListener listener) {
    this.listener = listener;
    render();
    return this;
    }

    public Button addButton(Button button) {
    items.add(button);
    render();

    return button;
    }

    public Button addButton() {
    return addButton(new Button());
    }

    public Button addButton(String text) {
    return addButton(new Button(text));
    }

    public Button addButton(String text, String image) {
    return addButton(new Button(text, image));
    }

    public void addSeparetor() {
    items.add(new Separetor());
    render();
    }

    private void render() {
    getChildren().clear();
    int numButtons = items.size();

    if (numButtons > 0) {
    // default value
    double[][] sizes = new double[][] { new double[numButtons + 1],
    { 0 } };

    // buttons length
    for (int i = 0; i < numButtons; i++) {
    sizes[0][i] = 26;
    }
    TableLayout layout = new TableLayout(sizes);
    setLayout(layout);

    // loop to element
    for (int i = 0; i < items.size(); i++) {
    Object item = items.get(i);
    if (item instanceof Separetor) {
    // se separatore
    layout.getColumns().get(i).setWidth(4);
    } else {
    getChildren().add(((Component) item).setLimit(i + ", 0"));

    // azione su click
    if (listener != null) {
    ((Component) item).addActionListener(
    Component.ACTION_CLICK, listener);
    }
    }
    }
    }
    }

    private class Separetor {
    }
    }
    =============================================================
    ....
    ToolBar toolBar = new ToolBar();
    toolBar.addButton("", Main.RES_PATH + "application/add.png").setUserObject("ADD");
    toolBar.addButton("", Main.RES_PATH + "application/delete.png").setUserObject("REMOVE");
    toolBar.addButton("",Main.RES_PATH + "application/application_edit.png").setUserObject("EDIT");
    dlg.getChildren().add(toolBar.setLimit("0,0"));

    =============================================================

    ciau

     

Log in to post a comment.