Java Code Examples for javax.swing.JEditorPane#addHyperlinkListener()

The following examples show how to use javax.swing.JEditorPane#addHyperlinkListener() . 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: SwingForm.java    From teamengine with Apache License 2.0 6 votes vote down vote up
private SwingForm(String name) {
    setTitle(name);
    // setBackground(Color.gray);
    getContentPane().setLayout(new BorderLayout());

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    getContentPane().add(topPanel, BorderLayout.CENTER);

    jedit = new JEditorPane();
    jedit.setEditorKit(new CustomHTMLEditorKit());
    jedit.setEditable(false);
    jedit.addHyperlinkListener(this);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add(jedit, BorderLayout.CENTER);
    topPanel.add(scrollPane, BorderLayout.CENTER);
}
 
Example 2
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 3
Source File: BrokenProjectInfo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static JEditorPane getErrorPane(String reason) {
    JEditorPane errorLabel = new JEditorPane();
    JLabel infoLabel = new JLabel();

    errorLabel.setContentType("text/html"); // NOI18N
    errorLabel.setEditable(false);
    errorLabel.setForeground(UIManager.getDefaults().getColor("nb.errorForeground"));
    errorLabel.setRequestFocusEnabled(false);
    errorLabel.setBackground(infoLabel.getBackground());
    errorLabel.setFont(infoLabel.getFont());

    errorLabel.addHyperlinkListener(new BrokenProjectInfo());

    errorLabel.setText(reason);
    
    return errorLabel;
}
 
Example 4
Source File: ConceptDetailPanel.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void buildDetail(String id, JPanel panel) {
    if (this.id.equals(id)) return;

    panel.setLayout(new MigLayout("wrap 1, center"));

    JLabel header = Utility.localizedHeaderLabel(Messages.nameKey(id),
        SwingConstants.LEADING, FontLibrary.FontSize.SMALL);
    panel.add(header, "align center, wrap 20");

    JEditorPane editorPane
        = new ConceptEditorPane(Messages.getDescription(id));
    editorPane.setFont(panel.getFont());
    editorPane.addHyperlinkListener(colopediaPanel);
    panel.add(editorPane, "width 95%");
}
 
Example 5
Source File: ExportToGURPSCalculatorCommand.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void showResult(boolean success) {
    String message = success ? I18n.Text("Export to GURPS Calculator was successful.") : I18n.Text("There was an error exporting to GURPS Calculator. Please try again later.");
    String key     = Preferences.getInstance().getGURPSCalculatorKey();
    if (key == null || !key.matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}")) {
        message = String.format(I18n.Text("You need to set a valid GURPS Calculator Key in sheet preferences.<br><a href='%s'>Click here</a> for more information."), OutputPreferences.GURPS_CALCULATOR_URL);
    }
    JLabel      styleLabel  = new JLabel();
    Font        font        = styleLabel.getFont();
    Color       color       = styleLabel.getBackground();
    JEditorPane messagePane = new JEditorPane("text/html", "<html><body style='font-family:" + font.getFamily() + ";font-weight:" + (font.isBold() ? "bold" : "normal") + ";font-size:" + font.getSize() + "pt;background-color: rgb(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ");'>" + message + "</body></html>");
    messagePane.setEditable(false);
    messagePane.setBorder(null);
    messagePane.addHyperlinkListener(event -> {
        if (Desktop.isDesktopSupported() && event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
            URL url = event.getURL();
            try {
                Desktop.getDesktop().browse(url.toURI());
            } catch (IOException | URISyntaxException exception) {
                WindowUtils.showError(null, MessageFormat.format(I18n.Text("Unable to open {0}"), url.toExternalForm()));
            }
        }
    });
    JOptionPane.showMessageDialog(Command.getFocusOwner(), messagePane, success ? I18n.Text("Success") : I18n.Text("Error"), success ? JOptionPane.INFORMATION_MESSAGE : JOptionPane.ERROR_MESSAGE);
}
 
Example 6
Source File: AboutDialogFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private JScrollPane center() {
  JEditorPane editorPane = new JEditorPane();
  editorPane.setOpaque(false);
  editorPane.setMargin(new Insets(0, 5, 2, 5));
  editorPane.setContentType("text/html");
  editorPane.setText(LICENSE_NOTICE);
  editorPane.setEditable(false);
  editorPane.addHyperlinkListener(hyperlinkListener);
  JScrollPane scrollPane = new JScrollPane(editorPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  scrollPane.setBorder(BorderFactory.createLineBorder(Color.gray));
  SwingUtilities.invokeLater(() -> {
    // Set the scroll bar position to top
    scrollPane.getVerticalScrollBar().setValue(0);
  });
  return scrollPane;
}
 
Example 7
Source File: ControlWindow.java    From ChatGameFontificator with The Unlicense 6 votes vote down vote up
/**
 * Construct the popup dialog containing the About message
 */
private void constructAboutPopup()
{
    aboutPane = new JEditorPane("text/html", ABOUT_CONTENTS);
    aboutPane.addHyperlinkListener(new HyperlinkListener()
    {
        public void hyperlinkUpdate(HyperlinkEvent e)
        {
            if (EventType.ACTIVATED.equals(e.getEventType()))
            {
                if (Desktop.isDesktopSupported())
                {
                    try
                    {
                        Desktop.getDesktop().browse(URI.create("https://" + e.getDescription()));
                    }
                    catch (IOException e1)
                    {
                        e1.printStackTrace();
                    }
                }
            }
        }
    });
    aboutPane.setEditable(false);
}
 
Example 8
Source File: GHelpHTMLEditorKit.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void deinstall(JEditorPane c) {

	c.removeHyperlinkListener(resolverHyperlinkListener);

	for (HyperlinkListener listener : delegateListeners) {
		c.addHyperlinkListener(listener);
	}

	super.deinstall(c);
}
 
Example 9
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 10
Source File: FileLock.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
private static JEditorPane getMessage(File file) {
	JLabel jLabel = new JLabel();
	JEditorPane jEditorPane = new JEditorPane("text/html", "");
	jEditorPane.setEditable(false);
	jEditorPane.setFocusable(false);
	jEditorPane.setOpaque(false);
	jEditorPane.setText("<html><body style=\"font-family: " + jLabel.getFont().getName() + "; font-size: " + jLabel.getFont().getSize() + "pt\">"
			+ General.get().fileLockMsg(file.getName())
			+ "</body></html>");
	jEditorPane.addHyperlinkListener(DesktopUtil.getHyperlinkListener(null));
	return jEditorPane;
}
 
Example 11
Source File: MultiSizeIssue.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static void chooseBandsWithSameSize() {
    String title = Dialogs.getDialogTitle("Choose bands with same size.");
    int optionType = JOptionPane.OK_CANCEL_OPTION;
    int messageType = JOptionPane.INFORMATION_MESSAGE;

    final StringBuilder msgTextBuilder = new StringBuilder("The functionality you have chosen is not supported for bands of different sizes.<br/>");

    JPanel panel = new JPanel(new BorderLayout(4, 4));
    final JEditorPane textPane = new JEditorPane("text/html", msgTextBuilder.toString());
    setFont(textPane);
    textPane.setEditable(false);
    textPane.setOpaque(false);
    textPane.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            try {
                Desktop.getDesktop().browse(e.getURL().toURI());
            } catch (IOException | URISyntaxException e1) {
                Dialogs.showWarning("Could not open URL: " + e.getDescription());
            }
        }
    });
    panel.add(textPane, BorderLayout.CENTER);
    final JComboBox<Object> resamplerBox = new JComboBox<>();

    NotifyDescriptor d = new NotifyDescriptor(panel, title, optionType, messageType, null, null);
    DialogDisplayer.getDefault().notify(d);
}
 
Example 12
Source File: BasicHTMLRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new JEditorPane with the given text
 *
 * @param text
 * 		the html text
 */
BasicHTMLRenderer(String text) {
	renderer = new JEditorPane("text/html", text);
	renderer.addHyperlinkListener(e -> {
		if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
			RMUrlHandler.handleUrl(e.getDescription());
		}
	});
	renderer.setOpaque(false);
	renderer.setEditable(false);
	renderer.setBorder(null);
}
 
Example 13
Source File: GithubPanel.java    From MakeLobbiesGreatAgain with MIT License 5 votes vote down vote up
/**
 * Creates the new Panel and parses the supplied HTML.  <br>
 * <b> Supported Github Markdown: </b><i> Lists (unordered), Links, Images, Bold ('**' and '__'), Strikethrough, & Italics.  </i>
 *
 * @param currentVersion The version of the Jar currently running.
 */
public GithubPanel(double currentVersion) {
	this.version = currentVersion;

	setTitle("MLGA Update");
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		parseReleases();
	} catch (Exception e1) {
		e1.printStackTrace();
	}
	if (updates <= 0) {
		return;
	}
	ed = new JEditorPane("text/html", html);
	ed.setEditable(false);
	ed.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
	ed.setFont(new Font("Helvetica", 0, 12));

	ed.addHyperlinkListener(he -> {
		// Listen to link clicks and open them in the browser.
		if (he.getEventType() == EventType.ACTIVATED && Desktop.isDesktopSupported()) {
			try {
				Desktop.getDesktop().browse(he.getURL().toURI());
				System.exit(0);
			} catch (IOException | URISyntaxException e) {
				e.printStackTrace();
			}
		}
	});
	final JScrollPane scrollPane = new JScrollPane(ed);
	scrollPane.setPreferredSize(new Dimension(1100, 300));
	add(scrollPane);
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	pack();
	setLocationRelativeTo(null);
}
 
Example 14
Source File: Help.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
public Help(URL contents, MessageDialogs messageDialogs,
            String title)
{
    m_messageDialogs = messageDialogs;
    m_contents = contents;
    Container contentPane;
    if (Platform.isMac())
    {
        JDialog dialog = new JDialog((Frame)null, title);
        contentPane = dialog.getContentPane();
        m_window = dialog;
    }
    else
    {
        JFrame frame = new JFrame(title);
        GuiUtil.setGoIcon(frame);
        contentPane = frame.getContentPane();
        m_window = frame;
    }
    JPanel panel = new JPanel(new BorderLayout());
    contentPane.add(panel);
    panel.add(createButtons(), BorderLayout.NORTH);
    m_editorPane = new JEditorPane();
    m_editorPane.setEditable(false);
    m_editorPane.addHyperlinkListener(this);
    int width = GuiUtil.getDefaultMonoFontSize() * 50;
    int height = GuiUtil.getDefaultMonoFontSize() * 60;
    JScrollPane scrollPane =
        new JScrollPane(m_editorPane,
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    if (Platform.isMac())
        // Default Apple L&F uses no border, but Quaqua 3.7.4 does
        scrollPane.setBorder(null);
    scrollPane.setPreferredSize(new Dimension(width, height));
    panel.add(scrollPane, BorderLayout.CENTER);
    m_window.pack();
    loadURL(m_contents);
    appendHistory(m_contents);
}
 
Example 15
Source File: AboutDialog.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
private JPanel createPanel(String text)
{
    JPanel panel = new JPanel(new GridLayout(1, 1));
    JEditorPane editorPane = new JEditorPane();
    editorPane.setBorder(GuiUtil.createEmptyBorder());
    editorPane.setEditable(false);
    if (Platform.isMac())
    {
        editorPane.setForeground(UIManager.getColor("Label.foreground"));
        editorPane.setBackground(UIManager.getColor("Label.background"));
    }
    else
    {
        editorPane.setForeground(Color.black);
        editorPane.setBackground(Color.white);
    }
    panel.add(editorPane);
    EditorKit editorKit =
        JEditorPane.createEditorKitForContentType("text/html");
    editorPane.setEditorKit(editorKit);
    editorPane.setText(text);
    editorPane.addHyperlinkListener(new HyperlinkListener()
        {
            public void hyperlinkUpdate(HyperlinkEvent event)
            {
                HyperlinkEvent.EventType type = event.getEventType();
                if (type == HyperlinkEvent.EventType.ACTIVATED)
                {
                    URL url = event.getURL();
                    if (! Platform.openInExternalBrowser(url))
                        m_messageDialogs.showError(null,
                                                   i18n("MSG_ABOUT_OPEN_URL_FAIL"),
                                                   "", false);
                }
            }
        });
    return panel;
}
 
Example 16
Source File: OperatorDocumentationBrowser.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Prepares the dockable and its elements.
 */
public OperatorDocumentationBrowser() {
	dockKey.putProperty(ResourceDockKey.PROPERTY_KEY_DEFAULT_FALLBACK_LOCATION, RelativeDockablePosition.BOTTOM_RIGHT);

	setLayout(new BorderLayout());
	contentGbc = new GridBagConstraints();

	contentPanel = new JPanel(new GridBagLayout()) {

		@Override
		public Dimension getPreferredSize() {
			return new Dimension(getParent().getWidth(), super.getPreferredSize().height);
		}
	};

	editor = new JEditorPane("text/html", "<html>-</html>") {

		@Override
		public Dimension getPreferredSize() {
			return new Dimension(getParent().getWidth(), super.getPreferredSize().height);
		}
	};

	// Instantiate Editor and set Settings
	editor.addHyperlinkListener(new OperatorHelpLinkListener());
	editor.setEditable(false);
	HTMLEditorKit hed = new HTMLEditorKit();
	hed.setStyleSheet(createStyleSheet(hed.getStyleSheet()));
	editor.setEditorKit(hed);
	editor.setBackground(Colors.PANEL_BACKGROUND);
	editor.setContentType("text/html");

	// add editor to scrollPane
	JScrollPane scrollPane = new ExtendedJScrollPane(contentPanel);
	scrollPane.setBorder(null);
	scrollPane.setMinimumSize(MINIMUM_DOCUMENTATION_SIZE);
	scrollPane.setPreferredSize(MINIMUM_DOCUMENTATION_SIZE);

	contentGbc.gridx = 0;
	contentGbc.gridy = 0;
	contentGbc.weightx = 1.0f;
	contentGbc.fill = GridBagConstraints.HORIZONTAL;
	contentPanel.add(editor, contentGbc);

	// add filler at bottom
	contentGbc.gridy += 1;
	contentGbc.weighty = 1.0f;
	contentGbc.fill = GridBagConstraints.BOTH;
	contentPanel.add(new JLabel(), contentGbc);

	// prepare contentGbc for feedback form
	contentGbc.gridy += 1;
	contentGbc.weighty = 0.0f;
	contentGbc.fill = GridBagConstraints.HORIZONTAL;

	// add scrollPane to Dockable
	this.add(scrollPane, BorderLayout.CENTER);

	this.setVisible(true);
	this.validate();

	documentationUpdateQueue.start();
}
 
Example 17
Source File: BugReportService.java    From Shuffle-Move with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return
 */
@SuppressWarnings("serial")
private JComponent getInstructionPanel() {
   ConfigManager preferencesManager = getUser().getPreferencesManager();
   final int width = preferencesManager.getIntegerValue(KEY_POPUP_WIDTH, DEFAULT_POPUP_WIDTH);
   JEditorPane textPane = new JEditorPane() {
      @Override
      public Dimension getPreferredSize() {
         Dimension d = super.getPreferredSize();
         d.width = width - 40;
         return d;
      }
   };
   textPane.setFocusable(false);
   textPane.setEditable(false);
   textPane.setContentType("text/html");
   textPane.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 | NullPointerException e1) {
                  LOG.severe(getString(KEY_BAD_LINK, e1.getMessage()));
               }
            }
         }
      }
   });
   JScrollPane jsp = new JScrollPane(textPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
         ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
   jsp.getVerticalScrollBar().setUnitIncrement(30);
   String text = getUser().getPathManager().readEntireDocument(getFilePath(), getDefaultFileKey());
   textPane.setText(text);
   textPane.setSelectionStart(0);
   textPane.setSelectionEnd(0);
   textPane.repaint();
   jsp.validate();
   return jsp;
}
 
Example 18
Source File: TutorialBrowser.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private Component createContentPanel() {
	contentGbc = new GridBagConstraints();

	contentPanel = new JPanel(new GridBagLayout()) {

		@Override
		public Dimension getPreferredSize() {
			return new Dimension(getParent().getWidth(), super.getPreferredSize().height);
		}
	};
	contentPanel.setBackground(Colors.WHITE);

	jEditorPane = new JEditorPane() {

		@Override
		public Dimension getPreferredSize() {
			return new Dimension(getParent().getWidth(), super.getPreferredSize().height);
		}
	};
	jEditorPane.setEditable(false);
	contentGbc.gridx = 0;
	contentGbc.gridy = 0;
	contentGbc.weightx = 1.0f;
	contentGbc.fill = GridBagConstraints.HORIZONTAL;
	contentPanel.add(jEditorPane, contentGbc);

	// add filler at bottom
	contentGbc.gridy += 1;
	contentGbc.weighty = 1.0f;
	contentGbc.fill = GridBagConstraints.BOTH;
	contentPanel.add(new JLabel(), contentGbc);

	// prepare contentGbc for feedback form
	contentGbc.gridy += 1;
	contentGbc.weighty = 0.0f;
	contentGbc.fill = GridBagConstraints.HORIZONTAL;

	scrollPane = new ExtendedJScrollPane(contentPanel);
	scrollPane.setBorder(null);

	HTMLEditorKit kit = new HTMLEditorKit();
	jEditorPane.setEditorKit(kit);
	jEditorPane.setMargin(new Insets(0, 0, 0, 0));

	Document doc = kit.createDefaultDocument();
	jEditorPane.setDocument(doc);
	jEditorPane.setText(String.format(INFO_TEMPLATE, NO_TUTORIAL_SELECTED));
	jEditorPane.addHyperlinkListener(e -> {

		if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
			ActionStatisticsCollector.INSTANCE.log(ActionStatisticsCollector.TYPE_GETTING_STARTED,
					TUTORIAL_BROWSER_DOCK_KEY, "open_remote_url");
			RMUrlHandler.handleUrl(e.getURL().toString());
		}
	});
	return scrollPane;
}
 
Example 19
Source File: MultiSizeIssue.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
public static Product maybeResample(Product product) {
    String title = Dialogs.getDialogTitle("Resampling Required");
    final List<Resampler> availableResamplers = getAvailableResamplers(product);
    int optionType;
    int messageType;
    final StringBuilder msgTextBuilder = new StringBuilder("The functionality you have chosen is not supported for products with bands of different sizes.<br/>");
    if (availableResamplers.isEmpty()) {
        optionType = JOptionPane.OK_CANCEL_OPTION;
        messageType = JOptionPane.INFORMATION_MESSAGE;
    } else if (availableResamplers.size() == 1) {
        msgTextBuilder.append("You can use the ").append(availableResamplers.get(0).getName()).
                append(" to resample this product so that all bands have the same size, <br/>" +
                               "which will enable you to use this feature.<br/>" +
                               "Do you want to resample the product now?");
        optionType = JOptionPane.YES_NO_OPTION;
        messageType = JOptionPane.QUESTION_MESSAGE;
    } else {
        msgTextBuilder.append("You can use one of these resamplers to resample this product so that all bands have the same size, <br/>" +
                                      "which will enable you to use this feature.<br/>" +
                                      "Do you want to resample the product now?");
        optionType = JOptionPane.YES_NO_OPTION;
        messageType = JOptionPane.QUESTION_MESSAGE;
    }
    msgTextBuilder.append("<br/>" +
                                  "<br/>" +
                                  "More info about this issue and its status can be found in the " +
                                  "<a href=\"https://senbox.atlassian.net/browse/SNAP-1\">SNAP Issue Tracker</a>."
    );
    JPanel panel = new JPanel(new BorderLayout(4, 4));
    final JEditorPane textPane = new JEditorPane("text/html", msgTextBuilder.toString());
    setFont(textPane);
    textPane.setEditable(false);
    textPane.setOpaque(false);
    textPane.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            try {
                Desktop.getDesktop().browse(e.getURL().toURI());
            } catch (IOException | URISyntaxException e1) {
                Dialogs.showWarning("Could not open URL: " + e.getDescription());
            }
        }
    });
    panel.add(textPane, BorderLayout.CENTER);
    final JComboBox<Object> resamplerBox = new JComboBox<>();
    if (availableResamplers.size() > 1) {
        String[] resamplerNames = new String[availableResamplers.size()];
        for (int i = 0; i < availableResamplers.size(); i++) {
            resamplerNames[i] = availableResamplers.get(i).getName();
            resamplerBox.addItem(resamplerNames[i]);
        }
        panel.add(resamplerBox, BorderLayout.SOUTH);
    }
    NotifyDescriptor d = new NotifyDescriptor(panel, title, optionType, messageType, null, null);
    DialogDisplayer.getDefault().notify(d);
    if (d.getValue() == NotifyDescriptor.YES_OPTION) {
        Resampler selectedResampler;
        if (availableResamplers.size() == 1) {
            selectedResampler = availableResamplers.get(0);
        } else {
            selectedResampler = availableResamplers.get(resamplerBox.getSelectedIndex());
        }
        return selectedResampler.resample(product);
    }
    return null;
}
 
Example 20
Source File: UpdateProgressBar.java    From stendhal with GNU General Public License v2.0 4 votes vote down vote up
private void initializeComponents() {
	JPanel contentPane = (JPanel) this.getContentPane();

	contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
	contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

	if (fromVersion == null) {
		contentPane.add(new JLabel("Please wait while " + ClientGameConfiguration.get("GAME_NAME") + " is downloaded..."));
	} else {
		contentPane.add(new JLabel("Downloading updates..."));
	}
	contentPane.add(Box.createVerticalStrut(5));

	progressBar = new JProgressBar(0, max);
	progressBar.setStringPainted(false);
	progressBar.setValue(0);
	contentPane.add(progressBar);
	contentPane.add(Box.createVerticalStrut(5));

	if (urlBase != null) {
		// Set up page display.
		browser = new JEditorPane();
		browser.setContentType("text/html");
		browser.setEditable(false);
		Dimension dim = new Dimension(600, 440);
		browser.setPreferredSize(dim);
		browser.addPropertyChangeListener("page", new UpdateProgressBarMetaRefreshSupport());
		browser.addHyperlinkListener(new UpdateProgressBarHyperLinkListener());

		Dimension windowSize = new Dimension(640, 480);
		setPreferredSize(windowSize);
		// TODO: load page async?
		try {
			browser.setPage(urlBase + fromVersion + "/" + toVersion + ".html");
		} catch (IOException e) {
			System.out.println(e);
		}

		// Gige the page scroll bars if it needs them
		final JScrollPane scrollPane = new JScrollPane(browser);
		contentPane.add(scrollPane);
	}
}