Changeset 159 in josm for src


Ignore:
Timestamp:
2006-10-13T13:02:57+02:00 (18 years ago)
Author:
imi
Message:
  • moved translations into plugins
  • added main menu control to main
  • added ImageProvider access to plugins
Location:
src/org/openstreetmap/josm
Files:
1 added
1 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r155 r159  
    77import java.awt.Rectangle;
    88import java.awt.Toolkit;
    9 import java.awt.event.ActionEvent;
    109import java.awt.event.KeyEvent;
    1110import java.io.File;
     
    2120import java.util.regex.Pattern;
    2221
    23 import javax.swing.AbstractAction;
    24 import javax.swing.Action;
    2522import javax.swing.JComponent;
    26 import javax.swing.JMenu;
    27 import javax.swing.JMenuBar;
    2823import javax.swing.JOptionPane;
    2924import javax.swing.JPanel;
    30 import javax.swing.JSeparator;
    3125import javax.swing.JToolBar;
    3226import javax.swing.KeyStroke;
     
    3428
    3529import org.openstreetmap.josm.actions.AboutAction;
    36 import org.openstreetmap.josm.actions.AlignInCircleAction;
    3730import org.openstreetmap.josm.actions.DownloadAction;
    38 import org.openstreetmap.josm.actions.ExitAction;
    39 import org.openstreetmap.josm.actions.ExternalToolsAction;
    40 import org.openstreetmap.josm.actions.GpxExportAction;
    41 import org.openstreetmap.josm.actions.HelpAction;
    42 import org.openstreetmap.josm.actions.OpenAction;
    43 import org.openstreetmap.josm.actions.PreferencesAction;
    44 import org.openstreetmap.josm.actions.RedoAction;
    45 import org.openstreetmap.josm.actions.ReverseSegmentAction;
    46 import org.openstreetmap.josm.actions.SaveAction;
    47 import org.openstreetmap.josm.actions.SaveAsAction;
    48 import org.openstreetmap.josm.actions.UndoAction;
    49 import org.openstreetmap.josm.actions.UploadAction;
    5031import org.openstreetmap.josm.actions.DownloadAction.DownloadTask;
    5132import org.openstreetmap.josm.actions.mapmode.MapMode;
     
    5536import org.openstreetmap.josm.data.projection.Epsg4326;
    5637import org.openstreetmap.josm.data.projection.Projection;
     38import org.openstreetmap.josm.gui.MainMenu;
    5739import org.openstreetmap.josm.gui.MapFrame;
    5840import org.openstreetmap.josm.gui.PleaseWaitDialog;
    5941import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    60 import org.openstreetmap.josm.gui.annotation.AnnotationTester;
    6142import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
    6243import org.openstreetmap.josm.gui.layer.Layer;
     
    10788         */
    10889        public static PleaseWaitDialog pleaseWaitDlg;
    109         /**
    110          * The access to the help subsystem
    111          */
    112         public HelpAction help;
     90
     91
     92        /**
     93         * The main menu bar at top of screen.
     94         */
     95        public final MainMenu menu;
    11396
    11497
     
    153136        public final void setLayerMenu(Component[] entries) {
    154137                if (entries == null || entries.length == 0)
    155                         layerMenu.setVisible(false);
     138                        menu.layerMenu.setVisible(false);
    156139                else {
    157                         layerMenu.removeAll();
     140                        menu.layerMenu.removeAll();
    158141                        for (Component c : entries)
    159                                 layerMenu.add(c);
    160                         layerMenu.setVisible(true);
     142                                menu.layerMenu.add(c);
     143                        menu.layerMenu.setVisible(true);
    161144                }
    162145        }
     
    177160                main = this;
    178161                contentPane.add(panel, BorderLayout.CENTER);
    179 
    180                 final Action annotationTesterAction = new AbstractAction(){
    181                         public void actionPerformed(ActionEvent e) {
    182                                 String annotationSources = pref.get("annotation.sources");
    183                                 if (annotationSources.equals("")) {
    184                                         JOptionPane.showMessageDialog(Main.parent, tr("You have to specify annotation sources in the preferences first."));
    185                                         return;
    186                                 }
    187                                 String[] args = annotationSources.split(";");
    188                                 new AnnotationTester(args);
    189                         }
    190                 };
    191                 annotationTesterAction.putValue(Action.NAME, tr("Annotation Preset Tester"));
    192                 annotationTesterAction.putValue(Action.SMALL_ICON, ImageProvider.get("annotation-tester"));
    193                 final Action reverseSegmentAction = new ReverseSegmentAction();
    194                 final Action alignInCircleAction = new AlignInCircleAction();
    195                 final Action uploadAction = new UploadAction();
    196                 final Action saveAction = new SaveAction();
    197                 final Action saveAsAction = new SaveAsAction();
    198                 final Action gpxExportAction = new GpxExportAction(null);
    199                 final Action exitAction = new ExitAction();
    200                 final Action preferencesAction = new PreferencesAction();
    201                 help = new HelpAction();
    202                 final Action aboutAction = new AboutAction();
    203 
    204                 final JMenu fileMenu = new JMenu(tr("Files"));
    205                 fileMenu.setMnemonic('F');
    206                 fileMenu.add(openAction);
    207                 fileMenu.add(saveAction);
    208                 fileMenu.add(saveAsAction);
    209                 fileMenu.add(gpxExportAction);
    210                 fileMenu.addSeparator();
    211                 fileMenu.add(exitAction);
    212                 mainMenu.add(fileMenu);
    213 
    214 
    215                 final JMenu connectionMenu = new JMenu(tr("Connection"));
    216                 connectionMenu.setMnemonic('C');
    217                 connectionMenu.add(downloadAction);
    218                 //connectionMenu.add(new DownloadIncompleteAction());
    219                 connectionMenu.add(uploadAction);
    220                 mainMenu.add(connectionMenu);
    221 
    222                 layerMenu = new JMenu(tr("Layer"));
    223                 layerMenu.setMnemonic('L');
    224                 mainMenu.add(layerMenu);
    225                 layerMenu.setVisible(false);
    226 
    227                 final JMenu editMenu = new JMenu(tr("Edit"));
    228                 editMenu.setMnemonic('E');
    229                 editMenu.add(undoAction);
    230                 editMenu.add(redoAction);
    231                 editMenu.addSeparator();
    232                 editMenu.add(reverseSegmentAction);
    233                 editMenu.add(alignInCircleAction);
    234                 editMenu.addSeparator();
    235                 editMenu.add(preferencesAction);
    236                 mainMenu.add(editMenu);
    237 
    238                 JMenu externalMenu = ExternalToolsAction.buildMenu();
    239                 if (externalMenu != null)
    240                         mainMenu.add(externalMenu);
    241 
    242                 mainMenu.add(new JSeparator());
    243                 final JMenu helpMenu = new JMenu(tr("Help"));
    244                 helpMenu.setMnemonic('H');
    245                 helpMenu.add(help);
    246                 helpMenu.add(aboutAction);
    247                 helpMenu.addSeparator();
    248                 helpMenu.add(annotationTesterAction);
    249                 mainMenu.add(helpMenu);
     162                menu = new MainMenu();
    250163
    251164                // creating toolbar
    252165                final JToolBar toolBar = new JToolBar();
    253166                toolBar.setFloatable(false);
    254                 toolBar.add(downloadAction);
    255                 toolBar.add(uploadAction);
     167                toolBar.add(menu.download);
     168                toolBar.add(menu.upload);
    256169                toolBar.addSeparator();
    257                 toolBar.add(openAction);
    258                 toolBar.add(saveAction);
    259                 toolBar.add(gpxExportAction);
     170                toolBar.add(menu.open);
     171                toolBar.add(menu.save);
     172                toolBar.add(menu.gpxExport);
    260173                toolBar.addSeparator();
    261                 toolBar.add(undoAction);
    262                 toolBar.add(redoAction);
     174                toolBar.add(menu.undo);
     175                toolBar.add(menu.redo);
    263176                toolBar.addSeparator();
    264                 toolBar.add(preferencesAction);
     177                toolBar.add(menu.preferences);
    265178                contentPane.add(toolBar, BorderLayout.NORTH);
    266179
    267180        contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "Help");
    268         contentPane.getActionMap().put("Help", help);
     181        contentPane.getActionMap().put("Help", menu.help);
    269182
    270183                contentPane.updateUI();
     
    280193                                try {
    281194                                        File pluginFile = new File(pref.getPreferencesDir()+"plugins/"+pluginName+".jar");
    282                                         if (pluginFile.exists())
    283                                                 plugins.add(new PluginInformation(pluginFile).load());
    284                                         else
     195                                        if (pluginFile.exists()) {
     196                                                PluginInformation info = new PluginInformation(pluginFile);
     197                                                Class<?> klass = info.loadClass();
     198                                                ImageProvider.sources.add(0, klass);
     199                                                plugins.add(info.load(klass));
     200                                        } else
    285201                                                JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName));
    286202                                } catch (PluginException e) {
     
    327243        ////////////////////////////////////////////////////////////////////////////////////////
    328244
    329 
    330245        public static JPanel panel = new JPanel(new BorderLayout());
    331246
    332         public final JMenuBar mainMenu = new JMenuBar();
    333247        protected static Rectangle bounds;
    334248
    335         public final UndoAction undoAction = new UndoAction();
    336         public final RedoAction redoAction = new RedoAction();
    337         public final OpenAction openAction = new OpenAction();
    338         public final DownloadAction downloadAction = new DownloadAction();
    339249
    340250        private final CommandQueueListener redoUndoListener = new CommandQueueListener(){
    341251                public void commandChanged(final int queueSize, final int redoSize) {
    342                         undoAction.setEnabled(queueSize > 0);
    343                         redoAction.setEnabled(redoSize > 0);
     252                        menu.undo.setEnabled(queueSize > 0);
     253                        menu.redo.setEnabled(redoSize > 0);
    344254                }
    345255        };
    346         private JMenu layerMenu;
    347256
    348257        /**
     
    420329                                JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed url: \"{0}\"", s));
    421330                        else {
    422                                 DownloadTask osmTask = main.downloadAction.downloadTasks.get(0);
    423                                 osmTask.download(main.downloadAction, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon());
     331                                DownloadTask osmTask = main.menu.download.downloadTasks.get(0);
     332                                osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon());
    424333                        }
    425334                        return;
     
    428337                if (s.startsWith("file:")) {
    429338                        try {
    430                                 main.openAction.openFile(new File(new URI(s)));
     339                                main.menu.open.openFile(new File(new URI(s)));
    431340                        } catch (URISyntaxException e) {
    432341                                JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed file url: \"{0}\"", s));
     
    438347                if (st.countTokens() == 4) {
    439348                        try {
    440                                 DownloadTask task = main.downloadAction.downloadTasks.get(rawGps ? 1 : 0);
    441                                 task.download(main.downloadAction, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
     349                                DownloadTask task = main.menu.download.downloadTasks.get(rawGps ? 1 : 0);
     350                                task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
    442351                                return;
    443352                        } catch (final NumberFormatException e) {
     
    445354                }
    446355
    447                 main.openAction.openFile(new File(s));
     356                main.menu.open.openFile(new File(s));
    448357        }
    449358}
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r103 r159  
    8888
    8989        /**
    90          * Return the id as hashcode or supers hashcode if 0.
     90         * Return the id plus the class type encoded as hashcode or supers hashcode if id is 0.
    9191         *
    9292         * An primitive has the same hashcode as its incomplete counter part.
    9393         */
    9494        @Override public final int hashCode() {
    95                 return id == 0 ? super.hashCode() : (int)id;
     95                if (id == 0)
     96                        return super.hashCode();
     97                final int[] ret = new int[1];
     98                Visitor v = new Visitor(){
     99                        public void visit(Node n) { ret[0] = 1; }
     100                        public void visit(Segment s) { ret[0] = 2; }
     101                        public void visit(Way w) { ret[0] = 3; }
     102                };
     103                visit(v);
     104                return id == 0 ? super.hashCode() : (int)(id<<3)+ret[0];
    96105        }
    97106
  • src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java

    r86 r159  
    4141         * Ways have all nodes from their segments.
    4242         */
    43         public void visit(Way t) {
    44                 for (Segment ls : t.segments)
     43        public void visit(Way w) {
     44                for (Segment ls : w.segments)
    4545                        visit(ls);
    4646        }
  • src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r146 r159  
    2828        }
    2929
    30         public void visit(Way t) {
    31                 for (Segment ls : t.segments)
     30        public void visit(Way w) {
     31                for (Segment ls : w.segments)
    3232                        visit(ls);
    3333        }
  • src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java

    r100 r159  
    5757        }
    5858        public void visit(Segment ls) {
    59                 for (Way t : ds.ways) {
    60                         if (t.deleted)
     59                for (Way w : ds.ways) {
     60                        if (w.deleted)
    6161                                continue;
    62                         if (t.segments.contains(ls))
    63                                 data.add(t);
     62                        if (w.segments.contains(ls))
     63                                data.add(w);
    6464                }
    6565        }
    66         public void visit(Way t) {}
     66        public void visit(Way w) {}
    6767}
  • src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java

    r86 r159  
    2929                ds.segments.remove(ls);
    3030        }
    31         public void visit(Way t) {
    32                 ds.ways.remove(t);
     31        public void visit(Way w) {
     32                ds.ways.remove(w);
    3333        }
    3434}
  • src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r119 r159  
    147147
    148148                Way my = null;
    149                 for (Way t : ds.ways) {
    150                         if (match(other, t)) {
    151                                 my = t;
     149                for (Way w : ds.ways) {
     150                        if (match(other, w)) {
     151                                my = w;
    152152                                break;
    153153                        }
     
    211211        }
    212212
    213         private void fixWay(Way t) {
     213        private void fixWay(Way w) {
    214214            boolean replacedSomething = false;
    215215            LinkedList<Segment> newSegments = new LinkedList<Segment>();
    216             for (Segment ls : t.segments) {
     216            for (Segment ls : w.segments) {
    217217                Segment otherLs = mergedSegments.get(ls);
    218218                newSegments.add(otherLs == null ? ls : otherLs);
     
    221221            }
    222222            if (replacedSomething) {
    223                 t.segments.clear();
    224                 t.segments.addAll(newSegments);
     223                w.segments.clear();
     224                w.segments.addAll(newSegments);
    225225            }
    226             for (Segment ls : t.segments)
     226            for (Segment ls : w.segments)
    227227                fixSegment(ls);
    228228    }
     
    258258         * @return Whether the ways matches (in sense of "be mergable").
    259259         */
    260         private boolean match(Way t1, Way t2) {
    261                 if (t1.id == 0 || t2.id == 0) {
    262                         if (t1.segments.size() != t2.segments.size())
     260        private boolean match(Way w1, Way w2) {
     261                if (w1.id == 0 || w2.id == 0) {
     262                        if (w1.segments.size() != w2.segments.size())
    263263                                return false;
    264                         Iterator<Segment> it = t1.segments.iterator();
    265                         for (Segment ls : t2.segments)
     264                        Iterator<Segment> it = w1.segments.iterator();
     265                        for (Segment ls : w2.segments)
    266266                                if (!match(ls, it.next()))
    267267                                        return false;
    268268                        return true;
    269269                }
    270                 return t1.id == t2.id;
     270                return w1.id == w2.id;
    271271        }
    272272
  • src/org/openstreetmap/josm/gui/MainApplet.java

    r104 r159  
    2626                private MainCaller() {
    2727                        setContentPane(contentPane);
    28                         setJMenuBar(mainMenu);
     28                        setJMenuBar(menu);
    2929                        setBounds(bounds);
    3030                }
  • src/org/openstreetmap/josm/gui/MainApplication.java

    r155 r159  
    1414import java.util.LinkedList;
    1515import java.util.List;
    16 import java.util.Locale;
    1716import java.util.Map;
    1817
     
    2322import org.openstreetmap.josm.gui.layer.Layer;
    2423import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     24import org.openstreetmap.josm.plugins.PluginException;
     25import org.openstreetmap.josm.plugins.PluginInformation;
    2526import org.openstreetmap.josm.tools.BugReportExceptionHandler;
     27import org.openstreetmap.josm.tools.ImageProvider;
    2628/**
    2729 * Main window class application.
     
    3638        public MainApplication(JFrame mainFrame) {
    3739                mainFrame.setContentPane(contentPane);
    38                 mainFrame.setJMenuBar(mainMenu);
     40                mainFrame.setJMenuBar(menu);
    3941                mainFrame.setBounds(bounds);
    4042                mainFrame.addWindowListener(new WindowAdapter(){
     
    7375                /////////////////////////////////////////////////////////////////////////
    7476                // Do not translate the early strings below until the locale is set up.
     77                // (By the eager loaded plugins)
     78                //
    7579                // These strings cannot be translated. That's live. Really. Sorry.
    76                 //
    77                 // The next one sending me a patch translating these strings owe me a beer!
    7880                //
    7981                //                                                                 Imi.
     
    118120                }
    119121
    120                 // setup the locale
    121                 if (args.containsKey("language") && !args.get("language").isEmpty() && args.get("language").iterator().next().length() >= 2) {
    122                         String s = args.get("language").iterator().next();
    123                         Locale l = null;
    124                         if (s.length() <= 2 || s.charAt(2) != '_')
    125                                 l = new Locale(s);
    126                         else if (s.length() <= 5 || s.charAt(5) != '.')
    127                                 l = new Locale(s.substring(0,2), s.substring(3));
    128                         else
    129                                 l = new Locale(s.substring(0,2), s.substring(3,5), s.substring(6));
    130                         Locale.setDefault(l);
    131                 } else if (!Main.pref.get("language").equals("")) {
    132                         String lang = Main.pref.get("language");
    133                         for (Locale l : Locale.getAvailableLocales()) {
    134                                 if (l.toString().equals(lang)) {
    135                                         Locale.setDefault(l);
    136                                         break;
     122                // load the early plugins
     123            if (Main.pref.hasKey("plugins")) {
     124                        for (String pluginName : Main.pref.get("plugins").split(",")) {
     125                                try {
     126                                        File pluginFile = new File(pref.getPreferencesDir()+"plugins/"+pluginName+".jar");
     127                                        if (pluginFile.exists()) {
     128                                                PluginInformation info = new PluginInformation(pluginFile);
     129                                                if (!info.early)
     130                                                        continue;
     131                                                Class<?> klass = info.loadClass();
     132                                                ImageProvider.sources.add(0, klass);
     133                                                Main.plugins.add(info.load(klass));
     134                                        } else
     135                                                System.out.println("Plugin not found: "+pluginName);
     136                                } catch (PluginException e) {
     137                                        System.out.println("Could not load plugin "+pluginName);
     138                                        e.printStackTrace();
    137139                                }
    138140                        }
    139141                }
    140 
    141                 // Locale is set. From now on, tr(), trn() and trc() may be called.
    142142
    143143                if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r155 r159  
    267267                }
    268268                if (osm instanceof Node || osm instanceof Segment) {
    269                         for (Way t : Main.ds.ways) {
    270                                 if (t.deleted)
     269                        for (Way w : Main.ds.ways) {
     270                                if (w.deleted)
    271271                                        continue;
    272                                 for (Segment ls : t.segments) {
     272                                for (Segment ls : w.segments) {
    273273                                        if (!ls.deleted && !ls.incomplete && c.contains(ls)) {
    274                                                 c.add(t);
     274                                                c.add(w);
    275275                                                break;
    276276                                        }
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r153 r159  
    1414import java.util.Collection;
    1515import java.util.HashMap;
    16 import java.util.HashSet;
    17 import java.util.Locale;
     16import java.util.LinkedList;
    1817import java.util.Map;
    1918import java.util.StringTokenizer;
     
    8584                public void actionPerformed(ActionEvent e) {
    8685                        Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
    87                         Main.pref.put("language", languages.getSelectedItem().toString());
    8886                        Main.pref.put("projection", projectionCombo.getSelectedItem().getClass().getName());
    8987                        Main.pref.put("osm-server.url", osmDataServer.getText());
     
    156154         */
    157155        private JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
    158         private JComboBox languages = new JComboBox(new Locale[]{
    159                         new Locale("en", "US"),
    160                         new Locale("en", "GB"),
    161                         Locale.GERMAN,
    162                         Locale.FRENCH,
    163                         new Locale("ro", "RO")});
    164156        /**
    165157         * The main tab panel.
     
    232224                });
    233225                lafCombo.addActionListener(requireRestartAction);
    234 
    235                 // language
    236                 String lang = Main.pref.get("language");
    237                 for (int i = 0; i < languages.getItemCount(); ++i) {
    238                         if (languages.getItemAt(i).toString().equals(lang)) {
    239                                 languages.setSelectedIndex(i);
    240                                 break;
    241                         }
    242                 }
    243                 languages.setRenderer(new DefaultListCellRenderer(){
    244                         @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    245                                 return super.getListCellRendererComponent(list, ((Locale)value).getDisplayName(), index, isSelected, cellHasFocus);
    246                         }
    247                 });
    248                 languages.addActionListener(requireRestartAction);
    249226
    250227                // projection combo box
     
    285262
    286263                Box pluginPanel = Box.createVerticalBox();
    287                 Collection<PluginInformation> availablePlugins = new HashSet<PluginInformation>();
     264                Collection<PluginInformation> availablePlugins = new LinkedList<PluginInformation>();
    288265                File[] pluginFiles = new File(Main.pref.getPreferencesDir()+"plugins").listFiles();
    289                 if (pluginFiles != null)
     266                if (pluginFiles != null) {
     267                        Arrays.sort(pluginFiles);
    290268                        for (File f : pluginFiles)
    291269                                if (f.isFile() && f.getName().endsWith(".jar"))
    292270                                        availablePlugins.add(new PluginInformation(f));
     271                }
    293272
    294273                Collection<String> enabledPlugins = Arrays.asList(Main.pref.get("plugins").split(","));
     
    320299                for (Entry<String,String> e : allColors.entrySet()) {
    321300                        Vector<Object> row = new Vector<Object>(2);
    322                         row.add(tr(e.getKey().substring("color.".length())));
     301                        row.add(e.getKey().substring("color.".length()));
    323302                        row.add(ColorHelper.html2color(e.getValue()));
    324303                        rows.add(row);
     
    342321                                        return l;
    343322                                }
    344                                 return oldColorsRenderer.getTableCellRendererComponent(t,o,selected,focus,row,column);
     323                                return oldColorsRenderer.getTableCellRendererComponent(t,tr(o.toString()),selected,focus,row,column);
    345324                        }
    346325                });
     
    429408                display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    430409                display.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
    431                 display.add(new JLabel(tr("Language")), GBC.std());
    432                 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    433                 display.add(languages, GBC.eol().fill(GBC.HORIZONTAL));
    434410                display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0));
    435411                display.add(forceRawGpsLines, GBC.eop().insets(40,0,0,0));
     
    487463                plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH));
    488464                plugin.add(GBC.glue(0,10), GBC.eol());
    489                 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", "Get more plugins"), GBC.std().fill(GBC.HORIZONTAL));
     465                plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", tr("Get more plugins")), GBC.std().fill(GBC.HORIZONTAL));
    490466
    491467                tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
     
    505481                setModal(true);
    506482                pack();
     483                if (getHeight() > 400)
     484                        setSize(getWidth(), 400);
     485                if (getWidth() > 600)
     486                        setSize(600, getHeight());
    507487                setLocationRelativeTo(Main.parent);
    508488        }
  • src/org/openstreetmap/josm/plugins/Plugin.java

    r154 r159  
    11package org.openstreetmap.josm.plugins;
    22
     3import java.io.File;
    34import java.io.FileNotFoundException;
    45import java.io.FileOutputStream;
     
    7172         */
    7273        public void copy(String from, String to) throws FileNotFoundException, IOException {
     74                File pluginDir = new File(getPluginDir());
     75                if (!pluginDir.exists())
     76                        pluginDir.mkdirs();
    7377        FileOutputStream out = new FileOutputStream(getPluginDir()+to);
    7478        InputStream in = getClass().getResourceAsStream(from);
  • src/org/openstreetmap/josm/plugins/PluginInformation.java

    r157 r159  
    66import java.net.URL;
    77import java.net.URLClassLoader;
     8import java.util.Map;
     9import java.util.TreeMap;
     10import java.util.jar.Attributes;
    811import java.util.jar.JarInputStream;
    912import java.util.jar.Manifest;
     
    2023        public final String className;
    2124        public final String description;
     25        public final boolean early;
     26        public final String author;
     27
     28        public final Map<String, String> attr = new TreeMap<String, String>();
    2229
    2330        public PluginInformation(File file) {
     
    2532                name = file.getName().substring(0, file.getName().length()-4);
    2633                try {
    27                 JarInputStream jar = new JarInputStream(new FileInputStream(file));
    28                 Manifest manifest = jar.getManifest();
    29                 className = manifest.getMainAttributes().getValue("Plugin-Class");
    30                 description = manifest.getMainAttributes().getValue("Plugin-Description");
    31                 jar.close();
    32         } catch (IOException e) {
    33                 throw new PluginException(null, name, e);
    34         }
    35     }
     34                        JarInputStream jar = new JarInputStream(new FileInputStream(file));
     35                        Manifest manifest = jar.getManifest();
     36                        Attributes attr = manifest.getMainAttributes();
     37                        className = attr.getValue("Plugin-Class");
     38                        description = attr.getValue("Plugin-Description");
     39                        early = Boolean.parseBoolean(attr.getValue("Plugin-Early"));
     40                        author = attr.getValue("Author");
     41                        for (Object o : attr.keySet())
     42                                this.attr.put(o.toString(), attr.getValue(o.toString()));
     43                        jar.close();
     44                } catch (IOException e) {
     45                        throw new PluginException(null, name, e);
     46                }
     47        }
    3648
    3749        /**
    3850         * Load and instantiate the plugin
    3951         */
    40         public PluginProxy load() {
     52        public PluginProxy load(Class<?> klass) {
     53                try {
     54                        return new PluginProxy(klass.newInstance(), this);
     55                } catch (Exception e) {
     56                        throw new PluginException(null, name, e);
     57                }
     58        }
     59
     60        /**
     61         * Load the class of the plugin
     62         */
     63        public Class<?> loadClass() {
    4164                try {
    4265                        ClassLoader loader = URLClassLoader.newInstance(
    4366                                        new URL[]{new URL(getURLString())},
    4467                                        getClass().getClassLoader());
    45                         Object plugin = Class.forName(className, true, loader).newInstance();
    46                         return new PluginProxy(plugin, this);
     68                        Class<?> realClass = Class.forName(className, true, loader);
     69                        return realClass;
    4770                } catch (Exception e) {
    4871                        throw new PluginException(null, name, e);
     
    5477                        return "file:/"+file.getAbsolutePath();
    5578                return "file://"+file.getAbsolutePath();
    56     }
     79        }
    5780}
  • src/org/openstreetmap/josm/tools/I18n.java

    r158 r159  
    11package org.openstreetmap.josm.tools;
    22
    3 import java.io.File;
    4 import java.net.URL;
    5 import java.net.URLClassLoader;
    63import java.text.MessageFormat;
    7 import java.util.Locale;
    8 import java.util.MissingResourceException;
    9 
    10 import org.openstreetmap.josm.Main;
    11 import org.xnap.commons.i18n.I18nFactory;
    124
    135/**
     
    179 */
    1810public class I18n {
    19         private static org.xnap.commons.i18n.I18n i18n;
    20 
    21         static {
    22                 String localeFile = Main.pref.getPreferencesDir()+"lang/"+Locale.getDefault()+".jar";
    23                 Class<?> klass = Main.class;
    24                 if (new File(localeFile).exists()) {
    25                         try {
    26                                 String url = localeFile.replace('\\','/');
    27                                 if (System.getProperty("os.name").startsWith("Windows"))
    28                                         url = "file:/"+url;
    29                                 else
    30                                         url = "file://"+url;
    31                         URLClassLoader loader = new URLClassLoader(new URL[]{new URL(url)});
    32                         klass = Class.forName("org.openstreetmap.josm.Translation_"+Locale.getDefault(), true, loader);
    33                 } catch (Exception e) {
    34                         System.out.println("Couldn't load locale file "+localeFile);
    35                         e.printStackTrace();
    36                 }
    37                 }
    38                 try {
    39                         i18n = I18nFactory.getI18n(klass);
    40                 } catch (MissingResourceException e) {
    41                         System.out.println("Locale '"+Locale.getDefault()+"' not found. Using default.");
    42                 }
    43         }
     11        /**
     12         * Set by MainApplication. Changes here later will probably mess up everything, because
     13         * many strings are already loaded.
     14         */
     15        public static org.xnap.commons.i18n.I18n i18n;
    4416
    4517        public static String tr(String text, Object... objects) {
  • src/org/openstreetmap/josm/tools/ImageProvider.java

    r101 r159  
    1212import java.net.URL;
    1313import java.util.HashMap;
     14import java.util.LinkedList;
     15import java.util.List;
    1416import java.util.Map;
    1517
     
    3739
    3840        /**
     41         * Add here all ClassLoader whose ressource should be searched.
     42         * Plugin's class loaders are added by main.
     43         */
     44        public static final List<Class<?>> sources = new LinkedList<Class<?>>();
     45
     46        /**
    3947         * Return an image from the specified location.
    4048         *
     
    4755                        subdir += "/";
    4856                String ext = name.indexOf('.') != -1 ? "" : ".png";
    49                 URL path = Main.class.getResource("/images/"+subdir+name+ext);
     57                URL path = null;
     58                for (Class<?> source : sources) {
     59                        path = source.getResource("/images/"+subdir+name+ext);
     60                        if (path != null)
     61                                break;
     62                }
    5063                if (path == null)
    5164                        throw new NullPointerException("/images/"+subdir+name+ext+" not found");
     
    108121                return new ImageIcon(img);
    109122        }
     123
     124        static {
     125                sources.add(Main.class);
     126        }
    110127}
  • src/org/openstreetmap/josm/tools/UrlLabel.java

    r149 r159  
    2121                setContentType("text/html");
    2222                setText("<html><a href=\""+url+"\">"+description+"</a></html>");
     23                setToolTipText(url);
    2324                setEditable(false);
    2425                setOpaque(false);
Note: See TracChangeset for help on using the changeset viewer.