Byte-Welt Forum

Zurück   Byte-Welt Forum > Projekte > DockingFrames

DockingFrames DockingFrames An extension of Swing, used to flexibly arrange windows. - Ist eine Erweiterung von Swing, mit der flexibel Panels angeordnet werden können.

Antwort
 
Themen-Optionen Thema durchsuchen
Alt 03.06.2010, 14:39   #1
ley starter
 
Registriert seit: 22.04.2009
Beiträge: 30
ley befindet sich auf einem aufstrebenden Ast
Standard Popup menu on a StackDockStation

Hi,

I'm using eclipse theme and I want to add a popup menu on a StackDockStation.As I implement it the menu is not shown everywhere on this station. It is not shown on the the tab info.

Java Code:
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.FlowLayout;
  4.  
  5. import javax.swing.JButton;
  6. import javax.swing.JComponent;
  7. import javax.swing.JFrame;
  8. import javax.swing.JMenuItem;
  9. import javax.swing.JPanel;
  10. import javax.swing.JPopupMenu;
  11.  
  12. import bibliothek.extension.gui.dock.theme.EclipseTheme;
  13.  
  14. import bibliothek.gui.DockController;
  15. import bibliothek.gui.dock.DefaultDockable;
  16. import bibliothek.gui.dock.StackDockStation;
  17. import bibliothek.gui.dock.station.stack.StackDockComponent;
  18.  
  19.  
  20. public class PopupOnStackDockStation {
  21.  
  22.     public PopupOnStackDockStation() {
  23.         JFrame frame = new JFrame();
  24.         frame.setSize(600, 500);
  25.  
  26.         JPopupMenu popupMenu = new JPopupMenu();
  27.         JMenuItem menu = new JMenuItem("MenuItem");
  28.         popupMenu.add(menu);
  29.  
  30.         DockController controller = new DockController();
  31.         controller.setTheme(new EclipseTheme());
  32.         StackDockStation station = new StackDockStation();
  33.         station.getComponent().setBackground(Color.RED);
  34.         frame.add(station.getComponent(), BorderLayout.CENTER);
  35.         controller.add(station);
  36.  
  37.         for (int i = 0; i < 2; i++) {
  38.             JPanel panel = new JPanel(new FlowLayout());
  39.             panel.add(new JButton("Button"));
  40.             station.drop(new DefaultDockable(panel, "Dockable " + i));
  41.         }
  42.         ((JComponent) ((StackDockComponent) station.getStackComponent()).getComponent()).setComponentPopupMenu(popupMenu);
  43.         frame.setVisible(true);
  44.     }
  45.  
  46.  
  47.     public static void main(String[] args) {
  48.         new PopupOnStackDockStation();
  49.     }
  50. }

Thanks,
ley ist offline   Mit Zitat antworten
Alt 03.06.2010, 18:26   #2
Beni
Moderator
 
Benutzerbild von Beni
 
Registriert seit: 27.08.2006
Beiträge: 571
Beni befindet sich auf einem aufstrebenden Ast
Beni eine Nachricht über Skype™ schicken
Standard AW: Popup menu on a StackDockStation

The MouseEvent gets processed by the Dockables and tabs - if there are any. If I run your code the popup menu appears at some places (right of the tabs). What exactly is your goal with this menu?

Maybe override "getDirectActionOffers" of StackDockStation, this way you can add DockAction's to the children of the station (but there are other, easier ways to get actions onto Dockables, e.g. the ActionGuards).
__________________
Beni ist offline   Mit Zitat antworten
Alt 03.06.2010, 18:40   #3
ley starter
 
Registriert seit: 22.04.2009
Beiträge: 30
ley befindet sich auf einem aufstrebenden Ast
Standard Re: AW: Popup menu on a StackDockStation

Hi Beni,

I want the popup menu to be shown even if I right click on the title of the Dockable. Currently if I right click on the tab with title "Dockable 1" the popup didn't appear, but if I right click on right of the dockable the popup menu appear, as you noticed in the example.

Thanks,
ley ist offline   Mit Zitat antworten
Alt 03.06.2010, 18:55   #4
Beni
Moderator
 
Benutzerbild von Beni
 
Registriert seit: 27.08.2006
Beiträge: 571
Beni befindet sich auf einem aufstrebenden Ast
Beni eine Nachricht über Skype™ schicken
Standard Re: Popup menu on a StackDockStation

An ActionGuard and a modified DockAction can do that:

Java Code:
  1. package test;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.FlowLayout;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10.  
  11. import bibliothek.extension.gui.dock.theme.EclipseTheme;
  12. import bibliothek.gui.DockController;
  13. import bibliothek.gui.Dockable;
  14. import bibliothek.gui.dock.DefaultDockable;
  15. import bibliothek.gui.dock.StackDockStation;
  16. import bibliothek.gui.dock.action.ActionGuard;
  17. import bibliothek.gui.dock.action.DefaultDockActionSource;
  18. import bibliothek.gui.dock.action.DockActionSource;
  19. import bibliothek.gui.dock.action.actions.SimpleButtonAction;
  20. import bibliothek.gui.dock.action.view.ActionViewConverter;
  21. import bibliothek.gui.dock.action.view.ViewTarget;
  22.  
  23. public class Dock9 {
  24.  
  25.     public static void main(String[] args) {
  26.         JFrame frame = new JFrame();
  27.         frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  28.         frame.setSize(600, 500);
  29.  
  30.         DockController controller = new DockController();
  31.         controller.addActionGuard( new MenuGuard() );
  32.        
  33.         controller.setTheme(new EclipseTheme());
  34.         StackDockStation station = new StackDockStation();
  35.         station.getComponent().setBackground(Color.RED);
  36.         frame.add(station.getComponent(), BorderLayout.CENTER);
  37.         controller.add(station);
  38.  
  39.         for (int i = 0; i < 2; i++) {
  40.             JPanel panel = new JPanel(new FlowLayout());
  41.             panel.add(new JButton("Button"));
  42.             station.drop(new DefaultDockable(panel, "Dockable " + i));
  43.         }
  44.        
  45.         frame.setVisible(true);
  46.     }
  47.    
  48.     private static class MenuGuard implements ActionGuard{
  49.         private DockActionSource source;
  50.        
  51.         public MenuGuard(){
  52.             source = new DefaultDockActionSource( new MenuItem( "alpha" ), new MenuItem( "beta" ) );
  53.         }
  54.        
  55.         @Override
  56.         public DockActionSource getSource( Dockable dockable ){
  57.             return source;
  58.         }
  59.  
  60.         @Override
  61.         public boolean react( Dockable dockable ){
  62.             return dockable.getDockParent() instanceof StackDockStation || dockable instanceof StackDockStation;
  63.         }
  64.     }
  65.    
  66.     private static class MenuItem extends SimpleButtonAction{
  67.         public MenuItem( String text ){
  68.             setText( text );
  69.         }
  70.        
  71.         @Override
  72.         public <V> V createView( ViewTarget<V> target, ActionViewConverter converter, Dockable dockable ){
  73.             if( target == ViewTarget.MENU || target == ViewTarget.DROP_DOWN ){
  74.                 return super.createView( target, converter, dockable );
  75.             }
  76.             else{
  77.                 return null;
  78.             }
  79.         }
  80.     }
  81. }
__________________
Beni ist offline   Mit Zitat antworten
Alt 10.06.2010, 10:51   #5
ley starter
 
Registriert seit: 22.04.2009
Beiträge: 30
ley befindet sich auf einem aufstrebenden Ast
Standard Re: Popup menu on a StackDockStation

Hi,

Thank you for your answer
In my case, I have multiple "StackDockStation" and on each station I have a different menu.

Before upgrading to version 1.0.8, I was able to set a popup menu on all the "StackDockStation" by adding a popup menu on
Java Code:
  1. stackDockStation.getStackComponent();
.

I was unable to set a popup menu on the whole "StackDockStation" in version 1.0.8 after the tab mechanism has been reimplemented
ley ist offline   Mit Zitat antworten
Alt 10.06.2010, 19:52   #6
Beni
Moderator
 
Benutzerbild von Beni
 
Registriert seit: 27.08.2006
Beiträge: 571
Beni befindet sich auf einem aufstrebenden Ast
Beni eine Nachricht über Skype™ schicken
Standard Re: Popup menu on a StackDockStation

In the current version panels/components can get replaced any time. Keeping track of some popup-menu, repositioning it when necessary or forward events to it, would be hard. And since there is already a mechanism that can show popup menus (including any custom JComponent, sub-menus, etc..), I don't see the point in supporting "old style" popup-menus.

If you have a lot of popup-menus already written, I can offer you a converter from popup-menu to DockActions. Unfortunatelly the menu will be destroyed in the process, I hope you can easily create new ones.

Java Code:
  1. package test;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.FlowLayout;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JComponent;
  10. import javax.swing.JFrame;
  11. import javax.swing.JPanel;
  12. import javax.swing.JPopupMenu;
  13.  
  14. import bibliothek.extension.gui.dock.theme.EclipseTheme;
  15. import bibliothek.gui.DockController;
  16. import bibliothek.gui.Dockable;
  17. import bibliothek.gui.dock.DefaultDockable;
  18. import bibliothek.gui.dock.StackDockStation;
  19. import bibliothek.gui.dock.action.ActionGuard;
  20. import bibliothek.gui.dock.action.DefaultDockActionSource;
  21. import bibliothek.gui.dock.action.DockAction;
  22. import bibliothek.gui.dock.action.DockActionSource;
  23. import bibliothek.gui.dock.action.view.ActionViewConverter;
  24. import bibliothek.gui.dock.action.view.ViewTarget;
  25. import bibliothek.gui.dock.themes.basic.action.menu.MenuViewItem;
  26.  
  27. public class Dock11 {
  28.  
  29.     public static void main(String[] args) {
  30.         JFrame frame = new JFrame();
  31.         frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  32.         frame.setSize(600, 500);
  33.  
  34.         DockController controller = new DockController();
  35.         controller.addActionGuard( new MenuGuard() );
  36.        
  37.         controller.setTheme(new EclipseTheme());
  38.         StackDockStation station = new StackDockStation();
  39.        
  40.         station.getComponent().setBackground(Color.RED);
  41.         frame.add(station.getComponent(), BorderLayout.CENTER);
  42.         controller.add(station);
  43.  
  44.         for (int i = 0; i < 2; i++) {
  45.             JPanel panel = new JPanel(new FlowLayout());
  46.             panel.add(new JButton("Button"));
  47.             station.drop(new DefaultDockable(panel, "Dockable " + i));
  48.         }
  49.        
  50.         frame.setVisible(true);
  51.     }
  52.    
  53.     public static JPopupMenu getPopupMenu(StackDockStation station){
  54.         JPopupMenu menu = new JPopupMenu();
  55.         menu.add( "one" );
  56.         menu.add( "two" );
  57.         menu.addSeparator();
  58.         menu.add( "three" );
  59.         return menu;
  60.     }
  61.    
  62.     private static class MenuGuard implements ActionGuard{
  63.         public DockActionSource getSource( Dockable dockable ){
  64.             StackDockStation station;
  65.             if( dockable instanceof StackDockStation ){
  66.                 station = (StackDockStation)dockable;
  67.             }
  68.             else{
  69.                 station = (StackDockStation)dockable.getDockParent();
  70.             }
  71.            
  72.             JPopupMenu menu = getPopupMenu( station );
  73.             DefaultDockActionSource source = new DefaultDockActionSource();
  74.             for( int i = 0, n = menu.getComponentCount(); i<n; i++ ){
  75.                 source.add( new MenuItem( (JComponent)menu.getComponent( i ) ) );
  76.             }
  77.             return source;
  78.         }
  79.  
  80.         public boolean react( Dockable dockable ){
  81.             return dockable.getDockParent() instanceof StackDockStation || dockable instanceof StackDockStation;
  82.         }
  83.     }
  84.    
  85.     private static class MenuItem implements DockAction{
  86.         private JComponent item;
  87.        
  88.         public MenuItem( JComponent item ){
  89.             this.item = item;
  90.         }
  91.        
  92.         @Override
  93.         public void bind( Dockable dockable ){
  94.             // ignore  
  95.         }
  96.        
  97.         @Override
  98.         public boolean trigger( Dockable dockable ){
  99.             // ignore
  100.             return false;
  101.         }
  102.        
  103.         @Override
  104.         public void unbind( Dockable dockable ){
  105.             // ignore  
  106.         }
  107.        
  108.         @SuppressWarnings("unchecked")
  109.         @Override
  110.         public <V> V createView( ViewTarget<V> target, ActionViewConverter converter, Dockable dockable ){
  111.             if( target == ViewTarget.MENU ){
  112.                 return (V)new MenuViewItem<JComponent>() {
  113.                     public void addActionListener( ActionListener listener ){
  114.                         // ignore
  115.                     }
  116.  
  117.                     public void removeActionListener( ActionListener listener ){
  118.                         // ignore
  119.                     }
  120.  
  121.                     public void bind(){
  122.                         // ignore
  123.                     }
  124.  
  125.                     public DockAction getAction(){
  126.                         return MenuItem.this;
  127.                     }
  128.  
  129.                     public JComponent getItem(){
  130.                         return item;
  131.                     }
  132.  
  133.                     public void unbind(){
  134.                         // ignore
  135.                     }
  136.                 };
  137.             }
  138.             else{
  139.                 return null;
  140.             }
  141.         }
  142.     }
  143. }
__________________
Beni ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Stichworte
-


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche

Forumregeln
Es ist Ihnen erlaubt, neue Themen zu verfassen.
Es ist Ihnen erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
StackDockStation displays the title and icons of its dockable by default ley DockingFrames 4 13.04.2010 15:39
StackDockStation not working properly with SecureDockControllerFactory ley DockingFrames 2 13.04.2010 14:45
Tab right-click menu? endho DockingFrames 3 12.04.2010 19:58
Questions to Layout (Menu) and Saving the Layout PeterM DockingFrames 3 31.03.2010 17:40
Ubuntu Blog auf Deutsch - System Menu Icons anzeigen RSS Reader Ubuntu Blog auf Deutsch 0 04.11.2009 05:30


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:05 Uhr.


Powered by vBulletin® Version 3.8.2 (Deutsch)
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.