Revision 8432 trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/SymbolSelector.java

View differences:

SymbolSelector.java
55 55
import java.io.File;
56 56
import java.io.FileFilter;
57 57
import java.io.FileWriter;
58
import java.io.IOException;
59 58

  
60 59
import javax.swing.BorderFactory;
61 60
import javax.swing.BoxLayout;
61
import javax.swing.JComponent;
62 62
import javax.swing.JFileChooser;
63 63
import javax.swing.JLabel;
64 64
import javax.swing.JList;
......
74 74
import javax.swing.tree.TreeModel;
75 75
import javax.swing.tree.TreePath;
76 76

  
77
import org.exolab.castor.xml.MarshalException;
78 77
import org.exolab.castor.xml.Marshaller;
79
import org.exolab.castor.xml.ValidationException;
80 78
import org.gvsig.gui.beans.AcceptCancelPanel;
81 79
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
82 80
import org.gvsig.gui.beans.swing.JButton;
......
88 86
import com.iver.cit.gvsig.fmap.core.FShape;
89 87
import com.iver.cit.gvsig.fmap.core.ISymbol;
90 88
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
89
import com.iver.utiles.StringUtilities;
91 90
import com.iver.utiles.XMLEntity;
92
import com.iver.utiles.xmlEntity.generate.XmlTag;
93 91

  
94 92
import de.ios.framework.swing.JDecimalField;
95 93
import de.ios.framework.swing.JNumberField;
......
113 111
	private ISymbol selectedSymbol = null;
114 112
	private JPanel northPanel;
115 113
	private ColorChooserPanel jcc1;
114
	private ColorChooserPanel jcc2;
116 115
	private JNumberField txtSize;
117 116
	private JDecimalField txtAngle;
118 117
	private JPanel jPanelButtons;
119 118
	private JButton btnProperties;
120 119
	private int shapeType;
121
	private ColorChooserPanel jcc2;
122 120
	private JButton btnSaveSymbol;
123 121
	private JButton btnResetSymbol;
124 122
	private ActionListener buttonListener = new MyButtonListener();
......
126 124
     * This method initializes
127 125
     *
128 126
     */
129
    public SymbolSelector(int shapeType) {
127
    public SymbolSelector(ISymbol symbol, int shapeType) {
130 128
    	super();
129
    	this.selectedSymbol = symbol;
131 130
    	this.shapeType = shapeType;
132 131
    	symbolDir = new File(getClass().
133 132
  				getClassLoader().
......
295 294
            jListSymbols.addListSelectionListener(new ListSelectionListener() {
296 295
            	public void valueChanged(ListSelectionEvent e) {
297 296
            		setSymbol((ISymbol) jListSymbols.getSelectedValue());
297
            		updateOptionsPanel();
298 298
            	}
299 299
            });
300 300
            ListCellRenderer renderer = new ListCellRenderer() {
......
328 328
    	return jListSymbols;
329 329
    }
330 330

  
331
    /**
331
    protected void updateOptionsPanel() {
332
    	ISymbol sym = ((ISymbol) jListSymbols.getSelectedValue());
333
    	if (sym == null)
334
    		return;
335

  
336
		XMLEntity xml = sym.getXMLEntity();
337

  
338
		Color c = null;
339
    	if (xml.contains("color")) {
340
    		c = StringUtilities.string2Color(xml.getStringProperty("color"));
341
    	}
342
		jcc1.setColor(c);
343

  
344
		if (jcc2 == null)
345
			return;
346
		if (xml.contains("outline")) {
347
    		c = StringUtilities.string2Color(xml.getStringProperty("outline"));
348
    		jcc2.setEnabled(true);
349
    		jcc2.setColor(c);
350
    	} else {
351
    		jcc2.setEnabled(false);
352
    	}
353

  
354

  
355
	}
356

  
357
	/**
332 358
     * This method initializes jPanel
333 359
     *
334 360
     * @return javax.swing.JPanel
......
434 460
     *
435 461
     * @return javax.swing.JPanel
436 462
     */
437
    private JPanel getJPanelPreview() {
463
    private SymbolPreview getJPanelPreview() {
438 464
    	if (jPanelPreview == null) {
439 465
    		jPanelPreview = new SymbolPreview();
440 466
    		jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
......
451 477
    private JPanel getJPanelOptions() {
452 478
    	if (jPanelOptions == null) {
453 479
    		jPanelOptions = new GridBagLayoutPanel();
480

  
481
    		jcc1 = new ColorChooserPanel();
482
    		jcc2 = new ColorChooserPanel();
483
    		jcc1.setAlpha(255);
484
    		jcc2.setAlpha(255);
485
    		jcc1.addActionListener(buttonListener);
486
    		jcc2.addActionListener(buttonListener);
454 487
    		if (shapeType == FShape.POINT) {
455
    			jcc1 = new ColorChooserPanel();
456 488
    			jPanelOptions.addComponent(
457 489
    					PluginServices.getText(this, "color")+":", jcc1);
458 490
    			jPanelOptions.addComponent(
......
462 494
    					PluginServices.getText(this, "angle")+":",
463 495
    					txtAngle = new JDecimalField());
464 496
    		} else if (shapeType == FShape.LINE) {
465
    			jcc1 = new ColorChooserPanel();
466 497
    			jPanelOptions.addComponent(
467 498
    					PluginServices.getText(this, "color")+":", jcc1);
468 499
    			jPanelOptions.addComponent(
......
470 501
    					txtSize = new JNumberField());
471 502
    			jPanelOptions.addComponent(new JLabel("AQUI VA EL COMBO DE PATTERN DE LINEA"));
472 503
    		} else if (shapeType == FShape.POLYGON) {
473
    			jcc1 = new ColorChooserPanel();
474 504
    			jPanelOptions.addComponent(
475 505
    					PluginServices.getText(this, "fill_color")+":", jcc1);
476
    			jcc2 = new ColorChooserPanel();
477 506
    			jPanelOptions.addComponent(
478 507
    					PluginServices.getText(this, "outline_color")+":", jcc2);
479 508
    			jPanelOptions.addComponent(
......
486 515
	public WindowInfo getWindowInfo() {
487 516
		if (wi == null) {
488 517
			wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
489
			wi.setWidth(750);
518
			wi.setWidth(706);
490 519
			wi.setHeight(500);
491 520
			wi.setTitle(PluginServices.getText(this, "symbol_selector"));
492 521
		}
......
502 531
		if (jSplitPane == null) {
503 532
			jSplitPane = new JSplitPane();
504 533
			jSplitPane.setDividerLocation(200);
534
			jSplitPane.setResizeWeight(0.4);
505 535
	        jSplitPane.setLeftComponent(getJScrollPane());
506 536
	        jSplitPane.setRightComponent(getJScrollPane1());
507 537
		}
......
527 557
			if (selectedSymbol ==null)
528 558
				return;
529 559

  
530
			JButton btn = (JButton) e.getSource();
531
			if ( btn.equals(getBtnProperties()) ) {
560
			JComponent comp = (JComponent) e.getSource();
561
			XMLEntity xml = null;
562
			if (selectedSymbol != null)
563
				xml = selectedSymbol.getXMLEntity();
564

  
565

  
566
			if ( comp.equals(getBtnProperties()) ) {
532 567
				// properties pressed
533 568
				SymbolEditor se = new SymbolEditor(selectedSymbol, shapeType);
534 569
				PluginServices.getMDIManager().addWindow(se);
535 570
				setSymbol(se.getSymbol());
536
			} else if ( btn.equals(getBtnResetSymbol()) ) {
571
			} else if ( comp.equals(getBtnResetSymbol()) ) {
537 572
				// reset pressed
538 573
				setSymbol(null);
539
			} else if ( btn.equals(getBtnSaveSymbol()) ) {
574
			} else if ( comp.equals(getBtnSaveSymbol()) ) {
540 575
				// save pressed
541
					JFileChooser jfc = new JFileChooser(SymbolSelectorListModel.SYMBOL_DIRECTORY);
542
					javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
543
						public boolean accept(File f) {
544
							return f.getAbsolutePath().
545
								toLowerCase().
546
								endsWith(SymbolSelectorListModel.
547
										SYMBOL_FILE_EXTENSION);
548
						}
576
				JFileChooser jfc = new JFileChooser(SymbolSelectorListModel.SYMBOL_DIRECTORY);
577
				javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
578
					public boolean accept(File f) {
579
						return f.getAbsolutePath().
580
						toLowerCase().
581
						endsWith(SymbolSelectorListModel.
582
								SYMBOL_FILE_EXTENSION);
583
					}
549 584

  
550
						public String getDescription() {
551
							return PluginServices.getText(
585
					public String getDescription() {
586
						return PluginServices.getText(
552 587
								this, "gvSIG_symbol_definition_file")+ " (*.sym)";
553
						}
554
					};
555
					jfc.setFileFilter(ff);
556
					if (jfc.showSaveDialog(SymbolSelector.this) == JFileChooser.APPROVE_OPTION) {
557
						File targetFile = jfc.getSelectedFile();
558
						String fExtension = SymbolSelectorListModel.SYMBOL_FILE_EXTENSION;
559
						if (!targetFile.
560
								getAbsolutePath().
561
								toLowerCase().
562
								endsWith(fExtension))
563
							targetFile = new File(targetFile.getAbsolutePath() + fExtension);
564
						XMLEntity xml = selectedSymbol.getXMLEntity();
565
						FileWriter writer;
566
						try {
567
							writer = new FileWriter(targetFile.getAbsolutePath());
568
							Marshaller m = new Marshaller(writer);
569
							m.setEncoding("ISO-8859-1");
570
							m.marshal(xml.getXmlTag());
588
					}
589
				};
590
				jfc.setFileFilter(ff);
591
				if (jfc.showSaveDialog(SymbolSelector.this) == JFileChooser.APPROVE_OPTION) {
592
					File targetFile = jfc.getSelectedFile();
593
					String fExtension = SymbolSelectorListModel.SYMBOL_FILE_EXTENSION;
594
					if (!targetFile.
595
							getAbsolutePath().
596
							toLowerCase().
597
							endsWith(fExtension))
598
						targetFile = new File(targetFile.getAbsolutePath() + fExtension);
599
					FileWriter writer;
600
					try {
601
						writer = new FileWriter(targetFile.getAbsolutePath());
602
						Marshaller m = new Marshaller(writer);
603
						m.setEncoding("ISO-8859-1");
604
						m.marshal(xml.getXmlTag());
571 605

  
572
						} catch (Exception ex) {
573
							NotificationManager.addError(
606
					} catch (Exception ex) {
607
						NotificationManager.addError(
574 608
								PluginServices.getText(this, "save_error"), ex);
575
						}
576

  
609
					}
577 610
				}
611
			} else if (comp.equals(jcc1) && xml != null) {
612
				xml.putProperty("color", StringUtilities.color2String(jcc1.getColor()));
613
			} else if (comp.equals(jcc2) && xml != null) {
614
				xml.putProperty("outline", StringUtilities.color2String(jcc2.getColor()));
578 615
			}
616

  
617
			if (selectedSymbol != null) {
618
				selectedSymbol.setXMLEntity(xml);
619
			}
620

  
621
			SymbolSelector.this.repaint();
579 622
		}
580 623
	}
581 624
}  //  @jve:decl-index=0:visual-constraint="10,10"

Also available in: Unified diff