Ejemplo n.º 1
0
  private void updateEditorView() {
    editorPane.setText("");
    numParameters = 0;
    try {
      java.util.List elements = editableTemplate.getPrintfElements();
      for (Iterator it = elements.iterator(); it.hasNext(); ) {
        PrintfUtil.PrintfElement el = (PrintfUtil.PrintfElement) it.next();
        if (el.getFormat().equals(PrintfUtil.PrintfElement.FORMAT_NONE)) {
          appendText(el.getElement(), PLAIN_ATTR);
        } else {
          insertParameter(
              (ConfigParamDescr) paramKeys.get(el.getElement()),
              el.getFormat(),
              editorPane.getDocument().getLength());
        }
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          this,
          "Invalid Format: " + ex.getMessage(),
          "Invalid Printf Format",
          JOptionPane.ERROR_MESSAGE);

      selectedPane = 1;
      printfTabPane.setSelectedIndex(selectedPane);
      updatePane(selectedPane);
    }
  }
Ejemplo n.º 2
0
 /**
  * Sets the accelerator sequence
  *
  * @param accSeq The new accelSeq value
  */
 public void setAccelSeq(AcceleratorSeq accSeq) {
   java.util.List<AcceleratorNode> accNodes = accSeq.getNodesOfType(Electromagnet.s_strType);
   java.util.Iterator<AcceleratorNode> itr = accNodes.iterator();
   while (itr.hasNext()) {
     Electromagnet emg = (Electromagnet) itr.next();
     if (emg.getStatus()) {
       emg.setUseFieldReadback(false);
     }
   }
   ringFoilPosCorr.setAccelSeq(accSeq);
 }
  public void tabRemoveHighlight(int tabIndex) {
    Iterator<Integer> highlightedIter = highlightedTabs.iterator();

    while (highlightedIter.hasNext()) {
      if (highlightedIter.next().intValue() == tabIndex) {
        highlightedIter.remove();
        break;
      }
    }
  }
 public boolean importData(JComponent c, Transferable t) {
   if (c != textComponent) { // ### never happens, we dont share transfer handlers
     System.out.println("*** importData(): c=" + c);
   }
   try {
     DataFlavor[] flavors = t.getTransferDataFlavors();
     boolean hasStringFlavor = t.isDataFlavorSupported(DataFlavor.stringFlavor);
     boolean hasImageFlavor = t.isDataFlavorSupported(DataFlavor.imageFlavor);
     boolean hasFilelistFlavor = t.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
     //
     System.out.println(">>> import data to text panel (" + flavors.length + " flavors)");
     // ### for (int i = 0; i < flavors.length; i++) {
     // ###	System.out.println(flavors[i]);
     // ###}
     System.out.println("  >   string flavor supported: " + hasStringFlavor);
     System.out.println("  >    image flavor supported: " + hasImageFlavor);
     System.out.println("  > filelist flavor supported: " + hasFilelistFlavor);
     //
     // We do not allow dropping on top of the selected text
     if ((source == textComponent)
         && (textComponent.getCaretPosition() >= p0.getOffset())
         && (textComponent.getCaretPosition() <= p1.getOffset())) {
       shouldRemove = false;
       System.out.println(
           ">>> dropping on top of the selected text is not allowed -- import canceled");
       return true;
     }
     //
     if (hasStringFlavor) {
       String data = (String) t.getTransferData(DataFlavor.stringFlavor);
       int pos = textComponent.getCaretPosition();
       if (DeepaMehtaUtils.isImage(data)) {
         HTMLEditorKit kit = (HTMLEditorKit) ((JEditorPane) textComponent).getEditorKit();
         HTMLDocument doc = (HTMLDocument) textComponent.getDocument();
         String html = "<img src=\"" + data + "\"></img>";
         kit.insertHTML(doc, pos, html, 0, 0, HTML.Tag.IMG); // ### <img> not XML conform
         // ### doc.insertBeforeStart(doc.getParagraphElement(pos), html);
         System.out.println(">>> IMG tag inserted: \"" + html + "\"");
       } else {
         textComponent.getDocument().insertString(pos, data, null);
         System.out.println(">>> regular text inserted: \"" + data + "\"");
       }
     } else if (hasFilelistFlavor) {
       java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
       System.out.println("    " + files.size() + " files:");
       for (int i = 0; i < files.size(); i++) {
         File file = (File) files.get(i);
         String filename = file.getName();
         System.out.println("    " + file);
         if (DeepaMehtaUtils.isHTML(filename)) {
           String html = DeepaMehtaUtils.readFile(file);
           textComponent.setText(html); // ### replace instead insert
           textComponent.setCaretPosition(0);
           // ### ((JEditorPane) textComponent).setPage("file://" + file);	// ### replace instead
           // insert
           // ### setDirty("dropping HTML file");
           System.out.println(">>> HTML inserted (read from file)");
           break; // ### max one file is inserted
         } else if (DeepaMehtaUtils.isImage(filename)) {
           HTMLEditorKit kit = (HTMLEditorKit) ((JEditorPane) textComponent).getEditorKit();
           HTMLDocument doc = (HTMLDocument) textComponent.getDocument();
           int pos = textComponent.getCaretPosition();
           String imagefile = file.getPath().replace('\\', '/'); // ###
           String html = "<img src=\"" + imagefile + "\"></img>";
           kit.insertHTML(doc, pos, html, 0, 0, HTML.Tag.IMG); // ### <img> not XML conform
           // ### doc.insertBeforeStart(doc.getParagraphElement(pos), html);
           System.out.println(">>> IMG tag inserted: \"" + html + "\"");
         } else {
           System.out.println(
               "### importData(): only implemented for HTML files -- import canceled");
         }
       }
     } else {
       System.out.println("*** importData(): no supported flavor " + c);
     }
     return true;
   } catch (UnsupportedFlavorException ufe) {
     System.out.println("*** while dropping to text panel: " + ufe);
   } catch (BadLocationException ble) {
     System.out.println("*** while dropping to text panel: " + ble);
   } catch (IOException ioe) {
     System.out.println("*** while dropping to text panel: " + ioe);
   }
   //
   return super.importData(c, t);
 }
 public boolean isTabHighlighted(int tabIndex) {
   return highlightedTabs.contains(tabIndex);
 }