Revision 47476 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.api/src/main/java/org/gvsig/app/gui/styling/SymbolSelector.java
SymbolSelector.java | ||
---|---|---|
38 | 38 |
import java.awt.event.MouseListener; |
39 | 39 |
import java.awt.event.MouseMotionListener; |
40 | 40 |
import java.io.File; |
41 |
|
|
42 | 41 |
import javax.swing.BorderFactory; |
43 | 42 |
import javax.swing.BoxLayout; |
44 | 43 |
import javax.swing.JComponent; |
... | ... | |
58 | 57 |
import javax.swing.tree.DefaultMutableTreeNode; |
59 | 58 |
import org.apache.commons.lang3.StringUtils; |
60 | 59 |
import org.apache.commons.lang3.mutable.MutableObject; |
61 |
|
|
62 |
import org.slf4j.Logger; |
|
63 |
import org.slf4j.LoggerFactory; |
|
64 | 60 |
import org.gvsig.andami.PluginServices; |
65 | 61 |
import org.gvsig.andami.messages.NotificationManager; |
66 | 62 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
... | ... | |
71 | 67 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
72 | 68 |
import org.gvsig.fmap.geom.Geometry; |
73 | 69 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
74 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
75 | 70 |
import org.gvsig.fmap.geom.GeometryLocator; |
76 | 71 |
import org.gvsig.fmap.geom.GeometryManager; |
77 | 72 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
... | ... | |
101 | 96 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
102 | 97 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMultiLayerMarkerSymbol; |
103 | 98 |
import org.gvsig.tools.dispose.Disposable; |
99 |
import org.slf4j.Logger; |
|
100 |
import org.slf4j.LoggerFactory; |
|
104 | 101 |
|
105 | 102 |
|
106 | 103 |
/** |
... | ... | |
109 | 106 |
* of all the symbols stored and posibilities to modify an existing one, to create |
110 | 107 |
* a new symbol and so on. |
111 | 108 |
* |
112 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
|
109 |
* @author gvSIG Team
|
|
113 | 110 |
*/ |
114 | 111 |
public class SymbolSelector extends JPanel implements ISymbolSelector, ActionListener { |
115 | 112 |
private static final long serialVersionUID = -6405660392303659551L; |
... | ... | |
271 | 268 |
try { |
272 | 269 |
GeometryType geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D); |
273 | 270 |
initialize(symbol,geometryType, initialize); |
274 |
} catch (GeometryTypeNotSupportedException e1) {
|
|
271 |
} catch (Exception e1) { |
|
275 | 272 |
logger.error("Impossible to get the geometry type", e1); |
276 |
} catch (GeometryTypeNotValidException e1) { |
|
277 |
logger.error("Impossible to get the geometry type", e1); |
|
278 | 273 |
} |
279 | 274 |
sFilter = filter; |
280 | 275 |
} |
... | ... | |
294 | 289 |
this.add(getJNorthPanel(), BorderLayout.NORTH); |
295 | 290 |
this.add(getJSplitPane(), BorderLayout.CENTER); |
296 | 291 |
this.add(getJEastPanel(), BorderLayout.EAST); |
297 |
ActionListener okAction = new ActionListener() { |
|
298 |
public void actionPerformed(ActionEvent e) { |
|
299 |
if(SymbolSelector.this.listModel != null){ |
|
300 |
SymbolSelector.this.listModel.dispose(); |
|
301 |
} |
|
302 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
|
303 |
|
|
304 |
} |
|
305 |
}, cancelAction = new ActionListener() { |
|
306 |
public void actionPerformed(ActionEvent e) { |
|
307 |
accepted = false; |
|
308 |
setSymbol(null); |
|
309 |
if(SymbolSelector.this.listModel != null){ |
|
310 |
SymbolSelector.this.listModel.dispose(); |
|
311 |
} |
|
312 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
|
313 |
} |
|
314 |
}; |
|
292 |
ActionListener okAction = (ActionEvent e) -> { |
|
293 |
if(SymbolSelector.this.listModel != null){ |
|
294 |
SymbolSelector.this.listModel.dispose(); |
|
295 |
} |
|
296 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
|
297 |
}, cancelAction = (ActionEvent e) -> { |
|
298 |
accepted = false; |
|
299 |
setSymbol(null); |
|
300 |
if(SymbolSelector.this.listModel != null){ |
|
301 |
SymbolSelector.this.listModel.dispose(); |
|
302 |
} |
|
303 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
|
304 |
}; |
|
315 | 305 |
|
316 | 306 |
okCancelPanel = new AcceptCancelPanel(); |
317 | 307 |
okCancelPanel.setOkButtonActionListener(okAction); |
... | ... | |
380 | 370 |
jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
381 | 371 |
jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP); |
382 | 372 |
jListSymbols.setVisibleRowCount(-1); |
383 |
jListSymbols.addListSelectionListener(new ListSelectionListener() { |
|
384 |
public void valueChanged(ListSelectionEvent e) { |
|
385 |
if (jListSymbols.getSelectedValue()!=null) { |
|
386 |
ISymbol selSym=null; |
|
387 |
try { |
|
388 |
selSym = (ISymbol) ((ISymbol) jListSymbols |
|
389 |
.getSelectedValue()).clone(); |
|
390 |
} catch (CloneNotSupportedException ex) { |
|
391 |
NotificationManager.addWarning("Symbol layer", ex); |
|
392 |
} |
|
393 |
setSymbol(selSym); |
|
394 |
updateOptionsPanel(); |
|
395 |
} |
|
396 |
} |
|
397 |
}); |
|
373 |
jListSymbols.addListSelectionListener((ListSelectionEvent e) -> { |
|
374 |
if (jListSymbols.getSelectedValue()!=null) { |
|
375 |
ISymbol selSym=null; |
|
376 |
try { |
|
377 |
selSym = (ISymbol) ((ISymbol) jListSymbols |
|
378 |
.getSelectedValue()).clone(); |
|
379 |
} catch (CloneNotSupportedException ex) { |
|
380 |
NotificationManager.addWarning("Symbol layer", ex); |
|
381 |
} |
|
382 |
setSymbol(selSym); |
|
383 |
updateOptionsPanel(); |
|
384 |
} |
|
385 |
}); |
|
398 | 386 |
ListCellRenderer renderer = new ListCellRenderer() { |
399 |
private Color mySelectedBGColor = new Color(255,145,100,255); |
|
387 |
private final Color mySelectedBGColor = new Color(255,145,100,255); |
|
388 |
@Override |
|
400 | 389 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
401 | 390 |
ISymbol sym = (ISymbol) value; |
402 | 391 |
JPanel pnl = new JPanel(); |
... | ... | |
436 | 425 |
*/ |
437 | 426 |
protected void updateOptionsPanel() throws IllegalArgumentException { |
438 | 427 |
Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol(); |
439 |
|
|
440 |
// if (mySelectedElement == null) { |
|
441 |
// return; |
|
442 |
// } |
|
443 | 428 |
act = false; // disable events |
444 | 429 |
|
445 | 430 |
if (mySelectedElement instanceof CartographicSupport) { |
... | ... | |
502 | 487 |
ILineSymbol outline = f.getOutline(); |
503 | 488 |
if (outline != null) { |
504 | 489 |
jcc2.setColor(outline.getColor()); |
490 |
jcc2.setAlpha(outline.getAlpha()); |
|
505 | 491 |
txtWidth.setDouble(outline.getLineWidth()); |
506 | 492 |
} |
507 | 493 |
|
... | ... | |
513 | 499 |
} |
514 | 500 |
} |
515 | 501 |
|
516 |
} catch (NullPointerException npEx) {
|
|
502 |
} catch (Exception npEx) { |
|
517 | 503 |
throw new IllegalArgumentException(npEx); |
518 |
} catch (ClassCastException ccEx) { |
|
519 |
throw new IllegalArgumentException(ccEx); |
|
520 | 504 |
} |
521 | 505 |
|
522 | 506 |
act = true; // enable events |
... | ... | |
615 | 599 |
jScrollPane.setPreferredSize(new java.awt.Dimension(80,130)); |
616 | 600 |
jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
617 | 601 |
libraryBrowser = new LibraryBrowser(library); |
618 |
libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() { |
|
619 |
public void valueChanged(javax.swing.event.TreeSelectionEvent e) { |
|
620 |
|
|
621 |
if (libraryBrowser.getLastSelectedPathComponent() == null) { |
|
622 |
/* |
|
623 |
* This happens when clicking on [+] to expand |
|
624 |
* or [-] to collapse a tree node. |
|
625 |
*/ |
|
626 |
return; |
|
627 |
} |
|
628 |
|
|
629 |
dir = (File) ((DefaultMutableTreeNode) |
|
630 |
libraryBrowser.getLastSelectedPathComponent()).getUserObject(); |
|
631 |
|
|
632 |
if (dir == null) { |
|
633 |
return; |
|
634 |
} |
|
635 |
ListModel model = jListSymbols.getModel(); |
|
636 |
if( model != null && model instanceof Disposable ) { |
|
637 |
((Disposable)model).dispose(); |
|
638 |
} |
|
639 |
jListSymbols.setModel(newListModel()); |
|
640 |
} |
|
641 |
}); |
|
602 |
libraryBrowser.addTreeSelectionListener((javax.swing.event.TreeSelectionEvent e) -> { |
|
603 |
if (libraryBrowser.getLastSelectedPathComponent() == null) { |
|
604 |
/* |
|
605 |
* This happens when clicking on [+] to expand |
|
606 |
* or [-] to collapse a tree node. |
|
607 |
*/ |
|
608 |
return; |
|
609 |
} |
|
610 |
|
|
611 |
dir = (File) ((DefaultMutableTreeNode) |
|
612 |
libraryBrowser.getLastSelectedPathComponent()).getUserObject(); |
|
613 |
|
|
614 |
if (dir == null) { |
|
615 |
return; |
|
616 |
} |
|
617 |
ListModel model = jListSymbols.getModel(); |
|
618 |
if( model != null && model instanceof Disposable ) { |
|
619 |
((Disposable)model).dispose(); |
|
620 |
} |
|
621 |
jListSymbols.setModel(newListModel()); |
|
622 |
}); |
|
642 | 623 |
jScrollPane.setViewportView(libraryBrowser); |
643 | 624 |
} |
644 | 625 |
return jScrollPane; |
... | ... | |
685 | 666 |
jcc1 = new ColorChooserPanel(true); |
686 | 667 |
|
687 | 668 |
jPanelOptions.addComponent( |
688 |
Messages.getText("color")+":", jcc1);
|
|
669 |
Messages.getText("Color")+":", jcc1);
|
|
689 | 670 |
jPanelOptions.addComponent( |
690 | 671 |
Messages.getText("size")+":", |
691 | 672 |
txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2)); |
... | ... | |
701 | 682 |
} else if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
702 | 683 |
jcc1 = new ColorChooserPanel(true); |
703 | 684 |
jPanelOptions.addComponent( |
704 |
Messages.getText("color")+":", jcc1);
|
|
685 |
Messages.getText("Color")+":", jcc1);
|
|
705 | 686 |
jPanelOptions.addComponent( |
706 | 687 |
Messages.getText("width")+":", |
707 | 688 |
txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2)); |
... | ... | |
788 | 769 |
return cmbFonts; |
789 | 770 |
} |
790 | 771 |
|
772 |
@Override |
|
791 | 773 |
public WindowInfo getWindowInfo() { |
792 | 774 |
if (wi == null) { |
793 | 775 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
... | ... | |
809 | 791 |
return jSplitPane; |
810 | 792 |
} |
811 | 793 |
|
794 |
@Override |
|
812 | 795 |
public Object getSelectedObject() { |
813 | 796 |
if (!accepted) { |
814 | 797 |
return null; |
... | ... | |
831 | 814 |
return mySelectedElement; |
832 | 815 |
} |
833 | 816 |
|
817 |
@Override |
|
834 | 818 |
public void setSymbol(Object symbol) { |
835 | 819 |
((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol); |
836 | 820 |
updateOptionsPanel(); |
... | ... | |
909 | 893 |
|
910 | 894 |
JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir); |
911 | 895 |
javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() { |
896 |
@Override |
|
912 | 897 |
public boolean accept(File f) { |
913 | 898 |
return f.getAbsolutePath().toLowerCase().endsWith( |
914 | 899 |
preferences.getSymbolFileExtension()) |
915 | 900 |
|| f.isDirectory(); |
916 | 901 |
} |
917 | 902 |
|
903 |
@Override |
|
918 | 904 |
public String getDescription() { |
919 | 905 |
return Messages.getText( |
920 | 906 |
"gvSIG_symbol_definition_file") |
... | ... | |
968 | 954 |
} |
969 | 955 |
|
970 | 956 |
|
957 |
@Override |
|
971 | 958 |
public void actionPerformed(ActionEvent e) { |
972 | 959 |
if (!act) { |
973 | 960 |
return; |
... | ... | |
1117 | 1104 |
} |
1118 | 1105 |
|
1119 | 1106 |
public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) { |
1120 |
ISymbolSelector selector = null;
|
|
1107 |
ISymbolSelector selector; |
|
1121 | 1108 |
|
1122 | 1109 |
GeometryType geometryType = null; |
1123 | 1110 |
try { |
1124 | 1111 |
geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D); |
1125 |
} catch (GeometryTypeNotSupportedException e) {
|
|
1112 |
} catch (Exception e) { |
|
1126 | 1113 |
logger.error("Impossible to get the geometry type", e); |
1127 |
} catch (GeometryTypeNotValidException e) { |
|
1128 |
logger.error("Impossible to get the geometry type", e); |
|
1129 | 1114 |
} |
1130 | 1115 |
|
1131 | 1116 |
if (filter==null) { |
... | ... | |
1145 | 1130 |
private Object selected; |
1146 | 1131 |
private File sourceFolder; |
1147 | 1132 |
|
1133 |
@Override |
|
1148 | 1134 |
public void mouseClicked(MouseEvent e) { } |
1135 |
|
|
1136 |
@Override |
|
1149 | 1137 |
public void mouseEntered(MouseEvent e) { } |
1138 |
|
|
1139 |
@Override |
|
1150 | 1140 |
public void mouseExited(MouseEvent e) { } |
1151 |
|
|
1141 |
|
|
1142 |
@Override |
|
1152 | 1143 |
public void mousePressed(MouseEvent e) { |
1153 | 1144 |
if (e.getSource().equals(getJListSymbols())) { |
1154 | 1145 |
selected = getJListSymbols().getSelectedValue(); |
... | ... | |
1161 | 1152 |
e.consume(); |
1162 | 1153 |
} |
1163 | 1154 |
|
1155 |
@Override |
|
1164 | 1156 |
public void mouseReleased(MouseEvent e) { |
1165 | 1157 |
if (doDrop && e.getSource().equals(getJListSymbols())) { |
1166 | 1158 |
Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y); |
... | ... | |
1184 | 1176 |
doDrop = false; |
1185 | 1177 |
} |
1186 | 1178 |
|
1179 |
@Override |
|
1187 | 1180 |
public void mouseDragged(MouseEvent e) { |
1188 | 1181 |
if (e.getSource().equals(getJListSymbols())) { |
1189 | 1182 |
|
... | ... | |
1194 | 1187 |
} |
1195 | 1188 |
} |
1196 | 1189 |
|
1190 |
@Override |
|
1197 | 1191 |
public void mouseMoved(MouseEvent e) { |
1198 | 1192 |
|
1199 | 1193 |
} |
1200 | 1194 |
|
1201 | 1195 |
} |
1202 | 1196 |
|
1197 |
@Override |
|
1203 | 1198 |
public Object getWindowProfile() { |
1204 | 1199 |
return WindowInfo.DIALOG_PROFILE; |
1205 | 1200 |
} |
Also available in: Unified diff