Beispiel #1
0
  // write ncml from given dataset
  boolean writeNcml(String location) {
    boolean err = false;

    closeOpenFiles();

    try {
      String result;
      ds = openDataset(location, addCoords, null);
      if (ds == null) {
        editor.setText("Failed to open <" + location + ">");
      } else {
        result = new NcMLWriter().writeXML(ds);
        editor.setText(result);
        editor.setCaretPosition(0);
      }

    } catch (FileNotFoundException ioe) {
      editor.setText("Failed to open <" + location + ">");
      err = true;

    } catch (Exception e) {
      StringWriter sw = new StringWriter(10000);
      e.printStackTrace();
      e.printStackTrace(new PrintWriter(sw));
      editor.setText(sw.toString());
      err = true;
    }

    return !err;
  }
  // WTF: this does not update packs!!
  // only updating info for selected pack. pulldown menus and info area!
  void updatePacks() {
    for (int i = 0; i < packPanels.size(); i++) {
      if (selectedPack == i && getIndex() >= 0) {
        ModPack pack = ModPack.getPackArray().get(getIndex());
        if (pack != null) {
          String mods = "";
          if (pack.getMods() != null) {
            mods += "<p>This pack contains the following mods by default:</p><ul>";
            for (String name : pack.getMods()) {
              mods += "<li>" + name + "</li>";
            }
            mods += "</ul>";
          }
          packPanels.get(i).setBackground(UIManager.getColor("control").darker().darker());
          packPanels.get(i).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
          File tempDir =
              new File(
                  OSUtils.getCacheStorageLocation(), "ModPacks" + File.separator + pack.getDir());
          packInfo.setText(
              "<html><img src='file:///"
                  + tempDir.getPath()
                  + File.separator
                  + pack.getImageName()
                  + "' width=400 height=200></img> <br>"
                  + pack.getInfo()
                  + mods);
          packInfo.setCaretPosition(0);

          if (ModPack.getSelectedPack(isFTB()).getServerUrl().equals("")
              || ModPack.getSelectedPack(isFTB()).getServerUrl() == null) {
            server.setEnabled(false);
          } else {
            server.setEnabled(true);
          }
          String tempVer = Settings.getSettings().getPackVer(pack.getDir());
          version.removeActionListener(al);
          version.removeAllItems();
          version.addItem("Recommended");
          if (pack.getOldVersions() != null) {
            for (String s : pack.getOldVersions()) {
              version.addItem(s);
            }
            version.setSelectedItem(tempVer);
          }
          version.addActionListener(al);
        }
      } else {
        packPanels.get(i).setBackground(UIManager.getColor("control"));
        packPanels.get(i).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      }
    }
  }
 public void showPageFor(RefEntity refEntity, CommonProblemDescriptor descriptor) {
   try {
     String html = generateHTML(refEntity, descriptor);
     myHTMLViewer.read(new StringReader(html), null);
     setupStyle();
     myHTMLViewer.setCaretPosition(0);
   } catch (Exception e) {
     showEmpty();
   } finally {
     myCurrentEntity = refEntity;
     myCurrentDescriptor = descriptor;
   }
 }
Beispiel #4
0
  // read text from textArea through NcMLReader
  // then write it back out via resulting dataset
  void doTransform(String text) {
    try {
      StringReader reader = new StringReader(text);
      NetcdfDataset ncd = NcMLReader.readNcML(reader, null);
      StringWriter sw = new StringWriter(10000);
      ncd.writeNcML(sw, null);
      editor.setText(sw.toString());
      editor.setCaretPosition(0);
      JOptionPane.showMessageDialog(this, "File successfully transformed");

    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage());
      ioe.printStackTrace();
    }
  }
  public void jumpToError() {
    if (parseError != null && parseError.hasLineNumbers()) {
      try {
        int offset = computeDocumentOffset(parseError.getBeginLine(), parseError.getBeginColumn());

        // scroll to center as much as possible.
        editor.setCaretPosition(offset);
        Rectangle r1 = editor.modelToView(offset);
        int dy = (editor.getVisibleRect().height - r1.height) / 2;
        Rectangle r2 =
            new Rectangle(0, r1.y - dy, editor.getVisibleRect().width, r1.height + 2 * dy);
        editor.scrollRectToVisible(r2);
      } catch (BadLocationException e) {

      }
    }
  }
 private void showPageFromHistory(RefEntity newEntity) {
   InspectionTool tool = getTool(newEntity);
   try {
     if (tool instanceof DescriptorProviderInspection
         && !(tool instanceof CommonInspectionToolWrapper)) {
       showEmpty();
     } else {
       try {
         String html = generateHTML(newEntity, tool);
         myHTMLViewer.read(new StringReader(html), null);
         setupStyle();
         myHTMLViewer.setCaretPosition(0);
       } catch (Exception e) {
         showEmpty();
       }
     }
   } finally {
     myCurrentEntity = newEntity;
     myCurrentDescriptor = null;
   }
 }
  @Override
  public void reset() {
    final String text = (myTemplate == null) ? "" : myTemplate.getText();
    String name = (myTemplate == null) ? "" : myTemplate.getName();
    String extension = (myTemplate == null) ? "" : myTemplate.getExtension();
    String description = (myTemplate == null) ? "" : myTemplate.getDescription();

    if ((description.length() == 0) && (myDefaultDescriptionUrl != null)) {
      try {
        description = UrlUtil.loadText(myDefaultDescriptionUrl);
      } catch (IOException e) {
        LOG.error(e);
      }
    }

    EditorFactory.getInstance().releaseEditor(myTemplateEditor);
    myFile = createFile(text, name);
    myTemplateEditor = createEditor();

    boolean adjust = (myTemplate != null) && myTemplate.isReformatCode();
    myNameField.setText(name);
    myExtensionField.setText(extension);
    myAdjustBox.setSelected(adjust);
    String desc = description.length() > 0 ? description : EMPTY_HTML;

    // [myakovlev] do not delete these stupid lines! Or you get Exception!
    myDescriptionComponent.setContentType(CONTENT_TYPE_PLAIN);
    myDescriptionComponent.setEditable(true);
    myDescriptionComponent.setText(desc);
    myDescriptionComponent.setContentType(UIUtil.HTML_MIME);
    myDescriptionComponent.setText(desc);
    myDescriptionComponent.setCaretPosition(0);
    myDescriptionComponent.setEditable(false);

    myDescriptionPanel.setVisible(StringUtil.isNotEmpty(description));

    myNameField.setEditable((myTemplate != null) && (!myTemplate.isDefault()));
    myExtensionField.setEditable((myTemplate != null) && (!myTemplate.isDefault()));
    myModified = false;
  }
Beispiel #8
0
  public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (node == null) {
      return;
    }

    Object userObject = node.getUserObject();
    if (userObject instanceof TopicInfo) {
      TopicInfo topicInfo = (TopicInfo) userObject;
      try {
        if (topicInfo.subtopicCount > 0) {
          htmlPane.setText(
              "<div style='font-family:Verdana,Tahoma;font-size:10px;'>Please choose a topic</div>");
          return;
        }

        URL helpFileUrl = ResourceManager.getHelpFileUrl(topicInfo.id);
        if (helpFileUrl == null) {
          throw new RuntimeException();
        }
        String content = CommonUtil.readStringFromUrl(helpFileUrl);
        content =
            "<html><body style=\"font-family:Verdana,Tahoma;font-size:10px;\">"
                + "<h2>"
                + topicInfo.title
                + "</h2>"
                + content
                + "</body></html>";
        ((HTMLDocument) htmlPane.getDocument()).setBase(helpFileUrl);
        htmlPane.setText(content);
        htmlPane.setCaretPosition(0);
      } catch (Exception e1) {
        htmlPane.setText(
            "<div style='color:#FF0000;font-family:Verdana,Tahoma;font-size:10px;'>Cannot read help for \""
                + topicInfo.title
                + "\"!</div>");
      }
    }
  }
  public static JEditorPane initPane(
      @NonNls Html html, final HintHint hintHint, @Nullable final JLayeredPane layeredPane) {
    final Ref<Dimension> prefSize = new Ref<Dimension>(null);
    String htmlBody = UIUtil.getHtmlBody(html);
    @NonNls
    String text =
        "<html><head>"
            + UIUtil.getCssFontDeclaration(
                hintHint.getTextFont(),
                hintHint.getTextForeground(),
                hintHint.getLinkForeground(),
                hintHint.getUlImg())
            + "</head><body>"
            + htmlBody
            + "</body></html>";

    final boolean[] prefSizeWasComputed = {false};
    final JEditorPane pane =
        new JEditorPane() {
          @Override
          public Dimension getPreferredSize() {
            if (!prefSizeWasComputed[0] && hintHint.isAwtTooltip()) {
              JLayeredPane lp = layeredPane;
              if (lp == null) {
                JRootPane rootPane = UIUtil.getRootPane(this);
                if (rootPane != null) {
                  lp = rootPane.getLayeredPane();
                }
              }

              Dimension size;
              if (lp != null) {
                size = lp.getSize();
                prefSizeWasComputed[0] = true;
              } else {
                size = ScreenUtil.getScreenRectangle(0, 0).getSize();
              }
              int fitWidth = (int) (size.width * 0.8);
              Dimension prefSizeOriginal = super.getPreferredSize();
              if (prefSizeOriginal.width > fitWidth) {
                setSize(new Dimension(fitWidth, Integer.MAX_VALUE));
                Dimension fixedWidthSize = super.getPreferredSize();
                Dimension minSize = super.getMinimumSize();
                prefSize.set(
                    new Dimension(
                        fitWidth > minSize.width ? fitWidth : minSize.width,
                        fixedWidthSize.height));
              } else {
                prefSize.set(new Dimension(prefSizeOriginal));
              }
            }

            Dimension s =
                prefSize.get() != null ? new Dimension(prefSize.get()) : super.getPreferredSize();
            Border b = getBorder();
            if (b != null) {
              Insets insets = b.getBorderInsets(this);
              if (insets != null) {
                s.width += insets.left + insets.right;
                s.height += insets.top + insets.bottom;
              }
            }
            return s;
          }
        };

    final HTMLEditorKit.HTMLFactory factory =
        new HTMLEditorKit.HTMLFactory() {
          @Override
          public View create(Element elem) {
            AttributeSet attrs = elem.getAttributes();
            Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
            Object o =
                elementName != null ? null : attrs.getAttribute(StyleConstants.NameAttribute);
            if (o instanceof HTML.Tag) {
              HTML.Tag kind = (HTML.Tag) o;
              if (kind == HTML.Tag.HR) {
                return new CustomHrView(elem, hintHint.getTextForeground());
              }
            }
            return super.create(elem);
          }
        };

    HTMLEditorKit kit =
        new HTMLEditorKit() {
          @Override
          public ViewFactory getViewFactory() {
            return factory;
          }
        };
    pane.setEditorKit(kit);
    pane.setText(text);

    pane.setCaretPosition(0);
    pane.setEditable(false);

    if (hintHint.isOwnBorderAllowed()) {
      setBorder(pane);
      setColors(pane);
    } else {
      pane.setBorder(null);
    }

    if (!hintHint.isAwtTooltip()) {
      prefSizeWasComputed[0] = true;
    }

    final boolean opaque = hintHint.isOpaqueAllowed();
    pane.setOpaque(opaque);
    if (UIUtil.isUnderNimbusLookAndFeel() && !opaque) {
      pane.setBackground(UIUtil.TRANSPARENT_COLOR);
    } else {
      pane.setBackground(hintHint.getTextBackground());
    }

    return pane;
  }
  public JBLabel setCopyable(boolean copyable) {
    if (copyable ^ myEditorPane != null) {
      if (myEditorPane == null) {
        final JLabel ellipsisLabel = new JBLabel("...");
        myIconLabel = new JLabel(getIcon());
        myEditorPane =
            new JEditorPane() {
              @Override
              public void paint(Graphics g) {
                Dimension size = getSize();
                boolean paintEllipsis = getPreferredSize().width > size.width && !myMultiline;

                if (!paintEllipsis) {
                  super.paint(g);
                } else {
                  Dimension ellipsisSize = ellipsisLabel.getPreferredSize();
                  int endOffset = size.width - ellipsisSize.width;
                  try {
                    // do not paint half of the letter
                    endOffset = modelToView(viewToModel(new Point(endOffset, 0)) - 1).x;
                  } catch (BadLocationException ignore) {
                  }
                  Shape oldClip = g.getClip();
                  g.clipRect(0, 0, endOffset, size.height);

                  super.paint(g);
                  g.setClip(oldClip);

                  g.translate(endOffset, 0);
                  ellipsisLabel.setSize(ellipsisSize);
                  ellipsisLabel.paint(g);
                  g.translate(-endOffset, 0);
                }
              }
            };
        myEditorPane.addFocusListener(
            new FocusAdapter() {
              @Override
              public void focusLost(FocusEvent e) {
                if (myEditorPane == null) return;
                int caretPosition = myEditorPane.getCaretPosition();
                myEditorPane.setSelectionStart(caretPosition);
                myEditorPane.setSelectionEnd(caretPosition);
              }
            });
        myEditorPane.setContentType("text/html");
        myEditorPane.setEditable(false);
        myEditorPane.setBackground(UIUtil.TRANSPARENT_COLOR);
        myEditorPane.setOpaque(false);
        myEditorPane.setBorder(null);
        myEditorPane.setText(getText());
        checkMultiline();
        myEditorPane.setCaretPosition(0);
        UIUtil.putClientProperty(
            myEditorPane, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Collections.singleton(ellipsisLabel));
        updateStyle(myEditorPane);
        setLayout(new BorderLayout(getIconTextGap(), 0));
        add(myIconLabel, BorderLayout.WEST);
        add(myEditorPane, BorderLayout.CENTER);
      } else {
        removeAll();
        myEditorPane = null;
        myIconLabel = null;
      }
    }
    return this;
  }
Beispiel #11
0
 public void updateToolTipText(String s) {
   if (tooltipAllowedToUpdated) mouseHoverTextPanel.setText(s);
   mouseHoverTextPanel.setCaretPosition(0);
 }