Revision 1750 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutExtension.java
LayoutExtension.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.app.extension; |
23 | 23 |
|
24 |
import java.awt.BorderLayout; |
|
25 | 24 |
import java.awt.Component; |
26 | 25 |
import java.awt.event.ActionEvent; |
27 | 26 |
import java.io.File; |
28 | 27 |
import java.io.FileOutputStream; |
28 |
import javax.swing.BoxLayout; |
|
29 | 29 |
import javax.swing.ImageIcon; |
30 | 30 |
import javax.swing.JButton; |
31 | 31 |
import javax.swing.JFileChooser; |
... | ... | |
131 | 131 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
132 | 132 |
PreferencesNode prefs = application.getPreferences("gvsig.foldering"); |
133 | 133 |
|
134 |
String prefsPath = prefs.get(TEMPLATES_FOLDER_PROPERTY_NAME, null); |
|
134 | 135 |
File projectfile = application.getCurrentProject().getFile(); |
136 |
JPanel accesory = null; |
|
137 |
if(projectfile != null || prefsPath != null) { |
|
138 |
accesory = new JPanel(); |
|
139 |
BoxLayout l = new BoxLayout(accesory, BoxLayout.PAGE_AXIS); |
|
140 |
accesory.setLayout(l); |
|
141 |
} |
|
135 | 142 |
if(projectfile != null) { |
136 |
JPanel accesory = new JPanel(); |
|
137 |
accesory.setLayout(new BorderLayout(0, 0)); |
|
138 | 143 |
ImageIcon icon = ToolsSwingLocator.getIconThemeManager().getActive().get("application-project-gotofolder"); |
139 | 144 |
JButton goToProjectButton = new JButton(icon); |
140 | 145 |
|
141 | 146 |
goToProjectButton.setToolTipText(i18n.getTranslation("_Go_to_folder_project")); |
142 |
accesory.add(goToProjectButton, BorderLayout.NORTH);
|
|
147 |
accesory.add(goToProjectButton); |
|
143 | 148 |
goToProjectButton.addActionListener((ActionEvent e) -> { |
144 | 149 |
fc.setCurrentDirectory(projectfile.getParentFile()); |
145 | 150 |
}); |
151 |
} |
|
152 |
if(prefsPath != null) { |
|
153 |
ImageIcon icon = ToolsSwingLocator.getIconThemeManager().getActive().get("application-layout-gotodefaulttemplatesfolder"); |
|
154 |
JButton goToTemplatesButton = new JButton(icon); |
|
155 |
|
|
156 |
goToTemplatesButton.setToolTipText(i18n.getTranslation("_Go_to_default_templates_folder")); |
|
157 |
accesory.add(goToTemplatesButton); |
|
158 |
goToTemplatesButton.addActionListener((ActionEvent e) -> { |
|
159 |
File prefsFile = new File(prefsPath); |
|
160 |
if(prefsFile.exists()){ |
|
161 |
fc.setCurrentDirectory(prefsFile); |
|
162 |
} |
|
163 |
}); |
|
164 |
} |
|
165 |
if(accesory != null){ |
|
146 | 166 |
fc.setAccessory(accesory); |
147 | 167 |
} |
148 | 168 |
|
149 | 169 |
File folder = null; |
150 |
folder = manager.getLastPath("_Last_layout_template_folder", null);
|
|
151 |
if(folder == null) {
|
|
170 |
folder = manager.getLastPath("_Last_layout_template_folder", new File(""));
|
|
171 |
if(folder == null || StringUtils.isBlank(folder.getPath())) {
|
|
152 | 172 |
if(projectfile != null){ |
153 | 173 |
folder = projectfile.getParentFile(); |
154 | 174 |
} |
155 |
if (folder == null) { |
|
156 |
folder = ToolsLocator.getFoldersManager().getHome(); |
|
157 |
} |
|
158 | 175 |
} |
159 | 176 |
|
160 |
if (folder == null) { |
|
177 |
if (folder == null || StringUtils.isBlank(folder.getPath())) {
|
|
161 | 178 |
String path = prefs.get(TEMPLATES_FOLDER_PROPERTY_NAME, null); |
162 | 179 |
if (StringUtils.isNotBlank(path)) { |
163 | 180 |
folder = new File(path); |
164 | 181 |
} |
165 | 182 |
} |
183 |
|
|
184 |
if (folder == null || StringUtils.isBlank(folder.getPath())) { |
|
185 |
folder = ToolsLocator.getFoldersManager().getHome(); |
|
186 |
} |
|
166 | 187 |
|
167 | 188 |
|
168 | 189 |
if (fc.showSaveDialog((Component) PluginServices.getMainFrame(), folder) != JFileChooser.APPROVE_OPTION) { |
... | ... | |
248 | 269 |
|
249 | 270 |
IconThemeHelper.registerIcon("action", |
250 | 271 |
"application-project-gotofolder", this); |
272 |
IconThemeHelper.registerIcon("action", |
|
273 |
"application-layout-gotodefaulttemplatesfolder", this); |
|
251 | 274 |
|
252 | 275 |
IconThemeHelper.registerIcon("action", |
253 | 276 |
"layout-navigation-zoom-in-center", this); |
Also available in: Unified diff