List of usage examples for javax.swing.event HyperlinkListener HyperlinkListener
HyperlinkListener
From source file:ja.lingo.application.gui.main.settings.dictionaries.add.AddPanel.java
public AddPanel(JDialog parentDialog, IEngine engine) { Arguments.assertNotNull("parentDialog", parentDialog); Arguments.assertNotNull("engine", engine); this.parentDialog = parentDialog; this.engine = engine; fileChooser = new FileChooser(); encodingComboBox = new JComboBox(); encodingAutoComboBox = new JComboBox(new String[] { resources.text("encoding_auto") }); encodingAutoComboBox.setEnabled(false); encodingCardPanel = new CardPanel(); encodingCardPanel.add(encodingComboBox); encodingCardPanel.add(encodingAutoComboBox); readerList = Components//from w w w .j av a 2 s .c om .list(new StaticListModel<IDictionaryReader>(new ReaderLabelBuilder(), engine.getReaders())); readerList.setSelectedIndex(0); editorPane = Components.editorPane(); editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { Browser.openUrl(e.getURL().toExternalForm()); } } }); continueButton = Buttons.continue1(); continueButton.setDefaultCapable(true); closeButton = Buttons.cancel(); JPanel buttonPanel = new JPanel(new GridLayout(1, 2, GAP5, GAP5)); buttonPanel.add(continueButton); buttonPanel.add(closeButton); JPanel listReaderPanel = new JPanel(new BorderLayout()); listReaderPanel.add(resources.label("reader"), BorderLayout.NORTH); listReaderPanel.add(new JScrollPane(readerList), BorderLayout.CENTER); readerList.setPreferredSize(new Dimension(50, 50)); listReaderPanel.setPreferredSize(new Dimension(100, 100)); JPanel descriptionReaderPanel = new JPanel(new BorderLayout()); descriptionReaderPanel.add(resources.label("readerDescription"), BorderLayout.NORTH); descriptionReaderPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listReaderPanel, descriptionReaderPanel); splitPane.setContinuousLayout(true); splitPane.setDividerLocation(130); gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED, GAP5, TableLayout.FILL }, { TableLayout.FILL, // 0: reader panel GAP5, TableLayout.PREFERRED, // 2: file GAP5, TableLayout.PREFERRED, // 4: encoding GAP5 * 2, TableLayout.PREFERRED // 6: button panel } })); gui.add(splitPane, "0, 0, 2, 0"); gui.add(resources.label("file"), "0, 2"); gui.add(fileChooser.getGui(), "2, 2"); gui.add(resources.label("encoding"), "0, 4"); gui.add(encodingCardPanel.getGui(), "2, 4"); gui.add(buttonPanel, "0, 6, 2, 6, right, center"); Gaps.applyBorder7(gui); ActionBinder.bind(this); if (encodingComboBox.getModel().getSize() > 0) { encodingComboBox.setSelectedIndex(0); } // filters for (IDictionaryReader reader : engine.getReaders()) { fileChooser.getChooser().addChoosableFileFilter(reader.getFileFilter()); } onReaderSelected(); onFileFieldEdited(); }
From source file:ca.sqlpower.enterprise.ServerInfoProvider.java
private static void init(URL url, String username, String password, CookieStore cookieStore) throws IOException { if (version.containsKey(generateServerKey(url, username, password))) return;/*from w w w .ja va 2s . c o m*/ try { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 2000); DefaultHttpClient httpClient = new DefaultHttpClient(params); httpClient.setCookieStore(cookieStore); httpClient.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); HttpUriRequest request = new HttpOptions(url.toURI()); String responseBody = httpClient.execute(request, new BasicResponseHandler()); // Decode the message String serverVersion; Boolean licensedServer; final String watermarkMessage; try { JSONObject jsonObject = new JSONObject(responseBody); serverVersion = jsonObject.getString(ServerProperties.SERVER_VERSION.toString()); licensedServer = jsonObject.getBoolean(ServerProperties.SERVER_LICENSED.toString()); watermarkMessage = jsonObject.getString(ServerProperties.SERVER_WATERMARK_MESSAGE.toString()); } catch (JSONException e) { throw new IOException(e.getMessage()); } // Save found values version.put(generateServerKey(url, username, password), new Version(serverVersion)); licenses.put(generateServerKey(url, username, password), licensedServer); watermarkMessages.put(generateServerKey(url, username, password), watermarkMessage); // Notify the user if the server is not licensed. if (!licensedServer || (watermarkMessage != null && watermarkMessage.trim().length() > 0)) { SwingUtilities.invokeLater(new Runnable() { public void run() { HyperlinkListener hyperlinkListener = new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { try { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (e.getURL() != null) { BrowserUtil.launch(e.getURL().toString()); } } } catch (IOException ex) { throw new RuntimeException(ex); } } }; HTMLUserPrompter htmlPrompter = new HTMLUserPrompter(UserPromptOptions.OK, UserPromptResponse.OK, null, watermarkMessage, hyperlinkListener, "OK"); htmlPrompter.promptUser(""); } }); } } catch (URISyntaxException e) { throw new IOException(e.getLocalizedMessage()); } }
From source file:net.sf.taverna.t2.workbench.ui.credentialmanager.WarnUserAboutJCEPolicyDialog.java
private void initComponents() { // Base font for all components on the form Font baseFont = new JLabel("base font").getFont().deriveFont(11f); // Message saying that updates are available JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(LOWERED))); JEditorPane message = new JEditorPane(); message.setEditable(false);//from w w w .j a va2 s .c o m message.setBackground(this.getBackground()); message.setFocusable(false); HTMLEditorKit kit = new HTMLEditorKit(); message.setEditorKit(kit); StyleSheet styleSheet = kit.getStyleSheet(); //styleSheet.addRule("body {font-family:"+baseFont.getFamily()+"; font-size:"+baseFont.getSize()+";}"); // base font looks bigger when rendered as HTML styleSheet.addRule("body {font-family:" + baseFont.getFamily() + "; font-size:10px;}"); Document doc = kit.createDefaultDocument(); message.setDocument(doc); message.setText( "<html><body>In order for Taverna's security features to function properly - you need to install<br>" + "'Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy'. <br><br>" + "If you do not already have it, for <b>Java 6</b> you can get it from:<br>" + "<a href=\"http://www.oracle.com/technetwork/java/javase/downloads/index.html\">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a><br<br>" + "Installation instructions are contained in the bundle you download." + "</body><html>"); message.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent he) { HyperlinkEvent.EventType type = he.getEventType(); if (type == ACTIVATED) // Open a Web browser try { getDesktop().browse(he.getURL().toURI()); // BrowserLauncher launcher = new BrowserLauncher(); // launcher.openURLinBrowser(he.getURL().toString()); } catch (Exception ex) { logger.error("Failed to launch browser to fetch JCE " + he.getURL()); } } }); message.setBorder(new EmptyBorder(5, 5, 5, 5)); messagePanel.add(message, CENTER); doNotWarnMeAgainCheckBox = new JCheckBox("Do not warn me again"); doNotWarnMeAgainCheckBox.setFont(baseFont.deriveFont(12f)); messagePanel.add(doNotWarnMeAgainCheckBox, SOUTH); // Buttons JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton okButton = new JButton("OK"); okButton.setFont(baseFont); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { okPressed(); } }); buttonsPanel.add(okButton); getContentPane().setLayout(new BorderLayout()); getContentPane().add(messagePanel, CENTER); getContentPane().add(buttonsPanel, SOUTH); pack(); setResizable(false); // Center the dialog on the screen (we do not have the parent) Dimension dimension = getToolkit().getScreenSize(); Rectangle abounds = getBounds(); setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2); setSize(getPreferredSize()); }
From source file:fxts.stations.ui.help.HelpPane.java
/** * Inits all components.//w w w. j av a2 s . co m */ private void initComponents() { //creates history mHistory = new HelpContentHistory(); //Create the text area for contents mTabbedPane = new JTabbedPane(); //creates content tree mContentTree = new ContentTree("fxts/stations/trader/resources/help/contents.xml"); mContentTree.addListener(this); //Create the scroll pane and add the tree to it. JScrollPane treeView = new JScrollPane(mContentTree.getTree()); mTabbedPane.addTab(mResMan.getString("IDS_HELP_CONTENTS", "Contents"), treeView); //xxx workaround for bug #6424509, memory leak JEditorPane.registerEditorKitForContentType("text/html", WeakHTMLEditorKit.class.getName()); //creates the text area for the showing of the help. mHtmlPage = new JEditorPane(); mHtmlPage.setEditable(false); mHtmlPage.putClientProperty("charset", "UTF-16"); mHtmlPage.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent aEvent) { if (aEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { onSelectContentByHyperlink(aEvent.getURL()); mHtmlPage.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } catch (Exception e) { mLogger.error("Hiperlink not processed!"); e.printStackTrace(); } } } }); JScrollPane scrollPane = new JScrollPane(mHtmlPage); //creates a split pane for the change log and the text area. mSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mTabbedPane, scrollPane); mSplitPane.setOneTouchExpandable(true); //Creates the toolbar area. JToolBar toolbar = UIManager.getInst().createToolBar(); toolbar.setFloatable(false); //creates label with left arrow UIManager uiMan = UIManager.getInst(); mBackButton = uiMan.createButton(null, "ID_HELP_LEFT_ARROW", "ID_HELP_LEFT_ARROW_DESC", "ID_HELP_LEFT_ARROW_DESC"); mBackButton.setEnabled(false); mBackButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { if (mHistory.hasBackStep()) { mIsHistorycalStep = true; onSelectContent(mHistory.back()); mBackButton.setEnabled(mHistory.hasBackStep()); mForwardButton.setEnabled(mHistory.hasForwardStep()); } } }); toolbar.add(mBackButton); //creates label with right arrow mForwardButton = uiMan.createButton(null, "ID_HELP_RIGHT_ARROW", "ID_HELP_RIGHT_ARROW_DESC", "ID_HELP_RIGHT_ARROW_DESC"); mForwardButton.setEnabled(false); mForwardButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { if (mHistory.hasForwardStep()) { mIsHistorycalStep = true; onSelectContent(mHistory.forward()); mBackButton.setEnabled(mHistory.hasBackStep()); mForwardButton.setEnabled(mHistory.hasForwardStep()); } } }); toolbar.add(mForwardButton); //creates label with up arrow mUpButton = uiMan.createButton(null, "ID_HELP_UP_ARROW", "ID_HELP_UP_ARROW_DESC", "ID_HELP_UP_ARROW_DESC"); mUpButton.setEnabled(mContentTree.getIterator().hasPrevious()); mUpButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { mContentsBrowsing = true; onSelectContent(mContentTree.getIterator().previous()); mUpButton.setEnabled(mContentTree.getIterator().hasPrevious()); mDownButton.setEnabled(mContentTree.getIterator().hasNext()); } }); toolbar.add(mUpButton); //creates label with down arrow mDownButton = uiMan.createButton(null, "ID_HELP_DOWN_ARROW", "ID_HELP_DOWN_ARROW_DESC", "ID_HELP_DOWN_ARROW_DESC"); mDownButton.setEnabled(mContentTree.getIterator().hasNext()); mDownButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { mContentsBrowsing = true; onSelectContent(mContentTree.getIterator().next()); mUpButton.setEnabled(mContentTree.getIterator().hasPrevious()); mDownButton.setEnabled(mContentTree.getIterator().hasNext()); } }); toolbar.add(mDownButton); //sets layout setLayout(new BorderLayout()); //add the components to the frame. add(mSplitPane, BorderLayout.CENTER); add(toolbar, BorderLayout.NORTH); //sets first page onSelectContent(mContentTree.getIterator().toBegin()); }
From source file:EditorPaneExample12.java
public EditorPaneExample12() { super("JEditorPane Example 12"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/*from w w w . j av a 2 s . co m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:EditorPaneExample15.java
public EditorPaneExample15() { super("JEditorPane Example 15"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/*from ww w. j av a2 s. c om*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:EditorPaneExample14.java
public EditorPaneExample14() { super("JEditorPane Example 14"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/*from w w w .ja va 2 s . c o m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Modify the default style sheet InputStream is = EditorPaneExample14.class.getResourceAsStream("changedDefault.css"); if (is != null) { try { addToStyleSheet(editorKit.getStyleSheet(), is); } catch (IOException e) { System.out.println("Failed to modify default style sheet"); } } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:EditorPaneExample13.java
public EditorPaneExample13() { super("JEditorPane Example 13"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;// w w w . j a v a2s . c o m c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Load a new default style sheet InputStream is = EditorPaneExample13.class.getResourceAsStream("changedDefault.css"); if (is != null) { try { StyleSheet ss = loadStyleSheet(is); editorKit.setStyleSheet(ss); } catch (IOException e) { System.out.println("Failed to load new default style sheet"); } } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:jamel.gui.JamelWindow.java
/** * Returns the info panel./*ww w . ja v a2s . c o m*/ * @return the info panel. */ private Component getInfoPanel() { final JEditorPane editorPane = new JEditorPane("text/html", "<center>" + this.infoString + "</center>"); editorPane.addHyperlinkListener(new HyperlinkListener() { 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(); JOptionPane.showMessageDialog(null, "<html>" + "Error.<br>" + "Cause: " + e.toString() + ".<br>" + "Please see server.log for more details.</html>", "Warning", JOptionPane.WARNING_MESSAGE); } } }); editorPane.setEditable(false); final JScrollPane scrollPane = new JScrollPane(editorPane); return scrollPane; }
From source file:EditorPaneExample16.java
public EditorPaneExample16() { super("JEditorPane Example 16"); pane = new JEditorPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/* w w w .j a v a 2 s .c om*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }