r4205 - in trunk: . src/main/java/fr/ifremer/isisfish/logging src/main/java/fr/ifremer/isisfish/logging/console src/main/java/fr/ifremer/isisfish/logging/io src/main/java/fr/ifremer/isisfish/ui/logging src/main/java/fr/ifremer/isisfish/ui/queue src/main/java/fr/ifremer/isisfish/ui/result src/main/java/fr/ifremer/isisfish/ui/widget src/main/java/fr/ifremer/isisfish/ui/widget/text src/main/resources/i18n
Author: echatellier Date: 2015-04-22 15:09:18 +0000 (Wed, 22 Apr 2015) New Revision: 4205 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4205 Log: Improve log console (broken offset with accent) Added: trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/package-info.java Modified: trunk/pom.xml trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsole.java trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsoleHandler.java trunk/src/main/java/fr/ifremer/isisfish/logging/io/OffsetReader.java trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java trunk/src/main/resources/i18n/isis-fish_en_GB.properties trunk/src/main/resources/i18n/isis-fish_fr_FR.properties Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/pom.xml 2015-04-22 15:09:18 UTC (rev 4205) @@ -115,6 +115,12 @@ <version>2.5.0</version> <scope>compile</scope> </dependency> + + <dependency> + <groupId>com.fifesoft</groupId> + <artifactId>rstaui</artifactId> + <version>2.5.0</version> + </dependency> <dependency> <groupId>javax.mail</groupId> Modified: trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/java/fr/ifremer/isisfish/logging/SimulationLoggerUtil.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -27,6 +27,7 @@ import static org.nuiton.i18n.I18n.t; +import java.awt.Component; import java.io.File; import java.io.IOException; @@ -54,9 +55,6 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(SimulationLoggerUtil.class); - /** pattern to use for simulation appender */ - public static final String LOG_PATTERN = "%p|%d{ABSOLUTE}|%F|%L|%M|%m%n"; - /** * Open a new log console for the given simulation * @@ -64,7 +62,7 @@ * @throws IOException * @throws IllegalArgumentException */ - public static void showSimulationLogConsole(String simulationName) throws IllegalArgumentException, IOException { + public static void showSimulationLogConsole(Component parent, String simulationName) throws IllegalArgumentException, IOException { SimulationStorage storage; storage = SimulationStorage.getSimulation(simulationName); @@ -76,7 +74,9 @@ String title = t("isisfish.simulation.log.console.title", simulationName); - LogConsole.newConsole(logFile, smtpServer, defaultFrom, null, title); + LogConsole ui = LogConsole.newConsole(logFile, smtpServer, defaultFrom, null, title); + ui.setLocationRelativeTo(parent); + ui.setVisible(true); if (log.isInfoEnabled()) { log.info(t("isisfish.simulation.log.showConsole", simulationName)); Modified: trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsole.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsole.java 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsole.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -120,9 +120,6 @@ // create ui ui = new LogConsole(handler, title); - // launchUI ui - ui.setVisible(true); - // notify the model to adjust the nbLinesInEditor ui.firePropertyChange(EDITOR_SIZE_CHANGED_PROPERTY, null, ui.getContent()); @@ -263,7 +260,7 @@ sendMail.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - handler.openLogMail(); + handler.openLogMail(LogConsole.this); } }); } Modified: trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsoleHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsoleHandler.java 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/java/fr/ifremer/isisfish/logging/console/LogConsoleHandler.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -429,7 +429,7 @@ propertyListeners.removePropertyChangeListener(propertyName, listener); } - public void openLogMail() { + public void openLogMail(LogConsole parent) { if (logMail==null) { logMail = new LogMail( model.getFrom(), @@ -437,6 +437,7 @@ model.getLogFile().getParentFile(), model.getSmtpServer()); } + logMail.setLocationRelativeTo(parent); logMail.setVisible(true); } } Modified: trunk/src/main/java/fr/ifremer/isisfish/logging/io/OffsetReader.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/logging/io/OffsetReader.java 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/java/fr/ifremer/isisfish/logging/io/OffsetReader.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -29,6 +29,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.RandomAccessFile; +import java.nio.charset.StandardCharsets; import java.util.regex.Pattern; /** @@ -128,7 +129,7 @@ storeOffset(nbLines + nbNewLines, offset); } - int lineSize = line.length(); + int lineSize = line.getBytes(StandardCharsets.UTF_8).length; offset += lineSize; // must find how many cars after the last car of the line @@ -201,7 +202,7 @@ long offset = 0; String line; while (!(line = readLine(reader)).isEmpty()) { - int lineSize = line.length(); + int lineSize = line.getBytes(StandardCharsets.UTF_8).length; if (lineReader.match(line)) { storeOffset(nbLines, offset); nbLines++; @@ -214,7 +215,7 @@ return nbLines; } - protected long createOffsetsForLog(LineReader lineReader) throws IOException { + /*protected long createOffsetsForLog(LineReader lineReader) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(lineReader.getFile())); long nbLines = 0; @@ -251,7 +252,7 @@ reader.close(); } return nbLines; - } + }*/ protected long createOffsets(LineReader lineReader, LineReader parent) throws IOException { long nbLines = 0; Added: trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -0,0 +1,68 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.logging; + +import static org.nuiton.i18n.I18n.t; + +import java.io.File; +import java.io.IOException; + +import javax.swing.JFrame; + +import org.apache.commons.io.FileUtils; + +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.ui.widget.text.IsisSyntaxContants; +import fr.ifremer.isisfish.ui.widget.text.IsisSyntaxEditor; + +/** + * Standalone frame to display log file with syntax highlight. + * + * @author Eric Chatellier + */ +public class LoggingFrame extends JFrame { + + /** serialVersionUID. */ + private static final long serialVersionUID = -655585012872692567L; + + protected IsisSyntaxEditor editor; + + public LoggingFrame() { + editor = new IsisSyntaxEditor(); + editor.setStyle(IsisSyntaxContants.SYNTAX_STYLE_LOG); + + add(editor); + + setJMenuBar(editor.createMenuBar(this)); + setSize(800, 600); + } + + public void loadSimulationLog(String simulationName) throws IOException { + setTitle(t("isisfish.simulation.log.console.title", simulationName)); + + SimulationStorage storage = SimulationStorage.getSimulation(simulationName); + File logFile = new File(storage.getSimulationLogFile()); + String content = FileUtils.readFileToString(logFile); + editor.setText(content); + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -126,7 +126,7 @@ String id = selectedJob.getItem().getControl().getId(); try { - SimulationLoggerUtil.showSimulationLogConsole(id); + SimulationLoggerUtil.showSimulationLogConsole(queueUI, id); } catch (Exception eee) { if (log.isErrorEnabled()) { log.error(t("Can't open log for %s", id), eee); Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -161,7 +161,7 @@ public void showLog(ResultUI resultUI) { String selected = (String)resultUI.getSimulationComboBox().getSelectedItem(); try { - SimulationLoggerUtil.showSimulationLogConsole(selected); + SimulationLoggerUtil.showSimulationLogConsole(resultUI, selected); } catch (Exception ex) { throw new IsisFishRuntimeException("Can't display simulation log", ex); } Added: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -0,0 +1,36 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.widget.text; + +import org.fife.ui.rsyntaxtextarea.SyntaxConstants; + +/** + * Extends rsyntaxtextarea contantx to add isis specific. + * + * @author Eric Chatellier + */ +public interface IsisSyntaxContants extends SyntaxConstants { + + public static final String SYNTAX_STYLE_LOG = "isisfish-log"; + +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -0,0 +1,221 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.widget.text; + +import static org.nuiton.i18n.I18n.t; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; + +import javax.swing.AbstractAction; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import javax.swing.UIManager; +import javax.swing.text.BadLocationException; + +import org.fife.rsta.ui.GoToDialog; +import org.fife.rsta.ui.search.FindDialog; +import org.fife.rsta.ui.search.ReplaceDialog; +import org.fife.rsta.ui.search.SearchDialogSearchContext; +import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; +import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; +import org.fife.ui.rsyntaxtextarea.SyntaxScheme; +import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rtextarea.RTextScrollPane; +import org.fife.ui.rtextarea.SearchEngine; + +/** + * {@link RSyntaxTextArea} component property configured for isis fish. + * + * @author Eric Chatellier + */ +public class IsisSyntaxEditor extends JPanel implements ActionListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1427883892685276516L; + + protected RSyntaxTextArea textArea; + private FindDialog findDialog; + private ReplaceDialog replaceDialog; + + public IsisSyntaxEditor() { + super(new BorderLayout()); + textArea = new RSyntaxTextArea(); + add(new RTextScrollPane(textArea), BorderLayout.CENTER); + setAutoscrolls(false); + } + + /** + * Set highligth style. + * + * @param style new style + * @see IsisSyntaxContants + */ + public void setStyle(String style) { + RSyntaxDocument doc = new RSyntaxDocument(new IsisTokenManagerFactory(), style); + textArea.setDocument(doc); + + // special theme for log + if (IsisSyntaxContants.SYNTAX_STYLE_LOG.equals(style)) { + SyntaxScheme scheme = textArea.getSyntaxScheme(); + scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.RED; + } + } + + public void setText(String text) { + textArea.setText(text); + textArea.invalidate(); + } + + /** + * Return menu bar configured for {@code textArea} component. + * + * @param parent parent + * @return JMenuBar instance + */ + public JMenuBar createMenuBar(Frame parent) { + JMenuBar mb = new JMenuBar(); + JMenu menu = new JMenu(t("isisfish.script.search")); + menu.add(new JMenuItem(new ShowFindDialogAction())); + menu.add(new JMenuItem(new ShowReplaceDialogAction())); + menu.add(new JMenuItem(new GoToLineAction(parent))); + mb.add(menu); + + initSearchDialogs(parent); + + return mb; + } + + /** + * Creates our Find and Replace dialogs. + */ + protected void initSearchDialogs(Frame parent) { + + findDialog = new FindDialog(parent, this); + replaceDialog = new ReplaceDialog(parent, this); + + // This ties the properties of the two dialogs together (match + // case, regex, etc.). + replaceDialog.setSearchContext(findDialog.getSearchContext()); + + } + + private class GoToLineAction extends AbstractAction { + protected Frame parent; + public GoToLineAction(Frame parent) { + super(t("isisfish.script.gotoline")); + this.parent = parent; + int c = getToolkit().getMenuShortcutKeyMask(); + putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, c)); + } + + public void actionPerformed(ActionEvent e) { + if (findDialog.isVisible()) { + findDialog.setVisible(false); + } + if (replaceDialog.isVisible()) { + replaceDialog.setVisible(false); + } + GoToDialog dialog = new GoToDialog(this.parent); + dialog.setMaxLineNumberAllowed(textArea.getLineCount()); + dialog.setVisible(true); + int line = dialog.getLineNumber(); + if (line>0) { + try { + textArea.setCaretPosition(textArea.getLineStartOffset(line-1)); + } catch (BadLocationException ble) { // Never happens + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + ble.printStackTrace(); + } + } + } + + } + + private class ShowFindDialogAction extends AbstractAction { + + public ShowFindDialogAction() { + super(t("isisfish.script.find")); + int c = getToolkit().getMenuShortcutKeyMask(); + putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, c)); + } + + public void actionPerformed(ActionEvent e) { + if (replaceDialog.isVisible()) { + replaceDialog.setVisible(false); + } + findDialog.setVisible(true); + } + + } + + private class ShowReplaceDialogAction extends AbstractAction { + + public ShowReplaceDialogAction() { + super(t("isisfish.script.replace")); + int c = getToolkit().getMenuShortcutKeyMask(); + putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, c)); + } + + public void actionPerformed(ActionEvent e) { + if (findDialog.isVisible()) { + findDialog.setVisible(false); + } + replaceDialog.setVisible(true); + } + + } + + /** + * Listens for events from our search dialogs and actually does the dirty + * work. + */ + public void actionPerformed(ActionEvent e) { + + String command = e.getActionCommand(); + SearchDialogSearchContext context = findDialog.getSearchContext(); + + if (FindDialog.ACTION_FIND.equals(command)) { + if (!SearchEngine.find(textArea, context)) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + } + } else if (ReplaceDialog.ACTION_REPLACE.equals(command)) { + if (!SearchEngine.replace(textArea, context)) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + } + } else if (ReplaceDialog.ACTION_REPLACE_ALL.equals(command)) { + int count = SearchEngine.replaceAll(textArea, context); + JOptionPane.showMessageDialog(null, count + + " occurrences replaced."); + } + + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -0,0 +1,60 @@ +package fr.ifremer.isisfish.ui.widget.text; + +import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; + +/** + * Extends rsyntaxtextarea factory to add Isis fish specific style. + * + * @author Eric Chatellier + */ +public class IsisTokenManagerFactory extends AbstractTokenMakerFactory implements IsisSyntaxContants { + + @Override + protected void initTokenMakerMap() { + // isis support for log + putMapping(SYNTAX_STYLE_LOG, IsisTokenMarker.class.getName()); + + // default code + String pkg = "org.fife.ui.rsyntaxtextarea.modes."; + + putMapping(SYNTAX_STYLE_NONE, pkg + "PlainTextTokenMaker"); + putMapping(SYNTAX_STYLE_ACTIONSCRIPT, pkg + "ActionScriptTokenMaker"); + putMapping(SYNTAX_STYLE_ASSEMBLER_X86, pkg + "AssemblerX86TokenMaker"); + putMapping(SYNTAX_STYLE_BBCODE, pkg + "BBCodeTokenMaker"); + putMapping(SYNTAX_STYLE_C, pkg + "CTokenMaker"); + putMapping(SYNTAX_STYLE_CLOJURE, pkg + "ClojureTokenMaker"); + putMapping(SYNTAX_STYLE_CPLUSPLUS, pkg + "CPlusPlusTokenMaker"); + putMapping(SYNTAX_STYLE_CSHARP, pkg + "CSharpTokenMaker"); + putMapping(SYNTAX_STYLE_CSS, pkg + "CSSTokenMaker"); + putMapping(SYNTAX_STYLE_DELPHI, pkg + "DelphiTokenMaker"); + putMapping(SYNTAX_STYLE_DTD, pkg + "DtdTokenMaker"); + putMapping(SYNTAX_STYLE_FORTRAN, pkg + "FortranTokenMaker"); + putMapping(SYNTAX_STYLE_GROOVY, pkg + "GroovyTokenMaker"); + putMapping(SYNTAX_STYLE_HTACCESS, pkg + "HtaccessTokenMaker"); + putMapping(SYNTAX_STYLE_HTML, pkg + "HTMLTokenMaker"); + putMapping(SYNTAX_STYLE_JAVA, pkg + "JavaTokenMaker"); + putMapping(SYNTAX_STYLE_JAVASCRIPT, pkg + "JavaScriptTokenMaker"); + putMapping(SYNTAX_STYLE_JSON, pkg + "JsonTokenMaker"); + putMapping(SYNTAX_STYLE_JSP, pkg + "JSPTokenMaker"); + putMapping(SYNTAX_STYLE_LATEX, pkg + "LatexTokenMaker"); + putMapping(SYNTAX_STYLE_LISP, pkg + "LispTokenMaker"); + putMapping(SYNTAX_STYLE_LUA, pkg + "LuaTokenMaker"); + putMapping(SYNTAX_STYLE_MAKEFILE, pkg + "MakefileTokenMaker"); + putMapping(SYNTAX_STYLE_MXML, pkg + "MxmlTokenMaker"); + putMapping(SYNTAX_STYLE_NSIS, pkg + "NSISTokenMaker"); + putMapping(SYNTAX_STYLE_PERL, pkg + "PerlTokenMaker"); + putMapping(SYNTAX_STYLE_PHP, pkg + "PHPTokenMaker"); + putMapping(SYNTAX_STYLE_PROPERTIES_FILE,pkg + "PropertiesFileTokenMaker"); + putMapping(SYNTAX_STYLE_PYTHON, pkg + "PythonTokenMaker"); + putMapping(SYNTAX_STYLE_RUBY, pkg + "RubyTokenMaker"); + putMapping(SYNTAX_STYLE_SAS, pkg + "SASTokenMaker"); + putMapping(SYNTAX_STYLE_SCALA, pkg + "ScalaTokenMaker"); + putMapping(SYNTAX_STYLE_SQL, pkg + "SQLTokenMaker"); + putMapping(SYNTAX_STYLE_TCL, pkg + "TclTokenMaker"); + putMapping(SYNTAX_STYLE_UNIX_SHELL, pkg + "UnixShellTokenMaker"); + putMapping(SYNTAX_STYLE_VISUAL_BASIC, pkg + "VisualBasicTokenMaker"); + putMapping(SYNTAX_STYLE_WINDOWS_BATCH, pkg + "WindowsBatchTokenMaker"); + putMapping(SYNTAX_STYLE_XML, pkg + "XMLTokenMaker"); + } + +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -0,0 +1,244 @@ +package fr.ifremer.isisfish.ui.widget.text; + +import javax.swing.text.Segment; + +import org.fife.ui.rsyntaxtextarea.AbstractTokenMaker; +import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; +import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rsyntaxtextarea.TokenMap; + +public class IsisTokenMarker extends AbstractTokenMaker { + + private int currentTokenStart; + private int currentTokenType; + + @Override + public Token getTokenList(Segment text, int initialTokenType, int startOffset) { + resetTokenList(); + + char[] array = text.array; + int offset = text.offset; + int count = text.count; + int end = offset + count; + + // See, when we find a token, its starting position is always of the form: + // 'startOffset + (currentTokenStart-offset)'; but since startOffset and + // offset are constant, tokens' starting positions become: + // 'newStartOffset+currentTokenStart' for one less subtraction operation. + int newStartOffset = startOffset - offset; + + currentTokenStart = offset; + currentTokenType = initialTokenType; + +//beginning: + for (int i=offset; i<end; i++) { + + char c = array[i]; + + switch (currentTokenType) { + + case Token.NULL: + + currentTokenStart = i; // Starting a new token here. + + switch (c) { + + case ' ': + case '\t': + currentTokenType = Token.WHITESPACE; + break; + + case '"': + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + // The "separators". + case '|': + addToken(text, currentTokenStart,i, Token.SEPARATOR, newStartOffset+currentTokenStart); + currentTokenType = Token.NULL; + break; + + default: + + // Just to speed things up a tad, as this will usually be the case (if spaces above failed). + if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { + currentTokenType = Token.IDENTIFIER; + break; + } + + + currentTokenType = Token.IDENTIFIER; + break; + + } // End of switch (c). + + break; + + case Token.WHITESPACE: + + switch (c) { + + case ' ': + case '\t': + break; // Still whitespace. + + case '"': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + // The "separators". + case '|': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + default: // Add the whitespace token and start anew. + + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + currentTokenStart = i; + + // Just to speed things up a tad, as this will usually be the case (if spaces above failed). + if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { + currentTokenType = Token.IDENTIFIER; + break; + } + + + currentTokenType = Token.IDENTIFIER; + + } // End of switch (c). + + break; + + default: // Should never happen + case Token.IDENTIFIER: + + switch (c) { + + case ' ': + case '\t': + // Check for REM comments. + if (i-currentTokenStart==3 && + (array[i-3]=='r' || array[i-3]=='R') && + (array[i-2]=='e' || array[i-2]=='E') && + (array[i-1]=='m' || array[i-1]=='M')) { + currentTokenType = Token.COMMENT_EOL; + break; + } + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.WHITESPACE; + break; + + case '"': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + // The "separators". + case '|': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + + default: + + // Just to speed things up a tad, as this will usually be the case. + if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { + break; + } + + // Otherwise, fall through and assume we're still okay as an IDENTIFIER... + + } // End of switch (c). + + break; + + case Token.COMMENT_EOL: + i = end - 1; + addToken(text, currentTokenStart,i, Token.COMMENT_EOL, newStartOffset+currentTokenStart); + // We need to set token type to null so at the bottom we don't add one more token. + currentTokenType = Token.NULL; + break; + + case Token.PREPROCESSOR: // Used for labels + i = end - 1; + addToken(text, currentTokenStart,i, Token.PREPROCESSOR, newStartOffset+currentTokenStart); + // We need to set token type to null so at the bottom we don't add one more token. + currentTokenType = Token.NULL; + break; + + case Token.ERROR_STRING_DOUBLE: + + if (c=='"') { + addToken(text, currentTokenStart,i, Token.LITERAL_STRING_DOUBLE_QUOTE, newStartOffset+currentTokenStart); + currentTokenStart = i + 1; + currentTokenType = Token.NULL; + } + // Otherwise, we're still an unclosed string... + + break; + + } // End of switch (currentTokenType). + + } // End of for (int i=offset; i<end; i++). + + // Deal with the (possibly there) last token. + if (currentTokenType != Token.NULL) { + + // Check for REM comments. + if (end-currentTokenStart==3 && + (array[end-3]=='r' || array[end-3]=='R') && + (array[end-2]=='e' || array[end-2]=='E') && + (array[end-1]=='m' || array[end-1]=='M')) { + currentTokenType = Token.COMMENT_EOL; + } + + addToken(text, currentTokenStart,end-1, currentTokenType, newStartOffset+currentTokenStart); + } + + addNullToken(); + + // Return the first token in our linked list. + return firstToken; + + } + + @Override + public TokenMap getWordsToHighlight() { + TokenMap tokenMap = new TokenMap(); + + tokenMap.put("FATAL", Token.RESERVED_WORD_2); + tokenMap.put("ERROR", Token.RESERVED_WORD_2); + tokenMap.put("INFO", Token.RESERVED_WORD); + tokenMap.put("DEBUG", Token.RESERVED_WORD); + tokenMap.put("TRACE", Token.RESERVED_WORD); + + return tokenMap; + } + + @Override + public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) { + + switch (tokenType) { + // Since reserved words, functions, and data types are all passed + // into here as "identifiers," we have to see what the token + // really is... + case Token.IDENTIFIER: + int value = wordsToHighlight.get(segment, start,end); + if (value!=-1) + tokenType = value; + break; + } + + super.addToken(segment, start, end, tokenType, startOffset); + + } + +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/package-info.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/package-info.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/package-info.java 2015-04-22 15:09:18 UTC (rev 4205) @@ -0,0 +1,28 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +/** + * Customization of rsyntaxtextarea editor for isisfish. + */ +package fr.ifremer.isisfish.ui.widget.text; Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2015-04-22 15:09:18 UTC (rev 4205) @@ -867,6 +867,8 @@ isisfish.script.export.tooltip=Export selected script(s) to zip archive isisfish.script.export.tooltip.checkAll=(Un)Check all scripts to export isisfish.script.export.tooltip.chooseDir=Choose directory to export script to +isisfish.script.find=Find... +isisfish.script.gotoline=Got to line... isisfish.script.import=Import scripts from archive isisfish.script.import.cancel=Cancel isisfish.script.import.checkAll=(Un)Check all script to import @@ -914,8 +916,10 @@ isisfish.script.newplus=New ► isisfish.script.paste=Paste isisfish.script.paste.tooltip=Paste current selection (Ctrl-v) +isisfish.script.replace=Replace... isisfish.script.save=Save isisfish.script.save.tooltip=Save script +isisfish.script.search=Search isisfish.script.title=Script Editor isisfish.season.toString=season %1$s-%2$s isisfish.selectivity.equation=Equation Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2015-04-21 14:25:19 UTC (rev 4204) +++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2015-04-22 15:09:18 UTC (rev 4205) @@ -865,6 +865,8 @@ isisfish.script.export.tooltip=Exporter les scripts sélectionnés vers une archive zip isisfish.script.export.tooltip.checkAll=(Dé-)Sélectionner tous les scripts à exporter isisfish.script.export.tooltip.chooseDir=Choisir le répertoire où exporter les scripts +isisfish.script.find=Rechercher... +isisfish.script.gotoline=Aller à la ligne... isisfish.script.import=Importer des scripts depuis une archive zip isisfish.script.import.cancel=Annuler isisfish.script.import.checkAll=Tout (dé-)sélectionner @@ -912,8 +914,10 @@ isisfish.script.newplus=Nouveau ► isisfish.script.paste=Coller isisfish.script.paste.tooltip=Colle la sélection courante (Ctrl-v) +isisfish.script.replace=Remplacer... isisfish.script.save=Sauver isisfish.script.save.tooltip=Sauve le script +isisfish.script.search=Rechercher isisfish.script.title=Editeur de scripts isisfish.season.toString=saison %1$s-%2$s isisfish.selectivity.equation=Equation
participants (1)
-
echatellier@users.forge.codelutin.com