Revision 8458 trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/MarkerFill.java

View differences:

MarkerFill.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.3  2006-10-30 19:30:35  jaume
46
* Revision 1.4  2006-10-31 16:16:34  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.3  2006/10/30 19:30:35  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.2  2006/10/29 23:53:49  jaume
50 53
* *** empty log message ***
51 54
*
......
71 74
import javax.swing.JRadioButton;
72 75

  
73 76
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
77
import org.gvsig.gui.beans.swing.JBlank;
74 78
import org.gvsig.gui.beans.swing.JButton;
75 79

  
76 80
import com.iver.andami.PluginServices;
77 81
import com.iver.cit.gvsig.fmap.core.FShape;
78 82
import com.iver.cit.gvsig.fmap.core.symbols.AbstractFillSymbol;
79
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarker;
83
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol;
80 84
import com.iver.cit.gvsig.fmap.core.symbols.MarkerFillSymbol;
81 85
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
82 86
import com.iver.utiles.StringUtilities;
......
87 91
public class MarkerFill extends AbstractTypeSymbolEditorPanel implements ActionListener {
88 92
    private static final String NAME = PluginServices.
89 93
    getText(MarkerFill.class, "marker_fill");
90
	private static final double DEFAULT_SEPARATION = 20;
91
	private static final double DEFAULT_OFFSET = 0;
94
    private static final double DEFAULT_SEPARATION = 20;
95
    private static final double DEFAULT_OFFSET = 10;
92 96
    private ArrayList tabs = new ArrayList();
93 97
    private JDecimalField txtOffsetX;
94 98
    private JDecimalField txtOffsetY;
95 99
    private JDecimalField txtSeparationX;
96 100
    private JDecimalField txtSeparationY;
97
	private ColorChooserPanel markerCC;
98
	private JButton btnChooseMarker;
99
	private JButton btnOutline;
100
	private JRadioButton rdGrid;
101
	private JRadioButton rdRandom;
102
	private MarkerFillSymbol mfs = new MarkerFillSymbol();
103

  
101
    private ColorChooserPanel markerCC;
102
    private JButton btnChooseMarker;
103
    private JButton btnOutline;
104
    private JRadioButton rdGrid;
105
    private JRadioButton rdRandom;
106
    private MarkerFillSymbol mfs = new MarkerFillSymbol();
104 107
    public MarkerFill(SymbolEditor owner) {
105 108
        super(owner);
106 109
        initialize();
107 110
    }
108 111

  
109 112
    private void initialize() {
110
    	//XMLEntity xml = owner.getSymbol().getXMLEntity();
111

  
112 113
        GridLayout layout;
113 114
        JPanel myTab;
114 115
        // Marker fill tab
115 116

  
116 117
        {
117 118

  
118
        	myTab = new GridBagLayoutPanel();
119
        	myTab.setName(PluginServices.getText(this, "marker_fill"));
119
            myTab = new GridBagLayoutPanel();
120
            myTab.setName(PluginServices.getText(this, "marker_fill"));
120 121

  
121
        	GridBagLayoutPanel p = (GridBagLayoutPanel) myTab;
122
        	JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
123
        	markerCC = new ColorChooserPanel();
124
        	markerCC.setAlpha(255);
125
        	markerCC.addActionListener(this);
126
        	aux.add(markerCC);
127 122

  
128
        	p.addComponent(PluginServices.getText(this, "color"), aux);
129
        	btnChooseMarker = new JButton(PluginServices.getText(this, "choose_marker"));
130
        	btnChooseMarker.addActionListener(this);
131
        	aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
132
        	aux.add(btnChooseMarker);
133
        	p.addComponent("", aux);
123
            GridBagLayoutPanel p = (GridBagLayoutPanel) myTab;
124
            JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
125
            markerCC = new ColorChooserPanel();
126
            markerCC.setAlpha(255);
127
            markerCC.addActionListener(this);
128
            aux.add(markerCC);
134 129

  
135
        	aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
136
        	btnOutline = new JButton(PluginServices.getText(this, "outline"));
137
        	aux.add(btnOutline);
138
        	btnOutline.setEnabled(false);
139
        	p.addComponent("", aux);
130
            p.addComponent(PluginServices.getText(this, "color"), aux);
131
            btnChooseMarker = new JButton(PluginServices.getText(this, "choose_marker"));
132
            btnChooseMarker.addActionListener(this);
133
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
134
            aux.add(btnChooseMarker);
135
            p.addComponent("", aux);
140 136

  
141
        	ButtonGroup group = new ButtonGroup();
142
        	rdGrid = new JRadioButton(PluginServices.getText(this, "grid"));
143
        	rdGrid.addActionListener(this);
144
        	rdRandom = new JRadioButton(PluginServices.getText(this, "random"));
145
        	rdRandom.addActionListener(this);
146
        	group.add(rdGrid);
147
        	group.add(rdRandom);
137
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
138
            btnOutline = new JButton(PluginServices.getText(this, "outline"));
139
            aux.add(btnOutline);
140
            btnOutline.setEnabled(false);
141
            p.addComponent("", aux);
148 142

  
143
            ButtonGroup group = new ButtonGroup();
144
            rdGrid = new JRadioButton(PluginServices.getText(this, "grid"));
145
            rdGrid.addActionListener(this);
146
            rdRandom = new JRadioButton(PluginServices.getText(this, "random"));
147
            rdRandom.addActionListener(this);
148
            group.add(rdGrid);
149
            group.add(rdRandom);
149 150

  
150 151

  
151
        	aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
152
        	aux.add(rdGrid);
153
        	aux.add(rdRandom);
154 152

  
155
        	p.addComponent("", aux);
153
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
154
            aux.add(rdGrid);
155
            aux.add(rdRandom);
156

  
157
            p.addComponent("", aux);
158

  
159
            p.addComponent(new JBlank(50,50), new JBlank(50,50));
156 160
        }
157 161
        tabs.add(myTab);
158 162

  
159 163
        // Fill properties tab
160 164
        {
161
        	layout = new GridLayout();
165
            layout = new GridLayout();
162 166
            layout.setColumns(1);
163 167
            layout.setVgap(5);
164 168
            myTab = new JPanel();
......
218 222
            myTab.setLayout(layout);
219 223
        }
220 224
       tabs.add(myTab);
225
//       if (xml != null) {
226
//    	   // restore previous values
227
//    	   txtOffsetX.setText(xml.getStringProperty("xOffset"));
228
//    	   txtOffsetY.setText(xml.getStringProperty("yOffset"));
229
//    	   txtSeparationX.setText(xml.getStringProperty("xSeparation"));
230
//    	   txtSeparationY.setText(xml.getStringProperty("ySeparation"));
231
//    	   rdGrid.setSelected(xml.getBooleanProperty("grid"));
232
//       } else {
233
//    	   // set defaults
234
//
235
//       }
221 236
    }
222 237

  
223 238
    public void refreshControls(int layerIndex) {
224 239

  
225 240

  
226
    	AbstractFillSymbol sym = (AbstractFillSymbol) owner.getSymbol();
227
    	if (layerIndex > sym.getLayers().length)
228
    		return;
229
    	XMLEntity xml = sym.getLayers()[layerIndex].getXMLEntity();
230
    	Color c = null;
231
    	if (xml.contains("color")) {
232
    		c = StringUtilities.string2Color(xml.getStringProperty("color"));
233
    	} else {
234
    		c = Color.BLACK;
235
    	}
236
    	markerCC.setColor(c);
241
        AbstractFillSymbol sym = (AbstractFillSymbol) owner.getSymbol();
242
        if (sym.getLayer(layerIndex) == null) {
243
        	// set defaults
244
           	markerCC.setColor(Color.BLACK);
245
           	rdGrid.setSelected(true);
246
    		rdRandom.setSelected(false);
247
    		txtOffsetX.setText(String.valueOf(DEFAULT_OFFSET));
248
    		txtOffsetY.setText(String.valueOf(DEFAULT_OFFSET));
249
    		txtSeparationX.setText(String.valueOf(DEFAULT_SEPARATION));
250
    		txtSeparationY.setText(String.valueOf(DEFAULT_SEPARATION));
251
        } else {
252
        	XMLEntity xml = sym.getLayer(layerIndex).getXMLEntity();
253
        	markerCC.setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
254
        	boolean b = xml.getBooleanProperty("grid");
255
        	rdGrid.setSelected(b);
256
        	rdRandom.setSelected(!b);
237 257

  
238
    	if (xml.contains("grid")) {
239
    		boolean b = xml.getBooleanProperty("grid");
240
    		rdGrid.setSelected(b);
241
    		rdRandom.setSelected(!b);
242
    	} else {
243
    		System.err.println("en un funcionament normal, per ac? no deuria de passar");
244
    	}
258
        	txtOffsetX.setText(String.valueOf(xml.getDoubleProperty("xOffset")));
259
        	txtOffsetY.setText(String.valueOf(xml.getDoubleProperty("yOffset")));
245 260

  
246
    	if (xml.contains("xOffset")) {
247
    		mfs.setXOffset(xml.getDoubleProperty("xOffset"));
248
    	} else {
249
    		mfs.setYOffset(DEFAULT_OFFSET);
250
    	}
251

  
252
    	if (xml.contains("yOffset")) {
253
    		mfs.setYOffset(xml.getDoubleProperty("yOffset"));
254
    	} else {
255
    		mfs.setXOffset(DEFAULT_OFFSET);
256
    	}
257

  
258
    	if (xml.contains("xSeparation")) {
259
    		mfs.setXSeparation(xml.getDoubleProperty("xSeparation"));
260
    	} else {
261
    		mfs.setXSeparation(DEFAULT_SEPARATION);
262
    	}
263

  
264
    	if (xml.contains("ySeparation")) {
265
    		mfs.setYSeparation(xml.getDoubleProperty("ySeparation"));
266
    	} else {
267
    		mfs.setYSeparation(DEFAULT_SEPARATION);
268
    	}
261
        	txtSeparationX.setText(String.valueOf(xml.getDoubleProperty("xSeparation")));
262
        	txtSeparationY.setText(String.valueOf(xml.getDoubleProperty("ySeparation")));
263
        }
269 264
    }
270 265

  
271 266
    public XMLEntity getXMLEntity() {
272
        XMLEntity xml = new XMLEntity();
273
        xml.putProperty("xOffset", txtOffsetX.getText());
274
        xml.putProperty("yOffset", txtOffsetY.getText());
275
        xml.putProperty("xSeparation", txtSeparationX.getText());
276
        xml.putProperty("ySeparation", txtSeparationY.getText());
277
        xml.putProperty("isGrid", rdGrid.isSelected());
278
        xml.putProperty("color", StringUtilities.color2String(markerCC.getColor()));
279
        return xml;
267
        return mfs.getXMLEntity();
280 268
    }
281 269

  
282 270
    public String getName() {
......
287 275
        return (JPanel[]) tabs.toArray(new JPanel[0]);
288 276
    }
289 277

  
290
	public void actionPerformed(ActionEvent e) {
291
		JComponent comp = (JComponent) e.getSource();
292
		if (comp.equals(btnChooseMarker)) {
293
			AbstractFillSymbol ownersSymbol = (AbstractFillSymbol) owner.getSymbol();
278
    public void actionPerformed(ActionEvent e) {
279
        JComponent comp = (JComponent) e.getSource();
280
        if (comp.equals(btnChooseMarker)) {
281
            AbstractFillSymbol ownersSymbol = (AbstractFillSymbol) owner.getSymbol();
294 282

  
295 283

  
296
			SymbolSelector symSelect = new SymbolSelector(
297
					ownersSymbol.getLayers().length >0 ? ownersSymbol.getLayers()[0] : null
298
					                         , FShape.POINT);
299
			PluginServices.getMDIManager().addWindow(symSelect);
300
			AbstractMarker marker = (AbstractMarker) symSelect.getSymbol();
301
			/*XMLEntity xml = owner.getSymbol().getXMLEntity();
302
			xml.removeAllChildren();
303
			xml.addChild(marker.getXMLEntity());
304
			owner.getSymbol().setXMLEntity(xml);*/
305
			mfs.setMarker(marker);
306
		}
307
		try {
308
			mfs.setXOffset(Double.parseDouble(txtOffsetX.getText()));
309
			mfs.setYOffset(Double.parseDouble(txtOffsetY.getText()));
310
			mfs.setXSeparation(Double.parseDouble(txtSeparationX.getText()));
311
			mfs.setYSeparation(Double.parseDouble(txtSeparationX.getText()));
312
			mfs.setGrid(rdGrid.isSelected());
313
		} catch (Exception ex) {}
314
		//mfs.setRotation() TODO
315
		fireSymbolChangedEvent();
316
	}
284
            SymbolSelector symSelect = new SymbolSelector( ownersSymbol.getLayer(layerIndex), FShape.POINT);
285
            PluginServices.getMDIManager().addWindow(symSelect);
286
            AbstractMarkerSymbol marker = (AbstractMarkerSymbol) symSelect.getSymbol();
287
            /*XMLEntity xml = owner.getSymbol().getXMLEntity();
288
            xml.removeAllChildren();
289
            xml.addChild(marker.getXMLEntity());
290
            owner.getSymbol().setXMLEntity(xml);*/
291
            mfs.setMarker(marker);
292
        }
293
        try {
294
            mfs.setXOffset(Double.parseDouble(txtOffsetX.getText()));
295
        } catch (Exception ex) {}
296
        try {
297
            mfs.setYOffset(Double.parseDouble(txtOffsetY.getText()));
298
        } catch (Exception ex) {}
299
        try {
300
            mfs.setXSeparation(Double.parseDouble(txtSeparationX.getText()));
301
        } catch (Exception ex) {}
302
        try {
303
            mfs.setYSeparation(Double.parseDouble(txtSeparationY.getText()));
304
        } catch (Exception ex) {}
305
        try {
306
            mfs.setGrid(rdGrid.isSelected());
307
        } catch (Exception ex) {}
317 308

  
309
        fireSymbolChangedEvent();
310
    }
311

  
318 312
}

Also available in: Unified diff