Docking Framework - Unable to add frames to same location

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Docking Framework - Unable to add frames to same location

Postby Maurice » Thu Oct 06, 2011 6:52 am

Hi,

I've been having a strange problem. I have adapted your demo DockingFrameworkDemo to add new frames to a window on demand (the user hits CTRL + N -> ENTER), and I am trying to add the new frame to exactly the same location as the previous frame. However, I am having two problems:

1) the new frame is not added to the same location and is therefore not tabbed, even though the initIndex, initMode and initSide are exactly the same?
2) If I change the docking side of the new tab to DOCK_SIDE_CENTER nothing gets added to the frame?

I've attached my code below.

Code: Select all
import java.awt.Component;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.util.Collections;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import com.google.common.collect.Lists;
import com.jidesoft.docking.DefaultDockableHolder;
import com.jidesoft.docking.DockContext;
import com.jidesoft.docking.DockableFrame;
import com.jidesoft.docking.DockingManager;
import com.jidesoft.icons.JideIconsFactory;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.ComboBoxSearchable;
import com.jidesoft.swing.JideScrollPane;

public class DockingFrameworkDemo2 extends DefaultDockableHolder {

    private static DockingFrameworkDemo2 _frame;
    public static String _lastDirectory = ".";

    private static final String PROFILE_NAME = "jidesoft";

    private static boolean _autohideAll = false;
    private static WindowAdapter _windowListener;
    public static JMenuItem _redoMenuItem;
    public static JMenuItem _undoMenuItem;
    public static long counter = System.currentTimeMillis();

    public DockingFrameworkDemo2(String title) throws HeadlessException {
        super(title);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
                new DockingFrameworkDemo2("Test").showDemo(true);
            }
        });

    }

    public DefaultDockableHolder showDemo(final boolean exit) {
      KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
       manager.addKeyEventDispatcher(new MyDispatcher());

        _frame = new DockingFrameworkDemo2("Demo of JIDE Docking Framework");
        _frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        _frame.getDockingManager().setXmlFormat(true);
        _frame.setIconImage(JideIconsFactory.getImageIcon(JideIconsFactory.JIDE32).getImage());

        // add a window listener to do clear up when windows closing.
        _windowListener = new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                clearUp();
                if (exit) {
                    System.exit(0);
                }
            }
        };
        _frame.addWindowListener(_windowListener);
        _frame.getDockingManager().setProfileKey(PROFILE_NAME);
        _frame.getDockingManager().setOutlineMode(DockingManager.FULL_OUTLINE_MODE);
        _frame.setJMenuBar(createMenuBar());
        _frame.getDockingManager().setUndoLimit(10);
        _frame.getDockingManager().beginLoadLayoutData();
        _frame.getDockingManager().setInitSplitPriority(DockingManager.SPLIT_EAST_WEST_SOUTH_NORTH);
      _frame.getDockingManager().addFrame(createSampleCommandFrame());
        _frame.getDockingManager().getWorkspace().setAcceptDockableFrame(false);
        _frame.getDockingManager().getWorkspace().setAdjustOpacityOnFly(true);
        _frame.getDockingManager().loadLayoutData();
        _frame.toFront();
        return _frame;
    }

    private static void clearUp() {
        _frame.removeWindowListener(_windowListener);
        _windowListener = null;

        if (_frame.getDockingManager() != null) {
            _frame.getDockingManager().saveLayoutData();
        }

        _frame.dispose();
        _frame = null;
    }

    protected static DockableFrame createDockableFrame(String key, Icon icon) {
        DockableFrame frame = new DockableFrame(key, icon);
        frame.setPreferredSize(new Dimension(200, 200));
        return frame;
    }

    protected DockableFrame createSampleCommandFrame() {
      DockableFrame frame = createDockableFrame("Command" + counter++, JideIconsFactory.getImageIcon(JideIconsFactory.DockableFrame.FRAME7));
      frame.getContext().setInitMode(DockContext.STATE_FRAMEDOCKED);
      frame.getContext().setInitSide(DockContext.DOCK_SIDE_SOUTH);
      frame.getContext().setInitIndex(0);
      JTextArea textArea = new JTextArea();
      frame.add(createScrollPane(textArea));
      textArea.setText(">");
      return frame;
   }
    protected static JMenuBar createMenuBar() {
        return new JMenuBar();
    }

    private static JScrollPane createScrollPane(Component component) {
        JScrollPane pane = new JideScrollPane(component);
        pane.setVerticalScrollBarPolicy(JideScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        return pane;
    }
   
    private void addPanel(DockableFrame frame) {
       frame.getContext().setInitMode(DockContext.STATE_FRAMEDOCKED);
       frame.getContext().setInitSide(DockContext.DOCK_SIDE_SOUTH);
      frame.getContext().setInitIndex(0);
       _frame.getDockingManager().beginLoadLayoutData();
       _frame.getDockingManager().addFrame(frame);
      _frame.getDockingManager().activateFrame(frame.getKey());
      _frame.getDockingManager().loadLayoutData();
    }
   
    class NewPaneAction extends AbstractAction {
       
        private final JFrame quickSelectorFrame = new JFrame("Quick Pane Creator");
        private final List<String> frameNames = Lists.newArrayList("Dummy");
        private JComboBox panelsComboBox;
       
        public NewPaneAction() {
            super("Quick Pane");
            Collections.sort(frameNames);
            init();
        }
       
        /**
         * Creates the actual quick pane window.
         */
        private void init() {
            // Create a simple combobox with the frame names and wrap it in a
            // Jide searchable wrapper.
           
//           for (NewPaneType type : NewPaneType.values()) {
//              frameNames.add(type.getTitle());
//           }
           
            panelsComboBox = new JComboBox(frameNames.toArray());
            final ComboBoxSearchable comboBoxSearchable = new ComboBoxSearchable(panelsComboBox);
            comboBoxSearchable.setWildcardEnabled(true);
            comboBoxSearchable.setCaseSensitive(false);
           
            final KeyListener keyHandler = new KeyListener() {
               
                @Override
                public void keyTyped(KeyEvent e) {
                }
               
                @Override
                public void keyReleased(KeyEvent e) {
                }
               
                @Override
                public void keyPressed(KeyEvent e) {
                    if (e.getKeyCode() == KeyEvent.VK_ESCAPE && !comboBoxSearchable.isPopupVisible())
                        quickSelectorFrame.setVisible(false);
                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                        // Extract the frame name from the long name and create
                        // a new frame.
                        final String longFrameName = (String) panelsComboBox.getSelectedItem();
                        if (longFrameName != null) {
                           addPanel(createSampleCommandFrame());
                        }
                        quickSelectorFrame.setVisible(false);
                    }
                }

            };
           
            panelsComboBox.addKeyListener(keyHandler);
            quickSelectorFrame.addKeyListener(keyHandler);
           
            Border framedBorder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Select a pane to create");
            Border emptyBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
            panelsComboBox.setBorder(BorderFactory.createCompoundBorder(emptyBorder, framedBorder));
           
            // We hide the window if it loses focus.
            quickSelectorFrame.addWindowFocusListener(new WindowFocusListener() {
               
                @Override
                public void windowLostFocus(WindowEvent e) {
                    quickSelectorFrame.setVisible(false);
                }
               
                @Override
                public void windowGainedFocus(WindowEvent e) {
                }
            });
           
            quickSelectorFrame.add(panelsComboBox);
            quickSelectorFrame.pack();
            quickSelectorFrame.setResizable(false);
        }
       
        @Override
        public void actionPerformed(ActionEvent e) {
            Point center = _frame.getLocationOnScreen();
            center.x += _frame.getSize().width / 2 - quickSelectorFrame.getSize().width / 2;
            center.y += _frame.getSize().height / 2 - quickSelectorFrame.getSize().height / 2;
            panelsComboBox.requestFocusInWindow();
            quickSelectorFrame.setLocation(center);
            quickSelectorFrame.setVisible(true);
        }
    }
   
   private class MyDispatcher implements KeyEventDispatcher {
       @Override
       public boolean dispatchKeyEvent(KeyEvent e) {
           if (e.getKeyCode() == (KeyEvent.VK_N) && e.isControlDown()) {
               new NewPaneAction().actionPerformed(null);
           }
           return false;
       }
   }

}


Many thanks
Maurice
 
Posts: 62
Joined: Tue Sep 14, 2010 3:36 am

Re: Docking Framework - Unable to add frames to same locatio

Postby JIDE Support » Thu Oct 06, 2011 11:05 am

The init settings are only considered during the initial layout process which is a call resetToDefault when there are no layout. In the other word, if two frames have the same init settings (side,mode,index), a call to resetToDefault will put them in a tabbed pane. If the layout is already finalized, addFrame call will not add a frame at the same location even all init settings are the same. The reason is the frame might have been moved by your users to some other location. Respecting the init settings doesn't make too much sense anymore. So if you want to force the newly added frame to a location as one of the existing frame, you can use moveFrame method.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Docking Framework - Unable to add frames to same locatio

Postby Maurice » Tue Oct 11, 2011 4:43 am

Great thanks for that.

I have a follow up question based on the code in my previous post. When I add frame to the screen (by hitting ctrl + n) no matter where i move them there is always a part of the screen which I cannot fill?

It is really frustrating that I cannot use all the space. any ideas?

Many thanks,

Maurice
Maurice
 
Posts: 62
Joined: Tue Sep 14, 2010 3:36 am

Re: Docking Framework - Unable to add frames to same locatio

Postby JIDE Support » Tue Oct 11, 2011 10:22 am

Please invoke DockingManager#setShowWorkspace(false) to remove that empty space.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Docking Framework - Unable to add frames to same locatio

Postby Maurice » Mon Oct 24, 2011 4:15 am

Thank you.

On a slightly different issue, I am trying to get two docking managers to work together.

If I create new frames and new panels from scratch for each docking manager then I can drag dockable frames across JFrames. However, If I have a layout saved for one of the docking managers, then on I am unable to drag those frames to the other docking manger. Any ideas?

Many thanks
Maurice
 
Posts: 62
Joined: Tue Sep 14, 2010 3:36 am

Re: Docking Framework - Unable to add frames to same locatio

Postby JIDE Support » Mon Oct 24, 2011 9:37 am

Can you please give JIDE TwoDockingFramewordDemo a try? It loads layout each time on launching the test case and could still drag and drop between those two DockingManager's.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Docking Framework - Unable to add frames to same locatio

Postby Maurice » Tue Oct 25, 2011 6:46 am

Thanks. I have tried this and would like to ask about a specific point.

In the demo code there is a line where the layouts are loaded:

Code: Select all
_firstPanel.getDockingManager().loadLayoutDataFrom("first_default");
 _secondPanel.getDockingManager().loadLayoutDataFrom("second_default");


However, when I load my layout I load it from a specific file location:

Code: Select all
getDockingManager().loadLayoutDataFromFile("C:/config.xml");


I don't seem to be able to load each docking managers layout where I have an overarching dockingManager for the frame.
Maurice
 
Posts: 62
Joined: Tue Sep 14, 2010 3:36 am

Re: Docking Framework - Unable to add frames to same locatio

Postby JIDE Support » Tue Oct 25, 2011 8:35 am

Please give the attached test case a try then. The idea is to create a LayoutPersistenceManager then add all docking managers to the manager. You could then save/load layout using that manager instead of every individual docking managers.

Thanks,
Attachments
NestedDockingFrameworkDemo.java
(12.98 KiB) Downloaded 1637 times
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 15 guests

cron