Revision 274

View differences:

trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/math/intervals/IntervalUtils.java
1
package org.gvsig.math.intervals;
2

  
3
public class IntervalUtils {
4

  
5
	/**
6
	 * Calculates an nice round interval division. For instance, for
7
	 * intervalLenght = 1100000 and numberOfDivisions=5,
8
	 * the result would be 250000.
9
	 * 
10
	 * @param intervalLength The full interval to be divided
11
	 * @param numberOfDivisions The exact number of divisions to perform
12
	 * @return A nice round interval division. The calculated result
13
	 * ensures that the whole interval length is covered by the proposed
14
	 * division, so it always fulfills the following formula:
15
	 *  <code>result*numberOfDivisions>=intervalLength</code>
16
	 */
17
	public static double roundIntervalDivision(double intervalLength, int numberOfDivisions) {
18
		if (intervalLength<=0.0d || numberOfDivisions<=0) {
19
			return 0.0d;
20
		}
21

  
22
		double division = intervalLength/numberOfDivisions;
23
		if (division==0.0d) {
24
			return 0.0d;
25
		}
26
		double digitShift = Math.floor((Math.log10(division)));
27
		double scale = Math.pow(10, -digitShift);
28
		double firstSignificatDigit = Math.floor(scale*division);
29
		double result = firstSignificatDigit*Math.pow(10, digitShift);
30
		if (result*numberOfDivisions>=intervalLength) {
31
			return result;
32
		}
33
		else {
34
			result = (0.5+firstSignificatDigit)*Math.pow(10, digitShift);
35
			if (result*numberOfDivisions>=intervalLength) {
36
				return result;
37
			}
38
		}
39
		result = (1+firstSignificatDigit)*Math.pow(10, digitShift);
40
		return result;
41
	}
42
}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameGrid.java
30 30
import java.awt.geom.Point2D;
31 31
import java.awt.geom.Rectangle2D;
32 32
import java.awt.image.BufferedImage;
33
import java.text.DecimalFormat;
34
import java.text.DecimalFormatSymbols;
33 35

  
34 36
import org.gvsig.andami.PluginServices;
35 37
import org.gvsig.compat.print.PrintAttributes;
......
46 48
import org.gvsig.fmap.mapcontext.ViewPort;
47 49
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
48 50
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
51
import org.gvsig.math.intervals.IntervalUtils;
49 52
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
50 53
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
51 54
import org.gvsig.tools.ToolsLocator;
......
76 79
    private static final String ISLINE_FIELD = "isLine";
77 80
    private static final String FONTSYZE_FIELD = "fontsize";
78 81
    private static final String TEXTCOLOR_FIELD = "textColor";
82
    private static final String USE_NUM_DIVISIONS_FIELD = "useNumDivisions";
83
    private static final String NUM_DIV_HORIZ_FIELD = "numDivHoriz";
84
    private static final String NUM_DIV_VERT_FIELD = "numDivVret";
85
    private static final String LABEL_FORMAT_FIELD = "labelFormat";
86
    private static final String HORIZ_LABEL_ROTATION_FIELD = "horizLabelRotation";
87
    private static final String VERT_LABEL_ROTATION_FIELD = "vertLabelRotation";
88
    
89
    /**
90
     * Use a fixed distance (intervalX and intervalY) 
91
     * to calculate the position of grid lines
92
     */
93
    public static final int FIXED_DISTANCE_MODE = 0;
94
    /**
95
     * Use a specific number of horizontal divisions in order
96
     * to calculate the position of grid lines
97
     */
98
    public static final int NUM_DIVISIONS_HORIZ_MODE = 1;
99
    /**
100
     * Use a specific number of vertical divisions in order to calculate
101
     * the position of grid lines
102
     */
103
    public static final int NUM_DIVISIONS_VERT_MODE = 2;
79 104

  
80
    private double intervalX = 10000;
81
    private double intervalY = 10000;
105
    private double defaultInterval = 100000;
106
    private Double intervalX = null;
107
    private Double intervalY = null;
82 108

  
83 109
    private Color textColor = Color.black;
84 110
    private boolean isLine;
85 111
    private int sizeFont = 8;
112
	private int useNumDivisions = FIXED_DISTANCE_MODE;
113
	private int numDivHoriz = 4;
114
	private int numDivVert = 4;
115
	private DecimalFormat labelFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance());
116
	private double horizLabelRotation = 0.0;
117
	private double vertLabelRotation = 0.0;
86 118

  
87 119
    // private boolean print=false;
88 120
    private SymbolManager symbolManager = MapContextLocator.getSymbolManager();
......
103 135
        if (r==null || rView==null) {
104 136
        	//extent may be null, for instance if no layer has been loaded on the view
105 137
        	return;
106
        }
107
                    
108
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y + (r.height / 2));
109
              
138
        }      
110 139
        Envelope envelope = vp.getAdjustedEnvelope();
140
        updateIntervals(envelope);
141
        double intervalX = getIntervalX();
142
        double intervalY = getIntervalY();
111 143
        
144
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y + (r.height / 2));
145
        
112 146
        double minX = envelope.getMinimum(0);
113 147
        double minY = envelope.getMinimum(1);
114 148
    	
......
180 214
        }
181 215
        
182 216
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y
183
            + (r.height / 2));       
217
            + (r.height / 2));
184 218
    } 
185 219
    
186 220
    private void drawPoints(Rectangle2D rView, 
......
279 313
                drawLine(p1.getX(), p1.getY() - OFFSET_IN_PIXELS, p1.getX() , p1.getY(), g, symbolForMargins);
280 314
                drawLine(p2.getX(), p2.getY(), p2.getX() , p2.getY() + OFFSET_IN_PIXELS, g, symbolForMargins);
281 315
                
282
                TextLayout textaux = new TextLayout(String.valueOf(xMap), font, frc);
283

  
316
                TextLayout textaux = new TextLayout(this.labelFormat.format(xMap), font, frc);
317
                g.setColor(textColor);
284 318
                double w = textaux.getBounds().getWidth();
285 319
                double h = textaux.getBounds().getHeight();
286
                g.setColor(textColor);                                                    
320

  
321
                double labelY = (p1.getY() + h) + 8;
322
                g.rotate(Math.toRadians(getVertLabelRotation()), p1.getX(), (labelY - (h / 2.0)));
287 323
                textaux.draw(g, (int) (p1.getX() - w / 2),
288
                    (int) (p1.getY() + h) + 8);
324
                    (int) labelY);
325
                g.rotate(Math.toRadians(-getVertLabelRotation()),  p1.getX(), (labelY - (h / 2.0)));
326

  
327
                labelY = (p2.getY() - h);
328
                g.rotate(Math.toRadians(getVertLabelRotation()), p1.getX(), (labelY - (h / 2.0)));
289 329
                textaux.draw(g, (int) (p2.getX() - w / 2),
290
                    (int) (p2.getY() - h));
330
                    (int) labelY);
331
                g.rotate(Math.toRadians(-getVertLabelRotation()),  p1.getX(), (labelY - (h / 2.0)));
291 332
            }
292 333
            xMap = xMap + intervalMapX;
293 334
            xPx = xPx + intervalPxX;
......
304 345
                drawLine(p1.getX() - OFFSET_IN_PIXELS, p1.getY(), p1.getX() , p1.getY(), g, symbolForMargins);
305 346
                drawLine(p2.getX(), p2.getY(), p2.getX() + OFFSET_IN_PIXELS, p2.getY(), g, symbolForMargins);
306 347
               
307
                TextLayout textaux = new TextLayout(String.valueOf(yMap), font, frc);
348
                TextLayout textaux = new TextLayout(this.labelFormat.format(yMap), font, frc);
308 349
                
309 350
                double w = textaux.getBounds().getWidth();
310 351
                double h = textaux.getBounds().getHeight();
311 352
                g.setColor(textColor);
353
                
354
                double rotationX = p1.getX()-10-w/2.0;
355
                g.rotate(Math.toRadians(getHorizLabelRotation()), rotationX, p1.getY());
312 356
                textaux.draw(g, 
313 357
                	(int) (p1.getX() - w - 10),
314 358
                    (int) (p1.getY() + h / 2));
359
                g.rotate(Math.toRadians(-getHorizLabelRotation()), rotationX, p1.getY());
360
                
361
                rotationX = p2.getX()+10+w/2.0;
362
                g.rotate(Math.toRadians(getHorizLabelRotation()), rotationX, p2.getY());
315 363
                textaux.draw(g, 
316 364
                	(int) p2.getX() + 10, 
317 365
                	(int) (p2.getY() + h / 2));
366
                g.rotate(Math.toRadians(-getHorizLabelRotation()), rotationX, p2.getY());
318 367
            }
319 368
            yMap = yMap + intervalMapY;
320 369
            yPx = yPx + intervalPxY;
......
399 448
    }
400 449

  
401 450
    public double getIntervalX() {
402
        return intervalX;
451
    	if (intervalX!=null) {
452
    		return intervalX;
453
    	}
454
    	intervalX = intervalY = getReasonableInterval();
455
    	return intervalX;
403 456
    }
457
    
458
    private double getReasonableInterval() {
459
    	if (fframeViewDependence!=null
460
    			&& fframeViewDependence.getMapContext().getViewPort().getAdjustedEnvelope()!=null) {
461
    		Envelope env = fframeViewDependence.getMapContext().getViewPort().getAdjustedEnvelope();
462
    		return IntervalUtils.roundIntervalDivision(env.getLength(0), 5);
463
    	}
464
    	return defaultInterval;
465
    }
466
    
404 467

  
405 468
    public double getIntervalY() {
406
        return intervalY;
469
    	if (intervalX!=null) {
470
    		return intervalX;
471
    	}
472
    	intervalX = intervalY = new Double(getReasonableInterval());
473
    	return intervalY;
407 474
    }
408 475

  
409 476
    public void setTextColor(Color textcolor) {
......
500 567
    }
501 568

  
502 569
    public int getFontSize() {
503
        return sizeFont;
570
        return font.getSize();
504 571
    }
505 572

  
573
    /**
574
     * Defines whether a number of divisions is used to calculate the
575
     * location of grid lines,
576
     * or a distance (intervalX and intervalY) is used to
577
     * calculate them.
578
     * 
579
     * @param useNumDivisions One of {@link #FIXED_DISTANCE_MODE},
580
     * {@link #NUM_DIVISIONS_HORIZ_MODE} or {@link #NUM_DIVISIONS_HORIZ_MODE}.
581
     * @return
582
     */
583
    public void setUseNumDivisions(int mode) {
584
    	this.useNumDivisions  = mode;
585
    }
586
    
587
    protected void updateIntervals() {
588
    	if (fframeViewDependence.getMapContext()!=null
589
    			&& fframeViewDependence.getMapContext().getViewPort()!=null) {
590
    		Envelope env = fframeViewDependence.getMapContext().getViewPort().getAdjustedEnvelope();
591
    		updateIntervals(env);
592
    	}
593
    }
594
    
595
    protected void updateIntervals(Envelope env) {
596
    	if (useNumDivisions==NUM_DIVISIONS_HORIZ_MODE) {
597
    		double division = IntervalUtils.roundIntervalDivision(env.getLength(0), numDivHoriz);
598
    		intervalX = division;
599
    		intervalY = division;
600
    	}
601
    	else if (useNumDivisions==NUM_DIVISIONS_VERT_MODE) {
602
    		double division = IntervalUtils.roundIntervalDivision(env.getLength(1), numDivVert);
603
    		intervalX = division;
604
    		intervalY = division;
605
    	}
606
    }
607
    
608
    /**
609
     * Returns true if a number of divisions is used to calculate the
610
     * location of grid lines,
611
     * or false if a distance (intervalX and intervalY) is used to
612
     * calculate them.
613
     * 
614
     * @return  One of {@link #FIXED_DISTANCE_MODE},
615
     * {@link #NUM_DIVISIONS_HORIZ_MODE} or {@link #NUM_DIVISIONS_HORIZ_MODE}.
616
     */
617
    public int getUseNumDivisions() {
618
    	return this.useNumDivisions;
619
    }
620
    
621
    public void setNumDivisionsHoriz(int nx) {
622
    	this.numDivHoriz = nx;
623
    }
624
    
625
    public void setNumDivisionsVert(int ny) {
626
    	this.numDivVert = ny;
627
    }
628
    
629
    public int getNumDivisionHoriz() {
630
    	return this.numDivHoriz;
631
    }
632
    
633
    public int getNumDivisionsVert() {
634
    	return this.numDivVert;
635
    }
636
    
637
    public void setLabelFormat(DecimalFormat f) {
638
    	this.labelFormat  = f;
639
    }
640
    
641
    public DecimalFormat  getLabelFormat() {
642
    	return this.labelFormat;
643
    }
644

  
645
    /**
646
     * Sets the rotation of the labels corresponding to horizontal lines
647
     * 
648
     * @param labelRotation Label rotation, measured in arc degrees
649
     */
650
    public void setHorizLabelRotation(double labelRotation) {
651
    	this.horizLabelRotation  = labelRotation;
652
    }
653
    
654
    /**
655
     * Sets the rotation of the labels corresponding to vertical lines
656
     * 
657
     * @param labelRotation Label rotation, measured in arc degrees
658
     */
659
    public void setVertLabelRotation(double labelRotation) {
660
    	this.vertLabelRotation  = labelRotation;
661
    }
662
    
663
    /**
664
     * Gets the rotation of the labels corresponding to horizontal lines
665
     * 
666
     * @param labelRotation Label rotation, measured in arc degrees
667
     */
668
    public double getHorizLabelRotation() {
669
    	return this.horizLabelRotation;
670
    }
671
    
672
    
673
    /**
674
     * Gets the rotation of the labels corresponding to vertical lines
675
     * 
676
     * @param labelRotation Label rotation, measured in arc degrees
677
     */
678
    public double getVertLabelRotation() {
679
    	return this.vertLabelRotation;
680
    }
681
    
506 682
    public void print(Graphics2D g, AffineTransform at, Geometry shape,
507 683
        PrintAttributes properties) {
508 684
        draw(g, at, null, null);
......
532 708
            definition.addDynFieldInt(FONTSYZE_FIELD).setMandatory(true);
533 709
            definition.addDynFieldObject(TEXTCOLOR_FIELD)
534 710
                .setClassOfValue(Color.class).setMandatory(true);
711
            definition.addDynFieldInt(USE_NUM_DIVISIONS_FIELD).setMandatory(false);
712
            definition.addDynFieldInt(NUM_DIV_HORIZ_FIELD).setMandatory(false);
713
            definition.addDynFieldInt(NUM_DIV_VERT_FIELD).setMandatory(false);
714
            definition.addDynFieldObject(LABEL_FORMAT_FIELD)
715
            .setClassOfValue(DecimalFormat.class).setMandatory(false);
716
            definition.addDynFieldDouble(VERT_LABEL_ROTATION_FIELD).setMandatory(false);
717
            definition.addDynFieldDouble(HORIZ_LABEL_ROTATION_FIELD).setMandatory(false);
535 718
        }
536 719
    }
537 720

  
......
547 730
        isLine = state.getBoolean(ISLINE_FIELD);
548 731
        sizeFont = state.getInt(FONTSYZE_FIELD);
549 732
        textColor = (Color) state.get(TEXTCOLOR_FIELD);
733
        if (state.hasValue(USE_NUM_DIVISIONS_FIELD)) {
734
        	useNumDivisions = state.getInt(USE_NUM_DIVISIONS_FIELD);
735
        }
736
        if (state.hasValue(NUM_DIV_HORIZ_FIELD)) {
737
        	numDivHoriz = state.getInt(NUM_DIV_HORIZ_FIELD);	
738
        }
739
        if (state.hasValue(NUM_DIV_VERT_FIELD)) {
740
        	numDivVert = state.getInt(NUM_DIV_VERT_FIELD);	
741
        }
742
        if (state.hasValue(LABEL_FORMAT_FIELD)) {
743
        	labelFormat = (DecimalFormat) state.get(LABEL_FORMAT_FIELD);	
744
        }
745
        if (state.hasValue(VERT_LABEL_ROTATION_FIELD)) {
746
        	vertLabelRotation = state.getDouble(VERT_LABEL_ROTATION_FIELD);
747
        }
748
        if (state.hasValue(HORIZ_LABEL_ROTATION_FIELD)) {
749
        	horizLabelRotation = state.getDouble(HORIZ_LABEL_ROTATION_FIELD);
750
        }
550 751
    }
551 752

  
552 753
    @Override
......
560 761
        state.set(ISLINE_FIELD, isLine);
561 762
        state.set(FONTSYZE_FIELD, sizeFont);
562 763
        state.set(TEXTCOLOR_FIELD, textColor);
764
        state.set(USE_NUM_DIVISIONS_FIELD, useNumDivisions);
765
        state.set(NUM_DIV_HORIZ_FIELD, numDivHoriz);
766
        state.set(NUM_DIV_VERT_FIELD, numDivVert);
767
        state.set(LABEL_FORMAT_FIELD, labelFormat);
768
        state.set(VERT_LABEL_ROTATION_FIELD, vertLabelRotation);
769
        state.set(HORIZ_LABEL_ROTATION_FIELD, horizLabelRotation);
770

  
563 771
    }
564 772
}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/gui/numberFormat/CharComboBox.java
60 60
	}
61 61
	
62 62
	/**
63
	 * Returns the selected char, or null if the NoneItem is
64
	 * selected.
63
	 * Returns the selected char or the NoneItem string.
64
	 * 
65 65
	 * @see javax.swing.JComboBox#getSelectedItem()
66 66
	 */
67 67
	public String getSelectedItem() {
......
75 75
			}
76 76
		}
77 77
		else {
78
			return null;
78
			return noneItem;
79 79
		}
80 80
	}
81 81
	
......
90 90
	 * 
91 91
	 * @param text The localized text to show as the NoneItem
92 92
	 */
93
	public void setNoneItemText(String text) {
93
	public void setNoneItem(String text) {
94
		removeItem(noneItem);
94 95
		noneItem = text;
96
		addItem(text);
95 97
	}
96 98
	
99
	/**
100
	 * This item represents that no item is selected
101
	 */
102
	public String getNoneItem() {
103
		return noneItem;
104
	}
97 105
	
98 106
	
99 107
	
100 108
	
101
	
102 109

  
103 110
}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/gui/numberFormat/DecimalFormatDialog.java
1
package org.gvsig.app.project.documents.layout.fframes.gui.numberFormat;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6

  
7
import javax.swing.BorderFactory;
8
import javax.swing.JPanel;
9

  
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.andami.ui.mdiManager.IWindow;
12
import org.gvsig.andami.ui.mdiManager.WindowInfo;
13
import org.gvsig.gui.beans.AcceptCancelPanel;
14
import org.gvsig.i18n.Messages;
15

  
16
/**
17
 * Encapsulates DecimalFormatPanel on an IWindow that can be directly
18
 * opened as Dialog.
19
 * 
20
 * @author Cesar Martinez Izquierdo
21
 *
22
 */
23
public class DecimalFormatDialog extends JPanel
24
				implements IWindow, ActionListener {
25
	private WindowInfo wi = null;
26
	private DecimalFormatPanel mainPanel;
27
	private AcceptCancelPanel okCancelPanel;
28
	private ActionListener okAction;
29
	private ActionListener cancelAction;
30
	
31
	public DecimalFormatDialog(ActionListener okAction, ActionListener cancelAction) {
32
		super(new BorderLayout());
33
		this.okAction = okAction;
34
		this.cancelAction = cancelAction;
35
		initComponents();
36
	}
37
	
38
	protected void initComponents() {
39
		mainPanel = new DecimalFormatPanel();
40
		// empty border is used here as margin
41
		mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
42
		okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
43
		okCancelPanel.addOkButtonActionListener(this);
44
		okCancelPanel.addCancelButtonActionListener(this);
45
		this.add(mainPanel, BorderLayout.CENTER);
46
		this.add(okCancelPanel, BorderLayout.SOUTH);
47
	}
48
	
49
	public DecimalFormatPanel getPanel() {
50
		return mainPanel;
51
	}
52
	
53
	public WindowInfo getWindowInfo() {
54
		if (wi == null) {
55
			wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
56
			wi.setWidth(300);
57
			wi.setHeight(150);
58
			wi.setTitle(Messages.getText("symbol_property_editor"));
59
		}
60
		return wi;
61
	}
62

  
63
	public Object getWindowProfile() {
64
		return WindowInfo.DIALOG_PROFILE;
65
	}
66

  
67
	public void actionPerformed(ActionEvent e) {
68
		PluginServices.getMDIManager().closeWindow(this);
69
	}
70
	
71
	public void addOkButtonActionListener(ActionListener l) {
72
		okCancelPanel.addOkButtonActionListener(l);
73
	}
74
	public void addCancelButtonActionListener(ActionListener l) {
75
		okCancelPanel.addCancelButtonActionListener(l);
76
	}
77

  
78
}
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/gui/numberFormat/DecimalFormatPanel.java
1 1
package org.gvsig.app.project.documents.layout.fframes.gui.numberFormat;
2 2

  
3
import java.awt.BorderLayout;
4 3
import java.awt.event.ActionEvent;
5 4
import java.awt.event.ActionListener;
6 5
import java.text.DecimalFormat;
7 6
import java.text.DecimalFormatSymbols;
8 7

  
9 8
import javax.swing.JComboBox;
10
import javax.swing.JFrame;
11 9
import javax.swing.JLabel;
12 10

  
13 11
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
......
154 152
		else {
155 153
			b_decimalSep = false;
156 154
		}
157
		if (thousandsSeparator!=null && thousandsSeparator.length()>0) {
155
		if (thousandsSeparator!=null &&
156
				thousandsSeparator!=getCbThousandsSep().getNoneItem() &&
157
				thousandsSeparator.length()>0) {
158 158
			sym.setGroupingSeparator(thousandsSeparator.charAt(0));
159 159
			b_thousandsSep = true;
160 160
		}
......
230 230
	
231 231
	public void setFormat(DecimalFormat format) {
232 232
		this.format = format;
233
		boolean groupingUsed = format.isGroupingUsed();
233 234
		getTfDecimalDigits().setInteger(format.getMinimumFractionDigits());
234 235
		
235 236
		String decSep = String.valueOf(format.getDecimalFormatSymbols().getDecimalSeparator());
236 237
		selectItem(getCbDecimalSep(), decSep);
237 238
		
238
		String thousandsSep = String.valueOf(format.getDecimalFormatSymbols().getGroupingSeparator());
239
		selectItem(getCbThousandsSep(), thousandsSep);
239
		if (groupingUsed) {
240
			String thousandsSep = String.valueOf(format.getDecimalFormatSymbols().getGroupingSeparator());
241
			selectItem(getCbThousandsSep(), thousandsSep);
242
		}
243
		else {
244
			selectItem(getCbThousandsSep(), getCbThousandsSep().getNoneItem());
245
		}
240 246
	}
241 247
	
242 248
	/**
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/gui/dialogs/FFrameGridDialog.java
22 22
package org.gvsig.app.project.documents.layout.fframes.gui.dialogs;
23 23

  
24 24
import java.awt.BorderLayout;
25
import java.awt.FlowLayout;
26 25
import java.awt.Font;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.Insets;
29
import java.awt.event.ActionEvent;
27 30
import java.awt.event.ActionListener;
31
import java.awt.event.FocusEvent;
32
import java.awt.event.FocusListener;
28 33
import java.awt.geom.Rectangle2D;
34
import java.text.DecimalFormat;
29 35

  
30 36
import javax.swing.BoxLayout;
31 37
import javax.swing.ButtonGroup;
......
42 48
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid;
43 49
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
44 50
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
51
import org.gvsig.app.project.documents.layout.fframes.gui.numberFormat.DecimalFormatDialog;
52
import org.gvsig.app.project.documents.layout.fframes.gui.numberFormat.DecimalFormatPanel;
45 53
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
46 54
import org.gvsig.app.project.documents.view.legend.gui.PanelEditSymbol;
47 55
import org.gvsig.fmap.geom.Geometry;
56
import org.gvsig.fmap.geom.primitive.Envelope;
48 57
import org.gvsig.fmap.mapcontext.MapContext;
49 58
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
50 59
import org.gvsig.gui.beans.AcceptCancelPanel;
60
import org.gvsig.gui.beans.numberTextField.NumberTextField;
61
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
62
import org.gvsig.gui.beans.swing.ValidatingTextField;
63
import org.gvsig.gui.beans.swing.ValidatingTextField.Cleaner;
64
import org.gvsig.gui.beans.swing.ValidatingTextField.Validator;
65
import org.gvsig.i18n.Messages;
66
import org.gvsig.math.intervals.IntervalUtils;
51 67

  
52 68
public class FFrameGridDialog extends AbstractFFrameDialog implements
53 69
IFFrameDialog {
54 70

  
55 71
    private static final long serialVersionUID = 1L;
56
    private JPanel jPanel1 = null;
57
    private JPanel jPanel4 = null;
58
    private JLabel jLabel = null;
72
    private JPanel pnlMain = null;
59 73
    private JTextField txtIntervalX = null;
60
    private JPanel jPanel5 = null;
61
    private JPanel jPanel6 = null;
62
    private JPanel jPanel7 = null;
63
    private JLabel jLabel1 = null;
74
    private JPanel pnlIntervalGroup = null;
64 75
    private JTextField txtIntervalY = null;
65 76
    private JLabel lblUnitsX = null;
66 77
    private JLabel lblUnitsY = null;
......
69 80
    private JRadioButton rbPoints = null;
70 81
    private JRadioButton rbLines = null;
71 82
    private JButton bSymbol = null;
72
    private JPanel jPanel10 = null;
73
    private JPanel jPanel11 = null;
83
    private JPanel pnlLabelGroup = null;
84
    private JPanel pnlFont = null;
74 85
    private JButton jButton = null;
75 86
    private ColorChooserPanel colorChooserPanel = null;
76
    private JPanel jPanel12 = null;
77
    private JLabel jLabel2 = null;
78
    private JTextField txtSize = null;
79 87

  
80 88
    private FFrameGrid fframegrid;
81 89
    private FFrameView fframeview;
82 90
    private AcceptCancelPanel accept;
83 91
    private FFrameGrid newFFrameGrid;
84
    private Rectangle2D rect; // @jve:decl-index=0:
85
    private LayoutPanel layout;
86 92
    // private Color textcolor;
87 93
    private ISymbol symbol;
88 94
    private Font m_font;
89 95
    private ButtonGroup bg = new ButtonGroup();
90
    private JPanel jPanel15 = null;
96
	private NumberTextField tfNumDivHoriz = null;
97
	private NumberTextField tfNumDivVert = null;
98
	private JRadioButton rbHorizDiv = null;
99
	private JRadioButton rbVertDiv = null;
100
	private JPanel pnlDistance = null;
101
	private JRadioButton rbDistance = null;
102
	private JButton btnNumberFormat = null;
103
	private JIncrementalNumberField nfRotationHoriz = null;
104
	private ButtonGroup btGrpInterval = null;
105
	private static final Insets defaultInsets = new Insets(4, 4, 4, 4);
106
	private DecimalFormat format = new DecimalFormat();
107
	private JIncrementalNumberField nfRotationVert = null;
91 108

  
92 109
    public FFrameGridDialog(LayoutPanel layout, FFrameGrid fframe) {
93 110
        super(layout, fframe);
......
102 119
     */
103 120
    private void initialize() {
104 121
        this.setLayout(new BorderLayout());
105
        this.setSize(350, 265);
106
        this.add(getJPanel1(), java.awt.BorderLayout.CENTER);
122
        this.add(getPnlMain(), java.awt.BorderLayout.CENTER);
107 123
        this.add(getAcceptCancelPanel(), java.awt.BorderLayout.SOUTH);
108 124
    }
109 125

  
......
112 128
     * 
113 129
     * @return javax.swing.JPanel
114 130
     */
115
    private JPanel getJPanel1() {
116
        if (jPanel1 == null) {
117
            jPanel1 = new JPanel();
118
            jPanel1.setLayout(new BorderLayout());
119
            jPanel1.add(getJPanel5(), java.awt.BorderLayout.NORTH);
120
            jPanel1.add(getJPanel15(), java.awt.BorderLayout.CENTER);
121
        }
122
        return jPanel1;
123
    }
131
    private JPanel getPnlMain() {
132
        if (pnlMain == null) {
133
            pnlMain = new JPanel(new GridBagLayout());
134
            GridBagConstraints c = new GridBagConstraints();
135
            c.insets = new Insets(4, 4, 4, 4);
136
            c.fill = GridBagConstraints.HORIZONTAL;
137
            c.anchor = GridBagConstraints.FIRST_LINE_START;
138
            c.gridx = 0;
139
            int row = 0;
140
            c.gridy = row++;
141
            pnlMain.add(getPnlIntervalGroup(), c);
142
            c.gridy = row++;
143
            pnlMain.add(getPnlLabelGroup(), c);
144
            c.gridy = row++;
145
            c.fill = GridBagConstraints.NONE;
146
            pnlMain.add(getPnlSymbologyGroup(), c);
124 147

  
125
    /**
126
     * This method initializes jPanel4
127
     * 
128
     * @return javax.swing.JPanel
129
     */
130
    private JPanel getJPanel4() {
131
        if (jPanel4 == null) {
132
            lblUnitsX = new JLabel();           
133
            jLabel = new JLabel();
134
            jLabel.setText("x");
135
            jLabel.setName("jLabel");
136
            jPanel4 = new JPanel();
137
            jPanel4.setLayout(new FlowLayout());
138
            jPanel4.add(jLabel, null);
139
            jPanel4.add(getTxtIntervalX(), null);
140
            jPanel4.add(lblUnitsX, null);
141 148
        }
142
        return jPanel4;
149
        return pnlMain;
143 150
    }
144 151

  
145 152
    /**
......
149 156
     */
150 157
    private JTextField getTxtIntervalX() {
151 158
        if (txtIntervalX == null) {
152
            txtIntervalX = new JTextField();
159
            txtIntervalX = new JTextField(10);
153 160
            txtIntervalX.setText(String.valueOf(fframegrid.getIntervalX()));
154
            txtIntervalX.setPreferredSize(new java.awt.Dimension(60, 20));
155 161
            txtIntervalX.setName("txtIntervalX");
156 162
        }
157 163
        return txtIntervalX;
158 164
    }
159 165

  
160 166
    /**
161
     * This method initializes jPanel5
162
     * 
163
     * @return javax.swing.JPanel
164
     */
165
    private JPanel getJPanel5() {
166
        if (jPanel5 == null) {
167
            jPanel5 = new JPanel();
168
            jPanel5.setLayout(new FlowLayout());
169
            jPanel5.add(getJPanel6(), null);
170
            jPanel5.add(getJPanel8(), null);
171
        }
172
        return jPanel5;
173
    }
174

  
175
    /**
176 167
     * This method initializes jPanel6
177 168
     * 
178 169
     * @return javax.swing.JPanel
179 170
     */
180
    private JPanel getJPanel6() {
181
        if (jPanel6 == null) {
182
            jPanel6 = new JPanel();
183
            jPanel6.setLayout(new BoxLayout(getJPanel6(), BoxLayout.Y_AXIS));
184
            jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(
185
                null, PluginServices.getText(this, "Intervalo"),
186
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
187
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
188
            jPanel6.add(getJPanel4(), null);
189
            jPanel6.add(getJPanel7(), null);
171
    private JPanel getPnlIntervalGroup() {
172
        if (pnlIntervalGroup == null) {
173
            pnlIntervalGroup = new JPanel(new GridBagLayout());
174
            pnlIntervalGroup.setBorder(javax.swing.BorderFactory.createTitledBorder(
175
                    null, PluginServices.getText(this, "Intervalo"),
176
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
177
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
178
            GridBagConstraints c = new GridBagConstraints();
179
            c.anchor = GridBagConstraints.FIRST_LINE_START;
180
            c.gridx = 0;
181
            c.insets = defaultInsets;
182
            int row = 0;
183
            c.gridy = row++;
184
            c.gridwidth = 1;
185
            pnlIntervalGroup.add(getRbDistance(), c);
186
            c.gridx = 1;
187
            c.gridwidth = 2;
188
            pnlIntervalGroup.add(getPnlDistance(), c);
189
            
190
            c.gridx = 0;
191
            c.gridy = row++;
192
            c.gridwidth = 2;
193
            pnlIntervalGroup.add(getRbHorizDiv(), c);
194
            c.gridx = 2;
195
            c.gridwidth = 1;
196
            pnlIntervalGroup.add(getTfNumDivHoriz(), c);
197
            
198
            c.gridy = row++;
199
            c.gridx = 0;
200
            c.gridwidth = 2;
201
            pnlIntervalGroup.add(getRbVertDiv(), c);
202
            c.gridx = 2;
203
            c.gridwidth = 1;
204
            pnlIntervalGroup.add(getTfNumDivVert(), c);
205
            
206
            getRbDistance().setSelected(true);
207
            getBtnGrpInterval().add(getRbDistance());
208
            getBtnGrpInterval().add(getRbVertDiv());
209
            getBtnGrpInterval().add(getRbHorizDiv());
190 210
        }
191
        return jPanel6;
211
        return pnlIntervalGroup;
192 212
    }
193

  
194
    /**
195
     * This method initializes jPanel7
196
     * 
197
     * @return javax.swing.JPanel
198
     */
199
    private JPanel getJPanel7() {
200
        if (jPanel7 == null) {
201
            lblUnitsY = new JLabel();           
202
            jLabel1 = new JLabel();
203
            jLabel1.setText("y");
204
            jPanel7 = new JPanel();
205
            jPanel7.add(jLabel1, null);
206
            jPanel7.add(getTxtIntervalY(), null);
207
            jPanel7.add(lblUnitsY, null);
208
        }
209
        return jPanel7;
213
    
214
    private JRadioButton getRbHorizDiv() {
215
    	if (rbHorizDiv==null) {
216
    		rbHorizDiv = new JRadioButton(Messages.getText("Number_of_horizontal_divisions"));
217
    		rbDistance.setSelected(fframegrid.getUseNumDivisions()==FFrameGrid.NUM_DIVISIONS_HORIZ_MODE);
218
    	}
219
    	return rbHorizDiv;
210 220
    }
221
    
222
    private JRadioButton getRbVertDiv() {
223
    	if (rbVertDiv==null) {
224
    		rbVertDiv = new JRadioButton(Messages.getText("Number_of_vertical_divisions"));
225
    		rbDistance.setSelected(fframegrid.getUseNumDivisions()==FFrameGrid.NUM_DIVISIONS_VERT_MODE);
226
    	}
227
    	return rbVertDiv;
228
    }
229
    
230
    private JRadioButton getRbDistance() {
231
    	if (rbDistance==null) {
232
    		rbDistance = new JRadioButton(Messages.getText("Distance"));
233
    		rbDistance.setSelected(fframegrid.getUseNumDivisions()==FFrameGrid.FIXED_DISTANCE_MODE);
234
    	}
235
    	return rbDistance;
236
    }
237
    
238
    private JPanel getPnlDistance() {
239
    	if (pnlDistance==null) {
240
    		pnlDistance = new JPanel(new GridBagLayout());
241
    		GridBagConstraints c = new GridBagConstraints();
242
    		
243
    		int row = 0;
244
    		c.insets = new Insets(0, 4, 4, 4);
245
    		c.gridy = row++;
246
            c.gridx = 0;
247
            c.anchor = GridBagConstraints.LINE_START;
248
            JLabel labelX = new JLabel("x");
249
    		pnlDistance.add(labelX, c);
250
    		c.gridx = 1;
251
    		pnlDistance.add(getTxtIntervalX(), c);
252
    		lblUnitsX = new JLabel();
253
    		c.gridx = 2;
254
    		pnlDistance.add(lblUnitsX, c);
255
    		
256
    		c.insets = defaultInsets;
257
    		c.gridy = row++;
258
            c.gridx = 0;
259
            JLabel labelY = new JLabel("y");
260
    		pnlDistance.add(labelY, c);
261
    		c.gridx = 1;
262
    		pnlDistance.add(getTxtIntervalY(), c);
263
    		lblUnitsY = new JLabel();
264
    		c.gridx = 2;
265
    		pnlDistance.add(lblUnitsY, c);
266
    		
267
    	}
268
    	return pnlDistance;
269
    }
270
    
271
    private ButtonGroup getBtnGrpInterval() {
272
    	if (btGrpInterval==null) {
273
    		btGrpInterval = new ButtonGroup();
274
    	}
275
    	return btGrpInterval;
276
    }
277
    
278
    private NumberTextField getTfNumDivHoriz() {
279
    	if (tfNumDivHoriz==null) {
280
    		tfNumDivHoriz = new NumberTextField(3);
281
    		tfNumDivHoriz.addFocusListener(new FocusListener() {
282
				public void focusLost(FocusEvent e) {
283
					if (getRbHorizDiv().isSelected()) {
284
						calculateDistance(1, tfNumDivHoriz.getIntValue());
285
					}
286
				}
287
				public void focusGained(FocusEvent e) {}
288
			});
289
    		tfNumDivHoriz.setValue(5);
290
    	}
291
    	return tfNumDivHoriz;
292
    }
293
    protected void calculateDistance(int axis, int numDivisions) {
294
    	if (fframeview!=null &&
295
    			fframeview.getMapContext().getViewPort().getAdjustedEnvelope()!=null) {
296
    		Envelope env = fframeview.getMapContext().getViewPort().getAdjustedEnvelope();
297
    		double interval = IntervalUtils.roundIntervalDivision(env.getLength(axis), numDivisions);
298
    		getTxtIntervalX().setText(String.valueOf(interval));
299
    		getTxtIntervalY().setText(String.valueOf(interval));
300
    	}
301
    }
302
    
303
    private NumberTextField getTfNumDivVert() {
304
    	if (tfNumDivVert==null) {
305
    		tfNumDivVert = new NumberTextField(3);
306
    		tfNumDivVert.addFocusListener(new FocusListener() {
307
				public void focusLost(FocusEvent e) {
308
					if (getRbVertDiv().isSelected()) {
309
						calculateDistance(0, tfNumDivVert.getIntValue());
310
					}
311
				}
312
				public void focusGained(FocusEvent e) {}
313
			});
314
    		tfNumDivVert.setValue(5);
315
    	}
316
    	return tfNumDivVert;
317
    }
211 318

  
212 319
    /**
213 320
     * This method initializes txtIntervalY
......
216 323
     */
217 324
    private JTextField getTxtIntervalY() {
218 325
        if (txtIntervalY == null) {
219
            txtIntervalY = new JTextField();
326
            txtIntervalY = new JTextField(10);
220 327
            txtIntervalY.setText(String.valueOf(fframegrid.getIntervalY()));
221
            txtIntervalY.setPreferredSize(new java.awt.Dimension(60, 20));
222 328
        }
223 329
        return txtIntervalY;
224 330
    }
......
228 334
     * 
229 335
     * @return javax.swing.JPanel
230 336
     */
231
    private JPanel getJPanel8() {
337
    private JPanel getPnlSymbologyGroup() {
232 338
        if (jPanel8 == null) {
233 339
            jPanel8 = new JPanel();
234
            jPanel8.setLayout(new BoxLayout(getJPanel8(), BoxLayout.Y_AXIS));
340
            jPanel8.setLayout(new BoxLayout(getPnlSymbologyGroup(), BoxLayout.Y_AXIS));
235 341
            jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(
236 342
                null, PluginServices.getText(this, "Simbologia"),
237 343
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
......
322 428
     * 
323 429
     * @return javax.swing.JPanel
324 430
     */
325
    private JPanel getJPanel10() {
326
        if (jPanel10 == null) {
327
            jPanel10 = new JPanel();
328
            jPanel10.setLayout(new BorderLayout());
329
            jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(
330
                null, PluginServices.getText(this, "Font"),
431
    private JPanel getPnlLabelGroup() {
432
        if (pnlLabelGroup == null) {
433
            pnlLabelGroup = new JPanel(new GridBagLayout());
434
            pnlLabelGroup.setBorder(javax.swing.BorderFactory.createTitledBorder(
435
                null, PluginServices.getText(this, "Label"),
331 436
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
332 437
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
333
            jPanel10.add(getJPanel11(), java.awt.BorderLayout.NORTH);
334
            jPanel10.add(getJPanel12(), java.awt.BorderLayout.CENTER);
438
            
439
            GridBagConstraints c = new GridBagConstraints();
440
            int row = 0;
441
            
442
            c.insets = defaultInsets;
443
            c.gridx = 0;
444
            c.gridy = row++;
445
            c.gridwidth = 1;
446
            c.anchor = GridBagConstraints.LINE_START;
447
            pnlLabelGroup.add(new JLabel(Messages.getText("Number_format")), c);
448
            c.gridx = 1;
449
            pnlLabelGroup.add(getBtnNumberFormat(), c);
450
            
451
            c.gridx = 0;
452
            c.gridy = row++;
453
            c.gridwidth = 1;
454
            pnlLabelGroup.add(new JLabel(Messages.getText("Horizontal_rotation")), c);
455
            c.gridx = 1;
456
            pnlLabelGroup.add(getNfRotationHoriz(), c);
457
            
458
            c.gridy = row++;
459
            c.gridx = 0;
460
            pnlLabelGroup.add(new JLabel(Messages.getText("Vertical_rotation")), c);
461
            c.gridx = 1;
462
            pnlLabelGroup.add(getNfRotationVert(), c);
463
            
464
            c.insets = new Insets(4, 0, 4, 4);
465
            c.gridx = 0;
466
            c.gridy = row++;
467
            c.gridwidth = 2;
468
            pnlLabelGroup.add(getPnlFont(), c);
335 469
        }
336
        return jPanel10;
470
        return pnlLabelGroup;
337 471
    }
472
    
473
    private JButton getBtnNumberFormat() {
474
    	if (btnNumberFormat==null) {
475
    		btnNumberFormat = new JButton(Messages.getText("Format"));
476
    		btnNumberFormat.addActionListener(new java.awt.event.ActionListener() {
477
                public void actionPerformed(java.awt.event.ActionEvent e) {
478
                	openDecimalFormatDialog();
479
                }
480
    		});
481
    	}
482
    	return btnNumberFormat;
483
    }
484
    
485
    protected void openDecimalFormatDialog() {
486
    	final DecimalFormatDialog dialog = new DecimalFormatDialog(null, null);
487
    	dialog.addOkButtonActionListener(new ActionListener() {
488
			public void actionPerformed(ActionEvent e) {
489
				applyDecimalFormatSettings(dialog.getPanel());
490
			}
491
    		
492
    	});
493
    	dialog.getPanel().setFormat(fframegrid.getLabelFormat());
494
    	PluginServices.getMDIManager().addWindow(dialog);
495
    }
496
    
497
    protected void applyDecimalFormatSettings(DecimalFormatPanel p) {
498
    	format = p.getFormat();
499
    }
500
    
501
    private JIncrementalNumberField getNfRotationHoriz() {
502
    	if (nfRotationHoriz==null) {
503
			Cleaner cleaner = ValidatingTextField.NUMBER_CLEANER;
504
			Validator validator = ValidatingTextField.INTEGER_VALIDATOR;
505
    		nfRotationHoriz = new JIncrementalNumberField("rotationH", 3, validator, cleaner, 0.0d, 360.0d, 1.0);
506
    		nfRotationHoriz.setInteger((int)fframegrid.getHorizLabelRotation());
507
    	}
508
    	return nfRotationHoriz;
509
    }
510
    
511
    private JIncrementalNumberField getNfRotationVert() {
512
    	if (nfRotationVert==null) {
513
			Cleaner cleaner = ValidatingTextField.NUMBER_CLEANER;
514
			Validator validator = ValidatingTextField.INTEGER_VALIDATOR;
515
    		nfRotationVert  = new JIncrementalNumberField("rotationV", 3, validator, cleaner, 0.0d, 360.0d, 1.0);
516
    		nfRotationVert.setInteger((int)fframegrid.getVertLabelRotation());
517
    	}
518
    	return nfRotationVert;
519
    }
338 520

  
339 521
    /**
340 522
     * This method initializes jPanel11
341 523
     * 
342 524
     * @return javax.swing.JPanel
343 525
     */
344
    private JPanel getJPanel11() {
345
        if (jPanel11 == null) {
346
            jPanel11 = new JPanel();
347
            jPanel11.add(getJButton(), null);
348
            jPanel11.add(getColorChooserPanel(), null);
526
    private JPanel getPnlFont() {
527
        if (pnlFont == null) {
528
            pnlFont = new JPanel();
529
            pnlFont.add(new JLabel(Messages.getText("Font_type")), null);
530
            pnlFont.add(getJButton(), null);
531
            pnlFont.add(getColorChooserPanel(), null);
349 532
        }
350
        return jPanel11;
533
        return pnlFont;
351 534
    }
352 535

  
353 536
    /**
......
390 573
        return colorChooserPanel;
391 574
    }
392 575

  
393
    /**
394
     * This method initializes jPanel12
395
     * 
396
     * @return javax.swing.JPanel
397
     */
398
    private JPanel getJPanel12() {
399
        if (jPanel12 == null) {
400
            jLabel2 = new JLabel();
401
            jLabel2.setText(PluginServices.getText(this, "size"));
402
            jPanel12 = new JPanel();
403
            jPanel12.add(jLabel2, null);
404
            jPanel12.add(getTxtSize(), null);
405
        }
406
        return jPanel12;
407
    }
408

  
409
    /**
410
     * This method initializes txtSize
411
     * 
412
     * @return javax.swing.JTextField
413
     */
414
    private JTextField getTxtSize() {
415
        if (txtSize == null) {
416
            txtSize = new JTextField();
417
            txtSize.setText(String.valueOf(fframegrid.getFontSize()));
418
            txtSize.setPreferredSize(new java.awt.Dimension(40, 20));
419
        }
420
        return txtSize;
421
    }
422

  
423 576
    public IFFrame getFFrame() {
424 577
        return newFFrameGrid;
425 578
    }
......
433 586
                    try {
434 587
                        newFFrameGrid = (FFrameGrid) fframegrid.clone();
435 588
                        newFFrameGrid.setFFrameDependence(fframeview);
436
                        // newFFrameGrid.setBoundBox();
589
                        // FIXME: use the new properties here
590
                        
437 591
                        newFFrameGrid
438 592
                        .setIntervalX(Double.parseDouble(getTxtIntervalX()
439 593
                            .getText().toString()));
......
451 605

  
452 606
                        newFFrameGrid.setTextColor(getColorChooserPanel()
453 607
                            .getColor());
454
                        newFFrameGrid.setSizeFont(Integer.parseInt(getTxtSize()
455
                            .getText()));
608
                        newFFrameGrid.setSizeFont(m_font.getSize());
456 609
                        newFFrameGrid.setIsLine(getRbLines().isSelected());
457 610
                        newFFrameGrid.setFont(m_font);
458 611
                        newFFrameGrid.setRotation(fframeview.getRotation());
612
                        newFFrameGrid.setHorizLabelRotation(getNfRotationHoriz().getInteger());
613
                        newFFrameGrid.setVertLabelRotation(getNfRotationVert().getInteger());
614
                        newFFrameGrid.setLabelFormat(format);
615
                        if (getRbDistance().isSelected()) {
616
                        	newFFrameGrid.setUseNumDivisions(FFrameGrid.FIXED_DISTANCE_MODE); 
617
                        }
618
                        else if (getRbHorizDiv().isSelected()) {
619
                        	newFFrameGrid.setUseNumDivisions(FFrameGrid.NUM_DIVISIONS_HORIZ_MODE);
620
                        }
621
                        else if (getRbVertDiv().isSelected()) {
622
                        	newFFrameGrid.setUseNumDivisions(FFrameGrid.NUM_DIVISIONS_VERT_MODE);
623
                        }
459 624
                    } catch (CloneNotSupportedException e1) {
460 625
                        LOG.error("It is not possible clonate the object", e);
461 626
                    }
......
474 639
                }
475 640
            };
476 641
            accept = new AcceptCancelPanel(okAction, cancelAction);
477
            // accept.setPreferredSize(new java.awt.Dimension(300, 300));
478
            // accept.setBounds(new java.awt.Rectangle(243,387,160,28));
479 642
            accept.setEnabled(true);
480
            // accept.setBounds(new java.awt.Rectangle(45, 250, 300, 32));
481 643
            accept.setVisible(true);
482 644
        }
483 645
        return accept;
484 646
    }
485 647

  
486
    public void setRectangle(Rectangle2D r) {
487
        rect = r;
488
    }
489

  
490 648
    public WindowInfo getWindowInfo() {
491 649
        WindowInfo m_viewinfo =
492 650
            new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
493 651
        m_viewinfo.setTitle(PluginServices.getText(this, "Grid_settings"));
652
        m_viewinfo.setWidth(450);
653
        m_viewinfo.setHeight(420);
494 654

  
495 655
        return m_viewinfo;
496 656
    }
......
500 660
        return false;
501 661
    }
502 662

  
503
    /**
504
     * This method initializes jPanel15
505
     * 
506
     * @return javax.swing.JPanel
507
     */
508
    private JPanel getJPanel15() {
509
        if (jPanel15 == null) {
510
            jPanel15 = new JPanel();
511
            jPanel15.add(getJPanel10(), null);
512
        }
513
        return jPanel15;
514
    }
515

  
516 663
    public void setFFrameView(FFrameView fview) {
517 664
        fframeview = fview;
518 665
        //Set the label
......
528 675
        return WindowInfo.DIALOG_PROFILE;
529 676
    }
530 677

  
678
	public void setRectangle(Rectangle2D r) {
679
		// nothing to do as this fframe takes the size from the associated fframeview
680
	}
681

  
531 682
} // @jve:decl-index=0:visual-constraint="10,10"
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutExtension.java
30 30

  
31 31
import org.slf4j.Logger;
32 32
import org.slf4j.LoggerFactory;
33

  
34 33
import org.gvsig.andami.IconThemeHelper;
35 34
import org.gvsig.andami.PluginServices;
36 35
import org.gvsig.andami.messages.NotificationManager;
......
45 44
import org.gvsig.tools.ToolsLocator;
46 45
import org.gvsig.tools.persistence.PersistenceManager;
47 46
import org.gvsig.tools.persistence.PersistentState;
47
import org.gvsig.tools.persistence.text.JavaTextFactory;
48 48
import org.gvsig.utils.GenericFileFilter;
49 49

  
50 50
/**
......
160 160
     * @see org.gvsig.andami.plugins.IExtension#initialize()
161 161
     */
162 162
    public void initialize() {
163
    	registerPersistence();
163 164
        registerIcons();
164 165
    }
165 166

  
167
    private void registerPersistence() {
168
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
169
        JavaTextFactory factory = new JavaTextFactory();
170
        manager.registerFactory(factory);
171
    }
172
    
166 173
    private void registerIcons() {
167 174
        
168 175
        IconThemeHelper.registerIcon("action", "application-layout-template-save", this);
trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/tools/persistence/text/JavaTextFactory.java
1
package org.gvsig.tools.persistence.text;
2

  
3
import java.awt.Color;
4
import java.awt.geom.Point2D;
5
import java.text.DecimalFormat;
6
import java.text.DecimalFormatSymbols;
7

  
8
import org.gvsig.tools.dynobject.DynStruct;
9
import org.gvsig.tools.persistence.AbstractMultiPersistenceFactory;
10
import org.gvsig.tools.persistence.PersistentState;
11
import org.gvsig.tools.persistence.exception.PersistenceException;
12

  
13
public class JavaTextFactory extends AbstractMultiPersistenceFactory {
14
	private static JavaTextFactory instance = null; 
15
	
16
	private static final String DYNCLASS_DECIMAL_FORMAT_NAME = "DecimalFormat";
17
	private static final String DYNCLASS_DECIMAL_FORMAT_DESCRIPTION = "DecimalFormat";
18
	private static final String PATTERN_FIELD = "pattern";
19
	private static final String DECIMAL_SEP_FIELD = "decimalSep";
20
	private static final String GROUPING_SEP_FIELD = "groupingSep";
21
	
22
	protected void makeDefinitions() {
23
		DynStruct decimalFromatDef = this.addDefinition(DecimalFormat.class, DYNCLASS_DECIMAL_FORMAT_NAME, DYNCLASS_DECIMAL_FORMAT_DESCRIPTION);
24
		decimalFromatDef.addDynFieldString(PATTERN_FIELD).setMandatory(true);
25
		decimalFromatDef.addDynFieldString(DECIMAL_SEP_FIELD).setMandatory(true);
26
		decimalFromatDef.addDynFieldString(GROUPING_SEP_FIELD).setMandatory(true);
27
	}
28
	
29
	public Object createFromState(PersistentState state)
30
			throws PersistenceException {
31
		if (this.getManagedClass(state).isAssignableFrom(DecimalFormat.class)) {
32
			String pattern = state.getString(PATTERN_FIELD);
33
			String decimalSep = state.getString(DECIMAL_SEP_FIELD);
34
			String groupingSep = state.getString(GROUPING_SEP_FIELD);
35
			
36
			DecimalFormatSymbols sym = DecimalFormatSymbols.getInstance();
37
			if (decimalSep!=null && decimalSep.length()>0) {
38
				sym.setDecimalSeparator(decimalSep.charAt(0));
39
			}
40
			if (groupingSep!=null && groupingSep.length()>0) {
41
				sym.setGroupingSeparator(groupingSep.charAt(0));
42
			}
43
			return new DecimalFormat(pattern, sym);
44
		}
45
		throw new RuntimeException(); //FIXME 
46
	}
47

  
48
	public void saveToState(PersistentState state, Object obj)
49
			throws PersistenceException {
50
		if (obj instanceof DecimalFormat) {
51
			DecimalFormat format = (DecimalFormat) obj;
52
			state.set(PATTERN_FIELD, format.toPattern());
53
			state.set(DECIMAL_SEP_FIELD, String.valueOf(format.getDecimalFormatSymbols().getDecimalSeparator()));
54
			state.set(GROUPING_SEP_FIELD, String.valueOf(format.getDecimalFormatSymbols().getGroupingSeparator()));
55
			return;
56
		}
57
		throw new RuntimeException(); //FIXME 
58
	}
59

  
60

  
61
	
62
}

Also available in: Unified diff