Search in sources :

Example 36 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project processing by processing.

the class DetailPanel method addPaneComponents.

/**
   * Create the widgets for the header panel which is visible when the
   * library panel is not clicked.
   */
private void addPaneComponents() {
    setLayout(new BorderLayout());
    descriptionPane = new JTextPane();
    descriptionPane.setInheritsPopupMenu(true);
    // why would this ever be true?
    descriptionPane.setEditable(false);
    Insets margin = descriptionPane.getMargin();
    margin.bottom = 0;
    descriptionPane.setMargin(margin);
    descriptionPane.setContentType("text/html");
    setTextStyle(descriptionPane, "0.95em");
    descriptionPane.setOpaque(false);
    if (UIManager.getLookAndFeel().getID().equals("Nimbus")) {
        descriptionPane.setBackground(new Color(0, 0, 0, 0));
    }
    descriptionPane.setBorder(new EmptyBorder(4, 7, 7, 7));
    descriptionPane.setHighlighter(null);
    descriptionPane.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                // adding/removing the listener repeatedly
                if (isSelected()) {
                    if (enableHyperlinks && e.getURL() != null) {
                        Platform.openURL(e.getURL().toString());
                    }
                }
            }
        }
    });
    add(descriptionPane, BorderLayout.CENTER);
    JPanel updateBox = new JPanel();
    updateBox.setLayout(new BorderLayout());
    notificationLabel = new JLabel();
    notificationLabel.setInheritsPopupMenu(true);
    notificationLabel.setVisible(false);
    notificationLabel.setOpaque(false);
    notificationLabel.setFont(ManagerFrame.SMALL_PLAIN);
    {
        updateButton = new JButton("Update");
        updateButton.setInheritsPopupMenu(true);
        Dimension dim = new Dimension(BUTTON_WIDTH, updateButton.getPreferredSize().height);
        updateButton.setMinimumSize(dim);
        updateButton.setPreferredSize(dim);
        updateButton.setOpaque(false);
        updateButton.setVisible(false);
        updateButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                update();
            }
        });
    }
    updateBox.add(updateButton, BorderLayout.EAST);
    updateBox.add(notificationLabel, BorderLayout.WEST);
    updateBox.setBorder(new EmptyBorder(4, 7, 7, 7));
    updateBox.setOpaque(false);
    add(updateBox, BorderLayout.SOUTH);
    JPanel rightPane = new JPanel();
    rightPane.setInheritsPopupMenu(true);
    rightPane.setOpaque(false);
    rightPane.setLayout(new BoxLayout(rightPane, BoxLayout.Y_AXIS));
    rightPane.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
    add(rightPane, BorderLayout.EAST);
    barButtonCardLayout = new CardLayout();
    barButtonCardPane.setLayout(barButtonCardLayout);
    barButtonCardPane.setInheritsPopupMenu(true);
    barButtonCardPane.setOpaque(false);
    barButtonCardPane.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
    {
        installProgressBar = new JProgressBar();
        installProgressBar.setInheritsPopupMenu(true);
        installProgressBar.setStringPainted(true);
        resetInstallProgressBarState();
        Dimension dim = new Dimension(BUTTON_WIDTH, installProgressBar.getPreferredSize().height);
        installProgressBar.setPreferredSize(dim);
        installProgressBar.setMaximumSize(dim);
        installProgressBar.setMinimumSize(dim);
        installProgressBar.setOpaque(false);
        installProgressBar.setAlignmentX(CENTER_ALIGNMENT);
    }
    installRemoveButton = new JButton(" ");
    installRemoveButton.setInheritsPopupMenu(true);
    installRemoveButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String mode = installRemoveButton.getText();
            if (mode.equals(installText)) {
                install();
            } else if (mode.equals(removeText)) {
                remove();
            } else if (mode.equals(undoText)) {
                undo();
            }
        }
    });
    Dimension installButtonDimensions = installRemoveButton.getPreferredSize();
    installButtonDimensions.width = BUTTON_WIDTH;
    installRemoveButton.setPreferredSize(installButtonDimensions);
    installRemoveButton.setMaximumSize(installButtonDimensions);
    installRemoveButton.setMinimumSize(installButtonDimensions);
    installRemoveButton.setOpaque(false);
    installRemoveButton.setAlignmentX(CENTER_ALIGNMENT);
    JPanel barPane = new JPanel();
    barPane.setOpaque(false);
    JPanel buttonPane = new JPanel();
    buttonPane.setOpaque(false);
    buttonPane.add(installRemoveButton);
    barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT);
    barButtonCardPane.add(barPane, PROGRESS_BAR_CONSTRAINT);
    barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT);
    rightPane.add(barButtonCardPane);
    // Set the minimum size of this pane to be the sum of the height of the
    // progress bar and install button
    Dimension dim = new Dimension(BUTTON_WIDTH, installRemoveButton.getPreferredSize().height);
    rightPane.setMinimumSize(dim);
    rightPane.setPreferredSize(dim);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) EmptyBorder(javax.swing.border.EmptyBorder)

Example 37 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project android by JetBrains.

the class ServicePanelBuilder method addLink.

public HyperlinkLabel addLink(@NotNull String text, @NotNull final URI uri) {
    HyperlinkLabel linkLabel = new HyperlinkLabel(text);
    linkLabel.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            try {
                Desktop.getDesktop().browse(uri);
            } catch (IOException e1) {
            // Don't care
            }
        }
    });
    addComponent(linkLabel);
    return linkLabel;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) IOException(java.io.IOException) HyperlinkLabel(com.intellij.ui.HyperlinkLabel)

Example 38 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project android by JetBrains.

the class ManifestPanel method createDetailsPane.

private JEditorPane createDetailsPane(@NotNull final AndroidFacet facet) {
    JEditorPane details = new JEditorPane();
    details.setMargin(JBUI.insets(5));
    details.setContentType(UIUtil.HTML_MIME);
    details.setEditable(false);
    details.setFont(myDefaultFont);
    details.setBackground(myBackgroundColor);
    HyperlinkListener hyperLinkListener = e -> {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            String url = e.getDescription();
            myHtmlLinkManager.handleUrl(url, facet.getModule(), null, null, null);
        }
    };
    details.addHyperlinkListener(hyperLinkListener);
    return details;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) FN_BUILD_GRADLE(com.android.SdkConstants.FN_BUILD_GRADLE) NamedObject(com.android.tools.idea.gradle.parser.NamedObject) HyperlinkEvent(javax.swing.event.HyperlinkEvent) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) IdeActions(com.intellij.openapi.actionSystem.IdeActions) PsiManager(com.intellij.psi.PsiManager) JBMenuItem(com.intellij.openapi.ui.JBMenuItem) Matcher(java.util.regex.Matcher) JBUI(com.intellij.util.ui.JBUI) HtmlLinkManager(com.android.tools.idea.rendering.HtmlLinkManager) MouseAdapter(java.awt.event.MouseAdapter) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) SourcePosition(com.android.ide.common.blame.SourcePosition) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) MouseListener(java.awt.event.MouseListener) XmlTag(com.intellij.psi.xml.XmlTag) SourceFile(com.android.ide.common.blame.SourceFile) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) XmlHighlighterColors(com.intellij.openapi.editor.XmlHighlighterColors) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) com.intellij.ui(com.intellij.ui) Sets(com.google.common.collect.Sets) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) JBScrollPane(com.intellij.ui.components.JBScrollPane) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EXPLODED_AAR(com.android.tools.idea.gradle.project.model.AndroidModuleModel.EXPLODED_AAR) IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) javax.swing.tree(javax.swing.tree) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) SdkConstants(com.android.SdkConstants) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) ModuleManager(com.intellij.openapi.module.ModuleManager) PositionXmlParser(com.android.utils.PositionXmlParser) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) MergingReport(com.android.manifmerger.MergingReport) AndroidLibrary(com.android.builder.model.AndroidLibrary) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ActionManager(com.intellij.openapi.actionSystem.ActionManager) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TreeSelectionListener(javax.swing.event.TreeSelectionListener) BuildFileKey(com.android.tools.idea.gradle.parser.BuildFileKey) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) TreeUtil(com.intellij.util.ui.tree.TreeUtil) HyperlinkListener(javax.swing.event.HyperlinkListener) org.w3c.dom(org.w3c.dom) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) MavenCoordinates(com.android.builder.model.MavenCoordinates) HtmlBuilder(com.android.utils.HtmlBuilder) MergedManifest(com.android.tools.idea.model.MergedManifest) AnAction(com.intellij.openapi.actionSystem.AnAction) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) java.awt(java.awt) CommandProcessor(com.intellij.openapi.command.CommandProcessor) XmlNode(com.android.manifmerger.XmlNode) Actions(com.android.manifmerger.Actions) GradleUtil(com.android.tools.idea.gradle.util.GradleUtil) javax.swing(javax.swing) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 39 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project intellij-plugins by JetBrains.

the class FlexBaseRunner method checkDebuggerFromSdk4.

private static void checkDebuggerFromSdk4(final Project project, final RunProfile runProfile, final FlashRunnerParameters params, final FlexBuildConfiguration bc) {
    final Sdk sdk = bc.getSdk();
    assert sdk != null;
    final Sdk sdkForDebugger = FlexDebugProcess.getDebuggerSdk(params.getDebuggerSdkRaw(), sdk);
    if (!FlexSdkUtils.isAirSdkWithoutFlex(sdk) && StringUtil.compareVersionNumbers(sdkForDebugger.getVersionString(), "4") < 0) {
        final HyperlinkListener listener = new HyperlinkAdapter() {

            @Override
            protected void hyperlinkActivated(final HyperlinkEvent e) {
                if ("RunConfiguration".equals(e.getDescription())) {
                    for (RunnerAndConfigurationSettings configuration : RunManager.getInstance(project).getConfigurationSettingsList(((RunConfiguration) runProfile).getType())) {
                        if (configuration.getConfiguration() == runProfile) {
                            RunDialog.editConfiguration(project, configuration, FlexBundle.message("edit.configuration.title"));
                            break;
                        }
                    }
                }
            }
        };
        final String message = FlexBundle.message("flex.sdk.3.mac.debug.problem", sdkForDebugger.getVersionString());
        ToolWindowManager.getInstance(project).notifyByBalloon(ToolWindowId.DEBUG, MessageType.WARNING, message, null, listener);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) Sdk(com.intellij.openapi.projectRoots.Sdk) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter)

Example 40 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project intellij-community by JetBrains.

the class SheetController method createSheetPanel.

private JPanel createSheetPanel(String title, String message, JButton[] buttons) {
    JPanel sheetPanel = new JPanel() {

        @Override
        protected void paintComponent(@NotNull Graphics g2d) {
            final Graphics2D g = (Graphics2D) g2d.create();
            super.paintComponent(g);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getSheetAlpha()));
            g.setColor(new JBColor(Gray._230, UIUtil.getPanelBackground()));
            Rectangle2D dialog = new Rectangle2D.Double(SHADOW_BORDER, 0, SHEET_WIDTH, SHEET_HEIGHT);
            paintShadow(g);
            // draw the sheet background
            if (UIUtil.isUnderDarcula()) {
                g.fillRoundRect((int) dialog.getX(), (int) dialog.getY() - 5, (int) dialog.getWidth(), (int) (5 + dialog.getHeight()), 5, 5);
            } else {
                //todo make bottom corners
                g.fill(dialog);
            }
            paintShadowFromParent(g);
        }
    };
    sheetPanel.setOpaque(false);
    sheetPanel.setLayout(null);
    JPanel ico = new JPanel() {

        @Override
        protected void paintComponent(@NotNull Graphics g) {
            super.paintComponent(g);
            myIcon.paintIcon(this, g, 0, 0);
        }
    };
    JEditorPane headerLabel = new JEditorPane();
    headerLabel.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    headerLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    headerLabel.setEditable(false);
    headerLabel.setContentType("text/html");
    headerLabel.setSize(250, Short.MAX_VALUE);
    headerLabel.setText(title);
    headerLabel.setSize(250, headerLabel.getPreferredSize().height);
    headerLabel.setOpaque(false);
    headerLabel.setFocusable(false);
    sheetPanel.add(headerLabel);
    headerLabel.repaint();
    messageTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    Font font = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
    messageTextPane.setFont(font);
    messageTextPane.setEditable(false);
    messageTextPane.setContentType("text/html");
    messageTextPane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent he) {
            if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        URL url = he.getURL();
                        if (url != null) {
                            Desktop.getDesktop().browse(url.toURI());
                        } else {
                            LOG.warn("URL is null; HyperlinkEvent: " + he.toString());
                        }
                    } catch (IOException | URISyntaxException e) {
                        LOG.error(e);
                    }
                }
            }
        }
    });
    FontMetrics fontMetrics = sheetPanel.getFontMetrics(font);
    int widestWordWidth = 250;
    String[] words = (message == null) ? ArrayUtil.EMPTY_STRING_ARRAY : message.split(SPACE_OR_LINE_SEPARATOR_PATTERN);
    for (String word : words) {
        widestWordWidth = Math.max(fontMetrics.stringWidth(word), widestWordWidth);
    }
    messageTextPane.setSize(widestWordWidth, Short.MAX_VALUE);
    messageTextPane.setText(handleBreaks(message));
    messageArea.setSize(widestWordWidth, messageTextPane.getPreferredSize().height);
    SHEET_WIDTH = Math.max(LEFT_SHEET_OFFSET + widestWordWidth + RIGHT_OFFSET, SHEET_WIDTH);
    messageTextPane.setSize(messageArea);
    messageTextPane.setOpaque(false);
    messageTextPane.setFocusable(false);
    sheetPanel.add(messageTextPane);
    messageTextPane.repaint();
    ico.setOpaque(false);
    ico.setSize(new Dimension(AllIcons.Logo_welcomeScreen.getIconWidth(), AllIcons.Logo_welcomeScreen.getIconHeight()));
    ico.setLocation(LEFT_SHEET_PADDING, TOP_SHEET_PADDING);
    sheetPanel.add(ico);
    headerLabel.setLocation(LEFT_SHEET_OFFSET, TOP_SHEET_PADDING);
    messageTextPane.setLocation(LEFT_SHEET_OFFSET, TOP_SHEET_PADDING + headerLabel.getPreferredSize().height + GAP_BETWEEN_LINES);
    SHEET_HEIGHT = TOP_SHEET_PADDING + headerLabel.getPreferredSize().height + GAP_BETWEEN_LINES + messageArea.height + GAP_BETWEEN_LINES;
    if (myDoNotAskOption != null) {
        layoutDoNotAskCheckbox(sheetPanel);
    }
    layoutWithAbsoluteLayout(buttons, sheetPanel);
    int BOTTOM_SHEET_PADDING = 10;
    SHEET_HEIGHT += BOTTOM_SHEET_PADDING;
    if (SHEET_HEIGHT < SHEET_MINIMUM_HEIGHT) {
        SHEET_HEIGHT = SHEET_MINIMUM_HEIGHT;
        shiftButtonsToTheBottom(SHEET_MINIMUM_HEIGHT - SHEET_HEIGHT);
    }
    sheetPanel.setFocusCycleRoot(true);
    recalculateShadow();
    sheetPanel.setSize(SHEET_NC_WIDTH, SHEET_NC_HEIGHT);
    return sheetPanel;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) Rectangle2D(java.awt.geom.Rectangle2D) NotNull(org.jetbrains.annotations.NotNull) URL(java.net.URL) HyperlinkListener(javax.swing.event.HyperlinkListener) JBColor(com.intellij.ui.JBColor)

Aggregations

HyperlinkListener (javax.swing.event.HyperlinkListener)59 HyperlinkEvent (javax.swing.event.HyperlinkEvent)57 JEditorPane (javax.swing.JEditorPane)15 URL (java.net.URL)11 JScrollPane (javax.swing.JScrollPane)9 JPanel (javax.swing.JPanel)8 JTextPane (javax.swing.JTextPane)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Dimension (java.awt.Dimension)6 IOException (java.io.IOException)6 NotNull (org.jetbrains.annotations.NotNull)6 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)5 URI (java.net.URI)5 HTMLDocument (javax.swing.text.html.HTMLDocument)5 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)5 Project (com.intellij.openapi.project.Project)4 BorderLayout (java.awt.BorderLayout)4 ActionEvent (java.awt.event.ActionEvent)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 MouseEvent (java.awt.event.MouseEvent)3