當前位置: 首頁>>代碼示例>>Java>>正文


Java StatusListener.statusChanged方法代碼示例

本文整理匯總了Java中gate.event.StatusListener.statusChanged方法的典型用法代碼示例。如果您正苦於以下問題:Java StatusListener.statusChanged方法的具體用法?Java StatusListener.statusChanged怎麽用?Java StatusListener.statusChanged使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gate.event.StatusListener的用法示例。


在下文中一共展示了StatusListener.statusChanged方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPersistentRepresentation

import gate.event.StatusListener; //導入方法依賴的package包/類
/**
 * Recursively traverses the provided object and replaces it and all
 * its contents with the appropriate persistent equivalent classes.
 *
 * @param target the object to be analysed and translated into a
 *          persistent equivalent.
 * @return the persistent equivalent value for the provided target
 */
public static Serializable getPersistentRepresentation(Object target)
        throws PersistenceException {
  if(target == null) return null;
  // first check we don't have it already
  Persistence res = existingPersistentReplacements
          .get().getFirst().get(new ObjectHolder(target));
  if(res != null) return res;

  Class<? extends Object> type = target.getClass();
  Class<?> newType = getMostSpecificPersistentType(type);
  if(newType == null) {
    // no special handler
    if(target instanceof Serializable)
      return (Serializable)target;
    else throw new PersistenceException(
            "Could not find a serialisable replacement for " + type);
  }

  // we have a new type; create the new object, populate and return it
  try {
    res = (Persistence)newType.newInstance();
  }
  catch(Exception e) {
    throw new PersistenceException(e);
  }
  if(target instanceof NameBearer) {
    StatusListener sListener = (StatusListener)Gate.getListeners().get(
            "gate.event.StatusListener");
    if(sListener != null) {
      sListener.statusChanged("Storing " + ((NameBearer)target).getName());
    }
  }
  res.extractDataFromSource(target);
  existingPersistentReplacements.get().getFirst().put(new ObjectHolder(target), res);
  return res;
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:45,代碼來源:PersistenceManager.java

示例2: toXml

import gate.event.StatusListener; //導入方法依賴的package包/類
/**
 * Returns a GateXml document that is a custom XML format for wich there is a
 * reader inside GATE called gate.xml.GateFormatXmlHandler. What it does is to
 * serialize a GATE document in an XML format.
 * 
 * @param doc the document to serialize.
 * @return a string representing a Gate Xml document.
 */
public static String toXml(TextualDocument doc) {
  // Initialize the xmlContent several time the size of the current document.
  // This is because of the tags size. This measure is made to increase the
  // performance of StringBuffer.
  StringBuffer xmlContent = new StringBuffer(
          DOC_SIZE_MULTIPLICATION_FACTOR
          * (doc.getContent().size().intValue()));
  // Add xml header
  xmlContent.append("<?xml version=\"1.0\" encoding=\"");
  xmlContent.append(doc.getEncoding());
  xmlContent.append("\" ?>");
  xmlContent.append(Strings.getNl());
  // Add the root element
  xmlContent.append("<GateDocument>\n");
  xmlContent.append("<!-- The document's features-->\n\n");
  xmlContent.append("<GateDocumentFeatures>\n");
  xmlContent.append(featuresToXml(doc.getFeatures(),null));
  xmlContent.append("</GateDocumentFeatures>\n");
  xmlContent.append("<!-- The document content area with serialized"
          + " nodes -->\n\n");
  // Add plain text element
  xmlContent.append("<TextWithNodes>");
  xmlContent.append(textWithNodes(doc, doc.getContent().toString()));
  xmlContent.append("</TextWithNodes>\n");
  // Serialize as XML all document's annotation sets
  // Serialize the default AnnotationSet
  StatusListener sListener = (StatusListener)gate.Gate
          .getListeners().get("gate.event.StatusListener");
  if(sListener != null)
    sListener.statusChanged("Saving the default annotation set ");
  xmlContent.append("<!-- The default annotation set -->\n\n");
  annotationSetToXml(doc.getAnnotations(), xmlContent);
  // Serialize all others AnnotationSets
  // namedAnnotSets is a Map containing all other named Annotation Sets.
  Map<String,AnnotationSet> namedAnnotSets = doc.getNamedAnnotationSets();
  if(namedAnnotSets != null) {
    Iterator<AnnotationSet> iter = namedAnnotSets.values().iterator();
    while(iter.hasNext()) {
      AnnotationSet annotSet = iter.next();
      xmlContent.append("<!-- Named annotation set -->\n\n");
      // Serialize it as XML
      if(sListener != null)
        sListener.statusChanged("Saving " + annotSet.getName()
                + " annotation set ");
      annotationSetToXml(annotSet, xmlContent);
    }// End while
  }// End if
  // Add the end of GateDocument
  xmlContent.append("</GateDocument>");
  if(sListener != null) sListener.statusChanged("Done !");
  // return the XmlGateDocument
  return xmlContent.toString();
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:62,代碼來源:DocumentXmlUtils.java

示例3: actionPerformed

import gate.event.StatusListener; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
  Runnable runnable = new Runnable() {
    @Override
    public void run() {
      DataStore ds = ((LanguageResource)target).getDataStore();
      if(ds != null) {
        try {
          MainFrame.lockGUI("Saving "
                  + ((LanguageResource)target).getName());
          StatusListener sListener = (StatusListener)gate.Gate
                  .getListeners().get("gate.event.StatusListener");
          if(sListener != null)
            sListener.statusChanged("Saving: "
                    + ((LanguageResource)target).getName());
          double timeBefore = System.currentTimeMillis();
          ((LanguageResource)target).getDataStore().sync(
                  (LanguageResource)target);
          double timeAfter = System.currentTimeMillis();
          if(sListener != null)
            sListener.statusChanged(((LanguageResource)target).getName()
                    + " saved in "
                    + NumberFormat.getInstance().format(
                            (timeAfter - timeBefore) / 1000) + " seconds");
        }
        catch(PersistenceException pe) {
          MainFrame.unlockGUI();
          JOptionPane.showMessageDialog(getLargeView(), "Save failed!\n "
                  + pe.toString(), "GATE", JOptionPane.ERROR_MESSAGE);
        }
        catch(SecurityException se) {
          MainFrame.unlockGUI();
          JOptionPane.showMessageDialog(getLargeView(), "Save failed!\n "
                  + se.toString(), "GATE", JOptionPane.ERROR_MESSAGE);
        }
        finally {
          MainFrame.unlockGUI();
        }
      }
      else {
        JOptionPane
                .showMessageDialog(
                        getLargeView(),
                        "This resource has not been loaded from a datastore.\n"
                                + "Please use the \"Save to Datastore...\" option.\n",
                        "GATE", JOptionPane.ERROR_MESSAGE);

      }
    }
  };
  new Thread(runnable).start();
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:53,代碼來源:NameBearerHandle.java


注:本文中的gate.event.StatusListener.statusChanged方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。