Revision 822

tmp/org.txm.setups/shared/debian/DEBIAN/control (revision 822)
4 4
Priority: optional
5 5
Architecture: all
6 6
Installed-Size: 250000
7
Depends: zenity, po-debconf, libwebkitgtk-1.0-0, debconf, libc6 (>= 2.15), libgtk2-perl, libblas3, libbz2-1.0, libcairo2, libgfortran3, libglib2.0-0, libgomp1, libjpeg8, liblapack3, liblzma5, libpango-1.0-0, libpangocairo-1.0-0, libpaper-utils, libpcre3, libpng12-0|libpng16, libreadline6, libtiff5, libx11-6, libxt6, tcl8.5, tk8.5, ucf, unzip, xdg-utils, zip, zlib1g
7
Depends: zenity, po-debconf, libwebkitgtk-1.0-0, debconf, libc6 (>= 2.15), libgtk2-perl, libblas3, libbz2-1.0, libcairo2, libgfortran3, libglib2.0-0, libgomp1, libjpeg8, liblapack3, liblzma5, libpango-1.0-0, libpangocairo-1.0-0, libpaper-utils, libpcre3, libpng12-0|libpng16-16, libreadline6|libreadline7, libtiff5, libx11-6, libxt6, tcl8.5, tk8.5, ucf, unzip, xdg-utils, zip, zlib1g
8 8
Maintainer: TXM team <textometrie@ens-lyon.fr>
9 9
Source: txm-src
10 10
License: GPL-2+
tmp/org.txm.progression.rcp/src/org/txm/progression/rcp/editors/ProgressionEditor.java (revision 822)
51 51
 */
52 52
public class ProgressionEditor extends ChartEditor<Progression> {
53 53

  
54

  
55 54
	/** The query widgets. */
56 55
	protected List<QueryField> queryWidgets = new ArrayList<QueryField>();
57 56

  
......
200 199
					if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
201 200
						if (queryWidget.getRawString().length() > 0 && onPlusButtonPressed(null, queryWidget.getRawString())) {
202 201
							super.keyPressed(e); // recompute only if the query has been added
202
							queryWidget.setText("");
203 203
						}
204 204
					}
205 205
				}
......
214 214
				public void widgetSelected(SelectionEvent e) {
215 215
					if (queryWidget.getRawString().length() > 0 && onPlusButtonPressed(null, queryWidget.getRawString())) {
216 216
						compute(true);
217
						queryWidget.setText("");
217 218
					}
218 219
				}
219 220
				
tmp/org.txm.information.rcp/src/org/txm/properties/rcp/editors/PropertiesEditor.java (revision 822)
1 1
package org.txm.properties.rcp.editors;
2 2

  
3 3
import java.io.File;
4
import java.net.MalformedURLException;
4 5

  
5 6
import org.eclipse.jface.layout.GridDataFactory;
6 7
import org.eclipse.swt.SWT;
......
133 134
	}
134 135

  
135 136
	@Override
136
	public void updateEditorFromResult(boolean update) {
137
	public void updateEditorFromResult(boolean update) throws Exception {
137 138
		File file = this.getResult().getHTMLFile();
138 139
		if (file.exists()) {
139
			this.browser.setUrl(file.getAbsolutePath());
140
			this.browser.setUrl(file.toURI().toURL().toString());
140 141
		}
141 142
		else	{
142 143
			Log.severe("Information HTML file doesn't exist."); //$NON-NLS-1$
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 822)
517 517
					this.syncExec(new Runnable() {
518 518
						@Override
519 519
						public void run() {
520
							refresh(update);
520
							try {
521
								refresh(update);
522
							} catch (Exception e) {
523
								System.out.println("Error while refreshing editor: "+e);
524
								Log.printStackTrace(e);
525
							}
521 526
						}
522 527
					});
523 528

  
......
590 595
	 * Synchronizes the editor with the result and refreshes the corpus view.
591 596
	 * Also fires a dirty property change.
592 597
	 * @param update
598
	 * @throws Exception 
593 599
	 */
594
	public final void refresh(boolean update)	{
600
	public final void refresh(boolean update) throws Exception {
595 601
		if (!createPartControlDoneSucessfully) return; // no refresh
596 602

  
597 603
		// FIXME: result should never be null?
......
640 646
	 * Dedicated to dynamically change the editor components from the stored result.
641 647
	 * <p>
642 648
	 * Use this method if you need to save parameter with Type not managed by the autoUpdateEditorFieldsFromResult method
649
	 * @throws Exception 
643 650
	 */
644
	public abstract void updateEditorFromResult(boolean update);
651
	public abstract void updateEditorFromResult(boolean update) throws Exception;
645 652

  
646 653

  
647 654

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/PropertiesComboViewer.java (revision 822)
64 64
	 * @param selectedProperty
65 65
	 * @param addBlankEntry
66 66
	 */
67
	public PropertiesComboViewer(Composite parent, TXMEditor editor, boolean autoCompute, List<? extends Property> properties, Property selectedProperty, boolean addBlankEntry) {
67
	public PropertiesComboViewer(Composite parent, TXMEditor<? extends TXMResult> editor, boolean autoCompute, List<? extends Property> properties, Property selectedProperty, boolean addBlankEntry) {
68 68
		this(parent, SWT.READ_ONLY, editor, autoCompute, properties, selectedProperty, addBlankEntry);
69 69
	}
70 70

  
......
88 88
			this.setSelection(new StructuredSelection(selectedProperty), true);
89 89
		}
90 90
	}
91

  
92
	
93
	
94 91
}
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/ExportCorpus.java (revision 822)
43 43
import org.eclipse.swt.widgets.Shell;
44 44
import org.eclipse.ui.handlers.HandlerUtil;
45 45
import org.txm.Toolbox;
46
import org.txm.core.preferences.TBXPreferences;
47 46
import org.txm.rcp.messages.TXMUIMessages;
48 47
import org.txm.rcp.swt.dialog.LastOpened;
49 48
import org.txm.rcp.utils.JobHandler;
50 49
import org.txm.searchengine.cqp.corpus.MainCorpus;
51 50

  
52
// TODO: Auto-generated Javadoc
53 51
/**
54
 * Call the function Information on a MainCorpus, a SubCorpus and a Partition
55
 * show basic stats and give some properties values @ author mdecorde.
52
 * Export a corpus to the .txm binary format (Zip)
56 53
 */
57 54
public class ExportCorpus extends AbstractHandler {
58 55

  
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/handlers/MergeLines.java (revision 822)
119 119

  
120 120
		LTeditor.refreshTable();
121 121
		lineTableViewer.getTable().deselectAll();
122
		LTeditor.refresh(false);
122
		try {
123
			LTeditor.refresh(false);
124
		} catch (Exception e) {
125
			// TODO Auto-generated catch block
126
			e.printStackTrace();
127
		}
123 128
		StatusLine.setMessage(""); //$NON-NLS-1$
124 129
	}
125 130
}
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/handlers/DeleteLines.java (revision 822)
91 91

  
92 92
		LTeditor.refreshTable();
93 93
		LTeditor.getlineTableViewer().getTable().deselectAll();
94
		LTeditor.refresh(false);
94
		try {
95
			LTeditor.refresh(false);
96
		} catch (Exception e) {
97
			// TODO Auto-generated catch block
98
			e.printStackTrace();
99
		}
95 100
	}
96 101

  
97 102
}
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RWorkspace.java (revision 822)
344 344
			isRServerOk = StartRserve.launchRserve(pathToRExecutable, port, debug, rargs, rServeArgs);
345 345
			// System.out.println("ap launchRserve");
346 346
			if (!isRServerOk) {
347
				System.out.println("Rserve not started with "+pathToRExecutable+". Trying with commons R installation paths (will works if Rserve, textometry and FactoMineR are installed).");
348
				isRServerOk = StartRserve.checkLocalRserve(port, debug, rargs, rServeArgs);
349
			}
350
			
351
			if (!isRServerOk) {
347 352
				throw new RWorkspaceException(RCoreMessages.bind(RCoreMessages.error_cantFindRServeInPath, pathToRExecutable));
348 353
			}
349 354
		}
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/StartRserve.java (revision 822)
224 224
			return true;
225 225
		}
226 226

  
227
		// R not in the PATH env, try with R common paths
227
		// R not in the PATH env, try with R common installation paths
228 228
		String[] paths = {
229
				"/usr/lib/TXM/R/bin/R", //$NON-NLS-1$
230
				"/Applications/TXM/R/bin/R", //$NON-NLS-1$
231 229
				"/Library/Frameworks/R.framework/Resources/bin/R", //$NON-NLS-1$
232 230
				"/usr/local/lib/R/bin/R", //$NON-NLS-1$
233 231
				"/usr/lib/R/bin/R", //$NON-NLS-1$
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/ZoneConcordancesMacro.groovy (revision 822)
1
// STANDARD DECLARATIONS
2
package org.txm.macroproto
3

  
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcpapplication.swt.widget.parameters.*
7
import org.txm.Toolbox
8
import org.txm.searchengine.cqp.corpus.*
9
import org.txm.searchengine.cqp.corpus.query.*
10
import org.apache.commons.lang.StringUtils
11

  
12
// BEGINNING OF PARAMETERS
13

  
14
if (!(corpusViewSelection instanceof Corpus)) {
15
	println "please select a corpus: $corpusViewSelection"
16
	return
17
}
18

  
19
def CQI = Toolbox.getCqiClient();
20

  
21
@Field @Option(name="query", usage="an example query", widget="Query", required=true, def='[pos="V.*"]')
22
def query
23

  
24
@Field @Option(name="property", usage="an example query", widget="String", required=true, def='word')
25
def property
26

  
27
@Field @Option(name="outputFile", usage="an example file", widget="FileSave", required=true, def="C:/Temp/foo.txt")
28
def outputFile
29

  
30
// Open the parameters input dialog box
31
if (!ParametersDialog.open(this)) return;
32

  
33
def writer = outputFile.newWriter("UTF-8")
34

  
35
// END OF PARAMETERS
36

  
37
String query_string = query.toString();
38
if (query_string.startsWith("@")) query_string = query_string.substring(1)
39

  
40
def split = query_string.split("@")
41
def queries = []
42
// @ A @ B @ C @ D
43
println "requête de zones: "+query_string
44
//println split
45
String current_q = ""
46
for (int i = 0 ; i < split.length ;i++) {
47
	def reconstructed_query = ""
48
	def q = split[i]
49
	
50
	//println "q=$q"
51
	
52
	//println "current_q=$current_q"
53
	
54
	if (i > 0 && q.length() > 0) {
55
		reconstructed_query = current_q+"@"+q
56
		if (i < (split.length-1)) reconstructed_query += split[i+1..split.length-1].join("")
57
		queries << reconstructed_query
58
	}
59
	
60
	current_q += q
61
	//println "Q="+current_q
62
}
63

  
64
if (queries.size() == 0) {
65
	println "no target @ found in query: $query"
66
	return
67
}
68

  
69
def corpus = corpusViewSelection
70
def wordProperty = corpus.getProperty(property)
71
def qrs = []
72
for (def q : queries) {
73
	qrs << corpus.query(new Query(q), "TMP", false).getMatches()
74
}
75
def qr = qrs[0]
76
println ""+qr.size()+" matches pour "+(queries.size()+1)+" zones"
77

  
78
writer.print "N\tposition\t"
79
for (int j = 0 ; j < queries.size()+1 ; j++) {
80
	writer.print "\t"
81
	writer.print "Z"+(j+1)
82
}
83
writer.println ""
84

  
85
for (int i = 0 ; i < qr.size() ; i++) {
86
	int[] positions = qr[i].getStart() .. qr[i].getEnd()
87
	def forms = CQI.cpos2Str(wordProperty.getQualifiedName(), positions)
88
	
89
	def targets = []
90
	for (int j = 0 ; j < queries.size() ; j++) {
91
		targets <<  (qrs[j][i]).getTarget()
92
	}
93
	
94
	writer.print ""+(i+1)+"\t"+positions[0]+"\t"
95
	boolean first = true
96
	for (int j = 0 ; j < forms.size() ; j++) {
97
		if (targets.contains(positions[j])) {
98
			writer.print "\t"
99
			first = true
100
		}
101
		
102
		if (!first) { writer.print " "}
103
		writer.print forms[j]
104
		first=false
105
	}
106
	writer.println ""
107
	
108
}
109

  
110
writer.close()
111
println "Result written in "+outputFile.getAbsolutePath()
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/ApplyXQueryMacro.groovy (revision 822)
1
// STANDARD DECLARATIONS
2
package org.txm.macroproto
3

  
4

  
5
import org.kohsuke.args4j.*
6
import groovy.transform.Field
7
import org.txm.rcpapplication.swt.widget.parameters.*
8
import org.txm.searchengine.cqp.corpus.*
9
import net.sf.saxon.*
10
import net.sf.saxon.query.*
11
import net.sf.saxon.om.*
12
import javax.xml.transform.*
13
import javax.xml.transform.sax.*
14
import javax.xml.transform.stream.*
15
import org.xml.sax.*
16
import javax.xml.xpath.*
17
import net.sf.saxon.event.*
18
import org.w3c.dom.*
19
import net.sf.saxon.s9api.*
20
import javax.xml.parsers.*
21

  
22
// BEGINNING OF PARAMETERS
23

  
24
if (!(corpusViewSelection instanceof Corpus)) {
25
	println "Error: Selection must be a corpus"
26
	return false;
27
}
28

  
29
@Field @Option(name="xqFile", usage="a Xquery file", widget="FileOpen", required=true, def="C:/Temp/foo.xq")
30
def xqFile
31
@Field @Option(name="outFile", usage="optional output file", widget="File", required=false, def="")
32
def outFile
33
@Field @Option(name="debug", usage="an example file", widget="Boolean", required=true, def="false")
34
def debug
35

  
36
// Open the parameters input dialog box
37
if (!ParametersDialog.open(this)) return;
38

  
39
// END OF PARAMETERS
40

  
41
println "corpora selection: "+corpusViewSelection
42
if (!xqFile.getName().endsWith(".xq")) {
43
	println "Error: Xquery selected file is not a '.xd' file: $xdFile"
44
	return false;
45
}
46

  
47
MainCorpus mainCorpus = ((Corpus)corpusViewSelection).getMainCorpus();
48
File binDir = mainCorpus.getBaseDirectory();
49
File txmDir = new File(binDir, "txm/"+mainCorpus.getName());
50

  
51
if (!txmDir.exists()) {
52
	println "Error: the 'txm' directory does not exist: $txmDir"
53
	return false;
54
}
55

  
56
def xmlFiles = txmDir.listFiles();
57
if (xmlFiles == null || xmlFiles.size() == 0) {
58
	println "Error: no file found in $txmDir"
59
	return false;
60
}
61

  
62
String query = """<matches>
63
  { 
64
    for \$t in fn:collection('$txmDir')
65
      for \$w in \$t//tei:w
66
        let \$pos := \$w/txm:ana[@type="#frpos"]/text()
67
        return <match>{\$w/@id}</match>
68
  }
69
</matches>
70
"""
71

  
72
Processor processor = new Processor(false)
73
XQueryCompiler xqc = processor.newXQueryCompiler()
74
xqc.declareNamespace("tei", "http://www.tei-c.org/ns/1.0")
75
xqc.declareNamespace("txm", "http://textometrie.org/1.0")
76
xqc.declareNamespace("fn", "http://www.w3.org/2005/xpath-functions")
77
XQueryExecutable exp = xqc.compile(query)
78

  
79
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
80
dfactory.setNamespaceAware(true);
81
Document dom = dfactory.newDocumentBuilder().newDocument();
82
exp.load().run(new DOMDestination(dom));
83
if (outFile instanceof File && outFile.getName().length() > 0) {
84
	def writer = outFile.newWriter("UTF-8")
85
	writer.println dom.getDocumentElement()
86
	writer.close()
87
	println "Result written in "+outFile.getAbsolutePath()
88
} else {
89
	println dom.getDocumentElement()
90
}
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/cqp/ListMatchesMacro.groovy (revision 822)
1
// STANDARD DECLARATIONS
2
package org.txm.macroproto.cqp
3

  
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcpapplication.swt.widget.parameters.*
7
import org.txm.Toolbox
8
import org.txm.searchengine.cqp.*
9
import org.txm.searchengine.cqp.corpus.*
10
import org.txm.utils.*
11

  
12
if (!(corpusViewSelection instanceof Corpus)) {
13
	println "Selection is not a Corpus: $corpusViewSelection"
14
	return false
15
}
16

  
17
println corpusViewSelection.getMatches()
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/cqp/ListSubcorpusMacro.groovy (revision 822)
1
// STANDARD DECLARATIONS
2
package org.txm.macroproto.cqp
3

  
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcpapplication.swt.widget.parameters.*
7
import org.txm.Toolbox
8
import org.txm.searchengine.cqp.*
9
import org.txm.searchengine.cqp.corpus.*
10
import org.txm.utils.*
11

  
12
if (!(corpusViewSelection instanceof Corpus)) {
13
	println "Selection is not a Corpus: $corpusViewSelection"
14
	return false
15
}
16

  
17
def CQI = Toolbox.getCqiClient();
18
if ((CQI instanceof NetCqiClient)) {
19
	println "Error: only available in CQP memory mode"
20
	return;
21
}
22

  
23
@Field @Option(name="subcorpusname", usage="an example file", widget="String", required=true, def="A")
24
def subcorpusname
25
@Field @Option(name="inputFile", usage="an example file", widget="FileOpen", required=true, def="C:/Temp/foo.txt")
26
def inputFile
27
@Field @Option(name="replace", usage="an example file", widget="Boolean", required=true, def="true")
28
def replace
29

  
30
// Open the parameters input dialog box
31
if (!ParametersDialog.open(this)) return;
32

  
33
// END OF PARAMETERS
34

  
35
println "corpora selection: "+corpusViewSelection
36

  
37
MainCorpus maincorpus = corpusViewSelection.getMainCorpus()
38
def existing = CQI.listSubcorpora(maincorpus.getQualifiedCqpId())
39
println existing
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/cqp/SaveSubCorpusMacro.groovy (revision 822)
1
// STANDARD DECLARATIONS
2
package org.txm.macroproto.cqp
3

  
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcpapplication.swt.widget.parameters.*
7
import org.txm.Toolbox
8
import org.txm.searchengine.cqp.*
9
import org.txm.searchengine.cqp.corpus.*
10
import org.txm.utils.*
11

  
12
if (!(corpusViewSelection instanceof Subcorpus)) {
13
	println "Selection is not a Corpus: $corpusViewSelection"
14
	return false
15
}
16

  
17
def CQI = Toolbox.getCqiClient();
18
if ((CQI instanceof NetCqiClient)) {
19
	println "Error: only available in CQP memory mode"
20
	return;
21
}
22

  
23
@Field @Option(name="outputDir", usage="an example file", widget="Folder", required=true, def="")
24
def outputDir
25

  
26
// Open the parameters input dialog box
27
if (!ParametersDialog.open(this)) return;
28

  
29
// END OF PARAMETERS
30

  
31
println "corpora selection: "+corpusViewSelection
32

  
33
MainCorpus maincorpus = corpusViewSelection.getMainCorpus()
34
File outputFile = new File(outputDir, corpusViewSelection.getQualifiedCqpId())
35
File regFile = new File(maincorpus.getBaseDirectory(), "registry")
36
if (!regFile.exists()) {
37
	println "Could not find corpus registry file $regFile"
38
	return
39
}
40

  
41
def outputStream = new FileOutputStream(outputFile);
42
LittleEndianOutputStream outputStreamBin = new LittleEndianOutputStream(outputStream);
43

  
44
outputStreamBin.writeInt(36193928+1);
45
outputStreamBin.writeBytes(regFile.getAbsolutePath()+"/");
46
outputStreamBin.write(0)
47
outputStreamBin.writeBytes(maincorpus.getName());
48
//outputStreamBin.write(0)
49
l2 = outputStreamBin.size()-3
50

  
51
//for (int i = 0; (i+l2)%4 != 0; i++) 
52
outputStreamBin.writeInt(0);
53

  
54
def matches = corpusViewSelection.getMatches()
55
outputStreamBin.writeInt(matches.size())
56

  
57
for (def match : matches) {
58
	outputStreamBin.writeInt(match.getStart());
59
	outputStreamBin.writeInt(match.getEnd());
60
}
61

  
62
outputStreamBin.writeInt(0) // sortidx
63
outputStreamBin.writeInt(0) // targets
64
outputStreamBin.writeInt(0) // keywords
65
outputStreamBin.close()
66

  
67
println "Subcorpus saved in "+outputFile.getAbsolutePath()
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/cqp/LittleEndianOutputStream.groovy (revision 822)
1
/*
2
 * @(#)LittleEndianOutputStream.java  1.0.1 99/05/19
3
 * 
4
 * Copyright 1998, 1999 Elliotte Rusty Harold
5
 *  
6
 */
7

  
8
package org.txm.macroproto.cqp;
9

  
10
/**
11
 * A little endian output stream writes primitive Java numbers 
12
 * and characters to an output stream in a little endian format. 
13
 * The standard java.io.DataOutputStream class which this class
14
 * imitates uses big-endian integers.
15
 *
16
 * @author  Elliotte Rusty Harold
17
 * @version 1.0.1, 19 May 1999
18
 * @see     com.macfaq.io.LittleEndianInputStream
19
 * @see     java.io.DataOutputStream
20
 */
21
public class LittleEndianOutputStream extends FilterOutputStream {
22

  
23
  /**
24
   * The number of bytes written so far to the little endian output stream. 
25
   */
26
  protected int written;
27

  
28
  /**
29
   * Creates a new little endian output stream and chains it to the  
30
   * output stream specified by the out argument. 
31
   *
32
   * @param   out   the underlying output stream.
33
   * @see     java.io.FilterOutputStream#out
34
   */
35
  public LittleEndianOutputStream(OutputStream out) {
36
    super(out);
37
  }
38

  
39
  /**
40
   * Writes the specified byte value to the underlying output stream. 
41
   *
42
   * @param      b   the <code>byte</code> value to be written.
43
   * @exception  IOException  if the underlying stream throws an IOException.
44
   */
45
  public synchronized void write(int b) throws IOException {
46
    out.write(b);
47
    written++;
48
  }
49

  
50
  /**
51
   * Writes <code>length</code> bytes from the specified byte array 
52
   * starting at <code>offset</code> to the underlying output stream.
53
   *
54
   * @param      data     the data.
55
   * @param      offset   the start offset in the data.
56
   * @param      length   the number of bytes to write.
57
   * @exception  IOException  if the underlying stream throws an IOException.
58
   */
59
  public synchronized void write(byte[] data, int offset, int length) 
60
   throws IOException {
61
    out.write(data, offset, length);
62
    written += length;
63
  }
64

  
65

  
66
  /**
67
   * Writes a <code>boolean</code> to the underlying output stream as 
68
   * a single byte. If the argument is true, the byte value 1 is written.
69
   * If the argument is false, the byte value <code>0</code> in written.
70
   *
71
   * @param      b   the <code>boolean</code> value to be written.
72
   * @exception  IOException  if the underlying stream throws an IOException.
73
   */
74
  public void writeBoolean(boolean b) throws IOException {
75
  
76
    if (b) this.write(1);
77
    else this.write(0);
78

  
79
  }
80

  
81
  /**
82
   * Writes out a <code>byte</code> to the underlying output stream
83
   *
84
   * @param      b   the <code>byte</code> value to be written.
85
   * @exception  IOException  if the underlying stream throws an IOException.
86
   */
87
  public void writeByte(int b) throws IOException {
88
    out.write(b);
89
    written++;
90
  }
91

  
92
  /**
93
   * Writes a two byte <code>short</code> to the underlying output stream in
94
   * little endian order, low byte first. 
95
   *
96
   * @param      s   the <code>short</code> to be written.
97
   * @exception  IOException  if the underlying stream throws an IOException.
98
   */
99
  public void writeShort(int s) throws IOException {
100

  
101
    out.write(s & 0xFF);
102
    out.write((s >>> 8) & 0xFF);
103
    written += 2;
104
    
105
  }
106

  
107
  /**
108
   * Writes a two byte <code>char</code> to the underlying output stream 
109
   * in little endian order, low byte first. 
110
   *
111
   * @param      c   the <code>char</code> value to be written.
112
   * @exception  IOException  if the underlying stream throws an IOException.
113
   */
114
  public void writeChar(int c) throws IOException {
115

  
116
    out.write(c & 0xFF);
117
    out.write((c >>> 8) & 0xFF);
118
    written += 2;
119
    
120
  }
121

  
122
  /**
123
   * Writes a four-byte <code>int</code> to the underlying output stream 
124
   * in little endian order, low byte first, high byte last
125
   *
126
   * @param      i   the <code>int</code> to be written.
127
   * @exception  IOException  if the underlying stream throws an IOException.
128
   */
129
  public void writeInt(int i) throws IOException {
130

  
131
    out.write(i & 0xFF);
132
    out.write((i >>> 8) & 0xFF);
133
    out.write((i >>> 16) & 0xFF);
134
    out.write((i >>> 24) & 0xFF);
135
    written += 4;
136
    
137
  }
138

  
139
  /**
140
   * Writes an eight-byte <code>long</code> to the underlying output stream 
141
   * in little endian order, low byte first, high byte last
142
   *
143
   * @param      l   the <code>long</code> to be written.
144
   * @exception  IOException  if the underlying stream throws an IOException.
145
   */
146
  public void writeLong(long l) throws IOException {
147

  
148
    out.write((int) l & 0xFF);
149
    out.write((int) (l >>> 8) & 0xFF);
150
    out.write((int) (l >>> 16) & 0xFF);
151
    out.write((int) (l >>> 24) & 0xFF);
152
    out.write((int) (l >>> 32) & 0xFF);
153
    out.write((int) (l >>> 40) & 0xFF);
154
    out.write((int) (l >>> 48) & 0xFF);
155
    out.write((int) (l >>> 56) & 0xFF);
156
    written += 8;
157

  
158
  }
159

  
160
 /**
161
  * Writes a 4 byte Java float to the underlying output stream in
162
  * little endian order.
163
  *
164
  * @param      f   the <code>float</code> value to be written.
165
  * @exception  IOException  if an I/O error occurs.
166
  */
167
  public final void writeFloat(float f) throws IOException {
168
  
169
    this.writeInt(Float.floatToIntBits(f));
170
    
171
  }
172

  
173
 /**
174
  * Writes an 8 byte Java double to the underlying output stream in
175
  * little endian order.
176
  *
177
  * @param      d   the <code>double</code> value to be written.
178
  * @exception  IOException  if an I/O error occurs.
179
  */
180
  public final void writeDouble(double d) throws IOException {
181
  
182
    this.writeLong(Double.doubleToLongBits(d));
183
    
184
  }
185

  
186
  /**
187
   * Writes a string to the underlying output stream as a sequence of 
188
   * bytes. Each character is written to the data output stream as 
189
   * if by the <code>writeByte()</code> method. 
190
   *
191
   * @param      s   the <code>String</code> value to be written.
192
   * @exception  IOException  if the underlying stream throws an IOException.
193
   * @see        java.io.LittleEndianOutputStream#writeByte(int)
194
   * @see        java.io.LittleEndianOutputStream#out
195
   */
196
  public void writeBytes(String s) throws IOException {
197

  
198
    int length = s.length();
199
    for (int i = 0; i < length; i++) {
200
      out.write((byte) s.charAt(i));
201
    }
202
    written += length;
203
    }
204

  
205
  /**
206
   * Writes a string to the underlying output stream as a sequence of 
207
   * characters. Each character is written to the data output stream as 
208
   * if by the <code>writeChar</code> method. 
209
   *
210
   * @param      s   a <code>String</code> value to be written.
211
   * @exception  IOException  if the underlying stream throws an IOException.
212
   * @see        java.io.LittleEndianOutputStream#writeChar(int)
213
   * @see        java.io.LittleEndianOutputStream#out
214
   */
215
  public void writeChars(String s) throws IOException {
216

  
217
    int length = s.length();
218
    for (int i = 0; i < length; i++) {
219
      int c = s.charAt(i);
220
      out.write(c & 0xFF);
221
      out.write((c >>> 8) & 0xFF);
222
    }
223
    written += length * 2;
224
    
225
  }
226

  
227
  /**
228
   * Writes a string of no more than 65,535 characters 
229
   * to the underlying output stream using UTF-8 
230
   * encoding. This method first writes a two byte short 
231
   * in <b>big</b> endian order as required by the 
232
   * UTF-8 specification. This gives the number of bytes in the 
233
   * UTF-8 encoded version of the string, not the number of characters
234
   * in the string. Next each character of the string is written
235
   * using the UTF-8 encoding for the character.
236
   *
237
   * @param      s   the string to be written.
238
   * @exception  UTFDataFormatException if the string is longer than 
239
   *             65,535 characters.
240
   * @exception  IOException  if the underlying stream throws an IOException.
241
   */
242
  public void writeUTF(String s) throws IOException {
243

  
244
    int numchars = s.length();
245
    int numbytes = 0;
246

  
247
    for (int i = 0 ; i < numchars ; i++) {
248
      int c = s.charAt(i);
249
      if ((c >= 0x0001) && (c <= 0x007F)) numbytes++;
250
      else if (c > 0x07FF) numbytes += 3;
251
      else numbytes += 2;
252
    }
253

  
254
    if (numbytes > 65535) throw new UTFDataFormatException();     
255

  
256
    out.write((numbytes >>> 8) & 0xFF);
257
    out.write(numbytes & 0xFF);
258
    for (int i = 0 ; i < numchars ; i++) {
259
      int c = s.charAt(i);
260
      if ((c >= 0x0001) && (c <= 0x007F)) {
261
        out.write(c);
262
      }
263
      else if (c > 0x07FF) {
264
        out.write(0xE0 | ((c >> 12) & 0x0F));
265
        out.write(0x80 | ((c >>  6) & 0x3F));
266
        out.write(0x80 | (c & 0x3F));
267
        written += 2;
268
      } 
269
      else {
270
        out.write(0xC0 | ((c >>  6) & 0x1F));
271
        out.write(0x80 | (c & 0x3F));
272
        written += 1;
273
      }
274
    }
275
    
276
    written += numchars + 2;
277
    
278
  }
279

  
280
  /**
281
   * Returns the number of bytes written to this little endian output stream.
282
   * (This class is not thread-safe with respect to this method. It is 
283
   * possible that this number is temporarily less than the actual 
284
   * number of bytes written.)
285
   * @return  the value of the <code>written</code> field.
286
   * @see     java.io.LittleEndianOutputStream#written
287
   */
288
  public int size() {
289
    return this.written;
290
  }
291
  
292
}
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/PlotEllipsesMacro.groovy (revision 822)
1
// STANDARD DECLARATIONS
2
package org.txm.macroproto
3

  
4
import org.kohsuke.args4j.*
5

  
6
import groovy.transform.Field
7

  
8
import org.txm.ca.core.functions.CA
9
import org.txm.rcpapplication.swt.widget.parameters.*
10
import org.txm.statsengine.r.core.RWorkspace
11

  
12
// BEGINNING OF PARAMETERS
13

  
14
if (!(corpusViewSelection instanceof CA)) {
15
	println "Selection is not a CA. Please select a CA result in the Corpus view"
16
	return;
17
}
18

  
19
@Field @Option(name="outputFile", usage="an example file", widget="FileSave", required=true, def="file.svg")
20
def outputFile
21

  
22
@Field @Option(name="draw", usage="'row' or 'col'", widget="String", required=true, def="row")
23
def draw
24
// Open the parameters input dialog box
25
if (!ParametersDialog.open(this)) return;
26

  
27
// END OF PARAMETERS
28
def ca = corpusViewSelection
29
def s = ca.getSymbol()
30
def RW = RWorkspace.getRWorkspaceInstance()
31

  
32
def script = """
33
plot($s);
34
ellipseCA($s, ellipse=c("$draw"));
35
"""
36

  
37
RW.plot(outputFile, script);
38

  
39
println "Done: "+outputFile.getAbsolutePath()

Also available in: Unified diff