Revision 6566

View differences:

org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.swing.impl.RasterSwingImplLibrary
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/resources/org/gvsig/raster/swing/impl/i18n/text.properties
1
delete_roi_file=Elimina todas las ROI de la capa. El fichero vectorial no es borrado, solo su relaci?n con la capa r?ster.
2
cargar_rois=Cargar ROIs de un fichero shp
0 3

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/resources/org/gvsig/raster/swing/impl/i18n/text_en.properties
1
delete_roi_file=Removes all ROI from the layer. The vectorial file is not deleted, just the relation with the raster layer.
2
cargar_rois=Load ROIs from shp file
0 3

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/buttonbar/ButtonBarContainerImpl.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.raster.swing.impl.buttonbar;
23

  
24
import java.awt.FlowLayout;
25
import java.util.ArrayList;
26

  
27
import javax.swing.JButton;
28
import javax.swing.JPanel;
29

  
30
import org.gvsig.andami.IconThemeHelper;
31
import org.gvsig.raster.swing.buttonbar.ButtonBar;
32

  
33
public class ButtonBarContainerImpl extends JPanel implements ButtonBar {
34
	private static final long serialVersionUID = -2556987128553063939L;
35

  
36
	private ArrayList<JButton> buttons = new ArrayList<JButton>();
37

  
38
	private int       wComp              = 400;
39
	private int       hComp              = 26;
40
	private boolean   disableAllControls = false;
41
	private boolean[] buttonsState       = null;
42

  
43

  
44
	/**
45
	 * This is the default constructor
46
	 */
47
	public ButtonBarContainerImpl() {
48
		super();
49
		initialize();
50
	}
51

  
52
	/**
53
	 * This method initializes this
54
	 *
55
	 * @return void
56
	 */
57
	private void initialize() {
58
		FlowLayout flowLayout = new FlowLayout();
59
		flowLayout.setHgap(0);
60
		flowLayout.setVgap(0);
61
		this.setLayout(flowLayout);
62
		this.setSize(wComp, hComp);
63
		}
64

  
65

  
66
	/**
67
	 * A?ade un boton al ArrayList de los botones.
68
	 *
69
	 * @param iconName: nombre del icono asignado al boton. La imagen tendr?a que
70
	 * 					estar dentro de la carpeta "images/"
71
	 * @param tip: tip del boton;
72
	 * @param order: orden que ocupar? el boton dentro del control
73
	 */
74
	public void addButton(String iconName, String tip, int order) {
75
		JButton bt = new JButton();
76

  
77
		bt.setPreferredSize(new java.awt.Dimension(22, 22));
78
		try{
79
			if (iconName != null)
80
				bt.setIcon(IconThemeHelper.getImageIcon(iconName));
81
		}catch(NullPointerException exc){
82
			//El icono no existe -> No se a?ade ninguno
83
		}
84

  
85
		if(tip != null)
86
			bt.setToolTipText(tip);
87

  
88
		buttons.add(order, bt);
89
		addList();
90

  
91
	}
92

  
93
	/**
94
	 * Elimina el bot?n correspondiente al indice que le pasamos.
95
	 * @param index
96
	 */
97
	public void delButton(int index){
98
		buttons.remove(index);
99
		this.removeAll();
100
		addList();
101
	}
102

  
103
	/**
104
	 * A?ade en el panel los botones que tenemos en el ArrayList.
105
	 *
106
	 */
107
	public void addList(){
108
		for(int i = 0 ; i < buttons.size() ; i++){
109
			this.add((JButton)buttons.get(i));
110
		}
111
	}
112

  
113

  
114
	/**
115
	 * Esta funci?n deshabilita todos los controles y guarda sus valores
116
	 * de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
117
	 * se vuelvan a quedar como estaba
118
	 */
119
	public void disableAllControls(){
120
		if(!disableAllControls){
121
			disableAllControls = true;
122

  
123
			buttonsState = new boolean[buttons.size()];
124

  
125

  
126

  
127
			for (int i = 0 ; i < buttons.size() ; i++){
128

  
129
				//Salvamos los estados
130
				buttonsState[i] = ((JButton)buttons.get(i)).isEnabled();
131
				//Desactivamos controles
132
				((JButton)buttons.get(i)).setEnabled(false);
133
			}
134
		}
135
	}
136

  
137
	/**
138
	 * Esta funci?n deja los controles como estaban al ejecutar la funci?n
139
	 * disableAllControls
140
	 */
141
	public void restoreControlsValue(){
142
		if(disableAllControls){
143
			disableAllControls = false;
144

  
145
			for(int i = 0 ; i < buttons.size() ; i++){
146
				((JButton)buttons.get(i)).setEnabled(buttonsState[i]);
147
			}
148
		}
149
	}
150

  
151
	/**
152
	 * M?todo para acceder a los botones del control;
153
	 * @param index
154
	 * @return
155
	 */
156
	public JButton getButton(int index){
157
		return (JButton)buttons.get(index);
158
	}
159

  
160
	/**
161
	 * M?todo para establecer la posici?n de los botones dentro del control.
162
	 * @param align: "left" o "right"
163
	 */
164
	public void setButtonAlignment(String align){
165
		FlowLayout layout = new FlowLayout();
166
		layout.setHgap(2);
167
		layout.setVgap(0);
168

  
169
		if (align.equals("right"))
170
			layout.setAlignment(FlowLayout.RIGHT);
171
		else
172
			layout.setAlignment(FlowLayout.LEFT);
173

  
174
		this.setLayout(layout);
175
	}
176

  
177
	public void setComponentBorder(boolean br){
178
		if(br)
179
			this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
180
		if(!br)
181
			this.setBorder(javax.swing.BorderFactory.createEmptyBorder());
182
	}
183

  
184
}
0 185

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/openfile/OpenFileContainerImpl.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.raster.swing.impl.openfile;
23

  
24
import java.awt.Dimension;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.io.File;
28
import java.util.List;
29

  
30
import javax.swing.ImageIcon;
31
import javax.swing.JButton;
32
import javax.swing.JPanel;
33
import javax.swing.JTextField;
34

  
35
import org.gvsig.andami.IconThemeHelper;
36
import org.gvsig.gui.beans.Messages;
37
import org.gvsig.raster.swing.openfile.OpenFileContainer;
38

  
39
/**
40
 * Implementation of a open file panel
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class OpenFileContainerImpl extends JPanel implements OpenFileContainer {
44
	private static final long       serialVersionUID = 5823371652872582451L;
45

  
46
	private JButton                 jButton          = null;
47
	private JTextField              tOpen            = null;
48
	private OpenFileListener        listener         = null;
49
	private boolean                 showBorder       = true;
50
	
51
	private boolean isButtonVisible = true;
52
	
53
	public OpenFileContainerImpl(boolean showBorder, String[] fileFilter, String defaultPath) {
54
		this.showBorder = showBorder;
55
		listener = new OpenFileListener(this, fileFilter, defaultPath);
56
		initialize();
57
		listener.setButton(this.getJButton());
58
	}
59
	
60
	public OpenFileContainerImpl(boolean showBorder, List<String> fileFilter, String defaultPath) {
61
		this(showBorder, (String[])fileFilter.toArray(new String[0]), defaultPath);
62
		listener.setButton(this.getJButton());
63
	}
64

  
65
	/**
66
	 * This method initializes this
67
	 *
68
	 */
69
	private void initialize() {
70
		this.setLayout(new GridBagLayout());
71
		if(showBorder)
72
			this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("open_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
73
		
74
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
75
		gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
76
		gridBagConstraints1.weightx = 1;
77
		gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
78
		
79
		this.add(getTOpen(), gridBagConstraints1);
80
		
81
		gridBagConstraints1.gridx = 1;
82
		gridBagConstraints1.weightx = 0;
83
		
84
		this.add(getJButton(), gridBagConstraints1);
85

  
86
	}
87

  
88
	/**
89
	 * This method initializes jButton
90
	 *
91
	 * @return javax.swing.JButton
92
	 */
93
	private JButton getJButton() {
94
		if (jButton == null) {
95
			ImageIcon icon = null;
96
			try {
97
				icon = IconThemeHelper.getImageIcon("icon-folder-open");
98
			} catch (Exception e) {
99
			}
100
			if(icon == null || icon.getIconWidth() <= 0 || icon.getIconHeight() <= 0) 
101
				icon = new ImageIcon(System.getProperty("user.dir") + "/src/main/resources/images/icon-folder-open.gif", "");
102

  
103
			jButton = new JButton(icon);
104
			jButton.setPreferredSize(new Dimension(22, 22));
105
			jButton.addActionListener(listener);
106
			jButton.setVisible(isButtonVisible);
107
			getTOpen().setEnabled(isButtonVisible);
108
		}
109
		return jButton;
110
	}
111

  
112
	/**
113
	 * This method initializes jTextField
114
	 *
115
	 * @return javax.swing.JTextField
116
	 */
117
	public JTextField getTOpen() {
118
		if (tOpen == null) {
119
			tOpen = new JTextField();
120
			tOpen.setPreferredSize(new Dimension(0, 22));
121
		}
122
		return tOpen;
123
	}
124
	
125
	/*
126
	 * (non-Javadoc)
127
	 * @see org.gvsig.raster.swing.openfile.OpenFileContainer#setPath(java.lang.String)
128
	 */
129
	public void setPath(String path) {
130
		getTOpen().setText(path);
131
	}
132

  
133

  
134
	/**
135
	 * Devuelve el file cuya ruta corresponde con el campo de texto.
136
	 * @return
137
	 */
138
	public File getFile() {
139
		File fil = null;
140
		if(this.getTOpen().getText() != "") {
141
			try {
142
				fil = new File(this.getTOpen().getText());
143
			} catch(Exception exc) {
144
				System.err.println("Ruta o archivo no v?lido");
145
			}
146
		}
147
		return fil;
148
	}
149
	
150
	public void setEnabled(boolean enabled) {
151
		getTOpen().setEnabled(enabled);
152
		getJButton().setEnabled(enabled);
153
	}
154

  
155
}
0 156

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/openfile/OpenFileListener.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.raster.swing.impl.openfile;
23

  
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26
import java.io.File;
27

  
28
import javax.swing.JButton;
29
import javax.swing.JFileChooser;
30

  
31
/**
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public class OpenFileListener implements ActionListener {
35
	private JButton               button        = null;
36
	private String                fName         = null;
37
	private OpenFileContainerImpl controlPanel  = null;
38
	private String[]              fileFilter    = null;
39
	private String                lastDirectory = null;
40
	
41
	public OpenFileListener(OpenFileContainerImpl panel, String[] fileFilter, String lastDirectory) {
42
		this.controlPanel = panel;
43
		this.fileFilter = fileFilter;
44
		this.lastDirectory = lastDirectory;
45
	}
46
	
47
	public void setButton(JButton but) {
48
		this.button = but;
49
	}
50
	
51
	
52
	public void actionPerformed(ActionEvent e) {
53
		if(e.getSource() == this.button) {
54
			JFileChooser file = new JFileChooser();
55
			//file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
56
			file.setDialogTitle("Select File");
57
			if(lastDirectory != null) {
58
				File lastDir = new File(lastDirectory);	
59
				if(lastDir.isDirectory() && lastDir.exists()) {
60
					file.setCurrentDirectory(lastDir);
61
				}
62
				if(!lastDir.isDirectory()) {
63
					lastDir = new File(lastDir.getParent());
64
					if(lastDir.exists())
65
						file.setCurrentDirectory(lastDir);
66
				}
67
			}
68
			
69
			if(fileFilter != null) {
70
				for (int i = 0; i < fileFilter.length; i++) {
71
					file.addChoosableFileFilter(new ReadFilter(file, fileFilter[i]));					
72
				}
73
				int returnVal = file.showOpenDialog(controlPanel);
74
				if(returnVal == JFileChooser.APPROVE_OPTION) {
75
					lastDirectory = file.getSelectedFile().getAbsolutePath();
76
					fName = file.getSelectedFile().toString();
77
					controlPanel.getTOpen().setText(fName);
78
				}
79
			}
80
		}
81

  
82
	}
83

  
84
	public String getFileName(){
85
		return fName;
86
	}
87
}
88

  
89
class ReadFilter extends javax.swing.filechooser.FileFilter{
90

  
91
	JFileChooser chooser = null;
92
	String filter = null;
93
	
94
	public ReadFilter(JFileChooser cho,String fil){
95
		this.chooser = cho;
96
		this.filter = fil;
97
	}
98
	
99
	public boolean accept(File f) {
100
		 return f.isDirectory() || f.getName().toLowerCase().endsWith("."+filter);
101
	}
102

  
103
	public String getDescription() {
104
		return "."+filter;
105
	}
106
	
107
}
0 108

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/openfile/FileTextField.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.raster.swing.impl.openfile;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.event.FocusEvent;
30
import java.awt.event.FocusListener;
31
import java.io.File;
32

  
33
import javax.swing.JButton;
34
import javax.swing.JPanel;
35
import javax.swing.JTextField;
36

  
37
import org.gvsig.gui.beans.Messages;
38
import org.gvsig.gui.beans.swing.JFileChooser;
39
import org.gvsig.raster.swing.openfile.FileFilter;
40

  
41
public class FileTextField extends JPanel {
42
	private static final long serialVersionUID = 1L;
43
	private JTextField tf_fileName = null;
44
	private JButton bt_chooseFile = null;
45
	private File selectedFile = null;
46
	private JFileChooser jfc;
47
	/**
48
	 * Used to create file choosers with 'memory'
49
	 */
50
	private String JFC_ID = null;
51

  
52
	public static final int ACTION_EVENT_FIELD_DISABLED = 0;
53
	public static final int ACTION_EVENT_FIELD_ENABLED = 1;
54
	public static final int ACTION_EVENT_VALUE_CHANGED = 1;
55

  
56
	public FileTextField() {
57
		super();
58
		JFC_ID = this.getClass().getName();
59
		initializeUI();
60
	}
61

  
62
	public FileTextField(String id) {
63
		super();
64
		JFC_ID = id;
65
		initializeUI();
66
	}
67

  
68
	private void initializeUI() {
69
		 jfc = new JFileChooser(JFC_ID, (String) null);
70
		setLayout(new GridBagLayout());
71

  
72
		GridBagConstraints constraints = new GridBagConstraints();
73
		constraints.gridx = 0;
74
		constraints.gridy = 0;
75
		constraints.gridwidth = 1;
76
		constraints.gridheight = 1;
77
		constraints.fill = GridBagConstraints.BOTH;
78
		constraints.anchor = GridBagConstraints.WEST;
79
		constraints.weightx = 1.0;
80
		constraints.weighty = 1.0;
81
		constraints.insets = new Insets(0,0,0,4);
82
		this.add(getNameField(), constraints);
83

  
84
		getChooseFileButton().addActionListener(new ActionListener() {
85

  
86
			public void actionPerformed(ActionEvent e) {
87
				if (e.getSource()==getChooseFileButton()) {
88
					int action = jfc.showDialog(FileTextField.this, Messages.getText("Open"));
89
					if (action == JFileChooser.APPROVE_OPTION) {
90
						setSelectedFile(jfc.getSelectedFile());
91
						setEnabled(true);	
92
					}
93
				}
94
			}
95
		});
96
		constraints.gridx = 1;
97
		constraints.gridy = 0;
98
		constraints.gridwidth = 1;
99
		constraints.gridheight = 1;
100
		constraints.fill = GridBagConstraints.BOTH;
101
		constraints.anchor = GridBagConstraints.WEST;
102
		constraints.weightx = 0.0;
103
		constraints.weighty = 1.0;
104
		constraints.insets = new Insets(0,0,0,0);
105
		this.add(getChooseFileButton(), constraints);
106
	}
107

  
108
	private JTextField getNameField() {
109
		if (tf_fileName==null) {
110
			tf_fileName = new JTextField();
111
			tf_fileName.addFocusListener(new FocusListener() {
112
				public void focusGained(FocusEvent e) {}
113

  
114
				public void focusLost(FocusEvent e) {
115
					updateSelectedFile();
116
				}
117
			});
118
		}
119
		return tf_fileName;
120
	}
121
	
122
	private JButton getChooseFileButton() {
123
		if (bt_chooseFile==null) {
124
			bt_chooseFile = new JButton("...");
125
		}
126
		return bt_chooseFile;
127
	}
128

  
129

  
130
	public void setSelectedFile(File file) {
131
		File oldFile = selectedFile;
132
		selectedFile = normalizeExtension(file);
133
		getNameField().setText(selectedFile.toString());
134
		if (file.isDirectory()) {
135
			jfc.setLastPath(file);
136
		}
137
		else {
138
		    jfc.setSelectedFile(file);
139
            jfc.setLastPath(file.getParentFile());
140
		}
141
		fireValueChanged(oldFile, file);
142
	}
143

  
144
	public File getSelectedFile() {
145
		return updateSelectedFile();
146
	}
147
	
148
	private File normalizeExtension(File file) {
149
		javax.swing.filechooser.FileFilter filter = (javax.swing.filechooser.FileFilter) jfc.getFileFilter();
150
		if (!filter.accept(file)) {
151
			String path = file.getPath();
152
			if (filter instanceof FileFilter)  {
153
				FileFilter ourFilter = (FileFilter) filter;
154
			if (path.endsWith(".")) {
155
				path = path+ourFilter.getDefaultExtension();
156
			}
157
			else {
158
				path = path+"."+ourFilter.getDefaultExtension();
159
			}
160
			file = new File(path);
161
			}
162
		}
163
		return file;	
164
	}
165
	
166
	private File updateSelectedFile() {
167
		File oldFile = selectedFile;
168
		String text = getNameField().getText();
169
		if ( (oldFile!=null && !oldFile.getPath().equals(text))
170
				|| ((oldFile==null) && !text.equals(""))){
171
			File newFile = normalizeExtension(new File(getNameField().getText()));
172
			selectedFile = newFile;
173
			fireValueChanged(oldFile, newFile);
174
		}
175
		return selectedFile;
176
	}
177

  
178
	protected void fireValueChanged(File oldValue, File newValue) {
179
		firePropertyChange("selectedFileChanged", oldValue, newValue);
180
	}
181

  
182
	protected void fireEnabledChanged(boolean oldValue, boolean newValue) {
183
		firePropertyChange("enabled", oldValue, newValue);
184
	}
185

  
186
	public void setEnabled(boolean enabled) {
187
		boolean oldValue = isEnabled();
188
		super.setEnabled(enabled);
189
		getNameField().setEnabled(enabled);
190
        getChooseFileButton().setEnabled(enabled);
191
		fireEnabledChanged(oldValue, enabled);
192
	}
193

  
194
	public javax.swing.filechooser.FileFilter getFileFilter() {
195
		return jfc.getFileFilter();
196
	}
197

  
198
	public int getFileSelectionMode() {
199
		return jfc.getFileSelectionMode();
200
	}
201

  
202
	public boolean removeChoosableFileFilter(FileFilter f) {
203
		return jfc.removeChoosableFileFilter(f);
204
	}
205

  
206
	public void setFileFilter(FileFilter filter) {
207

  
208
		jfc.setFileFilter(filter);
209
		
210
	}
211

  
212
	public void addChoosableFileFilter(FileFilter filter) {
213
		jfc.addChoosableFileFilter(filter);
214
	}
215

  
216
	public FileFilter getAcceptAllFileFilter() {
217
		return (FileFilter) jfc.getAcceptAllFileFilter();
218
	}
219

  
220
	public boolean isAcceptAllFileFilterUsed() {
221
		return jfc.isAcceptAllFileFilterUsed();
222
	}
223

  
224
	public void resetChoosableFileFilters() {
225
		jfc.resetChoosableFileFilters();
226
	}
227

  
228
	public void setAcceptAllFileFilterUsed(boolean b) {
229
		jfc.setAcceptAllFileFilterUsed(b);
230
	}
231
	
232
}
0 233

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/GenericBasePanel.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.raster.swing.impl;
23

  
24
import org.gvsig.raster.swing.BasePanel;
25

  
26
/**
27
 * Clase no abstracta para instanciar un BasePanel generico
28
 * 18/08/2008
29
 * @author Nacho Brodin nachobrodin@gmail.com
30
 */
31
public class GenericBasePanel extends BasePanel {
32
	private static final long serialVersionUID = 1L;
33

  
34
	/*
35
	 * (non-Javadoc)
36
	 * @see org.gvsig.raster.util.BasePanel#init()
37
	 */
38
	protected void init() {
39
	}
40

  
41
	/*
42
	 * (non-Javadoc)
43
	 * @see org.gvsig.raster.util.BasePanel#translate()
44
	 */
45
	protected void translate() {
46
	}	
47
}
0 48

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/canvas/layer/DefaultMinMaxLines.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.raster.swing.impl.canvas.layer;
23

  
24
import java.awt.BasicStroke;
25
import java.awt.Color;
26
import java.awt.Component;
27
import java.awt.Cursor;
28
import java.awt.Graphics;
29
import java.awt.Graphics2D;
30
import java.awt.Stroke;
31
import java.awt.event.MouseEvent;
32
import java.util.List;
33

  
34
import javax.swing.SwingUtilities;
35

  
36
import org.gvsig.raster.swing.gcanvas.DrawableElement;
37
import org.gvsig.raster.swing.gcanvas.MinMaxLines;
38
import org.gvsig.raster.swing.impl.canvas.DefaultGCanvas;
39
import org.gvsig.raster.swing.impl.canvas.layer.function.DefaultBaseFunction;
40

  
41
/**
42
 * Representa dos l?neas rectas que se?alizan el m?ximo y el m?nimo.
43
 *
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 */
46
public class DefaultMinMaxLines extends MinMaxLines {
47
	/**
48
	 * Representa el borde de separacion para los limites
49
	 */
50
	private int     border      = 2;
51

  
52
	private double  minPos      = 0.0D;
53
	private double  maxPos      = 1.0D;
54

  
55
	private boolean minSelected = false;
56
	private boolean maxSelected = false;
57
	
58
	/**
59
	 * Constructor. Asigna el color
60
	 * @param c
61
	 */
62
	public DefaultMinMaxLines(Color c) {
63
		setColor(c);
64
	}
65
	
66
	public void setMinimum(double min) {
67
		this.minPos = min;
68
	}
69
	
70
	public void setMaximum(double max) {
71
		this.maxPos = max;
72
	}
73
	
74
	private int valueToPixel(double value) {
75
		return (int) Math.round(canvas.getCanvasMinX() + border + ((canvas.getCanvasMaxX() - canvas.getCanvasMinX() - (border * 2)) * value));
76
	}
77

  
78
	private double pixelToValue(int pixel) {
79
		return ((double) (pixel - canvas.getCanvasMinX() - border) / (double) (canvas.getCanvasMaxX() - canvas.getCanvasMinX() - (border * 2)));
80
	}
81
	
82
	/**
83
	 * Dibujado de las l?neas y cuadros sobre el canvas
84
	 */
85
	public void paint(Graphics g) {
86
		g.setColor(color);
87
		int y = (int) canvas.getCanvasMinY();
88
		int x1 = valueToPixel(minPos);
89
		int x2 = valueToPixel(maxPos);
90
		Graphics2D g2 = (Graphics2D) g;
91
		float dash1[] = {10.0f};
92
		BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
93
		Stroke stroke2 = g2.getStroke();
94
		g2.setStroke(stroke);
95

  
96
		g2.drawLine(x1, y, x1, canvas.getCanvasMaxY());
97
		g2.drawLine(x2, y, x2, canvas.getCanvasMaxY());
98

  
99
		g2.setStroke(stroke2);
100
	}
101

  
102
	/**
103
	 * Asigna el objeto JComponent donde se pintan los elementos. Inicializa los puntos
104
	 * de inicio y fin de l?nea y asigna los listener
105
	 * @param canvas
106
	 */
107
	public void setCanvas(DefaultGCanvas canvas) {
108
		super.setCanvas(canvas);
109
	}
110
	
111
	/**
112
	 * Se captura el punto a arrastrar
113
	 */
114
	public boolean mousePressed(MouseEvent e) {
115
		if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0)
116
			return true;
117

  
118
		if (e.getY() > canvas.getCanvasMinY() && e.getY() < canvas.getCanvasMaxY()) {
119
			if (e.getX() >= (valueToPixel(minPos) - 3) && e.getX() <= (valueToPixel(minPos) + 3)) {
120
				minSelected = true;
121
				return false;
122
			}
123
			if (e.getX() >= (valueToPixel(maxPos) - 3) && e.getX() <= (valueToPixel(maxPos) + 3)) {
124
				maxSelected = true;
125
				return false;
126
			}
127
		}
128
		return true;
129
	}
130

  
131
	/**
132
	 * Inicializamos el punto arrastrado a un valor fuera del array
133
	 */
134
	public boolean mouseReleased(MouseEvent e) {
135
		if (canvas != null && (minSelected != false || maxSelected != false )) {
136
			((Component)canvas).repaint();
137
			canvas.callDataChanged("minmax", this);
138
		}
139
		minSelected = false;
140
		maxSelected = false;
141
		return true;
142
	}
143

  
144
	/**
145
	 * Cuando se ha pinchado un punto y se arrastra se define aqu? su comportamiento.
146
	 */
147
	public boolean mouseDragged(MouseEvent e) {
148
		if (canvas == null)
149
			return true;
150

  
151
		if (minSelected) {
152
			minPos = pixelToValue(e.getX());
153
			if (minPos < 0)
154
				minPos = 0;
155
			if (minPos > 1.0)
156
				minPos = 1.0;
157
			if (minPos > maxPos)
158
				maxPos = minPos;
159
			
160
			updateDrawableElements();
161
			return false;
162
		}
163
		if (maxSelected) {
164
			maxPos = pixelToValue(e.getX());
165
			if (maxPos < 0)
166
				maxPos = 0;
167
			if (maxPos > 1.0)
168
				maxPos = 1.0;
169
			if (maxPos < minPos)
170
				minPos = maxPos;
171
			
172
			updateDrawableElements();
173
			return false;
174
		}
175
		return true;
176
	}
177
	
178
	private void updateDrawableElements() {
179
		List<DrawableElement> elements = canvas.getDrawableElements(DefaultBaseFunction.class);
180
		if (elements.size() > 0) {
181
			DefaultBaseFunction baseFunction = (DefaultBaseFunction) elements.get(0);
182
			baseFunction.setMinX(minPos);
183
			baseFunction.setMaxX(maxPos);
184
		}
185
		
186
		((Component)canvas).repaint();
187
		SwingUtilities.invokeLater(new Runnable() {
188
			public void run() {
189
				canvas.callDataDragged("minmax", this);
190
			}
191
		});
192
	}
193
	
194
	public boolean mouseMoved(MouseEvent e) {
195
		if (e.getY() > canvas.getCanvasMinY() && e.getY() < canvas.getCanvasMaxY()) {
196
			if (e.getX() >= (valueToPixel(minPos) - 3) &&
197
					e.getX() <= (valueToPixel(minPos) + 3)) {
198
				((Component)canvas).setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
199
				return false;
200
			}
201
			if (e.getX() >= (valueToPixel(maxPos) - 3) &&
202
					e.getX() <= (valueToPixel(maxPos) + 3)) {
203
				((Component)canvas).setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
204
				return false;
205
			}
206
		}
207
		return true;
208
	}
209
	
210
	/**
211
	 * Obtiene la distancia de la l?nea del m?nimo al inicio del histograma. La 
212
	 * distancia la devuelve en tanto por cien del tama?o del gr?fico
213
	 * @return Porcentaje de distancia entre el punto inicial del gr?fico hasta la
214
	 * l?nea del m?nimo.
215
	 */
216
	public double getMinDistance() {
217
		return minPos;
218
	}
219
	
220
	/**
221
	 * Obtiene la distancia de la l?nea del m?ximo al inicio del histograma. La 
222
	 * distancia la devuelve en tanto por cien del tama?o del gr?fico
223
	 * @return Porcentaje de distancia entre el punto inicial del gr?fico hasta la
224
	 * l?nea del m?ximo.
225
	 */
226
	public double getMaxDistance() {
227
		return maxPos;
228
	}
229
	
230
	public void firstActions() {}
231
	public void firstDrawActions() {}
232
}
0 233

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/canvas/layer/Border.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.raster.swing.impl.canvas.layer;
23

  
24
import java.awt.Color;
25
import java.awt.Graphics;
26

  
27
import org.gvsig.raster.swing.gcanvas.DrawableElement;
28
/**
29
 * Gr?fico que representa un borde para el canvas. Dibuja un cuadrado sin relleno en el perimetro m?ximo de
30
 * dibujo del canvas. 
31
 *
32
 * 14-oct-2007
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class Border extends DrawableElement {
36
	public static final int BORDER = 5;
37
		
38
	/**
39
	 * Constructor. Asigna el color
40
	 * @param c
41
	 */
42
	public Border(Color c) {
43
		setColor(c);
44
	}
45
	
46
	/**
47
	 * Dibujado de la l?nea de incremento exponencial sobre el canvas.
48
	 */
49
	public void paint(Graphics g) {
50
		g.setColor(color);
51
		g.drawRect(canvas.getCanvasMinX(), canvas.getCanvasMinY(), canvas.getCanvasWidth(), canvas.getCanvasHeight());
52
	}
53

  
54
	/*
55
	 * (non-Javadoc)
56
	 * @see org.gvsig.raster.beans.canvas.DrawableElement#firstActions()
57
	 */
58
	public void firstActions() {
59
		canvas.addBorder(BORDER, BORDER, BORDER, BORDER);
60
	}
61

  
62
	public void firstDrawActions() {}
63
}
0 64

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.56/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/canvas/layer/DefaultInfoLayer.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.raster.swing.impl.canvas.layer;
23

  
24
import java.awt.Color;
25
import java.awt.Component;
26
import java.awt.Graphics;
27
import java.awt.Graphics2D;
28
import java.awt.RenderingHints;
29
import java.awt.geom.Rectangle2D;
30
import java.util.List;
31

  
32
import org.gvsig.raster.swing.gcanvas.DrawableElement;
33
import org.gvsig.raster.swing.gcanvas.InfoLayer;
34
/**
35
 * Capa para GCanvas que muestra el maximo y minimo de una banda
36
 * 
37
 * @author BorSanZa - Borja S?nchez Zamorano 
38
 */
39
public class DefaultInfoLayer extends InfoLayer {
40
	private Color        color       = null;
41
	private double       min         = 0.0;
42
	private double       max         = 1.0;
43
	private String       statusRight = null;
44
	private String       statusLeft  = null;
45
	
46
	/**
47
	 * Creacion de un InfoLayer especificando el color
48
	 * @param c
49
	 */
50
	public DefaultInfoLayer(Color c) {
51
		color = c;
52
	}
53

  
54
	/**
55
	 * Definir el borde que va a tener el componente
56
	 */
57
	public void firstActions() {
58
		canvas.addBorder(0, 15, 0, 15);
59
	}
60
	
61
	/**
62
	 * Establecer los valores maximo y minimo para dicha capa
63
	 * @param min
64
	 * @param max
65
	 */
66
	public void setLimits(double min, double max) {
67
		this.min = min;
68
		this.max = max;
69
	}
70

  
71
	/*
72
	 * (non-Javadoc)
73
	 * @see org.gvsig.raster.beans.canvas.DrawableElement#paint(java.awt.Graphics)
74
	 */
75
	protected void paint(Graphics g) {
76
		
77
		Graphics2D graphics2 = (Graphics2D) g;
78

  
79
		RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
80
		hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
81
		graphics2.setRenderingHints(hints);
82

  
83
		graphics2.setColor(color);
84
		graphics2.setFont(new java.awt.Font("Times", 1, 12));
85
		
86
		String min2 = clipDecimals(min, 1) + "";
87
		String max2 = clipDecimals(max, 1) + "";
88

  
89
		Rectangle2D rectangle2D = graphics2.getFontMetrics().getStringBounds(max2, g);
90
		
91
		graphics2.drawString(min2, canvas.getCanvasMinX(), canvas.getCanvasMinX() + 12);
92
		graphics2.drawString(max2, 
93
				(int) (((Component)canvas).getWidth() - rectangle2D.getWidth() - canvas.getCanvasMinX()), 
94
				canvas.getCanvasMinX() + 12);
95
		
96
		if (statusRight != null) {
97
			rectangle2D = graphics2.getFontMetrics().getStringBounds(statusRight, g);
98
			graphics2.drawString(statusRight, 
99
					(int) (((Component)canvas).getWidth() - rectangle2D.getWidth() - canvas.getCanvasMinX()), 
100
					(int) ((Component)canvas).getHeight() - canvas.getCanvasMinX());
101
		}
102

  
103
		if (statusLeft != null) {
104
			graphics2.drawString(statusLeft, 
105
					canvas.getCanvasMinX(), 
106
					(int) ((Component)canvas).getHeight() - canvas.getCanvasMinX());
107
		}
108
		
109
		List<DrawableElement> list = canvas.getDrawableElements(DefaultMinMaxLines.class);
110
		if (list.size() > 0) {
111
			DefaultMinMaxLines minMaxLines = (DefaultMinMaxLines) list.get(0);
112

  
113
			double minP = min + (minMaxLines.getMinDistance() * (max - min));
114
			double maxP = min + (minMaxLines.getMaxDistance() * (max - min));
115
			min2 = clipDecimals(minP, 1) + "";
116
			max2 = clipDecimals(maxP, 1) + "";
117

  
118
			list = canvas.getDrawableElements(DefaultGraphicHistogram.class);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff