Revision 11018

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/FilePage.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.2  2007-03-09 11:25:00  jaume
46
* Revision 1.3  2007-04-03 09:12:28  cesar
47
* When saving legends, ask before overwriting files
48
*
49
* Revision 1.2  2007/03/09 11:25:00  jaume
47 50
* Advanced symbology (start committing)
48 51
*
49 52
* Revision 1.1.2.1  2007/02/01 12:12:41  jaume
......
62 65

  
63 66
import javax.swing.JComponent;
64 67
import javax.swing.JFileChooser;
68
import javax.swing.JOptionPane;
65 69

  
66 70
import org.exolab.castor.xml.MarshalException;
67 71
import org.exolab.castor.xml.Marshaller;
......
93 97
				jfc.addChoosableFileFilter(new GenericFileFilter("sld","*.sld"));
94 98
				jfc.addChoosableFileFilter(new GenericFileFilter("gvl",
95 99
						PluginServices.getText(this, "tipo_de_leyenda")));
100
				File basedir = null;
101
				Object[] options = {PluginServices.getText(this, "Yes"),
102
	                    PluginServices.getText(this, "No"),
103
	                    PluginServices.getText(this, "Cancel")};
96 104

  
97

  
98
				if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
99
					File file=jfc.getSelectedFile();
100
					if (jfc.getFileFilter().accept(new File("dummy.sld"))) {
101
						if (!(file.getPath().toLowerCase().endsWith(".sld"))){
102
							file=new File(file.getPath()+".sld");
105
				while (true) {
106
					jfc.setCurrentDirectory(basedir);
107
					if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION)
108
					{
109
						File file=jfc.getSelectedFile();
110
						if (file.exists()) {
111
							int answer = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
112
									PluginServices.getText(this, "error_file_exists"),
113
									PluginServices.getText(this, "confirmation_dialog"),
114
									JOptionPane.YES_NO_CANCEL_OPTION,
115
									JOptionPane.QUESTION_MESSAGE,
116
									null,
117
									options, options[1]);
118
							if (answer==2 || answer==JOptionPane.CLOSED_OPTION) {
119
								// 'Cancel' pressed or window closed: don't save anythig, exit save dialog
120
								break;
121
							}
122
							else if (answer==1) {
123
								// 'No' pressed, show jfc dialog again
124
								basedir = file.getParentFile();
125
								continue;
126
							}
127
							// "Yes" pressed, overwrite the file...
103 128
						}
104
						export2SLD(file);
105
					}
106
					else{
107
						if (!(file.getPath().toLowerCase().endsWith(".gvl"))){
108
							file=new File(file.getPath()+".gvl");
129
						if (jfc.getFileFilter().accept(new File("dummy.sld")))
130
						{
131
							if (!(file.getPath().toLowerCase().endsWith(".sld"))){
132
								file=new File(file.getPath()+".sld");
133
							}
134
							export2SLD(file);
109 135
						}
110
						writeLegend(file);
136
						else{
137
							if (!(file.getPath().toLowerCase().endsWith(".gvl"))){
138
								file=new File(file.getPath()+".gvl");
139
							}
140
							writeLegend(file);
141
						}
142
						break;
111 143
					}
112 144
				}
113 145
			} else if (c.equals(getBtnLoadLegend())) {

Also available in: Unified diff