From: <tri...@us...> - 2007-08-22 10:34:05
|
Revision: 13 http://staticwiki.svn.sourceforge.net/staticwiki/?rev=13&view=rev Author: triathlon98 Date: 2007-08-22 03:34:00 -0700 (Wed, 22 Aug 2007) Log Message: ----------- simple editor to allow getting previews of the wiki formatting Modified Paths: -------------- trunk/staticwiki-editor/pom.xml trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/Editor.java Added Paths: ----------- trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/SaveException.java Modified: trunk/staticwiki-editor/pom.xml =================================================================== --- trunk/staticwiki-editor/pom.xml 2007-08-20 09:34:08 UTC (rev 12) +++ trunk/staticwiki-editor/pom.xml 2007-08-22 10:34:00 UTC (rev 13) @@ -23,11 +23,29 @@ <archive> <manifest> <mainClass>org.staticwiki.editor.Editor</mainClass> - <addClasspath>true</addClasspath> + <addClasspath>false</addClasspath> </manifest> </archive> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>unpack-dependencies</id> + <phase>compile</phase> + <goals> + <goal>unpack-dependencies</goal> + </goals> + <configuration> + <outputDirectory>${project.build.directory}/classes</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>true</overWriteSnapshots> + </configuration> + </execution> + </executions> + </plugin> </plugins> </build> <dependencies> Modified: trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/Editor.java =================================================================== --- trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/Editor.java 2007-08-20 09:34:08 UTC (rev 12) +++ trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/Editor.java 2007-08-22 10:34:00 UTC (rev 13) @@ -12,21 +12,241 @@ package org.staticwiki.editor; -//import org.apache.log4j.Logger; +import org.staticwiki.wiki.WikiRenderer; +import org.staticwiki.wiki.WikiFactory; +import org.staticwiki.wiki.WikiException; +import javax.swing.*; +import javax.swing.event.ChangeListener; +import javax.swing.event.ChangeEvent; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; + /** - * ... + * Simple swing gui for the editing of wiki text and viewing the rendered result. * * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> */ public class Editor { //private static Logger logger = Logger.getLogger( Editor.class ); + protected JFrame window = new JFrame(); + protected JTabbedPane tabPanel = new JTabbedPane(); + protected JTextArea wiki = new JTextArea(); + protected JEditorPane preview = new JEditorPane(); + protected WikiRenderer wikiRenderer; public static void main( String[] args ) { - //logger.info( "main: in" ); - System.out.println( "Hello World!" ); - //logger.info( "main: out" ); + Thread.currentThread().setUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() + { + public void uncaughtException( Thread thread, Throwable throwable ) + { + SaveException.saveException( throwable ); + } + } ); + + // build the window + new Editor().buildWindow(); } + + public void buildWindow() + { + final + + Dimension frameSize = new Dimension( 800, 600 ); + + window.setJMenuBar( getMenuBar() ); + window.add( getContentPanel(), BorderLayout.CENTER ); + + window.setSize( frameSize ); + window.setVisible( true ); + + window.setTitle( "staticwiki editor - " + "[unknown file]" ); + + window.addWindowListener( new java.awt.event.WindowAdapter() + { + public void windowClosing( WindowEvent e ) + { + SwingUtilities.invokeLater( new Runnable() + { + public void run() + { + int option = JOptionPane.showConfirmDialog( window, + "Are you sure you want to exit? Did you save the changes?", + "Confirmation", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE ); + if ( option == JOptionPane.OK_OPTION ) + { + System.exit( 0 ); + } + else + { + SwingUtilities.invokeLater( new Runnable() + { + public void run() + { + window.setVisible( true ); + } + } ); + } + } + } ); + } + } ); + + } + + private JMenuBar getMenuBar() + { + JMenuBar menuBar = new JMenuBar(); + JMenu fileMenu = new JMenu( "File" ); + JMenu editMenu = new JMenu( "Edit" ); + JMenu aboutMenu = new JMenu( "About" ); + + JMenuItem loadItem = new JMenuItem( "Load" ); + loadItem.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent e ) + { + // @todo + showError( "not yet implemented" ); + } + } + ); + JMenuItem saveItem = new JMenuItem( "Save" ); + saveItem.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent e ) + { + // @todo + showError( "not yet implemented" ); + } + } + ); + saveItem.setAccelerator( KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_S, + java.awt.Event.CTRL_MASK ) ); + + JMenuItem saveAsItem = new JMenuItem( "Save As" ); + saveAsItem.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent e ) + { + // @todo + showError( "not yet implemented" ); + } + } + ); + + JMenuItem exportPdfItem = new JMenuItem( "Export to PDF" ); + exportPdfItem.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent e ) + { + // @todo + showError( "not yet implemented" ); + } + } + ); + + JMenuItem editItem = new JMenuItem( "Edit" ); + editItem.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent e ) + { + if ( tabPanel.getSelectedIndex() != 0 ) + { + tabPanel.setSelectedIndex( 0 ); + } + } + } + ); + editItem.setAccelerator( KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_E, + java.awt.Event.CTRL_MASK ) ); + + JMenuItem previewItem = new JMenuItem( "Preview" ); + previewItem.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent e ) + { + if ( tabPanel.getSelectedIndex() != 1 ) + { + tabPanel.setSelectedIndex( 1 ); + } + } + } + ); + previewItem.setAccelerator( KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_P, + java.awt.Event.CTRL_MASK ) ); + + fileMenu.add( loadItem ); + fileMenu.add( saveItem ); + fileMenu.add( saveAsItem ); + fileMenu.add( exportPdfItem ); + editMenu.add( previewItem ); + editMenu.add( editItem ); + + menuBar.add( fileMenu ); + menuBar.add( editMenu ); + menuBar.add( aboutMenu ); + + return menuBar; + } + + private JComponent getContentPanel() + { + ScrollPane sp; + + tabPanel.addTab( "wiki", new JScrollPane(wiki, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ) ); + wiki.setLineWrap( true ); + wiki.setWrapStyleWord( true ); + + tabPanel.addTab( "preview", new JScrollPane(preview, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ) ); + preview.setEditable( false ); + preview.setContentType( "text/html" ); + + try + { + wikiRenderer = WikiFactory.getWikiRenderer(); + } + catch ( WikiException we ) + { + showError( we.toString() ); + SaveException.saveException( we ); + } + + tabPanel.getModel().addChangeListener( new ChangeListener() + { + public void stateChanged( ChangeEvent e ) + { + if ( tabPanel.getSelectedIndex() == 1 ) + { + // render it again + try + { + preview.setText( wikiRenderer.render( wiki.getText() ) ); + } + catch ( WikiException we ) + { + showError( we.toString() ); + SaveException.saveException( we ); + } + } + } + } ); + + return tabPanel; + } + + private void showError( String msg ) + { + JOptionPane optionPane = new JOptionPane( msg, JOptionPane.ERROR_MESSAGE, JOptionPane.OK_CANCEL_OPTION ); + JDialog dialog = optionPane.createDialog( window, "Error message" ); + dialog.setVisible( true ); + dialog.dispose(); + } + } \ No newline at end of file Added: trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/SaveException.java =================================================================== --- trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/SaveException.java (rev 0) +++ trunk/staticwiki-editor/src/main/java/org/staticwiki/editor/SaveException.java 2007-08-22 10:34:00 UTC (rev 13) @@ -0,0 +1,105 @@ +/** + * This file is part of the staticwiki project. + * + * The contents of this file are subject to the GNU Lesser General Public License Version 2.1 or later (the "LGPL") + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.fsf.org/licenses/lgpl.html + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + */ + +package org.staticwiki.editor; + +import java.io.File; +import java.io.PrintWriter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Date; + +/** + * Save exception details to a file + * + * @author Joachim Van der Auwera <jo...@pr...> + */ +public class SaveException +{ + public static void saveException( Throwable exc ) + { + saveException( exc, "" ); + } + + public static void saveException( Throwable exc, String message ) + { + File errorFile = new File( "errors.txt" ); + try + { + PrintWriter out = new PrintWriter( new FileOutputStream( errorFile.getAbsolutePath(), true ) ); + Date date = new Date( System.currentTimeMillis() ); + out.println( "----- error on " + date.toString() ); + String msg = exc.getLocalizedMessage(); + if ( msg == null ) msg = exc.getMessage(); + if ( msg == null ) msg = exc.toString(); + msg += " " + message; + out.println( msg ); + System.err.println( msg ); + exc.printStackTrace( out ); + out.println(); + out.close(); + } + catch ( IOException ioe ) + { + System.err.println( "oops, can't write error message to file" ); + } + } + + public static void saveWarning( Throwable exc ) + { + saveWarning( exc, "" ); + } + + public static void saveWarning( Throwable exc, String message ) + { + File errorFile = new File( "errors.txt" ); + try + { + PrintWriter out = new PrintWriter( new FileOutputStream( errorFile.getAbsolutePath(), true ) ); + Date date = new Date( System.currentTimeMillis() ); + out.println( "----- warning on " + date.toString() ); + String msg = exc.getLocalizedMessage(); + if ( msg == null ) msg = exc.getMessage(); + if ( msg == null ) msg = exc.toString(); + msg += " " + message; + out.println( msg ); + System.err.println( msg ); + exc.printStackTrace( out ); + out.println(); + out.close(); + } + catch ( IOException ioe ) + { + System.err.println( "oops, can't write error message to file" ); + } + } + + + public static void log( String error ) + { + File errorFile = new File( "errors.txt" ); + try + { + PrintWriter out = new PrintWriter( new FileOutputStream( errorFile.getAbsolutePath(), true ) ); + Date date = new Date( System.currentTimeMillis() ); + out.println( "----- error on " + date.toString() ); + out.println( error ); + System.err.println( error ); + out.println(); + out.close(); + } + catch ( IOException ioe ) + { + System.err.println( "oops, can't write error message to file" ); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |