root / trunk / examples / extNewDocumentExample / src / com / iver / cit / gvsig / project / documents / thedocument / TheDocument.java @ 7301
History | View | Annotate | Download (5.17 KB)
1 |
package com.iver.cit.gvsig.project.documents.thedocument; |
---|---|
2 |
|
3 |
import com.iver.andami.PluginServices; |
4 |
import com.iver.andami.ui.mdiManager.IWindow; |
5 |
|
6 |
import com.iver.cit.gvsig.fmap.DriverException; |
7 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
8 |
import com.iver.cit.gvsig.project.Project; |
9 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
10 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
11 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
12 |
import com.iver.cit.gvsig.project.documents.thedocument.gui.DocumentGUI; |
13 |
import com.iver.cit.gvsig.project.documents.thedocument.gui.DocumentProperties; |
14 |
|
15 |
import com.iver.utiles.XMLEntity; |
16 |
|
17 |
import java.text.DateFormat; |
18 |
|
19 |
import java.util.Date; |
20 |
|
21 |
import javax.swing.ImageIcon; |
22 |
|
23 |
|
24 |
/**
|
25 |
* New document.
|
26 |
*
|
27 |
* @author Vicente Caballero Navarro
|
28 |
*/
|
29 |
public class TheDocument extends ProjectDocument { |
30 |
public static int numElements = 0; |
31 |
|
32 |
/**
|
33 |
* Registration the document in the point extension.
|
34 |
*/
|
35 |
public static void register() { |
36 |
register("TheDocument", TheDocument.class);
|
37 |
} |
38 |
/**
|
39 |
* Returns the icon utilized to show in the button of the type of document.
|
40 |
*/
|
41 |
public ImageIcon getButtonIcon() { |
42 |
return new ImageIcon(getClass().getClassLoader().getResource("images/Document.png")); |
43 |
} |
44 |
/**
|
45 |
* Returns the icon utilized to show in the button of the type of document when is selected.
|
46 |
*/
|
47 |
public ImageIcon getSelectedButtonIcon() { |
48 |
return new ImageIcon(this.getClass().getClassLoader().getResource("images/Document_Sel.png")); |
49 |
} |
50 |
|
51 |
/**
|
52 |
* Creates a new document.
|
53 |
*
|
54 |
* @param baseName Name of document.
|
55 |
*
|
56 |
* @return new ProjectDocument.
|
57 |
*/
|
58 |
public ProjectDocument create(String baseName) { |
59 |
TheDocument m = new TheDocument();
|
60 |
m.setName(baseName + " - " + numElements);
|
61 |
m.setCreationDate(DateFormat.getInstance().format(new Date())); |
62 |
numElements++; |
63 |
|
64 |
return m;
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* Returns the XMEntity with all the characteristics that want to store in the project.
|
69 |
*
|
70 |
* @return XMLEntity
|
71 |
* @throws SaveException
|
72 |
* @throws XMLException
|
73 |
*
|
74 |
* @throws DriverException
|
75 |
*/
|
76 |
public XMLEntity getXMLEntity() throws SaveException { |
77 |
XMLEntity xml = super.getXMLEntity();
|
78 |
|
79 |
try {
|
80 |
xml.putProperty("numElements", numElements);
|
81 |
|
82 |
XMLEntity viewProperties = this.getViewInfoXMLEntity();
|
83 |
|
84 |
if (viewProperties != null) { //store the properties of the window |
85 |
xml.addChild(viewProperties); |
86 |
} |
87 |
} catch (Exception e) { |
88 |
throw new SaveException(e, this.getClass().getName()); |
89 |
} |
90 |
|
91 |
return xml;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* @throws OpenException
|
96 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
97 |
*/
|
98 |
public void setXMLEntity(XMLEntity xml, Project p) |
99 |
throws OpenException {
|
100 |
try {
|
101 |
numElements = xml.getIntProperty("numElements");
|
102 |
|
103 |
for (int i = 0; i < xml.getChildrenCount(); i++) { |
104 |
XMLEntity child = xml.getChild(i); |
105 |
|
106 |
if (child.contains("className") && |
107 |
child.getStringProperty("className").equals(this.getClass() |
108 |
.getName()) && |
109 |
child.contains("name") &&
|
110 |
child.getStringProperty("name").equals("ViewInfoProperties")) { |
111 |
seedViewInfo = createViewInfoFromXMLEntity(child); |
112 |
|
113 |
//PluginServices.getMDIManager().changeViewInfo(view, viewInfo);
|
114 |
} else if (child.contains("className") && |
115 |
child.getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.Layout") && |
116 |
child.contains("name") &&
|
117 |
child.getStringProperty("name").equals("layout")) { |
118 |
} |
119 |
} |
120 |
} catch (Exception e) { |
121 |
throw new OpenException(e, this.getClass().getName()); |
122 |
} |
123 |
} |
124 |
|
125 |
/**
|
126 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
127 |
*/
|
128 |
public void setXMLEntity03(XMLEntity xml, Project p) { |
129 |
} |
130 |
/**
|
131 |
* Creates the gui that we want in which we can introduce our document as model.
|
132 |
*/
|
133 |
public IWindow createWindow() {
|
134 |
DocumentGUI gui = new DocumentGUI();
|
135 |
gui.setModel(this);
|
136 |
|
137 |
return gui;
|
138 |
} |
139 |
/**
|
140 |
* Returns the name of register at extension point.
|
141 |
*/
|
142 |
public String getRegisterName() { |
143 |
return "document"; |
144 |
} |
145 |
/**
|
146 |
* Creates the gui that we want in which we can modify the properties of our document.
|
147 |
*/
|
148 |
public IWindow getProperties() {
|
149 |
DocumentProperties dp = new DocumentProperties(this); |
150 |
|
151 |
return dp;
|
152 |
} |
153 |
/**
|
154 |
* Code to apply when a document is removed.
|
155 |
*/
|
156 |
public void remove() { |
157 |
} |
158 |
/**
|
159 |
* Code to apply when a document is added.
|
160 |
*/
|
161 |
public void add() { |
162 |
} |
163 |
/**
|
164 |
* Returns the name of our document.
|
165 |
*/
|
166 |
public String getFrameName() { |
167 |
return PluginServices.getText(this, "Document"); |
168 |
} |
169 |
} |