[tonegodgui] Removing tab (and other stuff related and not related)

Hello.

I am using tonegodgui (and it’s a pretty nice library), but i am having some problem with the tab part.

First, i would like to be able to remove a tab. AFAIK, there is no such action in the current implementation.

Also, it would be nice to have a way to give an if to the tab so i can retrieve it later by its “name” (even if the id is not a name, as otherwise it would be a problem with the i18n).

Also, i noticed that when you add a tabcontrol to the screen, if the tab control doesn’t have tabs yet, it leads to a arrayindexoutofbound exception (with -1). I guess that it’s because you take the first tab to find the height of the tab list and when the tab list is empty you access an “out of array” element.

For the “id” part, i did that:

[java]
/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package meho.editor.view.tonegod;

import com.jme3.math.Vector2f;
import java.util.Map;
import java.util.TreeMap;
import tonegod.gui.controls.windows.TabControl;
import tonegod.gui.core.Element;
import tonegod.gui.core.ElementManager;

/**
*

  • @author Bubuche
    */
    public class Tabber extends TabControl
    {
    private Map<String, Integer> addedTabs;
    int nb;

public Tabber(ElementManager screen, String UID, Vector2f position, Vector2f dimensions)
{
super(screen, UID, position, dimensions);
nb = 0;
addedTabs = new TreeMap<>();

}

public int prepareTab(String text, String tabId)
{
addTab(text);
int result = nb;

addedTabs.put(tabId, nb);

nb += 1;
return result;

}

public void getTabContentSize(int i, Vector2f out)
{
Element elt = (Element) tabPanels.get(i);
out.set(elt.getDimensions());
}

public Element getTabElement(int i)
{
return (Element) tabPanels.get(i);
}

@Override
public void onTabSelect(int v)
{
}

public int indexOf(String tabId)
{
return this.addedTabs.get(tabId);
}
}
[/java]

You don’t need to take this implementation, but it’s just to give you an idea of what i am expecting.

For the “out of array exception”, i need to add an empty tabcontrol, cause i add element on it later (i have different classes that add different elements on the gui, and they need to get the place where they add elements).
To have a “quick-and-dirt” solution, i did this, in the screen (so, it’s really a workaround and not a fix at all):

[java]
/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package meho.editor.view.tonegod;

import com.jme3.app.Application;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import tonegod.gui.core.Element;
import tonegod.gui.core.Screen;

/**
*

  • @author Bubuche
    */
    public class ExtendedScreen extends Screen
    {
    private List<Element> toAdd;

public ExtendedScreen(Application app)
{
super(app);
init();
}

public ExtendedScreen(Application app, String styleMap)
{
super(app, styleMap);
init();
}

public ExtendedScreen(Application app, String styleMap, float width, float height)
{
super(app, styleMap, width, height);
init();
}

private void init()
{
this.toAdd = new ArrayList<>();
}

@Override
public Element getElementById(String id)
{
for ( Element elt : toAdd )
{
if ( id.equals(elt.getUID()) )
{
return elt;
}
}
return super.getElementById(id);
}

public void doAddElements()
{
Iterator<Element> it = toAdd.iterator();
while (it.hasNext())
{
Element elt = it.next();
it.remove();

  addElement(elt, ! elt.getIsVisible() );
  
}

}

public void addLater(Element element)
{
this.toAdd.add(element);
}
}
[/java]
With this, i can access the tabcontrol by its uid as if it was in the screen.

Now, i can start to work on the “removeTab” thing, but before that i prefer to have your (tonegod) opinion, to know if you already plan to do something like that.

Also, i would like to talk with you about the i18n thing, as i have an idea to put a very small change in the lib that would just enable it everywhere. Right now i have i18n stuff with codes like this:
[java]
translator = application.getStateManager().getState(I18nState.class);

addColumn(translator.translate(“bindings.action”, “Action”));
addColumn(translator.translate(“bindings.user”, “User”));
addColumn(translator.translate(“bindings.default”, “Default”));
[/java]
And to explain it briefly, my idea is this : in the Element class, instead of having a text(String) and an image you would be able to have a text OR a “I18nedText” (see below) and an image.
What is an I18nText ? Only something that has a method “getText”, which return a string.
What is the point of this ? Well, the I18nedText can have internally some way to consult the currently used Locale, ResourcesBundle etc. and give an appropriate translation. From the element’s point of view nothing change as if the element is an I18nedText it will call getText and display it as before.

Well, you can even do better : instead of a text, an Element can have an Object and call “toString” on the object to convert it into a string to display it. When you call “toString” on a String, it returns the same object, so everything that worked before will still work, but it will be easy to replace the String with something smarter.

Or you can go “swing-way” and do a lot of stuff with renderers but … i am not fan of this idea, it would change the lib too much.