You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by se...@apache.org on 2017/03/27 14:37:46 UTC

svn commit: r1788936 [7/7] - in /ctakes/trunk: ctakes-gui-res/ ctakes-gui-res/src/ ctakes-gui-res/src/main/ ctakes-gui-res/src/main/resources/ ctakes-gui-res/src/main/resources/org/ ctakes-gui-res/src/main/resources/org/apache/ ctakes-gui-res/src/main/...

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitInfoPanel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitInfoPanel.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitInfoPanel.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitInfoPanel.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,116 @@
+package org.apache.ctakes.gui.pipeline.bit.user;
+
+
+import org.apache.ctakes.core.pipeline.PipeBitInfo;
+import org.apache.ctakes.gui.pipeline.bit.BitInfoPanel;
+import org.apache.ctakes.gui.pipeline.bit.parameter.ParameterInfoPanel;
+import org.apache.log4j.Logger;
+
+import javax.swing.*;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.text.JTextComponent;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 1/31/2017
+ */
+final public class UserBitInfoPanel extends BitInfoPanel {
+
+   static private final Logger LOGGER = Logger.getLogger( "UserBitInfoPanel" );
+
+   private BitNameListener _bitNameListener = new BitNameListener();
+
+   public void setUserBitList( final JList<UserBit> userBitList ) {
+      userBitList.getSelectionModel().addListSelectionListener( new UserBitListListener( userBitList ) );
+   }
+
+   @Override
+   protected String getNameLabelPrefix() {
+      return "User";
+   }
+
+   @Override
+   protected JComponent createNameEditor() {
+      _bitNameListener = new BitNameListener();
+      final JTextField textField = new JTextField();
+      textField.addActionListener( _bitNameListener );
+      return textField;
+   }
+
+   @Override
+   protected void setBitName( final String text ) {
+      ((JTextComponent)_name).setText( text );
+   }
+
+   @Override
+   protected ParameterInfoPanel createParameterInfoPanel() {
+      return new UserParameterInfoPanel();
+   }
+
+   protected void clear() {
+      _bitNameListener.setUserBit( null );
+      super.clear();
+   }
+
+   private void setUserBit( final UserBit userBit ) {
+      if ( userBit == null ) {
+         clear();
+         return;
+      }
+      final PipeBitInfo info = userBit.getPipeBitInfo();
+      _bitNameListener.setUserBit( null );
+      setBitName( info.name() );
+      _description.setText( info.description() );
+      _dependencies.setText( Arrays.stream( info.dependencies() )
+            .map( PipeBitInfo.TypeProduct::toString )
+            .collect( Collectors.joining( ", " ) ) );
+      _usables.setText( Arrays.stream( info.usables() )
+            .map( PipeBitInfo.TypeProduct::toString )
+            .collect( Collectors.joining( ", " ) ) );
+      _outputs.setText( Arrays.stream( info.products() )
+            .map( PipeBitInfo.TypeProduct::toString )
+            .collect( Collectors.joining( ", " ) ) );
+      _parameterTableModel.setParameterHolder( userBit );
+      _parameterInfoPanel.setParameterHolder( userBit );
+      _bitNameListener.setUserBit( userBit );
+   }
+
+   private class UserBitListListener implements ListSelectionListener {
+      private final JList<UserBit> __userBitList;
+
+      private UserBitListListener( final JList<UserBit> userBitList ) {
+         __userBitList = userBitList;
+      }
+
+      @Override
+      public void valueChanged( final ListSelectionEvent event ) {
+         if ( event.getValueIsAdjusting() ) {
+            return;
+         }
+         final UserBit userBit = __userBitList.getSelectedValue();
+         setUserBit( userBit );
+      }
+   }
+
+   private class BitNameListener implements ActionListener {
+      private UserBit __userBit;
+
+      private void setUserBit( final UserBit userBit ) {
+         __userBit = userBit;
+      }
+
+      @Override
+      public void actionPerformed( final ActionEvent event ) {
+         if ( __userBit != null ) {
+            __userBit.setBitName( ((JTextComponent)_name).getText() );
+         }
+      }
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitListModel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitListModel.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitListModel.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitListModel.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,127 @@
+package org.apache.ctakes.gui.pipeline.bit.user;
+
+import org.apache.ctakes.core.pipeline.PipeBitInfo;
+
+import javax.swing.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 1/19/2017
+ */
+final public class UserBitListModel extends AbstractListModel<UserBit> {
+
+   static private final Logger LOGGER = Logger.getLogger( "UserBitListModel" );
+
+   private UserBit _readerBit = null;
+   private final List<UserBit> _userBits = new ArrayList<>();
+
+
+   private void setReaderBit( final UserBit reader ) {
+      if ( _readerBit != null ) {
+         _readerBit = reader;
+         fireContentsChanged( this, 0, 0 );
+         return;
+      }
+      _readerBit = reader;
+      fireIntervalAdded( this, 0, 0 );
+   }
+
+   public void addUserBit( final UserBit userBit ) {
+      insertUserBit( getSize(), userBit );
+   }
+
+   private void insertUserBit( final int viewIndex, final UserBit userBit ) {
+      if ( userBit.getPipeBitInfo().role() == PipeBitInfo.Role.READER ) {
+         setReaderBit( userBit );
+         return;
+      }
+      int listIndex = viewIndex;
+      if ( _readerBit != null ) {
+         listIndex = viewIndex - 1;
+      }
+      _userBits.add( listIndex, userBit );
+      fireIntervalAdded( this, viewIndex, viewIndex );
+   }
+
+   public void moveUserBitUp( final int viewIndex ) {
+      if ( viewIndex >= getSize() ) {
+         LOGGER.warning( "No User Pipe Bit at index " + viewIndex );
+         return;
+      }
+      int listIndex = viewIndex;
+      if ( _readerBit != null ) {
+         listIndex = viewIndex - 1;
+      }
+      if ( listIndex <= 0 ) {
+         return;
+      }
+      final UserBit userBit = _userBits.get( listIndex );
+      _userBits.remove( listIndex );
+      _userBits.add( listIndex - 1, userBit );
+   }
+
+   public void moveUserBitDown( final int viewIndex ) {
+      if ( viewIndex >= getSize() ) {
+         LOGGER.warning( "No User Pipe Bit at index " + viewIndex );
+         return;
+      }
+      int listIndex = viewIndex;
+      if ( _readerBit != null ) {
+         listIndex = viewIndex - 1;
+      }
+      if ( listIndex < 0 || listIndex >= _userBits.size() - 1 ) {
+         return;
+      }
+      final UserBit userBit = _userBits.get( listIndex );
+      _userBits.remove( listIndex );
+      _userBits.add( listIndex + 1, userBit );
+   }
+
+   public void removeUserBit( final int viewIndex ) {
+      if ( viewIndex >= getSize() ) {
+         LOGGER.warning( "No User Pipe Bit at index " + viewIndex );
+         return;
+      }
+      int listIndex = viewIndex;
+      if ( _readerBit != null ) {
+         if ( viewIndex == 0 ) {
+            _readerBit = null;
+            return;
+         }
+         listIndex = viewIndex - 1;
+      }
+      _userBits.remove( listIndex );
+   }
+
+   private UserBit getUserBit( final int viewIndex ) {
+      int listIndex = viewIndex;
+      if ( _readerBit != null ) {
+         if ( viewIndex == 0 ) {
+            return _readerBit;
+         }
+         listIndex = viewIndex - 1;
+      }
+      return _userBits.get( listIndex );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public int getSize() {
+      return _userBits.size() + (_readerBit == null ? 0 : 1);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public UserBit getElementAt( final int index ) {
+      return getUserBit( index );
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitRenderer.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitRenderer.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitRenderer.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserBitRenderer.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,111 @@
+package org.apache.ctakes.gui.pipeline.bit.user;
+
+import org.apache.ctakes.core.pipeline.PipeBitInfo;
+import org.apache.ctakes.gui.component.CellRendererPanel;
+import org.apache.ctakes.gui.pipeline.bit.PipeBitPainter;
+import org.apache.ctakes.gui.util.IconLoader;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.LineBorder;
+import java.awt.*;
+import java.util.logging.Logger;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 1/23/2017
+ */
+final public class UserBitRenderer implements ListCellRenderer<Object> {
+
+   static private final Logger LOGGER = Logger.getLogger( "UsersRenderer" );
+
+   static private final Border SELECTED_BORDER = new LineBorder( Color.DARK_GRAY, 1, true );
+   static private final Border UNSELECTED_BORDER = new EmptyBorder( 0, 0, 0, 5 );
+
+   private final ListCellRenderer<Object> _delegate = new DefaultListCellRenderer();
+   private JLabel _upLabel;
+   private JLabel _downLabel;
+   private JLabel _removeLabel;
+
+   private final JPanel _focusRenderer;
+
+
+   public UserBitRenderer() {
+      _focusRenderer = new CellRendererPanel( new BorderLayout() );
+      _focusRenderer.setBorder( UNSELECTED_BORDER );
+      final JPanel buttonPanel = new JPanel( new GridLayout( 1, 3 ) );
+      buttonPanel.setBorder( new EmptyBorder( 0, 0, 0, 5 ) );
+      buttonPanel.setBackground( null );
+      _upLabel = new JLabel();
+      _downLabel = new JLabel();
+      _removeLabel = new JLabel();
+      buttonPanel.add( _upLabel );
+      buttonPanel.add( _downLabel );
+      buttonPanel.add( _removeLabel );
+      _focusRenderer.add( buttonPanel, BorderLayout.EAST );
+      SwingUtilities.invokeLater( new ButtonIconLoader() );
+   }
+
+   static public boolean SUSPEND_BUTTONS = false;
+
+   @Override
+   public Component getListCellRendererComponent(
+         final JList<?> list,
+         final Object value,
+         final int index,
+         final boolean isSelected,
+         final boolean cellHasFocus ) {
+      final Component renderer = _delegate.getListCellRendererComponent( list, value, index, false, false );
+      final UserBit userBit = (UserBit)value;
+      PipeBitPainter.getInstance().paintObject( renderer, userBit.getPipeBitInfo(), false );
+      if ( renderer instanceof JLabel ) {
+         ((JLabel)renderer).setText( userBit.getBitName() );
+      }
+      if ( SUSPEND_BUTTONS || userBit.getPipeBitInfo().role() == PipeBitInfo.Role.READER ) {
+         if ( isSelected && renderer instanceof JComponent ) {
+            ((JComponent)renderer).setBorder( SELECTED_BORDER );
+         }
+         return renderer;
+      }
+      final Point p = list.getMousePosition();
+      if ( p != null ) {
+         final int hoverIndex = list.locationToIndex( p );
+         if ( hoverIndex == index ) {
+            _focusRenderer.add( renderer, BorderLayout.CENTER );
+            if ( isSelected ) {
+               _focusRenderer.setBorder( SELECTED_BORDER );
+            } else {
+               _focusRenderer.setBorder( UNSELECTED_BORDER );
+            }
+            return _focusRenderer;
+         }
+      }
+      if ( isSelected && renderer instanceof JComponent ) {
+         ((JComponent)renderer).setBorder( SELECTED_BORDER );
+      }
+      return renderer;
+   }
+
+
+   /**
+    * Simple Runnable that loads an icon
+    */
+   private final class ButtonIconLoader implements Runnable {
+      @Override
+      public void run() {
+         final String dir = "org/apache/ctakes/gui/pipeline/icon/";
+         final String upFile = "BlueUp.png";
+         final String downFile = "BlueDown.png";
+         final String removeFile = "RedCircleNo.png";
+         final Icon upIcon = IconLoader.loadIcon( dir + upFile, 20 );
+         final Icon downIcon = IconLoader.loadIcon( dir + downFile, 20 );
+         final Icon removeIcon = IconLoader.loadIcon( dir + removeFile, 20 );
+         _upLabel.setIcon( upIcon );
+         _downLabel.setIcon( downIcon );
+         _removeLabel.setIcon( removeIcon );
+      }
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserParameterInfoPanel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserParameterInfoPanel.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserParameterInfoPanel.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/bit/user/UserParameterInfoPanel.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,30 @@
+package org.apache.ctakes.gui.pipeline.bit.user;
+
+import org.apache.ctakes.gui.pipeline.bit.parameter.ParameterInfoPanel;
+
+import javax.swing.*;
+import javax.swing.text.JTextComponent;
+import java.util.logging.Logger;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 3/20/2017
+ */
+public class UserParameterInfoPanel extends ParameterInfoPanel {
+
+   static private final Logger LOGGER = Logger.getLogger( "UserParameterInfoPanel" );
+
+   protected String getValueLabelPrefix() {
+      return "User";
+   }
+
+   protected JComponent createValuesEditor() {
+      return new JTextField();
+   }
+
+   protected void setParameterValues( final String values ) {
+      ((JTextComponent)_values).setText( values );
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperFinder.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperFinder.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperFinder.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperFinder.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,68 @@
+package org.apache.ctakes.gui.pipeline.piper;
+
+
+import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
+import io.github.lukehutch.fastclasspathscanner.ScanInterruptedException;
+import io.github.lukehutch.fastclasspathscanner.matchprocessor.FileMatchProcessorWithContext;
+import io.github.lukehutch.fastclasspathscanner.scanner.ScanResult;
+import io.github.lukehutch.fastclasspathscanner.utils.ClasspathUtils;
+import org.apache.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 3/24/2017
+ */
+public class PiperFinder {
+
+   static private final Logger LOGGER = Logger.getLogger( "PiperFinder" );
+
+
+   private final Collection<PiperInfo> _piperFiles = new ArrayList<>();
+   private boolean _didScan = false;
+
+   synchronized public void reset() {
+      _piperFiles.clear();
+      _didScan = false;
+   }
+
+   synchronized public Collection<PiperInfo> getPiperInfos() {
+      scan();
+      return _piperFiles;
+   }
+
+   synchronized public void scan() {
+      if ( _didScan ) {
+         return;
+      }
+      final FastClasspathScanner scanner = new FastClasspathScanner();
+      LOGGER.info( "Starting Scan for Piper Filess" );
+      try {
+         scanner.matchFilenameExtension( "piper", new PiperAdder() );
+         final ScanResult result = scanner.scan();
+      } catch ( ScanInterruptedException siE ) {
+         LOGGER.error( siE.getMessage() );
+      }
+      LOGGER.info( "Scan Finished" );
+      _didScan = true;
+   }
+
+   private class PiperAdder implements FileMatchProcessorWithContext {
+      @Override
+      public void processMatch( final File classpathPrefix, final String relativePath,
+                                final InputStream inputStream, final long lengthBytes ) throws IOException {
+         final URL url = ClasspathUtils.getClasspathResourceURL( classpathPrefix, relativePath );
+         final String fullPath = url.toExternalForm();
+         final String simplePath = url.getPath();
+         _piperFiles.add( new PiperInfo( fullPath, simplePath ) );
+      }
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperInfo.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperInfo.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperInfo.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperInfo.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,41 @@
+package org.apache.ctakes.gui.pipeline.piper;
+
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 3/24/2017
+ */
+final public class PiperInfo {
+
+   static private final Logger LOGGER = Logger.getLogger( "PiperInfo" );
+
+   private final String _urlPath;
+   private final String _filePath;
+   private final boolean _readOnly;
+
+   public PiperInfo( final String urlPath, final String filePath ) {
+      this( urlPath, filePath, urlPath.startsWith( "jar:" ) );
+   }
+
+   public PiperInfo( final String urlPath, final String filePath, final boolean readOnly ) {
+      _urlPath = urlPath;
+      _filePath = filePath;
+      _readOnly = readOnly;
+   }
+
+   public String getUrlPath() {
+      return _urlPath;
+   }
+
+   public String getFilePath() {
+      return _filePath;
+   }
+
+   public boolean isReadOnly() {
+      return _readOnly;
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperTextFilter.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperTextFilter.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperTextFilter.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperTextFilter.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,178 @@
+package org.apache.ctakes.gui.pipeline.piper;
+
+import org.apache.log4j.Logger;
+
+import javax.swing.*;
+import javax.swing.text.*;
+import java.awt.*;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 3/25/2017
+ */
+final public class PiperTextFilter extends DocumentFilter {
+
+   static private final Logger LOGGER = Logger.getLogger( "PiperTextFilter" );
+
+   final private TextFormatter _textFormatter;
+
+
+   public PiperTextFilter( final DefaultStyledDocument document ) {
+      _textFormatter = new TextFormatter( document );
+      document.setDocumentFilter( this );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void remove( final FilterBypass fb, final int begin, final int length ) throws BadLocationException {
+      String text = "";
+      final Document document = fb.getDocument();
+      if ( begin + length <= document.getLength() ) {
+         text = fb.getDocument().getText( begin, length );
+      }
+      super.remove( fb, begin, length );
+      if ( shouldReformat( document, begin, length ) ) {
+         formatText( document );
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void insertString( final FilterBypass fb, final int begin, final String text, final AttributeSet attr )
+         throws BadLocationException {
+      super.insertString( fb, begin, text, attr );
+      if ( shouldReformat( fb.getDocument(), begin, text.length() ) ) {
+         formatText( fb.getDocument() );
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void replace( final FilterBypass fb, final int begin, final int length, final String text,
+                        final AttributeSet attrs )
+         throws BadLocationException {
+      super.replace( fb, begin, length, text, attrs );
+      if ( shouldReformat( fb.getDocument(), begin, length ) ) {
+         formatText( fb.getDocument() );
+      }
+   }
+
+   static private boolean shouldReformat( final Document document, final int begin, final int length )
+         throws BadLocationException {
+      final int testLength = Math.min( length + 2, document.getLength() - begin );
+      final String deltaText = document.getText( begin, testLength );
+      return deltaText.contains( " " ) || deltaText.contains( "\n" ) || deltaText.contains( "\t" );
+   }
+
+   private void formatText( final Document document ) {
+      if ( StyledDocument.class.isInstance( document ) ) {
+         SwingUtilities.invokeLater( _textFormatter );
+      }
+   }
+
+   static private final class TextFormatter implements Runnable {
+      final private StyledDocument _document;
+      final private Map<String, Style> _styles = new HashMap<>();
+
+      private TextFormatter( final StyledDocument document ) {
+         _document = document;
+         createStyles();
+      }
+
+      @Override
+      public void run() {
+         try {
+            final String text = _document.getText( 0, _document.getLength() );
+            int lineBegin = 0;
+            boolean lineEnded = false;
+            for ( int i = 0; i < _document.getLength(); i++ ) {
+               lineEnded = false;
+               if ( text.charAt( i ) == '\n' ) {
+                  formatLine( lineBegin, i );
+                  lineBegin = i + 1;
+                  lineEnded = true;
+               }
+            }
+            if ( !lineEnded ) {
+               formatLine( lineBegin, _document.getLength() );
+            }
+         } catch ( BadLocationException blE ) {
+            LOGGER.error( blE.getMessage() );
+         }
+      }
+
+      private void createStyles() {
+         createStyle( "PLAIN", Color.BLACK, "PLAIN" );
+         createStyle( "COMMENT", Color.GRAY, "COMMENT" );
+         final Style error = createStyle( "ERROR", Color.RED, "ERROR" );
+         StyleConstants.setStrikeThrough( error, true );
+         createStyle( "PARAMETER", Color.YELLOW, "PARAMETER" );
+         createStyle( "LOAD", Color.MAGENTA, "load" );
+         createStyle( "PACKAGE", Color.YELLOW.darker(), "package" );
+         createStyle( "SET", Color.ORANGE.darker(), "set", "cli" );
+         createStyle( "READER", Color.GREEN.darker().darker(), "reader", "readFiles" );
+         createStyle( "ADD", Color.CYAN.darker().darker(), "add", "addLogged", "addDescription", "addLast" );
+         createStyle( "WRITE_XMI", Color.BLUE, "writeXmis", "collectCuis", "collectEntities" );
+      }
+
+      private Style createStyle( final String name, final Color color, final String... keys ) {
+         final Style style = _document.addStyle( name, null );
+         StyleConstants.setForeground( style, color );
+         Arrays.stream( keys ).forEach( k -> _styles.put( k, style ) );
+         return style;
+      }
+
+      private void formatLine( final int begin, final int end ) throws BadLocationException {
+         final int length = end - begin;
+         if ( length <= 0 ) {
+            return;
+         }
+         final String text = _document.getText( begin, length );
+         if ( text.startsWith( "#" ) || text.startsWith( "//" ) || text.startsWith( "!" ) ) {
+            _document.setCharacterAttributes( begin, length, _styles.get( "COMMENT" ), true );
+            return;
+         }
+         int commandEnd = text.indexOf( ' ' );
+         if ( commandEnd < 0 ) {
+            commandEnd = length;
+         }
+         final Style commandStyle = getCommandStyle( text.substring( 0, commandEnd ) );
+         _document.setCharacterAttributes( begin, commandEnd, commandStyle, true );
+         if ( length > commandEnd ) {
+            _document.setCharacterAttributes( begin + commandEnd, length - commandEnd, _styles.get( "PLAIN" ), true );
+         }
+//         int nextSpace = text.indexOf( ' ', commandEnd );
+//         while ( nextSpace > 0 ) {
+//
+//
+//            nextSpace = text.indexOf( ' ', nextSpace + 1 );
+//         }
+      }
+
+      private Style getCommandStyle( final String command ) {
+         final Style style = _styles.get( command );
+         if ( style == null ) {
+            return _styles.get( "ERROR" );
+         }
+         return style;
+      }
+//      private Style getParameterStyle( final String parameter ) {
+//         final Style style = _styles.get( command );
+//         if ( style == null ) {
+//            return _styles.get( "ERROR" );
+//         }
+//         return style;
+//      }
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperValidator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperValidator.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperValidator.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/pipeline/piper/PiperValidator.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,412 @@
+//package org.apache.ctakes.gui.pipeline.piper;
+//
+//
+//import org.apache.ctakes.core.pipeline.CliOptionalsHandler;
+//import org.apache.ctakes.core.resource.FileLocator;
+//import org.apache.log4j.Logger;
+//import org.apache.uima.UIMAException;
+//import org.apache.uima.analysis_component.AnalysisComponent;
+//import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+//import org.apache.uima.collection.CollectionReader;
+//import org.apache.uima.resource.ResourceInitializationException;
+//
+//import java.io.BufferedReader;
+//import java.io.FileNotFoundException;
+//import java.io.IOException;
+//import java.io.InputStreamReader;
+//import java.lang.reflect.InvocationTargetException;
+//import java.lang.reflect.Method;
+//import java.util.ArrayList;
+//import java.util.Collection;
+//import java.util.HashSet;
+//import java.util.List;
+//import java.util.regex.Matcher;
+//import java.util.regex.Pattern;
+//
+///**
+// * @author SPF , chip-nlp
+// * @version %I%
+// * @since 3/25/2017
+// * TODO extract similar methods with PiperFileReader
+// */
+//final public class PiperValidator {
+//
+//   static private final Logger LOGGER = Logger.getLogger( "PiperValidator" );
+//
+//   static private final String[] CTAKES_PACKAGES
+//         = { "core",
+//             "assertion",
+//             "chunker",
+//             "clinicalpipeline",
+//             "constituency.parser",
+//             "contexttokenizer",
+//             "coreference",
+//             "dependency.parser",
+//             "dictionary.lookup2",
+//             "dictionary.lookup",
+//             "temporal",
+//             "drug-ner",
+//             "lvg",
+//             "necontexts",
+//             "postagger",
+//             "prepropessor",
+//             "relationextractor",
+//             "sideeffect",
+//             "smokingstatus",
+//             "template.filler" };
+//
+//   static private final Object[] EMPTY_OBJECT_ARRAY = new Object[ 0 ];
+//
+//   static private final Pattern KEY_VALUE_PATTERN = Pattern.compile( "=" );
+//   static private final Pattern NAME_VALUE_PATTERN = Pattern
+//         .compile( "[^\"\\s=]+=(?:(?:[^\"=\\s]+)|(?:\"[^\"=\\r\\n]+\"))" );
+//
+//   static private final char[] _reservedCli = { 'p', 'i', 'o', 's', 'l' };
+//   private final Collection<String> _userPackages = new HashSet<>();
+//
+//
+//
+//   /**
+//    * @param command   specified by first word in the file line
+//    * @param parameter specified by second word in the file line
+//    * @throws UIMAException if the command could not be executed
+//    */
+//   private boolean testParameter( final String command, final String parameter ) throws UIMAException {
+//      if ( parameter.trim().isEmpty() ) {
+//         return false;
+//      }
+//      switch ( command ) {
+//         case "load":
+//            return isValidPiper( parameter );
+//         case "package":
+//            return isPackageValid( parameter );
+//         case "set":
+//            return true;
+//         case "cli":
+//            return isCliValid( parameter );
+//         case "reader":
+//            if ( !isValidReader( parameter ) ) {
+//               return false;
+//            }
+//            if ( hasParameters( parameter ) ) {
+//               return isClassValid( parameter );
+//            } else {
+//               if ( hasParameters( parameter ) ) {
+//                  final String[] component_parameters = splitFromParameters( parameter );
+//                  final String component = component_parameters[ 0 ];
+//                  final Object[] parameters = splitParameters( component_parameters[ 1 ] );
+//                  _builder.reader( getReaderClass( component ), parameters );
+//               } else {
+//                  _builder.reader( getReaderClass( parameter ) );
+//               }
+//
+//               _builder.reader( getReaderClass( parameter ) );
+//            }
+//            break;
+//         case "readFiles":
+//            if ( parameter.isEmpty() ) {
+//               return true;
+//            } else {
+//               isPathValid( parameter );
+//            }
+//            break;
+//         case "add":
+//            if ( hasParameters( parameter ) ) {
+//               final String[] component_parameters = splitFromParameters( parameter );
+//               final String component = component_parameters[ 0 ];
+//               final Object[] parameters = splitParameters( component_parameters[ 1 ] );
+//               _builder.add( getComponentClass( component ), parameters );
+//            } else {
+//               return isValidAE( parameter );
+//            }
+//            break;
+//         case "addLogged":
+//            if ( hasParameters( parameter ) ) {
+//               final String[] component_parameters = splitFromParameters( parameter );
+//               final String component = component_parameters[ 0 ];
+//               final Object[] parameters = splitParameters( component_parameters[ 1 ] );
+//               _builder.addLogged( getComponentClass( component ), parameters );
+//            } else {
+//               return isValidAE( parameter );
+//            }
+//            break;
+//         case "addDescription":
+//            if ( hasParameters( parameter ) ) {
+//               final String[] descriptor_parameters = splitFromParameters( parameter );
+//               final String component = descriptor_parameters[ 0 ];
+//               final Object[] values = splitDescriptorValues( descriptor_parameters[ 1 ] );
+//               final AnalysisEngineDescription description = createDescription( component, values );
+//               _builder.addDescription( description );
+//            } else {
+//               final AnalysisEngineDescription description = createDescription( parameter );
+//               _builder.addDescription( description );
+//            }
+//            break;
+//         case "addLast":
+//            if ( hasParameters( parameter ) ) {
+//               final String[] component_parameters = splitFromParameters( parameter );
+//               final String component = component_parameters[ 0 ];
+//               final Object[] parameters = splitParameters( component_parameters[ 1 ] );
+//               _builder.addLast( getComponentClass( component ), parameters );
+//            } else {
+//               return isValidAE( parameter );
+//            }
+//            break;
+//         case "collectCuis":
+//            _builder.collectCuis();
+//            break;
+//         case "collectEntities":
+//            _builder.collectEntities();
+//            break;
+//         case "writeXmis":
+//            if ( parameter.isEmpty() ) {
+//               _builder.writeXMIs();
+//            } else {
+//               _builder.writeXMIs( parameter );
+//            }
+//            break;
+//         default:
+//            LOGGER.error( "Unknown Command: " + command );
+//      }
+//      return false;
+//   }
+//
+//   /**
+//    *
+//    * @param text -
+//    * @return true if there is more than one word in the text
+//    */
+//   static private boolean hasParameters( final String text ) {
+//      return SPACE_PATTERN.split( text ).length > 1;
+//   }
+//
+//
+//
+//   /**
+//    * @param filePath path to the pipeline command file
+//    * @return true if the file is found
+//    */
+//   static private boolean isPathValid( final String filePath ) {
+//      if ( filePath.isEmpty() ) {
+//         return false;
+//      }
+//      return !FileLocator.getFullPathQuiet( filePath ).isEmpty();
+//   }
+//
+//   private boolean isPackageValid( final String text ) {
+//      if ( text.isEmpty() ) {
+//         return false;
+//      }
+//      if ( hasParameters( text ) ) {
+//         return false;
+//      }
+//      _userPackages.add( text );
+//      return true;
+//   }
+//
+//   static private boolean isClassValid( final String text ) {
+//      if ( text.isEmpty() ) {
+//         return false;
+//      }
+//      final int spaceIndex = text.indexOf( ' ' );
+//      if ( spaceIndex > 0 ) {
+//         return isClassValid( text.substring( 0, spaceIndex ) );
+//      }
+//      return true;
+//   }
+//
+//   static private boolean isCliValid( final String text ) {
+//      if ( text.isEmpty() ) {
+//         return false;
+//      }
+//      final Matcher matcher = NAME_VALUE_PATTERN.matcher( text );
+//      final List<String> pairList = new ArrayList<>();
+//      while ( matcher.find() ) {
+//         pairList.add( text.substring( matcher.start(), matcher.end() ) );
+//      }
+//      final String[] pairs = pairList.toArray( new String[ pairList.size() ] );
+//      int i = 0;
+//      for ( String pair : pairs ) {
+//         final String[] keyAndValue = KEY_VALUE_PATTERN.split( pair );
+//         if ( keyAndValue.length != 2 ) {
+//            return false;
+//         }
+//         if ( keyAndValue[0].isEmpty() || keyAndValue[1].length() != 1 ){
+//            return false;
+//         }
+//      }
+//      return true;
+//   }
+//
+//   private boolean isValidReader( final String className ) {
+//      Class readerClass;
+//      try {
+//         readerClass = Class.forName( className );
+//      } catch ( ClassNotFoundException cnfE ) {
+//         readerClass = getPackagedReader( className );
+//      }
+//      if ( readerClass == null ) {
+//         return false;
+//      }
+//      return isClassType( readerClass, CollectionReader.class );
+//   }
+//
+//   /**
+//    * @param className fully-specified or simple name of an ae or cc component class
+//    * @return discovered class for ae or cc
+//    */
+//   private boolean isValidAE( final String className ) {
+//      Class componentClass;
+//      try {
+//         componentClass = Class.forName( className );
+//      } catch ( ClassNotFoundException cnfE ) {
+//         componentClass = getPackagedComponent( className );
+//      }
+//      if ( componentClass == null ) {
+//         return false;
+//      }
+//      return isClassType( componentClass, AnalysisComponent.class );
+//   }
+//
+////
+////   /**
+////    * @param className fully-specified or simple name of an ae or cc component class
+////    * @return discovered class for ae or cc
+////    */
+////   private Class<? extends AnalysisComponent> getComponentClass( final String className )  {
+////      Class componentClass;
+////      try {
+////         componentClass = Class.forName( className );
+////      } catch ( ClassNotFoundException cnfE ) {
+////         componentClass = getPackagedComponent( className );
+////      }
+////      if ( componentClass != null&& isClassType( componentClass, AnalysisComponent.class ) ) {
+////         return componentClass;
+////      }
+////      return null;
+////   }
+//
+//   /**
+//    * @param className simple name of a cr Collection Reader class
+//    * @return discovered class for a cr
+//    */
+//   private Class<? extends CollectionReader> getPackagedReader( final String className ) {
+//      Class readerClass;
+//      for ( String packageName : _userPackages ) {
+//         readerClass = getPackagedClass( packageName, className, CollectionReader.class );
+//         if ( readerClass != null ) {
+//            return readerClass;
+//         }
+//      }
+//      for ( String packageName : CTAKES_PACKAGES ) {
+//         readerClass = getPackagedClass(
+//               "org.apache.ctakes." + packageName + ".cr", className, CollectionReader.class );
+//         if ( readerClass != null ) {
+//            return readerClass;
+//         }
+//         readerClass = getPackagedClass(
+//               "org.apache.ctakes." + packageName, className, CollectionReader.class );
+//         if ( readerClass != null ) {
+//            return readerClass;
+//         }
+//      }
+//      return null;
+//   }
+//
+//   /**
+//    * @param className fully-specified or simple name of an ae or cc component class
+//    * @return discovered class for ae or cc
+//    */
+//   private Class<? extends AnalysisComponent> getPackagedComponent( final String className ) {
+//      Class componentClass;
+//      for ( String packageName : _userPackages ) {
+//         componentClass = getPackagedClass( packageName, className, AnalysisComponent.class );
+//         if ( componentClass != null ) {
+//            return componentClass;
+//         }
+//      }
+//      for ( String packageName : CTAKES_PACKAGES ) {
+//         componentClass = getPackagedClass(
+//               "org.apache.ctakes." + packageName + ".ae", className, AnalysisComponent.class );
+//         if ( componentClass != null ) {
+//            return componentClass;
+//         }
+//         componentClass = getPackagedClass(
+//               "org.apache.ctakes." + packageName + ".cc", className, AnalysisComponent.class );
+//         if ( componentClass != null ) {
+//            return componentClass;
+//         }
+//         componentClass = getPackagedClass(
+//               "org.apache.ctakes." + packageName, className, AnalysisComponent.class );
+//         if ( componentClass != null ) {
+//            return componentClass;
+//         }
+//      }
+//      return null;
+//   }
+//
+//   /**
+//    * @param packageName     possible package for class
+//    * @param className       simple name for class
+//    * @param wantedClassType desired superclass type
+//    * @return discovered class or null if no proper class was discovered
+//    */
+//   static private Class<?> getPackagedClass( final String packageName, final String className,
+//                                             final Class<?> wantedClassType ) {
+//      try {
+//         Class<?> classType = Class.forName( packageName + "." + className );
+//         if ( isClassType( classType, wantedClassType ) ) {
+//            return classType;
+//         }
+//      } catch ( ClassNotFoundException cnfE ) {
+//         // do nothing
+//      }
+//      return null;
+//   }
+//
+//   /**
+//    * @param filePath fully-specified or simple path of a piper file
+//    * @return discovered path for the piper file
+//    */
+//   private boolean isValidPiper( final String filePath ) {
+//      String fullPath = FileLocator.getFullPathQuiet( filePath );
+//      if ( fullPath != null && !fullPath.isEmpty() ) {
+//         return true;
+//      }
+//      // Check user packages
+//      for ( String packageName : _userPackages ) {
+//         fullPath = FileLocator.getFullPathQuiet( packageName.replace( '.', '/' ) + '/' + filePath );
+//         if ( fullPath != null && !fullPath.isEmpty() ) {
+//            return true;
+//         }
+//         fullPath = FileLocator.getFullPathQuiet( packageName.replace( '.', '/' ) + "/pipeline/" + filePath );
+//         if ( fullPath != null && !fullPath.isEmpty() ) {
+//            return true;
+//         }
+//      }
+//      // Check ctakes packages
+//      for ( String packageName : CTAKES_PACKAGES ) {
+//         fullPath = FileLocator
+//               .getFullPathQuiet( "org/apache/ctakes/" + packageName.replace( '.', '/' ) + '/' + filePath );
+//         if ( fullPath != null && !fullPath.isEmpty() ) {
+//            return true;
+//         }
+//         fullPath = FileLocator
+//               .getFullPathQuiet( "org/apache/ctakes/" + packageName.replace( '.', '/' ) + "/pipeline/" + filePath );
+//         if ( fullPath != null && !fullPath.isEmpty() ) {
+//            return true;
+//         }
+//      }
+//      return false;
+//   }
+//
+//   /**
+//    * @param classType       class type to test
+//    * @param wantedClassType wanted class type
+//    * @return true if the class type extends the wanted class type
+//    */
+//   static private boolean isClassType( final Class<?> classType, final Class<?> wantedClassType ) {
+//      return wantedClassType.isAssignableFrom( classType );
+//   }
+//
+//}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/ColorFactory.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/ColorFactory.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/ColorFactory.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/ColorFactory.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,33 @@
+package org.apache.ctakes.gui.util;
+
+
+import org.apache.log4j.Logger;
+
+import java.awt.*;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 3/24/2017
+ */
+final public class ColorFactory {
+
+   static private final Logger LOGGER = Logger.getLogger( "ColorFactory" );
+
+   private ColorFactory() {
+   }
+
+
+   static public Color getColor( final String seed ) {
+      return getColor( seed.hashCode() );
+   }
+
+   static public Color getColor( final int seed ) {
+      return new Color( seed );
+   }
+
+   static public Color addTransparency( final Color color, final int transparency ) {
+      return new Color( color.getRed(), color.getGreen(), color.getBlue(), transparency % 256 );
+   }
+
+}

Added: ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/IconLoader.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/IconLoader.java?rev=1788936&view=auto
==============================================================================
--- ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/IconLoader.java (added)
+++ ctakes/trunk/ctakes-gui/src/main/java/org/apache/ctakes/gui/util/IconLoader.java Mon Mar 27 14:37:44 2017
@@ -0,0 +1,59 @@
+package org.apache.ctakes.gui.util;
+
+import org.apache.ctakes.core.resource.FileLocator;
+import org.apache.log4j.Logger;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 1/23/2017
+ */
+final public class IconLoader {
+
+   static private final Logger LOGGER = Logger.getLogger( "IconLoader" );
+
+   private IconLoader() {
+   }
+
+   /**
+    * @param filePath path to the icon file
+    * @param iconSize size of the square in pixels
+    * @return an icon of the specified size
+    */
+   static public Icon loadIcon( final String filePath, final int iconSize ) {
+      try {
+         final File imageFile = FileLocator.locateFile( filePath );
+         final Image image = ImageIO.read( imageFile );
+         final BufferedImage scaleImage = new BufferedImage( iconSize, iconSize, BufferedImage.TYPE_INT_ARGB );
+         final Graphics g = scaleImage.createGraphics();
+         g.drawImage( image, 0, 0, iconSize, iconSize, null );
+         return new ImageIcon( scaleImage );
+      } catch ( IOException ioE ) {
+         LOGGER.warn( ioE.getMessage() );
+      }
+      return null;
+   }
+
+   /**
+    * @param filePath path to the icon file
+    * @return the icon stored in the given file
+    */
+   static public Icon loadIcon( final String filePath ) {
+      try {
+         final File imageFile = FileLocator.locateFile( filePath );
+         final Image image = ImageIO.read( imageFile );
+         return new ImageIcon( image );
+      } catch ( IOException ioE ) {
+         LOGGER.warn( ioE.getMessage() );
+      }
+      return null;
+   }
+
+}