Revision 41080 trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/mdiFrame/MDIFrame.java
MDIFrame.java | ||
---|---|---|
43 | 43 |
import java.util.Enumeration; |
44 | 44 |
import java.util.HashMap; |
45 | 45 |
import java.util.Iterator; |
46 |
import java.util.List; |
|
46 | 47 |
import java.util.Map; |
47 | 48 |
import java.util.Map.Entry; |
48 | 49 |
import java.util.NoSuchElementException; |
... | ... | |
52 | 53 |
import javax.swing.AbstractButton; |
53 | 54 |
import javax.swing.ButtonGroup; |
54 | 55 |
import javax.swing.ImageIcon; |
56 |
import javax.swing.JButton; |
|
55 | 57 |
import javax.swing.JComponent; |
56 | 58 |
import javax.swing.JFileChooser; |
57 | 59 |
import javax.swing.JFrame; |
... | ... | |
62 | 64 |
import javax.swing.JPopupMenu; |
63 | 65 |
import javax.swing.JSeparator; |
64 | 66 |
import javax.swing.JToolBar; |
67 |
import javax.swing.KeyStroke; |
|
65 | 68 |
import javax.swing.MenuElement; |
66 | 69 |
import javax.swing.SwingUtilities; |
67 | 70 |
import javax.swing.Timer; |
68 | 71 |
import javax.swing.WindowConstants; |
69 | 72 |
import javax.swing.filechooser.FileFilter; |
70 | 73 |
|
71 |
import org.slf4j.Logger; |
|
72 |
import org.slf4j.LoggerFactory; |
|
73 |
|
|
74 | 74 |
import org.gvsig.andami.IconThemeHelper; |
75 | 75 |
import org.gvsig.andami.Launcher; |
76 | 76 |
import org.gvsig.andami.LibraryExtension; |
... | ... | |
93 | 93 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
94 | 94 |
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory; |
95 | 95 |
import org.gvsig.gui.beans.controls.IControl; |
96 |
import org.gvsig.tools.ToolsLocator; |
|
97 |
import org.gvsig.tools.i18n.I18nManager; |
|
96 | 98 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
97 | 99 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
98 |
import org.gvsig.tools.task.RunnableWithParameters; |
|
100 |
import org.slf4j.Logger; |
|
101 |
import org.slf4j.LoggerFactory; |
|
99 | 102 |
|
100 | 103 |
/** |
101 | 104 |
* Main application window. |
... | ... | |
447 | 450 |
} |
448 | 451 |
} |
449 | 452 |
|
453 |
public void addTool(final ActionInfo action, final String toolBarName) { |
|
454 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
455 |
|
|
456 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
457 |
SwingUtilities.invokeLater(new Runnable() { |
|
458 |
public void run() { |
|
459 |
addTool(action, toolBarName); |
|
460 |
} |
|
461 |
}); |
|
462 |
return; |
|
463 |
} |
|
464 |
JToolBarButton btn = new JToolBarButton(action.getIcon()); |
|
465 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
|
466 |
btn.addMouseListener(tooltipListener); |
|
467 |
btn.addActionListener(this); |
|
468 |
btn.setFocusable(false); |
|
469 |
btn.setActionCommand(action.getCommand()); |
|
470 |
btn.setEnabled(false); |
|
471 |
btn.setVisible(false); |
|
472 |
btn.setName(action.getName()); |
|
473 |
if (action.getTooltip() != null) { |
|
474 |
btn.setToolTip(i18nManager.getTranslation(action.getTooltip())); |
|
475 |
} |
|
476 |
|
|
477 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(toolBarName); |
|
478 |
if (jtb == null) { |
|
479 |
jtb = new SelectableToolBar(toolBarName); |
|
480 |
jtb.setRollover(true); |
|
481 |
jtb.setAndamiVisibility(true); |
|
482 |
toolBarMap.put(toolBarName, jtb); |
|
483 |
toolBars.add(jtb); |
|
484 |
} |
|
485 |
jtb.add(btn); |
|
486 |
|
|
487 |
controlClass.put(btn, action.getExtension().getClass()); |
|
488 |
} |
|
489 |
|
|
450 | 490 |
/** |
451 | 491 |
* Creates the needed menu structure to add the menu to the bar. |
452 | 492 |
* Returns the father which must hold the menu which was |
... | ... | |
464 | 504 |
* @return The proper father for the menu which was provided as parameter |
465 | 505 |
*/ |
466 | 506 |
private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) { |
507 |
return createMenuAncestors(menu.getText()); |
|
508 |
} |
|
509 |
|
|
510 |
private JMenu createMenuAncestors(String text) { |
|
511 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
512 |
|
|
467 | 513 |
MenuElement menuPadre = null; |
468 | 514 |
|
469 |
PluginServices ps = |
|
470 |
PluginServices.getPluginServices(loader.getPluginName()); |
|
471 |
|
|
472 |
String[] menues = menu.getText().split("/"); |
|
473 |
ArrayList menuList = new ArrayList(); |
|
515 |
String[] menues = text.split("/"); |
|
516 |
List menuList = new ArrayList(); |
|
474 | 517 |
menuList.add(menues[0]); |
475 | 518 |
menuPadre = getMenu(menuList, menuBar); |
476 | 519 |
|
477 | 520 |
JMenu padre = null; |
478 | 521 |
|
479 | 522 |
if (menuPadre == null) { |
480 |
padre = new JMenu(ps.getText(menues[0]));
|
|
523 |
padre = new JMenu(i18nManager.getTranslation(menues[0]));
|
|
481 | 524 |
padre.setName(menues[0]); |
482 | 525 |
menuBar.add(padre); |
483 | 526 |
} else |
484 | 527 |
if (menuPadre instanceof JMenu) { |
485 | 528 |
padre = (JMenu) menuPadre; |
486 | 529 |
} else { |
487 |
logger.error(ps |
|
488 |
.getText("error_creating_menu_Ancestor_does_not_exist")); |
|
530 |
logger.error(i18nManager.getTranslation("error_creating_menu_Ancestor_does_not_exist")); |
|
489 | 531 |
return null; |
490 | 532 |
} |
491 | 533 |
|
... | ... | |
540 | 582 |
controlClass.put(nuevoMenu, classExtension); |
541 | 583 |
} |
542 | 584 |
|
585 |
public void addMenu(final ActionInfo action, final String text) { |
|
586 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
587 |
SwingUtilities.invokeLater(new Runnable() { |
|
588 |
public void run() { |
|
589 |
addMenu(action,text); |
|
590 |
} |
|
591 |
}); |
|
592 |
return; |
|
593 |
} |
|
594 |
JMenu menuPadre = createMenuAncestors(text); |
|
595 |
JMenuItem nuevoMenu = createJMenuItem(action, text); |
|
596 |
nuevoMenu.addMouseListener(tooltipListener); |
|
597 |
menuPadre.add(nuevoMenu); |
|
598 |
Class<? extends IExtension> classExtension = action.getExtension().getClass(); |
|
599 |
controlClass.put(nuevoMenu, classExtension); |
|
600 |
} |
|
601 |
|
|
543 | 602 |
/** |
544 | 603 |
* Dado un array de nombres de menu, encuentra el men� |
545 | 604 |
* |
... | ... | |
550 | 609 |
* |
551 | 610 |
* @return DOCUMENT ME! |
552 | 611 |
*/ |
553 |
private javax.swing.JMenuItem getMenu(ArrayList nombres, MenuElement parent) {
|
|
612 |
private javax.swing.JMenuItem getMenu(List nombres, MenuElement parent) { |
|
554 | 613 |
if (parent instanceof javax.swing.JMenu) { |
555 | 614 |
javax.swing.JMenu parentItem = (javax.swing.JMenu) parent; |
556 | 615 |
|
... | ... | |
626 | 685 |
* @param nombres |
627 | 686 |
* @return |
628 | 687 |
*/ |
629 |
private boolean lastMenuItemWithoutName(Component mc, ArrayList names) {
|
|
688 |
private boolean lastMenuItemWithoutName(Component mc, List names) { |
|
630 | 689 |
|
631 | 690 |
/* |
632 | 691 |
* names must have 1 string |
... | ... | |
949 | 1008 |
return nuevoMenu; |
950 | 1009 |
} |
951 | 1010 |
|
1011 |
private JMenuItem createJMenuItem(ActionInfo action, String text) { |
|
1012 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
1013 |
JMenuItem nuevoMenu = null; |
|
1014 |
String label = null; |
|
1015 |
|
|
1016 |
if( text == null ) { |
|
1017 |
label = action.getLabel(); |
|
1018 |
} else if( text.contains("/") ) { |
|
1019 |
String[] ss = text.split("/"); |
|
1020 |
label = ss[ss.length-1]; |
|
1021 |
} else { |
|
1022 |
label = text; |
|
1023 |
} |
|
1024 |
String translatedText = i18nManager.getTranslation(label); |
|
1025 |
if( action.getIconName()!=null ) { |
|
1026 |
ImageIcon image = action.getIcon(); |
|
1027 |
if ( image != null) { |
|
1028 |
nuevoMenu = new JMenuItem(translatedText, image); |
|
1029 |
} else { |
|
1030 |
nuevoMenu = new JMenuItem(translatedText); |
|
1031 |
} |
|
1032 |
} else { |
|
1033 |
nuevoMenu = new JMenuItem(translatedText); |
|
1034 |
} |
|
1035 |
nuevoMenu.setName(action.getName()); |
|
1036 |
KeyStroke key = action.getKeyStroke(); |
|
1037 |
if ( key!= null) { |
|
1038 |
nuevoMenu.setAccelerator(key); |
|
1039 |
} |
|
1040 |
nuevoMenu.setActionCommand(action.getCommand()); |
|
1041 |
if (action.getTooltip() != null) { |
|
1042 |
nuevoMenu.setToolTip(i18nManager.getTranslation(action.getTooltip())); |
|
1043 |
} |
|
1044 |
nuevoMenu.setEnabled(true); |
|
1045 |
nuevoMenu.setVisible(true); |
|
1046 |
nuevoMenu.addActionListener(action); |
|
1047 |
return nuevoMenu; |
|
1048 |
} |
|
1049 |
|
|
952 | 1050 |
/** |
953 | 1051 |
* Muestra u oculta el menu de nombre 'name' |
954 | 1052 |
* |
Also available in: Unified diff