Overriding the Close Button in the Eclipse Theme

Hi!

I’ve managed to track down the string to replace the given icon in the eclipse theme:

mainControl.getIcons().setIconClient("close", closeIcon);

However, I’d rather override eclipse’s button as a whole, as I’d like to have it not highlight the whole button on mouseover, but rather simply swap the icon to a hover image (like what chrome and eclipse do).

In addition to this, I’d like to only include the close button on the currently selected item in a stack (like eclipse does). I presume this would be implemented in the LocationManager or something.

I’ve included a simplified version of my code below.

Thanks!

-nate

		editorFrame = new JFrame();
		setRootPane(editorFrame.getRootPane());
		mainControl = new CControl(editorFrame);
		mainControl.addSingleDockableFactory(myDockableFactory,myDockableFactory);
		editorFrame.setLayout(new GridLayout(1, 1));
		editorFrame.add(mainControl.getContentArea());
		
		CControlPerspective controlPerspectives = mainControl.getPerspectives();
		CPerspective perspective = controlPerspectives.createEmptyPerspective();
		CGridPerspective center = perspective.getContentArea().getCenter();
		
		//add a bunch of stacks and tools... simplified down to one.
		CStackPerspective stack = new CStackPerspective();
		stack.add(new SingleCDockablePerspective("tool"));
		center.grid().addDockable(0,0,100,100,stack);
		
		controlPerspectives.setPerspective("main", perspective);
		mainControl.load("main");
		mainControl.setTheme(ThemeMap.KEY_ECLIPSE_THEME);
		mainControl.getIcons().setIconClient(CLOSE_BUTTON_ICON_KEY, SystemEditorIconFactory.getEditorIcon(IconType.VIEW_CLOSE));
		editorFrame.setBounds(0, 0, 500, 400);
		mainControl.readXML("prefs.xml");

I’m currently updating the framework to support your ideas. The code that follows will only work with the next version, 1.1.2p8. It allows you to hide the close action if a tab is not selected.

[edit: I won’t add support for showing the action when hovering over the tab, I simply do not have enough time to do that right now.]

Answers to the other questions will follow, but the update of the framework must wait (I certainly have it online on Monday).

This code is written with the “docking-frames-demo-tutorial.jar” in the class-path.


import java.awt.Color;

import tutorial.support.ColorSingleCDockable;
import tutorial.support.JTutorialFrame;
import tutorial.support.Tutorial;
import bibliothek.extension.gui.dock.theme.EclipseTheme;
import bibliothek.extension.gui.dock.theme.eclipse.EclipseTabDockActionLocation;
import bibliothek.extension.gui.dock.theme.eclipse.EclipseTabStateInfo;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.action.CAction;
import bibliothek.gui.dock.common.action.predefined.CCloseAction;
import bibliothek.gui.dock.common.theme.ThemeMap;
import bibliothek.gui.dock.common.theme.eclipse.CommonEclipseThemeConnector;


@Tutorial(title="Hide Close Action", id="HideCloseAction")
public class HideCloseActionExample {
	public static void main( String[] args ){
		/* What if the close action of CDockables should only be visible if on a selected
		 * tab in the EclipseTheme?
		 * 
		 *  The CommonEclipseThemeConnector offers a method that can be overriden to achieve this goal. 
		 * */
		
		/* As usual we need some frame... */
		JTutorialFrame frame = new JTutorialFrame( HideCloseActionExample.class );
		
		/* ... and a control */
		CControl control = new CControl( frame );
		
		/* We set the EclipseTheme and at the same time reconfigure the framework to use our
		 * customized EclipseThemeConnector */
		control.setTheme( ThemeMap.KEY_ECLIPSE_THEME );
		control.putProperty( EclipseTheme.THEME_CONNECTOR, new HidingEclipseThemeConnector( control ) );
		
		/* And now we just add some closeable dockables to the application */
		frame.add( control.getContentArea() );
		
		ColorSingleCDockable red = new ColorSingleCDockable( "Red", Color.RED );
		red.setCloseable( true );
		
		ColorSingleCDockable green = new ColorSingleCDockable( "Green", Color.GREEN );
		green.setCloseable( true );
		
		ColorSingleCDockable blue = new ColorSingleCDockable( "Blue", Color.BLUE );
		blue.setCloseable( true );
		
		CGrid grid = new CGrid( control );
		grid.add( 0, 0, 1, 1, red, green, blue );
		control.getContentArea().deploy( grid );
		
		frame.setVisible( true );
	}
	
	/* The EclipseThemeConnector is reponsible to fine tune the look and feel of the EclipseTheme */
	public static class HidingEclipseThemeConnector extends CommonEclipseThemeConnector{
		public HidingEclipseThemeConnector( CControl control ){
			super( control );
		}

		@Override
		protected EclipseTabDockActionLocation getLocation( CAction action, EclipseTabStateInfo tab ){
			if( action instanceof CCloseAction ){
				/* By redefining the behavior of the close-action, we can hide it if the tab
				 * is not selected */
				if( tab.isSelected() ){
					return EclipseTabDockActionLocation.TAB;
				}
				else{
					return EclipseTabDockActionLocation.HIDDEN;
				}
			}
			return super.getLocation( action, tab );
		}
	}
}

I’ve uploaded a new version (1.1.2p8). Download the source, and search for a class called „EclipseLikeCloseButtonExample“ (it is in the tutorials project). This class should show you everything you need to know for modifying the close button :wink:

Thanks so much Beni! I’ll check it out.