Author: sletellier Date: 2012-06-14 19:35:04 +0200 (Thu, 14 Jun 2012) New Revision: 721 Url: http://nuiton.org/repositories/revision/jrst/721 Log: - up to jaxx 2.5-SNAPSHOT - clean some code - use FileEditor Removed: trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanelHandler.java Modified: trunk/jrst/pom.xml trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTCommandModel.java trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx trunk/pom.xml Modified: trunk/jrst/pom.xml =================================================================== --- trunk/jrst/pom.xml 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/jrst/pom.xml 2012-06-14 17:35:04 UTC (rev 721) @@ -223,7 +223,7 @@ <plugins> <plugin> <groupId>org.nuiton.jaxx</groupId> - <artifactId>maven-jaxx-plugin</artifactId> + <artifactId>jaxx-maven-plugin</artifactId> <executions> <execution> <goals> Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-06-14 17:35:04 UTC (rev 721) @@ -24,7 +24,8 @@ */ package org.nuiton.jrst; -import java.awt.*; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -37,14 +38,12 @@ import java.io.Reader; import java.net.URL; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.TransformerException; - import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -55,8 +54,8 @@ import org.nuiton.i18n.init.ClassPathI18nInitializer; import org.nuiton.jrst.convertisor.DocUtils2RST; import org.nuiton.jrst.convertisor.DocUtilsVisitor; -import org.nuiton.jrst.ui.JRSTView; import org.nuiton.jrst.legacy.JRSTReader; +import org.nuiton.jrst.ui.JRSTView; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.Resource; import org.nuiton.util.StringUtil; @@ -205,9 +204,6 @@ if (args.length == 0) { askOption(); } else { - if (args == null) { - System.exit(0); - } ApplicationConfig config = JRSTConfig.getConfig(args); config.doAction(0); @@ -238,7 +234,6 @@ private static void askOption() throws SecurityException, NoSuchMethodException, IOException { - String[] result = null; try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); @@ -255,7 +250,6 @@ /** * Graphical user interface * - * @return command as string * @throws SecurityException * @throws NoSuchMethodException */ @@ -285,7 +279,7 @@ log.info("Don't generate file " + fileOut + ", because already exists"); } else { - Document doc = null; + Document doc; if (simpleGeneration) { doc = generateSimpleDoc(fileIn, UTF_8); @@ -431,9 +425,8 @@ // Execution of the docutils script to transform rst to xml String commandExec = String.format("__run__.exec_docutils('%s', '%s', [",docutilsPath, TYPE_XML); - Iterator<File> iterator = listIn.iterator(); - while (iterator.hasNext()) { - commandExec += "'" + iterator.next().getAbsolutePath() + "',"; + for (File aListIn : listIn) { + commandExec += "'" + aListIn.getAbsolutePath() + "',"; } commandExec = commandExec.substring(0,commandExec.lastIndexOf(",")); Modified: trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTCommandModel.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTCommandModel.java 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTCommandModel.java 2012-06-14 17:35:04 UTC (rev 721) @@ -26,9 +26,9 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; -import java.util.Iterator; +import java.io.File; import java.util.List; -import org.apache.commons.lang3.StringUtils; +import org.nuiton.util.StringUtil; import org.python.google.common.collect.Lists; /** @@ -43,19 +43,17 @@ protected Boolean simpleMode = Boolean.FALSE; protected Boolean formatEnabled = Boolean.TRUE; - protected String saveLocationText; - protected String openLocationText; + protected File saveFile; + protected File openFile; protected String selectedFormat; - protected List<String> xslList; + protected List<File> xslFileList; protected JRSTView jrstView; public JRSTCommandModel(JRSTView jrstView) { this.jrstView = jrstView; - xslList = Lists.newArrayList(); - saveLocationText = StringUtils.EMPTY; - openLocationText = StringUtils.EMPTY; + xslFileList = Lists.newArrayList(); selectedFormat = "xml"; } @@ -89,24 +87,24 @@ firePropertyChange("formatEnabled", oldValue, formatEnabled); } - public String getSaveLocationText() { - return saveLocationText; + public File getSaveFile() { + return saveFile; } - public void setSaveLocationText(String saveLocationText) { - String oldValue = getSaveLocationText(); - this.saveLocationText = saveLocationText; - firePropertyChange("saveLocationText", oldValue, saveLocationText); + public void setSaveFile(File saveFile) { + File oldValue = getSaveFile(); + this.saveFile = saveFile; + firePropertyChange("saveFile", oldValue, saveFile); } - public String getOpenLocationText() { - return openLocationText; + public File getOpenFile() { + return openFile; } - public void setOpenLocationText(String openLocationText) { - String oldValue = getOpenLocationText(); - this.openLocationText = openLocationText; - firePropertyChange("openLocationText", oldValue, openLocationText); + public void setOpenFile(File openFile) { + File oldValue = getOpenFile(); + this.openFile = openFile; + firePropertyChange("openFile", oldValue, openFile); } public String getSelectedFormat() { @@ -119,48 +117,42 @@ firePropertyChange("selectedFormat", oldValue, selectedFormat); } - public List<String> getXslList() { - return xslList; + public List<File> getXslFileList() { + return xslFileList; } - public void setXslList(List<String> xslList) { - List<String> oldValue = getXslList(); - this.xslList = xslList; - firePropertyChange("xslList", oldValue, xslList); + public void setXslFileList(List<File> xslFileList) { + List<File> oldValue = getXslFileList(); + this.xslFileList = xslFileList; + firePropertyChange("xslFileList", oldValue, xslFileList); } public String getXsls() { - String xsls = ""; - Iterator<String> iterator = xslList.iterator(); - while (iterator.hasNext()) { - xsls += iterator.next(); - if (iterator.hasNext()) { - xsls += ","; + String xslAsString = StringUtil.join(getXslFileList(), new StringUtil.ToString<File>() { + + @Override + public String toString(File file) { + return file.getAbsolutePath(); } - } - return xsls; + }, ",", true); + return xslAsString; } - public String getElementXslList(Integer number) { - if (xslList.size() <= number) { - xslList.add(StringUtils.EMPTY); - } - String text = xslList.get(number); - return text; + public void addXslFile(File xslFile, int index) { + List<File> oldValue = getXslFileList(); + xslFileList.add(index, xslFile); + firePropertyChange("xslFileList", oldValue, xslFileList); } - public void setElementXslList(Integer number, String text) { - List<String> oldValue = getXslList(); - if(number == xslList.size()) { - xslList.add(text); - } else { - xslList.set(number, text); + public File getXslFile(Integer number) { + if (xslFileList.size() <= number) { + return null; } - firePropertyChange("xslList", oldValue, xslList); + return xslFileList.get(number); } public int getPanelNumber() { - return xslList.size(); + return xslFileList.size(); } public void addPropertyChangeListener(PropertyChangeListener listener) { Modified: trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx 2012-06-14 17:35:04 UTC (rev 721) @@ -33,6 +33,7 @@ java.awt.Dimension org.nuiton.jrst.JRST org.nuiton.util.Resource + jaxx.runtime.swing.editor.FileEditor </import> <JRSTViewHandler id='handler' constructorParams='this'/> @@ -59,39 +60,19 @@ <cell anchor='west'> <JLabel text='Open'/> </cell> - <cell weightx='1' fill='horizontal'> - <JTextField id='openLocationText' - text='{model.getOpenLocationText()}' - onKeyReleased='model.setOpenLocationText(openLocationText.getText())' - columns='31'/> + <cell weightx='1' fill='horizontal' columns='2'> + <FileEditor id='openLocation' + exts='rst' + selectedFile='{model.getOpenFile()}' + directoryEnabled='{false}' + fileEnabled='{true}' + acceptAllFileFilterUsed='{true}' + extsDescription='reStructuredText (*.rst)' + onActionPerformed='model.setOpenFile(openLocation.getSelectedFile())'/> </cell> - <cell> - <JButton id ='boutonOpenLocation' - onActionPerformed='handler.doOpenLocation()' - preferredSize='{new Dimension(30,30)}' - constructorParams='Resource.getIcon("icone/open.png")'/> - </cell> </row> <row> <cell anchor='west'> - <JLabel text='saveAs'/> - </cell> - <cell weightx='1' fill='horizontal'> - <JTextField id='saveLocationText' - text='{model.getSaveLocationText()}' - onKeyReleased='model.setSaveLocationText(saveLocationText.getText())' - columns='31'/> - </cell> - <cell> - <JButton id ='boutonSaveLocation' - onActionPerformed='handler.doOpenSaveLocation()' - preferredSize='{new Dimension(30,30)}' - constructorParams='Resource.getIcon("icone/open.png")'/> - </cell> - </row> - - <row> - <cell anchor='west'> <JRadioButton id='format' text='Format : ' selected='{model.isFormatEnabled()}' @@ -104,9 +85,22 @@ onActionPerformed='model.setSelectedFormat((String)formatList.getSelectedItem())'/> </cell> </row> - <row> <cell anchor='west'> + <JLabel text='saveAs'/> + </cell> + <cell weightx='1' fill='horizontal' columns='2'> + <FileEditor id='saveLocation' + exts='{model.getSelectedFormat()}' + selectedFile='{model.getSaveFile()}' + directoryEnabled='{false}' + fileEnabled='{true}' + acceptAllFileFilterUsed='{true}' + onActionPerformed='model.setSaveFile(saveLocation.getSelectedFile())'/> + </cell> + </row> + <row> + <cell anchor='west'> <JRadioButton id='xslRadio' text='externalXSL' selected='{!model.isFormatEnabled()}' Modified: trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java 2012-06-14 17:35:04 UTC (rev 721) @@ -26,11 +26,8 @@ import com.google.common.io.Files; import java.awt.Color; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.io.File; import javax.swing.ButtonGroup; -import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPanel; import jaxx.runtime.context.JAXXInitialContext; @@ -63,37 +60,6 @@ addXslLocation(); } - public void doOpenLocation() { - JFileChooser fc = new JFileChooser(System.getProperty("user.home")); - fc.showOpenDialog(jrstView); - File file = fc.getSelectedFile(); - if (file != null) { - JRSTCommandModel model = jrstView.getModel(); - String absolutePath = file.getAbsolutePath(); - model.setOpenLocationText(absolutePath); - } - } - - public void doOpenSaveLocation() { - JFileChooser fc = new JFileChooser(System.getProperty("user.home")); - fc.showSaveDialog(jrstView); - JRSTCommandModel model = jrstView.getModel(); - File file = fc.getSelectedFile(); - if (file != null) { - String absolutePath = file.getAbsolutePath(); - if (file.exists()) { - int choix = askEcraser(); - if (choix == JOptionPane.YES_OPTION) { - model.setOverwrite(true); - model.setSaveLocationText(absolutePath); - } else if (choix == JOptionPane.NO_OPTION) - doOpenSaveLocation(); - } else { - model.setSaveLocationText(absolutePath); - } - } - } - public int askEcraser() { return JOptionPane.showConfirmDialog(jrstView, _("overwriteGraph?")); } @@ -116,26 +82,14 @@ xslPanel.setModel(model); xslPanel.setModel(model); int panelNumber = model.getPanelNumber(); - String xslPath = model.getElementXslList(panelNumber); - xslPanel.setXslPath(xslPath); xslPanel.setPanelNumber(panelNumber); - - xslPanel.addPropertyChangeListener(XslPanel.PROPERTY_XSL_PATH, new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - XslPanel source = (XslPanel)evt.getSource(); - jrstView.getModel().setElementXslList(source.getPanelNumber(), (String)evt.getNewValue()); - } - }); - JPanel xslListPanel = jrstView.getXslListPanel(); xslListPanel.add(xslPanel); jrstView.pack(); } public void convert() { - if (jrstView.getOpenLocationText().getText().equals("")) { + if (jrstView.getOpenLocation() == null) { jrstView.getErrorLbl().setText(_("openEmpty?")); jrstView.getErrorLbl().setForeground(Color.RED); jrstView.pack(); @@ -146,17 +100,8 @@ } public void launchJRST() { - File fileIn = null; JRSTCommandModel model = jrstView.getModel(); - if (!model.isOverwrite()) { - fileIn = new File(model.getOpenLocationText()); - if (fileIn.exists()) { - int choix = jrstView.getHandler().askEcraser(); - if (choix == JOptionPane.NO_OPTION) { - fileIn = null; - } - } - } + File fileIn = model.getOpenFile(); if (fileIn != null) { String xslListOrFormat; @@ -165,28 +110,30 @@ else { xslListOrFormat = model.getXsls(); } - String outputFile = ""; - int length = model.getSaveLocationText().length(); - if (length > 0) { - outputFile = model.getSaveLocationText(); - } else { + File outputFile = model.getSaveFile(); + if (outputFile.exists()) { + int choix = jrstView.getHandler().askEcraser(); + if (choix == JOptionPane.NO_OPTION) { + return; + } + } + if (model.getSaveFile() == null) { // If the user didn't give the output file, we take the input file name with the right extension // For example, nameExample.rst becomes nameExample.xml - if (fileIn.isFile()) { - outputFile = fileIn.getAbsolutePath(); - String ext = Files.getFileExtension(outputFile); + if (outputFile.isFile()) { + String outputPath = fileIn.getAbsolutePath(); + String ext = Files.getFileExtension(outputPath); if (ext.isEmpty()) { - ext = xslListOrFormat; - outputFile = outputFile + "." + xslListOrFormat; + outputPath = outputPath + "." + xslListOrFormat; } else { - outputFile = outputFile.replace("." + ext, "." + xslListOrFormat); + outputPath = outputPath.replace("." + ext, "." + xslListOrFormat); } + outputFile = new File(outputPath); } } - File fileOut = new File(outputFile); try{ - JRST.generate(xslListOrFormat, fileIn, fileOut, JRST.Overwrite.ALLTIME, model.isSimpleMode()); + JRST.generate(xslListOrFormat, fileIn, outputFile, JRST.Overwrite.ALLTIME, model.isSimpleMode()); } catch (Exception e) { log.error("Can't generate the document with this configuration", e); } finally { Modified: trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx 2012-06-14 17:35:04 UTC (rev 721) @@ -26,35 +26,23 @@ <import> java.awt.Dimension org.nuiton.util.Resource + jaxx.runtime.swing.editor.FileEditor </import> - <XslPanelHandler id='handler' constructorParams='this'/> - <Integer id='panelNumber' javaBean='null'/> + <Integer id='panelNumber' javaBean='0'/> <JRSTCommandModel id='model' javaBean='getContextValue(JRSTCommandModel.class)'/> - <String id='xslPath' javaBean='null'/> - <script><![CDATA[ - - protected void $afterCompleteSetup() { - handler.init(); - } - - ]]></script> - <row> <cell fill='horizontal' weightx='1'> - <JTextField id='xslLocationText' - columns='30' + <FileEditor id='xslLocation' enabled='{!model.isFormatEnabled()}' - text='{xslPath}' - onKeyReleased='setXslPath(xslLocationText.getText())'/> + exts='xsl' + selectedFile='{model.getXslFile(panelNumber)}' + directoryEnabled='{false}' + fileEnabled='{true}' + acceptAllFileFilterUsed='{true}' + extsDescription='xsl file (*.xsl)' + onActionPerformed='model.addXslFile(xslLocation.getSelectedFile(), panelNumber)'/> </cell> - <cell> - <JButton id='boutonXslLocation' - enabled='{!model.isFormatEnabled()}' - preferredSize='{new Dimension(30, 30)}' - constructorParams='Resource.getIcon("icone/open.png")' - onActionPerformed='handler.openXslLocation()'/> - </cell> </row> </Table> \ No newline at end of file Deleted: trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanelHandler.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanelHandler.java 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanelHandler.java 2012-06-14 17:35:04 UTC (rev 721) @@ -1,57 +0,0 @@ -/* - * #%L - * JRst :: Api - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jrst.ui; - -import java.io.File; -import javax.swing.JFileChooser; - -/** - * Created with IntelliJ IDEA. - * User: jpages - * Date: 12/06/12 - * Time: 11:35 - * To change this template use File | Settings | File Templates. - */ -public class XslPanelHandler { - - XslPanel xslPanel; - - public XslPanelHandler(XslPanel xslPanel) { - this.xslPanel = xslPanel; - } - - public void init() { - - } - - public void openXslLocation() { - JFileChooser fc = new JFileChooser(System.getProperty("user.home")); - fc.showOpenDialog(xslPanel); - File file = fc.getSelectedFile(); - if (file != null) { - xslPanel.getXslLocationText().setText(file.getAbsolutePath()); - } - } -} Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-06-14 16:10:29 UTC (rev 720) +++ trunk/pom.xml 2012-06-14 17:35:04 UTC (rev 721) @@ -395,7 +395,7 @@ <nuitonUtilsVersion>2.4.8</nuitonUtilsVersion> <nuitonI18nVersion>2.4.1</nuitonI18nVersion> <xalanVersion>2.7.1</xalanVersion> - <jaxxVersion>2.4.2</jaxxVersion> + <jaxxVersion>2.5-SNAPSHOT</jaxxVersion> </properties> @@ -412,7 +412,7 @@ <plugin> <groupId>org.nuiton.jaxx</groupId> - <artifactId>maven-jaxx-plugin</artifactId> + <artifactId>jaxx-maven-plugin</artifactId> <version>${jaxxVersion}</version> </plugin>