Ignore:
Timestamp:
2010-10-02T01:23:18+02:00 (14 years ago)
Author:
tordanik
Message:

option to change graph colors; closes ticket 5523 in JOSM Trac

Location:
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/dialogs/GraphViewPreferenceEditor.java

    r23189 r23434  
    11package org.openstreetmap.josm.plugins.graphview.plugin.dialogs;
    22
     3import java.awt.Color;
    34import java.awt.GridBagConstraints;
    45import java.awt.GridBagLayout;
     6import java.awt.GridLayout;
    57import java.awt.event.ActionEvent;
    68import java.awt.event.ActionListener;
     
    1517import javax.swing.JButton;
    1618import javax.swing.JCheckBox;
     19import javax.swing.JColorChooser;
    1720import javax.swing.JComboBox;
    1821import javax.swing.JFileChooser;
     
    2225import javax.swing.JTextField;
    2326
    24 import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
    2527import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    2628import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
     
    4850
    4951    private JCheckBox separateDirectionsCheckBox;
    50 
     52    private JButton segmentColorButton;
     53    private JPanel segmentColorField;
     54    private JButton nodeColorButton;
     55    private JPanel nodeColorField;
     56   
    5157    public void addGui(PreferenceTabbedPane gui) {
    5258
     
    174180        return vehiclePanel;
    175181    }
    176 
     182   
    177183    private JPanel createVisualizationPanel() {
    178 
    179         JPanel visualizationPanel = new JPanel();
    180         visualizationPanel.setBorder(BorderFactory.createTitledBorder("visualization"));
    181         visualizationPanel.setLayout(new BoxLayout(visualizationPanel, BoxLayout.Y_AXIS));
    182 
    183         separateDirectionsCheckBox = new JCheckBox("draw directions separately");
    184         separateDirectionsCheckBox.setSelected(GraphViewPreferences.getInstance().getSeparateDirections());
    185         visualizationPanel.add(separateDirectionsCheckBox);
    186 
    187         return visualizationPanel;
     184       
     185        JPanel visualizationPanel = new JPanel();
     186        visualizationPanel.setBorder(BorderFactory.createTitledBorder("visualization"));
     187        visualizationPanel.setLayout(new BoxLayout(visualizationPanel, BoxLayout.Y_AXIS));
     188       
     189        separateDirectionsCheckBox = new JCheckBox("draw directions separately");
     190        separateDirectionsCheckBox.setSelected(GraphViewPreferences.getInstance().getSeparateDirections());
     191        visualizationPanel.add(separateDirectionsCheckBox);
     192       
     193        { // create color chooser panel
     194               
     195                JPanel colorPanel = new JPanel();
     196                colorPanel.setLayout(new GridLayout(2, 2));
     197               
     198                Color nodeColor = GraphViewPreferences.getInstance().getNodeColor();
     199               
     200                nodeColorButton = new JButton("node color");
     201                nodeColorButton.addActionListener(chooseNodeColorActionListener);
     202                colorPanel.add(nodeColorButton);
     203                nodeColorField = new JPanel();
     204                nodeColorField.setBackground(nodeColor);
     205                colorPanel.add(nodeColorField);
     206               
     207                Color segmentColor = GraphViewPreferences.getInstance().getSegmentColor();
     208               
     209                segmentColorButton = new JButton("arrow color");
     210                segmentColorButton.addActionListener(chooseSegmentColorActionListener);
     211                colorPanel.add(segmentColorButton);
     212                segmentColorField = new JPanel();
     213                segmentColorField.setBackground(segmentColor);
     214                colorPanel.add(segmentColorField);
     215               
     216                visualizationPanel.add(colorPanel);
     217               
     218        }
     219       
     220        return visualizationPanel;
    188221    }
    189222
     
    202235        preferences.setSeparateDirections(separateDirectionsCheckBox.isSelected());
    203236
     237        preferences.setNodeColor(nodeColorField.getBackground());
     238        preferences.setSegmentColor(segmentColorField.getBackground());
     239       
    204240        preferences.distributeChanges();
    205241
     
    333369        }
    334370    };
     371   
     372    private final ActionListener chooseNodeColorActionListener = new ActionListener() {
     373        public void actionPerformed(ActionEvent e) {
     374               
     375                Color selectedColor = JColorChooser.showDialog(
     376                                preferencePanel, "Choose node color", nodeColorField.getBackground());
     377               
     378                if (selectedColor != null) {
     379                        nodeColorField.setBackground(selectedColor);
     380                }
     381               
     382        }
     383    };
     384   
     385    private final ActionListener chooseSegmentColorActionListener = new ActionListener() {
     386        public void actionPerformed(ActionEvent e) {
     387               
     388                Color selectedColor = JColorChooser.showDialog(
     389                                preferencePanel, "Choose arrow color", segmentColorField.getBackground());
     390               
     391                if (selectedColor != null) {
     392                        segmentColorField.setBackground(selectedColor);
     393                }
     394               
     395        }
     396    };
    335397
    336398    private void updateRulesetPanel() {
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/layer/GraphViewLayer.java

    r23189 r23434  
    179179        } else {
    180180
    181             g2D.setColor(Color.WHITE);
    182 
     181                Color color = GraphViewPreferences.getInstance().getSegmentColor();
     182            g2D.setColor(color);
     183           
    183184            Point p1 = getNodePoint(e.getStartNode(), mv);
    184185            Point p2 = getNodePoint(e.getTargetNode(), mv);
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/preferences/GraphViewPreferences.java

    r23189 r23434  
    3636 * changes will also be synchronized (two-way) with JOSM's preference storage.
    3737 * This is a singleton class.
     38 *
     39 * Note: Currently, manual updates in the "advanced preferences" will not have any effect
     40 * because this class isn't registered as a preference listener.
    3841 */
    3942public class GraphViewPreferences extends Observable {
Note: See TracChangeset for help on using the changeset viewer.