I am creating a new GUI application using Docking Frames and a lot of components from my other GUI application. So, I thought it would be a good idea to change up the Eclipse Theme color palette, so that things appear visually different.
I was playing around with your ‘size-and-color’ demo and when I change the ‘tab.background.focused’, the color changes correctly but it is now a solid color. The original medium blue color was gradient and not a solid color. i.e. The tab is lighter blue at the top and gets a little darker blue towards the bottom.
How can I change the ‘tab.background.focused’ color and keep the gradient? Can I just change the color palette from medium blue to medium green (or medium orange)? If so, how?
2nd question: I found the following piece of code (I don’t remember where):
An “easy” way to override the default colors is to write your own “ColorBridge”. Like in the example below where the colors of the tabs are red and green (if focused and selected).
import java.awt.Color;
import javax.swing.JFrame;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.ColorMap;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.intern.CommonDockable;
import bibliothek.gui.dock.common.theme.ThemeMap;
import bibliothek.gui.dock.themes.color.TabColor;
import bibliothek.gui.dock.util.Priority;
import bibliothek.gui.dock.util.color.ColorBridge;
import bibliothek.gui.dock.util.color.DockColor;
public class MyColors {
public static void main( String[] args ) {
JFrame frame = new JFrame( "Test" );
CControl control = new CControl( frame );
control.setTheme( ThemeMap.KEY_ECLIPSE_THEME );
// override the default ColorBridge. Every color that is used by a tab must first be approved by the bridge.
control.getController().getColors().publish( Priority.CLIENT, TabColor.KIND_TAB_COLOR,
// you could also extend from EclipseTabTransmitter if you would like to keep support for the other colors
new ColorBridge() {
@Override
public void set( String id, Color value, DockColor uiValue ) {
// see "BaseTabComponent" for all the "ids" that we may experience here
TabColor tab = (TabColor) uiValue;
tab.getDockable();
if( id.equals( "stack.tab.top.selected.focused" ) ) {
value = getTopColor( tab.getDockable(), value );
} else if( id.equals( "stack.tab.bottom.selected.focused" ) ) {
value = getBottomColor( tab.getDockable(), value );
}
uiValue.set( value );
}
@Override
public void remove( String id, DockColor uiValue ) {
// ignore
}
@Override
public void add( String id, DockColor uiValue ) {
// ignore
}
} );
frame.add( control.getContentArea() );
CGrid grid = new CGrid( control );
grid.add( 0, 0, 1, 1, dockable( "a", "Aaaa", Color.RED ) );
grid.add( 1, 0, 1, 1, dockable( "b", "Bbbb", Color.GREEN ) );
control.getContentArea().deploy( grid );
frame.setBounds( 50, 50, 800, 800 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
}
private static DefaultSingleCDockable dockable( String id, String title, Color color ){
DefaultSingleCDockable dockable = new DefaultSingleCDockable( id, title );
// let's make use of the existing ColorMap instead of inventing our own collection of colors.
dockable.getColors().setColor( "myTop", color.brighter() );
dockable.getColors().setColor( "myBottom", color.darker() );
return dockable;
}
private static Color getTopColor( Dockable dockable, Color backup ) {
return getColor( dockable, "myTop", backup );
}
private static Color getBottomColor( Dockable dockable, Color backup ) {
return getColor( dockable, "myBottom", backup );
}
private static Color getColor( Dockable dockable, String id, Color backup ) {
Color result = null;
if( dockable instanceof CommonDockable ) {
ColorMap colors = ((CommonDockable) dockable).getDockable().getColors();
result = colors.getColor( id );
}
if( result == null ) {
result = backup;
}
return result;
}
}
(1) In the example you gave, if you click on either the red or green tab, there is still a blue outline where a JPanel or JTable would go.
What do I set to make this outline/border match the tab color?
(2) Who/what controls the color of the scroll bars of a JComponent in a dock? Is it Java L&F or Docking Frames? It looks like it is Docking Frames. What do I set to have the scroll bars of my JTable that is in a dock match the color of the tab?
Currently a bit occupied reinstalling and fixing my Linux
But for the question about the scrollbars: that would be the L&F, DockingFrames does not change the look of your Components. And I really have no idea how to change the color of scrollbars.
After I posted the question, I did a lot of fooling around and testing and I think I figured it out.
On a side note, it would be nice if you were a little more consistent with how you do your defined constants. The ColorMap class has many but you have a HUGE amount where you are hard-coding the same strings over and over. This can lead to typos aka bugs.
Ok, back to the issue. I believe that the border/outline setting that I was looking for is “stack.tab.border.selected.focused”.
So, I took your example above and created my own MyColorBridge class which is used as follows:
control.getController().getColors().publish( Priority.CLIENT, TabColor.KIND_TAB_COLOR, new MyColorBridge());
And here is my MyColorBridge class:
import java.awt.Color;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.common.ColorMap;
import bibliothek.gui.dock.common.intern.CommonDockable;
import bibliothek.gui.dock.themes.color.TabColor;
import bibliothek.gui.dock.util.color.ColorBridge;
import bibliothek.gui.dock.util.color.DockColor;
public class MyColorBridge implements ColorBridge
{
public void set( String id, Color value, DockColor uiValue )
{
// see "BaseTabComponent" for all the "ids" that we may experience here
TabColor tab = (TabColor) uiValue;
tab.getDockable();
if( id.equals( "stack.tab.top.selected.focused" ) )
{
value = getTopColor( tab.getDockable(), value );
}
else if( id.equals( "stack.tab.bottom.selected.focused" ) )
{
value = getBottomColor( tab.getDockable(), value );
}
else if( id.equals( "stack.tab.border.selected.focused" ) )
{
value = getBottomColor( tab.getDockable(), value );
}
uiValue.set( value );
}
public void remove( String id, DockColor uiValue )
{
// ignore
}
public void add( String id, DockColor uiValue )
{
// ignore
}
private static Color getTopColor( Dockable dockable, Color backup )
{
return getColor( dockable, "myTop", backup );
}
private static Color getBottomColor( Dockable dockable, Color backup )
{
return getColor( dockable, "myBottom", backup );
}
private static Color getColor( Dockable dockable, String id, Color backup )
{
Color result = null;
if( dockable instanceof CommonDockable )
{
ColorMap colors = ((CommonDockable) dockable).getDockable().getColors();
result = colors.getColor( id );
}
if( result == null )
{
result = backup;
}
return result;
}
}
This appears to work. So, is this the correct way of setting the border/outline color to match the darker part of the tab?
Well if it works it is good . But to tell you which piece of code is painting that line (and what id the color has) I would need to identify the line. With other words, a screenshot would be really helpful. Because right now I am a bit confused.
…
About the constant. You are right, different concepts are mixed and the result is a bit messy. If I could do the project again, I would certainly make the management of properties less tedious. Especially the „magic“ strings that are all over the place are not very helpful.