Revision 3374

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/FFrameScaleBar.java
111 111
    private boolean aboveDescription = false;
112 112
    private String description = "";
113 113
    private int dependenceIndex=-1;
114
    private int numDec=0;
114 115

  
115 116
    /**
116 117
     * Creates a new FFrameScaleBar object.
......
192 193
     *
193 194
     * @return long.
194 195
     */
195
    public double obtainInterval() {
196
    public String obtainInterval() {
196 197
        if (fframeview != null) {
197 198
            Rectangle2D.Double rect = getBoundBox();
198 199

  
......
208 209
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
209 210
            m_dif = getExact(scaleXunit);
210 211
            m_numUnit = m_numUnit * m_dif;
211
            m_interval = (scaleXunit * m_dif);
212
            m_interval=scaleXunit;
213
            ///m_interval = (scaleXunit * m_dif);
212 214

  
213
            return m_interval;
215
            return format(m_interval);
214 216
        }
215 217

  
216
        return 0;
218
        return "0";
217 219
    }
218 220

  
219 221
    /**
......
303 305
     *
304 306
     * @return Intervalo.
305 307
     */
306
    public double getInterval() {
307
        return m_interval;
308
    public String getInterval() {
309
        return format(m_interval);
308 310
    }
309 311

  
310 312
    /**
......
455 457
            double scaleXunit = (m_numUnit * getScaleView()) / m_typeUnit;
456 458
            m_dif = getExact(scaleXunit);
457 459
            m_numUnit = m_numUnit * m_dif;
458
            m_interval = (long) (scaleXunit * m_dif);
460
            m_interval = (scaleXunit * m_dif);
459 461
        }
460 462

  
461 463
        if (m_bIntervalSet) {
......
496 498
        g.setFont(m_f);
497 499
        
498 500
        FontMetrics fm=g.getFontMetrics();
501
        String formatInterval=format(m_interval);
499 502
        double d=rectotal.getWidth()/m_numinterval+m_hasleft;
500
        double difpos=((r.getHeight() / 4) * String.valueOf(m_interval).length()) / 4;
501
    	if (fm.stringWidth(String.valueOf(m_interval))>(d*0.7)){
502
    		double dif=fm.stringWidth(String.valueOf(m_interval))/(d*0.7);
503
        double difpos=((r.getHeight() / 4) * formatInterval.length()) / 4;
504
    	if (fm.stringWidth(formatInterval)>(d*0.7)){
505
    		double dif=fm.stringWidth(formatInterval)/(d*0.7);
503 506
    		difpos=(d*0.7)/2;
504 507
    		m_f=new Font(m_f.getName(),m_f.getStyle(),(int)(m_f.getSize()/dif));
505 508
    		g.setFont(m_f);
......
862 865
        xml.putProperty("fontStyle", m_f.getStyle());
863 866
        xml.putProperty("tag", getTag());
864 867
        xml.putProperty("m_rotation", getRotation());
868
        xml.putProperty("numDec",numDec);
865 869
        if (fframeview != null){
866 870
        Layout layout = fframeview.getLayout();
867 871
        IFFrame[] fframes = layout.getAllFFrames();
......
974 978
            this.aboveDescription = xml.getBooleanProperty("aboveDescription");
975 979
            this.description = xml.getStringProperty("description");
976 980
        }
981
        if (xml.contains("numDec")){
982
        	setNumDec(xml.getIntProperty("numDec"));
983
        }
977 984
    }
978 985

  
979 986
    /**
......
1157 1164
    public String format(double d) {
1158 1165
    	NumberFormat nf = NumberFormat.getInstance();
1159 1166
    	if ((d % (long)d )!=0){
1160
    		nf.setMaximumFractionDigits(2);
1167
    		nf.setMaximumFractionDigits(getNumDec());
1161 1168
    	}else{
1162 1169
    		nf.setMaximumFractionDigits(0);
1163 1170
    	}
......
1168 1175

  
1169 1176
		return nf.format(d);//(Double.valueOf(s).doubleValue());
1170 1177
	}
1178

  
1179
	public int getNumDec() {
1180
		return numDec;
1181
	}
1182

  
1183
	public void setNumDec(int numDec) {
1184
		this.numDec = numDec;
1185
	}
1171 1186
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/dialogs/FFrameScaleBarDialog.java
60 60
import java.awt.Color;
61 61
import java.awt.Component;
62 62
import java.awt.Dimension;
63
import java.awt.event.KeyEvent;
63 64
import java.awt.geom.Rectangle2D;
64 65

  
65 66
import javax.swing.ImageIcon;
......
137 138
	private JPRotation pRotation = null;
138 139
	private JLabel lblBarColor = null;
139 140
	private JLabel lblLabelColor = null;
141
	private JTextField txtNumDec = null;
142
	private JLabel lblNumDec = null;
140 143

  
141 144
	/**
142 145
	 * This is the default constructor
......
286 289
								fframescalebar.getNumInterval()));
287 290
						getTDivIzquierda().setText(String.valueOf(
288 291
								fframescalebar.getNumLeft()));
289
						getTIntervalo().setText(String.valueOf(
290
								fframescalebar.obtainInterval()));
292
						getTIntervalo().setText(fframescalebar.obtainInterval());
291 293
						getTfDescripcion().setText(fframescalebar.getDescripcion());
292 294
					}
293 295
					}
......
404 406
					public void actionPerformed(java.awt.event.ActionEvent e) {
405 407
						fframescalebar.setUnits(getCbUnidades()
406 408
													.getSelectedIndex());
407
						getTIntervalo().setText(Double.toString(
408
								fframescalebar.obtainInterval()));
409
						getTIntervalo().setText(fframescalebar.obtainInterval());
409 410
					}
410 411
				});
411 412
		}
......
437 438
		if (tIntervalo == null) {
438 439
			tIntervalo = new javax.swing.JTextField();
439 440
			tIntervalo.setPreferredSize(new java.awt.Dimension(90, 20));
440
			tIntervalo.setText(Double.toString(fframescalebar.getInterval()));
441
			tIntervalo.setText(fframescalebar.getInterval());
441 442
			tIntervalo.addKeyListener(new java.awt.event.KeyAdapter() {
442 443
					public void keyReleased(java.awt.event.KeyEvent e) {
443 444
						if (!tIntervalo.getText().toString().equals("")) {
......
484 485
						if (!tNumIntervalos.getText().toString().equals("")) {
485 486
							fframescalebar.setNumInterval(Integer.parseInt(
486 487
									tNumIntervalos.getText().toString()));
487
							getTIntervalo().setText(String.valueOf(
488
									fframescalebar.obtainInterval()));
488
							getTIntervalo().setText(fframescalebar.obtainInterval());
489 489
						}
490 490
					}
491 491
				});
......
569 569
						fframescalebar.setDescripcion(getTfDescripcion()
570 570
														  .getText());
571 571
						fframescalebar.setRotation(getPRotation().getRotation());
572
						fframescalebar.setNumDec(Integer.parseInt(getNumDec().getText()));
572 573
						PluginServices.getMDIManager().closeView(FFrameScaleBarDialog.this);
573 574
						m_layout.refresh();
574 575
						isAcepted = true;
......
817 818
	 */
818 819
	private JPanel getPBarra() {
819 820
		if (pBarra == null) {
821
			lblNumDec = new JLabel();
822
			lblNumDec.setText("numero_decimales_mostrar");
820 823
			lblBarColor = new JLabel();
821 824
			lblBarColor.setText(PluginServices.getText(this,"color"));
822 825
			pBarra = new JPanel();
......
826 829
					javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
827 830
					javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
828 831
			pBarra.add(getCbEscala(), null);
832
			pBarra.add(lblNumDec, null);
833
			pBarra.add(getNumDec(), null);
834
			pBarra.add(getJPanel5(), null);
829 835
			pBarra.add(getChbMantenerIntervalo(), null);
830
			pBarra.add(getJPanel5(), null);
831 836
			pBarra.add(getJPanel7(), null);
832 837
			pBarra.add(getJPanel6(), null);
833 838
			pBarra.add(lblBarColor, null);
834 839
			pBarra.add(getBBarraColor(), null);
835

  
836 840
			//pBarra.add(getJPanel(), null);
837 841
		}
838 842

  
......
1069 1073
		}
1070 1074
		return pRotation;
1071 1075
	}
1076

  
1077
	/**
1078
	 * This method initializes numDec	
1079
	 * 	
1080
	 * @return javax.swing.JTextField	
1081
	 */
1082
	private JTextField getNumDec() {
1083
		if (txtNumDec == null) {
1084
			txtNumDec = new JTextField();
1085
			txtNumDec.setPreferredSize(new java.awt.Dimension(30,20));
1086
			txtNumDec.setText(String.valueOf(fframescalebar.getNumDec()));
1087
			txtNumDec.addKeyListener(new java.awt.event.KeyAdapter() {
1088
				public void keyReleased(KeyEvent arg0) {
1089
					super.keyReleased(arg0);
1090
					if (!getNumDec().getText().toString().equals("")) {
1091
						fframescalebar.setNumDec(Integer.parseInt(
1092
								getNumDec().getText().toString()));
1093
						getTIntervalo().setText(fframescalebar.obtainInterval());
1094
					}
1095
				}
1096
			});
1097
		}
1098
		return txtNumDec;
1099
	}
1072 1100
} //  @jve:decl-index=0:visual-constraint="17,10"
1073 1101
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"

Also available in: Unified diff