Changeset 3894 in josm


Ignore:
Timestamp:
Feb 13, 2011 10:30:28 AM (2 years ago)
Author:
bastiK
Message:

integrate wireframe into mappaint dialog; rename 'shortdescription' to 'title' (xml header key is unchanged)

Location:
trunk
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    r3083 r3894  
    6868        setEnabled(Main.map != null && Main.main.getEditLayer() != null); 
    6969    } 
     70 
     71    public boolean isSelected() { 
     72        return selected; 
     73    } 
    7074} 
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r3837 r3894  
    138138 
    139139    /* View menu */ 
     140    public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction(); 
    140141    public final JosmAction toggleGPXLines = new ToggleGPXLinesAction(); 
    141142    public final InfoAction info = new InfoAction(); 
     
    272273 
    273274        // -- wireframe toggle action 
    274         WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction(); 
    275275        final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(wireFrameToggleAction); 
    276276        viewMenu.add(wireframe); 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r3882 r3894  
    99import java.awt.Font; 
    1010import java.awt.GridBagLayout; 
     11import java.awt.Insets; 
    1112import java.awt.Point; 
    1213import java.awt.Rectangle; 
    1314import java.awt.event.ActionEvent; 
     15import java.awt.event.ActionListener; 
    1416import java.awt.event.KeyEvent; 
    1517import java.awt.event.MouseEvent; 
     
    2628 
    2729import javax.swing.AbstractAction; 
     30import javax.swing.DefaultButtonModel; 
    2831import javax.swing.DefaultListSelectionModel; 
     32import javax.swing.JCheckBox; 
    2933import javax.swing.JFileChooser; 
    3034import javax.swing.JLabel; 
     
    3842import javax.swing.ListSelectionModel; 
    3943import javax.swing.SingleSelectionModel; 
     44import javax.swing.SwingConstants; 
    4045import javax.swing.SwingUtilities; 
    4146import javax.swing.UIManager; 
     47import javax.swing.border.EmptyBorder; 
    4248import javax.swing.event.ChangeEvent; 
    4349import javax.swing.event.ChangeListener; 
     
    4652import javax.swing.table.AbstractTableModel; 
    4753import javax.swing.table.DefaultTableCellRenderer; 
     54import javax.swing.table.TableCellRenderer; 
    4855import javax.swing.table.TableModel; 
    4956 
     
    7279    protected OnOffAction onoffAction; 
    7380    protected ReloadAction reloadAction; 
     81    protected MoveUpDownAction upAction; 
     82    protected MoveUpDownAction downAction; 
     83    protected JCheckBox cbWireframe; 
    7484 
    7585    public MapPaintDialog() { 
     
    8494 
    8595        model = new StylesModel(); 
     96 
     97        cbWireframe = new JCheckBox(); 
     98        JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL); 
     99        wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN)); 
     100 
     101        cbWireframe.setModel(new DefaultButtonModel() { 
     102            @Override 
     103            public void setSelected(boolean b) { 
     104                super.setSelected(b); 
     105                tblStyles.setEnabled(!b); 
     106                onoffAction.updateEnabledState(); 
     107                upAction.updateEnabledState(); 
     108                downAction.updateEnabledState(); 
     109            } 
     110        }); 
     111        cbWireframe.addActionListener(new ActionListener() { 
     112            public void actionPerformed(ActionEvent e) { 
     113                Main.main.menu.wireFrameToggleAction.actionPerformed(null); 
     114            } 
     115        }); 
     116        cbWireframe.setBorder(new EmptyBorder(new Insets(1,1,1,1))); 
    86117         
    87118        tblStyles = new StylesTable(model); 
     
    94125        tblStyles.getColumnModel().getColumn(0).setMaxWidth(1); 
    95126        tblStyles.getColumnModel().getColumn(0).setResizable(false); 
     127        tblStyles.getColumnModel().getColumn(0).setCellRenderer(new MyCheckBoxRenderer()); 
    96128        tblStyles.getColumnModel().getColumn(1).setCellRenderer(new StyleSourceRenderer()); 
    97129        tblStyles.setShowGrid(false); 
    98130        tblStyles.setIntercellSpacing(new Dimension(0, 0)); 
    99131 
    100         pnl.add(new JScrollPane(tblStyles), BorderLayout.CENTER); 
     132        JPanel p = new JPanel(new GridBagLayout()); 
     133        p.add(cbWireframe, GBC.std(0, 0)); 
     134        p.add(wfLabel, GBC.std(1, 0).weight(1, 0)); 
     135        p.add(tblStyles, GBC.std(0, 1).span(2).fill()); 
     136 
     137        pnl.add(new JScrollPane(p), BorderLayout.CENTER); 
    101138 
    102139        pnl.add(buildButtonRow(), BorderLayout.SOUTH); 
     
    126163        reloadAction = new ReloadAction(); 
    127164        onoffAction = new OnOffAction(); 
    128         MoveUpDownAction up = new MoveUpDownAction(false); 
    129         MoveUpDownAction down = new MoveUpDownAction(true); 
     165        upAction = new MoveUpDownAction(false); 
     166        downAction = new MoveUpDownAction(true); 
    130167        selectionModel.addListSelectionListener(onoffAction); 
    131168        selectionModel.addListSelectionListener(reloadAction); 
    132         selectionModel.addListSelectionListener(up); 
    133         selectionModel.addListSelectionListener(down); 
     169        selectionModel.addListSelectionListener(upAction); 
     170        selectionModel.addListSelectionListener(downAction); 
    134171        p.add(new SideButton(onoffAction)); 
    135         p.add(new SideButton(up)); 
    136         p.add(new SideButton(down)); 
     172        p.add(new SideButton(upAction)); 
     173        p.add(new SideButton(downAction)); 
    137174        p.add(new SideButton(new LaunchMapPaintPreferencesAction())); 
    138175 
     
    143180    public void showNotify() { 
    144181        MapPaintStyles.addMapPaintSylesUpdateListener(model); 
     182        Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel()); 
    145183    } 
    146184 
    147185    @Override 
    148186    public void hideNotify() { 
     187        Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel()); 
    149188        MapPaintStyles.removeMapPaintSylesUpdateListener(model); 
    150189    } 
     
    232271    } 
    233272 
    234     private static class StyleSourceRenderer extends DefaultTableCellRenderer { 
     273    private class MyCheckBoxRenderer extends JCheckBox implements TableCellRenderer { 
     274 
     275        public MyCheckBoxRenderer() { 
     276            setHorizontalAlignment(SwingConstants.CENTER); 
     277            setVerticalAlignment(SwingConstants.CENTER); 
     278        } 
     279 
     280        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row,int column) { 
     281            boolean b = (Boolean) value; 
     282            setSelected(b); 
     283            setEnabled(!cbWireframe.isSelected()); 
     284            return this; 
     285        } 
     286    } 
     287 
     288    private class StyleSourceRenderer extends DefaultTableCellRenderer { 
    235289        @Override 
    236290        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 
     
    240294            label.setIcon(s.getIcon()); 
    241295            label.setToolTipText(s.getToolTipText()); 
     296            label.setEnabled(!cbWireframe.isSelected()); 
    242297            return label; 
    243298        } 
     
    252307 
    253308        protected void updateEnabledState() { 
    254             setEnabled(tblStyles.getSelectedRowCount() > 0); 
     309            setEnabled(!cbWireframe.isSelected() && tblStyles.getSelectedRowCount() > 0); 
    255310        } 
    256311 
     
    274329     * The action to move down the currently selected entries in the list. 
    275330     */ 
    276     class MoveUpDownAction extends AbstractAction implements ListSelectionListener { 
     331    protected class MoveUpDownAction extends AbstractAction implements ListSelectionListener { 
    277332 
    278333        final int increment; 
     
    287342        public void updateEnabledState() { 
    288343            int[] sel = tblStyles.getSelectedRows(); 
    289             setEnabled(MapPaintStyles.canMoveStyles(sel, increment)); 
     344            setEnabled(!cbWireframe.isSelected() && MapPaintStyles.canMoveStyles(sel, increment)); 
    290345        } 
    291346 
     
    328383            putValue(SHORT_DESCRIPTION, tr("reload selected styles from file")); 
    329384            putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh")); 
    330             updateEnabledState(); 
    331         } 
    332  
    333         protected void updateEnabledState() { 
     385            setEnabled(getEnabledState()); 
     386        } 
     387 
     388        protected boolean getEnabledState() { 
     389            if (cbWireframe.isSelected()) 
     390                return false; 
    334391            int[] pos = tblStyles.getSelectedRows(); 
    335             boolean e = pos.length > 0; 
     392            if (pos.length == 0) 
     393                return false; 
    336394            for (int i : pos) { 
    337                 if (!model.getRow(i).isLocal()) { 
    338                     e = false; 
    339                     break; 
    340                 } 
    341             } 
    342             setEnabled(e); 
     395                if (!model.getRow(i).isLocal()) 
     396                    return false; 
     397            } 
     398            return true; 
    343399        } 
    344400 
    345401        @Override 
    346402        public void valueChanged(ListSelectionEvent e) { 
    347             updateEnabledState(); 
     403            setEnabled(getEnabledState()); 
    348404        } 
    349405 
     
    599655        @Override 
    600656        public void launch(MouseEvent evt) { 
     657            if (cbWireframe.isSelected()) 
     658                return; 
    601659            Point p = evt.getPoint(); 
    602660            int index = tblStyles.rowAtPoint(p); 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r3876 r3894  
    1515 
    1616import org.openstreetmap.josm.data.osm.OsmPrimitive; 
     17import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 
    1718import org.openstreetmap.josm.gui.preferences.SourceEntry; 
    1819import org.openstreetmap.josm.tools.ImageProvider; 
     
    2324    public File zipIcons; 
    2425 
    25     public StyleSource(String url, String name, String shortdescription) { 
    26         super(url, name, shortdescription, true); 
     26    private ImageIcon imageIcon; 
     27 
     28    /****** 
     29     * The following fields is additional information found in the header 
     30     * of the source file. 
     31     */ 
     32     
     33    public String icon; 
     34 
     35    public StyleSource(String url, String name, String title) { 
     36        super(url, name, title, true); 
    2737    } 
    2838 
    2939    public StyleSource(SourceEntry entry) { 
    30         super(entry.url, entry.name, entry.shortdescription, entry.active); 
     40        super(entry.url, entry.name, entry.title, entry.active); 
    3141    } 
    3242 
     
    4555    } 
    4656 
    47     protected void clearErrors() { 
     57    protected void init() { 
    4858        errors.clear(); 
     59        imageIcon = null; 
     60        icon = null; 
    4961    } 
    5062 
    51     private static ImageIcon pencil; 
     63    private static ImageIcon defaultIcon; 
     64 
     65    private static ImageIcon getDefaultIcon() { 
     66        if (defaultIcon == null) { 
     67            defaultIcon = ImageProvider.get("dialogs/mappaint", "pencil"); 
     68        } 
     69        return defaultIcon; 
     70    } 
    5271 
    5372    protected ImageIcon getSourceIcon() { 
    54         if (pencil == null) { 
    55             pencil = ImageProvider.get("dialogs/mappaint", "pencil"); 
     73        if (imageIcon == null) { 
     74            if (icon != null) { 
     75                imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), false); 
     76            } 
     77            if (imageIcon == null) { 
     78                imageIcon = getDefaultIcon(); 
     79            } 
    5680        } 
    57         return pencil; 
     81        return imageIcon; 
    5882    } 
    5983 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r3893 r3894  
    4141    @Override 
    4242    public void loadStyleSource() { 
     43        init(); 
    4344        rules.clear(); 
    44         clearErrors(); 
    4545        try { 
    4646            MapCSSParser parser = new MapCSSParser(getSourceInputStream(), "UTF-8"); 
     
    100100        } 
    101101        Cascade c = mc.getCascade("default"); 
    102         String sd = c.get("title", null, String.class); 
    103         if (sd != null) { 
    104             this.shortdescription = sd; 
     102        String pTitle = c.get("title", null, String.class); 
     103        if (title == null) { 
     104            title = pTitle; 
     105        } 
     106        String pIcon = c.get("icon", null, String.class); 
     107        if (icon == null) { 
     108            icon = pIcon; 
    105109        } 
    106110    } 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r3893 r3894  
    5050 
    5151    protected void init() { 
    52         clearErrors(); 
     52        super.init(); 
    5353        icons.clear(); 
    5454        lines.clear(); 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java

    r3863 r3894  
    160160                    style.name = atts.getValue("name"); 
    161161                } 
    162                 if (style.shortdescription == null) { 
    163                     style.shortdescription = atts.getValue("shortdescription"); 
     162                if (style.title == null) { 
     163                    style.title = atts.getValue("shortdescription"); 
     164                } 
     165                if (style.icon == null) { 
     166                    style.icon = atts.getValue("icon"); 
    164167                } 
    165168            } 
  • trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java

    r3870 r3894  
    242242            ExtendedSourceEntry i = new ExtendedSourceEntry("elemstyles.xml", "resource://styles/standard/elemstyles.xml"); 
    243243            i.name = "standard"; 
    244             i.shortdescription = tr("Internal Style"); 
     244            i.title = tr("JOSM Internal Style"); 
    245245            i.description = tr("Internal style to be used as base for runtime switchable overlay styles"); 
    246246            return Collections.singletonList(i); 
     
    249249        @Override 
    250250        public Collection<String> serialize(SourceEntry entry) { 
    251             return Arrays.asList(new String[] {entry.url, entry.name, entry.shortdescription, Boolean.toString(entry.active)}); 
     251            return Arrays.asList(new String[] {entry.url, entry.name, entry.title, Boolean.toString(entry.active)}); 
    252252        } 
    253253 
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r3855 r3894  
    621621            super(url, null, null, true); 
    622622            this.simpleFileName = simpleFileName; 
    623             version = author = link = description = shortdescription = null; 
     623            version = author = link = description = title = null; 
    624624        } 
    625625 
     
    628628         */ 
    629629        public String getDisplayName() { 
    630             return shortdescription == null ? simpleFileName : shortdescription; 
     630            return title == null ? simpleFileName : title; 
    631631        } 
    632632 
     
    656656    protected class EditSourceEntryDialog extends ExtendedDialog { 
    657657 
    658         /** 
    659          * We call this text field "name", but it is actually the shortdescription. 
    660          */ 
    661         private JTextField tfName; 
     658        private JTextField tfTitle; 
    662659        private JTextField tfURL; 
    663660        private JCheckBox cbActive; 
     
    670667            JPanel p = new JPanel(new GridBagLayout()); 
    671668 
    672             tfName = new JTextField(60); 
     669            tfTitle = new JTextField(60); 
    673670            p.add(new JLabel(tr("Name (optional):")), GBC.std().insets(15, 0, 5, 5)); 
    674             p.add(tfName, GBC.eol().insets(0, 0, 5, 5)); 
     671            p.add(tfTitle, GBC.eol().insets(0, 0, 5, 5)); 
    675672 
    676673            tfURL = new JTextField(60); 
     
    682679 
    683680            if (e != null) { 
    684                 if (e.shortdescription != null) { 
    685                     tfName.setText(e.shortdescription); 
     681                if (e.title != null) { 
     682                    tfTitle.setText(e.title); 
    686683                } 
    687684                tfURL.setText(e.url); 
     
    738735        } 
    739736 
    740         public String getShortdescription() { 
    741             return tfName.getText(); 
     737        public String getTitle() { 
     738            return tfTitle.getText(); 
    742739        } 
    743740 
     
    773770                activeSourcesModel.addSource(new SourceEntry( 
    774771                        editEntryDialog.getURL(), 
    775                         null, editEntryDialog.getShortdescription(), active)); 
     772                        null, editEntryDialog.getTitle(), active)); 
    776773                activeSourcesModel.fireTableDataChanged(); 
    777774            } 
     
    828825            editEntryDialog.showDialog(); 
    829826            if (editEntryDialog.getValue() == 1) { 
    830                 if (e.shortdescription != null || !equal(editEntryDialog.getShortdescription(), "")) { 
    831                     e.shortdescription = editEntryDialog.getShortdescription(); 
    832                     if (equal(e.shortdescription, "")) { 
    833                         e.shortdescription = null; 
     827                if (e.title != null || !equal(editEntryDialog.getTitle(), "")) { 
     828                    e.title = editEntryDialog.getTitle(); 
     829                    if (equal(e.title, "")) { 
     830                        e.title = null; 
    834831                    } 
    835832                } 
     
    11741171                            } else if ("description".equals(key) && last.description == null) { 
    11751172                                last.description = value; 
    1176                             } else if ("shortdescription".equals(key) && last.shortdescription == null) { 
    1177                                 last.shortdescription = value; 
     1173                            } else if ((lang + "shortdescription").equals(key) && last.title == null) { 
     1174                                last.title = value; 
     1175                            } else if ("shortdescription".equals(key) && last.title == null) { 
     1176                                last.title = value; 
    11781177                            } else if ("name".equals(key) && last.name == null) { 
    11791178                                last.name = value; 
     
    11841183                            } else if ((lang + "description").equals(key)) { 
    11851184                                last.description = value; 
    1186                             } else if ((lang + "shortdescription").equals(key)) { 
    1187                                 last.shortdescription = value; 
    11881185                            } 
    11891186                        } 
     
    12221219        private String fromSourceEntry(SourceEntry entry) { 
    12231220            StringBuilder s = new StringBuilder("<html><b>"); 
    1224             if (entry.shortdescription != null) { 
    1225                 s.append(entry.shortdescription).append("</b> ("); 
     1221            if (entry.title != null) { 
     1222                s.append(entry.title).append("</b> ("); 
    12261223            } 
    12271224            s.append(entry.url); 
    1228             if (entry.shortdescription != null) { 
     1225            if (entry.title != null) { 
    12291226                s.append(")"); 
    12301227            } 
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java

    r3886 r3894  
    3232 
    3333    /** 
    34      * A short description that can be used as menu entry. 
     34     * A title that can be used as menu entry. 
    3535     */ 
    36     public String shortdescription; 
     36    public String title; 
    3737 
    3838    /** 
     
    4545        this.url = url; 
    4646        this.name = equal(name, "") ? null : name; 
    47         this.shortdescription = equal(shortdescription, "") ? null : shortdescription; 
     47        this.title = equal(shortdescription, "") ? null : shortdescription; 
    4848        this.active = active; 
    4949    } 
     
    5252        this.url = e.url; 
    5353        this.name = e.name; 
    54         this.shortdescription = e.shortdescription; 
     54        this.title = e.title; 
    5555        this.active = e.active; 
    5656    } 
     
    6363        return equal(other.url, url) &&  
    6464                equal(other.name, name) && 
    65                 equal(other.shortdescription, shortdescription) && 
     65                equal(other.title, title) && 
    6666                other.active == active; 
    6767    } 
     
    7272        hash = 89 * hash + (this.url != null ? this.url.hashCode() : 0); 
    7373        hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0); 
    74         hash = 89 * hash + (this.shortdescription != null ? this.shortdescription.hashCode() : 0); 
     74        hash = 89 * hash + (this.title != null ? this.title.hashCode() : 0); 
    7575        hash = 89 * hash + (this.active ? 1 : 0); 
    7676        return hash; 
     
    7979    @Override 
    8080    public String toString() { 
    81         return shortdescription != null ? shortdescription : url; 
     81        return title != null ? title : url; 
    8282    } 
    8383 
     
    8888     */ 
    8989    public String getDisplayString() { 
    90         if (shortdescription != null) 
    91             return shortdescription; 
     90        if (title != null) 
     91            return title; 
    9292        else 
    9393            return getFileNamePart(); 
  • trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java

    r3885 r3894  
    329329        public Collection<ExtendedSourceEntry> getDefault() { 
    330330            ExtendedSourceEntry i = new ExtendedSourceEntry("defaultpresets.xml", "resource://data/defaultpresets.xml"); 
    331             i.shortdescription = tr("Internal Preset"); 
     331            i.title = tr("Internal Preset"); 
    332332            i.description = tr("The default preset for JOSM"); 
    333333            return Collections.singletonList(i); 
     
    336336        @Override 
    337337        public Collection<String> serialize(SourceEntry entry) { 
    338             return Arrays.asList(new String[] {entry.url, entry.shortdescription}); 
     338            return Arrays.asList(new String[] {entry.url, entry.title}); 
    339339        } 
    340340 
  • trunk/src/org/openstreetmap/josm/tools/GBC.java

    r3338 r3894  
    120120        return new Box.Filler(new Dimension(x,y), new Dimension(x,y), new Dimension(maxx,maxy)); 
    121121    } 
     122 
     123    public GBC grid(int x, int y) { 
     124        gridx = x; 
     125        gridy = y; 
     126        return this; 
     127    } 
     128 
     129    public GBC span(int width, int height) { 
     130        gridwidth = width; 
     131        gridheight = height; 
     132        return this; 
     133    } 
     134 
     135    public GBC span(int width) { 
     136        gridwidth = width; 
     137        return this; 
     138    } 
     139 
     140    public static GBC std(int x, int y) { 
     141        GBC c = new GBC(); 
     142        c.anchor = WEST; 
     143        c.gridx = x; 
     144        c.gridy = y; 
     145        return c; 
     146    } 
     147 
    122148} 
  • trunk/styles/standard/elemstyles.xml

    r3658 r3894  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<rules xmlns="http://josm.openstreetmap.de/mappaint-style-1.0" 
    3        name="standard"> 
     3       name="standard" icon="dialogs/mappaint/josm_small.png"> 
    44<!-- 
    55A little help: 
Note: See TracChangeset for help on using the changeset viewer.