Revision 46673
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/mdiFrame/MDIFrame.java | ||
---|---|---|
50 | 50 |
import java.util.NoSuchElementException; |
51 | 51 |
import java.util.StringTokenizer; |
52 | 52 |
import java.util.Vector; |
53 |
|
|
54 | 53 |
import javax.swing.AbstractButton; |
55 | 54 |
import javax.swing.ButtonGroup; |
56 | 55 |
import javax.swing.ImageIcon; |
... | ... | |
72 | 71 |
import javax.swing.filechooser.FileFilter; |
73 | 72 |
import org.apache.commons.lang3.StringUtils; |
74 | 73 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
75 |
|
|
76 | 74 |
import org.gvsig.andami.IconThemeHelper; |
77 | 75 |
import org.gvsig.andami.Launcher; |
78 | 76 |
import org.gvsig.andami.PluginServices; |
... | ... | |
81 | 79 |
import org.gvsig.andami.actioninfo.ActionInfo; |
82 | 80 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
83 | 81 |
import org.gvsig.andami.actioninfo.ActionInfoStatusCache; |
84 |
import org.gvsig.andami.messages.Messages; |
|
85 | 82 |
import org.gvsig.andami.plugins.ExtensionDecorator; |
86 | 83 |
import org.gvsig.andami.plugins.IExtension; |
87 | 84 |
import org.gvsig.andami.plugins.PluginClassLoader; |
... | ... | |
348 | 345 |
} |
349 | 346 |
return; |
350 | 347 |
} |
348 |
|
|
349 |
ButtonGroup group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup()); |
|
350 |
if ( group == null ) { |
|
351 |
group = new ButtonGroup(); |
|
352 |
buttonGroupMap.put(selectableTool.getGroup(), group); |
|
353 |
} |
|
354 |
|
|
351 | 355 |
String name = toolBar.getName(); |
352 | 356 |
SelectableToolBar jtb = getToolBar(name, loader.getPluginName()); |
353 | 357 |
if( selectableTool.getDropDownGroup()!=null ) { |
... | ... | |
355 | 359 |
ActionInfo action = actionManager.getAction(selectableTool.getName()); |
356 | 360 |
if( action!=null ) { |
357 | 361 |
DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(selectableTool.getDropDownGroup()); |
358 |
if( dropDownButton==null ) { |
|
362 |
if (dropDownButton == null) { |
|
363 |
ToggleButtonModel buttonModel = new ToggleButtonModel(); |
|
359 | 364 |
dropDownButton = new DropDownButton(); |
365 |
dropDownButton.setModel(buttonModel); |
|
360 | 366 |
dropDownButton.setName(selectableTool.getDropDownGroup()); |
361 |
jtb.add(dropDownButton); |
|
367 |
dropDownButton.setMargin(new Insets(2, 2, 2, 2)); |
|
368 |
jtb.addButton(group, dropDownButton); |
|
362 | 369 |
addControl(dropDownButton); |
370 |
buttonModel.setGroupName(selectableTool.getGroup()); |
|
371 |
|
|
363 | 372 |
} |
364 | 373 |
dropDownButton.add(actionManager.getTranslated(action)); |
365 | 374 |
} |
... | ... | |
386 | 395 |
btn.setEnabled(false); |
387 | 396 |
btn.setVisible(false); |
388 | 397 |
|
389 |
ButtonGroup group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup()); |
|
390 |
if ( group == null ) { |
|
391 |
group = new ButtonGroup(); |
|
392 |
buttonGroupMap.put(selectableTool.getGroup(), group); |
|
393 |
} |
|
394 |
|
|
398 |
// ButtonGroup group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
|
|
399 |
// if ( group == null ) {
|
|
400 |
// group = new ButtonGroup();
|
|
401 |
// buttonGroupMap.put(selectableTool.getGroup(), group);
|
|
402 |
// }
|
|
403 |
// |
|
395 | 404 |
jtb.addButton(group, btn); |
396 | 405 |
|
397 | 406 |
buttonModel.setGroupName(selectableTool.getGroup()); |
... | ... | |
1644 | 1653 |
Enumeration enumeration = group.getElements(); |
1645 | 1654 |
while ( enumeration.hasMoreElements() ) { |
1646 | 1655 |
AbstractButton button = (AbstractButton) enumeration.nextElement(); |
1647 |
if ( button.getActionCommand().equals(actionCommand) ) { |
|
1648 |
button.setSelected(true); |
|
1656 |
if(button instanceof DropDownButton){ |
|
1657 |
((DropDownButton)button).setSelected(actionCommand, true); |
|
1658 |
} else { |
|
1659 |
if ( button.getActionCommand().equals(actionCommand) ) { |
|
1660 |
button.setSelected(true); |
|
1661 |
} |
|
1649 | 1662 |
} |
1650 | 1663 |
} |
1651 | 1664 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/mdiFrame/DropDownButton.java | ||
---|---|---|
1 | 1 |
package org.gvsig.andami.ui.mdiFrame; |
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Point;
|
|
4 |
import java.awt.Insets;
|
|
5 | 5 |
import java.awt.event.ActionEvent; |
6 | 6 |
import java.awt.event.ActionListener; |
7 | 7 |
import java.awt.event.FocusEvent; |
... | ... | |
14 | 14 |
import javax.swing.JButton; |
15 | 15 |
import javax.swing.JMenuItem; |
16 | 16 |
import javax.swing.JPopupMenu; |
17 |
import javax.swing.JToggleButton; |
|
17 | 18 |
import javax.swing.SwingConstants; |
19 |
import javax.swing.UIManager; |
|
18 | 20 |
import javax.swing.plaf.basic.BasicArrowButton; |
19 | 21 |
import org.apache.commons.lang3.BooleanUtils; |
22 |
import org.apache.commons.lang3.StringUtils; |
|
23 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
|
20 | 24 |
|
21 |
public class DropDownButton extends JButton { |
|
25 |
public class DropDownButton extends JToggleButton {
|
|
22 | 26 |
|
23 | 27 |
private final List<Action> actions = new ArrayList<Action>(); |
24 | 28 |
private Action currentAction = null; |
25 |
private final JButton mainButton; |
|
29 |
private final JToggleButton mainButton;
|
|
26 | 30 |
private final JButton dropDownButton; |
27 | 31 |
private JPopupMenu dropDownMenu; |
28 | 32 |
private boolean showText = false; |
29 | 33 |
|
30 | 34 |
public DropDownButton() { |
31 | 35 |
super(); |
32 |
this.mainButton = new JButton(); |
|
36 |
this.mainButton = new JToggleButton(); |
|
37 |
this.mainButton.setOpaque(true); |
|
33 | 38 |
this.dropDownMenu = null; |
34 | 39 |
|
35 | 40 |
this.dropDownButton = new BasicArrowButton(SwingConstants.SOUTH); |
... | ... | |
45 | 50 |
this.setLayout(new BorderLayout()); |
46 | 51 |
this.add(mainButton, BorderLayout.CENTER); |
47 | 52 |
this.add(dropDownButton, BorderLayout.EAST); |
53 |
this.mainButton.setMargin(new Insets(0, 2, 0, 2)); |
|
54 |
this.mainButton.setBackground(UIManager.getColor(ToolsSwingManager.COLOR_PANEL_BACKGROUND)); |
|
55 |
this.dropDownButton.setBackground(UIManager.getColor(ToolsSwingManager.COLOR_PANEL_BACKGROUND)); |
|
56 |
this.setBackground(UIManager.getColor(ToolsSwingManager.COLOR_PANEL_BACKGROUND)); |
|
57 |
|
|
58 |
this.mainButton.setFocusable(false); |
|
59 |
this.setFocusable(false); |
|
48 | 60 |
|
61 |
|
|
49 | 62 |
this.mainButton.addActionListener(new ActionListener() { |
50 | 63 |
|
51 | 64 |
public void actionPerformed(ActionEvent ae) { |
... | ... | |
80 | 93 |
} |
81 | 94 |
|
82 | 95 |
public void updateMainButton(){ |
96 |
if(currentAction != null && currentAction.isEnabled()){ |
|
97 |
return; |
|
98 |
} |
|
83 | 99 |
for (Action action : actions) { |
84 | 100 |
if (action.isEnabled()){ |
85 | 101 |
setMainButton(action); |
... | ... | |
143 | 159 |
} |
144 | 160 |
} |
145 | 161 |
|
162 |
void setSelected(String actionCommand, boolean b) { |
|
163 |
for (Action action : actions) { |
|
164 |
String s = (String) action.getValue(Action.ACTION_COMMAND_KEY); |
|
165 |
if(StringUtils.equals(s, actionCommand)){ |
|
166 |
setMainButton(action); |
|
167 |
if (action.isEnabled()){ |
|
168 |
this.mainButton.setSelected(b); |
|
169 |
this.setSelected(b); |
|
170 |
} |
|
171 |
return; |
|
172 |
} |
|
173 |
} |
|
174 |
this.mainButton.setSelected(false); |
|
175 |
} |
|
176 |
|
|
146 | 177 |
private class MyItemActionListener implements ActionListener { |
147 | 178 |
private Action action = null; |
148 | 179 |
MyItemActionListener(Action action) { |
... | ... | |
159 | 190 |
currentAction = action; |
160 | 191 |
dropDownMenu.setVisible(false); |
161 | 192 |
mainButton.setEnabled(true); |
193 |
setActionCommand((String) currentAction.getValue(Action.ACTION_COMMAND_KEY)); |
|
162 | 194 |
action.actionPerformed(ae); |
163 | 195 |
} |
164 | 196 |
} |
Also available in: Unified diff