Revision 32707

View differences:

trunk/frameworks/_fwAndami/src/com/iver/andami/ui/mdiFrame/MDIFrame.java
104 104
 * @version $Revision$
105 105
 */
106 106
public class MDIFrame extends JFrame implements ComponentListener,
107
	ContainerListener, ActionListener, MainFrame {
107
ContainerListener, ActionListener, MainFrame {
108 108
	/** DOCUMENT ME! */
109 109
	private static Logger logger = Logger.getLogger(MDIFrame.class.getName());
110 110
	private MDIManager mdiManager = MDIManagerFactory.createManager();
......
121 121
	/** Asocia los nombres con las barras de herramientas */
122 122
	private HashMap toolBarMap = new HashMap();
123 123

  
124
		/** Almacena los grupos de selectableTools */
124
	/** Almacena los grupos de selectableTools */
125 125
	private HashMap buttonGroupMap = new HashMap();
126 126
	/**
127 127
	 * Stores the initially selected tools.
128
     * It contains pairs (String groupName, JToolBarToggleButton button)
128
	 * It contains pairs (String groupName, JToolBarToggleButton button)
129 129
	 */
130 130
	private HashMap initialSelectedTools = new HashMap();
131 131

  
132
    /**
133
     * Stores the actionCommand of the selected tool, for each group.
134
     * It contains pairs (String groupName, JToolBarToggleButton button)
135
     */
136
    private HashMap selectedTool = null;
137
    // this should be the same value defined at plugin-config.xsd
138
    private String defaultGroup = "unico";
132
	/**
133
	 * Stores the actionCommand of the selected tool, for each group.
134
	 * It contains pairs (String groupName, JToolBarToggleButton button)
135
	 */
136
	private HashMap selectedTool = null;
137
	// this should be the same value defined at plugin-config.xsd
138
	private String defaultGroup = "unico";
139 139

  
140 140
	/** Asocia los nombres con los popupMenus */
141 141
	private HashMap popupMap = new HashMap();
......
184 184

  
185 185
		//Se a�aden los listeners del JFrame
186 186
		this.addWindowListener(new WindowAdapter() {
187
				public void windowClosing(WindowEvent e) {
188
					Launcher.closeApplication();
189
				}
190
			});
187
			public void windowClosing(WindowEvent e) {
188
				Launcher.closeApplication();
189
			}
190
		});
191 191
		this.addComponentListener(this);
192 192
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
193 193

  
......
244 244
	 * @throws RuntimeException DOCUMENT ME!
245 245
	 */
246 246
	public void addTool(PluginClassLoader loader, SkinExtensionType ext,
247
		ToolBar toolBar, SelectableTool selectableTool)
248
		throws ClassNotFoundException {
247
			ToolBar toolBar, SelectableTool selectableTool)
248
	throws ClassNotFoundException {
249 249
		if (!SwingUtilities.isEventDispatchThread()) {
250 250
			throw new RuntimeException("No Event Dispatch Thread");
251 251
		}
......
334 334
	 * @throws RuntimeException DOCUMENT ME!
335 335
	 */
336 336
	public void addTool(PluginClassLoader loader, SkinExtensionType ext,
337
		ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException {
337
			ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException {
338 338
		if (!SwingUtilities.isEventDispatchThread()) {
339 339
			throw new RuntimeException("No Event Dispatch Thread");
340 340
		}
......
460 460
	 * @throws RuntimeException DOCUMENT ME!
461 461
	 */
462 462
	public void addMenu(PluginClassLoader loader, SkinExtensionType ext,
463
		Menu menu) throws ClassNotFoundException {
463
			Menu menu) throws ClassNotFoundException {
464 464
		if (!SwingUtilities.isEventDispatchThread()) {
465 465
			throw new RuntimeException("No Event Dispatch Thread");
466 466
		}
......
468 468
		JMenu menuPadre = createMenuAncestors(menu, loader);
469 469

  
470 470
		//Se registra y a�ade el menu
471
        /* String[] aux = menu.getText().split("/");
471
		/* String[] aux = menu.getText().split("/");
472 472

  
473 473
        if (aux.length == 2)
474 474
            if (aux[1].equals("----"))
......
476 476
                menuPadre.addSeparator();
477 477
                return;
478 478
            } */
479
        if (menu.getIs_separator())
480
        {
481
            menuPadre.addSeparator();
482
            return;
483
        }
479
		if (menu.getIs_separator())
480
		{
481
			menuPadre.addSeparator();
482
			return;
483
		}
484 484

  
485 485
		JMenuItem nuevoMenu = createJMenuItem(loader, menu);
486 486
		nuevoMenu.addMouseListener(tooltipListener);
487 487
		nuevoMenu.addActionListener(this);
488 488
		menuPadre.add(nuevoMenu);
489
        controlClass.put(nuevoMenu, loader.loadClass(ext.getClassName()));
489
		controlClass.put(nuevoMenu, loader.loadClass(ext.getClassName()));
490 490
	}
491 491

  
492 492

  
......
504 504

  
505 505
			for (int i=0; i<parentItem.getMenuComponentCount(); i++) {
506 506
				if (parentItem.getMenuComponent(i).getName()!=null // not a JToolBar.Separator
507
					&& parentItem.getMenuComponent(i).getName().compareTo((String)nombres.get(0)) == 0) {
507
						&& parentItem.getMenuComponent(i).getName().compareTo((String)nombres.get(0)) == 0) {
508 508
					nombres.remove(0);
509 509
					if (nombres.isEmpty()) {
510 510
						if (parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem) {
......
685 685
				logger.error(Messages.getString("No_extension_associated_with_this_event_")+ e.getActionCommand());
686 686
			}
687 687
			NotificationManager.addError(Messages.getString(
688
					"MDIFrame.Error_no_capturado_por_el_usuario"), t);
688
			"MDIFrame.Error_no_capturado_por_el_usuario"), t);
689 689
		}
690 690

  
691 691
		enableControls();
......
775 775
		if (menu.getMnemonic() != null) {
776 776
			if (menu.getMnemonic().length() != 1) {
777 777
				throw new RuntimeException(
778
					"Mnemonic must be 1 character length");
778
				"Mnemonic must be 1 character length");
779 779
			}
780 780

  
781 781
			nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic().charAt(0)));
......
855 855
	 * @param loader
856 856
	 */
857 857
	public void addPopupMenuListener(String popupName, Component c,
858
		ActionListener listener, PluginClassLoader loader) {
858
			ActionListener listener, PluginClassLoader loader) {
859 859
		final String name = getName(popupName, loader);
860 860

  
861 861
		JPopupMenu menu = (JPopupMenu) popupMap.get(name);
......
871 871
		}
872 872

  
873 873
		c.addMouseListener(new MouseAdapter() {
874
				public void mousePressed(MouseEvent e) {
875
					if (e.isPopupTrigger()) {
876
						showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
877
					}
874
			public void mousePressed(MouseEvent e) {
875
				if (e.isPopupTrigger()) {
876
					showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
878 877
				}
878
			}
879 879

  
880
				public void mouseReleased(MouseEvent e) {
881
					if (e.isPopupTrigger()) {
882
						showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
883
					}
880
			public void mouseReleased(MouseEvent e) {
881
				if (e.isPopupTrigger()) {
882
					showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
884 883
				}
885
			});
884
			}
885
		});
886 886
	}
887 887

  
888 888
	/**
......
934 934
				}
935 935
			} catch (Throwable e1) {
936 936
				NotificationManager.addError(Messages.getString(
937
						"MDIFrame.Error_no_capturado_por_el_usuario"), e1);
937
				"MDIFrame.Error_no_capturado_por_el_usuario"), e1);
938 938
				estadoExtensiones.put(ext, Boolean.FALSE);
939 939
			}
940 940
		}
......
947 947

  
948 948
			try {
949 949
				com.iver.andami.plugins.IExtension ext = (com.iver.andami.plugins.IExtension) classesExtensions.get((Class) controlClass.get(
950
							control));
950
						control));
951 951
				boolean enabled = ((Boolean) estadoExtensiones.get(ext)).booleanValue();
952 952
				boolean visible = ((Boolean) visibilidadExtensiones.get(ext)).booleanValue();
953 953
				control.setEnabled(enabled);
......
962 962
		for (int i = 0; i < menuBar.getMenuCount(); i++) {
963 963
			MenuElement menu = menuBar.getMenu(i);
964 964
			hideMenus(menu);
965
			hideSeparators(menu);
965 966
		}
966 967

  
967 968
		// hide the toolbars that don't contain any visible tool
......
1049 1050
	}
1050 1051

  
1051 1052
	/**
1053
	 * Recurse through all menu elements and make sure there are no
1054
	 * redundant separators.
1055
	 * This method will make sure that a separator only becomes visible
1056
	 * if at least one visible non-separator menu entry preceeded it.
1057
	 */ 
1058
	private void hideSeparators(MenuElement menu) {
1059

  
1060
		// flag that indicates whether a separator is to be displayed or not
1061
		boolean	allowSeparator;
1062

  
1063
		if (menu instanceof JMenu) {
1064
			allowSeparator = false; // separator not allowed as very first menu item
1065
			Component[] comps = ((JMenu)menu).getMenuComponents(); 
1066
			for (int i=0; i < comps.length; i++) {
1067
				if (comps[i] instanceof JSeparator){
1068
					// got a separator: display only if allowed at this position 
1069
					if (allowSeparator == true) {
1070
						// look at all successive menu entries to make sure that at least one 
1071
						// is visible and not a separator (otherwise, this separator would 
1072
						// be the last visible item in this menu) -- we don't want that 
1073
						comps[i].setVisible( false );
1074
						for ( int j = i; j < comps.length; j ++ ) {
1075
							if ( !(comps[j] instanceof JSeparator)) {
1076
								if ( comps[j].isVisible() ) {
1077
									comps[i].setVisible(true); // display separator! 
1078
									break;
1079
								}
1080
							}
1081
						}
1082
					} else {
1083
						comps[i].setVisible(false);
1084
					} allowSeparator = false; // separator is not allowed right after another separator
1085
				}else{
1086
					if (comps[i] instanceof JMenu) { 
1087
						// got a submenu: recurse through it
1088
						hideSeparators ( ((MenuElement)comps[i]) ); if ( comps[i].isVisible() ) {
1089
							allowSeparator = true; // separators are OK after visible submenus
1090
						}
1091
					} else {
1092
						if ( comps[i].isVisible() ) {
1093
							allowSeparator = true; // separators are OK after regular, visible entries
1094
						}
1095
					}
1096
				}
1097
			}
1098
		}
1099
	}
1100

  
1101
	/**
1052 1102
	 * Muestra la memoria consumida por el programa
1053 1103
	 */
1054 1104
	private void showMemory() {
......
1075 1125
		return bEstado;
1076 1126
	}
1077 1127
	/**
1078
     * You can use this function to select the appropiate
1079
     * tool inside the toolbars
1080
     */
1081
    public void setSelectedTool(String actionCommand)
1082
    {
1083
    	setSelectedTool(defaultGroup, actionCommand);
1084
    }
1128
	 * You can use this function to select the appropiate
1129
	 * tool inside the toolbars
1130
	 */
1131
	public void setSelectedTool(String actionCommand)
1132
	{
1133
		setSelectedTool(defaultGroup, actionCommand);
1134
	}
1085 1135

  
1086 1136
	/**
1087
     * You can use this function to select the appropiate
1088
     * tool inside the toolbars
1089
     */
1090
    public void setSelectedTool(String groupName, String actionCommand)
1091
    {
1092
    	ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1093
    	if (group==null)
1094
    		return;
1137
	 * You can use this function to select the appropiate
1138
	 * tool inside the toolbars
1139
	 */
1140
	public void setSelectedTool(String groupName, String actionCommand)
1141
	{
1142
		ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1143
		if (group==null)
1144
			return;
1095 1145

  
1096
    	Enumeration enumeration = group.getElements();
1097
    	while (enumeration.hasMoreElements()) {
1098
    		AbstractButton button = (AbstractButton) enumeration.nextElement();
1099
    		if (button.getActionCommand().equals(actionCommand)) {
1100
    			button.setSelected(true);
1101
    		}
1102
    	}
1146
		Enumeration enumeration = group.getElements();
1147
		while (enumeration.hasMoreElements()) {
1148
			AbstractButton button = (AbstractButton) enumeration.nextElement();
1149
			if (button.getActionCommand().equals(actionCommand)) {
1150
				button.setSelected(true);
1151
			}
1152
		}
1103 1153

  
1104
    	selectedTool.put(groupName, actionCommand);
1105
    }
1154
		selectedTool.put(groupName, actionCommand);
1155
	}
1106 1156

  
1107 1157
	/**
1108
     * You can use this function to select the appropiate
1109
     * tool inside the toolbars
1110
     */
1111
    public void setSelectedTools(HashMap selectedTools)
1112
    {
1113
        selectedTool = selectedTools;
1114
        if (selectedTools==null) return;
1115
    	Iterator groupNames = selectedTools.keySet().iterator();
1116
    	while (groupNames.hasNext()) {
1117
    		try {
1118
    			String groupName = (String) groupNames.next();
1119
    			ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1120
	        	Enumeration enumeration = group.getElements();
1121
	        	String actionCommand = (String) selectedTools.get(groupName);
1122
	        	if (actionCommand==null) continue;
1123
	        	while (enumeration.hasMoreElements()) {
1124
	        		AbstractButton button = (AbstractButton) enumeration.nextElement();
1125
	        		if (button.getActionCommand().equals(actionCommand)) {
1126
	        			button.setSelected(true);
1127
	        		}
1128
	        	}
1129
    		}
1130
    		catch (ClassCastException ex) {
1131
    			logger.error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
1132
    		}
1133
    	}
1134
    }
1158
	 * You can use this function to select the appropiate
1159
	 * tool inside the toolbars
1160
	 */
1161
	public void setSelectedTools(HashMap selectedTools)
1162
	{
1163
		selectedTool = selectedTools;
1164
		if (selectedTools==null) return;
1165
		Iterator groupNames = selectedTools.keySet().iterator();
1166
		while (groupNames.hasNext()) {
1167
			try {
1168
				String groupName = (String) groupNames.next();
1169
				ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1170
				Enumeration enumeration = group.getElements();
1171
				String actionCommand = (String) selectedTools.get(groupName);
1172
				if (actionCommand==null) continue;
1173
				while (enumeration.hasMoreElements()) {
1174
					AbstractButton button = (AbstractButton) enumeration.nextElement();
1175
					if (button.getActionCommand().equals(actionCommand)) {
1176
						button.setSelected(true);
1177
					}
1178
				}
1179
			}
1180
			catch (ClassCastException ex) {
1181
				logger.error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
1182
			}
1183
		}
1184
	}
1135 1185

  
1136 1186
	/**
1137 1187
	 * DOCUMENT ME!
......
1178 1228
	 * 		java.awt.event.ActionListener, PluginClassLoader)
1179 1229
	 */
1180 1230
	public void addMenu(Menu menu, ActionListener listener,
1181
		PluginClassLoader loader) {
1231
			PluginClassLoader loader) {
1182 1232
		JMenu menuPadre = createMenuAncestors(menu, loader);
1183 1233

  
1184 1234
		//Se registra y a�ade el menu
......
1195 1245
	 * 		String, com.iver.andami.plugins.PluginClassLoader)
1196 1246
	 */
1197 1247
	public void changeMenuName(String[] menu, String newName,
1198
		PluginClassLoader loader) {
1248
			PluginClassLoader loader) {
1199 1249

  
1200 1250
		ArrayList menuList = new ArrayList();
1201 1251
		for (int i = 0; i < menu.length; i++) {
......
1293 1343
		this.titlePrefix = titlePrefix;
1294 1344
	}
1295 1345

  
1296
    public HashMap getSelectedTools() {
1297
        return selectedTool;
1298
    }
1346
	public HashMap getSelectedTools() {
1347
		return selectedTool;
1348
	}
1299 1349

  
1300
    public HashMap getInitialSelectedTools() {
1301
        return initialSelectedTools;
1302
    }
1350
	public HashMap getInitialSelectedTools() {
1351
		return initialSelectedTools;
1352
	}
1303 1353

  
1304 1354

  
1305
    /**
1306
     * Get a previously added JComponent by name. For example
1307
     * you can use it if you need to obtain a JToolBar to
1308
     * add some customized component.
1309
     * @param name
1310
     * @return the JComponent or null if none has been found
1311
     */
1312
    public JComponent getComponentByName(String name)
1313
    {
1314
        Iterator e = controlClass.keySet().iterator();
1355
	/**
1356
	 * Get a previously added JComponent by name. For example
1357
	 * you can use it if you need to obtain a JToolBar to
1358
	 * add some customized component.
1359
	 * @param name
1360
	 * @return the JComponent or null if none has been found
1361
	 */
1362
	public JComponent getComponentByName(String name)
1363
	{
1364
		Iterator e = controlClass.keySet().iterator();
1315 1365

  
1316
        while (e.hasNext()) {
1317
            JComponent control = (JComponent) e.next();
1318
            String nameCtrl = control.getName();
1319
            if (nameCtrl != null)
1320
            {
1321
            	if (nameCtrl.compareTo(name) == 0)
1322
            		return control;
1323
            }
1324
        }
1325
        Iterator it = toolBarMap.values().iterator();
1326
        while (it.hasNext()) {
1327
            SelectableToolBar t = (SelectableToolBar) it.next();
1328
            String nameCtrl = t.getName();
1329
            if (nameCtrl != null)
1330
            	if (nameCtrl.compareTo(name) == 0)
1331
            		return t;
1366
		while (e.hasNext()) {
1367
			JComponent control = (JComponent) e.next();
1368
			String nameCtrl = control.getName();
1369
			if (nameCtrl != null)
1370
			{
1371
				if (nameCtrl.compareTo(name) == 0)
1372
					return control;
1373
			}
1374
		}
1375
		Iterator it = toolBarMap.values().iterator();
1376
		while (it.hasNext()) {
1377
			SelectableToolBar t = (SelectableToolBar) it.next();
1378
			String nameCtrl = t.getName();
1379
			if (nameCtrl != null)
1380
				if (nameCtrl.compareTo(name) == 0)
1381
					return t;
1332 1382

  
1333
        }
1383
		}
1334 1384

  
1335
        return null;
1336
    }
1385
		return null;
1386
	}
1337 1387

  
1338
    public SelectableToolBar[] getToolbars() {
1339
    	return (SelectableToolBar[]) toolBarMap.values().toArray(new SelectableToolBar[0]);
1340
    }
1388
	public SelectableToolBar[] getToolbars() {
1389
		return (SelectableToolBar[]) toolBarMap.values().toArray(new SelectableToolBar[0]);
1390
	}
1341 1391

  
1342
    public boolean getToolbarVisibility(String name) {
1343
    	JComponent component = PluginServices.getMainFrame().getComponentByName(name);
1392
	public boolean getToolbarVisibility(String name) {
1393
		JComponent component = PluginServices.getMainFrame().getComponentByName(name);
1344 1394
		if (component!=null && component instanceof SelectableToolBar) {
1345 1395
			SelectableToolBar toolBar = (SelectableToolBar) component;
1346 1396
			return toolBar.getAndamiVisibility();
1347 1397
		}
1348 1398
		return false;
1349
    }
1399
	}
1350 1400

  
1351
    public boolean setToolbarVisibility(String name, boolean visibility) {
1352
    	JComponent component = PluginServices.getMainFrame().getComponentByName(name);
1401
	public boolean setToolbarVisibility(String name, boolean visibility) {
1402
		JComponent component = PluginServices.getMainFrame().getComponentByName(name);
1353 1403
		if (component!=null && component instanceof SelectableToolBar) {
1354 1404
			SelectableToolBar toolBar = (SelectableToolBar) component;
1355 1405
			boolean oldVisibility = toolBar.getAndamiVisibility();
......
1358 1408
			return oldVisibility;
1359 1409
		}
1360 1410
		return false;
1361
    }
1411
	}
1362 1412

  
1363
    public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1364
    	ArrayList menu = new ArrayList();
1365
    	for (int i=0; i<menuPath.length; i++)
1366
    		menu.add(menuPath[i]);
1367
    	return getMenu(menu, menuBar);
1368
    }
1413
	public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1414
		ArrayList menu = new ArrayList();
1415
		for (int i=0; i<menuPath.length; i++)
1416
			menu.add(menuPath[i]);
1417
		return getMenu(menu, menuBar);
1418
	}
1369 1419
}

Also available in: Unified diff