Revision 1648

View differences:

tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/VCN
1
REALIZADOS:
2

  
3
- Al a?adir un nuevo fframe se debe de quedar ese como seleccionado 
4
y todos los dem?s hay que dejarlos como no seleccionados.
5

  
6
- Implementar el FFrameLegend con todos los nombres de capas 
7
como textLayout y los s?mbolos.
8

  
9
-Meterle un m?todo que cambie cada uno de los nombres y s?mbolos 
10
del fframe en un fframe por separado.
11
(Simplificar)A partir de un FFrameLegend crear FFrameText y FFrameSymbol.
12

  
13
-Introducir dentro FGraphicsUtilities la parte del m?todo paintcomponent 
14
de FPreviewSymbol que sea com?n dibujar sobre el mapa de forma est?tica.
15
Se dibuja por la posici?n del shape y no del rect?ngulo.
16

  
17
-Crear una clase FLayoutUtilities, con los m?todos est?ticos fromSheet y toSheet.
18

  
19
-Crear grupos de fframes unidos, Agrupar y para Desagrupar, 
20
de forma que cuando se agrupan se crea un FframeGroup que contenga dentro 
21
todos los fframes seleccionados previamente, y cuando se desagrupa 
22
se elimina el fframegroup y se vuelve a crear un fframe 
23
de cada uno de los fframe que contenia dentro el fframegroup.
24

  
25
-Alinear como lo hace arcView o como lo hace el visual editor en funci?n 
26
de los fframes seleccionados o en funci?n del Layout.
27

  
28
-Colocar detr?s y delante fframes seleccionados respecto de los dem?s.
29

  
30
-El FConstanstLayout debe de desaparecer y a?adir las 
31
constantes que contiene en las clases que las necesiten.
32

  
33
- Crear las barras de escala y modificar la escala en vez de en metros en cent?metros.
34

  
35
-Cuando se muestra una escala que no es fija, y se modifica la escala de la vista, 
36
la escala que lo representa no varia.
37

  
38
- Se pueda abrir el di?logo de propiedades de cada uno de los fframes a?adidos al Layout, 
39
con la informaci?n que necesita.
40

  
41
- Cuando se alinea un solo elemento no se hace como deber?a. 
42

  
43
-L?nea gr?fica.
44

  
45
-FullExtent.
46

  
47
- El di?logo de FPanelDefault no tiene la posibilidad p?blica de modificar 
48
que no contenga relleno.
49
-Los puntos se deben de poder cambiar su tama?o al cambiar su tama?o arrastrando con 
50
el rat?n en el Layout y no solo desde el di?logo de propiedades de este.
51

  
52
- El Fshape se crea cada vez que se dibuja y por lo tanto no hay que guardarlo.
53

  
54
- FSymbol tiene que guardarse en XML utilizando la XMLEntity.La forma separar el modelo del Layout.
55

  
56
-Al cambiar de tama?o un fframe por encima de su posicion x e y, se distorsiona.
57

  
58
-Al modificar la escala de una vista en el Layout la escala gr?fica debe de cambiar su tama?o 
59
de acuerdo al cambio en la escala de la vista.
60

  
61
-Haciendo un doble click se acceda al dialogo de propiedades de cada uno de los fframes.
62

  
63
-FFrameText: Falta poder posicionar las l?neas a la izquierda, centro o derecha.
64

  
65
-Hacer el entramado que sea transparente totalmente en vez de blanco y que se pueda controlar su transparencia en las l?neas que lo componen.
66

  
67
- La propiedad de poder a?adir una vista, una imagen o una leyenda en forma de borrador o presentaci?n.
68

  
69
- Popupmenu en el Layout que se abre pulsando el bot?n derecho del rat?n.
70

  
71
- En FFrameViewDialog si no se selecciona ninguna vista y se acepta salta una excepci?n.
72

  
73
- Al cambiar el zoom y posicionar alg?n elemento detr?s o delante respecto de los dem?s 
74
cambia el zoom y se coloca siempre en mismo lugar.
75

  
76
- Teniendo seleccionada la herramienta de selecci?n y desplazar un fframe cambia su tama?o, ahora lo sigue cambiando pero solo cuando
77
 se desplaza de su posici?n, el desplazamiento y cambio de tama?o de un rect?ngulo 
78
con el grid seleccionado no funciona del todo bien, cambia 
79
el tama?o de forma anormal, pero no siempre.
80

  
81
- Separar el drawLayout para imprimir del drawLayout para visualizar en pantalla.
82

  
83
-En FBorderDialog, falta a?adir propiedades al rect?ngulo que se a?ade, 
84
por ejemplo elegir el color, grosor, textura,de momento es un rect?ngulo simple.
85

  
86

  
87
- FFramePicture se debe cambiar, ya que crea un bufferedimage tan grande como el zoom que se hace y salta la excepci?n de out of memory.
88

  
89
PENDIENTES:
90

  
91
- Rematar el a?adir una vista al Layout, 
92
y su actualizaci?n.
93

  
94
- El Di?logo FLegendManagerWindow, 
95
para que pueda funcionar igual que en arcView 
96
debe ser ?nico implementando SingletonView y que se pueda cambiar su modelo 
97
por el de otra vista que lo requiera. 
98
Ahora mismo lo he dejado como modal y que implementa View.
99

  
100
-Al a?adir una misma vista dos veces al Layout sigue cambiando su extent, cada repaint.
101
Tambi?n al tocar la vista y refrescar en el Layout, que debe ser por lo mismo ya que la 
102
escala que calcula es diferente cada vez y eso cambia el extent.
103
Supongo que es la forma de calcular el extent respecto de la anchura y altura del 
104
fframe que lo contiene y al ser dos se reajusta sin parar. Para corregir esto hay que:
105
El extent del Fmap debe de quedarse fuera de este, 
106
de esta forma no se necesitara clonar fmap cuando el extent 
107
de la vista a a?adir al Layout no tiene que ser la misma.
108

  
109
-A?adir el insertar un rect?ngulo a cada uno de los fframes seleccionados
110
dentro de fframeGraphics contener FShapes con el rect?ngulo dentro en este caso y 
111
pensando en poder a?adir tambi?n de otras formas los rect?ngulos y l?neas que queramos.
112
fshape + symbol==graphics.
113

  
114
- No corren prisa: deshacer, escala real, 
115
zoom a lo seleccionado.
116

  
117
-Revisar los di?logos de los fframes para ver posibles fallos.
118

  
119
- Hay que tener en cuenta que di?logos abrir cuando hay varios fframes seleccionados 
120
cuando se quiere abrir el di?logo de propiedades. En FLayoutGraphics,openFFrameDialog(), 
121
hay que abrir el di?logo de propiedades cuando hayan m?s de uno seleccionado, 
122
incluido cuando son de tipos diferentes.
123

  
124
- Cuando se deslinka el extent de una vista a?adidar al Layout del extent original, se clona el FMap. 
125

  
126
-FFrameView: Falta recortar a la vista y lo de los eventos de cuando se tiene que actualizar el Layout respecto de los cambios de la vista.
127
	Enlace vivo: Se debe guardar el extent actual de la vista y quedarse con ese extent.
128
	
129
-FFramePicture: Falta lo de los eventos.
130
-FFrameScaleBar: Visualizar solo las vistas que esten a?adidas al Layout y no todas.
131
-FFrameLegend: Eventos .Y visualizar en la lista de selecci?n, si se quiere, las vistas a?adidas solamente y no todas.
132

  
133

  
134
-Preparar p?gina: FConfigLayoutDialog muestra una apariencia que no es la del Look and feel elegida. 
135
Puede que sea porque es un MODALDIALOG.
136

  
137
- Cuando se posiciona delante o detr?s una barra de escala, se cambia el tipo de fuente. 
138
Pero el tama?o es el mismo, el color del graphics tambi?n y el tipo de fuente.
139
- El area imprimible hay que conseguir que sea la misma para 
140
los attributes, PageFormat y para guardarla en un atributo 
141
de la clase Attributes. Imprimir de acuerdo a los m?rgenes establecidos, no funciona bien todav?a. Es un tema delicado.
142

  
143
- m_name de FFrame solo lo utilizan tres fframes de momento.
144

  
145
- Mirar el por que una vista tarda tanto en dibujar un trocillo peque?o en el Layout.
146

  
147
- La leyenda que se introduzca con tama?o adecuado, mirar arcView.
148

  
149
DUDAS:
150

  
151
- El simplificar un fframe, como por ejemplo la leyenda esta ya hecho pero el arcView 
152
tambi?n simplifica una vista por cada uno de sus shapes.(Esto no).
153

  
0 154

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/build.number
1
#Build Number for ANT. Do not edit!
2
#Wed Dec 15 13:09:14 CET 2004
3
build.number=128
0 4

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/distFiles/LEEME.txt
1
gvSIG v 0.2.0 beta.
2

  
3
Prerequisitos:
4
  - Java instalado (JRE 1.4.2 o superior) (http://java.sun.com)
5
  - JAI + JAI image I/O (http://java.sun.com)
6
  - librer?as din?micas para los ECW: vienen con cualquier
7
    producto de ERMAPPER y son gratuitas (Actualmente solo hay disponibles para
8
    MS windows)(http://www.ermapper.com)
9
  
10
Instalaci?n:
11

  
12
	Descomprimir el archivo zip completo en el directorio deseado
13
	
14
Ejecuci?n
15
	En windows: gvSIG.bat
16
	En linux:  gvSIG.sh
17

  
18
M?s informaci?n:
19
	gvsig@gva.es
0 20

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/src/log4j.properties
1
log4j.rootLogger=info, stdout
2

  
3
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5

  
6
# Pattern to output the caller's file name and line number.
7
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
8

  
9
log4j.appender.R=org.apache.log4j.RollingFileAppender
10
log4j.appender.R.File=application.log
11

  
12
log4j.appender.R.MaxFileSize=100KB
13
# Keep one backup file
14
log4j.appender.R.MaxBackupIndex=1
15

  
16
log4j.appender.R.layout=org.apache.log4j.PatternLayout
17
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
18

  
0 19

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/lamatek/swingextras/DaySelectionListener.java
1
package com.lamatek.swingextras;
2

  
3
/**
4
 * Interface used by {@link com.lamatek.swingextras.JDateChooser JDateChooser}
5
 * to notify when the user has selected a date.
6
 */
7
public interface DaySelectionListener {
8
	
9
	/**
10
	 * Called when a user selects a date.
11
	 */
12
	public void daySelected(int day);
13
	
14
}
0 15

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/lamatek/swingextras/JDateChooser.java
1
package com.lamatek.swingextras;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Component;
6
import java.awt.FlowLayout;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
9
import java.awt.GridLayout;
10
import java.awt.Insets;
11
import java.awt.event.ActionEvent;
12
import java.awt.event.ActionListener;
13
import java.awt.event.MouseAdapter;
14
import java.awt.event.MouseEvent;
15
import java.awt.event.MouseListener;
16
import java.text.DateFormat;
17
import java.util.Calendar;
18
import java.util.Date;
19
import java.util.Vector;
20

  
21
import javax.swing.BorderFactory;
22
import javax.swing.JButton;
23
import javax.swing.JLabel;
24
import javax.swing.JPanel;
25
import javax.swing.border.BevelBorder;
26
import javax.swing.border.EtchedBorder;
27

  
28
import com.iver.andami.PluginServices;
29
import com.iver.andami.Utilities;
30
import com.iver.andami.ui.mdiManager.View;
31
import com.iver.andami.ui.mdiManager.ViewInfo;
32

  
33
/**
34
 * JDateChooser is a simple Date choosing component with similar functionality
35
 * to JFileChooser and JColorChooser. It can be used as a component, to 
36
 * be inserted into a client layout, or can display it's own Dialog
37
 * through use of the {@link #showDialog(Component, String) showDialog} method.
38
 * <p>
39
 * JDateChooser can be initialized to the current date using the no argument
40
 * constructor, or initialized to a predefined date by passing an instance
41
 * of Calendar to the constructor.<p>
42
 * Using the JDateChooser dialog works in a similar manner to JFileChooser
43
 * or JColorChooser. The {@link #showDialog(Component, String) showDialog} method
44
 * returns an int that equates to the public variables ACCEPT_OPTION, CANCEL_OPTION
45
 * or ERROR_OPTION.<p>
46
 * <tt>
47
 * JDateChooser chooser = new JDateChooser();<br>
48
 * if (chooser.showDialog(this, "Select a date...") == JDateChooser.ACCEPT_OPTION) {<br>
49
 * &nbsp;&nbsp;Calendar selectedDate = chooser.getSelectedDate();<br>
50
 * &nbsp;&nbsp;// process date here...<br>
51
 * }<p>
52
 * To use JDateChooser as a component within a GUI, users should subclass
53
 * JDateChooser and override the {@link #acceptSelection() acceptSelection} and
54
 * {@link #cancelSelection() cancelSelection} methods to process the 
55
 * corresponding user selection.<p>
56
 * The current date can be retrieved by calling {@link #getSelectedDate() getSelectedDate}
57
 * method.
58
 */
59

  
60
public class JDateChooser extends JPanel implements ActionListener, DaySelectionListener, View {
61
	
62
	public static final int CANCEL_OPTION = 4;
63
	private int currentDay;
64
	private int currentMonth;
65
	private int currentYear;
66
	private JLabel dateText;
67
	private Calendar calendar;
68
	private Date date;
69
	private JButton previousYear;
70
	private JButton previousMonth;
71
	private JButton nextMonth;
72
	private JButton nextYear;
73
	private JButton okay;
74
	private JButton cancel;
75
	private JPanel days;
76
	
77
	private DayListener dayListener = new DayListener();
78
	/**
79
	 * This constructor creates a new instance of JDateChooser initialized to
80
	 * the current date.
81
	 */
82
	public JDateChooser() {
83
		this(Calendar.getInstance());
84
	}
85
	
86
	/**
87
	 * Creates a new instance of JDateChooser initialized to the given Calendar.
88
	 */
89
	public JDateChooser(Calendar c) {
90
		super();
91
		this.calendar = c;
92
		this.calendar.setLenient(true);
93
		setup();
94
	}
95
	
96
	private void setup() {
97
		GridBagLayout g = new GridBagLayout();
98
		GridBagConstraints c = new GridBagConstraints();
99
		JPanel header = new JPanel(g);
100
		c.gridx = 0;
101
		c.gridy = 0;
102
		c.insets = new Insets(2, 0, 2, 0);
103
		previousYear = (JButton) header.add(new JButton("<<"));
104
		previousYear.addActionListener(this);
105
		previousYear.setToolTipText("A?o anterior");
106
		g.setConstraints(previousYear, c);
107
		previousMonth = (JButton) header.add(new JButton("<"));
108
		previousMonth.addActionListener(this);
109
		previousMonth.setToolTipText("Mes anterior");
110
		c.gridx++;
111
		g.setConstraints(previousMonth, c);
112
		dateText = (JLabel) header.add(new JLabel("", JLabel.CENTER));
113
		dateText.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
114
		c.gridx++;
115
		c.weightx = 1.0;
116
		c.fill = c.BOTH;
117
		g.setConstraints(dateText, c);
118
		nextMonth = (JButton) header.add(new JButton(">"));
119
		nextMonth.addActionListener(this);
120
		nextMonth.setToolTipText("Mes siguiente");
121
		c.gridx++;
122
		c.weightx = 0.0;
123
		c.fill = c.NONE;
124
		g.setConstraints(nextMonth, c);
125
		nextYear = (JButton) header.add(new JButton(">>"));
126
		nextYear.addActionListener(this);
127
		nextYear.setToolTipText("A?o siguiente");
128
		c.gridx++;
129
		g.setConstraints(nextYear, c);
130
		
131
		updateCalendar(calendar);
132
		
133
		JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
134
		okay = (JButton) buttons.add(new JButton("Ok"));
135
		okay.addActionListener(this);
136
		cancel = (JButton) buttons.add(new JButton("Cancelar"));
137
		cancel.addActionListener(this);
138
		
139
		setLayout(new BorderLayout());
140
		add("North", header);
141
		days.setBackground(Color.WHITE);
142
		days.setOpaque(true);
143
		days.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
144
		add("Center", days);
145
		add("South", buttons);
146
	}
147
	
148
	private void updateCalendar(Calendar c) {
149
		if (days != null)
150
			remove(days);
151
		currentDay = calendar.get(Calendar.DAY_OF_MONTH);
152
		currentMonth = calendar.get(Calendar.MONTH);
153
		currentYear = calendar.get(Calendar.YEAR);
154
		days = new JPanel(new GridLayout(7, 7));
155
		Calendar setup = (Calendar) calendar.clone();
156
		setup.set(Calendar.DAY_OF_WEEK, setup.getFirstDayOfWeek());
157
		int lastLayoutPosition = 0;
158
		for (int i = 0; i < 7; i++) {
159
			int dayInt = setup.get(Calendar.DAY_OF_WEEK);
160
			if (dayInt == Calendar.MONDAY)
161
				days.add(new JLabel("Mon", JLabel.CENTER));
162
			if (dayInt == Calendar.TUESDAY)
163
				days.add(new JLabel("Tue", JLabel.CENTER));
164
			if (dayInt == Calendar.WEDNESDAY)
165
				days.add(new JLabel("Wed", JLabel.CENTER));
166
			if (dayInt == Calendar.THURSDAY)
167
				days.add(new JLabel("Thu", JLabel.CENTER));
168
			if (dayInt == Calendar.FRIDAY)
169
				days.add(new JLabel("Fri", JLabel.CENTER));
170
			if (dayInt == Calendar.SATURDAY)
171
				days.add(new JLabel("Sat", JLabel.CENTER));
172
			if (dayInt == Calendar.SUNDAY)
173
				days.add(new JLabel("Sun", JLabel.CENTER));
174
			setup.roll(Calendar.DAY_OF_WEEK, true);
175
			lastLayoutPosition++;
176
		}
177
		setup = (Calendar) calendar.clone();
178
		setup.set(Calendar.DAY_OF_MONTH, 1);
179
		int first = setup.get(Calendar.DAY_OF_WEEK);
180
		for (int i = 0; i < (first - 1); i++) {
181
			days.add(new JLabel(""));
182
			lastLayoutPosition++;
183
		}
184
		setup.set(Calendar.DAY_OF_MONTH, 1);
185
		for (int i = 0; i < setup.getActualMaximum(setup.DAY_OF_MONTH); i++) {
186
			DayButton button = new DayButton(setup.get(setup.DAY_OF_MONTH));
187
			if (setup.get(Calendar.DAY_OF_MONTH) == currentDay){
188
				button.setBackground(Color.BLUE);
189
				button.setForeground(Color.WHITE);
190
				dayListener.setDia(button);
191
			}
192
			button.addDaySelectionListener(this);
193
			button.addMouseListener(dayListener);
194
			days.add(button);
195
			setup.roll(setup.DAY_OF_MONTH, true);
196
			lastLayoutPosition++;
197
		}
198
		for (int i = lastLayoutPosition; i < 49; i++)
199
			days.add(new JLabel(""));
200
		add("Center", days);
201
		validate();
202
		setup = null;
203
		updateLabel();
204
	}
205
	
206
	private void updateLabel() {
207
		Date date = calendar.getTime();
208
		dateText.setText(DateFormat.getInstance().format(date));
209
	}
210
	
211
	/**
212
	 * Returns the currently selected Date in the form of a java.util.Calendar
213
	 * object. Typically called adter receipt of an {@link #ACCEPT_OPTION ACCEPT_OPTION}
214
	 * (using the {@link #showDialog(Component, String) showDialog} method) or
215
	 * within the {@link #acceptSelection() acceptSelection} method (using the
216
	 * JDateChooser as a component.)<p>
217
	 * @return java.util.Calendar The selected date in the form of a Calendar object.
218
	 */
219
	public Calendar getSelectedDate() {
220
		return calendar;
221
	}
222
	
223
	/**
224
	 * Used to process events from the previous month, previous year, next month, next year,
225
	 * okay and cancel buttons. Users should call super.actionPerformed(ActionEvent) if overriding
226
	 * this method.
227
	 */
228
	public void actionPerformed(ActionEvent e) {
229
		if (e.getSource() == okay) {
230
			PluginServices.getMDIManager().closeView(this);
231
		}
232
		if (e.getSource() == cancel) {
233
			calendar = null;
234
			PluginServices.getMDIManager().closeView(this);
235
		}
236
		if (e.getSource() == previousYear) {
237
			calendar.roll(Calendar.YEAR, -1);
238
			updateCalendar(calendar);
239
		}
240
		if (e.getSource() == previousMonth) {
241
			calendar.roll(Calendar.MONTH, -1);
242
			updateCalendar(calendar);
243
		}
244
		if (e.getSource() == nextMonth) {
245
			calendar.roll(Calendar.MONTH, 1);
246
			updateCalendar(calendar);
247
		}
248
		if (e.getSource() == nextYear) {
249
			calendar.roll(Calendar.YEAR, 1);
250
			updateCalendar(calendar);
251
		}
252
	}
253
	
254
	/**
255
	 * Used to process day selection events from the user. This method resets
256
	 * resets the Calendar object to the selected day. Subclasses should make a call
257
	 * to super.daySelected() if overriding this method.
258
	 */
259
	public void daySelected(int d) {
260
		calendar.set(Calendar.DAY_OF_MONTH, d);
261
		updateLabel();
262
		currentDay = d;
263
	}
264

  
265
	/**
266
	 * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
267
	 */
268
	public ViewInfo getViewInfo() {
269
		ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
270
			m_viewinfo.setTitle(PluginServices.getText(this,"seleccione_fecha"));
271
			m_viewinfo.setWidth(400);
272
			m_viewinfo.setHeight(200);
273
		
274
		return m_viewinfo;
275
	}
276

  
277
	/**
278
	 * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
279
	 */
280
	public void viewActivated() {
281
	}
282
}
283

  
284
class DayListener extends MouseAdapter{
285
	private DayButton btnDia;
286
	
287
	public void setDia(DayButton btn){
288
		btnDia = btn; 
289
	}
290
	/**
291
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
292
	 */
293
	public void mouseClicked(MouseEvent e) {
294
		if (btnDia != null){
295
			btnDia.setBackground(Color.WHITE);
296
			btnDia.setForeground(Color.BLACK);
297
		}
298

  
299
		btnDia = (DayButton) e.getSource();
300
		btnDia.setBackground(Color.BLUE);
301
		btnDia.setForeground(Color.WHITE);
302
		
303
	}
304

  
305
}
306

  
307
class DayButton extends JLabel implements MouseListener {
308
	
309
	private int day;
310
	private Vector listeners;
311
	
312
	public DayButton(int d) {
313
		super((new Integer(d)).toString());
314
		this.day = d;
315
		addMouseListener(this);
316
		this.setBackground(Color.WHITE);
317
		this.setOpaque(true);
318
		this.setHorizontalAlignment(JLabel.CENTER);
319
	}
320
	
321
	public void addDaySelectionListener(DaySelectionListener l) {
322
		if (listeners == null)
323
			listeners = new Vector(1, 1);
324
		listeners.addElement(l);
325
	}
326
	
327
	public void removeDaySelectionListener(DaySelectionListener l) {
328
		if (listeners != null)
329
			listeners.removeElement(l);
330
	}
331
	
332
	public void removeAllListeners() {
333
		listeners = new Vector(1,1);
334
	}
335

  
336
	/**
337
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
338
	 */
339
	public void mouseClicked(MouseEvent e) {
340
		if (listeners != null) {
341
			for (int i = 0; i < listeners.size(); i++) {
342
				((DaySelectionListener) listeners.elementAt(i)).daySelected(day);
343
			}
344
		}
345
	}
346

  
347
	/**
348
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
349
	 */
350
	public void mouseEntered(MouseEvent arg0) {
351
	}
352

  
353
	/**
354
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
355
	 */
356
	public void mouseExited(MouseEvent arg0) {
357
	}
358

  
359
	/**
360
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
361
	 */
362
	public void mousePressed(MouseEvent arg0) {
363
	}
364

  
365
	/**
366
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
367
	 */
368
	public void mouseReleased(MouseEvent arg0) {
369
	}
370
}
371

  
372
	
0 373

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/vividsolutions/jump/util/UniqueList.java
1

  
2
/*
3
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
4
 * for visualizing and manipulating spatial features with geometry and attributes.
5
 *
6
 * Copyright (C) 2003 Vivid Solutions
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 * 
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 * 
22
 * For more information, contact:
23
 *
24
 * Vivid Solutions
25
 * Suite #1A
26
 * 2328 Government Street
27
 * Victoria BC  V8T 5G5
28
 * Canada
29
 *
30
 * (250)385-6040
31
 * www.vividsolutions.com
32
 */
33

  
34
package com.vividsolutions.jump.util;
35

  
36
import java.util.*;
37

  
38

  
39
/**
40
 * A List that ignores duplicates. Note: performance is not optimized - a simple linear
41
 * search is performed.
42
 */
43
public class UniqueList implements List {
44
    private List list;
45

  
46
    /**
47
     * Creates a UniqueList.
48
     */
49
    public UniqueList() {
50
        this(new ArrayList());
51
    }
52

  
53
    /**
54
     * Creates a UniqueList backed by the given List.
55
     * @param list a List that will be this UniqueList's underlying List
56
     */
57
    public UniqueList(List list) {
58
        this.list = list;
59
    }
60

  
61
    public int size() {
62
        return list.size();
63
    }
64

  
65
    public boolean isEmpty() {
66
        return list.isEmpty();
67
    }
68

  
69
    public boolean contains(Object o) {
70
        return list.contains(o);
71
    }
72

  
73
    public Iterator iterator() {
74
        return list.iterator();
75
    }
76

  
77
    public Object[] toArray() {
78
        return list.toArray();
79
    }
80

  
81
    public Object[] toArray(Object[] a) {
82
        return list.toArray(a);
83
    }
84

  
85
    public boolean add(Object o) {
86
        if (list.contains(o)) {
87
            return false;
88
        }
89

  
90
        return list.add(o);
91
    }
92

  
93
    public boolean remove(Object o) {
94
        return list.remove(o);
95
    }
96

  
97
    public boolean containsAll(Collection c) {
98
        return list.containsAll(c);
99
    }
100

  
101
    public boolean addAll(Collection c) {
102
    	return addAll(size(), c);
103
    }
104

  
105
    public boolean addAll(int index, Collection c) {
106
		ArrayList itemsToAdd = new ArrayList(c);
107
		itemsToAdd.removeAll(this);
108
		return list.addAll(index, itemsToAdd);    	
109
    }
110

  
111
    public boolean removeAll(Collection c) {
112
        return list.removeAll(c);
113
    }
114

  
115
    public boolean retainAll(Collection c) {
116
        return list.retainAll(c);
117
    }
118

  
119
    public void clear() {
120
        list.clear();
121
    }
122

  
123
    public boolean equals(Object o) {
124
        return list.equals(o);
125
    }
126

  
127
    public Object get(int index) {
128
        return list.get(index);
129
    }
130

  
131
    public Object set(int index, Object element) {
132
        return list.set(index, element);
133
    }
134

  
135
    public void add(int index, Object element) {
136
        if (list.contains(element)) {
137
            return;
138
        }
139

  
140
        list.add(index, element);
141
    }
142

  
143
    public Object remove(int index) {
144
        return list.remove(index);
145
    }
146

  
147
    public int indexOf(Object o) {
148
        return list.indexOf(o);
149
    }
150

  
151
    public int lastIndexOf(Object o) {
152
        return list.lastIndexOf(o);
153
    }
154

  
155
    public ListIterator listIterator() {
156
        return list.listIterator();
157
    }
158

  
159
    public ListIterator listIterator(int index) {
160
        return list.listIterator(index);
161
    }
162

  
163
    public List subList(int fromIndex, int toIndex) {
164
        return list.subList(fromIndex, toIndex);
165
    }
166
}
0 167

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/vividsolutions/jump/util/FlexibleDateParser.txt
1
#Forget 2-digit year specifications ("yyyy"). Otherwise yyMMdd will 
2
#consider "20040203" to be invalid (a valid "200402" with a couple of
3
#extra characters). (FlexibleDateParser skips patterns that don't
4
#parse *all* the characters). Anyway, FlexibleDateParser also tries
5
#the (deprecated) Date constructor, and that should parse the most
6
#common 2-digit-year formats. [Jon Aquino]
7

  
8
#Lines beginning with "#" and blank lines are ignored. [Jon Aquino]
9

  
10
#Earlier patterns have precedence over later patterns. [Jon Aquino]
11

  
12
#####################################################################
13
#Popular SimpleDateFormat strings, culled from the top 1000 hits on 
14
#Google and Google Groups on 21 May 2003 [Jon Aquino]
15

  
16
#Multiple Google hits [Jon Aquino]
17

  
18
yyyy-MM-dd
19
yyyyMMdd
20
dd.MM.yyyy
21

  
22
#Although dd/MM/yyyy had a few more hits in Google, give priority to
23
#MM/dd/yyyy because JUMP will be used mainly in North America. 
24
#Anyway, yyyy-MM-dd should be preferred to both. [Jon Aquino]
25
MM/dd/yyyy
26
dd/MM/yyyy
27

  
28
yyyy-MM-dd HH:mm:ss
29
yyyyMMddHHmmss
30
MMMM d, yyyy
31
yyyy.MM.dd hh:mm:ss
32
yyyy/MM/dd
33
HH:mm
34
MMddyyyy
35
HH:mm:ss
36
ddMMyyyy
37
dd-MMM-yyyy
38
dd-MM-yyyy
39
dd MMM yyyy
40
yyyyMMddHHmmssSSS
41
yyyyMMddHHmm
42
yyyy/MM/dd HH:mm:ss
43
yyyy/MM/dd HH:mm
44
yyyy.MM.dd
45
hh:mm a
46
h:mmaa
47
MMM d, yyyy
48
HHmm
49

  
50
#Single Google hits [Jon Aquino]
51

  
52
yyyyMMddhhmmss
53
yyyy_MM_dd.hh_mm_ss_a.zzz
54
yyyy_MM_dd
55
yyyyMMddhhmmssSSS
56
yyyyMMddHHss
57
yyyyMMddHHmmsszzzzHHmm
58
yyyy/MM/dd/HH/mm/ss/SS
59
yyyy.MMM.dd HH:mm:ss.SSS z
60
yyyy.MM.dd HH:mm:ss
61
yyyy-Md HH:mm:ss
62
yyyy-MM-dd-G-hh-mm-ss-z
63
yyyy-MM-dd'T'HH:mm:ss
64
yyyy-MM-dd hh:mm:ss
65
yyyy-MM-dd HH:mm:sszzzzzzzzz
66
yyyy-MM-dd HH:mm:sszzz
67
yyyy-MM-dd HH:mm:ss.SSSzzzzzzzzz
68
yyyy-MM-dd HH:mm:ss.SSSSSS z
69
yyyy-MM-dd HH:mm:ss.SSS z
70
yyyy-MM-dd HH:mm:ss z
71
yyyy-MM-dd HH:mm
72
yyyy-MM-d HH:mm:ss
73
yyyy-DDD/HH:mm:ss.SSS
74
yyyy'-'MM'-'dd
75
yyyy DDD:HH:mm:ss
76
yyyyMMdd HH:mm
77
yyyy/MM/dd hh:mm:ss
78
MMM dd, yyyy
79
mm:ss:SS
80
MM-dd-yyyy
81
hh:mm:ss:SSS
82
hh:mm:ss dd-MM-yyyy
83
hh:mm
84
h:mm a, zzzz
85
h:mm
86
h:m
87
ddMMyyyyHHmmssSSS
88
ddhhmmz MMM yyyy
89
ddMMMyyyy
90
dd/MM/yyyy HH:mm:ss zzz
91
dd/MMM/yyyy
92
dd/MM/yyyy:HHmm
93
dd/MM/yyyy -- HH:mm:ss
94
dd/MM/yyyy - HH:mm:ss
95
dd/MM/yyyy hh:mm
96
dd.MMM.yyyy
97
dd.MM.yyyy hh:mm:ss a zzz
98
dd.MM.yyyy HH:mm:ss
99
dd.MM.yyyy '-' HH:mm:ss z
100
dd-MMM-yyyy HH:mm
101
dd'/'MM'/'yyyy
102
dd MMMMM, yyyy
103
dd MMMM yyyy
104
dd MM yyyy
105
d_M_yyyy_hh_mm_ss
106
d MMM yyyy
107
MMddyyyy.HHmm
108
MMddyyyyHHmm
109
MMM-dd-yyyy HH:mm:ss.S
110
MMM d hh:mm:ss
111
MM/dd/yyyy hh:mm:ss z
112
MM/dd/yyyy hh:mm:ss.SSS a
113
MM/dd/yyyy HH:mm
114
MM.dd.yyyy
115
MM'/'dd'/'yyyy
116
M/dd/yyyy
117
M/d/yyyy
118
M-dd-yyyy
119
HH:mm:ss '-' dd.MM.yyyy
120
H:mm
121
:mm:ss
122

  
123
#####################################################################
124
# Excel patterns [Jon Aquino]
125

  
126
M/dd
127
dd-MMM
128
MMM-yyyy
129
MM/dd/yyyy hh:mm a
130
M-yyyy
131
hh:mm:ss a
132

  
133
#####################################################################
134
# Other patterns [Jon Aquino]
135
MMM d
136
MMM yyyy
0 137

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/vividsolutions/jump/util/StringUtil.java
1
/*
2
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
3
 * for visualizing and manipulating spatial features with geometry and attributes.
4
 *
5
 * Copyright (C) 2003 Vivid Solutions
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 *
21
 * For more information, contact:
22
 *
23
 * Vivid Solutions
24
 * Suite #1A
25
 * 2328 Government Street
26
 * Victoria BC  V8T 5G5
27
 * Canada
28
 *
29
 * (250)385-6040
30
 * www.vividsolutions.com
31
 */
32
package com.vividsolutions.jump.util;
33

  
34
import java.io.ByteArrayOutputStream;
35
import java.io.PrintStream;
36
import java.util.ArrayList;
37
import java.util.Collection;
38
import java.util.Iterator;
39
import java.util.List;
40
import java.util.StringTokenizer;
41

  
42
import com.vividsolutions.jts.util.Assert;
43

  
44
/**
45
 * Useful String-related utilities.
46
 */
47
public class StringUtil {
48

  
49
    public static String s(int n) {
50
        return (n != 1) ? "s" : "";
51
    }
52

  
53
    public static String ies(int n) {
54
        return (n != 1) ? "ies" : "y";
55
    }
56

  
57
    public static String classNameWithoutQualifiers(String className) {
58
        return className.substring(
59
            Math.max(className.lastIndexOf("."), className.lastIndexOf("$")) + 1);
60
    }
61

  
62
    public static String classNameWithoutPackageQualifiers(String className) {
63
        return className.substring(className.lastIndexOf(".") + 1);
64
    }
65

  
66
    public static String repeat(char c, int n) {
67
        StringBuffer b = new StringBuffer();
68

  
69
        for (int i = 0; i < n; i++) {
70
            b.append(c);
71
        }
72

  
73
        return b.toString();
74
    }
75

  
76
    /**
77
     *  Line-wraps s by inserting a newline instead of the first space after the nth
78
     *  column. Word-wraps.
79
     */
80
    public static String split(String s, int n) {
81
        StringBuffer b = new StringBuffer();
82
        boolean wrapPending = false;
83

  
84
        for (int i = 0; i < s.length(); i++) {
85
            if (((i % n) == 0) && (i > 0)) {
86
                wrapPending = true;
87
            }
88

  
89
            char c = s.charAt(i);
90

  
91
            if (wrapPending && (c == ' ')) {
92
                b.append("\n");
93
                wrapPending = false;
94
            } else {
95
                b.append(c);
96
            }
97
        }
98

  
99
        return b.toString();
100
    }
101

  
102
    public static String capitalize(String word) {
103
        if (word.length() == 0) {
104
            return word;
105
        }
106

  
107
        return (word.charAt(0) + "").toUpperCase() + word.substring(1);
108
    }
109
    
110
    public static String uncapitalize(String word) {
111
        if (word.length() == 0) {
112
            return word;
113
        }
114

  
115
        return (word.charAt(0) + "").toLowerCase() + word.substring(1);        
116
    }
117

  
118
    /**
119
     * Converts the comma-delimited string into a List of trimmed strings.
120
     * @param s a String with comma-delimited values
121
     * @return a List of the Strings that were delimited by commas
122
     */
123
    public static List fromCommaDelimitedString(String s) {
124
        ArrayList result = new ArrayList();
125
        StringTokenizer tokenizer = new StringTokenizer(s, ",");
126

  
127
        while (tokenizer.hasMoreTokens()) {
128
            result.add(tokenizer.nextToken().toString().trim());
129
        }
130

  
131
        return result;
132
    }
133

  
134
    /**
135
     * Returns a List of empty Strings.
136
     * @param size the size of the List to create
137
     * @return a List of blank Strings
138
     */
139
    public static List blankStringList(int size) {
140
        ArrayList list = new ArrayList();
141

  
142
        for (int i = 0; i < size; i++) {
143
            list.add("");
144
        }
145

  
146
        return list;
147
    }
148

  
149
    public static String toFriendlyName(String className) {
150
        return toFriendlyName(className, null);
151
    }
152
    
153
    public static String friendlyName(Class c) {
154
        return toFriendlyName(c.getName());
155
    }
156

  
157
    public static String toFriendlyName(String className, String substringToRemove) {
158
        String name = className;
159

  
160
        //Remove substring sooner rather than later because, for example,
161
        //?"PlugIn" will become "Plug In". [Jon Aquino]
162
        if (substringToRemove != null) {
163
            name = StringUtil.replaceAll(name, substringToRemove, "");
164
        }
165

  
166
        name = StringUtil.classNameWithoutQualifiers(name);
167
        name = insertSpaces(name);
168

  
169
        return name;
170
    }
171

  
172
    public static String insertSpaces(String s) {
173
        if (s.length() < 2) {
174
            return s;
175
        }
176

  
177
        String result = "";
178

  
179
        for (int i = 0; i < (s.length() - 2); i++) { //-2
180
            result += s.charAt(i);
181

  
182
            if ((Character.isLowerCase(s.charAt(i))
183
                && Character.isUpperCase(s.charAt(i + 1)))
184
                || (Character.isUpperCase(s.charAt(i + 1))
185
                    && Character.isLowerCase(s.charAt(i + 2)))) {
186
                result += " ";
187
            }
188
        }
189

  
190
        result += s.charAt(s.length() - 2);
191
        result += s.charAt(s.length() - 1);
192

  
193
        return result.trim();
194
    }
195

  
196
    /**
197
     * Returns the elements of c separated by commas. If c is empty, an empty
198
     * String will be returned.
199
     * @param c a Collection of objects to convert to Strings and delimit by commas
200
     * @return a String containing c's elements, delimited by commas
201
     */
202
    public static String toCommaDelimitedString(Collection c) {
203
        return toDelimitedString(c, ", ");
204
    }
205

  
206
    /**
207
     *  Returns original with all occurrences of oldSubstring replaced by
208
     *  newSubstring
209
     */
210
    public static String replaceAll(
211
        String original,
212
        String oldSubstring,
213
        String newSubstring) {
214
        return replace(original, oldSubstring, newSubstring, true);
215
    }
216

  
217
    /**
218
     *  Returns original with occurrences of oldSubstring replaced by
219
     *  newSubstring. Set all to true to replace all occurrences, or false to
220
     *  replace the first occurrence only.
221
     */
222
    public static String replace(
223
        String original,
224
        String oldSubstring,
225
        String newSubstring,
226
        boolean all) {
227
        StringBuffer b = new StringBuffer(original);
228
        replace(b, oldSubstring, newSubstring, all);
229

  
230
        return b.toString();
231
    }
232

  
233
    /**
234
     *  Replaces all instances of the String o with the String n in the
235
     *  StringBuffer orig if all is true, or only the first instance if all is
236
     *  false. Posted by Steve Chapel <schapel@breakthr.com> on UseNet
237
     */
238
    public static void replace(StringBuffer orig, String o, String n, boolean all) {
239
        if ((orig == null) || (o == null) || (o.length() == 0) || (n == null)) {
240
            throw new IllegalArgumentException("Null or zero-length String");
241
        }
242

  
243
        int i = 0;
244

  
245
        while ((i + o.length()) <= orig.length()) {
246
            if (orig.substring(i, i + o.length()).equals(o)) {
247
                orig.replace(i, i + o.length(), n);
248

  
249
                if (!all) {
250
                    break;
251
                } else {
252
                    i += n.length();
253
                }
254
            } else {
255
                i++;
256
            }
257
        }
258
    }
259

  
260
    /**
261
     * Returns an throwable's stack trace
262
     */
263
    public static String stackTrace(Throwable t) {
264
        ByteArrayOutputStream os = new ByteArrayOutputStream();
265
        PrintStream ps = new PrintStream(os);
266
        t.printStackTrace(ps);
267

  
268
        return os.toString();
269
    }
270
    
271
    public static String head(String s, int lines) {
272
        int newlinesEncountered = 0;
273
        for (int i = 0; i < s.length(); i++) {
274
            if (s.charAt(i) == '\n') {
275
                newlinesEncountered++;
276
                if (newlinesEncountered == lines) {
277
                    return s.substring(0, i);
278
                }
279
            }
280
        }
281
        return s;
282
    }
283

  
284
    public static String limitLength(String s, int maxLength) {
285
        Assert.isTrue(maxLength >= 3);
286

  
287
        if (s == null) {
288
            return null;
289
        }
290

  
291
        if (s.length() > maxLength) {
292
            return s.substring(0, maxLength - 3) + "...";
293
        }
294

  
295
        return s;
296
    }
297

  
298
    public static boolean isNumber(String token) {
299
        try {
300
            Double.parseDouble(token);
301

  
302
            return true;
303
        } catch (NumberFormatException e) {
304
            return false;
305
        }
306
    }  
307

  
308
    public static String toDelimitedString(Collection c, String delimiter) {
309
        if (c.isEmpty()) {
310
            return "";
311
        }
312

  
313
        StringBuffer result = new StringBuffer();
314

  
315
        for (Iterator i = c.iterator(); i.hasNext();) {
316
            Object o = i.next();
317
            result.append(delimiter + ((o == null) ? "" : o.toString()));
318
        }
319

  
320
        return result.substring(delimiter.length());
321
    }
322

  
323
    public static String toTimeString(long milliseconds) {
324
        long remainder = milliseconds;
325
        long days = remainder / 86400000;
326
        remainder = remainder % 86400000;
327

  
328
        long hours = remainder / 3600000;
329
        remainder = remainder % 3600000;
330

  
331
        long minutes = remainder / 60000;
332
        remainder = remainder % 60000;
333

  
334
        long seconds = remainder / 1000;
335
        String s = "";
336

  
337
        if (days > 0) {
338
            s += (days + " days ");
339
        }
340

  
341
        s
342
            += (Fmt.fmt(hours, 2, Fmt.ZF)
343
                + ":"
344
                + Fmt.fmt(minutes, 2, Fmt.ZF)
345
                + ":"
346
                + Fmt.fmt(seconds, 2, Fmt.ZF));
347

  
348
        return s;
349
    }
350
}
0 351

  
tags/Root_gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/vividsolutions/jump/util/FlexibleDateParser.java
1
/*
2
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
3
 * for visualizing and manipulating spatial features with geometry and attributes.
4
 *
5
 * Copyright (C) 2003 Vivid Solutions
6
 * 
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * 
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 * 
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 * 
21
 * For more information, contact:
22
 *
23
 * Vivid Solutions
24
 * Suite #1A
25
 * 2328 Government Street
26
 * Victoria BC  V8T 5G5
27
 * Canada
28
 *
29
 * (250)385-6040
30
 * www.vividsolutions.com
31
 */
32
package com.vividsolutions.jump.util;
33

  
34
import com.vividsolutions.jts.util.Assert;
35

  
36
import java.awt.Color;
37
import java.awt.Component;
38

  
39
import java.io.IOException;
40
import java.io.InputStream;
41

  
42
import java.text.DateFormat;
43
import java.text.ParseException;
44
import java.text.ParsePosition;
45
import java.text.SimpleDateFormat;
46

  
47
import java.util.ArrayList;
48
import java.util.Calendar;
49
import java.util.Collection;
50
import java.util.Comparator;
51
import java.util.Date;
52
import java.util.Iterator;
53
import java.util.List;
54
import java.util.StringTokenizer;
55
import java.util.TreeSet;
56

  
57
import javax.swing.DefaultCellEditor;
58
import javax.swing.JComponent;
59
import javax.swing.JTable;
60
import javax.swing.JTextField;
61
import javax.swing.border.LineBorder;
62
import javax.swing.table.TableCellEditor;
63

  
64
/**
65
 * Warning: This class can parse a wide variety of formats. This flexibility is fine for parsing user
66
 * input because the user immediately sees whether the parser is correct and can fix it if
67
 * necessary. However, GML files are advised to stick with a safe format like yyyy-MM-dd.
68
 * yy/MM/dd is not as safe because while 99/03/04 will be parsed as yyyy/MM/dd, 
69
 * 02/03/04 will be parsed as MM/dd/yyyy (because MM/dd/yyyy appears earlier than yyyy/MM/dd
70
 * in FlexibleDateParser.txt).
71
 */
72
public class FlexibleDateParser {
73
    private static Collection lenientFormatters = null;
74
    private static Collection unlenientFormatters = null;
75
    //CellEditor used to be a static field CELL_EDITOR, but I was getting
76
    //problems calling it from ESETextField (it simply didn't appear).
77
    //The problems vanished when I turned it into a static class. I didn't
78
    //investigate further. [Jon Aquino]
79
    public static final class CellEditor extends DefaultCellEditor {
80
        public CellEditor() {
81
            super(new JTextField());
82
        }
83
        private Object value;
84
        private FlexibleDateParser parser = new FlexibleDateParser();
85

  
86
        public boolean stopCellEditing() {
87
            try {
88
                value = parser.parse((String) super.getCellEditorValue(), true);
89
            } catch (Exception e) {
90
                ((JComponent) getComponent()).setBorder(new LineBorder(Color.red));
91

  
92
                return false;
93
            }
94

  
95
            return super.stopCellEditing();
96
        }
97

  
98
        public Component getTableCellEditorComponent(
99
            JTable table,
100
            Object value,
101
            boolean isSelected,
102
            int row,
103
            int column) {
104
            this.value = null;
105
            ((JComponent) getComponent()).setBorder(new LineBorder(Color.black));
106

  
107
            return super.getTableCellEditorComponent(
108
                table,
109
                format((Date) value),
110
                isSelected,
111
                row,
112
                column);
113
        }
114

  
115
        private String format(Date date) {
116
            return (date == null) ? "" : formatter.format(date);
117
        }
118

  
119
        public Object getCellEditorValue() {
120
            return value;
121
        }
122

  
123
        //Same formatter as used by JTable.DateRenderer. [Jon Aquino]
124
        private DateFormat formatter = DateFormat.getDateInstance();
125
    };
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff