Ticket #6629: coloringPrefsAndLocal.patch

File coloringPrefsAndLocal.patch, 7.0 KB (added by akks, 13 years ago)
  • org/openstreetmap/josm/gui/layer/GpxLayer.java

     
    14061406
    14071407        @Override
    14081408        public void actionPerformed(ActionEvent e) {
    1409             GPXSettingsPanel panel=new GPXSettingsPanel(getName());
     1409            boolean hasLocal = false, hasNonlocal = false;
     1410            for (Layer layer : layers) {
     1411                if (layer instanceof GpxLayer) {
     1412                    if (((GpxLayer) layer).isLocalFile) hasLocal = true;
     1413                    else hasNonlocal = true;
     1414                }
     1415            }
     1416            System.out.println(hasLocal+"--"+hasNonlocal);
     1417            GPXSettingsPanel panel=new GPXSettingsPanel(getName(), hasLocal, hasNonlocal);
     1418           
    14101419            int answer = JOptionPane.showConfirmDialog(Main.parent, panel,
    14111420                    tr("Customize track drawing"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    14121421            if (answer == JOptionPane.CANCEL_OPTION || answer == JOptionPane.CLOSED_OPTION) return;
    14131422            for(Layer layer : layers) {
    14141423                // save preferences for all layers
    1415                 panel.savePreferences(layer.getName());
     1424                boolean f=false;
     1425                if (layer instanceof GpxLayer) f=((GpxLayer)layer).isLocalFile;
     1426                panel.savePreferences(layer.getName(),f);
    14161427            }
    14171428            Main.map.repaint();
    14181429        }
  • org/openstreetmap/josm/gui/preferences/GPXSettingsPanel.java

     
    4848    private JComboBox waypointLabel = new JComboBox(new String[] {tr("Auto"), /* gpx data field name */ trc("gpx_field", "Name"),
    4949            /* gpx data field name */ trc("gpx_field", "Desc(ription)"), tr("Both"), tr("None")});
    5050    private String layerName;
     51    private boolean local; // flag to display LocalOnly checkbox
     52    private boolean nonlocal; // flag to display AllLines checkbox
    5153
    52     public GPXSettingsPanel(String layerName) {
     54    public GPXSettingsPanel(String layerName, boolean local, boolean nonlocal) {
    5355        super(new GridBagLayout());
     56        this.local=local; this.nonlocal=nonlocal;
    5457        this.layerName = "layer "+layerName;
    5558        initComponents();
    5659        loadPreferences();
     
    5962    public GPXSettingsPanel() {
    6063        super(new GridBagLayout());
    6164        initComponents();
     65        local=false; nonlocal=false;
    6266        loadPreferences(); // preferences -> controls
    6367    }
     68   
    6469    private void initComponents() {
    6570        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    6671
     
    8085        add(new JLabel(tr("Draw lines between raw GPS points")), GBC.eol().insets(20,0,0,0));
    8186        if (layerName!=null) add(drawRawGpsLinesGlobal, GBC.eol().insets(40,0,0,0));
    8287        add(drawRawGpsLinesNone, GBC.eol().insets(40,0,0,0));
    83         add(drawRawGpsLinesLocal, GBC.eol().insets(40,0,0,0));
    84         add(drawRawGpsLinesAll, GBC.eol().insets(40,0,0,0));
     88        if (layerName==null || local) add(drawRawGpsLinesLocal, GBC.eol().insets(40,0,0,0));
     89        if (layerName==null || nonlocal) add(drawRawGpsLinesAll, GBC.eol().insets(40,0,0,0));
    8590
    8691        drawRawGpsLinesActionListener = new ActionListener(){
    8792            public void actionPerformed(ActionEvent e) {
     
    200205    public void loadPreferences () {
    201206        makeAutoMarkers.setSelected(Main.pref.getBoolean("marker.makeautomarkers", true));
    202207        if(layerName!=null && !Main.pref.hasKey("draw.rawgps.lines."+layerName)
    203                 && !Main.pref.hasKey("draw.rawgps.lines.local"+layerName)){
     208                && !Main.pref.hasKey("draw.rawgps.lines.local."+layerName)){
    204209            // no line preferences for layer is found
    205210            drawRawGpsLinesGlobal.setSelected(true);
    206211        } else {
     
    253258     * Save preferences from UI controls for specified layer
    254259     * if layerName==null, global preferences are written
    255260     */
    256     public boolean savePreferences (String layerName) {
     261    public boolean savePreferences (String layerName, boolean locLayer) {
    257262        String layerNameDot = ".layer "+layerName;
     263        if (layerName==null) layerNameDot="";
    258264        Main.pref.put("marker.makeautomarkers"+layerNameDot, makeAutoMarkers.isSelected());
    259265        if (drawRawGpsLinesGlobal.isSelected()) {
    260             Main.pref.put("draw.rawgps.lines"+layerNameDot, null);
    261             Main.pref.put("draw.rawgps.lines.local"+layerNameDot, null);
    262             Main.pref.put("draw.rawgps.max-line-length"+layerNameDot, null);
    263             Main.pref.put("draw.rawgps.max-line-length.local"+layerNameDot, null);
     266            Main.pref.put("draw.rawgps.lines" + layerNameDot, null);
     267            Main.pref.put("draw.rawgps.max-line-length" + layerNameDot, null);
     268            Main.pref.put("draw.rawgps.lines.local" + layerNameDot, null);
     269            Main.pref.put("draw.rawgps.max-line-length.local" + layerNameDot, null);
    264270            Main.pref.put("draw.rawgps.lines.force"+layerNameDot, null);
    265271            Main.pref.put("draw.rawgps.direction"+layerNameDot, null);
    266272            Main.pref.put("draw.rawgps.alternatedirection"+layerNameDot, null);
    267273            Main.pref.put("draw.rawgps.min-arrow-distance"+layerNameDot, null);
    268274        } else {
    269             Main.pref.put("draw.rawgps.lines"+layerNameDot, drawRawGpsLinesAll.isSelected());
    270             Main.pref.put("draw.rawgps.lines.local"+layerNameDot, drawRawGpsLinesAll.isSelected() || drawRawGpsLinesLocal.isSelected());
    271             Main.pref.put("draw.rawgps.max-line-length"+layerNameDot, drawRawGpsMaxLineLength.getText());
    272             Main.pref.put("draw.rawgps.max-line-length.local"+layerNameDot, drawRawGpsMaxLineLengthLocal.getText());
     275            if (layerName==null || !locLayer) {
     276                Main.pref.put("draw.rawgps.lines" +  layerNameDot, drawRawGpsLinesAll.isSelected());
     277                Main.pref.put("draw.rawgps.max-line-length" + layerNameDot, drawRawGpsMaxLineLength.getText());
     278            }
     279            if (layerName==null || locLayer) {
     280                Main.pref.put("draw.rawgps.lines.local" + layerNameDot, drawRawGpsLinesAll.isSelected() || drawRawGpsLinesLocal.isSelected());
     281                Main.pref.put("draw.rawgps.max-line-length.local" + layerNameDot, drawRawGpsMaxLineLengthLocal.getText());
     282            }
    273283            Main.pref.put("draw.rawgps.lines.force"+layerNameDot, forceRawGpsLines.isSelected());
    274284            Main.pref.put("draw.rawgps.direction"+layerNameDot, drawGpsArrows.isSelected());
    275285            Main.pref.put("draw.rawgps.alternatedirection"+layerNameDot, drawGpsArrowsFast.isSelected());
     
    307317     * Save preferences from UI controls for initial layer or globally
    308318     */
    309319    public void savePreferences() {
    310         savePreferences(null);
     320        savePreferences(null, false);
    311321    }
    312322}