Revision 10819 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramDialog.java

View differences:

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"));

Also available in: Unified diff