Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectViewFactory.java @ 7738

History | View | Annotate | Download (3.7 KB)

1
package com.iver.cit.gvsig.project.documents.view;
2

    
3
import java.text.DateFormat;
4
import java.util.ArrayList;
5
import java.util.Date;
6

    
7
import javax.swing.ImageIcon;
8

    
9
import com.iver.andami.PluginServices;
10
import com.iver.cit.gvsig.fmap.MapContext;
11
import com.iver.cit.gvsig.fmap.ViewPort;
12
import com.iver.cit.gvsig.project.Project;
13
import com.iver.cit.gvsig.project.documents.ProjectDocument;
14
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory;
15

    
16

    
17
/**
18
 * Factory of View.
19
 *
20
 * @author Vicente Caballero Navarro
21
 */
22
public class ProjectViewFactory extends ProjectDocumentFactory {
23
    public static String registerName = "ProjectView";
24

    
25

    
26
    /**
27
     * Returns image of button.
28
     *
29
     * @return Image button.
30
     */
31
    public ImageIcon getButtonIcon() {
32
        return new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista.png"));
33
    }
34

    
35
    /**
36
     * Returns image of selected button.
37
     *
38
     * @return Image button.
39
     */
40
    public ImageIcon getSelectedButtonIcon() {
41
        return new ImageIcon(this.getClass().getClassLoader().getResource("images/Vista_sel.png"));
42
    }
43

    
44
    /**
45
     * Create a new ProjectDocument.
46
     *
47
     * @param project Opened project.
48
     *
49
     * @return ProjectDocument.
50
     */
51
    public ProjectDocument create(Project project) {
52
        String viewName = "";
53
        String aux = PluginServices.getText(this, "untitled");
54
        viewName = aux + " - " + ProjectView.numViews++;
55

    
56
        if (project != null) {
57
            // Buscamos si alguna vista ya ten?a este nombre:
58
            while (existViewName(project, viewName)) {
59
                viewName = aux + " - " + ProjectView.numViews++;
60
            }
61
        }
62

    
63
        ProjectView vista = createView(viewName);
64
        vista.setProject(project, 0);
65

    
66
        return vista;
67
    }
68

    
69
    /**
70
     * Create a new ProjectView.
71
     *
72
     * @param baseName name
73
     *
74
     * @return ProjectView.
75
     */
76
    private static ProjectView createView(String viewName) {
77
        ProjectView v = new ProjectView();
78
        v.setMapContext(new MapContext(
79
                new ViewPort(Project.getDefaultProjection())));
80
        v.setMapOverViewContext(new MapContext(null));
81
        v.getMapOverViewContext().setProjection(v.getMapContext().getProjection());
82
        v.setName(viewName);
83
        v.setCreationDate(DateFormat.getInstance().format(new Date()));
84

    
85
        return v;
86
    }
87

    
88
    /**
89
     *
90
     *
91
     * @param project DOCUMENT ME!
92
     * @param viewName DOCUMENT ME!
93
     *
94
     * @return DOCUMENT ME!
95
     */
96
    private boolean existViewName(Project project, String viewName) {
97
        ArrayList viewList = project.getDocumentsByType(getRegisterName());
98

    
99
        for (int i = 0; i < viewList.size(); i++) {
100
            ProjectView pv = (ProjectView) viewList.get(i);
101
            String title = pv.getName();
102

    
103
            if (title.compareTo(viewName) == 0) {
104
                return true;
105
            }
106
        }
107

    
108
        return false;
109
    }
110

    
111
    /**
112
     * Returns the name of registration in the point of extension.
113
     *
114
     * @return Name of registration
115
     */
116
    public String getRegisterName() {
117
        return registerName;
118
    }
119

    
120
    /**
121
     * Returns the name of ProjectDocument.
122
     *
123
     * @return Name of ProjectDocument.
124
     */
125
    public String getNameType() {
126
        return PluginServices.getText(this, "Vista");
127
    }
128

    
129
    /**
130
     * Registers in the points of extension the Factory with alias.
131
     *
132
     */
133
    public static void register() {
134
        register(registerName, new ProjectViewFactory(),
135
            "com.iver.cit.gvsig.project.ProjectView");
136
    }
137

    
138
    /**
139
     * Returns the priority of de ProjectDocument.
140
     *
141
     * @return Priority.
142
     */
143
    public int getPriority() {
144
        return 0;
145
    }
146
}