Revision 1200 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/composer/DefaultJScriptingComposer.java
DefaultJScriptingComposer.java | ||
---|---|---|
36 | 36 |
import javax.swing.JMenuItem; |
37 | 37 |
import javax.swing.JOptionPane; |
38 | 38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JPopupMenu; |
|
39 | 40 |
import javax.swing.JScrollPane; |
40 | 41 |
import javax.swing.JSplitPane; |
41 | 42 |
import javax.swing.JTabbedPane; |
... | ... | |
114 | 115 |
import org.slf4j.Logger; |
115 | 116 |
import org.slf4j.LoggerFactory; |
116 | 117 |
|
118 |
@SuppressWarnings("UseSpecificCatch") |
|
117 | 119 |
public class DefaultJScriptingComposer extends JPanel implements JScriptingComposer, Observer, ActionListener { |
118 | 120 |
|
119 | 121 |
/** |
... | ... | |
724 | 726 |
@Override |
725 | 727 |
public void actionPerformed(ActionEvent e) { |
726 | 728 |
try { |
727 |
ScriptingUnit selectedItem = getLauncherSelectedScript();
|
|
729 |
ScriptingUnit selectedItem = getLauncherSelectedUnit();
|
|
728 | 730 |
if( uimanager.hasEditor(selectedItem) ) { |
729 | 731 |
scriptEdit(selectedItem); |
730 | 732 |
} |
... | ... | |
768 | 770 |
@Override |
769 | 771 |
public void actionPerformed(ActionEvent e) { |
770 | 772 |
try { |
771 |
scriptRename(getLauncherSelectedScript());
|
|
773 |
scriptRename(getLauncherSelectedUnit());
|
|
772 | 774 |
} catch (Exception e1) { |
773 | 775 |
LOGGER.warn("Can't rename document", e1); |
774 | 776 |
} |
... | ... | |
790 | 792 |
@Override |
791 | 793 |
public void actionPerformed(ActionEvent e) { |
792 | 794 |
try { |
793 |
scriptMove(getLauncherSelectedScript());
|
|
795 |
scriptMove(getLauncherSelectedUnit());
|
|
794 | 796 |
} catch (Exception e1) { |
795 | 797 |
LOGGER.warn("Can't move document", e1); |
796 | 798 |
} |
... | ... | |
812 | 814 |
@Override |
813 | 815 |
public void actionPerformed(ActionEvent e) { |
814 | 816 |
try { |
815 |
scriptDelete(getLauncherSelectedScript(), false);
|
|
817 |
scriptDelete(getLauncherSelectedUnit(), false);
|
|
816 | 818 |
} catch (Exception e1) { |
817 | 819 |
LOGGER.warn("Can't delete document", e1); |
818 | 820 |
} |
... | ... | |
1300 | 1302 |
* |
1301 | 1303 |
* @return Selected ScriptingUnit on the tree |
1302 | 1304 |
*/ |
1303 |
private ScriptingUnit getLauncherSelectedScript() {
|
|
1305 |
public ScriptingUnit getLauncherSelectedUnit() {
|
|
1304 | 1306 |
JScriptingBrowser browser = this.getCurrentBrowser(); |
1305 | 1307 |
ScriptingUnit unit = browser.getSelectedNode(); |
1306 | 1308 |
return unit; |
1307 | 1309 |
} |
1308 | 1310 |
|
1311 |
public void msgbox(String title, String msg) { |
|
1312 |
msgbox(title, msg, JOptionPane.INFORMATION_MESSAGE); |
|
1313 |
} |
|
1314 |
|
|
1315 |
public void msgbox(final String title, final String msg, final int type) { |
|
1316 |
if( SwingUtilities.isEventDispatchThread() ) { |
|
1317 |
try { |
|
1318 |
SwingUtilities.invokeAndWait(() -> { |
|
1319 |
msgbox(title, msg, type); |
|
1320 |
}); |
|
1321 |
} catch (Exception ex) { |
|
1322 |
} |
|
1323 |
return; |
|
1324 |
} |
|
1325 |
JOptionPane.showMessageDialog(this, msg, title, type); |
|
1326 |
} |
|
1327 |
|
|
1309 | 1328 |
private JScriptingBrowser getCurrentBrowser() { |
1310 | 1329 |
JScriptingLauncher launcher = this.getProjects(); |
1311 | 1330 |
JScriptingBrowser browser = launcher.getSelectedBrowser(); |
... | ... | |
1964 | 1983 |
private boolean changed = false; |
1965 | 1984 |
private final Font fontNormal; |
1966 | 1985 |
private final Font fontBold; |
1986 |
private JPopupMenu popup; |
|
1967 | 1987 |
|
1968 | 1988 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
1969 | 1989 |
public TabTitleComponent(String title, final ActionListener onclose) { |
... | ... | |
1997 | 2017 |
this.setLayout(new BorderLayout()); |
1998 | 2018 |
this.add(this.label, BorderLayout.CENTER); |
1999 | 2019 |
this.add(this.button, BorderLayout.EAST); |
2020 |
|
|
2021 |
this.popup = null; |
|
2022 |
this.label.addMouseListener(new MouseAdapter() { |
|
2023 |
@Override |
|
2024 |
public void mouseClicked(MouseEvent e) { |
|
2025 |
if( e.isPopupTrigger() || e.getButton()==MouseEvent.BUTTON3) { |
|
2026 |
if( popup!=null ) { |
|
2027 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
|
2028 |
} |
|
2029 |
} else { |
|
2030 |
int index = indexOfTabComponent(TabTitleComponent.this); |
|
2031 |
setSelectedIndex(index); |
|
2032 |
} |
|
2033 |
} |
|
2034 |
}); |
|
2000 | 2035 |
} |
2001 | 2036 |
|
2002 | 2037 |
public void setTitle(String title) { |
... | ... | |
2019 | 2054 |
public boolean isChanged() { |
2020 | 2055 |
return this.changed; |
2021 | 2056 |
} |
2057 |
|
|
2058 |
@Override |
|
2059 |
public void setComponentPopupMenu(final JPopupMenu popup) { |
|
2060 |
// Asignarle un popup menu consume los eventos y no cambia de pesta?a. |
|
2061 |
// this.label.setComponentPopupMenu(popup); |
|
2062 |
this.popup = popup; |
|
2063 |
} |
|
2022 | 2064 |
} |
2023 | 2065 |
|
2024 | 2066 |
public JTabbedPaneClosable(ScriptingUIManager uimanager) { |
... | ... | |
2032 | 2074 |
TabTitleComponent title = (TabTitleComponent) this.getTabComponentAt(index); |
2033 | 2075 |
if (title == null) { |
2034 | 2076 |
return null; |
2035 |
} |
|
2077 |
}
|
|
2036 | 2078 |
return title.getTitle(); |
2037 | 2079 |
} |
2038 | 2080 |
|
... | ... | |
2045 | 2087 |
@Override |
2046 | 2088 |
public void addTab(String title, java.awt.Component component) { |
2047 | 2089 |
super.addTab(null, component); |
2048 |
int index = getTabCount() - 1; |
|
2090 |
final int index = getTabCount() - 1;
|
|
2049 | 2091 |
TabTitleComponent tabcomponent = new TabTitleComponent(title, new ActionListener() { |
2050 | 2092 |
|
2051 | 2093 |
@Override |
... | ... | |
2429 | 2471 |
public void select() { |
2430 | 2472 |
DefaultDock.this.select(this.getId()); |
2431 | 2473 |
} |
2474 |
|
|
2475 |
@Override |
|
2476 |
public void moveto(String position) { |
|
2477 |
switch(position) { |
|
2478 |
case Dock.DOCK_LEFT: |
|
2479 |
add(this.getId(), this.getTitle(), this.getComponent(), Dock.DOCK_LEFT); |
|
2480 |
break; |
|
2481 |
case Dock.DOCK_CENTER: |
|
2482 |
add(this.getId(), this.getTitle(), this.getComponent(), Dock.DOCK_CENTER); |
|
2483 |
break; |
|
2484 |
case Dock.DOCK_BOTTOM: |
|
2485 |
default: |
|
2486 |
add(this.getId(), this.getTitle(), this.getComponent(), Dock.DOCK_BOTTOM); |
|
2487 |
break; |
|
2488 |
} |
|
2489 |
} |
|
2432 | 2490 |
} |
2433 | 2491 |
|
2434 | 2492 |
private final Map<String, Dock.DockedPanel> panels; |
... | ... | |
2610 | 2668 |
panel = new DefaultDockedPanel(id, title, component, align); |
2611 | 2669 |
this.panels.put(id, panel); |
2612 | 2670 |
tabbedPanel.add(panel.getTitle(), panel.getComponent().asJComponent()); |
2671 |
JComponent tabComponent = (JComponent) tabbedPanel.getTabComponentAt(tabbedPanel.getTabCount()-1); |
|
2672 |
tabComponent.setComponentPopupMenu(this.createDefaultComponentPopupMenu(panel)); |
|
2613 | 2673 |
return panel; |
2614 | 2674 |
} |
2675 |
|
|
2676 |
private JPopupMenu createDefaultComponentPopupMenu(DockedPanel panel) { |
|
2677 |
JPopupMenu menu = new JPopupMenu(); |
|
2678 |
menu.add(createMenuItem("Move to left", (ActionEvent e) -> { |
|
2679 |
panel.moveto(Dock.DOCK_LEFT); |
|
2680 |
})); |
|
2681 |
menu.add(createMenuItem("Move to bottom", (ActionEvent e) -> { |
|
2682 |
panel.moveto(Dock.DOCK_BOTTOM); |
|
2683 |
})); |
|
2684 |
menu.add(createMenuItem("Move to center", (ActionEvent e) -> { |
|
2685 |
panel.moveto(Dock.DOCK_CENTER); |
|
2686 |
})); |
|
2687 |
return menu; |
|
2688 |
} |
|
2689 |
|
|
2690 |
private JMenuItem createMenuItem(String text, ActionListener listener) { |
|
2691 |
JMenuItem item = new JMenuItem(text); |
|
2692 |
item.addActionListener(listener); |
|
2693 |
return item; |
|
2694 |
} |
|
2615 | 2695 |
|
2616 | 2696 |
@Override |
2617 | 2697 |
public void remove(String id) { |
Also available in: Unified diff