Exemple #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;
  }
  private void setDataInternal(
      SmartPsiElementPointer element, String text, final Rectangle viewRect, boolean skip) {
    boolean justShown = false;

    myElement = element;

    if (!myIsShown && myHint != null) {
      myEditorPane.setText(text);
      applyFontSize();
      myManager.showHint(myHint);
      myIsShown = justShown = true;
    }

    if (!justShown) {
      myEditorPane.setText(text);
      applyFontSize();
    }

    if (!skip) {
      myText = text;
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            myEditorPane.scrollRectToVisible(viewRect);
          }
        });
  }
  public void showDescription(InspectionTool tool) {
    if (tool.getShortName().length() == 0) {
      showEmpty();
      return;
    }
    @NonNls StringBuffer page = new StringBuffer();
    page.append("<table border='0' cellspacing='0' cellpadding='0' width='100%'>");
    page.append("<tr><td colspan='2'>");
    HTMLComposer.appendHeading(
        page, InspectionsBundle.message("inspection.tool.in.browser.id.title"));
    page.append("</td></tr>");
    page.append("<tr><td width='37'></td>" + "<td>");
    page.append(tool.getShortName());
    page.append("</td></tr>");
    page.append("<tr height='10'></tr>");
    page.append("<tr><td colspan='2'>");
    HTMLComposer.appendHeading(
        page, InspectionsBundle.message("inspection.tool.in.browser.description.title"));
    page.append("</td></tr>");
    page.append("<tr><td width='37'></td>" + "<td>");
    @NonNls final String underConstruction = "<b>" + UNDER_CONSTRUCTION + "</b></html>";
    try {
      @NonNls String description = tool.loadDescription();
      if (description == null) {
        description = underConstruction;
      }
      page.append(UIUtil.getHtmlBody(description));

      page.append("</td></tr></table>");
      myHTMLViewer.setText(XmlStringUtil.wrapInHtml(page));
      setupStyle();
    } finally {
      myCurrentEntity = null;
    }
  }
 private void jbInit() throws Exception {
   border1 = BorderFactory.createEmptyBorder(20, 20, 20, 20);
   contentPane.setBorder(border1);
   contentPane.setLayout(borderLayout1);
   controlsPane.setLayout(gridLayout1);
   gridLayout1.setColumns(1);
   gridLayout1.setHgap(10);
   gridLayout1.setRows(0);
   gridLayout1.setVgap(10);
   okButton.setVerifyInputWhenFocusTarget(true);
   okButton.setMnemonic('O');
   okButton.setText("OK");
   buttonsPane.setLayout(flowLayout1);
   flowLayout1.setAlignment(FlowLayout.CENTER);
   messagePane.setEditable(false);
   messagePane.setText("");
   borderLayout1.setHgap(10);
   borderLayout1.setVgap(10);
   this.setTitle("Subscription Authorization");
   this.getContentPane().add(contentPane, BorderLayout.CENTER);
   contentPane.add(controlsPane, BorderLayout.SOUTH);
   controlsPane.add(responsesComboBox, null);
   controlsPane.add(buttonsPane, null);
   buttonsPane.add(okButton, null);
   contentPane.add(messageScrollPane, BorderLayout.CENTER);
   messageScrollPane.getViewport().add(messagePane, null);
 }
 public void filterPacks() {
   packPanels.clear();
   packs.removeAll();
   currentPacks.clear();
   packMapping.clear();
   int counter = 0;
   selectedPack = 0;
   packInfo.setText("");
   // all removed, repaint
   packs.repaint();
   // not really needed
   // modPacksAdded = false;
   for (ModPack pack : ModPack.getPackArray()) {
     if (filterForTab(pack)
         && mcVersionCheck(pack)
         && avaliabilityCheck(pack)
         && textSearch(pack)) {
       currentPacks.put(counter, pack);
       packMapping.put(counter, pack.getIndex());
       addPack(pack);
       counter++;
     }
   }
   updateDatas();
   updatePacks();
 }
  private void setSubscriberDetails(
      String subscriberName, String subscriberAddress, String message) {
    this.name = subscriberName;
    this.address = subscriberAddress;

    Color color = messagePane.getForeground();

    messagePane.setText(
        "<FONT COLOR=\"#"
            + Integer.toHexString(color.getRGB()).substring(2)
            + "\">"
            + messageString1
            + "<p>"
            + namePrefix
            + name
            + nameSuffix
            + "<br>"
            + addressPrefix
            + address
            + addressSuffix
            + "<p>"
            + ((message != null && message.trim().length() > 0)
                ? messagePrefix + message + messageSuffix + "<p>"
                : "")
            + messageString2
            + "</FONT>");
  }
 /**
  * Called when the selection changed in the tree. Loads the selected certificate.
  *
  * @param e the event
  */
 private void valueChangedPerformed(TreeSelectionEvent e) {
   Object o = e.getNewLeadSelectionPath().getLastPathComponent();
   if (o instanceof DefaultMutableTreeNode) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
     infoTextPane.setText(toString(node.getUserObject()));
   }
 }
Exemple #8
0
  /** standard constructor */
  public AboutDialog(JFrame frame) {
    super(frame, true);

    getConfDbVersion(); // load info from confdb.version file
    getContactPerson(); // load info from confdb.version file

    setTitle("About ConfDbGUI");

    setContentPane(initComponents());

    String txt =
        "<p>Thank you for using <b>ConfDbGUI</b>,"
            + "a CMS tool to create and manage "
            + "CMSSW job configurations based on a "
            + "relational database.</p>"
            + "This software was originally developed "
            + "by Philipp Schieferdecker and is currently "
            + "maintained by Raul Jimenez Estupinan "
            + "with contributions from Ulf Behrens, "
            + "Jonathan Hollar, Vasundhara Chetluru "
            + "and Martin Gruenewald. "
            + "<p>For feedback please contact me at "
            + "<b>"
            + contactEmail
            + "</b>.</p>"
            + "<p>Find documentation on the web under "
            + "<b>https://twiki.cern.ch/twiki/bin/view/CMS/EvfConfDBGUI</b>.</p>";

    jTextFieldApplication.setText("ConfDbGUI");
    // jTextFieldVersion.setText("V01-05-82"); // Change in confdb.version file!

    jEditorPaneAbout.setContentType("text/html");
    jEditorPaneAbout.setText(txt);
  }
 private void showSubscriptionInfo(
     final ApplicationSubscriptionInfo.ApplicationSendingSubscription clientSendingSubscription) {
   _receiverList.clearSelection();
   _label.setText(
       "<html>"
           + "<b>Objekt: </b>"
           + clientSendingSubscription.getObject()
           + "<br>"
           + "<b>Attributgruppe: </b>"
           + clientSendingSubscription.getUsage().getAttributeGroup()
           + "<br>"
           + "<b>Aspekt: </b>"
           + clientSendingSubscription.getUsage().getAspect()
           + "<br>"
           + "<b>Simulationsvariante: </b>"
           + clientSendingSubscription.getSimVar()
           + "<br>"
           + "<b>Typ: </b>"
           + (clientSendingSubscription.isSource() ? "Quelle" : "Sender")
           + "<br>"
           + "<b>Unterstützt Sendesteuerung: </b>"
           + (clientSendingSubscription.isRequestSupported() ? "Ja" : "Nein")
           + "<br>"
           + "<b>Status: </b>"
           + stateToString(clientSendingSubscription.getState()));
 }
 private void showSubscriptionInfo(
     final ApplicationSubscriptionInfo.ApplicationReceivingSubscription
         clientReceivingSubscription) {
   _senderList.clearSelection();
   _label.setText(
       "<html>"
           + "<b>Objekt: </b>"
           + clientReceivingSubscription.getObject()
           + "<br>"
           + "<b>Attributgruppe: </b>"
           + clientReceivingSubscription.getUsage().getAttributeGroup()
           + "<br>"
           + "<b>Aspekt: </b>"
           + clientReceivingSubscription.getUsage().getAspect()
           + "<br>"
           + "<b>Simulationsvariante: </b>"
           + clientReceivingSubscription.getSimVar()
           + "<br>"
           + "<b>Typ: </b>"
           + (clientReceivingSubscription.isDrain() ? "Senke" : "Empfänger")
           + "<br>"
           + "<b>Nachgelieferte Daten: </b>"
           + (clientReceivingSubscription.isDelayed() ? "Ja" : "Nein")
           + "<br>"
           + "<b>Nur Änderungen: </b>"
           + (clientReceivingSubscription.isDelta() ? "Ja" : "Nein")
           + "<br>"
           + "<b>Status: </b>"
           + stateToString(clientReceivingSubscription.getState()));
 }
 @Override
 public void setText(String text) {
   super.setText(text);
   if (myEditorPane != null) {
     myEditorPane.setText(getText());
     updateStyle(myEditorPane);
     checkMultiline();
   }
 }
 public static void clearAll(JEditorPane txt) {
   try {
     txt.setText("");
     HTMLEditorKit kit = (HTMLEditorKit) txt.getEditorKit();
     HTMLDocument doc = (HTMLDocument) txt.getDocument();
     kit.insertHTML(
         doc, 0, "<body style=\"font-family:'Courier New';font-size: 12pt;\">", 0, 0, null);
   } catch (Exception e) {
   }
 }
  protected void initDialog() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.setLayout(new GridLayout(3, 2));
    this.add(new JLabel("Server address:"));
    serverAddress = new JEditorPane();
    serverAddress.setText("127.0.0.1");
    this.add(serverAddress);
    this.add(new JLabel("Server port:"));
    serverPort = new JEditorPane();
    serverPort.setText("23456");
    this.add(serverPort);

    ok_button = new JButton("OK");
    ok_button.addActionListener(this);
    this.add(ok_button);
    cancel_button = new JButton("Cancel");
    cancel_button.addActionListener(this);
    this.add(cancel_button);
    this.setResizable(true);
  }
Exemple #14
0
 public boolean setNcml(String cmd) {
   if (cmd.endsWith(".xml") || cmd.endsWith(".ncml")) {
     if (!cmd.startsWith("http:") && !cmd.startsWith("file:")) cmd = "file:" + cmd;
     ncmlLocation = cmd;
     String text = IO.readURLcontents(cmd);
     editor.setText(text);
   } else {
     writeNcml(cmd);
   }
   return true;
 }
  @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;
  }
  // 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));
      }
    }
  }
Exemple #17
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 void doReplaceAll() {
    EditWindow currentWindow = editor.getActiveWindow();

    if (currentWindow == null || getFindTextField().getText().length() == 0) {
      // launch error dialog?
      return;
    }
    JEditorPane editorPane = currentWindow.getEditorPane();
    String text = editorPane.getText();

    String replacement = getReplaceTextField().getText();

    editorPane.setText(getCurrentPattern().matcher(text).replaceAll(replacement));
  }
Exemple #19
0
  public void reload() throws Exception {
    if (saved) {
      long a = file.lastModified();
      if (a > file_lastModified) {
        sem.fireEvent("stop", null, null);

        text.setText(U.slurp(file));
        saved = true;

        sem.pushEvent("updateTitle", this, null);
        file_lastModified = a;
      }
    }
  }
Exemple #20
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      System.exit(-1);
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      System.exit(-1);
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      System.exit(-1);
    }
    // do the replacement.

    for (i = 0; i < COMPONENTS; i++) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "$$$" + (i + 1);
      // get the position of the search string in the content string.
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(str1);
      strBuf.replace(posFound, posFound + str1.length(), sliderValue);
      strContent = new String(strBuf);
    }
    textPane.setText(strContent);
  }
Exemple #21
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();
    }
  }
    TextPanel(String file) {
      super(new BorderLayout());

      JEditorPane text = new JEditorPane();

      try {
        text.setPage(TextPanel.this.getClass().getResource(file));
      } catch (Exception e) {
        text.setText("Error loading '" + file + "'");
        e.printStackTrace();
      }

      text.setEditable(false);

      JScrollPane scrollPane = new JScrollPane(text);
      Dimension dim = new Dimension();
      dim.width = 450;
      dim.height = 200;
      scrollPane.setPreferredSize(dim);
      TextPanel.this.add(BorderLayout.CENTER, scrollPane);
    }
  private void updateList(final List<WCInfo> infoList) {
    myPanel.removeAll();
    final Insets nullIndent = new Insets(1, 3, 1, 0);
    final GridBagConstraints gb =
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(2, 2, 0, 0),
            0,
            0);
    gb.insets.left = 4;
    myPanel.add(myRefreshLabel, gb);
    gb.insets.left = 1;

    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    final Insets topIndent = new Insets(10, 3, 0, 0);
    for (final WCInfo wcInfo : infoList) {
      final VirtualFile vf = lfs.refreshAndFindFileByIoFile(new File(wcInfo.getPath()));
      final VirtualFile root = (vf == null) ? wcInfo.getVcsRoot() : vf;

      final JEditorPane editorPane = new JEditorPane(UIUtil.HTML_MIME, "");
      editorPane.setEditable(false);
      editorPane.setFocusable(true);
      editorPane.setBackground(UIUtil.getPanelBackground());
      editorPane.addHyperlinkListener(
          new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
              if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (CONFIGURE_BRANCHES.equals(e.getDescription())) {
                  if (!checkRoot(root, wcInfo.getPath(), " invoke Configure Branches")) return;
                  BranchConfigurationDialog.configureBranches(myProject, root, true);
                } else if (FIX_DEPTH.equals(e.getDescription())) {
                  final int result =
                      Messages.showOkCancelDialog(
                          myVcs.getProject(),
                          "You are going to checkout into '"
                              + wcInfo.getPath()
                              + "' with 'infinity' depth.\n"
                              + "This will update your working copy to HEAD revision as well.",
                          "Set working copy infinity depth",
                          Messages.getWarningIcon());
                  if (result == 0) {
                    // update of view will be triggered by roots changed event
                    SvnCheckoutProvider.checkout(
                        myVcs.getProject(),
                        new File(wcInfo.getPath()),
                        wcInfo.getRootUrl(),
                        SVNRevision.HEAD,
                        SVNDepth.INFINITY,
                        false,
                        null,
                        wcInfo.getFormat());
                  }
                } else if (CHANGE_FORMAT.equals(e.getDescription())) {
                  changeFormat(wcInfo);
                } else if (MERGE_FROM.equals(e.getDescription())) {
                  if (!checkRoot(root, wcInfo.getPath(), " invoke Merge From")) return;
                  mergeFrom(wcInfo, root, editorPane);
                }
              }
            }

            private boolean checkRoot(
                VirtualFile root, final String path, final String actionName) {
              if (root == null) {
                Messages.showWarningDialog(
                    myProject, "Invalid working copy root: " + path, "Can not " + actionName);
                return false;
              }
              return true;
            }
          });
      editorPane.setBorder(null);
      editorPane.setText(formatWc(wcInfo));

      final JPanel copyPanel = new JPanel(new GridBagLayout());

      final GridBagConstraints gb1 =
          new GridBagConstraints(
              0,
              0,
              1,
              1,
              0,
              0,
              GridBagConstraints.NORTHWEST,
              GridBagConstraints.NONE,
              nullIndent,
              0,
              0);
      gb1.insets.top = 1;
      gb1.gridwidth = 3;

      gb.insets = topIndent;
      gb.fill = GridBagConstraints.HORIZONTAL;
      ++gb.gridy;

      final JPanel contForCopy = new JPanel(new BorderLayout());
      contForCopy.add(copyPanel, BorderLayout.WEST);
      myPanel.add(contForCopy, gb);

      copyPanel.add(editorPane, gb1);
      gb1.insets = nullIndent;
    }

    myPanel.revalidate();
    myPanel.repaint();
  }
Exemple #24
0
 public void display(CavityDBObject obj) {
   String str = obj.asString();
   // System.out.println(String.format("Displaying:\n%s", str));
   editorPane.setText(str);
   revalidate();
 }
 public void setText(String text) {
   editor.setText(text);
 }
  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;
  }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }
Exemple #28
0
  /** Construct a new "about&hellip;" dialog */
  public DialogAbout(MDIManager mdimgr) {

    buttonOk = new JButton(localize("button.OK"));
    buttonOk.addActionListener(this);

    JPanel buttonPanel = new JPanel(new FlowLayout(), false);
    buttonPanel.add(buttonOk);

    JPanel logoPanel = new JPanel(new FlowLayout(), false);
    logoPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    logoPanel.add(PEToolKit.createJLabel("Frankenstein"));

    JPanel infoPanel = new JPanel(new GridLayout(9, 1, 5, 5), true);
    infoPanel.setBorder(new EmptyBorder(10, 60, 10, 10));
    infoPanel.add(
        new JLabel("jPicEdt " + Version.getVersion() + " Built " + Version.getBuildDate()));
    infoPanel.add(new JLabel(localize("about.APictureEditorFor")));
    final String[] addressLines = {
      "(c) Sylvain Reynal",
      "É.N.S.É.A. - Dept. of Physics",
      "6, avenue du Ponceau",
      "F-95014 CERGY Cedex",
      "Fax: +33 (0) 130 736 667",
      "*****@*****.**",
      "http://www.jpicedt.org"
    };
    for (String addressLine : addressLines) infoPanel.add(new JLabel(addressLine));

    JTabbedPane caveatPanel = new JTabbedPane();
    String[] tabKeys = {"license.lines", "license.thirdparty.lines"};
    for (String tabKey : tabKeys) {
      JEditorPane caveatTA = new JEditorPane();
      caveatTA.setContentType("text/html; charset=" + localize(tabKey + ".encoding"));
      caveatTA.setEditable(false);
      caveatTA.setPreferredSize(new Dimension(485, 300));
      JScrollPane scrollCaveat = new JScrollPane(caveatTA);
      caveatTA.setText(localize(tabKey));
      caveatPanel.addTab(localize(tabKey + ".tabname"), null, scrollCaveat, null);
    }

    caveatPanel.setBorder(BorderFactory.createEtchedBorder());

    JPanel upperPanel = new JPanel(new BorderLayout(), false);
    upperPanel.add(logoPanel, BorderLayout.WEST);
    upperPanel.add(infoPanel, BorderLayout.CENTER);
    upperPanel.add(caveatPanel, BorderLayout.SOUTH);
    upperPanel.setBorder(BorderFactory.createEtchedBorder());

    JPanel contentPane = new JPanel(new BorderLayout(5, 5));
    contentPane.add(upperPanel, BorderLayout.NORTH);
    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    String title = localize("about.AboutPicEdt") + " " + Version.getVersion();
    boolean modal = true;
    frame = mdimgr.createDialog(title, modal, contentPane);
    frame.setResizable(true);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    Dimension dlgSize = frame.getPreferredSize();
    frame.setSize(dlgSize);

    // this.pack();
    frame.setVisible(true);
  }
  protected void createAndShowGUI() {
    System.setProperty("swing.defaultlaf", UIManager.getSystemLookAndFeelClassName());

    image = DavGatewayTray.loadImage("tray.png");
    image2 = DavGatewayTray.loadImage(AwtGatewayTray.TRAY_ACTIVE_PNG);
    inactiveImage = DavGatewayTray.loadImage(AwtGatewayTray.TRAY_INACTIVE_PNG);

    mainFrame = new JFrame();
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setTitle(BundleMessage.format("UI_DAVMAIL_GATEWAY"));
    mainFrame.setIconImage(image);

    JPanel errorPanel = new JPanel();
    errorPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_LAST_MESSAGE")));
    errorPanel.setLayout(new BoxLayout(errorPanel, BoxLayout.X_AXIS));
    errorArea = new JTextPane();
    errorArea.setEditable(false);
    errorArea.setBackground(mainFrame.getBackground());
    errorLabel = new JLabel();
    errorPanel.add(errorLabel);
    errorPanel.add(errorArea);

    JPanel messagePanel = new JPanel();
    messagePanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_LAST_LOG")));
    messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.X_AXIS));

    messageArea = new JTextPane();
    messageArea.setText(BundleMessage.format("LOG_STARTING_DAVMAIL"));
    messageArea.setEditable(false);
    messageArea.setBackground(mainFrame.getBackground());
    messagePanel.add(messageArea);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.add(errorPanel);
    mainPanel.add(messagePanel);
    mainFrame.add(mainPanel);

    aboutFrame = new AboutFrame();
    settingsFrame = new SettingsFrame();
    buildMenu();

    mainFrame.setMinimumSize(new Dimension(400, 180));
    mainFrame.pack();
    // workaround MacOSX
    if (mainFrame.getSize().width < 400 || mainFrame.getSize().height < 180) {
      mainFrame.setSize(
          Math.max(mainFrame.getSize().width, 400), Math.max(mainFrame.getSize().height, 180));
    }
    // center frame
    mainFrame.setLocation(
        mainFrame.getToolkit().getScreenSize().width / 2 - mainFrame.getSize().width / 2,
        mainFrame.getToolkit().getScreenSize().height / 2 - mainFrame.getSize().height / 2);
    mainFrame.setVisible(true);

    // display settings frame on first start
    if (Settings.isFirstStart()) {
      settingsFrame.setVisible(true);
      settingsFrame.toFront();
      settingsFrame.requestFocus();
    }
  }
  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;
  }