1 /*
2  * aTunes
3  * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
4  *
5  * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
6  *
7  * http://www.atunes.org
8  * http://sourceforge.net/projects/atunes
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 package net.sourceforge.atunes.gui.views.controls;
22 
23 import java.awt.Component;
24 
25 import javax.swing.JSplitPane;
26 
27 import net.sourceforge.atunes.model.IControlsBuilder;
28 import net.sourceforge.atunes.model.ILookAndFeelChangeListener;
29 import net.sourceforge.atunes.model.ILookAndFeelManager;
30 
31 /**
32  * @author alex
33  *
34  *         JSplitPane does not support component orientation, so we must do this
35  *         manually http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4265389
36  *
37  */
38 public class CustomSplitPane extends JSplitPane implements
39 		ILookAndFeelChangeListener {
40 
41 	private static final long serialVersionUID = 7760369696865269164L;
42 
43 	private final IControlsBuilder controlsBuilder;
44 
45 	private final ILookAndFeelManager lookAndFeelManager;
46 
CustomSplitPane(final int newOrientation, final IControlsBuilder controlsBuilder, final ILookAndFeelManager lookAndFeelManager)47 	CustomSplitPane(final int newOrientation,
48 			final IControlsBuilder controlsBuilder,
49 			final ILookAndFeelManager lookAndFeelManager) {
50 		super(newOrientation);
51 		this.controlsBuilder = controlsBuilder;
52 		this.lookAndFeelManager = lookAndFeelManager;
53 		this.lookAndFeelManager.addLookAndFeelChangeListener(this);
54 		this.lookAndFeelManager.getCurrentLookAndFeel()
55 				.customizeSplitPane(this);
56 	}
57 
58 	@Override
setLeftComponent(final Component comp)59 	public void setLeftComponent(final Component comp) {
60 		if (!this.controlsBuilder.getComponentOrientation().isLeftToRight()
61 				&& getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
62 			super.setRightComponent(comp);
63 		} else {
64 			super.setLeftComponent(comp);
65 		}
66 	}
67 
68 	@Override
setRightComponent(final Component comp)69 	public void setRightComponent(final Component comp) {
70 		if (!this.controlsBuilder.getComponentOrientation().isLeftToRight()
71 				&& getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
72 			super.setLeftComponent(comp);
73 		} else {
74 			super.setRightComponent(comp);
75 		}
76 	}
77 
78 	@Override
lookAndFeelChanged()79 	public void lookAndFeelChanged() {
80 		this.lookAndFeelManager.getCurrentLookAndFeel()
81 				.customizeSplitPane(this);
82 	}
83 }
84