* @param domain
* @param domain The domain (ie MapEditor or MapPart) for which we are tacking tools
* @return PaletteRoot suitable for use with a PaletteView
*/
public static PaletteRoot createPalette() {
PaletteRoot root = new PaletteRoot();
IToolManager toolManager = ApplicationGIS.getToolManager();
List<PaletteContainer> categories = new ArrayList<PaletteContainer>();
// Normal GEF Tools (SelectionTool etc...)
// PaletteContainer controlGroup = createControlGroup(root);
// categories.add(controlGroup);
PaletteToolbar navigation = new PaletteToolbar("Navigation");
// navigation.setInitialState(PaletteDrawer.INITIAL_STATE_OPEN);
// navigation.setDrawerType(ToolEntry.PALETTE_TYPE_TOOL);
navigation.setUserModificationPermission(PaletteContainer.PERMISSION_NO_MODIFICATION);
// navigation.setShowDefaultIcon(false);
for( ModalToolCategory category : toolManager.getModalToolCategories() ) {
// Simple PaletteDrawer (no icon for the tool category at this time)
String shortcut = shortcut(category.getName());
String name = fixLabel(category.getName());
PaletteContainer container;
if( category.getId().equals("org.locationtech.udig.tool.category.zoom") ||
category.getId().equals("org.locationtech.udig.tool.category.pan")){
container = navigation;
}
else {
PaletteDrawer drawer = new PaletteDrawer(name);
drawer.setId( category.getId() );
if( category == toolManager.getActiveCategory()){
drawer.setInitialState(PaletteDrawer.INITIAL_STATE_OPEN);
}
else {
drawer.setInitialState(PaletteDrawer.INITIAL_STATE_CLOSED);
}
drawer.setDrawerType(ToolEntry.PALETTE_TYPE_TOOL);
drawer.setUserModificationPermission(PaletteContainer.PERMISSION_NO_MODIFICATION);
drawer.setShowDefaultIcon(false);
if( shortcut != null ){
drawer.setDescription( "("+shortcut+")" );
}
container = drawer;
}
category.container( container ); // hook up so container can cycle tools on keypress
for( ModalItem modalItem : category ) {
String label = fixLabel(modalItem.getName());
String keypress = shortcut(modalItem.getName());
ToolEntry tool = new MapToolEntry(label, modalItem, keypress, category.getId());
//set the default tool
if(modalItem.getId().equals(DEFAULT_ID)){
root.setDefaultEntry(tool);
}
container.add(tool);
}
if( container == navigation){
continue; // don't add navigation container multiple times
}
categories.add(container);
}
Comparator<PaletteContainer> sorter = new Comparator<PaletteContainer>(){
List<String> preferredOrder = Arrays.asList(new String[]{
"org.locationtech.udig.tool.category.zoom",
"org.locationtech.udig.tool.category.pan",
"org.locationtech.udig.tool.category.info",
"org.locationtech.udig.tool.category.selection"
});
int order( String id ){
int index = preferredOrder.indexOf(id);
if ("Other".equals(id)) {
// Other will be -2 after everything else
return -2;
}
else if (index == -1 ){
return -1;
}
else {
// make this a positive experience with "zoom" showing up first
return 100-index;
}
}
public int compare( PaletteContainer o1, PaletteContainer o2 ) {
String s1 = o1.getId();
String s2 = o2.getId();
int order1 = order(s1);
int order2 = order(s2);
if ( order1 == order2){
return 0;
}
else if (order1 < order2){
return 1;
}
else {
return -1;
}
// return order1-order2; // is this the fast way? I am not good a C
}
};
Collections.sort(categories,sorter );
categories.add(0,navigation);
// try and prevent tool category order from changing
root.setUserModificationPermission( PaletteContainer.PERMISSION_NO_MODIFICATION );
root.setChildren(categories);
return root;
}