javax.swing.event.HyperlinkListener Java Examples

The following examples show how to use javax.swing.event.HyperlinkListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditorPaneDemo.java    From Darcula with Apache License 2.0 6 votes vote down vote up
private HyperlinkListener createHyperLinkListener() {
    return new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (e instanceof HTMLFrameHyperlinkEvent) {
                    ((HTMLDocument) html.getDocument()).processHTMLFrameHyperlinkEvent(
                            (HTMLFrameHyperlinkEvent) e);
                } else {
                    try {
                        html.setPage(e.getURL());
                    } catch (IOException ioe) {
                        System.out.println("IOE: " + ioe);
                    }
                }
            }
        }
    };
}
 
Example #2
Source File: GHelpHTMLEditorKit.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void install(JEditorPane c) {
	super.install(c);

	delegateListeners = c.getHyperlinkListeners();
	for (HyperlinkListener listener : delegateListeners) {
		c.removeHyperlinkListener(listener);
	}

	resolverHyperlinkListener = new ResolverHyperlinkListener();
	c.addHyperlinkListener(resolverHyperlinkListener);

	// add a listener to report trace information
	c.addPropertyChangeListener(new PropertyChangeListener() {
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			String propertyName = evt.getPropertyName();
			if ("page".equals(propertyName)) {
				Msg.trace(this, "Page loaded: " + evt.getNewValue());
			}
		}
	});
}
 
Example #3
Source File: GHelpHTMLEditorKit.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {

	if (delegateListeners == null) {
		return;
	}

	if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
		Msg.trace(this, "Link activated: " + e.getURL());
		e = validateURL(e);
		Msg.trace(this, "Validated event: " + e.getURL());
	}

	for (HyperlinkListener listener : delegateListeners) {
		listener.hyperlinkUpdate(e);
	}
}
 
Example #4
Source File: LiMeUserAgreementFrame.java    From LiMe with MIT License 6 votes vote down vote up
private HyperlinkListener createHyperLinkListener() {
    return e -> {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            if (e instanceof HTMLFrameHyperlinkEvent) {
                ((HTMLDocument) htmlPane.getDocument()).processHTMLFrameHyperlinkEvent(
                        (HTMLFrameHyperlinkEvent) e);
            } else {
                try {
                    htmlPane.setPage(e.getURL());
                } catch (IOException ioe) {
                    System.out.println("IOE: " + ioe);
                }
            }
        }
    };
}
 
Example #5
Source File: BrowserUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static HyperlinkListener createHyperlinkListener() {
    return new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent hlevt) {
            if (HyperlinkEvent.EventType.ACTIVATED == hlevt.getEventType()) {
                final URL url = hlevt.getURL();
                if (url != null) {
                    try {
                        openBrowser(url.toURI());
                    } catch (URISyntaxException e) {
                        LogManager.log(e);
                    }
                }
            }
        }
    };
}
 
Example #6
Source File: ShowNotifications.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static JTextPane createInfoPanel(String notification) {
    JTextPane balloon = new JTextPane();
    balloon.setContentType("text/html");
    String text = getDetails(notification).replaceAll("(\r\n|\n|\r)", "<br>");
    balloon.setText(text);
    balloon.setOpaque(false);
    balloon.setEditable(false);
    balloon.setBorder(new EmptyBorder(0, 0, 0, 0));


    if (UIManager.getLookAndFeel().getID().equals("Nimbus")) {
        //#134837
        //http://forums.java.net/jive/thread.jspa?messageID=283882
        balloon.setBackground(new Color(0, 0, 0, 0));
    }

    balloon.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                URLDisplayer.getDefault().showURL(e.getURL());
            }
        }
    });
    return balloon;
}
 
Example #7
Source File: JTextPaneTableCellRenderer.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public JTextPaneTableCellRenderer() {
  textPane.setContentType("text/html");
  textPane.setEditable(false);
  textPane.setOpaque(true);
  textPane.setBorder(null);

  textPane.setForeground(UIManager.getColor("Table.selectionForeground"));
  textPane.setBackground(UIManager.getColor("Table.selectionBackground"));

  Font font = UIManager.getFont("Label.font");
  String bodyRule =
      "body { font-family: " + font.getFamily() + "; " + "font-size: "
          + font.getSize() + "pt; "
          + (font.isBold() ? "font-weight: bold;" : "") + "}";
  ((HTMLDocument)textPane.getDocument()).getStyleSheet().addRule(bodyRule);

  textPane.addHyperlinkListener(new HyperlinkListener() {

    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
          MainFrame.getInstance().showHelpFrame(e.getURL().toString(), "CREOLE Plugin Manager");
    }
  });
}
 
Example #8
Source File: Navigator.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JComponent createComponent() {
    pane.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == EventType.ACTIVATED) {
                location = e.getURL().toExternalForm();
                openLocation();
            }
        }
    });

    pane.setEditable(false);

    scrollPane = new JScrollPane();
    scrollPane.setViewportView(this.pane);
    return scrollPane;
}
 
Example #9
Source File: Browser.java    From scelight with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new {@link Browser}.
 */
public Browser() {
	setEditable( false );
	setContentType( "text/html" );
	
	addHyperlinkListener( new HyperlinkListener() {
		@Override
		public void hyperlinkUpdate( final HyperlinkEvent event ) {
			if ( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) {
				if ( event.getURL() != null )
					LEnv.UTILS_IMPL.get().showURLInBrowser( event.getURL() );
			} else if ( event.getEventType() == HyperlinkEvent.EventType.ENTERED ) {
				if ( event.getURL() != null )
					setToolTipText( LUtils.urlToolTip( event.getURL() ) );
			} else if ( event.getEventType() == HyperlinkEvent.EventType.EXITED )
				setToolTipText( null );
		}
	} );
}
 
Example #10
Source File: DiffUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void showSuccessPopup(@Nonnull String message,
                                    @Nonnull RelativePoint point,
                                    @Nonnull Disposable disposable,
                                    @Nullable Runnable hyperlinkHandler) {
  HyperlinkListener listener = null;
  if (hyperlinkHandler != null) {
    listener = new HyperlinkAdapter() {
      @Override
      protected void hyperlinkActivated(HyperlinkEvent e) {
        hyperlinkHandler.run();
      }
    };
  }

  Color bgColor = MessageType.INFO.getPopupBackground();

  Balloon balloon = JBPopupFactory.getInstance()
          .createHtmlTextBalloonBuilder(message, null, bgColor, listener)
          .setAnimationCycle(200)
          .createBalloon();
  balloon.show(point, Balloon.Position.below);
  Disposer.register(disposable, balloon);
}
 
Example #11
Source File: EnvironmentVariablesTextFieldWithBrowseButton.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected MyEnvironmentVariablesDialog() {
  super(EnvironmentVariablesTextFieldWithBrowseButton.this, true);
  myEnvVariablesTable = new EnvVariablesTable();
  myEnvVariablesTable.setValues(convertToVariables(myData.getEnvs(), false));

  myUseDefaultCb.setSelected(isPassParentEnvs());
  myWholePanel.add(myEnvVariablesTable.getComponent(), BorderLayout.CENTER);
  JPanel useDefaultPanel = new JPanel(new BorderLayout());
  useDefaultPanel.add(myUseDefaultCb, BorderLayout.CENTER);
  HyperlinkLabel showLink = new HyperlinkLabel(ExecutionBundle.message("env.vars.show.system"));
  useDefaultPanel.add(showLink, BorderLayout.EAST);
  showLink.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        showParentEnvironmentDialog(MyEnvironmentVariablesDialog.this.getWindow());
      }
    }
  });

  myWholePanel.add(useDefaultPanel, BorderLayout.SOUTH);
  setTitle(ExecutionBundle.message("environment.variables.dialog.title"));
  init();
}
 
Example #12
Source File: ResultsTextPane.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public ResultsTextPane(StyledDocument doc) {
  super(doc);
  createStyles();
  setEditorKit(JTextPane.createEditorKitForContentType("text/html"));
  setEditable(false);
  addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        if (Desktop.isDesktopSupported()) {
          try {
            Desktop.getDesktop().browse(e.getURL().toURI());
          } catch (IOException | URISyntaxException e1) {
            e1.printStackTrace();
          }
        }
      }
    }
  });
}
 
Example #13
Source File: GuiUtils.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an editor pane.
 * 
 * <p>The returned editor pane is set to be non-editable, handles hyperlinks (opens them in the default browser),
 * and removes the CTRL+SHIFT+O hotkey which is used by Sc2gears (it is associated with opening last replay).</p>
 * 
 * @return the created editor pane
 */
public static JEditorPane createEditorPane() {
	final JEditorPane editorPane = new JEditorPane();
	
	editorPane.setEditable( false );
	
	editorPane.addHyperlinkListener( new HyperlinkListener() {
		@Override
		public void hyperlinkUpdate( final HyperlinkEvent event ) {
			if ( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
				GeneralUtils.showURLInBrowser( event.getURL().toExternalForm() );
		}
	} );
	
	// Remove CTRL+SHIFT+O
	Object actionKey;
	editorPane.getInputMap( JComponent.WHEN_FOCUSED ).put( KeyStroke.getKeyStroke( KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK ), actionKey = new Object() );
	editorPane.getActionMap().put( actionKey, null );
	
	return editorPane;
}
 
Example #14
Source File: HTMLDialogBox.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Turns HTML into a clickable dialog text component.
 * @param html String of valid HTML.
 * @return a JTextComponent with the HTML inside.
 */
public JTextComponent createHyperlinkListenableJEditorPane(String html) {
	final JEditorPane bottomText = new JEditorPane();
	bottomText.setContentType("text/html");
	bottomText.setEditable(false);
	bottomText.setText(html);
	bottomText.setOpaque(false);
	final HyperlinkListener hyperlinkListener = new HyperlinkListener() {
		public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
			if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				if (Desktop.isDesktopSupported()) {
					try {
						Desktop.getDesktop().browse(hyperlinkEvent.getURL().toURI());
					} catch (IOException | URISyntaxException exception) {
						// Auto-generated catch block
						exception.printStackTrace();
					}
				}

			}
		}
	};
	bottomText.addHyperlinkListener(hyperlinkListener);
	return bottomText;
}
 
Example #15
Source File: EditableNotificationMessageElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
private MyCellEditor() {
  editorComponent = installJep(new MyJEditorPane(EditableNotificationMessageElement.this));

  HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener();
  editorComponent.addHyperlinkListener(hyperlinkListener);
  editorComponent.addMouseListener(new PopupHandler() {
    @Override
    public void invokePopup(Component comp, int x, int y) {
      if (myTree == null) return;

      final TreePath path = myTree.getLeadSelectionPath();
      if (path == null) {
        return;
      }
      DefaultActionGroup group = new DefaultActionGroup();
      group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
      group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));

      ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.COMPILER_MESSAGES_POPUP, group);
      menu.getComponent().show(comp, x, y);
    }
  });
}
 
Example #16
Source File: NotificationComponent.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
static JScrollPane createHtmlPane(String html, HyperlinkListener hyperlinkListener) {
  JEditorPane htmlPane = UIUtil.createHtmlPane(html, hyperlinkListener);
  htmlPane.setBackground(Color.YELLOW);
  htmlPane.setBorder(BorderFactory.createEmptyBorder());
  Dimension htmlSize = htmlPane.getPreferredSize();

  final JScrollPane scrollPane = new JScrollPane(htmlPane);
  scrollPane.setAutoscrolls(false);
  scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  scrollPane.setBorder(BorderFactory.createEmptyBorder());
  scrollPane.setPreferredSize(new Dimension(Math.min(400, htmlSize.width + 50), Math.min(300, htmlSize.height + 50)));
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      scrollPane.getVerticalScrollBar().setValue(0);
    }
  });
  return scrollPane;
}
 
Example #17
Source File: CreditsDialog.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
private void addCreditsPane() throws IOException {
	String creditsText = getCreditsTextAsHtml();
	
	JTextPane textPane = JTextPaneFactory.createHmtlJTextPane(imageInfoReader); 
	textPane.setEditable(false);
	textPane.setText(creditsText);
	
	textPane.addHyperlinkListener(new HyperlinkListener() {
		
		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				try {
					openWebPage(e.getURL().toURI());
				} catch (URISyntaxException e1) {
					 throw new IllegalStateException("Problem opening " + e.getURL().toString(), e1);
				}
			}
		}
	});
	
	JScrollPane scrollPane = new JScrollPane(textPane);
	scrollPane.setBounds(15, 15, 668, 720);
	addComponent(scrollPane);
}
 
Example #18
Source File: DepLoader.java    From CodeChickenCore with MIT License 6 votes vote down vote up
@Override
public void showErrorDialog(String name, String url) {
    JEditorPane ep = new JEditorPane("text/html",
            "<html>" +
                    owner + " was unable to download required library " + name +
                    "<br>Check your internet connection and try restarting or download it manually from" +
                    "<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" +
                    "</html>");

    ep.setEditable(false);
    ep.setOpaque(false);
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent event) {
            try {
                if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
                    Desktop.getDesktop().browse(event.getURL().toURI());
            } catch (Exception e) {
            }
        }
    });

    JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE);
}
 
Example #19
Source File: FixedWidthEditorPane.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates a pane with the given rootlessHTML as text with the given width.
 *
 * @param width
 *            the desired width
 * @param rootlessHTML
 *            the text, can contain hyperlinks that will be clickable
 */
public FixedWidthEditorPane(int width, String rootlessHTML) {
	super("text/html", "");
	this.width = width;
	this.rootlessHTML = rootlessHTML;
	updateLabel();

	setEditable(false);
	setFocusable(false);
	installDefaultStylesheet();
	addHyperlinkListener(new HyperlinkListener() {

		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				RMUrlHandler.handleUrl(e.getDescription());
			}
		}
	});

}
 
Example #20
Source File: Browser.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Browser(@Nonnull InspectionResultsView view) {
  super(new BorderLayout());
  myView = view;

  myCurrentEntity = null;
  myCurrentDescriptor = null;

  myHTMLViewer = new JEditorPane(UIUtil.HTML_MIME, InspectionsBundle.message("inspection.offline.view.empty.browser.text"));
  myHTMLViewer.setEditable(false);
  myHyperLinkListener = new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      Browser.this.hyperlinkUpdate(e);
    }
  };
  myHTMLViewer.addHyperlinkListener(myHyperLinkListener);

  final JScrollPane pane = ScrollPaneFactory.createScrollPane(myHTMLViewer);
  pane.setBorder(null);
  add(pane, BorderLayout.CENTER);
  setupStyle();
}
 
Example #21
Source File: DepLoader.java    From WirelessRedstone with MIT License 6 votes vote down vote up
@Override
public void showErrorDialog(String name, String url) {
    JEditorPane ep = new JEditorPane("text/html",
            "<html>" +
                    owner + " was unable to download required library " + name +
                    "<br>Check your internet connection and try restarting or download it manually from" +
                    "<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" +
                    "</html>");

    ep.setEditable(false);
    ep.setOpaque(false);
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent event) {
            try {
                if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
                    Desktop.getDesktop().browse(event.getURL().toURI());
            } catch (Exception e) {
            }
        }
    });

    JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE);
}
 
Example #22
Source File: LegalNotice.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected final JComponent createCenterPanel() {

    JPanel iconPanel = new JBPanel(new BorderLayout());
    iconPanel.add(new JBLabel(AllIcons.General.WarningDialog), BorderLayout.NORTH);

    JEditorPane messageEditorPane = new JEditorPane();
    messageEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
    messageEditorPane.setEditable(false);
    messageEditorPane.setPreferredSize(MESSAGE_EDITOR_PANE_PREFERRED_SIZE);
    messageEditorPane.setBorder(BorderFactory.createLineBorder(Gray._200));
    String text = DIV_STYLE_MARGIN_5PX + getLegalNoticeMessage() + "\n"
            + KODEBEAGLE_PRIVACY_POLICY + DIV;
    messageEditorPane.setText(text);
    JPanel legalNoticePanel = new JPanel(LEGAL_NOTICE_LAYOUT);
    legalNoticePanel.add(iconPanel, BorderLayout.WEST);
    legalNoticePanel.add(messageEditorPane, BorderLayout.CENTER);

    messageEditorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(final HyperlinkEvent he) {
            if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                BrowserUtil.browse(he.getURL());
            }
        }
    });
    return legalNoticePanel;
}
 
Example #23
Source File: HTMLPane.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * @param html HTML text.
 * @return HTML pane.
 */
public static HTMLPane createHTMLPane(String html) {
  HTMLPane pane = new HTMLPane(html);
  pane.setEditable(false);
  pane.addHyperlinkListener(EventHandler.create(
      HyperlinkListener.class, pane, "hyperLink", ""));
  return pane;
}
 
Example #24
Source File: NotificationComponent.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
void addNotification(String title, String body, HyperlinkListener hyperlinkListener, NotificationChannel channel) {
  JComponent htmlPane = createHtmlPane(GanttLanguage.getInstance().formatText("error.channel.text", title, body),
      hyperlinkListener);
  UIUtil.setBackgroundTree(htmlPane, channel.getColor());
  htmlPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(channel.getColor().darker()),
      BorderFactory.createEmptyBorder(3, 3, 3, 3)));
  myComponent.add(htmlPane, String.valueOf(myComponent.getComponentCount()));
}
 
Example #25
Source File: UIUtil.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
public static JEditorPane createHtmlPane(String html, HyperlinkListener hyperlinkListener) {
  JEditorPane htmlPane = new JEditorPane();
  htmlPane.setEditorKit(new HTMLEditorKit());
  htmlPane.setEditable(false);
  // htmlPane.setPreferredSize(new Dimension(400, 290));
  htmlPane.addHyperlinkListener(hyperlinkListener);
  //htmlPane.setBackground(Color.YELLOW);
  htmlPane.setText(html);
  return htmlPane;
}
 
Example #26
Source File: OutOfDateDialog.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
static Component showOutOfDateComponent(final Version latestVersionOut) {
  final JPanel panel = new JPanel(new BorderLayout());
  final JEditorPane intro = new JEditorPane("text/html", getOutOfDateMessage(latestVersionOut));
  intro.setEditable(false);
  intro.setOpaque(false);
  intro.setBorder(BorderFactory.createEmptyBorder());
  final HyperlinkListener hyperlinkListener =
      e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
          OpenFileUtility.openUrl(e.getDescription());
        }
      };
  intro.addHyperlinkListener(hyperlinkListener);
  panel.add(intro, BorderLayout.NORTH);
  final JEditorPane updates = new JEditorPane("text/html", getOutOfDateReleaseUpdates());
  updates.setEditable(false);
  updates.setOpaque(false);
  updates.setBorder(BorderFactory.createEmptyBorder());
  updates.addHyperlinkListener(hyperlinkListener);
  updates.setCaretPosition(0);
  final JScrollPane scroll = new JScrollPane(updates);
  panel.add(scroll, BorderLayout.CENTER);
  final Dimension maxDimension = panel.getPreferredSize();
  maxDimension.width = Math.min(maxDimension.width, 700);
  maxDimension.height = Math.min(maxDimension.height, 480);
  panel.setMaximumSize(maxDimension);
  panel.setPreferredSize(maxDimension);
  return panel;
}
 
Example #27
Source File: HintUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static JComponent createInformationLabel(@Nonnull String text,
                                                @Nullable HyperlinkListener hyperlinkListener,
                                                @Nullable MouseListener mouseListener,
                                                @Nullable Ref<? super Consumer<? super String>> updatedTextConsumer) {
  HintHint hintHint = getInformationHint();
  HintLabel label = createLabel(text, null, hintHint.getTextBackground(), hintHint);
  configureLabel(label, hyperlinkListener, mouseListener, updatedTextConsumer);
  return label;
}
 
Example #28
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void reportMessage(@Nonnull final String message, @Nonnull final MessageType type, @Nullable final HyperlinkListener listener) {
  NotificationListener notificationListener = listener == null ? null : (notification, event) -> {
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      listener.hyperlinkUpdate(event);
    }
  };
  NOTIFICATION_GROUP.createNotification("", message, type.toNotificationType(), notificationListener).notify(myProject);
}
 
Example #29
Source File: GlassFishOverviewPlugin.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void initComponents() {
    setOpaque(true);
    setBorder(BorderFactory.createEmptyBorder());
    addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                StringTokenizer st = new StringTokenizer(e.getDescription(), "#");
                String service = st.nextToken();
                String level = st.nextToken();
                setMonitoringLevel(AMXUtil.getMonitoringConfig(jmxModel), service, cycleLevel(level));
                setText(buildInfo());                        
            }
        }
    });

   new  SwingWorker<Void, Void>() {
        private String areaText = null;
        @Override
        protected Void doInBackground() throws Exception {
            areaText = buildInfo();
            return null;
        }

        @Override
        protected void done() {
            if (areaText != null) setText(areaText);
        
        }
    }.execute();
}
 
Example #30
Source File: HtmlPanel.java    From jamel with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes the specified {@code HtmlPanel}.
 * 
 * @param htmlPanel
 *            the {@code HtmlPanel} to be initialized.
 */
static private void init(HtmlPanel htmlPanel) {
	htmlPanel.jEditorPane = new JEditorPane();
	htmlPanel.jEditorPane.setContentType("text/html");
	htmlPanel.jEditorPane.setText(htmlPanel.htmlElement.getText());
	htmlPanel.jEditorPane.setEditable(false);
	htmlPanel.jEditorPane.addHyperlinkListener(new HyperlinkListener() {
		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
				try {
					java.awt.Desktop.getDesktop().browse(e.getURL().toURI());
				} catch (Exception ex) {
					ex.printStackTrace();
				}
		}
	});
	htmlPanel.setPreferredSize(new Dimension(660, 400));
	final Border border = BorderFactory.createCompoundBorder(
			BorderFactory.createLineBorder(ColorParser.getColor("background"), 5),
			BorderFactory.createLineBorder(Color.LIGHT_GRAY));
	htmlPanel.setBorder(border);
	htmlPanel.setViewportView(htmlPanel.jEditorPane);

	// Smart scrolling

	final DefaultCaret caret = (DefaultCaret) htmlPanel.jEditorPane.getCaret();
	caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
	htmlPanel.getVerticalScrollBar().addAdjustmentListener(htmlPanel);

}