use of javax.swing.text.html.HTMLEditorKit in project jdk8u_jdk by JetBrains.
the class bug7189299 method verifySingleDefaultButtonModelListener.
private static void verifySingleDefaultButtonModelListener() {
HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit();
StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit.getInputAttributes());
DefaultButtonModel model = ((DefaultButtonModel) style.getAttribute(StyleConstants.ModelAttribute));
ActionListener[] listeners = model.getActionListeners();
int actionListenerNum = listeners.length;
if (actionListenerNum != 1) {
throw new RuntimeException("Expected single ActionListener object registered with " + "DefaultButtonModel; found " + actionListenerNum + " listeners registered.");
}
int changeListenerNum = model.getChangeListeners().length;
if (changeListenerNum != 1) {
throw new RuntimeException("Expected at most one ChangeListener object registered " + "with DefaultButtonModel; found " + changeListenerNum + " listeners registered.");
}
int itemListenerNum = model.getItemListeners().length;
if (itemListenerNum != 1) {
throw new RuntimeException("Expected at most one ItemListener object registered " + "with DefaultButtonModel; found " + itemListenerNum + " listeners registered.");
}
}
use of javax.swing.text.html.HTMLEditorKit in project knime-core by knime.
the class JSnippetPanel method initComponents.
private void initComponents() {
m_colList = new JList(new DefaultListModel());
m_colList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_colList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_colList.getSelectedValue();
if (selected != null) {
onSelectionInColumnList(selected);
}
}
}
});
m_colList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_colList.getSelectedValue();
if (selected != null) {
onSelectionInColumnList(selected);
}
}
}
});
m_colList.setCellRenderer(new ListRenderer());
m_flowVarsList = new JList(new DefaultListModel());
m_flowVarsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// enable tooltip
m_flowVarsList.setToolTipText("");
m_flowVarsList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_flowVarsList.getSelectedValue();
if (selected != null) {
onSelectionInVariableList(selected);
}
}
}
});
m_flowVarsList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_flowVarsList.getSelectedValue();
if (selected != null) {
onSelectionInVariableList(selected);
}
}
}
});
m_flowVarsList.setCellRenderer(new FlowVariableListCellRenderer());
m_categories = new JComboBox(m_manipProvider.getCategories().toArray());
m_categories.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
String category = (String) cb.getSelectedItem();
updateManipulatorList(category);
}
});
m_manipulators = new JList(new DefaultListModel());
m_manipulators.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_manipulators.setCellRenderer(new ManipulatorListCellRenderer());
m_manipulators.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
onSelectionInManipulatorList(selected);
}
}
}
});
m_manipulators.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
onSelectionInManipulatorList(selected);
}
}
}
});
m_manipulators.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
Object selected = m_manipulators.getSelectedValue();
if (selected != null) {
Manipulator manipulator = (Manipulator) selected;
m_description.setText(manipulator.getDescription());
m_description.setCaretPosition(0);
} else {
m_description.setText("");
}
}
});
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet css = new StyleSheet();
css.addRule("* { font-family: sans-serif; }");
kit.setStyleSheet(css);
m_description = new JTextPane();
m_description.setEditorKit(kit);
m_description.setEditable(false);
m_description.setBackground(getBackground());
updateManipulatorList(ManipulatorProvider.ALL_CATEGORY);
initSubComponents();
}
use of javax.swing.text.html.HTMLEditorKit in project megameklab by MegaMek.
the class UnitUtil method showUnitCostBreakDown.
public static void showUnitCostBreakDown(Entity unit, JFrame frame) {
HTMLEditorKit kit = new HTMLEditorKit();
unit.calculateBattleValue(true, true);
unit.getCost(true);
JEditorPane textPane = new JEditorPane("text/html", "");
JScrollPane scroll = new JScrollPane();
textPane.setEditable(false);
textPane.setCaret(new DefaultCaret());
textPane.setEditorKit(kit);
scroll.setViewportView(textPane);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scroll.getVerticalScrollBar().setUnitIncrement(20);
textPane.setText(unit.getBVText());
scroll.setVisible(true);
JDialog jdialog = new JDialog();
jdialog.add(scroll);
Dimension size = new Dimension(CConfig.getIntParam("WINDOWWIDTH") / 2, CConfig.getIntParam("WINDOWHEIGHT"));
jdialog.setPreferredSize(size);
jdialog.setMinimumSize(size);
scroll.setPreferredSize(size);
scroll.setMinimumSize(size);
jdialog.setLocationRelativeTo(frame);
jdialog.setVisible(true);
try {
textPane.setSelectionStart(0);
textPane.setSelectionEnd(0);
} catch (Exception ex) {
}
}
use of javax.swing.text.html.HTMLEditorKit in project erlide_eclipse by erlang.
the class UIStringUtils method extractTextFromHTML.
/**
* Given some html, extracts its text.
*/
public static String extractTextFromHTML(final String html) {
try {
final EditorKit kit = new HTMLEditorKit();
final Document doc = kit.createDefaultDocument();
// The Document class does not yet handle charset's properly.
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
// Create a reader on the HTML content.
final Reader rd = new StringReader(html);
// Parse the HTML.
kit.read(rd, doc, 0);
// The HTML text is now stored in the document
return doc.getText(0, doc.getLength());
} catch (final Exception e) {
}
return "";
}
use of javax.swing.text.html.HTMLEditorKit in project keystore-explorer by kaikramer.
the class DTipOfTheDay method initComponents.
private void initComponents(boolean showTipsOnStartup) {
jpTipOfTheDay = new JPanel(new BorderLayout());
jpTipOfTheDay.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 5, 10), new LineBorder(Color.LIGHT_GRAY, 1)));
jpTipMargin = new JPanel(new FlowLayout());
jpTipMargin.setBackground(Color.LIGHT_GRAY);
jlTipMarginBulb = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("images/tip.png"))));
jpTipMargin.add(jlTipMarginBulb);
jpTipBody = new JPanel(new BorderLayout());
jpTipOfTheDay.add(jpTipMargin, BorderLayout.WEST);
jpTipOfTheDay.add(jpTipBody, BorderLayout.CENTER);
jpTipHeader = new JPanel(new FlowLayout(FlowLayout.LEFT));
jpTipHeader.setBackground(Color.WHITE);
jpTipHeader.setBorder(new MatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY));
jlTipHeader = new JLabel(res.getString("DTipOfTheDay.jlTipHeader.text"));
jlTipHeader.setFont(jlTipHeader.getFont().deriveFont(Font.BOLD, 18f));
jlTipHeader.setBorder(new EmptyBorder(5, 5, 5, 5));
jpTipHeader.add(jlTipHeader);
jepTip = new JEditorPane();
// workaround for rare NPE, see https://community.oracle.com/thread/1478325?start=0&tstart=0
jepTip.setEditorKit(new HTMLEditorKit());
jepTip.setContentType("text/html");
jepTip.setText(getCurrentTip());
jepTip.setEditable(false);
jepTip.setBackground(Color.WHITE);
jepTip.setCaretPosition(0);
jepTip.setBorder(new EmptyBorder(10, 10, 10, 10));
jspTip = PlatformUtil.createScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jspTip.setPreferredSize(new Dimension(300, 150));
jspTip.setBorder(new EmptyBorder(0, 0, 0, 0));
jspTip.getViewport().add(jepTip);
jpTipBody.add(jpTipHeader, BorderLayout.NORTH);
jpTipBody.add(jspTip, BorderLayout.CENTER);
jpShowTipsOnStartup = new JPanel(new FlowLayout());
jpShowTipsOnStartup.setBorder(new EmptyBorder(5, 5, 5, 5));
jcbShowTipsOnStartup = new JCheckBox(res.getString("DTipOfTheDay.jcbShowTipsOnStartup.text"), showTipsOnStartup);
PlatformUtil.setMnemonic(jcbShowTipsOnStartup, res.getString("DTipOfTheDay.jcbShowTipsOnStartup.mnemonic").charAt(0));
jpShowTipsOnStartup.add(jcbShowTipsOnStartup);
jpNavigation = new JPanel(new FlowLayout());
jpNavigation.setBorder(new EmptyBorder(5, 10, 10, 10));
jbPreviousTip = new JButton(res.getString("DTipOfTheDay.jbPreviousTip.text"));
PlatformUtil.setMnemonic(jbPreviousTip, res.getString("DTipOfTheDay.jbPreviousTip.mnemonic").charAt(0));
jbPreviousTip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
CursorUtil.setCursorBusy(DTipOfTheDay.this);
jepTip.setText(getPreviousTip());
jepTip.setCaretPosition(0);
} finally {
CursorUtil.setCursorFree(DTipOfTheDay.this);
}
}
});
jbNextTip = new JButton(res.getString("DTipOfTheDay.jbNextTip.text"));
PlatformUtil.setMnemonic(jbNextTip, res.getString("DTipOfTheDay.jbNextTip.mnemonic").charAt(0));
jbNextTip.setDefaultCapable(true);
jbNextTip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
CursorUtil.setCursorBusy(DTipOfTheDay.this);
jepTip.setText(getNextTip());
jepTip.setCaretPosition(0);
} finally {
CursorUtil.setCursorFree(DTipOfTheDay.this);
}
}
});
jbClose = new JButton(res.getString("DTipOfTheDay.jbClose.text"));
PlatformUtil.setMnemonic(jbClose, res.getString("DTipOfTheDay.jbClose.mnemonic").charAt(0));
jbClose.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closePressed();
}
});
jbClose.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CLOSE_KEY);
jbClose.getActionMap().put(CLOSE_KEY, new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent evt) {
closePressed();
}
});
jpNavigation = PlatformUtil.createDialogButtonPanel(jbClose, null, new JButton[] { jbPreviousTip, jbNextTip }, false);
jpNavigation.setBorder(new EmptyBorder(5, 5, 5, 5));
jpControls = new JPanel(new BorderLayout());
jpControls.add(jpShowTipsOnStartup, BorderLayout.WEST);
jpControls.add(jpNavigation, BorderLayout.EAST);
setLayout(new BorderLayout());
add(jpTipOfTheDay, BorderLayout.CENTER);
add(jpControls, BorderLayout.SOUTH);
getRootPane().setDefaultButton(jbClose);
setTitle(res.getString("DTipOfTheDay.Title"));
setResizable(false);
pack();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jbClose.requestFocus();
}
});
}
Aggregations