1
/*FreeMind - A Program for creating and viewing Mindmaps
2
*Copyright (C) 2000-2007 Joerg Mueller, Daniel Polansky, Christian Foltin, Dimitri Polivaev and others.
3
*See COPYING for Details
5
*This program is free software; you can redistribute it and/or
6
*modify it under the terms of the GNU General Public License
7
*as published by the Free Software Foundation; either version 2
8
*of the License, or (at your option) any later version.
10
*This program is distributed in the hope that it will be useful,
11
*but WITHOUT ANY WARRANTY; without even the implied warranty of
12
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
*GNU General Public License for more details.
15
*You should have received a copy of the GNU General Public License
16
*along with this program; if not, write to the Free Software
17
*Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
/* $Id: NodeViewFactory.java,v 1.1.4.9 2008/07/21 21:57:51 dpolivaev Exp $ */
20
package freemind.view.mindmapview;
22
import java.awt.Component;
23
import java.awt.Container;
24
import java.awt.Dimension;
25
import java.awt.Graphics;
26
import java.awt.Graphics2D;
27
import java.awt.Insets;
28
import java.awt.LayoutManager;
29
import java.awt.RenderingHints;
31
import javax.swing.Box;
32
import javax.swing.JComponent;
34
import freemind.modes.EdgeAdapter;
35
import freemind.modes.MindMapNode;
37
class NodeViewFactory {
39
private static class ContentPane extends JComponent{
40
static private LayoutManager layoutManager = new ContentPaneLayout();
43
setLayout(layoutManager );
47
private static class ContentPaneLayout implements LayoutManager{
49
public void addLayoutComponent(String name, Component comp) {
52
public void layoutContainer(Container parent) {
53
final int componentCount = parent.getComponentCount();
54
final int width = parent.getWidth();
56
for(int i = 0; i < componentCount; i++){
57
final Component component = parent.getComponent(i);
58
if(component.isVisible()){
59
final Dimension preferredCompSize = component.getPreferredSize();
60
if(component instanceof MainView){
61
component.setBounds(0, y, width, preferredCompSize.height);
64
int x = (int)(component.getAlignmentX() * (width - preferredCompSize.width));
65
component.setBounds(x, y, preferredCompSize.width, preferredCompSize.height);
67
y += preferredCompSize.height;
72
public Dimension minimumLayoutSize(Container parent) {
73
return preferredLayoutSize(parent);
76
public Dimension preferredLayoutSize(Container parent) {
77
final Dimension prefSize = new Dimension(0, 0);
78
final int componentCount = parent.getComponentCount();
79
for(int i = 0; i < componentCount; i++){
80
final Component component = parent.getComponent(i);
81
if(component.isVisible()){
82
final Dimension preferredCompSize = component.getPreferredSize();
83
prefSize.height += preferredCompSize.height;
84
prefSize.width = Math.max(prefSize.width, preferredCompSize.width);
90
public void removeLayoutComponent(Component comp) {
95
private static NodeViewFactory factory;
96
private EdgeView sharpBezierEdgeView;
97
private EdgeView sharpLinearEdgeView;
98
private EdgeView bezierEdgeView;
99
private EdgeView linearEdgeView;
102
private NodeViewFactory(){
107
static NodeViewFactory getInstance(){
109
factory = new NodeViewFactory();
114
EdgeView getEdge(NodeView newView) {
115
final String edgeStyle = newView.getModel().getEdge().getStyle();
116
if (edgeStyle.equals(EdgeAdapter.EDGESTYLE_LINEAR)) {
117
return getLinearEdgeView();
118
} else if (edgeStyle.equals(EdgeAdapter.EDGESTYLE_BEZIER)) {
119
return getBezierEdgeView();
120
} else if (edgeStyle.equals(EdgeAdapter.EDGESTYLE_SHARP_LINEAR)) {
121
return getSharpEdgeView();
122
} else if (edgeStyle.equals(EdgeAdapter.EDGESTYLE_SHARP_BEZIER)) {
123
return getSharpBezierEdgeView();
125
System.err.println("Unknown Edge Type.");
126
return getLinearEdgeView();
130
private EdgeView getSharpBezierEdgeView() {
131
if(sharpBezierEdgeView == null){
132
sharpBezierEdgeView = new SharpBezierEdgeView();
134
return sharpBezierEdgeView;
137
private EdgeView getSharpEdgeView() {
138
if(sharpLinearEdgeView == null){
139
sharpLinearEdgeView = new SharpLinearEdgeView();
141
return sharpLinearEdgeView;
144
private EdgeView getBezierEdgeView() {
145
if(bezierEdgeView == null){
146
bezierEdgeView = new BezierEdgeView();
148
return bezierEdgeView;
151
private EdgeView getLinearEdgeView() {
152
if(linearEdgeView == null){
153
linearEdgeView = new LinearEdgeView();
155
return linearEdgeView;
160
* Factory method which creates the right NodeView for the model.
162
NodeView newNodeView(MindMapNode model, int position, MapView map, Container parent) {
163
NodeView newView = new NodeView( model, position, map, parent);
165
if (model.isRoot()) {
166
final MainView mainView = new RootMainView();
167
newView.setMainView(mainView);
168
newView.setLayout(VerticalRootNodeViewLayout.getInstance());
171
newView.setMainView(newMainView(model));
172
if(newView.isLeft()){
173
newView.setLayout(LeftNodeViewLayout.getInstance());
176
newView.setLayout(RightNodeViewLayout.getInstance());
180
model.addViewer(newView);
182
fireNodeViewCreated(newView);
187
MainView newMainView(MindMapNode model) {
188
if (model.isRoot()) {
189
return new RootMainView();
191
if (model.getStyle().equals(MindMapNode.STYLE_FORK) ){
192
return new ForkMainView();
194
else if (model.getStyle().equals(MindMapNode.STYLE_BUBBLE)) {
195
return new BubbleMainView();
198
System.err.println("Tried to create a NodeView of unknown Style.");
199
return new ForkMainView();
204
private void fireNodeViewCreated(NodeView newView) {
205
newView.getMap().getModel().getModeController().onViewCreatedHook(newView);
209
JComponent newContentPane(NodeView view) {
210
return new ContentPane();