Hi,

the attached patch are a first version of my selectionstyle enhancement. You can change the selectionstyle with a new tab in the optionsdialog. The stylings are stored in the persistent Blackboard -> workbench-state.xml.

Please take a look at my code and tell me your opinion. It would be nice if you can integrate the code into the project.

Can anybody tell me how i can do a "repaint" after the OK button was pressed(SelectionStyllingOptionsPanel.okPressed()). In the actual version you must move or zoom the map that you see the new styling setting. It would be better if you see the changes immediately.

Matthias

# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /data/home/mscholz/netbeans/openjump_svn
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: src/com/vividsolutions/jump/jump.properties
--- src/com/vividsolutions/jump/jump.properties Base (BASE)
+++ src/com/vividsolutions/jump/jump.properties Locally Modified (Based On LOCAL)
@@ -535,6 +535,7 @@
 
 ui.plugin.OptionsPlugIn.view-edit=View / Edit
 ui.plugin.OptionsPlugIn.snap-vertices-tools=Snap Vertices Tools
+ui.plugin.OptionsPlugIn.selection-style=Selection Style
 ui.plugin.RemoveSelectedCategoriesPlugIn.at-least-1-category-must-be-left-unselected=At least 1 category must be left unselected
 ui.plugin.SaveDatasetAsPlugIn.save-dataset=Save Dataset
 ui.plugin.SaveDatasetAsPlugIn.save-dataset-as-old=Save Dataset As (old)
@@ -1742,3 +1743,8 @@
 pirol.ui.panels.type-of-new-attribute=type of new attribute
 pirol.ui.panels.name-of-new-attribute=name of new attribute
 pirol.ui.panels.default-value-for-new-attribute=default value for new attribute
+
+# SelectionStyllingOptionsPanel - 18. Jun. 2010
+ui.SelectionStyllingOptionsPanel.LineColor = Linecolor:
+ui.SelectionStyllingOptionsPanel.PointStyle = Pointstyle:
+ui.SelectionStyllingOptionsPanel.PointSize = Pointsize:
\ No newline at end of file
Index: src/com/vividsolutions/jump/workbench/ui/plugin/OptionsPlugIn.java
--- src/com/vividsolutions/jump/workbench/ui/plugin/OptionsPlugIn.java Base (BASE)
+++ src/com/vividsolutions/jump/workbench/ui/plugin/OptionsPlugIn.java Locally Modified (Based On LOCAL)
@@ -44,6 +44,7 @@
 import com.vividsolutions.jump.workbench.ui.SnapVerticesToolsOptionsPanel;
 import com.vividsolutions.jump.workbench.ui.snap.GridRenderer;
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
+import org.openjump.core.ui.SelectionStyllingOptionsPanel;
 
 public class OptionsPlugIn extends AbstractPlugIn {
 
@@ -82,6 +83,9 @@
                         new SnapVerticesToolsOptionsPanel(context
                                 .getWorkbenchContext().getWorkbench()
                                 .getBlackboard()))        ;
+        dialog(context)
+                .addTab(I18N.get("ui.plugin.OptionsPlugIn.selection-style"),
+						new SelectionStyllingOptionsPanel(PersistentBlackboardPlugIn.get(context.getWorkbenchContext())));
     }
 
 }
Index: src/com/vividsolutions/jump/workbench/ui/renderer/AbstractSelectionRenderer.java
--- src/com/vividsolutions/jump/workbench/ui/renderer/AbstractSelectionRenderer.java Base (BASE)
+++ src/com/vividsolutions/jump/workbench/ui/renderer/AbstractSelectionRenderer.java Locally Modified (Based On LOCAL)
@@ -49,13 +49,19 @@
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.util.Assert;
 import com.vividsolutions.jump.feature.Feature;
+import com.vividsolutions.jump.util.Blackboard;
 import com.vividsolutions.jump.util.CollectionMap;
 import com.vividsolutions.jump.workbench.model.Layer;
 import com.vividsolutions.jump.workbench.ui.GUIUtil;
 import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
 import com.vividsolutions.jump.workbench.ui.Viewport;
+import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
+import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
 import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
 import com.vividsolutions.jump.workbench.ui.renderer.style.StyleUtil;
+import com.vividsolutions.jump.workbench.ui.renderer.style.VertexStyle;
+import de.latlon.deejump.plugin.style.VertexStylesFactory;
+import org.openjump.core.ui.SelectionStyllingOptionsPanel;
 
 public abstract class AbstractSelectionRenderer extends FeatureCollectionRenderer implements Style {
     public final static int HANDLE_WIDTH = 5;
@@ -121,6 +127,9 @@
         throws NoninvertibleTransformException {
     	if (!viewport.getEnvelopeInModelCoordinates().intersects(geometry.getEnvelopeInternal()))
     		return;
+		// get the persistent Blackboard
+		Blackboard blackboard = ((WorkbenchFrame)panel.getContext()).getContext().getBlackboard();
+		blackboard = PersistentBlackboardPlugIn.get(blackboard);
         Coordinate[] modelCoordinates = geometry.getCoordinates();
         if ((geometry.getDimension() > 0) || (!paintingHandles)) {  //points will be obscurred by handles anyway      
         	StyleUtil.paint(
@@ -132,7 +141,7 @@
             fillColor,
             true,
             lineStroke,
-            lineColor);
+            (Color) blackboard.get(SelectionStyllingOptionsPanel.BB_SELECTION_STYLE_COLOR, SelectionStyllingOptionsPanel.DEFAULT_SELECTION_STYLE_COLOR));
         }
         if (paintingHandles) {
            //paintHandles(g, coordinates, handleStroke, handleFillColor, handleLineColor, panel.getViewport());
@@ -150,12 +159,9 @@
                     //Otherwise get "sun.dc.pr.PRException: endPath: bad path" exception [Jon Aquino 10/22/2003]
                     continue;
                 }
-                handle.x = x - (HANDLE_WIDTH / 2);
-                handle.y = y - (HANDLE_WIDTH / 2);
-                g.setColor(handleFillColor);
-                g.fill(handle);
-                g.setColor(handleLineColor);
-                g.draw(handle);                		 
+				VertexStyle vertexStyle = VertexStylesFactory.createVertexStyle((String) blackboard.get(SelectionStyllingOptionsPanel.BB_SELECTION_STYLE_POINT_FORM, SelectionStyllingOptionsPanel.DEFAULT_SELECTION_STYLE_POINT_FORM));
+				vertexStyle.setSize(((Integer)blackboard.get(SelectionStyllingOptionsPanel.BB_SELECTION_STYLE_POINT_SIZE, SelectionStyllingOptionsPanel.DEFAULT_SELECTION_STYLE_POINT_SIZE)).intValue());
+				vertexStyle.paint(g, new Point2D.Double(x, y));
             }
         }
     }
Index: src/language/jump_de.properties
--- src/language/jump_de.properties Base (BASE)
+++ src/language/jump_de.properties Locally Modified (Based On LOCAL)
@@ -1402,6 +1402,7 @@
 ui.plugin.OpenProjectPlugIn.open-project = Projekt öffnen 
 ui.plugin.OptionsPlugIn.snap-vertices-tools = Fang-Funktion
 ui.plugin.OptionsPlugIn.view-edit = Anzeige / Bearbeiten
+ui.plugin.OptionsPlugIn.selection-style= Auswahl Darstellung
 ui.plugin.RemoveSelectedCategoriesPlugIn.at-least-1-category-must-be-left-unselected = Mindestens eine Ebene darf nicht ausgewählt werden
 ui.plugin.SaveDatasetAsPlugIn.save-dataset = Datensatz speichern
 ui.plugin.SaveDatasetAsPlugIn.save-dataset-as-old = Datensatz speichern als (alt)
@@ -1731,3 +1732,8 @@
 com.vividsolutions.jump.workbench.plugin.At-least-one-feature-must-have-selected-items = Mindestens ein Feature muss ausgewählte Objekte haben
 com.vividsolutions.jump.workbench.plugin.At-least-n-features-must-have-selected-items = Mindestens {0} Features müssen ausgewählte Objekte haben
 ui.AboutDialog = Deutsch\: Stefan Steiniger
+
+# SelectionStyllingOptionsPanel - 18. Jun. 2010
+ui.SelectionStyllingOptionsPanel.LineColor = Linienfarbe:
+ui.SelectionStyllingOptionsPanel.PointStyle = Punktdarstellung:
+ui.SelectionStyllingOptionsPanel.PointSize = Punktgröße:
\ No newline at end of file
Index: src/org/openjump/core/ui/SelectionStyllingOptionsPanel.java
--- src/org/openjump/core/ui/SelectionStyllingOptionsPanel.java Locally New
+++ src/org/openjump/core/ui/SelectionStyllingOptionsPanel.java Locally New
@@ -0,0 +1,211 @@
+package org.openjump.core.ui;
+
+import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.util.Blackboard;
+import com.vividsolutions.jump.workbench.ui.ColorChooserPanel;
+import com.vividsolutions.jump.workbench.ui.GUIUtil;
+import com.vividsolutions.jump.workbench.ui.OptionsPanel;
+import de.latlon.deejump.plugin.style.VertexStylesFactory;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Hashtable;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.ListCellRenderer;
+import javax.swing.border.EmptyBorder;
+
+/**
+ *
+ * @author Matthias Scholz <m...@jammerhund.de<
+ */
+public class SelectionStyllingOptionsPanel extends JPanel implements OptionsPanel, ListCellRenderer {
+
+	public static final String BB_SELECTION_STYLE_COLOR = SelectionStyllingOptionsPanel.class.getName() + " SELECTION_STYLE_COLOR";
+	public static final String BB_SELECTION_STYLE_POINT_FORM = SelectionStyllingOptionsPanel.class.getName() + " SELECTION_STYLE_POINT_FORM";
+	public static final String BB_SELECTION_STYLE_POINT_SIZE = SelectionStyllingOptionsPanel.class.getName() + " SELECTION_STYLE_POINT_SIZE";
+
+	public static final Color DEFAULT_SELECTION_STYLE_COLOR = Color.yellow;
+	public static final String DEFAULT_SELECTION_STYLE_POINT_FORM = VertexStylesFactory.SQUARE_STYLE;
+	public static final Integer DEFAULT_SELECTION_STYLE_POINT_SIZE = 5;
+
+	private JPanel mainPanel;
+    private ColorChooserPanel lineColorChooserPanel;
+    private JLabel lineColorLabe;
+    private JComboBox pointStyleComboBox;
+    private JLabel pointStyleLabel;
+	private JLabel pointSizeLabel;
+	private JSlider pointSizeSlider;
+	private JPanel fillPanel;
+
+	private Blackboard blackboard = null;
+
+	public SelectionStyllingOptionsPanel(Blackboard blackboard) {
+		this.blackboard = blackboard;
+		initComponents();
+	}
+
+    private void initComponents() {
+        java.awt.GridBagConstraints gridBagConstraints;
+
+		mainPanel = new JPanel();
+        lineColorLabe = new JLabel();
+        pointStyleLabel = new JLabel();
+        lineColorChooserPanel = new ColorChooserPanel();
+
+		lineColorChooserPanel.addActionListener(new ActionListener() {
+
+			public void actionPerformed(ActionEvent e) {
+				ColorChooserPanel ccp = (ColorChooserPanel) e.getSource();
+				ccp.setAlpha(255);
+			}
+		});
+		lineColorChooserPanel.setColor(Color.GREEN); //TODO: initiale farbe holen
+		lineColorChooserPanel.setAlpha(255);
+        pointStyleComboBox = new javax.swing.JComboBox();
+		pointStyleComboBox.setRenderer(this);
+		pointStyleComboBox.setEditable(false);
+		// an item is a String Array, while index 0 is the Text in the ComboBox and index 1 is the VertexStyle
+		pointStyleComboBox.addItem(new String[] {I18N.get("deejump.ui.style.RenderingStylePanel.square"), VertexStylesFactory.SQUARE_STYLE});
+        pointStyleComboBox.addItem(new String[] {I18N.get("deejump.ui.style.RenderingStylePanel.circle"), VertexStylesFactory.CIRCLE_STYLE});
+        pointStyleComboBox.addItem(new String[] {I18N.get("deejump.ui.style.RenderingStylePanel.triangle"), VertexStylesFactory.TRIANGLE_STYLE});
+        pointStyleComboBox.addItem(new String[] {I18N.get("deejump.ui.style.RenderingStylePanel.cross"), VertexStylesFactory.CROSS_STYLE});
+        pointStyleComboBox.addItem(new String[] {I18N.get("deejump.ui.style.RenderingStylePanel.star"), VertexStylesFactory.STAR_STYLE});
+		pointSizeLabel = new JLabel();
+		pointSizeSlider = new JSlider();
+		fillPanel = new JPanel();
+
+		this.setLayout(new BorderLayout());
+		this.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
+		mainPanel.setLayout(new GridBagLayout());
+		this.add(mainPanel, BorderLayout.CENTER);
+
+		// Linecolor
+        lineColorLabe.setText(I18N.get("ui.SelectionStyllingOptionsPanel.LineColor"));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        mainPanel.add(lineColorLabe, gridBagConstraints);
+
+		gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 1;
+        gridBagConstraints.gridy = 0;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
+        mainPanel.add(lineColorChooserPanel, gridBagConstraints);
+
+		// Pointform
+        pointStyleLabel.setText(I18N.get("ui.SelectionStyllingOptionsPanel.PointStyle"));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 1;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        mainPanel.add(pointStyleLabel, gridBagConstraints);
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 1;
+        gridBagConstraints.gridy = 1;
+		gridBagConstraints.gridwidth = 2;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
+        mainPanel.add(pointStyleComboBox, gridBagConstraints);
+
+		// Pointsize
+        pointSizeLabel.setText(I18N.get("ui.SelectionStyllingOptionsPanel.PointSize"));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        mainPanel.add(pointSizeLabel, gridBagConstraints);
+
+        Hashtable labelTable = new Hashtable();
+        labelTable.put(new Integer(1), new JLabel("1"));
+        labelTable.put(new Integer(5), new JLabel("5"));
+        labelTable.put(new Integer(10), new JLabel("10"));
+        labelTable.put(new Integer(15), new JLabel("15"));
+        labelTable.put(new Integer(20), new JLabel("20"));
+		pointSizeSlider.setLabelTable(labelTable);
+		pointSizeSlider.setMinorTickSpacing(1);
+		pointSizeSlider.setMajorTickSpacing(0);
+		pointSizeSlider.setPaintLabels(true);
+		pointSizeSlider.setMinimum(1);
+		pointSizeSlider.setValue(2);
+		pointSizeSlider.setMaximum(20);
+		pointSizeSlider.setSnapToTicks(true);
+		pointSizeSlider.setPreferredSize(new Dimension(130, 49));
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 1;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
+        mainPanel.add(pointSizeSlider, gridBagConstraints);
+
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 2;
+        gridBagConstraints.gridy = 2;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
+		mainPanel.add(GUIUtil.createSyncdTextField(pointSizeSlider, 3), gridBagConstraints);
+
+		// fill Panel
+        gridBagConstraints = new java.awt.GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.gridy = 3;
+        gridBagConstraints.gridwidth = 2;
+        gridBagConstraints.weightx = 1.0;
+        gridBagConstraints.weighty = 1.0;
+        mainPanel.add(fillPanel, gridBagConstraints);
+
+    }
+
+
+	public String validateInput() {
+		return null;
+	}
+
+	public void okPressed() {
+		blackboard.put(BB_SELECTION_STYLE_COLOR, lineColorChooserPanel.getColor());
+		blackboard.put(BB_SELECTION_STYLE_POINT_SIZE, pointSizeSlider.getValue());
+		blackboard.put(BB_SELECTION_STYLE_POINT_FORM, ((String[])pointStyleComboBox.getSelectedItem())[1]);
+	}
+
+	public void init() {
+		Object color = blackboard.get(BB_SELECTION_STYLE_COLOR, DEFAULT_SELECTION_STYLE_COLOR);
+		if (color instanceof Color) lineColorChooserPanel.setColor((Color) color);
+		Object size = blackboard.get(BB_SELECTION_STYLE_POINT_SIZE, DEFAULT_SELECTION_STYLE_POINT_SIZE);
+		if (size instanceof Integer) pointSizeSlider.setValue(((Integer) blackboard.get(BB_SELECTION_STYLE_POINT_SIZE, DEFAULT_SELECTION_STYLE_POINT_SIZE)).intValue());
+		// select the item
+		String style = (String) blackboard.get(BB_SELECTION_STYLE_POINT_FORM, DEFAULT_SELECTION_STYLE_POINT_FORM);
+		int count = pointStyleComboBox.getItemCount();
+		for (int i = 0; i < count; i++) {
+			String[] item = (String[]) pointStyleComboBox.getItemAt(i);
+			if (item[1].equals(style)) {
+				pointStyleComboBox.setSelectedIndex(i);
+				break;
+			}
+		}
+
+	}
+
+	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+		JLabel label = new JLabel(((String[]) value)[0]);
+		label.setOpaque(true);
+		if (isSelected) {
+			label.setBackground(new Color(163, 184, 204)); // may be the original Color of a JComboBox
+		}
+		return label;
+	}
+
+}
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to