Revision: 19806
          http://sourceforge.net/p/gate/code/19806
Author:   markagreenwood
Date:     2016-11-26 06:12:42 +0000 (Sat, 26 Nov 2016)
Log Message:
-----------
minor code cleanup

Modified Paths:
--------------
    
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaAnnotationEditor.java
    
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaFeaturesEditor.java

Property Changed:
----------------
    gate/branches/sawdust2/plugins/Schema_Annotation_Editor/

Index: gate/branches/sawdust2/plugins/Schema_Annotation_Editor
===================================================================
--- gate/branches/sawdust2/plugins/Schema_Annotation_Editor     2016-11-26 
02:22:54 UTC (rev 19805)
+++ gate/branches/sawdust2/plugins/Schema_Annotation_Editor     2016-11-26 
06:12:42 UTC (rev 19806)

Property changes on: gate/branches/sawdust2/plugins/Schema_Annotation_Editor
___________________________________________________________________
Modified: svn:ignore
## -1,2 +1,2 ##
-
+target
 .settings
Modified: 
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaAnnotationEditor.java
===================================================================
--- 
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaAnnotationEditor.java
  2016-11-26 02:22:54 UTC (rev 19805)
+++ 
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaAnnotationEditor.java
  2016-11-26 06:12:42 UTC (rev 19806)
@@ -15,27 +15,6 @@
  */
 package gate.gui.annedit;
 
-import gate.Annotation;
-import gate.AnnotationSet;
-import gate.Factory;
-import gate.FeatureMap;
-import gate.Gate;
-import gate.LanguageResource;
-import gate.Resource;
-import gate.creole.AbstractVisualResource;
-import gate.creole.AnnotationSchema;
-import gate.creole.FeatureSchema;
-import gate.creole.ResourceInstantiationException;
-import gate.creole.metadata.CreoleResource;
-import gate.event.CreoleEvent;
-import gate.event.CreoleListener;
-import gate.gui.MainFrame;
-import gate.swing.JChoice;
-import gate.util.GateException;
-import gate.util.GateRuntimeException;
-import gate.util.InvalidOffsetException;
-import gate.util.LuckyException;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
@@ -46,7 +25,6 @@
 import java.awt.Frame;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
-import java.awt.HeadlessException;
 import java.awt.Insets;
 import java.awt.Point;
 import java.awt.Rectangle;
@@ -80,11 +58,8 @@
 import javax.swing.JButton;
 import javax.swing.JComponent;
 import javax.swing.JDialog;
-import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.JToggleButton;
 import javax.swing.KeyStroke;
@@ -95,6 +70,27 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.JTextComponent;
 
+import gate.Annotation;
+import gate.AnnotationSet;
+import gate.Factory;
+import gate.FeatureMap;
+import gate.Gate;
+import gate.LanguageResource;
+import gate.Resource;
+import gate.creole.AbstractVisualResource;
+import gate.creole.AnnotationSchema;
+import gate.creole.FeatureSchema;
+import gate.creole.ResourceInstantiationException;
+import gate.creole.metadata.CreoleResource;
+import gate.event.CreoleEvent;
+import gate.event.CreoleListener;
+import gate.gui.MainFrame;
+import gate.swing.JChoice;
+import gate.util.GateException;
+import gate.util.GateRuntimeException;
+import gate.util.InvalidOffsetException;
+import gate.util.LuckyException;
+
 /**
  * An annotation editor that enforces the annotation schemas currently loaded 
in
  * the system. Once the editing of an annotation is started, it cannot be
@@ -639,11 +635,11 @@
     mainPane.setLayout(new BorderLayout());
     featureEditorsByType = new HashMap<String, SchemaFeaturesEditor>();
     // for each schema we need to create a type button and a features editor
-    for(String annType : schemasByType.keySet()) {
-      AnnotationSchema annSchema = schemasByType.get(annType);
+    for(Map.Entry<String,AnnotationSchema> entry : schemasByType.entrySet()) {
+      AnnotationSchema annSchema = entry.getValue();
       SchemaFeaturesEditor aFeaturesEditor =
           new SchemaFeaturesEditor(annSchema);
-      featureEditorsByType.put(annType, aFeaturesEditor);
+      featureEditorsByType.put(entry.getKey(), aFeaturesEditor);
     }
     List<String> typeList = new ArrayList<String>(schemasByType.keySet());
     Collections.sort(typeList);
@@ -670,7 +666,7 @@
     featuresBox = Box.createVerticalBox();
     aTitle = "Features ";
     featuresBox.setBorder(BorderFactory.createTitledBorder(aTitle));
-    aLabel = new JLabel(aTitle);
+    
     mainPane.add(featuresBox, BorderLayout.SOUTH);
     add(mainPane, BorderLayout.CENTER);
     // add the search and annotate GUI at the bottom of the annotator editor
@@ -814,68 +810,6 @@
   private Point dialogLocation = new Point(0, 0);
 
   /**
-   * @param args
-   */
-  public static void main(String[] args) {
-    try {
-      Gate.init();
-      JFrame aFrame = new JFrame("New Annotation Editor");
-      aFrame.setSize(800, 600);
-      aFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
-      JDialog annDialog =
-          new JDialog(aFrame, "Annotation Editor Dialog", false);
-      annDialog.setFocusableWindowState(false);
-      // annDialog.setResizable(false);
-      // annDialog.setUndecorated(true);
-      SchemaAnnotationEditor pane = new SchemaAnnotationEditor();
-      annDialog.add(pane);
-      annDialog.pack();
-      // JToolBar tBar = new JToolBar("Annotation Editor", 
JToolBar.HORIZONTAL);
-      // tBar.setLayout(new BorderLayout());
-      // tBar.setMinimumSize(tBar.getPreferredSize());
-      // tBar.add(pane);
-      // aFrame.getContentPane().add(tBar, BorderLayout.NORTH);
-      StringBuffer strBuf = new StringBuffer();
-      for(int i = 0; i < 100; i++) {
-        strBuf.append("The quick brown fox jumped over the lazy dog.\n");
-      }
-      JTextArea aTextPane = new JTextArea(strBuf.toString());
-      JScrollPane scroller = new JScrollPane(aTextPane);
-      aFrame.getContentPane().add(scroller, BorderLayout.CENTER);
-      // Box aBox = Box.createVerticalBox();
-      // aFrame.getContentPane().add(aBox);
-      //
-      // FeatureEditor aFeatEditor = new FeatureEditor("F-nominal-small",
-      // FeatureType.nominal, "val1");
-      // aFeatEditor.setValues(new String[]{"val1", "val2", "val3"});
-      // aBox.add(aFeatEditor.getGui());
-      //
-      // aFeatEditor = new FeatureEditor("F-nominal-large",
-      // FeatureType.nominal, "val1");
-      // aFeatEditor.setValues(new String[]{"val1", "val2", "val3", "val4",
-      // "val5",
-      // "val6", "val7", "val8", "val9"});
-      // aBox.add(aFeatEditor.getGui());
-      //
-      // aFeatEditor = new FeatureEditor("F-boolean-true",
-      // FeatureType.bool, "true");
-      // aBox.add(aFeatEditor.getGui());
-      //
-      // aFeatEditor = new FeatureEditor("F-boolean-false",
-      // FeatureType.bool, "false");
-      // aBox.add(aFeatEditor.getGui());
-      aFrame.setVisible(true);
-      System.out.println("Window up");
-      annDialog.setVisible(true);
-      System.out.println("Dialog up");
-    } catch(HeadlessException e) {
-      e.printStackTrace();
-    } catch(GateException e) {
-      e.printStackTrace();
-    }
-  }
-
-  /**
    * Base class for actions on annotations.
    */
   protected abstract class AnnotationAction extends AbstractAction {
@@ -908,7 +842,7 @@
           annotation.getStartNode().getOffset().longValue() - increment;
       if(newValue < 0) newValue = 0;
       try {
-        moveAnnotation(annSet, annotation, new Long(newValue), annotation
+        moveAnnotation(annSet, annotation, newValue, annotation
             .getEndNode().getOffset());
       } catch(InvalidOffsetException ioe) {
         throw new GateRuntimeException(ioe);
@@ -939,7 +873,7 @@
           annotation.getStartNode().getOffset().longValue() + increment;
       if(newValue > endOffset) newValue = endOffset;
       try {
-        moveAnnotation(annSet, annotation, new Long(newValue), annotation
+        moveAnnotation(annSet, annotation, newValue, annotation
             .getEndNode().getOffset());
       } catch(InvalidOffsetException ioe) {
         throw new GateRuntimeException(ioe);
@@ -970,7 +904,7 @@
       if(newValue < startOffset) newValue = startOffset;
       try {
         moveAnnotation(annSet, annotation, annotation.getStartNode()
-            .getOffset(), new Long(newValue));
+            .getOffset(), newValue);
       } catch(InvalidOffsetException ioe) {
         throw new GateRuntimeException(ioe);
       }
@@ -1001,7 +935,7 @@
       if(newValue > maxOffset) newValue = maxOffset;
       try {
         moveAnnotation(annSet, annotation, annotation.getStartNode()
-            .getOffset(), new Long(newValue));
+            .getOffset(), newValue);
       } catch(InvalidOffsetException ioe) {
         throw new GateRuntimeException(ioe);
       }

Modified: 
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaFeaturesEditor.java
===================================================================
--- 
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaFeaturesEditor.java
    2016-11-26 02:22:54 UTC (rev 19805)
+++ 
gate/branches/sawdust2/plugins/Schema_Annotation_Editor/src/main/java/gate/gui/annedit/SchemaFeaturesEditor.java
    2016-11-26 06:12:42 UTC (rev 19806)
@@ -66,7 +66,7 @@
      */
     text};
 
-  protected class FeatureEditor{
+  protected class FeatureEditor {
     
     /**
      * Constructor for nominal features
@@ -122,14 +122,14 @@
         public void actionPerformed(ActionEvent e) {          
           Object newValue = null;
           if(e.getSource() == checkbox){
-            newValue = new Boolean(checkbox.isSelected());
+            newValue = checkbox.isSelected();
           }else if(e.getSource() == textField){
             newValue = textField.getText();
           }else if(e.getSource() == jchoice){
             newValue = jchoice.getSelectedItem();
             if(newValue != null && type == FeatureType.bool){
               //convert eh new value to Boolean
-              newValue = new Boolean(BOOLEAN_TRUE == newValue);
+              newValue = BOOLEAN_TRUE.equals(newValue);
             }
           }else if(e.getSource() == SchemaFeaturesEditor.this){
             //synthetic event
@@ -371,7 +371,7 @@
         case bool:
           Object choiceValue = jchoice.getSelectedItem();        
           return choiceValue == null ? null : 
-            new Boolean(choiceValue == BOOLEAN_TRUE);
+            choiceValue.equals(BOOLEAN_TRUE);
 //        case bool:
 //          return new Boolean(checkbox.isSelected());
         case text:
@@ -486,11 +486,11 @@
       }
     }
     //add the feature editors in the alphabetical order
-    for(String featureName : featureEditors.keySet()){
-      FeatureEditor featureEditor = featureEditors.get(featureName);
+    for(Map.Entry<String,FeatureEditor> entry : featureEditors.entrySet()){
+      FeatureEditor featureEditor = entry.getValue();
       constraints.gridy = gridy++;
       JLabel nameLabel = new JLabel(
-              "<html>" + featureName + 
+              "<html>" + entry.getKey() + 
               (featureEditor.isRequired() ? "<b><font 
color='red'>*</font></b>: " : ": ") +
               "</html>");
       add(nameLabel, constraints);
@@ -557,9 +557,10 @@
       }
     }
     // 2) then update all the displays
-    for(String featureName : featureEditors.keySet()){
+    for(Map.Entry<String,FeatureEditor> entry : featureEditors.entrySet()){
 //      FeatureSchema fSchema = featureSchemas.get(featureName);
-      FeatureEditor aFeatureEditor = featureEditors.get(featureName);
+      FeatureEditor aFeatureEditor = entry.getValue();
+      String featureName = entry.getKey();
       Object featureValue = featureMap == null ? 
               null : featureMap.get(featureName);
       if(featureValue == null){

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to