List of usage examples for javax.swing.text.html HTMLEditorKit HTMLEditorKit
public HTMLEditorKit()
From source file:net.sf.taverna.t2.workbench.ui.impl.UserRegistrationForm.java
private void initComponents() { JPanel mainPanel = new JPanel(new GridBagLayout()); // Base font for all components on the form Font baseFont = new JLabel("base font").getFont().deriveFont(11f); // Title panel JPanel titlePanel = new JPanel(new FlowLayout(LEFT)); titlePanel.setBackground(WHITE);/*from ww w . ja v a2 s . c om*/ // titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10)); JLabel titleLabel = new JLabel(WELCOME); titleLabel.setFont(baseFont.deriveFont(BOLD, 13.5f)); // titleLabel.setBorder(new EmptyBorder(10, 10, 0, 10)); JLabel titleIcon = new JLabel(tavernaCogs32x32Icon); // titleIcon.setBorder(new EmptyBorder(10, 10, 10, 10)); DialogTextArea titleMessage = new DialogTextArea(PLEASE_FILL_IN_THIS_REGISTRATION_FORM); titleMessage.setMargin(new Insets(0, 20, 0, 10)); titleMessage.setFont(baseFont); titleMessage.setEditable(false); titleMessage.setFocusable(false); // titlePanel.setBorder( new EmptyBorder(10, 10, 0, 10)); JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.add(titleLabel, NORTH); messagePanel.add(titleMessage, CENTER); messagePanel.setBackground(WHITE); titlePanel.add(titleIcon); titlePanel.add(messagePanel); addDivider(titlePanel, BOTTOM, true); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 0; gbc.fill = HORIZONTAL; gbc.anchor = WEST; gbc.gridwidth = 2; // gbc.insets = new Insets(5, 10, 0, 0); mainPanel.add(titlePanel, gbc); // Registration messages gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 1; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 2; // gbc.insets = new Insets(5, 0, 0, 10); DialogTextArea registrationMessage1 = new DialogTextArea(WHY_REGISTER); registrationMessage1.setMargin(new Insets(0, 10, 0, 0)); registrationMessage1.setFont(baseFont); registrationMessage1.setEditable(false); registrationMessage1.setFocusable(false); registrationMessage1.setBackground(getBackground()); DialogTextArea registrationMessage2 = new DialogTextArea(WE_DO); registrationMessage2.setMargin(new Insets(0, 10, 0, 10)); registrationMessage2.setFont(baseFont); registrationMessage2.setEditable(false); registrationMessage2.setFocusable(false); registrationMessage2.setBackground(getBackground()); JPanel registrationMessagePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); registrationMessagePanel.add(registrationMessage1); registrationMessagePanel.add(registrationMessage2); addDivider(registrationMessagePanel, BOTTOM, true); mainPanel.add(registrationMessagePanel, gbc); // Mandatory label // JLabel mandatoryLabel = new JLabel("* Mandatory fields"); // mandatoryLabel.setFont(baseFont); // gbc.weightx = 0.0; // gbc.weighty = 0.0; // gbc.gridx = 0; // gbc.gridy = 3; // gbc.fill = NONE; // gbc.anchor = GridBagConstraints.EAST; // gbc.gridwidth = 2; // gbc.insets = new Insets(0, 10, 0, 20); // mainPanel.add(mandatoryLabel, gbc); // First name JLabel firstNameLabel = new JLabel(FIRST_NAME); firstNameLabel.setFont(baseFont); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 4; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(0, 10, 0, 10); mainPanel.add(firstNameLabel, gbc); firstNameTextField = new JTextField(); firstNameTextField.setFont(baseFont); if (previousRegistrationData != null) firstNameTextField.setText(previousRegistrationData.getFirstName()); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 4; gbc.fill = HORIZONTAL; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(firstNameTextField, gbc); // Last name JLabel lastNameLabel = new JLabel(LAST_NAME); lastNameLabel.setFont(baseFont); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 5; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(0, 10, 0, 10); mainPanel.add(lastNameLabel, gbc); lastNameTextField = new JTextField(); lastNameTextField.setFont(baseFont); if (previousRegistrationData != null) lastNameTextField.setText(previousRegistrationData.getLastName()); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 5; gbc.fill = HORIZONTAL; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(lastNameTextField, gbc); // Email address JLabel emailLabel = new JLabel(EMAIL_ADDRESS); emailLabel.setFont(baseFont); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 6; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(emailLabel, gbc); emailTextField = new JTextField(); emailTextField.setFont(baseFont); if (previousRegistrationData != null) emailTextField.setText(previousRegistrationData.getEmailAddress()); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 6; gbc.fill = HORIZONTAL; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(emailTextField, gbc); // Keep me informed keepMeInformedCheckBox = new JCheckBox(KEEP_ME_INFORMED); keepMeInformedCheckBox.setFont(baseFont); if (previousRegistrationData != null) keepMeInformedCheckBox.setSelected(previousRegistrationData.getKeepMeInformed()); keepMeInformedCheckBox.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == VK_ENTER) { evt.consume(); keepMeInformedCheckBox.setSelected(!keepMeInformedCheckBox.isSelected()); } } }); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 7; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 2; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(keepMeInformedCheckBox, gbc); // Institution name JLabel institutionLabel = new JLabel(INSTITUTION_COMPANY_NAME); institutionLabel.setFont(baseFont); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 8; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(institutionLabel, gbc); institutionOrCompanyTextField = new JTextField(); institutionOrCompanyTextField.setFont(baseFont); if (previousRegistrationData != null) institutionOrCompanyTextField.setText(previousRegistrationData.getInstitutionOrCompanyName()); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 8; gbc.fill = HORIZONTAL; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(institutionOrCompanyTextField, gbc); // Industry type JLabel industryLabel = new JLabel(" Industry type:"); industryLabel.setFont(baseFont); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 9; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(industryLabel, gbc); industryTypeTextField = new JComboBox<>(industryTypes); industryTypeTextField.setFont(baseFont); if (previousRegistrationData != null) industryTypeTextField.setSelectedItem(previousRegistrationData.getIndustry()); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 9; gbc.fill = HORIZONTAL; gbc.anchor = WEST; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(industryTypeTextField, gbc); // Field of investigation JTextArea fieldLabel = new JTextArea(FIELD_OF_INVESTIGATION); fieldLabel.setFont(baseFont); fieldLabel.setEditable(false); fieldLabel.setFocusable(false); fieldLabel.setBackground(getBackground()); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 10; gbc.fill = NONE; gbc.anchor = LINE_START; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(fieldLabel, gbc); fieldTextField = new JTextField(); fieldTextField.setFont(baseFont); if (previousRegistrationData != null) fieldTextField.setText(previousRegistrationData.getField()); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 10; gbc.fill = HORIZONTAL; gbc.anchor = FIRST_LINE_START; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(fieldTextField, gbc); // Purpose of using Taverna JTextArea purposeLabel = new JTextArea(WHY_YOU_INTEND_TO_USE_TAVERNA); purposeLabel.setFont(baseFont); purposeLabel.setEditable(false); purposeLabel.setFocusable(false); purposeLabel.setBackground(getBackground()); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 11; gbc.fill = NONE; gbc.anchor = LINE_START; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(purposeLabel, gbc); purposeTextArea = new JTextArea(4, 30); purposeTextArea.setFont(baseFont); purposeTextArea.setLineWrap(true); purposeTextArea.setAutoscrolls(true); if (previousRegistrationData != null) purposeTextArea.setText(previousRegistrationData.getPurposeOfUsingTaverna()); purposeTextArea.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == VK_TAB) { if (evt.getModifiers() > 0) purposeTextArea.transferFocusBackward(); else purposeTextArea.transferFocus(); evt.consume(); } } }); JScrollPane purposeScrollPane = new JScrollPane(purposeTextArea); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 1; gbc.gridy = 11; gbc.fill = HORIZONTAL; gbc.anchor = FIRST_LINE_START; gbc.gridwidth = 1; gbc.insets = new Insets(5, 10, 0, 10); mainPanel.add(purposeScrollPane, gbc); // Terms and conditions termsAndConditionsCheckBox = new JCheckBox(I_AGREE_TO_THE_TERMS_AND_CONDITIONS); termsAndConditionsCheckBox.setFont(baseFont); termsAndConditionsCheckBox.setBorder(null); termsAndConditionsCheckBox.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == VK_ENTER) { evt.consume(); termsAndConditionsCheckBox.setSelected(!termsAndConditionsCheckBox.isSelected()); } } }); // gbc.weightx = 0.0; // gbc.weighty = 0.0; // gbc.gridx = 0; // gbc.gridy = 12; // gbc.fill = NONE; // gbc.anchor = WEST; // gbc.gridwidth = 2; // gbc.insets = new Insets(10, 10, 0, 0); // mainPanel.add(termsAndConditionsCheckBox, gbc); // Terms and conditions link JEditorPane termsAndConditionsURL = new JEditorPane(); termsAndConditionsURL.setEditable(false); termsAndConditionsURL.setBackground(getBackground()); termsAndConditionsURL.setFocusable(false); HTMLEditorKit kit = new HTMLEditorKit(); termsAndConditionsURL.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:9px;}"); Document doc = kit.createDefaultDocument(); termsAndConditionsURL.setDocument(doc); termsAndConditionsURL.setText("<html><body><a href=\"" + TERMS_AND_CONDITIONS_URL + "\">" + TERMS_AND_CONDITIONS_URL + "</a></body></html>"); termsAndConditionsURL.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent he) { if (he.getEventType() == ACTIVATED) followHyperlinkToTandCs(); } }); gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = 13; gbc.fill = NONE; gbc.anchor = WEST; gbc.gridwidth = 2; gbc.insets = new Insets(5, 10, 0, 10); JPanel termsAndConditionsPanel = new JPanel(new FlowLayout(LEFT)); termsAndConditionsPanel.add(termsAndConditionsCheckBox); termsAndConditionsPanel.add(termsAndConditionsURL); mainPanel.add(termsAndConditionsPanel, gbc); // Button panel JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton registerButton = new JButton("Register"); registerButton.setFont(baseFont); registerButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == VK_ENTER) { evt.consume(); register(); } } }); registerButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { register(); } }); JButton doNotRegisterButton = new JButton("Do not ask me again"); doNotRegisterButton.setFont(baseFont); doNotRegisterButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == VK_ENTER) { evt.consume(); doNotRegister(); } } }); doNotRegisterButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doNotRegister(); } }); JButton remindMeLaterButton = new JButton("Remind me later"); // in 2 weeks remindMeLaterButton.setFont(baseFont); remindMeLaterButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == VK_ENTER) { evt.consume(); remindMeLater(); } } }); remindMeLaterButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { remindMeLater(); } }); buttonPanel.add(registerButton); buttonPanel.add(remindMeLaterButton); buttonPanel.add(doNotRegisterButton); addDivider(buttonPanel, TOP, true); gbc.gridx = 0; gbc.gridy = 14; gbc.fill = HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(5, 10, 0, 10); gbc.gridwidth = 2; mainPanel.add(buttonPanel, gbc); getContentPane().setLayout(new BorderLayout()); getContentPane().add(mainPanel, CENTER); 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:net.minelord.gui.panes.IRCPane.java
public void startClient(final String nick) { IRCLog = new ArrayList<String>(); SwingUtilities.invokeLater(new Runnable() { @Override//from w w w . j av a2s . com public void run() { text = new JEditorPane("text/html", "<HTML>"); text.setEditable(false); kit = new HTMLEditorKit(); text.setEditorKit(kit); client.connect("irc.liberty-unleashed.co.uk", "#moomoohk", nick, instance); scroller = new JScrollPane(text); text.setEditable(false); connect(); scroller.setBounds(20, 20, 810, 250); add(scroller); input = new JTextField(); input.setBounds(20, 270, 810, 30); Color bgColor = Color.gray.darker().darker(); UIDefaults defaults = new UIDefaults(); defaults.put("EditorPane[Enabled].backgroundPainter", bgColor); text.putClientProperty("Nimbus.Overrides", defaults); text.putClientProperty("Nimbus.Overrides.InheritDefaults", true); text.setBackground(bgColor); input.setBackground(Color.gray); input.setForeground(Color.gray.darker().darker().darker()); input.setEnabled(false); text.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (event.getDescription().charAt(0) == '#') { String[] params = { event.getDescription() }; IRCCommand.getCommand("/join").execute(client, params); } else OSUtils.browse(event.getURL().toString()); } } }); text.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent paramFocusEvent) { } @Override public void focusGained(FocusEvent paramFocusEvent) { input.requestFocus(); } }); scroller.setViewportView(text); add(input); input.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == 10) { if (input.getText().length() > 0) { lastCommandSelector = lastCommands.size(); lastCommands.add(input.getText()); } sendMessage(input.getText()); input.setText(""); } if (arg0.getKeyCode() == 27) input.setText(""); if (arg0.getKeyCode() == 17) { int before = input.getText().length(); if (input.getText().charAt(0) == '/') { input.setText(completeNick(input.getText())); input.select( input.getText().length() - completeNick(input.getText()).length() + before, input.getText().length()); } else { input.setText(completeCommand(input.getText())); input.select(input.getText().length() - completeCommand(input.getText()).length() + before, input.getText().length()); } } if (arg0.getKeyCode() == 38) if (lastCommandSelector > 0) { lastCommandSelector--; input.setText(lastCommands.get(lastCommandSelector)); } if (arg0.getKeyCode() == 40) if (lastCommandSelector < lastCommands.size()) { lastCommandSelector++; if (lastCommandSelector == lastCommands.size()) input.setText(""); if (lastCommandSelector < lastCommands.size()) input.setText(lastCommands.get(lastCommandSelector)); return; } } @Override public void keyPressed(KeyEvent arg0) { } }); } }); }
From source file:com.marginallyclever.makelangelo.MainGUI.java
public Container CreateContentPane() { //Create the content-pane-to-be. JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setOpaque(true);// w w w .j av a 2s. c o m // the log panel log = new JTextPane(); log.setEditable(false); log.setBackground(Color.BLACK); logPane = new JScrollPane(log); kit = new HTMLEditorKit(); doc = new HTMLDocument(); log.setEditorKit(kit); log.setDocument(doc); DefaultCaret c = (DefaultCaret) log.getCaret(); c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); ClearLog(); settingsPane = SettingsPanel(); previewPane = new DrawPanel(machineConfiguration); preparePane = ProcessImages(); driveControls = new MakelangeloDriveControls(); driveControls.createPanel(this, translator, machineConfiguration); driveControls.updateButtonAccess(false, false); statusBar = new StatusBar(translator); contextMenu = new JTabbedPane(); contextMenu.addTab(translator.get("MenuSettings"), null, settingsPane, null); contextMenu.addTab(translator.get("MenuGCODE"), null, preparePane, null); contextMenu.addTab(translator.get("MenuDraw"), null, driveControls, null); contextMenu.addTab("Log", null, logPane, null); // major layout split_left_right = new Splitter(JSplitPane.HORIZONTAL_SPLIT); split_left_right.add(previewPane); split_left_right.add(contextMenu); contentPane.add(statusBar, BorderLayout.SOUTH); contentPane.add(split_left_right, BorderLayout.CENTER); return contentPane; }
From source file:net.yacy.cora.util.Html2Image.java
/** * render a html page with a JEditorPane, which can do html up to html v 3.2. No CSS supported! * @param url//from w ww .jav a2 s. c o m * @param size * @throws IOException */ public static void writeSwingImage(String url, Dimension size, File destination) throws IOException { // set up a pane for rendering final JEditorPane htmlPane = new JEditorPane(); htmlPane.setSize(size); htmlPane.setEditable(false); final HTMLEditorKit kit = new HTMLEditorKit() { private static final long serialVersionUID = 1L; @Override public Document createDefaultDocument() { HTMLDocument doc = (HTMLDocument) super.createDefaultDocument(); doc.setAsynchronousLoadPriority(-1); return doc; } @Override public ViewFactory getViewFactory() { return new HTMLFactory() { @Override public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView) view).setLoadsSynchronously(true); } return view; } }; } }; htmlPane.setEditorKitForContentType("text/html", kit); htmlPane.setContentType("text/html"); htmlPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { } }); // load the page try { htmlPane.setPage(url); } catch (IOException e) { e.printStackTrace(); } // render the page Dimension prefSize = htmlPane.getPreferredSize(); BufferedImage img = new BufferedImage(prefSize.width, htmlPane.getPreferredSize().height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = img.getGraphics(); htmlPane.setSize(prefSize); htmlPane.paint(graphics); ImageIO.write(img, destination.getName().endsWith("jpg") ? "jpg" : "png", destination); }
From source file:org.ambraproject.service.trackback.LinkbackServiceImpl.java
/** * {@inheritDoc}// w w w. j av a 2 s. com */ @Override public BlogLinkDigest examineBlogPage(URL blogUrl, LinkValidator linkValidator) throws IOException { log.debug("Validating blog at {}", blogUrl); // Trick gets Swing's HTML parser HTMLEditorKit.Parser parser = (new HTMLEditorKit() { public Parser getParser() { return super.getParser(); } }).getParser(); // Read HTML file into string StringBuilder html = new StringBuilder(); BufferedReader bufferedReader = null; try { InputStream inputStream = blogUrl.openStream(); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = bufferedReader.readLine()) != null) { html.append(line); } //parse the html, looking for links LinkCallback callback = new LinkCallback(linkValidator); parser.parse(new StringReader(html.toString()), callback, true); return callback.makeDigest(); } finally { //close our reader (closes all the encapsulated streams) if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { log.error("Error closing buffered input reader to " + blogUrl, e); } } } }
From source file:org.apache.roller.weblogger.util.LinkbackExtractor.java
private void extractByParsingHtml(String refererURL, String requestURL) throws MalformedURLException, IOException { URL url = new URL(refererURL); InputStream is = url.openStream(); mRefererURL = refererURL;/* w ww. j a v a 2 s . com*/ if (requestURL.startsWith("http://www.")) { mRequestURLWWW = requestURL; mRequestURL = "http://" + mRequestURLWWW.substring(11); } else { mRequestURL = requestURL; mRequestURLWWW = "http://www." + mRequestURL.substring(7); } // Trick gets Swing's HTML parser Parser parser = (new HTMLEditorKit() { public Parser getParser() { return super.getParser(); } }).getParser(); // Read HTML file into string StringBuffer sb = new StringBuffer(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); try { String line = null; while ((line = br.readLine()) != null) { sb.append(line); } } finally { br.close(); } // Parse HTML string to find title and start and end position // of the referring excerpt. StringReader sr = new StringReader(sb.toString()); parser.parse(sr, new LinkbackCallback(), true); if (mStart != 0 && mEnd != 0 && mEnd > mStart) { mExcerpt = sb.toString().substring(mStart, mEnd); mExcerpt = Utilities.removeHTML(mExcerpt); if (mExcerpt.length() > mMaxExcerpt) { mExcerpt = mExcerpt.substring(0, mMaxExcerpt) + "..."; } } if (mTitle.startsWith(">") && mTitle.length() > 1) { mTitle = mTitle.substring(1); } }
From source file:org.codinjutsu.tools.jenkins.view.ConfigurationPanel.java
private void initDebugTextPane() { HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); HTMLDocument htmlDocument = new HTMLDocument(); debugTextPane.setEditable(false);//from w w w. j a v a2 s .c o m debugTextPane.setBackground(Color.WHITE); debugTextPane.setEditorKit(htmlEditorKit); htmlEditorKit.install(debugTextPane); debugTextPane.setDocument(htmlDocument); }
From source file:org.deegree.tools.metadata.InspireValidator.java
/** * parse INSPIRE metadata validator response and print out result onto the console * /* ww w . j a v a2 s . com*/ * @param response * @throws IOException * @throws IllegalStateException */ private void parseServiceResponse(HttpResponse response) throws Exception { String s = FileUtils.readTextFile(((BasicHttpResponse) response).getEntity().getContent()).toString(); if (response.getStatusLine().getStatusCode() != 200) { outputWriter.println(s); outputWriter.println(); return; } s = "<html><head></head><body>" + s + "</body></html>"; BufferedReader br = new BufferedReader(new StringReader(s)); HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument(); HTMLEditorKit.Parser parser = new ParserDelegator(); HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0); parser.parse(br, callback, true); // Parse ElementIterator iterator = new ElementIterator(htmlDoc); Element element; while ((element = iterator.next()) != null) { AttributeSet attributes = element.getAttributes(); Object name = attributes.getAttribute(StyleConstants.NameAttribute); if ((name instanceof HTML.Tag) && ((name == HTML.Tag.IMPLIED))) { // Build up content text as it may be within multiple elements StringBuffer text = new StringBuffer(); int count = element.getElementCount(); for (int i = 0; i < count; i++) { Element child = element.getElement(i); AttributeSet childAttributes = child.getAttributes(); if (childAttributes.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.CONTENT) { int startOffset = child.getStartOffset(); int endOffset = child.getEndOffset(); int length = endOffset - startOffset; text.append(htmlDoc.getText(startOffset, length)); } } outputWriter.println(text.toString()); } } outputWriter.println("---------------------------------------------------------------------"); outputWriter.println(); }
From source file:org.jivesoftware.sparkimpl.updater.CheckUpdates.java
public void downloadUpdate(final File downloadedFile, final SparkVersion version) { final java.util.Timer timer = new java.util.Timer(); // Prepare HTTP post final GetMethod post = new GetMethod(version.getDownloadURL()); // Get HTTP client Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443)); final HttpClient httpclient = new HttpClient(); String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (ModelUtil.hasLength(proxyHost) && ModelUtil.hasLength(proxyPort)) { try {//from ww w . ja v a 2s . com httpclient.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); } catch (NumberFormatException e) { Log.error(e); } } // Execute request try { int result = httpclient.executeMethod(post); if (result != 200) { return; } long length = post.getResponseContentLength(); int contentLength = (int) length; bar = new JProgressBar(0, contentLength); } catch (IOException e) { Log.error(e); } final JFrame frame = new JFrame(Res.getString("title.downloading.im.client")); frame.setIconImage(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_IMAGE).getImage()); titlePanel = new TitlePanel(Res.getString("title.upgrading.client"), Res.getString("message.version", version.getVersion()), SparkRes.getImageIcon(SparkRes.SEND_FILE_24x24), true); final Thread thread = new Thread(new Runnable() { public void run() { try { InputStream stream = post.getResponseBodyAsStream(); long size = post.getResponseContentLength(); ByteFormat formater = new ByteFormat(); sizeText = formater.format(size); titlePanel.setDescription(Res.getString("message.version", version.getVersion()) + " \n" + Res.getString("message.file.size", sizeText)); downloadedFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(downloadedFile); copy(stream, out); out.close(); if (!cancel) { downloadComplete = true; promptForInstallation(downloadedFile, Res.getString("title.download.complete"), Res.getString("message.restart.spark")); } else { out.close(); downloadedFile.delete(); } UPDATING = false; frame.dispose(); } catch (Exception ex) { // Nothing to do } finally { timer.cancel(); // Release current connection to the connection pool once you are done post.releaseConnection(); } } }); frame.getContentPane().setLayout(new GridBagLayout()); frame.getContentPane().add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); frame.getContentPane().add(bar, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); JEditorPane pane = new JEditorPane(); boolean displayContentPane = version.getChangeLogURL() != null || version.getDisplayMessage() != null; try { pane.setEditable(false); if (version.getChangeLogURL() != null) { pane.setEditorKit(new HTMLEditorKit()); pane.setPage(version.getChangeLogURL()); } else if (version.getDisplayMessage() != null) { pane.setText(version.getDisplayMessage()); } if (displayContentPane) { frame.getContentPane().add(new JScrollPane(pane), new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); } } catch (IOException e) { Log.error(e); } frame.getContentPane().setBackground(Color.WHITE); frame.pack(); if (displayContentPane) { frame.setSize(600, 400); } else { frame.setSize(400, 100); } frame.setLocationRelativeTo(SparkManager.getMainWindow()); GraphicUtils.centerWindowOnScreen(frame); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { thread.interrupt(); cancel = true; UPDATING = false; if (!downloadComplete) { JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.updating.cancelled"), Res.getString("title.cancelled"), JOptionPane.ERROR_MESSAGE); } } }); frame.setVisible(true); thread.start(); timer.scheduleAtFixedRate(new TimerTask() { int seconds = 1; public void run() { ByteFormat formatter = new ByteFormat(); long value = bar.getValue(); long average = value / seconds; String text = formatter.format(average) + "/Sec"; String total = formatter.format(value); titlePanel.setDescription(Res.getString("message.version", version.getVersion()) + " \n" + Res.getString("message.file.size", sizeText) + "\n" + Res.getString("message.transfer.rate") + ": " + text + "\n" + Res.getString("message.total.downloaded") + ": " + total); seconds++; } }, 1000, 1000); }
From source file:org.knime.ext.textprocessing.nodes.view.documentviewer2.DocumentPanel2.java
/** * Creates new instance of {@code DocumentPanel} with given document view model to show, and the preferred width and * height to set.// w ww . j a v a 2 s.c o m * * @param docViewModel The document view model. * @param preferredWidth The preferred width to set. * @param preferredHeight The preferred height to set. */ public DocumentPanel2(final DocumentViewModel docViewModel, final int preferredWidth, final int preferredHeight) { super(new BorderLayout()); if (docViewModel == null) { throw new IllegalArgumentException("Document view model may not be null!"); } m_docViewModel = docViewModel; m_fulltextPane = new JEditorPane(); m_fulltextPane.setContentType("text/html"); m_fulltextPane.setEditable(false); m_fulltextPane.setCaretPosition(0); m_fulltextPane.addHyperlinkListener(new LinkListener()); m_fulltextPane.setToolTipText("Select text and right click."); HTMLEditorKit editorKit = new HTMLEditorKit(); // Adding stylesheet to the document StyleSheet sheet = editorKit.getStyleSheet(); sheet.addRule( "html, body {margin: 0; padding: 4px; color: #000000; font-family: 'Roboto', sans-serif; background: #ffffff; font-size: 12px;}"); sheet.addRule("table { border-collapse: collapse; }"); sheet.addRule("th, td { border: 1px solid #000000; padding: 10px 15px; }"); sheet.addRule( ".docHeading {display: block; font-size: 15px; font-weight: bold; margin: 5px 0 30px 0; width: 100%;}"); sheet.addRule( ".sep { width:100%; border-bottom: 1px dashed #8c8b8b ; top: 10%; bottom: 20%; position: absolute; margin: 10px 0 10px 0;}"); sheet.addRule(".subHeading { font-weight: 500; font-style: italic; text-transform: lowercase; }"); editorKit.setStyleSheet(sheet); m_fulltextPane.setEditorKit(editorKit); Document doc = editorKit.createDefaultDocument(); m_fulltextPane.setDocument(doc); m_fulltextPane.setText(getPreparedText()); m_rightClickMenue = new JPopupMenu(); JMenuItem item; for (String source : SearchEngines.getInstance().getSearchEngineNames()) { item = new JMenuItem(source); item.addActionListener(new RightClickMenueListener()); m_rightClickMenue.add(item); } m_fulltextPane.setComponentPopupMenu(m_rightClickMenue); JScrollPane jsp = new JScrollPane(m_fulltextPane); jsp.setPreferredSize(new Dimension(preferredWidth, preferredHeight)); add(jsp, BorderLayout.CENTER); }