Revision 10819
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramIncrement.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.rastertools.histogram.ui; |
20 | 20 |
|
21 |
import java.awt.Dimension; |
|
22 |
import java.awt.FlowLayout; |
|
23 |
import java.awt.Toolkit; |
|
24 |
|
|
25 |
import javax.swing.JFrame; |
|
26 |
import javax.swing.JLabel; |
|
27 |
import javax.swing.JPanel; |
|
28 |
|
|
29 | 21 |
import org.cresques.i18n.Messages; |
22 |
import org.gvsig.gui.beans.progressPanel.ProgressPanel; |
|
30 | 23 |
import org.gvsig.rastertools.histogram.Histogram; |
31 | 24 |
/** |
32 | 25 |
* <code>HistogramIncrement</code>. Ventana de incremento para la construcci?n |
... | ... | |
39 | 32 |
public class HistogramIncrement extends Thread { |
40 | 33 |
private HistogramPanelListener histogramPanelListener = null; |
41 | 34 |
|
42 |
private JPanel panel = null; |
|
43 |
private JLabel label = null; |
|
44 |
private JFrame window = new JFrame(); |
|
35 |
private ProgressPanel window = new ProgressPanel(); |
|
45 | 36 |
|
46 | 37 |
/** |
47 | 38 |
* Constructor del <code>HistogramIncrement</code>. |
... | ... | |
56 | 47 |
* histograma. |
57 | 48 |
*/ |
58 | 49 |
public void showWindow(){ |
59 |
window.getContentPane().add(getJPanel()); |
|
60 |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); |
|
61 |
window.setLocation( ((int)d.getWidth()) >> 1, |
|
62 |
((int)d.getHeight()) >> 1); |
|
63 |
window.setSize(200, 60); |
|
50 |
window.setTitle("Actualizando datos"); |
|
51 |
window.showLog(true); |
|
64 | 52 |
window.show(); |
53 |
|
|
65 | 54 |
if(this.isAlive()) |
66 | 55 |
this.resume(); |
67 | 56 |
else |
... | ... | |
69 | 58 |
} |
70 | 59 |
|
71 | 60 |
/** |
72 |
* Obtiene el panel del interior de la ventana de incremento |
|
73 |
* @return JPanel |
|
74 |
*/ |
|
75 |
private JPanel getJPanel(){ |
|
76 |
if (panel == null){ |
|
77 |
FlowLayout f = new FlowLayout(); |
|
78 |
panel = new JPanel(); |
|
79 |
panel.setLayout(f); |
|
80 |
label = new JLabel(); |
|
81 |
label.setText(Messages.getText("calculando... ") + 0 + "%"); |
|
82 |
panel.add(label, null); |
|
83 |
} |
|
84 |
return panel; |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 | 61 |
* Este thread va leyendo el porcentaje hasta que se completa el histograma. |
89 | 62 |
*/ |
90 | 63 |
public synchronized void run(){ |
91 | 64 |
while(true){ |
92 | 65 |
Histogram hist = this.getHistogramPanelListener().getHistogram(); |
93 | 66 |
while (hist.getPercent() < 100){ |
94 |
label.setText(Messages.getText("calculando ...") + hist.getPercent() +"%"); |
|
67 |
window.setLabel(Messages.getText("calculando ...") + hist.getPercent() +"%"); |
|
68 |
window.setPercent(hist.getPercent()); |
|
95 | 69 |
try { |
96 | 70 |
sleep(100); |
97 | 71 |
} catch (InterruptedException e) { |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramPanelListener.java | ||
---|---|---|
39 | 39 |
* @author Nacho Brodin (brodin_ign@gva.es) |
40 | 40 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
41 | 41 |
*/ |
42 |
public class HistogramPanelListener implements FocusListener, KeyListener, MouseListener, ActionListener, MouseMotionListener{
|
|
42 |
public class HistogramPanelListener implements ActionListener, KeyListener, FocusListener {
|
|
43 | 43 |
|
44 | 44 |
private HistogramPanel panel = null; |
45 | 45 |
/** |
46 | 46 |
* Objeto histograma para la gesti?n de procesos de histograma |
47 | 47 |
*/ |
48 |
private Histogram histogramObj = null;
|
|
48 |
private Histogram histogram = null; |
|
49 | 49 |
/** |
50 | 50 |
* ?ltimo histograma visualizado en el gr?fico |
51 | 51 |
*/ |
... | ... | |
67 | 67 |
panel.getGraphicContainer().getTextControlRight().addFocusListener(this); |
68 | 68 |
panel.getGraphicContainer().getTextControlLeft().addFocusListener(this); |
69 | 69 |
} |
70 |
|
|
71 |
public void mouseDragged(MouseEvent e) { |
|
72 |
|
|
73 |
} |
|
74 | 70 |
|
75 |
public void mousePressed(MouseEvent e) { |
|
76 |
|
|
77 |
} |
|
78 |
|
|
79 |
public void mouseReleased(MouseEvent e) { |
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
public void setLabels(JLabel left, JLabel right){ |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
public void mouseMoved(MouseEvent e) { |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
private void initialize(){ |
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 | 71 |
public void actionPerformed(ActionEvent e) { |
96 | 72 |
/* |
97 | 73 |
//-------------------------------------- |
... | ... | |
164 | 140 |
*/ |
165 | 141 |
} |
166 | 142 |
|
167 |
public void tableChanged(TableModelEvent e) { |
|
168 |
|
|
169 |
} |
|
170 |
|
|
171 |
public void mouseClicked(MouseEvent e) { |
|
172 |
|
|
173 |
} |
|
174 |
|
|
175 |
public void mouseEntered(MouseEvent e) { |
|
176 |
|
|
177 |
} |
|
178 |
|
|
179 |
public void mouseExited(MouseEvent e) { |
|
180 |
|
|
181 |
} |
|
182 |
|
|
183 | 143 |
/** |
184 | 144 |
* Obtiene el ?ltimo histograma visualizado |
185 | 145 |
* @return |
... | ... | |
192 | 152 |
* Asigna el objeto histograma para la gesti?n de procesos de histograma |
193 | 153 |
* @param histogramObj |
194 | 154 |
*/ |
195 |
public void setHistogram(Histogram histogramObj) {
|
|
196 |
this.histogramObj = histogramObj;
|
|
155 |
public void setHistogram(Histogram histogram) { |
|
156 |
this.histogram = histogram;
|
|
197 | 157 |
} |
198 | 158 |
|
199 | 159 |
/** |
... | ... | |
203 | 163 |
*/ |
204 | 164 |
public void readFullHistogramFromThread(){ |
205 | 165 |
if (panel.getType() == 0) |
206 |
lastHistogram = histogramObj.getFullHistogram();
|
|
166 |
lastHistogram = getHistogram().getFullHistogram();
|
|
207 | 167 |
else if(panel.getType() == 1) |
208 |
lastHistogram = histogramObj.getFullAccumulatedHistogram();
|
|
168 |
lastHistogram = getHistogram().getFullAccumulatedHistogram();
|
|
209 | 169 |
|
210 | 170 |
/* setStatistic(Statistic.getBasicStatsFromHistogram( lastHistogram, |
211 | 171 |
(int)getBoxesValues()[1], |
... | ... | |
255 | 215 |
* @return |
256 | 216 |
*/ |
257 | 217 |
public Histogram getHistogram() { |
258 |
return histogramObj;
|
|
218 |
return histogram; |
|
259 | 219 |
} |
260 | 220 |
|
261 | 221 |
public void keyPressed(KeyEvent e) { |
... | ... | |
269 | 229 |
} |
270 | 230 |
|
271 | 231 |
public void keyReleased(KeyEvent e) { |
232 |
// TODO Auto-generated method stub |
|
233 |
|
|
272 | 234 |
} |
273 | 235 |
|
274 | 236 |
public void keyTyped(KeyEvent e) { |
237 |
// TODO Auto-generated method stub |
|
238 |
|
|
275 | 239 |
} |
276 | 240 |
|
277 | 241 |
public void focusGained(FocusEvent e) { |
242 |
// TODO Auto-generated method stub |
|
243 |
|
|
278 | 244 |
} |
279 | 245 |
|
280 | 246 |
public void focusLost(FocusEvent e) { |
247 |
// TODO Auto-generated method stub |
|
248 |
|
|
281 | 249 |
} |
282 | 250 |
} |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramDialog.java | ||
---|---|---|
19 | 19 |
package org.gvsig.rastertools.histogram.ui; |
20 | 20 |
|
21 | 21 |
import java.awt.BorderLayout; |
22 |
import java.io.IOException; |
|
23 | 22 |
|
24 | 23 |
import javax.swing.JPanel; |
25 | 24 |
|
... | ... | |
51 | 50 |
public HistogramPanel getHistogramPanel(){ |
52 | 51 |
if(histogramPanel == null){ |
53 | 52 |
histogramPanel = new HistogramPanel(); |
54 |
// histogramPanel.getBCreateTable().addActionListener(histogramPanel);
|
|
53 |
// TODO: A?adir los eventos para cerrar la ventana
|
|
55 | 54 |
} |
56 | 55 |
return histogramPanel; |
57 | 56 |
} |
58 |
/* |
|
59 |
public void actionPerformed(ActionEvent e) { |
|
60 |
|
|
61 |
//Bot?n de cerrar |
|
62 |
if(e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CLOSE + "") == 0){ |
|
63 |
try{ |
|
64 |
PluginServices.getMDIManager().closeWindow(this); |
|
65 |
}catch(ArrayIndexOutOfBoundsException ex){ |
|
66 |
//Si la ventana no se puede eliminar no hacemos nada |
|
67 |
} |
|
68 |
} |
|
69 |
// -------------------------------------- |
|
70 |
//Bot?n Crear tabla. |
|
71 |
JButton table = histogramPanel.getBCreateTable(); |
|
72 |
if(e.getSource() == table){ |
|
73 | 57 |
|
74 |
try { |
|
75 |
// -------Mostrar un fileChooser------------------ |
|
76 |
String fName; |
|
77 |
JFileChooser chooser = new JFileChooser(); |
|
78 |
chooser.setDialogTitle(PluginServices.getText(this, "guardar_tabla")); |
|
79 |
|
|
80 |
int returnVal = chooser.showOpenDialog(this); |
|
81 |
if(returnVal == JFileChooser.APPROVE_OPTION){ |
|
82 |
fName = chooser.getSelectedFile().toString(); |
|
83 |
if(!fName.endsWith(".dbf")) |
|
84 |
fName += ".dbf"; |
|
85 |
|
|
86 |
//-------------Crear el dbf---------------------- |
|
87 |
|
|
88 |
DbaseFileWriterNIO dbfWrite = null; |
|
89 |
DbaseFileHeaderNIO myHeader; |
|
90 |
Value[] record; |
|
91 |
|
|
92 |
int histogram[][]=histogramPanel.getLastHistogram(); |
|
93 |
int numBands = histogram.length; |
|
94 |
int numRecors = histogram[0].length; |
|
95 |
|
|
96 |
File file = new File(fName); |
|
97 |
|
|
98 |
String names[] = new String[numBands+1]; |
|
99 |
int types[] = new int [numBands+1]; |
|
100 |
int lengths[] = new int [numBands+1]; |
|
101 |
|
|
102 |
names[0]="Value"; |
|
103 |
types[0]=4; |
|
104 |
lengths[0]=15; |
|
105 |
for (int band = 0; band < numBands; band++){ |
|
106 |
names[band+1]="Band"+band; |
|
107 |
types[band+1]=4; |
|
108 |
lengths[band+1]=15; |
|
109 |
} |
|
110 |
|
|
111 |
myHeader = DbaseFileHeaderNIO.createDbaseHeader(names,types,lengths); |
|
112 |
|
|
113 |
myHeader.setNumRecords(numRecors); |
|
114 |
dbfWrite = new DbaseFileWriterNIO(myHeader, |
|
115 |
(FileChannel) getWriteChannel(file.getPath())); |
|
116 |
record = new Value[numBands+1]; |
|
117 |
|
|
118 |
for (int j = 0; j < numRecors; j++) { |
|
119 |
record[0] = ValueFactory.createValue(j); |
|
120 |
for (int r = 0; r < numBands; r++) { |
|
121 |
record[r+1] = ValueFactory.createValue(histogram[r][j]); |
|
122 |
} |
|
123 |
|
|
124 |
dbfWrite.write(record); |
|
125 |
} |
|
126 |
|
|
127 |
dbfWrite.close(); |
|
128 |
|
|
129 |
//------------A?adir el dbf al proyecto-------------- |
|
130 |
ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
|
131 |
String name = file.getName(); |
|
132 |
LayerFactory.getDataSourceFactory().addFileDataSource("gdbms dbf driver", name, fName); |
|
133 |
DataSource dataSource; |
|
134 |
dataSource = LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_OPENING); |
|
135 |
|
|
136 |
SelectableDataSource sds = new SelectableDataSource(dataSource); |
|
137 |
EditableAdapter auxea=new EditableAdapter(); |
|
138 |
auxea.setOriginalDataSource(sds); |
|
139 |
ProjectTable projectTable = ProjectFactory.createTable(name, auxea); |
|
140 |
//ext.getProject().addTable(projectTable); |
|
141 |
ext.getProject().addDocument(projectTable); |
|
142 |
|
|
143 |
Table t = new Table(); |
|
144 |
t.setModel(projectTable); |
|
145 |
//projectTable.setAndamiWindow(t); |
|
146 |
PluginServices.getMDIManager().addWindow(t); |
|
147 |
} |
|
148 |
} catch (DriverLoadException e1) { |
|
149 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " + |
|
150 |
PluginServices.getText(this,"table_not_create")); |
|
151 |
NotificationManager.addError(e1); |
|
152 |
} catch (NoSuchTableException e1) { |
|
153 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " + |
|
154 |
PluginServices.getText(this,"table_not_create")); |
|
155 |
NotificationManager.addError(e1); |
|
156 |
} catch (ReadDriverException e1) { |
|
157 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " + |
|
158 |
PluginServices.getText(this,"table_not_create")); |
|
159 |
NotificationManager.addError(e1); |
|
160 |
}catch (IOException ex) { |
|
161 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " + |
|
162 |
PluginServices.getText(this,"table_not_create")); |
|
163 |
NotificationManager.addError("Error al crear un DbaseFileHeaderNIO", ex); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
//-------------------------------------- |
|
168 |
} |
|
169 |
*/ |
|
170 |
/** |
|
171 |
* |
|
172 |
* @param path |
|
173 |
* @return |
|
174 |
* @throws IOException |
|
175 |
*/ |
|
176 |
/* |
|
177 |
private WritableByteChannel getWriteChannel(String path)throws IOException { |
|
178 |
WritableByteChannel channel; |
|
179 |
|
|
180 |
File f = new File(path); |
|
181 |
|
|
182 |
if (!f.exists()) { |
|
183 |
System.out.println("Creando fichero " + f.getAbsolutePath()); |
|
184 |
|
|
185 |
if (!f.createNewFile()) { |
|
186 |
throw new IOException("Cannot create file " + f); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
RandomAccessFile raf = new RandomAccessFile(f, "rw"); |
|
191 |
channel = raf.getChannel(); |
|
192 |
|
|
193 |
return channel; |
|
194 |
} |
|
195 |
*/ |
|
196 |
|
|
197 | 58 |
public WindowInfo getWindowInfo() { |
198 | 59 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
199 | 60 |
m_viewinfo.setTitle(PluginServices.getText(this, "histograma")); |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramPanel.java | ||
---|---|---|
45 | 45 |
public class HistogramPanel extends DialogPanel { |
46 | 46 |
private static final long serialVersionUID = 2772897994667886753L; |
47 | 47 |
|
48 |
|
|
49 | 48 |
private HistogramPanelListener histogramPanelListener = null; |
50 |
|
|
51 | 49 |
|
52 | 50 |
public static int MAXBANDS = 10; |
53 | 51 |
private int HSUP = 60; |
Also available in: Unified diff