Ignore:
Timestamp:
2010-09-12T18:33:47+02:00 (14 years ago)
Author:
upliner
Message:

'show stderr contents in debug window'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ext_tools/src/ext_tools/ExtTool.java

    r21930 r23126  
    44
    55import java.awt.Cursor;
     6import java.awt.GridBagLayout;
    67import java.io.File;
    78import java.io.IOException;
     
    1415import javax.swing.JMenuItem;
    1516import javax.swing.JOptionPane;
     17import javax.swing.JPanel;
     18import javax.swing.JScrollPane;
     19import javax.swing.JTextArea;
    1620import javax.swing.SwingUtilities;
    1721
     
    2226import org.openstreetmap.josm.data.coor.LatLon;
    2327import org.openstreetmap.josm.data.osm.DataSet;
     28import org.openstreetmap.josm.gui.JMultilineLabel;
    2429import org.openstreetmap.josm.gui.MainMenu;
    2530import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    2732import org.openstreetmap.josm.io.IllegalDataException;
    2833import org.openstreetmap.josm.io.OsmReader;
     34import org.openstreetmap.josm.tools.GBC;
    2935
    3036public class ExtTool {
     
    110116    }
    111117
     118    protected void showErrorMessage(String message, String details) {
     119        JPanel p = new JPanel(new GridBagLayout());
     120        p.add(new JMultilineLabel(message),GBC.eol());
     121        if (details != null) {
     122            JTextArea info = new JTextArea(details, 20, 60);
     123            info.setCaretPosition(0);
     124            info.setEditable(false);
     125            p.add(new JScrollPane(info), GBC.eop());
     126        }
     127        JOptionPane.showMessageDialog(Main.parent, p, tr("External tool error"), JOptionPane.ERROR_MESSAGE);
     128    }
     129
    112130    public void runTool(LatLon pos) {
    113131        Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     
    138156        builder.directory(new File(ExtToolsPlugin.plugin.getPluginDir()));
    139157
     158        final StringBuilder debugstr = new StringBuilder();
     159
    140160        // debug: print resulting cmdline
    141161        for (String s : builder.command())
    142             System.out.print(s + " ");
    143         System.out.print("\n");
     162            debugstr.append(s + " ");
     163        debugstr.append("\n");
     164        System.out.print(debugstr.toString());
    144165
    145166        final ToolProcess tp = new ToolProcess();
     
    159180                    int len;
    160181                    while ((len = errStream.read(buffer)) > 0) {
     182                        synchronized (debugstr) {
     183                            debugstr.append(new String(buffer, 0, len));
     184                        }
    161185                        System.err.write(buffer, 0, len);
    162186                    }
     
    185209                        SwingUtilities.invokeLater(new Runnable() {
    186210                            public void run() {
    187                                 JOptionPane.showMessageDialog(Main.parent,
    188                                         tr("Child script have returned invalid data."));
     211                                synchronized (debugstr) {
     212                                    showErrorMessage(
     213                                            tr("Child script have returned invalid data.\n\nstderr contents:"),
     214                                            debugstr.toString());
     215                                }
    189216                            }
    190217                        });
Note: See TracChangeset for help on using the changeset viewer.