Revision 1200

View differences:

org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/syntaxhighlight/JRSyntaxTextArea.java
6 6
import java.awt.Container;
7 7
import java.awt.Cursor;
8 8
import java.awt.Dimension;
9
import java.awt.Graphics;
10 9
import java.awt.Point;
11 10
import java.awt.Rectangle;
12 11
import java.awt.event.ActionEvent;
......
16 15
import java.awt.event.KeyListener;
17 16
import java.awt.event.MouseAdapter;
18 17
import java.awt.event.MouseEvent;
19
import java.awt.event.MouseListener;
20 18
import java.net.URL;
21 19
import java.util.ArrayList;
22 20
import java.util.Arrays;
......
61 59

  
62 60
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
63 61
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
62
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
64 63
import org.fife.ui.rtextarea.GutterIconInfo;
65 64
import org.fife.ui.rtextarea.RTextScrollPane;
66 65
import org.fife.ui.rtextarea.SearchContext;
67 66
import org.fife.ui.rtextarea.SearchEngine;
68 67
import org.fife.ui.rtextarea.SearchResult;
69
import org.gvsig.scripting.ScriptingLocator;
70 68
import org.gvsig.scripting.swing.api.ScriptingSwingLocator;
71 69
import org.gvsig.scripting.swing.api.ScriptingUIManager;
72 70
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent;
......
559 557
    }
560 558

  
561 559
    public void setContentType(String contentType) {
562
        this.textArea.setSyntaxEditingStyle(this.normalizeContentType(contentType));
560
        TokenMakerFactory factory = TokenMakerFactory.getDefaultInstance();
561
        Set<String> mimetypes = factory.keySet();
562
        String mimetype = this.normalizeContentType(contentType);
563
        if( !mimetypes.contains(mimetype)) {
564
          mimetype = mimetype.replace("-source", "");
565
          if( !mimetypes.contains(mimetype)) {
566
            mimetype = mimetype.replace("/x-", "/");
567
            if( !mimetypes.contains(mimetype)) {
568
              mimetype = this.normalizeContentType(contentType);
569
            }
570
          }
571
        }
572
        this.textArea.setSyntaxEditingStyle(mimetype);
563 573
    }
564 574

  
565 575
    public JScrollPane getJScrollPane() {
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/DefaultJScriptingBrowser.java
9 9
import java.awt.event.KeyEvent;
10 10
import java.awt.event.MouseEvent;
11 11
import java.awt.event.MouseListener;
12
import java.net.URL;
12 13
import java.util.ArrayList;
13 14
import java.util.Enumeration;
14 15
import java.util.HashMap;
......
34 35
import javax.swing.tree.TreeModel;
35 36
import javax.swing.tree.TreePath;
36 37
import javax.swing.tree.TreeSelectionModel;
38
import org.apache.commons.io.FilenameUtils;
39
import org.gvsig.scripting.ScriptingExternalFile;
37 40

  
38 41
import org.gvsig.scripting.ScriptingFolder;
39 42
import org.gvsig.scripting.ScriptingManager;
......
428 431
        }
429 432

  
430 433
        private ImageIcon getExpandedIcon(ScriptingUnit unit) {
434
            if( unit instanceof ScriptingExternalFile) {
435
              ScriptingExternalFile extfile = (ScriptingExternalFile) unit;
436
              String ext = FilenameUtils.getExtension(extfile.getExternalFile().getName());
437
              ClassLoader loader = this.getClass().getClassLoader();
438
              URL res = loader.getResource("org/gvsig/scripting/i18n/images/16x16/extensions/"+ext+"-icon-16x16.png");
439
              if( res!=null ) {
440
                return new ImageIcon(res);
441
              }
442
            }
431 443
            return getIcon(unit.getIconNames()[1]);
432 444
        }
433 445

  
434 446
        private ImageIcon getCollapsedIcon(ScriptingUnit unit) {
447
            if( unit instanceof ScriptingExternalFile) {
448
              ScriptingExternalFile extfile = (ScriptingExternalFile) unit;
449
              String ext = FilenameUtils.getExtension(extfile.getExternalFile().getName());
450
              ClassLoader loader = this.getClass().getClassLoader();
451
              URL res = loader.getResource("org/gvsig/scripting/images/16x16/extensions/"+ext+"-icon-16x16.png");
452
              if( res!=null ) {
453
                return new ImageIcon(res);
454
              }
455
            }
435 456
            return getIcon(unit.getIconNames()[0]);
436 457
        }
437 458

  
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/composer/DefaultJScriptingComposer.java
36 36
import javax.swing.JMenuItem;
37 37
import javax.swing.JOptionPane;
38 38
import javax.swing.JPanel;
39
import javax.swing.JPopupMenu;
39 40
import javax.swing.JScrollPane;
40 41
import javax.swing.JSplitPane;
41 42
import javax.swing.JTabbedPane;
......
114 115
import org.slf4j.Logger;
115 116
import org.slf4j.LoggerFactory;
116 117

  
118
@SuppressWarnings("UseSpecificCatch")
117 119
public class DefaultJScriptingComposer extends JPanel implements JScriptingComposer, Observer, ActionListener {
118 120

  
119 121
    /**
......
724 726
        @Override
725 727
        public void actionPerformed(ActionEvent e) {
726 728
            try {
727
                ScriptingUnit selectedItem = getLauncherSelectedScript();
729
                ScriptingUnit selectedItem = getLauncherSelectedUnit();
728 730
                if( uimanager.hasEditor(selectedItem) ) {
729 731
                    scriptEdit(selectedItem);
730 732
                }
......
768 770
        @Override
769 771
        public void actionPerformed(ActionEvent e) {
770 772
            try {
771
                scriptRename(getLauncherSelectedScript());
773
                scriptRename(getLauncherSelectedUnit());
772 774
            } catch (Exception e1) {
773 775
                LOGGER.warn("Can't rename document", e1);
774 776
            }
......
790 792
        @Override
791 793
        public void actionPerformed(ActionEvent e) {
792 794
            try {
793
                scriptMove(getLauncherSelectedScript());
795
                scriptMove(getLauncherSelectedUnit());
794 796
            } catch (Exception e1) {
795 797
                LOGGER.warn("Can't move document", e1);
796 798
            }
......
812 814
        @Override
813 815
        public void actionPerformed(ActionEvent e) {
814 816
            try {
815
                scriptDelete(getLauncherSelectedScript(), false);
817
                scriptDelete(getLauncherSelectedUnit(), false);
816 818
            } catch (Exception e1) {
817 819
                LOGGER.warn("Can't delete document", e1);
818 820
            }
......
1300 1302
     *
1301 1303
     * @return Selected ScriptingUnit on the tree
1302 1304
     */
1303
    private ScriptingUnit getLauncherSelectedScript() {
1305
    public ScriptingUnit getLauncherSelectedUnit() {
1304 1306
        JScriptingBrowser browser = this.getCurrentBrowser();
1305 1307
        ScriptingUnit unit = browser.getSelectedNode();
1306 1308
        return unit;
1307 1309
    }
1308 1310
    
1311
    public void msgbox(String title, String msg) {
1312
      msgbox(title, msg, JOptionPane.INFORMATION_MESSAGE);
1313
    }
1314
    
1315
    public void msgbox(final String title, final String msg, final int type) {
1316
      if( SwingUtilities.isEventDispatchThread() ) {
1317
        try {
1318
          SwingUtilities.invokeAndWait(() -> {
1319
            msgbox(title, msg, type);
1320
          });
1321
        } catch (Exception ex) {
1322
        }
1323
        return;
1324
      }
1325
      JOptionPane.showMessageDialog(this, msg, title, type);
1326
    }
1327
    
1309 1328
    private JScriptingBrowser getCurrentBrowser() {
1310 1329
        JScriptingLauncher launcher = this.getProjects();
1311 1330
        JScriptingBrowser browser = launcher.getSelectedBrowser();
......
1964 1983
            private boolean changed = false;
1965 1984
            private final Font fontNormal;
1966 1985
            private final Font fontBold;
1986
            private JPopupMenu popup;
1967 1987

  
1968 1988
            @SuppressWarnings("OverridableMethodCallInConstructor")
1969 1989
            public TabTitleComponent(String title, final ActionListener onclose) {
......
1997 2017
                this.setLayout(new BorderLayout());
1998 2018
                this.add(this.label, BorderLayout.CENTER);
1999 2019
                this.add(this.button, BorderLayout.EAST);
2020
                
2021
                this.popup = null;
2022
                this.label.addMouseListener(new MouseAdapter() {
2023
                  @Override
2024
                  public void mouseClicked(MouseEvent e) {
2025
                    if( e.isPopupTrigger() || e.getButton()==MouseEvent.BUTTON3) {
2026
                      if( popup!=null ) {
2027
                        popup.show(e.getComponent(), e.getX(), e.getY());
2028
                      }
2029
                    } else {
2030
                      int index = indexOfTabComponent(TabTitleComponent.this);
2031
                      setSelectedIndex(index);
2032
                    }
2033
                  }
2034
                });
2000 2035
            }
2001 2036

  
2002 2037
            public void setTitle(String title) {
......
2019 2054
            public boolean isChanged() {
2020 2055
                return this.changed;
2021 2056
            }
2057
            
2058
            @Override
2059
            public void setComponentPopupMenu(final JPopupMenu popup) {
2060
              // Asignarle un popup menu consume los eventos y no cambia de pesta?a.
2061
              // this.label.setComponentPopupMenu(popup);
2062
              this.popup = popup;
2063
            }
2022 2064
        }
2023 2065

  
2024 2066
        public JTabbedPaneClosable(ScriptingUIManager uimanager) {
......
2032 2074
            TabTitleComponent title = (TabTitleComponent) this.getTabComponentAt(index);
2033 2075
            if (title == null) {
2034 2076
                return null;
2035
            }
2077
            } 
2036 2078
            return title.getTitle();
2037 2079
        }
2038 2080

  
......
2045 2087
        @Override
2046 2088
        public void addTab(String title, java.awt.Component component) {
2047 2089
            super.addTab(null, component);
2048
            int index = getTabCount() - 1;
2090
            final int index = getTabCount() - 1;
2049 2091
            TabTitleComponent tabcomponent = new TabTitleComponent(title, new ActionListener() {
2050 2092

  
2051 2093
                @Override
......
2429 2471
            public void select() {
2430 2472
                DefaultDock.this.select(this.getId());
2431 2473
            }
2474

  
2475
            @Override
2476
            public void moveto(String position) {
2477
              switch(position) {
2478
                case Dock.DOCK_LEFT:
2479
                  add(this.getId(), this.getTitle(), this.getComponent(), Dock.DOCK_LEFT);
2480
                  break;
2481
                case Dock.DOCK_CENTER:
2482
                  add(this.getId(), this.getTitle(), this.getComponent(), Dock.DOCK_CENTER);
2483
                  break;
2484
                case Dock.DOCK_BOTTOM:
2485
                default:
2486
                  add(this.getId(), this.getTitle(), this.getComponent(), Dock.DOCK_BOTTOM);
2487
                  break;
2488
              }
2489
            }
2432 2490
        }
2433 2491

  
2434 2492
        private final Map<String, Dock.DockedPanel> panels;
......
2610 2668
            panel = new DefaultDockedPanel(id, title, component, align);
2611 2669
            this.panels.put(id, panel);
2612 2670
            tabbedPanel.add(panel.getTitle(), panel.getComponent().asJComponent());
2671
            JComponent tabComponent = (JComponent) tabbedPanel.getTabComponentAt(tabbedPanel.getTabCount()-1);
2672
            tabComponent.setComponentPopupMenu(this.createDefaultComponentPopupMenu(panel));
2613 2673
            return panel;
2614 2674
        }
2675
        
2676
        private JPopupMenu createDefaultComponentPopupMenu(DockedPanel panel) {
2677
          JPopupMenu menu = new JPopupMenu();
2678
          menu.add(createMenuItem("Move to left", (ActionEvent e) -> {
2679
            panel.moveto(Dock.DOCK_LEFT);
2680
          }));
2681
          menu.add(createMenuItem("Move to bottom", (ActionEvent e) -> {
2682
            panel.moveto(Dock.DOCK_BOTTOM);
2683
          }));
2684
          menu.add(createMenuItem("Move to center", (ActionEvent e) -> {
2685
            panel.moveto(Dock.DOCK_CENTER);
2686
          }));
2687
          return menu;
2688
        }
2689
        
2690
        private JMenuItem createMenuItem(String text, ActionListener listener) {
2691
          JMenuItem item = new JMenuItem(text);
2692
          item.addActionListener(listener);
2693
          return item;
2694
        }
2615 2695

  
2616 2696
        @Override
2617 2697
        public void remove(String id) {
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.api/src/main/java/org/gvsig/scripting/swing/api/JScriptingComposer.java
42 42
            public void setModified(boolean modified);
43 43
            public void remove();
44 44
            public void select();
45
            public void moveto(String position);
45 46
        }
46
        public DockedPanel add(String id, String title, Component compnent, String align);
47
        public DockedPanel add(String id, String title, Component compnent, String position);
47 48
        public void remove(String id);
48 49
        public DockedPanel get(String id);
49 50
        public void select(String id);
50
        public DockedPanel getSelected(String align);
51
        public DockedPanel getSelected(String position);
51 52
        public void setModified(DockedPanel panel, boolean modified);
52 53
        public boolean getModified(DockedPanel panel);
53 54
        public void addCloseListener(ActionListener listener);
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/pom.xml
277 277
                
278 278
        </dependency>
279 279
                
280
<!--        <dependency>
281
            <groupId>com.vladsch.flexmark</groupId>
282
            <artifactId>flexmark-all</artifactId>
283
            <version>0.60.2</version>
284
        </dependency>-->
280 285
        <dependency>
281 286
            <groupId>com.vladsch.flexmark</groupId>
282 287
            <artifactId>flexmark-all</artifactId>
283
            <version>0.27.0</version>
288
            <version>0.60.2</version>
289
            <scope>runtime</scope>
284 290
        </dependency>
291
        <dependency>
292
          <groupId>org.apache.pdfbox</groupId>
293
          <artifactId>pdfbox</artifactId>
294
          <version>2.0.16</version>
295
          <scope>runtime</scope>
296
        </dependency>
297
        <dependency>
298
          <groupId>org.apache.pdfbox</groupId>
299
          <artifactId>fontbox</artifactId>
300
          <version>2.0.16</version>
301
          <scope>runtime</scope>
302
        </dependency>
285 303

  
286 304
    </dependencies>
287 305

  
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
71 71
        <include>org.python:${jython.artifactId}</include>
72 72
        <include>com.github.tbekolay.jnumeric:jnumeric</include>
73 73
        
74
        <!--
75
        JRuby doesn't work by default on gvSIG, maybe the problems are
76
        related to the PluginClassLoader or to the way JRuby sets its
77
        internal classpath, so maybe setting the system property
78
        "org.jruby.embed.class.path" may solve the problem.
79
        See:
80
        http://kenai.com/projects/jruby/pages/RedBridge#Class_Path_%28Load_Path%29
81
        <include>org.jruby:jruby</include>
82
        -->
83

  
84
        <!--
85
            Scala doesn't work. When try to run a scala script show the message:
86
            Failed to initialize compiler: object scala in compiler mirror not found.
87
            ** Note that as of 2.8 scala does not assume use of the java classpath.
88
            ** For the old behavior pass -usejavacp to scala, or if using a Settings
89
            ** object programmatically, settings.usejavacp.value = true.
90
        
91
 
92
        <include>org.scala-lang:scala-dist</include>
93
        <include>org.scala-lang:scala-compiler</include>
94
        <include>org.scala-lang:scala-library</include>
95
        <include>org.scala-lang:scala-reflect</include>
96
        <include>org.scala-lang:scalap</include>
97
        -->
98
        <!--
99
        <include>jline:jline</include>
100
        -->
101

  
102 74
      </includes>
103 75
    </dependencySet>
104 76

  
......
137 109
      <outputDirectory>lib</outputDirectory>
138 110
      <includes>
139 111
        <!--
140
            flexmark-java, Markdown support libreries
112
            flexmark-java, Markdown support libraries
141 113
        -->        
142 114
        <include>com.vladsch.flexmark:flexmark-all</include>
143 115
        <include>com.vladsch.flexmark:flexmark</include>
144 116
        <include>com.vladsch.flexmark:flexmark-ext-abbreviation</include>
117
        <include>com.vladsch.flexmark:flexmark-util</include>
118
        <include>com.vladsch.flexmark:flexmark-ext-admonition</include>
145 119
        <include>com.vladsch.flexmark:flexmark-ext-anchorlink</include>
146 120
        <include>com.vladsch.flexmark:flexmark-ext-aside</include>
121
        <include>com.vladsch.flexmark:flexmark-ext-attributes</include>
147 122
        <include>com.vladsch.flexmark:flexmark-ext-autolink</include>
148 123
        <include>org.nibor.autolink:autolink</include>
149 124
        <include>com.vladsch.flexmark:flexmark-ext-definition</include>
150 125
        <include>com.vladsch.flexmark:flexmark-ext-emoji</include>
126
        <include>com.vladsch.flexmark:flexmark-ext-enumerated-reference</include>
151 127
        <include>com.vladsch.flexmark:flexmark-ext-escaped-character</include>
152 128
        <include>com.vladsch.flexmark:flexmark-ext-footnotes</include>
153 129
        <include>com.vladsch.flexmark:flexmark-ext-gfm-issues</include>
154 130
        <include>com.vladsch.flexmark:flexmark-ext-gfm-strikethrough</include>
155
        <include>com.vladsch.flexmark:flexmark-ext-gfm-tables</include>
156 131
        <include>com.vladsch.flexmark:flexmark-ext-gfm-tasklist</include>
157 132
        <include>com.vladsch.flexmark:flexmark-ext-gfm-users</include>
133
        <include>com.vladsch.flexmark:flexmark-ext-gitlab</include>
158 134
        <include>com.vladsch.flexmark:flexmark-ext-jekyll-front-matter</include>
159 135
        <include>com.vladsch.flexmark:flexmark-ext-jekyll-tag</include>
136
        <include>com.vladsch.flexmark:flexmark-ext-media-tags</include>
137
        <include>com.vladsch.flexmark:flexmark-ext-macros</include>
160 138
        <include>com.vladsch.flexmark:flexmark-ext-ins</include>
161 139
        <include>com.vladsch.flexmark:flexmark-ext-xwiki-macros</include>
162 140
        <include>com.vladsch.flexmark:flexmark-ext-superscript</include>
......
165 143
        <include>com.vladsch.flexmark:flexmark-ext-typographic</include>
166 144
        <include>com.vladsch.flexmark:flexmark-ext-wikilink</include>
167 145
        <include>com.vladsch.flexmark:flexmark-ext-yaml-front-matter</include>
168
        <include>com.vladsch.flexmark:flexmark-formatter</include>
169
        <include>com.vladsch.flexmark:flexmark-html-parser</include>
146
        <include>com.vladsch.flexmark:flexmark-ext-youtube-embedded</include>
147
        <include>com.vladsch.flexmark:flexmark-html2md-converter</include>
170 148
        <include>org.jsoup:jsoup</include>
171 149
        <include>com.vladsch.flexmark:flexmark-jira-converter</include>
172 150
        <include>com.vladsch.flexmark:flexmark-pdf-converter</include>
173 151
        <include>com.openhtmltopdf:openhtmltopdf-core</include>
174 152
        <include>com.openhtmltopdf:openhtmltopdf-pdfbox</include>
175
        <include>org.apache.pdfbox:pdfbox</include>
176
        <include>org.apache.pdfbox:fontbox</include>
153
        <include>org.apache.pdfbox:xmpbox</include>
154
        <include>de.rototor.pdfbox:graphics2d</include>
177 155
        <include>com.openhtmltopdf:openhtmltopdf-rtl-support</include>
178 156
        <include>com.ibm.icu:icu4j</include>
179 157
        <include>com.openhtmltopdf:openhtmltopdf-jsoup-dom-converter</include>
180 158
        <include>com.vladsch.flexmark:flexmark-profile-pegdown</include>
181
        <include>com.vladsch.flexmark:flexmark-util</include>
182
        <include>com.vladsch.flexmark:flexmark-youtrack-converter</include>        
159
        <include>com.vladsch.flexmark:flexmark-util-ast</include>
160
        <include>org.jetbrains:annotations</include>
161
        <include>com.vladsch.flexmark:flexmark-util-builder</include>
162
        <include>com.vladsch.flexmark:flexmark-util-collection</include>
163
        <include>com.vladsch.flexmark:flexmark-util-data</include>
164
        <include>com.vladsch.flexmark:flexmark-util-dependency</include>
165
        <include>com.vladsch.flexmark:flexmark-util-format</include>
166
        <include>com.vladsch.flexmark:flexmark-util-html</include>
167
        <include>com.vladsch.flexmark:flexmark-util-misc</include>
168
        <include>com.vladsch.flexmark:flexmark-util-options</include>
169
        <include>com.vladsch.flexmark:flexmark-util-sequence</include>
170
        <include>com.vladsch.flexmark:flexmark-util-visitor</include>
171
        <include>com.vladsch.flexmark:flexmark-youtrack-converter</include>
172
        <include>org.apache.pdfbox:pdfbox</include>
173
        <include>org.apache.pdfbox:fontbox</include>
174
        <include>commons-logging:commons-logging</include>
183 175
      </includes>
184 176
    </dependencySet>
185 177
    

Also available in: Unified diff