Hi all.
I would like to know if it is possible to add any type of component in the actionPanel? Because i would like to add a combobox as an action to a dockable.
Thanks very much in advance!
Khrysto
Hi all.
I would like to know if it is possible to add any type of component in the actionPanel? Because i would like to add a combobox as an action to a dockable.
Thanks very much in advance!
Khrysto
And if it possible, can you please send me a sample on how to add a customized component?
Thanks again
Khrysto
And old example upgraded to use a ComboBox:
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.action.ActionType;
import bibliothek.gui.dock.action.DockAction;
import bibliothek.gui.dock.action.view.ActionViewConverter;
import bibliothek.gui.dock.action.view.ViewGenerator;
import bibliothek.gui.dock.action.view.ViewTarget;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.common.action.CAction;
import bibliothek.gui.dock.common.layout.ThemeMap;
import bibliothek.gui.dock.common.mode.ExtendedMode;
import bibliothek.gui.dock.themes.basic.action.BasicTitleViewItem;
import bibliothek.gui.dock.title.DockTitle.Orientation;
public class Dock7 {
public static class CustomButton implements BasicTitleViewItem<JComponent>{
private JComboBox box;
private CustomAction action;
public CustomButton( CustomAction action ){
// do something with action...
box = new JComboBox();
this.action = action;
}
public void setOrientation( Orientation orientation ){
// ignore
}
public void bind(){
// ignore
}
public JComponent getItem(){
return box;
}
public void unbind(){
// ignore
}
public DockAction getAction(){
return action;
}
public void setBackground( Color background ){
// ignore
}
public void setForeground( Color foreground ){
// ignore
}
}
// creates new comboboxes
public static class CustomViewGenerator implements ViewGenerator<CustomAction, BasicTitleViewItem<JComponent>>{
public BasicTitleViewItem<JComponent> create( ActionViewConverter converter, CustomAction action, Dockable dockable ){
return new CustomButton( action );
}
}
public static final ActionType<CustomAction> CUSTOM_TYPE = new ActionType<CustomAction>( "custom" );
// represents comboboxes
public static class CustomAction implements DockAction{
public void bind( Dockable dockable ){
// ignore
}
public <V> V createView( ViewTarget<V> target, ActionViewConverter converter, Dockable dockable ){
return converter.createView( CUSTOM_TYPE, this, target, dockable );
}
public boolean trigger( Dockable dockable ){
return false;
}
public void unbind( Dockable dockable ){
// ignore
}
}
// for the Common framework
public static class CCustomAction extends CAction{
public CCustomAction(){
super( new CustomAction() );
}
}
public static void main( String[] args ){
JFrame frame = new JFrame( "Demo" );
CControl control = new CControl( frame );
control.setTheme( ThemeMap.KEY_ECLIPSE_THEME );
// access the action-view-factories
ActionViewConverter actions = control.intern().getController().getActionViewConverter();
// put a factory for our custom button
actions.putClient( CUSTOM_TYPE, ViewTarget.TITLE, new CustomViewGenerator() );
frame.add( control.getContentArea(), BorderLayout.CENTER );
CGrid grid = new CGrid( control );
grid.add( 0, 0, 1, 1, createDockable( "Red", Color.RED ) );
grid.add( 0, 1, 1, 1, createDockable( "Green", Color.GREEN ) );
grid.add( 0, 2, 1, 1, createDockable( "Blue", Color.BLUE ) );
grid.add( 1, 0, 1, 1, createDockable( "Cyan", Color.CYAN ) );
grid.add( 1, 1, 1, 1, createDockable( "Magenta", Color.MAGENTA ) );
grid.add( 1, 2, 1, 1, createDockable( "Yellow", Color.YELLOW ) );
control.getContentArea().deploy( grid );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setBounds( 20, 20, 400, 400 );
frame.setVisible( true );
}
public static SingleCDockable createDockable( String title, Color color ){
JPanel panel = new JPanel();
panel.setOpaque( true );
panel.setBackground( color );
DefaultSingleCDockable dockable = new DefaultSingleCDockable( title, title, panel );
dockable.setDefaultLocation(ExtendedMode.MINIMIZED, CLocation.base().minimalEast());
dockable.setDefaultLocation(ExtendedMode.EXTERNALIZED, CLocation.external( 0, 0, 300, 300 ));
dockable.addAction( new CCustomAction() );
return dockable;
}
}
And how can you do this with the current version 1.1.1? Unfortunately this example doesn’t work anymore.
Thank you!
Thargor
Ok, I got it. The example “TitleWithTextFieldExample” was a good starting point to adapt the old example to the new wrapper CommonDockAction().
Thank you!