List of usage examples for javax.swing JEditorPane JEditorPane
public JEditorPane()
JEditorPane
. From source file:com.enderville.enderinstaller.ui.Installer.java
private void loadModDescription(String modName) { JPanel p = getModDescriptionPane(); p.removeAll();/*from w w w . j a va 2 s .com*/ p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); final String extras = InstallerConfig.getExtraModsFolder(); final String modFolderName = FilenameUtils.concat(extras, modName); File modFolder = new File(modFolderName); if (!modFolder.exists()) { LOGGER.error("Mod folder for " + modName + " does not exist."); } File descrFile = new File(FilenameUtils.concat(modFolderName, "description.txt")); File imgFile = new File(FilenameUtils.concat(modFolderName, "image.png")); if (!descrFile.exists() && !imgFile.exists()) { p.add(new JLabel("<html>No description for:<br>" + modName + "</html>")); } else { if (imgFile.exists()) { try { JLabel label = new JLabel(); BufferedImage img = ImageIO.read(imgFile); label.setIcon(new ImageIcon(img)); p.add(label); } catch (IOException e) { LOGGER.error("Error reading image file: " + imgFile.getPath(), e); } } if (descrFile.exists()) { StringBuilder buffer = new StringBuilder(); try { BufferedReader r = new BufferedReader(new FileReader(descrFile)); String l = null; while ((l = r.readLine()) != null) { buffer.append(l + "\n"); } r.close(); JEditorPane area = new JEditorPane(); area.setContentType("text/html"); area.setText(buffer.toString()); area.setEditable(false); area.addHyperlinkListener(this); area.setCaretPosition(0); p.add(new JScrollPane(area)); } catch (IOException e) { LOGGER.error("Error reading description file: " + descrFile.getPath(), e); } } } p.validate(); p.repaint(); }
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java
/** * Convert a html code to an image// w w w . jav a 2 s . co m * * @param html html to convert * @return html converted to png * @throws IOException if error * @throws PPTGeneratorException */ protected byte[] htmlToImage(String html) throws IOException, PPTGeneratorException { try { JEditorPane editor = new JEditorPane(); editor.setContentType("text/html"); editor.setText(html); editor.setSize(editor.getPreferredSize()); editor.addNotify(); LOGGER.debug("Panel is built"); BufferedImage bufferSave = new BufferedImage(editor.getPreferredSize().width, editor.getPreferredSize().height, BufferedImage.TYPE_3BYTE_BGR); Graphics g = bufferSave.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, editor.getPreferredSize().width, editor.getPreferredSize().height); editor.paint(g); LOGGER.debug("graphics is drawn"); ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(bufferSave, "png", out); return out.toByteArray(); } catch (HeadlessException e) { LOGGER.error("X Server no initialized or -Djava.awt.headless=true not set !"); throw new PPTGeneratorException("X Server no initialized or -Djava.awt.headless=true not set !"); } }
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java
/** * Add an image with a html code without change its dimension * /* w w w . ja v a 2s. c o m*/ * @param slideToSet slide to set * @param html html code * @param x horizontal position * @param y vertical position * @throws IOException if error * @throws PPTGeneratorException */ protected void addHtmlPicture(Slide slideToSet, String html, int x, int y) throws IOException, PPTGeneratorException { try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (!ge.isHeadlessInstance()) { LOGGER.warn("Runtime is not configured for supporting graphiv manipulation !"); } JEditorPane editor = new JEditorPane(); editor.setContentType("text/html"); editor.setText(html); LOGGER.debug("Editor pane is built"); editor.setSize(editor.getPreferredSize()); editor.addNotify(); // Serveur X requis LOGGER.debug("Panel rendering is done"); BufferedImage bufferSave = new BufferedImage(editor.getPreferredSize().width, editor.getPreferredSize().height, BufferedImage.TYPE_3BYTE_BGR); Graphics g = bufferSave.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, editor.getPreferredSize().width, editor.getPreferredSize().height); editor.paint(g); LOGGER.debug("graphics is drawn"); ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(bufferSave, "png", out); LOGGER.debug("image is written"); addPicture(slideToSet, out.toByteArray(), new Rectangle(x, y, editor.getPreferredSize().width, editor.getPreferredSize().height)); LOGGER.debug("image is added"); } catch (HeadlessException e) { LOGGER.error("X Server no initialized or -Djava.awt.headless=true not set !"); throw new PPTGeneratorException("X Server no initialized or -Djava.awt.headless=true not set !"); } }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * Create if needed and return the editorpane for the description tab * * @return description view/*from www . j a v a 2s . c om*/ */ private JEditorPane getHtmlView() { if (htmlView == null) { JEditorPane tmp = new JEditorPane(); tmp.setContentType("text/html"); tmp.setPreferredSize(new Dimension(300, 400)); tmp.setEditable(false); tmp.setText(" "); htmlView = tmp; } return htmlView; }
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 w w w . j a v a 2 s . co m // 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:EditorPaneExample20.java
public static void main(String[] args) { try {//from w ww . ja va 2s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new HTMLInsertFrame("Custom HTML Insertion", new JEditorPane()); f.setVisible(true); }
From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java
public void actionPerformed(ActionEvent arg0) { JMenuItem source = (JMenuItem) (arg0.getSource()); if (source.getText().equals(MENU_ABOUT)) { JOptionPane.showMessageDialog(this, WDBearManager.VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "\n" + "Supports any WDB version\n" + "\n" + "Thanks to:\n" + "DarkMan for testing,\n" + "John for the 1.10 specs, Annunaki for helping with the header,\n" + "Andrikos for the 1.6.x WDB specs, Pyro's WDBViewer, WDDG Forum,\n" + "blizzhackers, etc etc\n\n" + "This program uses: \n" + "JGoodies from http://www.jgoodies.com/\n" + "Hypersonic SQL database 1.7.3\n" + "Apache Log4J, Xerces\n" + "Jakarta Commons Logging and CLI\n" + "Castor from ExoLab\n" + "MySQL JDBC connector 3.1.7\n" + "HTTPUNIT from Russell Gold\n" + "Jython 2.1\n" + "Refer to directory 'licenses' for more details about the software used\n" + "PLEASE:\n" + "If you like this program and find it usefull:\n" + "Please donate money to a charity oranization of your choice.\n" + "I recommend any organization that fights cancer.\n\n" + "License:\n" + "WDBearMgr is placed under the GNU GPL. \n" + "For further information, see the page :\n" + "http://www.gnu.org/copyleft/gpl.html.\n" + "See licenses/GPL_license.html\n" + "\n" + "For a different license please contact the author.", "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); return;// w w w.j ava2 s .com } else if (source.getText().equals(MENU_HELP)) { JFrame myFrame = new JFrame("doc/html/index.html"); //myFrame.setFont( ); URL urlHTML = null; try { JEditorPane htmlPane = new JEditorPane(); //htmlPane.setFont(sourceFont); // .out.println("/scripts/"+source.getName()+".py"); File scriptFile = new File("doc/html/index.html"); urlHTML = scriptFile.toURL();//this.getClass().getResource("/scripts/"+source.getName()+".py"); // .out.println( urlHTML ); // .out.println( urlHTML.toExternalForm() ); htmlPane.setPage(urlHTML); htmlPane.setEditable(false); JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane); htmlPane.addHyperlinkListener(myJEPHL); myFrame.getContentPane().add(new JScrollPane(htmlPane)); myFrame.pack(); myFrame.setSize(640, 480); myFrame.show(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not open 'doc/html/index.html'", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); } } else if (source.getText().equals(MENU_JDOCS)) { JFrame myFrame = new JFrame("doc/javadoc/index.html"); //myFrame.setFont( ); URL urlHTML = null; try { JEditorPane htmlPane = new JEditorPane(); //htmlPane.setFont(sourceFont); // .out.println("/scripts/"+source.getName()+".py"); File scriptFile = new File("doc/javadoc/index.html"); urlHTML = scriptFile.toURL(); htmlPane.setPage(urlHTML); htmlPane.setEditable(false); JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane); htmlPane.addHyperlinkListener(myJEPHL); myFrame.getContentPane().add(new JScrollPane(htmlPane)); myFrame.pack(); myFrame.setSize(640, 480); myFrame.show(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not open 'doc/javadoc/index.html'", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); } } else if (source.getText().equals(MENU_CHECKUPDATE)) { Properties dbProps = null; String filName = PROPS_CHECK_UPDATE; try { dbProps = ReadPropertiesFile.readProperties(filName); String updFile = dbProps.getProperty(KEY_UPD_FILE); if (updFile == null) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not find update information", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); return; } String updSite = dbProps.getProperty(KEY_WDBMGR_SITE); if (updFile == null) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not find SITE information", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); return; } URL urlUpdScript = new URL(updFile); BufferedReader in = new BufferedReader(new InputStreamReader(urlUpdScript.openStream())); String versionTXT = in.readLine(); String downloadName = in.readLine(); in.close(); if (versionTXT.equals(WDBearManager.VERSION_INFO)) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "You are using the latest version, no updates available", "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); return; } else { // Read version.txt String versionInfo = (String) dbProps.getProperty(KEY_VERSION_INFO); URL urlversionInfo = new URL(versionInfo); BufferedReader brVInfo = new BufferedReader(new InputStreamReader(urlversionInfo.openStream())); StringBuffer sbuVInfo = new StringBuffer(); String strLine = ""; boolean foundStart = false; while ((strLine = brVInfo.readLine()) != null) { if (strLine.startsWith("---")) { break; } if (foundStart == true) { sbuVInfo.append(strLine); sbuVInfo.append("\n"); continue; } if (strLine.startsWith(versionTXT)) { foundStart = true; continue; } } brVInfo.close(); int n = JOptionPane.showConfirmDialog(this, "New version available - Please visit " + updSite + "\n\n" + versionTXT + "\n" + "\n" + "You are using version:\n" + WDBearManager.VERSION_INFO + "\n" + "\n" + "Do you want to download this version?\n\n" + "Version information:\n" + sbuVInfo.toString(), VERSION_INFO + "by kizura", JOptionPane.YES_NO_OPTION); // JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" // + "by kizura\n" + WDBManager.EMAIL + "\n\n" // + "New version available - Please visit " + updSite, // "Warning " // + VERSION_INFO, JOptionPane.WARNING_MESSAGE); if (n == 0) { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Please select download location"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { URL urlUpd = new URL(downloadName); BufferedInputStream bin = new BufferedInputStream(urlUpd.openStream()); System.out.println( new File(chooser.getSelectedFile(), urlUpd.getFile()).getAbsolutePath()); File thisFile = new File(chooser.getSelectedFile(), urlUpd.getFile()); BufferedOutputStream bout = new BufferedOutputStream( new FileOutputStream(thisFile)); byte[] bufFile = new byte[102400]; int bytesRead = 0; while ((bytesRead = bin.read(bufFile)) != -1) { bout.write(bufFile, 0, bytesRead); } bin.close(); bout.close(); JOptionPane.showMessageDialog(this, "Update downloaded successfully" + "\n" + "Please check '" + thisFile.getAbsolutePath() + "'", "Success " + WDBearManager.VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); //String msg = WriteCSV.writeCSV(chooser.getSelectedFile(), this.items); } catch (Exception ex) { String msg = ex.getMessage(); JOptionPane.showMessageDialog(this, msg + "\n" + "Error downloading update", "Error " + WDBearManager.VERSION_INFO, JOptionPane.ERROR_MESSAGE); } } } // user selected "download" return; } } catch (Exception ex) { ex.printStackTrace(); } } else { System.exit(0); } }
From source file:com.marginallyclever.makelangelo.MainGUI.java
/** * * @param html String of valid HTML./* w w w . j a va 2 s. co m*/ * @return a */ private 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) { // FIXME Auto-generated catch block exception.printStackTrace(); } } } } }; bottomText.addHyperlinkListener(hyperlinkListener); return bottomText; }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
private void printHtmlParagraphsPdf(Section section, String content, int parentLevel) throws Exception { if (content == null || content.length() == 0) return;//from www . jav a2s. c o m if (isBase64Encoded(content) || "true".equals(System.getProperty("mdw.designer.force.msword"))) { byte[] docBytes = decodeBase64(content); content = new DocxBuilder(docBytes).toHtml(); content = content.replaceAll(" ", " "); } JEditorPane documentation = new JEditorPane(); documentation.setContentType("text/html"); documentation.setText(content); javax.swing.text.Document swingdoc = documentation.getDocument(); Element[] elements = swingdoc.getRootElements(); boolean useGenerate = true; if (useGenerate) { for (Element e : elements) { Object gen = generateElementHtml(e, 0, normalFont); addSectionContentPdf(section, gen, parentLevel); } } else { // use print for (Element e : elements) { printElementHtml(e, section, 0, normalFont, parentLevel); } } }
From source file:base.BasePlayer.Main.java
void setMenuBar() { //filemenu.addMouseListener(this); //toolmenu.addMouseListener(this); filemenu = new JMenu("File"); toolmenu = new JMenu("Tools"); help = new JMenu("Help"); about = new JMenu("About"); menubar = new JMenuBar(); //help.addMouseListener(this); exit = new JMenuItem("Exit"); manual = new JButton("Online manual"); manual.addActionListener(new ActionListener() { @Override//from w ww. j av a 2s . co m public void actionPerformed(ActionEvent arg0) { Main.gotoURL("https://baseplayer.fi/BPmanual"); } }); // opensamples = new JMenuItem("Add samples"); zoomout = new JButton("Zoom out"); back = new JButton("<<"); forward = new JButton(">>"); manage = new JButton("Variant Manager"); openvcfs = new JMenuItem("Add VCFs", open); openbams = new JMenuItem("Add BAMs", open); average = new JMenuItem("Coverage calculator"); update = new JMenuItem("Update"); update.setVisible(false); errorlog = new JMenuItem("View log"); //helpLabel = new JLabel("This is pre-release version of BasePlayer\nContact: help@baseplayer.fi\n\nUniversity of Helsinki"); addURL = new JMenu("Add from URL"); urlField = new JTextField("Enter URL"); addtracks = new JMenuItem("Add tracks"); fromURL = new JMenuItem("Add track from URL"); addcontrols = new JMenuItem("Add controls"); pleiadesButton = new JMenuItem("PLEIADES"); saveProject = new JMenuItem("Save project"); saveProjectAs = new JMenuItem("Save project as..."); openProject = new JMenuItem("Open project"); clear = new JMenuItem("Clear data"); clearMemory = new JMenuItem("Clean memory"); // welcome = new JMenuItem("Welcome screen"); filemenu.add(openvcfs); filemenu.add(openbams); variantCaller = new JMenuItem("Variant Caller"); tbrowser = new JMenuItem("Table Browser"); bconvert = new JMenuItem("BED converter"); peakCaller = new JMenuItem("Peak Caller"); addtracks = new JMenuItem("Add tracks", open); filemenu.add(addtracks); addcontrols = new JMenuItem("Add controls", open); filemenu.add(addcontrols); filemenu.add(fromURL); if (pleiades) { pleiadesButton.setPreferredSize(buttonDimension); pleiadesButton.addActionListener(this); filemenu.add(pleiadesButton); } filemenu.add(new JSeparator()); openProject = new JMenuItem("Open project", open); filemenu.add(openProject); saveProject = new JMenuItem("Save project", save); filemenu.add(saveProject); saveProjectAs = new JMenuItem("Save project as...", save); filemenu.add(saveProjectAs); filemenu.add(new JSeparator()); filemenu.add(genome); filemenu.add(update); filemenu.add(clear); filemenu.add(new JSeparator()); filemenu.add(exit); exit.addActionListener(this); menubar.add(filemenu); manage.addActionListener(this); manage.addMouseListener(this); update.addActionListener(this); average.addActionListener(this); average.setEnabled(false); average.setToolTipText("No bam/cram files opened"); tbrowser.addActionListener(this); bconvert.addActionListener(this); toolmenu.add(tbrowser); toolmenu.add(average); toolmenu.add(variantCaller); toolmenu.add(bconvert); fromURL.addMouseListener(this); fromURL.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { final JPopupMenu menu = new JPopupMenu(); final JTextField area = new JTextField(); JButton add = new JButton("Fetch"); JLabel label = new JLabel("Paste track URL below"); JScrollPane menuscroll = new JScrollPane(); add.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String urltext = area.getText().trim(); Boolean size = true; if (urltext.contains("pleiades")) { openPleiades(urltext); return; } if (!FileRead.isTrackFile(urltext)) { showError("The file format is not supported.\n" + "Supported formats: bed, bigwig, bigbed, gff, bedgraph", "Error"); return; } if (!urltext.toLowerCase().endsWith(".bw") && !urltext.toLowerCase().endsWith(".bigwig") && !urltext.toLowerCase().endsWith(".bb") && !urltext.toLowerCase().endsWith(".bigbed")) { URL url = null; try { url = new URL(urltext); } catch (Exception ex) { menu.setVisible(false); Main.showError("Please paste whole url (protocol included)", "Error"); return; } URL testurl = url; HttpURLConnection huc = (HttpURLConnection) testurl.openConnection(); huc.setRequestMethod("HEAD"); int responseCode = huc.getResponseCode(); if (responseCode != 404) { SeekableStream stream = SeekableStreamFactory.getInstance().getStreamFor(url); TabixReader tabixReader = null; String index = null; try { if (stream.length() / (double) 1048576 >= Settings.settings .get("bigFile")) { size = false; } tabixReader = new TabixReader(urltext, urltext + ".tbi", stream); index = urltext + ".tbi"; testurl = new URL(index); huc = (HttpURLConnection) testurl.openConnection(); huc.setRequestMethod("HEAD"); responseCode = huc.getResponseCode(); if (responseCode == 404) { menu.setVisible(false); Main.showError("Index file (.tbi) not found in the URL.", "Error"); return; } } catch (Exception ex) { try { tabixReader = new TabixReader(urltext, urltext.substring(0, urltext.indexOf(".gz")) + ".tbi", stream); index = urltext.substring(0, urltext.indexOf(".gz")) + ".tbi"; } catch (Exception exc) { menu.setVisible(false); Main.showError("Could not read tabix file.", "Error"); } } if (tabixReader != null && index != null) { stream.close(); tabixReader.close(); menu.setVisible(false); FileRead filereader = new FileRead(); filereader.readBED(urltext, index, size); } } else { menu.setVisible(false); Main.showError("Not a valid URL", "Error"); } } else { URL url = null; try { url = new URL(urltext); } catch (Exception ex) { Main.showError("Please paste whole url (protocol included)", "Error"); return; } final URL testurl = url; HttpURLConnection huc = (HttpURLConnection) testurl.openConnection(); huc.setRequestMethod("HEAD"); int responseCode = huc.getResponseCode(); if (responseCode != 404) { menu.setVisible(false); FileRead filereader = new FileRead(); filereader.readBED(urltext, "nan", true); } else { menu.setVisible(false); Main.showError("Not a valid URL", "Error"); } } } catch (Exception ex) { ex.printStackTrace(); } } }); area.setFont(Main.menuFont); //area.setText("https://baseplayer.fi/tracks/Mappability_1000Genomes_pilot_mask.bed.gz"); menu.add(label); menu.add(menuscroll); menu.add(add); area.setPreferredSize(new Dimension(300, Main.defaultFontSize + 8)); area.setCaretPosition(0); area.revalidate(); menuscroll.getViewport().add(area); area.requestFocus(); menu.pack(); menu.show(frame, mouseX + 20, fromURL.getY()); } }); //toolmenu.add(peakCaller); variantCaller.setToolTipText("No bam/cram files opened"); variantCaller.addActionListener(this); variantCaller.setEnabled(false); peakCaller.setEnabled(true); peakCaller.addActionListener(this); settings.addActionListener(this); clearMemory.addActionListener(this); errorlog.addActionListener(this); toolmenu.add(clearMemory); toolmenu.add(errorlog); toolmenu.add(new JSeparator()); toolmenu.add(settings); menubar.add(toolmenu); menubar.add(manage); area = new JEditorPane(); String infotext = "<html><h2>BasePlayer</h2>This is a version " + version + " of BasePlayer (<a href=https://baseplayer.fi>https://baseplayer.fi</a>)<br/> Author: Riku Katainen <br/> University of Helsinki<br/>" + "Tumor Genomics Group (<a href=http://research.med.helsinki.fi/gsb/aaltonen/>http://research.med.helsinki.fi/gsb/aaltonen/</a>) <br/> " + "Contact: help@baseplayer.fi <br/> <br/>" + "Supported filetype for variants is VCF and VCF.gz (index file will be created if missing)<br/> " + "Supported filetypes for reads are BAM and CRAM. Index files required (.bai or .crai). <br/> " + "Supported filetypes for additional tracks are BED(.gz), GFF.gz, BedGraph, BigWig, BigBed.<br/> (tabix index required for bgzipped files). <br/><br/> " + "For optimal usage, you should have vcf.gz and bam -files for each sample. <br/> " + "e.g. in case you have a sample named as sample1, name all files similarly and <br/>" + "place in the same folder:<br/>" + "sample1.vcf.gz<br/>" + "sample1.vcf.gz.tbi<br/>" + "sample1.bam<br/>" + "sample1.bam.bai<br/><br/>" + "When you open sample1.vcf.gz, sample1.bam is recognized and opened<br/>" + "on the same track.<br/><br/>" + "Instructional videos can be viewed at our <a href=https://www.youtube.com/channel/UCywq-T7W0YPzACyB4LT7Q3g> Youtube channel</a>"; area = new JEditorPane(); area.setEditable(false); area.setEditorKit(JEditorPane.createEditorKitForContentType("text/html")); area.setText(infotext); area.setFont(Main.menuFont); area.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) { HyperlinkEvent.EventType type = hyperlinkEvent.getEventType(); final URL url = hyperlinkEvent.getURL(); if (type == HyperlinkEvent.EventType.ACTIVATED) { Main.gotoURL(url.toString()); } } }); about.add(area); about.addMouseListener(this); help.add(about); help.add(manual); menubar.add(help); JLabel emptylab = new JLabel(" "); emptylab.setEnabled(false); emptylab.setOpaque(false); menubar.add(emptylab); chromosomeDropdown.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 1, Color.lightGray)); chromosomeDropdown.setBorder(BorderFactory.createCompoundBorder(chromosomeDropdown.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 0))); chromlabel.setToolTipText("Current chromosome"); chromlabel.setFocusable(false); chromlabel.addMouseListener(this); chromlabel.setBackground(Color.white); chromlabel.setEditable(false); chromlabel.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.lightGray)); chromlabel.setBorder(BorderFactory.createCompoundBorder(chromlabel.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 0))); menubar.add(chromlabel); chromosomeDropdown.setBackground(Color.white); chromosomeDropdown.setToolTipText("Current chromosome"); menubar.add(chromosomeDropdown); JLabel empty3 = new JLabel(" "); empty3.setEnabled(false); empty3.setOpaque(false); menubar.add(empty3); menubar.add(back); menubar.add(searchField); searchField.setForeground(Color.gray); searchField.setBorder(BorderFactory.createCompoundBorder(searchField.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 0))); searchField.addMouseListener(this); menubar.add(back); menubar.add(searchField); searchField.setForeground(Color.gray); back.addMouseListener(this); back.setToolTipText("Back"); forward.addMouseListener(this); forward.setToolTipText("Forward"); back.setEnabled(false); forward.setEnabled(false); searchField.addMouseListener(this); menubar.add(back); menubar.add(searchField); searchField.setForeground(Color.gray); back.addMouseListener(this); forward.addMouseListener(this); back.setEnabled(false); forward.setEnabled(false); forward.setMargin(new Insets(0, 2, 0, 2)); back.setMargin(new Insets(0, 2, 0, 2)); menubar.add(forward); JLabel empty4 = new JLabel(" "); empty4.setOpaque(false); empty4.setEnabled(false); menubar.add(empty4); menubar.add(zoomout); JLabel empty5 = new JLabel(" "); empty5.setEnabled(false); empty5.setOpaque(false); menubar.add(empty5); positionField.setEditable(false); positionField.setBackground(new Color(250, 250, 250)); positionField.setMargin(new Insets(0, 2, 0, 0)); positionField.setBorder(BorderFactory.createCompoundBorder(widthLabel.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 0))); menubar.add(positionField); widthLabel.setEditable(false); widthLabel.setBackground(new Color(250, 250, 250)); widthLabel.setMargin(new Insets(0, 2, 0, 0)); widthLabel.setBorder(BorderFactory.createCompoundBorder(widthLabel.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 0))); JLabel empty6 = new JLabel(" "); empty6.setEnabled(false); empty6.setOpaque(false); menubar.add(empty6); menubar.add(widthLabel); JLabel empty7 = new JLabel(" "); empty7.setOpaque(false); empty7.setEnabled(false); menubar.add(empty7); }