How can I change flap tab text direction?

how can I change flap tab text direction

when flap is created in “vertical” space, such as:

frame.add(flapDockStation.getComponent(), BorderLayout.WEST);

There is a method “FlapDockStation.setDirection” which tells the station in which direction to open its window, and thus how the titles have to be layed out.

Or if the windows already open in the right direction and you just want to change the titles:
Create a new class extending FlapDockStation, override the method “orientation”. This method gets the current position of the FlapDockStation and tells how to layout the titles.

In order to use your new class in Common you need to extend “EfficientControlFactory” and override “createFlapDockStation”. You then have to give the new factory to the constructor of CControl.

got it; thanks!

it feels like guides/common need a section: “how to extend docking-frames/common - by example”

I will post my examples here when done: http://code.google.com/p/docking-frames/

Beni:

I followed your advice:
http://code.google.com/p/docking-frames/source/browse/#svn/demo/trunk/docking-frames-examples/src/main/java/org/dockingframes/example/flap_title_direction

and reversed all your definitions:
http://code.google.com/p/docking-frames/source/browse/demo/trunk/docking-frames-examples/src/main/java/org/dockingframes/example/flap_title_direction/AP_FlapDockStation.java

expecting that updated text will show up in reverse to the original text in all 4 directions;

still no dice:

original title:
http://code.google.com/p/docking-frames/source/browse/demo/trunk/docking-frames-examples/src/main/java/org/dockingframes/example/flap_title_direction/direction-original.png

and

updated title:
http://code.google.com/p/docking-frames/source/browse/demo/trunk/docking-frames-examples/src/main/java/org/dockingframes/example/flap_title_direction/direction-updated.png

both still have same text direction;

what I want is that you tilt your head to the left when looking and reading title text on the left minimize area;

what am I missing?

thank you;

Andrei

Ah, I think we are not speaking of the same thing. Hm, currently nothing but writing a custom title (from scratch) would achieve what you want. :-/ I’ll add some property that will allow to rotate the text at any multiple of 90 degrees.

Using the newest version you will be able to run the code below which now paints the text upside down in titles. Tabs do not (yet) support rotated text.


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import bibliothek.gui.Dockable;
import bibliothek.gui.dock.FlapDockStation;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.DefaultMultipleCDockable;
import bibliothek.gui.dock.common.EmptyMultipleCDockableFactory;
import bibliothek.gui.dock.common.MultipleCDockable;
import bibliothek.gui.dock.common.MultipleCDockableFactory;
import bibliothek.gui.dock.common.MultipleCDockableLayout;
import bibliothek.gui.dock.common.layout.ThemeMap;
import bibliothek.gui.dock.event.DockHierarchyEvent;
import bibliothek.gui.dock.event.DockHierarchyListener;
import bibliothek.gui.dock.title.DockTitle;
import bibliothek.gui.dock.title.OrientationToRotationStrategy;
import bibliothek.gui.dock.title.OrientationToRotationStrategyListener;
import bibliothek.gui.dock.title.DockTitle.Orientation;
import bibliothek.gui.dock.util.swing.Rotation;

public class Dock15 {
    public static DefaultMultipleCDockable createDockable( MultipleCDockableFactory<MultipleCDockable, MultipleCDockableLayout> factory, String title, Color color ){
        JPanel panel = new JPanel();
        panel.setOpaque(true);
        panel.setBackground(color);
        final DefaultMultipleCDockable dockable = new DefaultMultipleCDockable(factory, title, panel);
        dockable.setTitleIcon(new RectIcon());

        return dockable;
    }

    public static void main( String[] args ){
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                JFrame frame = new JFrame("Demo");
                CControl control = new CControl(frame);
                
                control.putProperty(DockTitle.ORIENTATION_STRATEGY, new RotationStrategy() );

                // ignore @deprecated
                control.setTheme(ThemeMap.KEY_ECLIPSE_THEME);

                frame.add(control.getContentArea(), BorderLayout.CENTER);

                CGrid grid = new CGrid(control);

                MultipleCDockableFactory<MultipleCDockable, MultipleCDockableLayout> factory = new EmptyMultipleCDockableFactory<MultipleCDockable>(){
                    public MultipleCDockable createDockable(){
                        return null;
                    }
                };
                
                control.addMultipleDockableFactory( "color", factory );

                grid = new CGrid(control);
                grid.add(0, 0, 1, 1, createDockable( factory, "Yellow", Color.YELLOW));
                grid.add(0, 1, 1, 1, createDockable( factory, "Red", Color.RED));
                control.getContentArea().deploy(grid);

                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setBounds(20, 20, 400, 400);
                frame.setVisible(true);
            }
        });
    }
    
    private static class RectIcon implements Icon{
        public int getIconWidth(){
            return 16;
        }
        
        public int getIconHeight(){
            return 16;
        }
        
        @Override
        public void paintIcon( Component c, Graphics g, int x, int y ){
            g.setColor(Color.RED);
            g.fillRect(x, y, 16, 16);
        }
    }
    
    private static class RotationStrategy implements OrientationToRotationStrategy, DockHierarchyListener{
        private Set<DockTitle> titles = new HashSet<DockTitle>();
        private List<OrientationToRotationStrategyListener> listeners = new ArrayList<OrientationToRotationStrategyListener>();
        
        public Rotation convert( Orientation orientation, DockTitle title ){
            Dockable dockable = title.getDockable();
            if( dockable.getDockParent() instanceof FlapDockStation ){
                if( title.getOrigin() != null && title.getOrigin().getID().equals( FlapDockStation.BUTTON_TITLE_ID )){
                    if( orientation.isHorizontal() ){
                        return Rotation.DEGREE_180;
                    }
                    else{
                        return Rotation.DEGREE_270;
                    }
                }
            }
            
            if( orientation.isHorizontal() ){
                return Rotation.DEGREE_0;
            }
            else{
                return Rotation.DEGREE_90;
            }
        }
        
        public void install( DockTitle title ){
            if( !monitored( title.getDockable() )){
                title.getDockable().addDockHierarchyListener( this );
            }
            titles.add( title );
        }
        
        public void uninstall( DockTitle title ){
            titles.remove( title );
            if( !monitored( title.getDockable() )){
                title.getDockable().removeDockHierarchyListener( this );
            }
        }
        
        public void controllerChanged( DockHierarchyEvent event ){
            // ignore
        }
        
        public void hierarchyChanged( DockHierarchyEvent event ){
            for( OrientationToRotationStrategyListener listener : listeners ){
                listener.rotationChanged( event.getDockable(), null );
            }
        }
        
        private boolean monitored( Dockable dockable ){
            for( DockTitle title : titles ){
                if( title.getDockable() == dockable ){
                    return true;
                }
            }
            return false;
        }
        
        public void addListener( OrientationToRotationStrategyListener listener ){
            listeners.add( listener );    
        }
        
        public void removeListener( OrientationToRotationStrategyListener listener ){
            listeners.remove( listener );
        }
    }
}```

wow! it works! thank you;

this is rather involved; probably some code you shared
qualified to be included in core/common?

also, do you have some hidden “strategy” for tabs alignment?

like {left, center, right} or {top, middle, bottom}}

More some code for an example. I’m not so happy with adding code to the libraries that is not actually used, it just would get messy.

Well, about tabs… not that easy… there is an interface called “TabLayoutManager” and a property “TabPane.LAYOUT_MANAGER”. Currently you would need to implement a new layout-manager. You could copy one of the existing managers and rewrite its code… don’t know if you really want that.

It’s not a bad idea, but an idea that will requires some work. I put it on the todo list for 1.1.0, but not for 1.0.8.

thanks!

here is what I needed:

http://code.google.com/p/docking-frames/source/browse/demo/trunk/docking-frames-examples/src/main/java/org/dockingframes/example/flap_title_direction/AP_RotationStrategy.java

and how it looks before and after applying rotation strategy;

http://code.google.com/p/docking-frames/source/browse/demo/trunk/docking-frames-examples/src/main/java/org/dockingframes/example/flap_title_direction/direction-original.png

http://code.google.com/p/docking-frames/source/browse/demo/trunk/docking-frames-examples/src/main/java/org/dockingframes/example/flap_title_direction/direction-updated.png

by adding code to core/commons, I meant to provide

AbstractRotationStrategy or RotationStrategyAdabpter

instead of asking people for full implementation:

class RotationStrategy implements
OrientationToRotationStrategy, DockHierarchyListener {

anyway, just minor idea;