Revision 38543
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/java/org/gvsig/mkmvnproject/CreatePluginConsoleWindow.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.mkmvnproject; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.io.IOException; |
|
26 |
|
|
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindowListener; |
|
29 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
30 |
|
|
31 |
/** |
|
32 |
* A gvSIG window which shows the execution log messages of the create plugin |
|
33 |
* process. |
|
34 |
* |
|
35 |
* @author gvSIG Team |
|
36 |
* @version $Id$ |
|
37 |
*/ |
|
38 |
public class CreatePluginConsoleWindow extends CreatePluginConsolePanel |
|
39 |
implements IWindow, IWindowListener { |
|
40 |
|
|
41 |
private static final long serialVersionUID = -5589080107545290284L; |
|
42 |
|
|
43 |
private WindowInfo info; |
|
44 |
|
|
45 |
private Object profile = WindowInfo.EDITOR_PROFILE; |
|
46 |
|
|
47 |
/** |
|
48 |
* Constructor. |
|
49 |
* |
|
50 |
* @throws IOException |
|
51 |
* if there is an error creating the console streams |
|
52 |
*/ |
|
53 |
public CreatePluginConsoleWindow() throws IOException { |
|
54 |
super(); |
|
55 |
initializeWindow(); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Constructor. |
|
60 |
* |
|
61 |
* @param isDoubleBuffered |
|
62 |
* if the panel must be double buffered. |
|
63 |
* @throws IOException |
|
64 |
* if there is an error creating the console streams |
|
65 |
*/ |
|
66 |
public CreatePluginConsoleWindow(boolean isDoubleBuffered) throws IOException { |
|
67 |
super(isDoubleBuffered); |
|
68 |
initializeWindow(); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Initializes the window. |
|
73 |
*/ |
|
74 |
private void initializeWindow() { |
|
75 |
Dimension dimension = new Dimension(600, 300); |
|
76 |
setSize(dimension); |
|
77 |
int code = WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE |
|
78 |
| WindowInfo.RESIZABLE | WindowInfo.MODELESSDIALOG; |
|
79 |
profile = WindowInfo.EDITOR_PROFILE; |
|
80 |
info = new WindowInfo(code); |
|
81 |
info.setTitle("Console"); |
|
82 |
info.setMinimumSize(dimension); |
|
83 |
} |
|
84 |
|
|
85 |
public WindowInfo getWindowInfo() { |
|
86 |
return info; |
|
87 |
} |
|
88 |
|
|
89 |
public Object getWindowProfile() { |
|
90 |
return profile; |
|
91 |
} |
|
92 |
|
|
93 |
public void windowActivated() { |
|
94 |
// Nothing to do |
|
95 |
} |
|
96 |
|
|
97 |
public void windowClosed() { |
|
98 |
super.closeConsole(); |
|
99 |
} |
|
100 |
|
|
101 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/java/org/gvsig/mkmvnproject/CreatePluginConsolePanel.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.mkmvnproject; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.Color; |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.io.BufferedReader; |
|
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStreamReader; |
|
30 |
import java.io.PipedInputStream; |
|
31 |
import java.io.PipedOutputStream; |
|
32 |
import java.io.PrintStream; |
|
33 |
|
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JScrollPane; |
|
36 |
import javax.swing.JTextArea; |
|
37 |
import javax.swing.SwingUtilities; |
|
38 |
|
|
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
|
|
42 |
/** |
|
43 |
* A panel which shows the execution log messages of the create plugin process. |
|
44 |
* |
|
45 |
* @author gvSIG Team |
|
46 |
* @version $Id$ |
|
47 |
*/ |
|
48 |
public class CreatePluginConsolePanel extends JPanel { |
|
49 |
|
|
50 |
private static final long serialVersionUID = -7213048219847956909L; |
|
51 |
|
|
52 |
private static final Logger LOG = LoggerFactory |
|
53 |
.getLogger(CreatePluginConsolePanel.class); |
|
54 |
|
|
55 |
private JTextArea console; |
|
56 |
|
|
57 |
private PrintStream printStream; |
|
58 |
private PipedOutputStream pipedos; |
|
59 |
private PipedInputStream pipedis; |
|
60 |
private Thread consoleThread; |
|
61 |
|
|
62 |
/** |
|
63 |
* Constructor. |
|
64 |
* |
|
65 |
* @throws IOException |
|
66 |
* if there is an error creating the console streams |
|
67 |
*/ |
|
68 |
public CreatePluginConsolePanel() throws IOException { |
|
69 |
super(); |
|
70 |
initialize(); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Constructor. |
|
75 |
* |
|
76 |
* @param isDoubleBuffered |
|
77 |
* if the panel must be double buffered. |
|
78 |
* @throws IOException |
|
79 |
* if there is an error creating the console streams |
|
80 |
*/ |
|
81 |
public CreatePluginConsolePanel(boolean isDoubleBuffered) |
|
82 |
throws IOException { |
|
83 |
super(isDoubleBuffered); |
|
84 |
initialize(); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Initializes the panel GUI. |
|
89 |
* |
|
90 |
* @throws IOException |
|
91 |
*/ |
|
92 |
private void initialize() throws IOException { |
|
93 |
Dimension dimension = new Dimension(600, 200); |
|
94 |
setSize(dimension); |
|
95 |
setLayout(new BorderLayout()); |
|
96 |
|
|
97 |
console = new JTextArea(); |
|
98 |
console.setEditable(false); |
|
99 |
// console.setColumns(20); |
|
100 |
// console.setRows(5); |
|
101 |
console.setBackground(Color.WHITE); |
|
102 |
console.setLineWrap(true); |
|
103 |
console.setWrapStyleWord(true); |
|
104 |
|
|
105 |
JScrollPane consoleScrollPane = new JScrollPane(console); |
|
106 |
add(consoleScrollPane, BorderLayout.CENTER); |
|
107 |
|
|
108 |
pipedis = new PipedInputStream(); |
|
109 |
|
|
110 |
pipedos = new PipedOutputStream(pipedis); |
|
111 |
|
|
112 |
printStream = new PrintStream(pipedos); |
|
113 |
consoleThread = new ConsoleThread(pipedis, console); |
|
114 |
consoleThread.start(); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Returns a {@link PrintStream} which allows to write messages to the |
|
119 |
* console. |
|
120 |
* |
|
121 |
* @return a {@link PrintStream} which allows to write messages to the |
|
122 |
* console |
|
123 |
*/ |
|
124 |
public PrintStream getPrintStream() { |
|
125 |
return printStream; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Returns a {@link PrintStream} which allows to write error messages to the |
|
130 |
* console. |
|
131 |
* |
|
132 |
* @return a {@link PrintStream} which allows to write error messages to the |
|
133 |
* console |
|
134 |
*/ |
|
135 |
public PrintStream getErrorPrintStream() { |
|
136 |
return getPrintStream(); |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Closes the console. Once this method is called, any more calls to the |
|
141 |
* console {@link PrintStream} will throw an exception. |
|
142 |
*/ |
|
143 |
public void closeConsole() { |
|
144 |
printStream.flush(); |
|
145 |
printStream.close(); |
|
146 |
try { |
|
147 |
pipedos.close(); |
|
148 |
pipedis.close(); |
|
149 |
// Wait for the thread to finish |
|
150 |
consoleThread.join(500); |
|
151 |
} catch (IOException e) { |
|
152 |
LOG.warn("Error closing the internal piped streams", e); |
|
153 |
} catch (InterruptedException e) { |
|
154 |
// Nothing special to do |
|
155 |
LOG.debug("Console thread interrupted while waiting to finish", e); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
private static final class ConsoleThread extends Thread { |
|
160 |
|
|
161 |
private final PipedInputStream pipedis; |
|
162 |
private final JTextArea console; |
|
163 |
|
|
164 |
/** |
|
165 |
* Constructor. |
|
166 |
*/ |
|
167 |
public ConsoleThread(PipedInputStream pipedis, JTextArea console) { |
|
168 |
super("Create plugin console update thread"); |
|
169 |
setDaemon(true); |
|
170 |
this.pipedis = pipedis; |
|
171 |
this.console = console; |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public void run() { |
|
176 |
try { |
|
177 |
BufferedReader reader = new BufferedReader( |
|
178 |
new InputStreamReader(pipedis)); |
|
179 |
String line; |
|
180 |
while ((line = reader.readLine()) != null) { |
|
181 |
SwingUtilities.invokeLater(new ConsoleUpdateRunnable( |
|
182 |
console, line)); |
|
183 |
} |
|
184 |
LOG.debug("Console input stream end, finish reading"); |
|
185 |
reader.close(); |
|
186 |
} catch (IOException e) { |
|
187 |
LOG.warn("Error reading from the console string", e); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Runnable used to update the console text field. |
|
195 |
* |
|
196 |
* @author gvSIG Team |
|
197 |
* @version $Id$ |
|
198 |
*/ |
|
199 |
private static final class ConsoleUpdateRunnable implements Runnable { |
|
200 |
private final String newLine; |
|
201 |
private final JTextArea console; |
|
202 |
|
|
203 |
/** |
|
204 |
* Constructor. |
|
205 |
*/ |
|
206 |
public ConsoleUpdateRunnable(JTextArea console, String newLine) { |
|
207 |
this.console = console; |
|
208 |
this.newLine = newLine; |
|
209 |
} |
|
210 |
|
|
211 |
public void run() { |
|
212 |
console.append(newLine); |
|
213 |
console.append("\n"); |
|
214 |
} |
|
215 |
} |
|
216 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/java/org/gvsig/mkmvnproject/gui/settings/PlatformPropertiesWindow.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2012 gvSIG Association |
|
4 |
* |
|
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. |
|
9 |
* |
|
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. |
|
14 |
* |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.mkmvnproject.gui.settings; |
|
24 |
|
|
25 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.Font; |
|
27 |
import java.awt.GridBagConstraints; |
|
28 |
import java.awt.GridBagLayout; |
|
29 |
import java.awt.GridLayout; |
|
30 |
import java.awt.Insets; |
|
31 |
import java.awt.event.ActionEvent; |
|
32 |
import java.awt.event.ActionListener; |
|
33 |
import java.io.File; |
|
34 |
import java.io.FileOutputStream; |
|
35 |
import java.io.IOException; |
|
36 |
|
|
37 |
import javax.swing.JButton; |
|
38 |
import javax.swing.JLabel; |
|
39 |
import javax.swing.JOptionPane; |
|
40 |
import javax.swing.JPanel; |
|
41 |
import javax.swing.JScrollBar; |
|
42 |
import javax.swing.JScrollPane; |
|
43 |
import javax.swing.JTextArea; |
|
44 |
import javax.swing.event.DocumentEvent; |
|
45 |
import javax.swing.event.DocumentListener; |
|
46 |
|
|
47 |
import org.slf4j.Logger; |
|
48 |
import org.slf4j.LoggerFactory; |
|
49 |
|
|
50 |
import org.gvsig.andami.PluginServices; |
|
51 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
52 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
53 |
import org.gvsig.i18n.Messages; |
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* This dialog lets the user write the file .gvsig.platform.properties |
|
58 |
* |
|
59 |
* @author jldominguez |
|
60 |
* |
|
61 |
*/ |
|
62 |
public class PlatformPropertiesWindow extends JPanel |
|
63 |
implements IWindow, ActionListener, DocumentListener { |
|
64 |
|
|
65 |
private static final Logger logger = |
|
66 |
LoggerFactory.getLogger(PlatformPropertiesWindow.class); |
|
67 |
|
|
68 |
private WindowInfo winfo = null; |
|
69 |
private File targetFile = null; |
|
70 |
private boolean isWindows = false; |
|
71 |
|
|
72 |
private JPanel northPanel = null; |
|
73 |
|
|
74 |
private JTextArea contentArea = null; |
|
75 |
|
|
76 |
private JPanel southPanel = null; |
|
77 |
private JButton saveButton = null; |
|
78 |
private JButton suggButton = null; |
|
79 |
private JButton okButton = null; |
|
80 |
private JButton cancelButton = null; |
|
81 |
|
|
82 |
private boolean validSettings = false; |
|
83 |
|
|
84 |
public PlatformPropertiesWindow( |
|
85 |
File non_existing_file, boolean is_win) { |
|
86 |
|
|
87 |
targetFile = non_existing_file; |
|
88 |
isWindows = is_win; |
|
89 |
init(); |
|
90 |
} |
|
91 |
|
|
92 |
private void init() { |
|
93 |
|
|
94 |
this.setLayout(new BorderLayout()); |
|
95 |
|
|
96 |
northPanel = new JPanel(new GridBagLayout()); |
|
97 |
GridBagConstraints c = new GridBagConstraints(); |
|
98 |
c.insets = new Insets(1, 10, 1, 10); |
|
99 |
c.weightx = 0.5; // |
|
100 |
c.fill = GridBagConstraints.HORIZONTAL; |
|
101 |
c.gridx = 0; |
|
102 |
|
|
103 |
c.gridy = 0; |
|
104 |
northPanel.add(new JLabel(" "), c); |
|
105 |
c.gridy = 1; |
|
106 |
northPanel.add(new JLabel(Messages.getText( |
|
107 |
"_Mandatory_platform_properties_file_not_found")), c); |
|
108 |
c.gridy = 2; |
|
109 |
northPanel.add(new JLabel(Messages.getText( |
|
110 |
"_Use_this_text_editor_to_write_it")), c); |
|
111 |
c.gridy = 3; |
|
112 |
northPanel.add(new JLabel(" "), c); |
|
113 |
// ============================================= |
|
114 |
// ============================================= |
|
115 |
southPanel = new JPanel(); |
|
116 |
southPanel.setLayout(new GridLayout(1, 5, 8, 4)); |
|
117 |
// ------------ |
|
118 |
southPanel.add(getSaveButton()); |
|
119 |
southPanel.add(getSuggButton()); |
|
120 |
// ------------ |
|
121 |
southPanel.add(new JLabel(" ")); |
|
122 |
// ------------ |
|
123 |
southPanel.add(getOkButton()); |
|
124 |
southPanel.add(getCancelButton()); |
|
125 |
// ============================================= |
|
126 |
|
|
127 |
this.add(northPanel, BorderLayout.NORTH); |
|
128 |
|
|
129 |
JScrollPane scroll = new JScrollPane(); |
|
130 |
scroll.setViewportView(getContentArea()); |
|
131 |
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
132 |
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
|
133 |
this.add(scroll, BorderLayout.CENTER); |
|
134 |
|
|
135 |
JPanel south2 = new JPanel(new GridBagLayout()); |
|
136 |
GridBagConstraints cs = new GridBagConstraints(); |
|
137 |
cs.insets = new Insets(15,15,15,15); |
|
138 |
south2.add(southPanel, cs); |
|
139 |
|
|
140 |
this.add(south2, BorderLayout.SOUTH); |
|
141 |
} |
|
142 |
|
|
143 |
private JTextArea getContentArea() { |
|
144 |
|
|
145 |
if (contentArea == null) { |
|
146 |
contentArea = new JTextArea(); |
|
147 |
loadSuggested(contentArea); |
|
148 |
contentArea.getDocument().addDocumentListener(this); |
|
149 |
} |
|
150 |
return contentArea; |
|
151 |
} |
|
152 |
|
|
153 |
private JButton getCancelButton() { |
|
154 |
if (cancelButton == null) { |
|
155 |
cancelButton = new JButton(Messages.getText("_Cancel")); |
|
156 |
cancelButton.addActionListener(this); |
|
157 |
} |
|
158 |
return cancelButton; |
|
159 |
} |
|
160 |
|
|
161 |
private JButton getSuggButton() { |
|
162 |
if (suggButton == null) { |
|
163 |
suggButton = new JButton(Messages.getText("_Suggested")); |
|
164 |
suggButton.addActionListener(this); |
|
165 |
} |
|
166 |
return suggButton; |
|
167 |
} |
|
168 |
|
|
169 |
private JButton getOkButton() { |
|
170 |
if (okButton == null) { |
|
171 |
okButton = new JButton(Messages.getText("_Accept")); |
|
172 |
okButton.addActionListener(this); |
|
173 |
okButton.setEnabled(false); |
|
174 |
} |
|
175 |
return okButton; |
|
176 |
} |
|
177 |
|
|
178 |
private JButton getSaveButton() { |
|
179 |
if (saveButton == null) { |
|
180 |
saveButton = new JButton(Messages.getText("_Save")); |
|
181 |
Font fnt = saveButton.getFont(); |
|
182 |
fnt = fnt.deriveFont(Font.BOLD); |
|
183 |
saveButton.setFont(fnt); |
|
184 |
saveButton.addActionListener(this); |
|
185 |
} |
|
186 |
return saveButton; |
|
187 |
} |
|
188 |
|
|
189 |
// =================================================== |
|
190 |
// =================================================== |
|
191 |
|
|
192 |
public WindowInfo getWindowInfo() { |
|
193 |
if (winfo == null) { |
|
194 |
winfo = new WindowInfo(WindowInfo.MODALDIALOG); |
|
195 |
winfo.setWidth(550); |
|
196 |
winfo.setHeight(350); |
|
197 |
winfo.setTitle( |
|
198 |
Messages.getText("_Checking_platform_properties")); |
|
199 |
} |
|
200 |
return winfo; |
|
201 |
} |
|
202 |
|
|
203 |
public Object getWindowProfile() { |
|
204 |
return WindowInfo.DIALOG_PROFILE; |
|
205 |
} |
|
206 |
|
|
207 |
public static final String SUGGESTED_WINDOWN_CONTENT = |
|
208 |
"native_platform=win\n" + |
|
209 |
"native_distribution=nt\n" + |
|
210 |
"native_compiler=vs8\n" + |
|
211 |
"native_arch=i386\n" + |
|
212 |
"native_libraryType=dynamic"; |
|
213 |
|
|
214 |
public static final String SUGGESTED_NON_WINDOWS_CONTENT = |
|
215 |
"native_platform=linux\n" + |
|
216 |
"native_distribution=all\n" + |
|
217 |
"native_compiler=gcc4\n" + |
|
218 |
"native_arch=i386\n" + |
|
219 |
"native_libraryType=dynamic"; |
|
220 |
|
|
221 |
|
|
222 |
public void actionPerformed(ActionEvent e) { |
|
223 |
|
|
224 |
Object src = e.getSource(); |
|
225 |
if (src == getOkButton()) { |
|
226 |
if (getSaveButton().isEnabled()) { |
|
227 |
if (!userAcceptsNotSaving()) { |
|
228 |
return; |
|
229 |
} |
|
230 |
} |
|
231 |
validSettings = true; |
|
232 |
PluginServices.getMDIManager().closeWindow(this); |
|
233 |
} |
|
234 |
|
|
235 |
if (src == getCancelButton()) { |
|
236 |
validSettings = false; |
|
237 |
PluginServices.getMDIManager().closeWindow(this); |
|
238 |
} |
|
239 |
|
|
240 |
if (src == getSaveButton()) { |
|
241 |
if (saveContent()) { |
|
242 |
this.getSaveButton().setEnabled(false); |
|
243 |
} |
|
244 |
this.refreshOkButton(); |
|
245 |
} |
|
246 |
|
|
247 |
if (src == getSuggButton()) { |
|
248 |
loadSuggested(getContentArea()); |
|
249 |
this.getSaveButton().setEnabled(true); |
|
250 |
} |
|
251 |
|
|
252 |
} |
|
253 |
|
|
254 |
|
|
255 |
/** |
|
256 |
* @return |
|
257 |
*/ |
|
258 |
private boolean userAcceptsNotSaving() { |
|
259 |
|
|
260 |
String _msg = |
|
261 |
Messages.getText("_There_are_unsaved_changes_Continue_question"); |
|
262 |
String _tit = |
|
263 |
Messages.getText("_Not_saved"); |
|
264 |
int usr_opt = JOptionPane.showConfirmDialog( |
|
265 |
this, _msg, _tit, JOptionPane.YES_NO_OPTION, |
|
266 |
JOptionPane.WARNING_MESSAGE); |
|
267 |
return (usr_opt == JOptionPane.YES_OPTION); |
|
268 |
} |
|
269 |
|
|
270 |
private boolean saveContent() { |
|
271 |
|
|
272 |
try { |
|
273 |
if (targetFile.exists()) { |
|
274 |
targetFile.delete(); |
|
275 |
} |
|
276 |
targetFile.createNewFile(); |
|
277 |
|
|
278 |
FileOutputStream fos = new FileOutputStream(targetFile); |
|
279 |
String contnt = getContentArea().getText(); |
|
280 |
fos.write(contnt.getBytes()); |
|
281 |
fos.flush(); |
|
282 |
fos.close(); |
|
283 |
return true; |
|
284 |
} catch (IOException ioe) { |
|
285 |
logger.info("While writing file: " + ioe.getMessage(), ioe); |
|
286 |
String _msg = Messages.getText("_Unable_to_store_file") |
|
287 |
+ ": " + targetFile.getAbsolutePath(); |
|
288 |
String _tit = Messages.getText("_Error"); |
|
289 |
JOptionPane.showMessageDialog( |
|
290 |
this, _msg, _tit, JOptionPane.ERROR_MESSAGE); |
|
291 |
return false; |
|
292 |
} |
|
293 |
|
|
294 |
} |
|
295 |
|
|
296 |
private void loadSuggested(JTextArea ta) { |
|
297 |
|
|
298 |
if (isWindows) { |
|
299 |
ta.setText(SUGGESTED_WINDOWN_CONTENT); |
|
300 |
} else { |
|
301 |
ta.setText(SUGGESTED_NON_WINDOWS_CONTENT); |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
public void insertUpdate(DocumentEvent e) { |
|
306 |
this.getSaveButton().setEnabled(true); |
|
307 |
} |
|
308 |
|
|
309 |
public void removeUpdate(DocumentEvent e) { |
|
310 |
this.getSaveButton().setEnabled(true); |
|
311 |
} |
|
312 |
|
|
313 |
public void changedUpdate(DocumentEvent e) { |
|
314 |
// should not be called because this text area is simple |
|
315 |
} |
|
316 |
|
|
317 |
public boolean validSettings() { |
|
318 |
return validSettings; |
|
319 |
} |
|
320 |
|
|
321 |
private void refreshOkButton() { |
|
322 |
this.getOkButton().setEnabled(targetFile.exists()); |
|
323 |
} |
|
324 |
|
|
325 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/java/org/gvsig/mkmvnproject/gui/CreatePluginConsolePanel.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.mkmvnproject.gui; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.Color; |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.io.BufferedReader; |
|
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStreamReader; |
|
30 |
import java.io.PipedInputStream; |
|
31 |
import java.io.PipedOutputStream; |
|
32 |
import java.io.PrintStream; |
|
33 |
|
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JScrollPane; |
|
36 |
import javax.swing.JTextArea; |
|
37 |
import javax.swing.SwingUtilities; |
|
38 |
|
|
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
|
|
42 |
/** |
|
43 |
* A panel which shows the execution log messages of the create plugin process. |
|
44 |
* |
|
45 |
* @author gvSIG Team |
|
46 |
* @version $Id$ |
|
47 |
*/ |
|
48 |
public class CreatePluginConsolePanel extends JPanel { |
|
49 |
|
|
50 |
private static final long serialVersionUID = -7213048219847956909L; |
|
51 |
|
|
52 |
private static final Logger LOG = LoggerFactory |
|
53 |
.getLogger(CreatePluginConsolePanel.class); |
|
54 |
|
|
55 |
private JTextArea console; |
|
56 |
|
|
57 |
private PrintStream printStream; |
|
58 |
private PipedOutputStream pipedos; |
|
59 |
private PipedInputStream pipedis; |
|
60 |
private Thread consoleThread; |
|
61 |
|
|
62 |
/** |
|
63 |
* Constructor. |
|
64 |
* |
|
65 |
* @throws IOException |
|
66 |
* if there is an error creating the console streams |
|
67 |
*/ |
|
68 |
public CreatePluginConsolePanel() throws IOException { |
|
69 |
super(); |
|
70 |
initialize(); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Constructor. |
|
75 |
* |
|
76 |
* @param isDoubleBuffered |
|
77 |
* if the panel must be double buffered. |
|
78 |
* @throws IOException |
|
79 |
* if there is an error creating the console streams |
|
80 |
*/ |
|
81 |
public CreatePluginConsolePanel(boolean isDoubleBuffered) |
|
82 |
throws IOException { |
|
83 |
super(isDoubleBuffered); |
|
84 |
initialize(); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Initializes the panel GUI. |
|
89 |
* |
|
90 |
* @throws IOException |
|
91 |
*/ |
|
92 |
private void initialize() throws IOException { |
|
93 |
Dimension dimension = new Dimension(600, 200); |
|
94 |
setSize(dimension); |
|
95 |
setLayout(new BorderLayout()); |
|
96 |
|
|
97 |
console = new JTextArea(); |
|
98 |
console.setEditable(false); |
|
99 |
// console.setColumns(20); |
|
100 |
// console.setRows(5); |
|
101 |
console.setBackground(Color.WHITE); |
|
102 |
console.setLineWrap(true); |
|
103 |
console.setWrapStyleWord(true); |
|
104 |
|
|
105 |
JScrollPane consoleScrollPane = new JScrollPane(console); |
|
106 |
add(consoleScrollPane, BorderLayout.CENTER); |
|
107 |
|
|
108 |
pipedis = new PipedInputStream(); |
|
109 |
|
|
110 |
pipedos = new PipedOutputStream(pipedis); |
|
111 |
|
|
112 |
printStream = new PrintStream(pipedos); |
|
113 |
consoleThread = new ConsoleThread(pipedis, console); |
|
114 |
consoleThread.start(); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Returns a {@link PrintStream} which allows to write messages to the |
|
119 |
* console. |
|
120 |
* |
|
121 |
* @return a {@link PrintStream} which allows to write messages to the |
|
122 |
* console |
|
123 |
*/ |
|
124 |
public PrintStream getPrintStream() { |
|
125 |
return printStream; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Returns a {@link PrintStream} which allows to write error messages to the |
|
130 |
* console. |
|
131 |
* |
|
132 |
* @return a {@link PrintStream} which allows to write error messages to the |
|
133 |
* console |
|
134 |
*/ |
|
135 |
public PrintStream getErrorPrintStream() { |
|
136 |
return getPrintStream(); |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Closes the console. Once this method is called, any more calls to the |
|
141 |
* console {@link PrintStream} will throw an exception. |
|
142 |
*/ |
|
143 |
public void closeConsole() { |
|
144 |
printStream.flush(); |
|
145 |
printStream.close(); |
|
146 |
try { |
|
147 |
pipedos.close(); |
|
148 |
pipedis.close(); |
|
149 |
// Wait for the thread to finish |
|
150 |
consoleThread.join(500); |
|
151 |
} catch (IOException e) { |
|
152 |
LOG.warn("Error closing the internal piped streams", e); |
|
153 |
} catch (InterruptedException e) { |
|
154 |
// Nothing special to do |
|
155 |
LOG.debug("Console thread interrupted while waiting to finish", e); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
private static final class ConsoleThread extends Thread { |
|
160 |
|
|
161 |
private final PipedInputStream pipedis; |
|
162 |
private final JTextArea console; |
|
163 |
|
|
164 |
/** |
|
165 |
* Constructor. |
|
166 |
*/ |
|
167 |
public ConsoleThread(PipedInputStream pipedis, JTextArea console) { |
|
168 |
super("Create plugin console update thread"); |
|
169 |
setDaemon(true); |
|
170 |
this.pipedis = pipedis; |
|
171 |
this.console = console; |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public void run() { |
|
176 |
try { |
|
177 |
BufferedReader reader = new BufferedReader( |
|
178 |
new InputStreamReader(pipedis)); |
|
179 |
String line; |
|
180 |
while ((line = reader.readLine()) != null) { |
|
181 |
SwingUtilities.invokeLater(new ConsoleUpdateRunnable( |
|
182 |
console, line)); |
|
183 |
} |
|
184 |
LOG.debug("Console input stream end, finish reading"); |
|
185 |
reader.close(); |
|
186 |
} catch (IOException e) { |
|
187 |
LOG.warn("Error reading from the console string", e); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Runnable used to update the console text field. |
|
195 |
* |
|
196 |
* @author gvSIG Team |
|
197 |
* @version $Id$ |
|
198 |
*/ |
|
199 |
private static final class ConsoleUpdateRunnable implements Runnable { |
|
200 |
private final String newLine; |
|
201 |
private final JTextArea console; |
|
202 |
|
|
203 |
/** |
|
204 |
* Constructor. |
|
205 |
*/ |
|
206 |
public ConsoleUpdateRunnable(JTextArea console, String newLine) { |
|
207 |
this.console = console; |
|
208 |
this.newLine = newLine; |
|
209 |
} |
|
210 |
|
|
211 |
public void run() { |
|
212 |
console.append(newLine); |
|
213 |
console.append("\n"); |
|
214 |
} |
|
215 |
} |
|
216 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/java/org/gvsig/mkmvnproject/gui/CreatePluginConsoleWindow.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.mkmvnproject.gui; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.io.IOException; |
|
26 |
|
|
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindowListener; |
|
29 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
30 |
|
|
31 |
/** |
|
32 |
* A gvSIG window which shows the execution log messages of the create plugin |
|
33 |
* process. |
|
34 |
* |
|
35 |
* @author gvSIG Team |
|
36 |
* @version $Id$ |
|
37 |
*/ |
|
38 |
public class CreatePluginConsoleWindow extends CreatePluginConsolePanel |
|
39 |
implements IWindow, IWindowListener { |
|
40 |
|
|
41 |
private static final long serialVersionUID = -5589080107545290284L; |
|
42 |
|
|
43 |
private WindowInfo info; |
|
44 |
|
|
45 |
private Object profile = WindowInfo.EDITOR_PROFILE; |
|
46 |
|
|
47 |
/** |
|
48 |
* Constructor. |
|
49 |
* |
|
50 |
* @throws IOException |
|
51 |
* if there is an error creating the console streams |
|
52 |
*/ |
|
53 |
public CreatePluginConsoleWindow() throws IOException { |
|
54 |
super(); |
|
55 |
initializeWindow(); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Constructor. |
|
60 |
* |
|
61 |
* @param isDoubleBuffered |
|
62 |
* if the panel must be double buffered. |
|
63 |
* @throws IOException |
|
64 |
* if there is an error creating the console streams |
|
65 |
*/ |
|
66 |
public CreatePluginConsoleWindow(boolean isDoubleBuffered) throws IOException { |
|
67 |
super(isDoubleBuffered); |
|
68 |
initializeWindow(); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Initializes the window. |
|
73 |
*/ |
|
74 |
private void initializeWindow() { |
|
75 |
Dimension dimension = new Dimension(600, 300); |
|
76 |
setSize(dimension); |
|
77 |
int code = WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE |
|
78 |
| WindowInfo.RESIZABLE | WindowInfo.MODELESSDIALOG; |
|
79 |
profile = WindowInfo.EDITOR_PROFILE; |
|
80 |
info = new WindowInfo(code); |
|
81 |
info.setTitle("Console"); |
|
82 |
info.setMinimumSize(dimension); |
|
83 |
} |
|
84 |
|
|
85 |
public WindowInfo getWindowInfo() { |
|
86 |
return info; |
|
87 |
} |
|
88 |
|
|
89 |
public Object getWindowProfile() { |
|
90 |
return profile; |
|
91 |
} |
|
92 |
|
|
93 |
public void windowActivated() { |
|
94 |
// Nothing to do |
|
95 |
} |
|
96 |
|
|
97 |
public void windowClosed() { |
|
98 |
super.closeConsole(); |
|
99 |
} |
|
100 |
|
|
101 |
} |
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/java/org/gvsig/mkmvnproject/MakeMavenProjectExtension.java | ||
---|---|---|
41 | 41 |
import org.gvsig.andami.plugins.Extension; |
42 | 42 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
43 | 43 |
import org.gvsig.i18n.Messages; |
44 |
import org.gvsig.mkmvnproject.gui.CreatePluginConsoleWindow; |
|
45 |
import org.gvsig.mkmvnproject.gui.settings.PlatformPropertiesWindow; |
|
44 | 46 |
|
45 | 47 |
/** |
46 | 48 |
* Extension to launch the project creation from templates. |
... | ... | |
54 | 56 |
private static final String ANT_CHECK_JDK = "checkjdk.xml"; |
55 | 57 |
|
56 | 58 |
private static final String ANT_TARGET = "mkproject"; |
59 |
|
|
60 |
public static final String GVSIG_PLATFORM_PROPERTIES_FILE_NAME = |
|
61 |
".gvsig.platform.properties"; |
|
57 | 62 |
|
58 | 63 |
private static final Logger LOG = LoggerFactory |
59 | 64 |
.getLogger(MakeMavenProjectExtension.class); |
... | ... | |
64 | 69 |
|
65 | 70 |
public void execute(String actionCommand) { |
66 | 71 |
|
67 |
if (!doJdkCheck()) {
|
|
72 |
if (!checkJDK()) {
|
|
68 | 73 |
return; |
69 | 74 |
} |
75 |
|
|
76 |
if (!checkPlatformProperties()) { |
|
77 |
return; |
|
78 |
} |
|
70 | 79 |
|
71 | 80 |
// ========================================================== |
72 | 81 |
// TODO: add support to parallel executions in Andami?? |
... | ... | |
100 | 109 |
} |
101 | 110 |
|
102 | 111 |
/** |
112 |
* Checks existence of file: |
|
113 |
* |
|
114 |
* USER_HOME/.gvsig.platform.properties |
|
115 |
* |
|
116 |
* If not present, show text area with suggested content. |
|
117 |
* |
|
118 |
* @return whether the mentioned file is present or the |
|
119 |
* user has created it here and accepts to continue. |
|
120 |
* |
|
121 |
*/ |
|
122 |
private boolean checkPlatformProperties() { |
|
123 |
|
|
124 |
String user_home = System.getProperty("user.home"); |
|
125 |
File the_file = new File( |
|
126 |
user_home + |
|
127 |
File.separator + |
|
128 |
GVSIG_PLATFORM_PROPERTIES_FILE_NAME); |
|
129 |
|
|
130 |
Component parent_window = getActiveWindowComponent(); |
|
131 |
|
|
132 |
try { |
|
133 |
if (the_file.exists()) { |
|
134 |
// ok file exists |
|
135 |
LOG.info("Found platform properties file: " |
|
136 |
+ the_file.getAbsolutePath()); |
|
137 |
return true; |
|
138 |
} |
|
139 |
|
|
140 |
boolean is_windows = isThisWindows(); |
|
141 |
PlatformPropertiesWindow ppw = new PlatformPropertiesWindow( |
|
142 |
the_file, is_windows); |
|
143 |
PluginServices.getMDIManager().addCentredWindow(ppw); |
|
144 |
// it's a modal dialog |
|
145 |
return ppw.validSettings(); |
|
146 |
|
|
147 |
} catch (Exception ex) { |
|
148 |
|
|
149 |
String _msg = |
|
150 |
Messages.getText("_Error_while_checking_platform_properties") |
|
151 |
+ "\n\n[ " + ex.getMessage() + " ]"; |
|
152 |
String _tit = Messages.getText( |
|
153 |
"_Checking_platform_properties"); |
|
154 |
JOptionPane.showMessageDialog( |
|
155 |
parent_window, |
|
156 |
_msg, _tit, |
|
157 |
JOptionPane.ERROR_MESSAGE); |
|
158 |
} |
|
159 |
return false; |
|
160 |
|
|
161 |
} |
|
162 |
|
|
163 |
|
|
164 |
/** |
|
165 |
* @return whether we are running on a windows system |
|
166 |
*/ |
|
167 |
private boolean isThisWindows() { |
|
168 |
String os = System.getProperty("os.name").toLowerCase(); |
|
169 |
return (os.indexOf("win") >= 0); |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Check and possibly show JDK and JAVA_HOME settings and |
|
174 |
* prompt user with suggestion. |
|
103 | 175 |
* |
176 |
* @return whether JDK is detected or user accepts to |
|
177 |
* continue anyway |
|
104 | 178 |
*/ |
105 |
private boolean doJdkCheck() {
|
|
179 |
private boolean checkJDK() {
|
|
106 | 180 |
|
107 | 181 |
boolean this_is_jdk = false; |
108 | 182 |
try { |
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/resources/config/text.properties | ||
---|---|---|
12 | 12 |
_On_Windows_run_JDK_use_devel_exe=En Windows, aseg?rese de que gvSIG se ejecuta sobre un JDK y use 'gvsig-desktop-devel.exe' para iniciarlo |
13 | 13 |
_Make_maven_project_plugin=Complemento para crear proyecto maven |
14 | 14 |
_Requirements_for_this_plugin=Requisitos para este plugin |
15 |
_Mandatory_platform_properties_file_not_found=No se ha encontrado el archivo necesario: [USUARIO]/.gvsig.platform.properties |
|
16 |
_Use_this_text_editor_to_write_it=Use este editor de texto para crearlo |
|
17 |
_Cancel=Cancelar |
|
18 |
_Suggested=Ejemplo |
|
19 |
_Accept=Aceptar |
|
20 |
_Save=Guardar |
|
21 |
_Checking_platform_properties=Comprobando propiedades del sistema |
|
22 |
_There_are_unsaved_changes_Continue_question=Hay cambios no guardados. ?Desea continuar? |
|
23 |
_Not_saved=No se ha guardado |
|
24 |
_Unable_to_store_file=No se pudo guardar archivo |
|
25 |
_Error=Error |
|
15 | 26 |
|
27 |
|
branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/resources/config/text_en.properties | ||
---|---|---|
12 | 12 |
_On_Windows_run_JDK_use_devel_exe=On Windows, make sure you are running gvSIG on a JDK and start it with 'gvsig-desktop-devel.exe' |
13 | 13 |
_Make_maven_project_plugin=Make maven project plugin |
14 | 14 |
_Requirements_for_this_plugin=Requirements for this plugin |
15 |
_Mandatory_platform_properties_file_not_found=Mandatory file not found: [USER]/.gvsig.platform.properties |
|
16 |
_Use_this_text_editor_to_write_it=Use this text editor to create it |
|
17 |
_Cancel=Cancel |
|
18 |
_Suggested=Example |
|
19 |
_Accept=Accept |
|
20 |
_Save=Save |
|
21 |
_Checking_platform_properties=Checking platform properties |
|
22 |
_There_are_unsaved_changes_Continue_question=There are unsaved changes. Continue anyway? |
|
23 |
_Not_saved=Not saved |
|
24 |
_Unable_to_store_file=Unable to store file |
|
25 |
_Error=Error |
Also available in: Unified diff