Why this doesn't work? I think I'm missing something

Please help me! :slight_smile:

I’ve spent a lot of time trying to stack several DefaultSingleCDockable in the center of a CGridArea. When I deploy the grid, I get an error:

java.lang.ClassCastException: bibliothek.gui.dock.common.location.CStackLocation cannot be cast to bibliothek.gui.dock.common.location.CBaseLocation

I’m not sure how to proceed.

I have built an example that illustrates my problem:


public class ExampleFrame extends javax.swing.JFrame {

    /**
    * Auto-generated main method to display this JFrame
    */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ExampleFrame inst = new ExampleFrame();
                inst.setLocationRelativeTo(null);
                inst.setVisible(true);
            }
        });
    }
    
    public ExampleFrame() {
        super();
        initGUI();
    }
    
    private void initGUI() {
        try {
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            
            CControl control = new CControl(this);
            CGridArea gridArea = control.createGridArea("grid");
            CGrid grid = new CGrid();
            
            JPanel panelA = new JPanel();
            panelA.setBackground(Color.BLUE);
            
            JPanel panelB = new JPanel();
            panelB.setBackground(Color.RED);
            
            JPanel panelC = new JPanel();
            panelC.setBackground(Color.YELLOW);
            
            DefaultSingleCDockable dockableA = new DefaultSingleCDockable("panelA");
            dockableA.getContentPane().add(panelA);
            dockableA.setLocation(CLocation.base());
            
            DefaultSingleCDockable dockableB = new DefaultSingleCDockable("panelB");
            dockableB.getContentPane().add(panelB);        
            
            DefaultSingleCDockable dockableC = new DefaultSingleCDockable("panelC");
            dockableC.getContentPane().add(panelC);        
            
            // Trying to stack the dockableB with the dockableA
            CStackLocation stackLocationB = CLocation.base().normalNorth(1).stack();
            dockableB.setLocation(stackLocationB);
            
            // Trying to stack the dockableB with the dockableA
            CStackLocation stackLocationC = CLocation.base().normalNorth(1).stack();
            dockableC.setLocation(stackLocationC);
            
            grid.add(0d, 0d, 1d, 1d, dockableA, dockableB, dockableC);
            
            gridArea.deploy(grid);
            
            this.add(gridArea.getComponent(), BorderLayout.CENTER);
            
            pack();
            setSize(400, 300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

When I remove the dockableC, I see the dockableA and dockableB stacked correctly.

How can I stack N components in the center of a CGridArea? I’m I using the grid correctly? I think I’m missing soemthing on how to build the correct CLocation for the N dockables I want to stack…

All I need is all DefaultSingleCDockable stacked using all space available in the middle of the CGridArea (possibly with other DefaultSingleCDockable around).

Thank you very much for spending the time to read my post and also thanks in advance for any clues you may have! :slight_smile:

That is a bug in the library… I’ve fixed it and in version 1.0.7 p4 your code will work (I’ll upload the new library tomorrow, there is some other stuff which needs to be tested before the “release”. I’ll sure write again once it is up).

You don’t need to set the locations when using a CGrid: the CGrid alone is enough.

But if you want to work with locations: Since you are not using the default-CContentArea you should use this code:

CLocation.normalized( gridArea )...

… instead of …

CLocation.base()...

… because the later one leads to the default content area, and not gridArea.

Sorry for the time you lost, but there are not yet many people using the library and I can’t always test all the possible combinations how the library might be used… if you have other problems just ask, chances to find another bug are high.

A new version is now on the server, you can download it here. I’ve tested it with the code below.

There are some changes compared to your version. Most important is this one:

control.add( dockableB );
control.add( dockableC );```
If you do that, then the Dockables are provided with some additional buttons (although minimizing will not work because in this code no minimize-are is created, "control.createMinimizeArea( uniqueId )" would do the trick).

```package test;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import bibliothek.gui.dock.common.*;
import bibliothek.gui.dock.common.location.CStackLocation;

public class ExampleFrame extends javax.swing.JFrame {

    /**
    * Auto-generated main method to display this JFrame
    */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ExampleFrame inst = new ExampleFrame();
                inst.setLocationRelativeTo(null);
                inst.setVisible(true);
            }
        });
    }
    
    public ExampleFrame() {
        super();
        initGUI();
    }
    
    private void initGUI() {
        try {
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            
            CControl control = new CControl(this);
            CGridArea gridArea = control.createGridArea("grid");
            
            JPanel panelA = new JPanel();
            panelA.setBackground(Color.BLUE);
            
            JPanel panelB = new JPanel();
            panelB.setBackground(Color.RED);
            
            JPanel panelC = new JPanel();
            panelC.setBackground(Color.YELLOW);
            
            DefaultSingleCDockable dockableA = new DefaultSingleCDockable("panelA");
            dockableA.getContentPane().add(panelA);
            
            DefaultSingleCDockable dockableB = new DefaultSingleCDockable("panelB");
            dockableB.getContentPane().add(panelB);        
            
            DefaultSingleCDockable dockableC = new DefaultSingleCDockable("panelC");
            dockableC.getContentPane().add(panelC);        
            
            control.add( dockableA );
            control.add( dockableB );
            control.add( dockableC );
            
            boolean tryGrid = true;
            
            if( tryGrid ){
                CGrid grid = new CGrid();
                grid.add(0d, 0d, 1d, 1d, dockableA, dockableB, dockableC);
                gridArea.deploy(grid);
            }
            else{
                dockableA.setLocation( CLocation.normalized( gridArea ) );
                dockableA.setVisible( true );
                
                dockableB.setLocation( CLocation.normalized( gridArea ).stack() );
                dockableB.setVisible( true );
                
                // put this one to the front
                dockableC.setLocation( CLocation.normalized( gridArea ).stack( 0 ) );
                dockableC.setVisible( true );
            }
            
            this.add(gridArea.getComponent(), BorderLayout.CENTER);
            
            pack();
            setSize(400, 300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}```

Nice!!
Thank you very much!!

The library is awesome, the best docking library by far (and I’ve been using many others, believe me). bugs are inevitable and are part of the fun. :smiley:

Thanks once more!
Eduardo

Hi Beni!
I did a different test, and based on your previous answer I think this looks like a bug too. On 1.0.7 Preview 4, if I add the dockables to the grid using as you showed me:


            grid.add(0d, 0d, 1d, 1d, dockableA, dockableB, dockableC);

it works.

Now, it I add them one by one (which should have the same effect), they won’t stack:

            grid.add(0d, 0d, 1d, 1d, dockableA);
            grid.add(0d, 0d, 1d, 1d, dockableB);
            grid.add(0d, 0d, 1d, 1d, dockableC);

I’m not using the CLocation now, just the grid. =)

Cheers,
Eduardo

This time it is not a bug, it may not be nice but no bug. The algorithm in CGrid just sees some entries with a preferred size and location and tries to align them nicely. It just does not stack unless you explicitly give a stack to the grid.

Beni, I jhave fixed the bug I posted above, it was quite simple.

In the SplitDockGrid.addDockable method, a new Node was always being created even when an existing node located at the same position and with the same size was already in the grid.

Basically have I added the following code to the method:

       Node node = null;
        int copyNewDockablesAt = 0;
        for (Node existingNode : nodes) {
            if (existingNode.x == x
                    && existingNode.y == y
                    && existingNode.width == width
                    && existingNode.height == height) {
                node = existingNode;
                Dockable[] dockablesInExistingNode = node.dockables;
                copyNewDockablesAt = dockablesInExistingNode.length;
                node.dockables = new Dockable[ node.dockables.length + dockables.length ];
                System.arraycopy(dockablesInExistingNode, 0, node.dockables, 0, dockablesInExistingNode.length );
                break;
            }
        }
        if (node == null) {
            node = new Node();
            node.dockables = new Dockable[ dockables.length ];
            nodes.add( node );
        }

        System.arraycopy( dockables, 0, node.dockables, copyNewDockablesAt, dockables.length );

Instead of:


        Node node = new Node();
        node.dockables = new Dockable[ dockables.length ];
        System.arraycopy( dockables, 0, node.dockables, 0, dockables.length );

Also, in the end of the method, I have subtracted the

nodes.add( node );

call, since it happens now only when we create a new node (in the else clause of the above code.

This is the final, resultant method:

    public void addDockable( double x, double y, double width, double height, Dockable... dockables ){
        if( dockables == null )
            throw new IllegalArgumentException( "Dockable must not be null" );
        
        if( dockables.length == 0 )
            throw new IllegalArgumentException( "Dockables must at least have one element" );
        
        for( Dockable dockable : dockables )
            if( dockable == null )
                throw new IllegalArgumentException( "Entry of dockables-array is null" );
        
        if( width < 0 )
            throw new IllegalArgumentException( "width < 0" );
        
        if( height < 0 )
            throw new IllegalArgumentException( "height < 0" );
        
        Node node = null;
        int copyNewDockablesAt = 0;
        for (Node existingNode : nodes) {
            if (existingNode.x == x
                    && existingNode.y == y
                    && existingNode.width == width
                    && existingNode.height == height) {
                node = existingNode;
                Dockable[] dockablesInExistingNode = node.dockables;
                copyNewDockablesAt = dockablesInExistingNode.length;
                node.dockables = new Dockable[ node.dockables.length + dockables.length ];
                System.arraycopy(dockablesInExistingNode, 0, node.dockables, 0, dockablesInExistingNode.length );
                break;
            }
        }
        if (node == null) {
            node = new Node();
            node.dockables = new Dockable[ dockables.length ];
            nodes.add( node );
        }
        
        System.arraycopy( dockables, 0, node.dockables, copyNewDockablesAt, dockables.length );
        node.x = x;
        node.y = y;
        node.width = width;
        node.height = height;
    }

You may want to include these changes to the code base, I have tested extensively and it works fine.

I hope that is useful. :slight_smile:

Cheers,
Eduardo Born

Oh, I just saw your reply!

Hummm, interesting. I’ll leave up to you whether you want to incorporate the changes to the code base or not, but as both calls (sending the dockables at once or one at a time to the same location and position) are actually semantically equivalent, I think they should behave the same.

Thoughts?

Eduardo

Well, since you already have written the code, it would be a shame not to use it :wink:

thanks

Hi Beni!
When updating my fixed version of preview 4 to the released preview 6, I have noticed that this problem appeared again.

I have opened a bug record at:
http://javaforge.com/issue/8602?navigation=true

Do you think this fix would be included in the following preview or the final version of 1.7?

Thanks!
Eduardo

I’m such an idiot. I’ve copied your fix and then made some “improvement”. Since that improvement was one line of code and your code worked well I “forgot” not make a clean test.

I’m now compiling the library again and will upload it as version “preview 6b”. Wait for another 30 minutes then you can download it.

[Edit: please try this version]

Beni,
With preview 6b it worked like a charm!!!

Thank you VERY MUCH!!
Eduardo

jA7NjH bcceqywdkfnl, sudpvopglicl, [link=http://gjvumkhwjkpg.com/]gjvumkhwjkpg[/link], http://oygnyqlxsqfs.com/

world; dog prednisone; zoloft lawsuit; viagra dose schedule; zithromax azithromycin; _effets secondaires de levitra;

comment1, gateway casino, 9832, river rock and casino, 8PP, hard rock cafe and casino tampa, zrp, charder30 poker, emcils, br pro poker, 773005, online poker mac compatible, wrczg, corning rolling hills casino, 041702, hollywood slots bangor maine hotel, 8D, seven card stud poker rules, 93700, is casino royale a remake, avx, seif poker, %-[, pub poker championship, 669, moosejaw casino, >:[[, 888 com pacific poker, jop, motor city casino u0026 hotel, epl, caesars palace casino las vegas, 754759, starting hands in poker, 066, venetian casino resort macau, >:-DDD, real casino chips, 3016, playtech slots, fwhxdz, jogar poker, :-]]], konstanz casino, 15057, bond theme casino, 111, video strip poker classic 2007 crack, btet, you tube high stakes poker, >:-))), global casinos, 496, round table poker neopets guide, 1188, killer poker online 2, =(((, journal of gambling business and economics, asvwz, hotels near argosy casino in indiana, suq, rolling hills casino, 747539, new york council on problem gambling, sxyc, latin series of poker, 8[, video strip poker supreme serial, :OOO, avi resort and casino laughlin nevada, 871493, non casino hotels in las vegas, 1742, big slick poker maryland, deedu, video strip poker classic megaupload, 008655, tips for betting on roulette, 036791, singapore casino project, %-PP, vermont poker tables, eago, superstar poker ll, 26704, seneca niagara poker, =)), las vegas poker chips, 45270, springsteen roulette, ttuz, video strip poker supreme keygen, fmu, used casino playing cards, %-[, wsex poker download, 445, charity poker tournament, tcf, mobile phone casino, hxqy, single zero roulette odds, gde, online poker is it legal, %O, new season high stakes poker gsn, 763684, michael watson poker, :-OOO,

little; viagra; generic viagra; cialis side effects; cheap cialis;

glass; levitra 120 pills; cialis levitra; cialis; cialis for sale; levitra 4 pills; cialis drug impotence;

food; cialis side effects; levitra 4 pills; dr drew viagra;

new york city gambling, ks poker, 4012, hotel du casino paris, fvr, riverside casino, mlcvw, tekst poker face lady gaga, 8O, bc poker tournaments, fne, nicknames for poker hands, cnnm, downstream casino, >:-[[[, money maker poker, 213, canfield casino, 90119, north carolina cherokee casino, %-]]], pearl concert theater at palms casino resort las vegas nv, %-]], seven card stud poker rules, 04012, new jersey gambling age, =PP, imac memory slots, :-)), all in hold em poker 2.8, %-], kiowa casino, 148276, absolute poker no deposit, pbhxrl, internet casino deutschland, 98742, las vegas circus circus casino, >:), cabazon casino, akh, download hoyle casino, %DDD, louisiana gambling, 198, norman ok casino, %]], northern quest casino, =(, should gambling be legalized and regulated, mjh, adwords gambling, 308, budweiser poker chips, %-))), yukon gold casino, bubnbp, regulation poker chips, kah, mgm grand hotel casino las vegas nv, subp, 5 reel slots, :-], play omaha poker online, fcxq, song lyrics for poker face by lady gaga, nbfhvo, clam casino, 9600, ballys casino las vegas, 8DDD, absolute poker promotional code, :), scoala de poker, 65355, foldable poker table, =]], wynn hotel and casino, pbl, cherry red casino, apfb, sonic heroes casino park, wtdyc, betsson casino, 5687, y8 casino, 550, planning poker cards, 8847, oklahoma gambling, 235099, pacific poker no download, 876, minnesota poker rooms, 2019, macao casino hotel, 302118, wales poker league, ckqze, spirit mountain casino jobs, =-), liquid vegas casino, 8274, cheats governor of poker, 1095, video poker tutorial, 462262, pai gow poker free, :DDD,

golden casino slot, golden nugget casino game, 897, el capitan casino, 190292, vegas poker tournament schedule, 8], wwe divas strip poker video, 4534, horizon casino and resort, avooek, 4 poker, =OO, charlestown races and slots hotels, 0381, little creek casino washington state, >:]], tunica mississippi gambling, 797056, foxwoods casino connecticut, 8), charity poker chicago, 8-D, different poker games, :-)), suited poker, :-[[, mohegan sun casino pennsylvania, brtle, music video poker face by lady gaga, =((, bodog casino blackjack, 361309, north american poker championship 2008, blyhe, newgrounds poker, 760439, macau china casino, nlck, little river gambling boat, 8-)), foxwoods casino and resort, 925, party poker calculator, 5742, borgata poker, 688, la poker scene, uriuc, cool hand poker bonus, 8-), atlantis casino resort, mwedi, las vegas casino job openings, 56662, northern quest casino, =[[, santa anna casino, sgu, prestige online casino, osqlj, cleopatra casino game, uiywd, reglamento poker, =-[[[, motorcycle poker run rules, 87432, monte vista casino, 02200, yonker casino, fyppyg, niagara falls casino, bagewy, connecticut gambling age, >:-], overlay poker, pfsp, 50 stars casino, 60485, myspace poker chips, 674205, blackoak casino, 874674, paddy gambling, 55471, las vegas poker tournaments schedule, bre, lido poker, kisrcm, paroles poker face, 88349, fruit poker free, >:-((, chipin casino, raocq, new casino in bethlehem pa, :-((, giant vegas casino, 750865, party poker popup, >:-O,