Java Code Examples for javax.swing.JEditorPane#setContentType()
The following examples show how to use
javax.swing.JEditorPane#setContentType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectivePanel.java From triplea with GNU General Public License v3.0 | 6 votes |
EditorPaneCellEditor() { super(new JTextField()); final JEditorPane textArea = new JEditorPane(); textArea.setEditable(false); textArea.setContentType("text/html"); final JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setBorder(null); editorComponent = scrollPane; delegate = new DefaultCellEditor.EditorDelegate() { private static final long serialVersionUID = 5746645959173385516L; @Override public void setValue(final Object value) { textArea.setText((value != null) ? value.toString() : ""); } @Override public Object getCellEditorValue() { return textArea.getText(); } }; }
Example 2
Source File: HTMLDialogBox.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
/** * Turns HTML into a clickable dialog text component. * @param html String of valid HTML. * @return a JTextComponent with the HTML inside. */ public JTextComponent createHyperlinkListenableJEditorPane(String html) { final JEditorPane bottomText = new JEditorPane(); bottomText.setContentType("text/html"); bottomText.setEditable(false); bottomText.setText(html); bottomText.setOpaque(false); final HyperlinkListener hyperlinkListener = new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) { if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(hyperlinkEvent.getURL().toURI()); } catch (IOException | URISyntaxException exception) { // Auto-generated catch block exception.printStackTrace(); } } } } }; bottomText.addHyperlinkListener(hyperlinkListener); return bottomText; }
Example 3
Source File: UnitSelectorDialog.java From megamek with GNU General Public License v2.0 | 5 votes |
public void actionPerformed(ActionEvent ev) { if (ev.getSource().equals(comboWeight) || ev.getSource().equals(comboUnitType)) { filterUnits(); } else if (ev.getSource().equals(btnSelect)) { select(false); } else if (ev.getSource().equals(btnSelectClose)) { select(true); } else if (ev.getSource().equals(btnClose)) { close(); } else if (ev.getSource().equals(btnShowBV)) { JEditorPane tEditorPane = new JEditorPane(); tEditorPane.setContentType("text/html"); tEditorPane.setEditable(false); Entity e = getSelectedEntity(); if (null == e) { return; } e.calculateBattleValue(); tEditorPane.setText(e.getBVText()); tEditorPane.setCaretPosition(0); JScrollPane tScroll = new JScrollPane(tEditorPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension size = new Dimension(550, 300); tScroll.setPreferredSize(size); JOptionPane.showMessageDialog(null, tScroll, "BV", JOptionPane.INFORMATION_MESSAGE, null); } else if(ev.getSource().equals(btnAdvSearch)) { searchFilter = asd.showDialog(); btnResetSearch.setEnabled((searchFilter != null) && !searchFilter.isDisabled); filterUnits(); } else if(ev.getSource().equals(btnResetSearch)) { asd.clearValues(); searchFilter=null; btnResetSearch.setEnabled(false); filterUnits(); } }
Example 4
Source File: MarkdownTextPane.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Initializes the widgets. */ @Override protected void initGUI() { super.initGUI(); setLayout(new BorderLayout()); m_PaneView = new JEditorPane(); m_PaneView.setEditable(false); m_PaneView.setContentType("text/html"); add(new BaseScrollPane(m_PaneView), BorderLayout.CENTER); }
Example 5
Source File: HTMLReader.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent e) { JDialog dlg = new JDialog(((Main) PacketSamurai.getUserInterface()).getMainFrame(),"HTML"); dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dlg.setSize(350, 400); dlg.setLocationRelativeTo(((Main) PacketSamurai.getUserInterface()).getMainFrame()); JTabbedPane tabPane = new JTabbedPane(); // HTML JEditorPane htmlDisplay = new JEditorPane(); htmlDisplay.setEditable(false); htmlDisplay.setContentType("text/html"); htmlDisplay.setText(_html); // Source JEditorPane sourceDisplay = new JEditorPane(); sourceDisplay.setEditable(false); sourceDisplay.setContentType("text/plain"); sourceDisplay.setText(_html); tabPane.add(new JScrollPane(htmlDisplay), "HTML"); tabPane.add(new JScrollPane(sourceDisplay), "Source"); dlg.add(tabPane); dlg.setVisible(true); }
Example 6
Source File: PropertiesCustomEditor.java From netbeans with Apache License 2.0 | 5 votes |
/** This method is called from within the constructor to * initialize the form. */ private void initComponents() { setLayout(new BorderLayout()); editorPane = new JEditorPane(); editorPane.setContentType("text/x-properties"); // NOI18N // XXX pretty arbitrary! No way to set by rows & columns?? editorPane.setPreferredSize(new Dimension(200, 100)); add(new JScrollPane(editorPane), BorderLayout.CENTER); warnings = new JTextField(30); warnings.setEditable(false); add(warnings, BorderLayout.SOUTH); }
Example 7
Source File: DetailPanel.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a new <code>DetailPanel</code> instance. * * @param aTable the table to listen for selections on * @param aModel the model backing the table */ DetailPanel(JTable aTable, final MyTableModel aModel) { mModel = aModel; setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder("Details: ")); mDetails = new JEditorPane(); mDetails.setEditable(false); mDetails.setContentType("text/html"); add(new JScrollPane(mDetails), BorderLayout.CENTER); final ListSelectionModel rowSM = aTable.getSelectionModel(); rowSM.addListSelectionListener(this); }
Example 8
Source File: mxCellEditor.java From blog-codes with Apache License 2.0 | 5 votes |
/** * */ public mxCellEditor(mxGraphComponent graphComponent) { this.graphComponent = graphComponent; // Creates the plain text editor textArea = new JTextArea(); textArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); textArea.setOpaque(false); // Creates the HTML editor editorPane = new JEditorPane(); editorPane.setOpaque(false); editorPane.setBackground(new Color(0,0,0,0)); editorPane.setContentType("text/html"); // Workaround for inserted linefeeds in HTML markup with // lines that are longar than 80 chars editorPane.setEditorKit(new NoLinefeedHtmlEditorKit()); // Creates the scollpane that contains the editor // FIXME: Cursor not visible when scrolling scrollPane = new JScrollPane(); scrollPane.setBorder(BorderFactory.createEmptyBorder()); scrollPane.getViewport().setOpaque(false); scrollPane.setVisible(false); scrollPane.setOpaque(false); // Installs custom actions editorPane.getActionMap().put(CANCEL_EDITING, cancelEditingAction); textArea.getActionMap().put(CANCEL_EDITING, cancelEditingAction); editorPane.getActionMap().put(SUBMIT_TEXT, textSubmitAction); textArea.getActionMap().put(SUBMIT_TEXT, textSubmitAction); // Remembers the action map key for the enter keystroke editorEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke); textEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke); }
Example 9
Source File: HighlightingManagerTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testCaching() { MemoryMimeDataProvider.reset(null); JEditorPane pane1 = new JEditorPane(); HighlightingManager hm1 = HighlightingManager.getInstance(pane1); pane1.setContentType("text/plain"); assertEquals("The pane has got wrong mime type", "text/plain", pane1.getContentType()); JEditorPane pane2 = new JEditorPane(); HighlightingManager hm2 = HighlightingManager.getInstance(pane2); pane2.setContentType("text/plain"); assertEquals("The pane has got wrong mime type", "text/plain", pane2.getContentType()); { HighlightsContainer hc1_A = hm1.getHighlights(HighlightsLayerFilter.IDENTITY); HighlightsContainer hc1_B = hm1.getHighlights(HighlightsLayerFilter.IDENTITY); // Current impl of hm.getHighlights() does not cache HC instances so the following test would fail // assertSame("HighlightsContainer is not cached", hc1_A, hc1_B); HighlightsContainer hc2 = hm2.getHighlights(HighlightsLayerFilter.IDENTITY); assertNotSame("HighlightsContainer should not be shared between JEPs", hc1_A, hc2); } gc(); { int hc1_A_hash = System.identityHashCode(hm1.getHighlights(HighlightsLayerFilter.IDENTITY)); int hc1_B_hash = System.identityHashCode(hm1.getHighlights(HighlightsLayerFilter.IDENTITY)); // Current impl of hm.getHighlights() does not cache HC instances so the following test would fail // assertEquals("HighlightsContainer is not cached (different hash codes)", hc1_A_hash, hc1_B_hash); } }
Example 10
Source File: OQLSyntaxEditor.java From visualvm with GNU General Public License v2.0 | 5 votes |
@Override public JEditorPane getEditorPane() { JEditorPane pane = new JEditorPane(); pane.setContentType("text/x-oql"); pane.getDocument().addDocumentListener(new DocumentListenerEx()); return pane; }
Example 11
Source File: YogaCombinationsView.java From Astrosoft with GNU General Public License v2.0 | 4 votes |
private Component createYogaDetailPane(){ //JPanel yogaDetail= new JPanel(); editorPane = new JEditorPane(); editorPane.setContentType("text/html"); editorPane.setEditable(false); yogaChanged((YogaResults.Result)yogaList.getSelectedValue()); editorPane.setBorder(BorderFactory.createEtchedBorder()); return editorPane; }
Example 12
Source File: XArrayDataViewer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection<?>) value).toArray(); } else if (value instanceof Map) { arr = ((Map<?,?>) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + oddRowColor.getGreen() + "," + oddRowColor.getBlue() + ")"; Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } else { sb.append("<tr style=\"background-color: " + oddRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td></td></tr>"); } sb.append("</table></body></html>"); arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }
Example 13
Source File: XArrayDataViewer.java From visualvm with GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection) value).toArray(); } else if (value instanceof Map) { arr = ((Map) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); // NOI18N arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; // NOI18N Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + // NOI18N oddRowColor.getGreen() + "," + // NOI18N oddRowColor.getBlue() + ")"; // NOI18N Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", // NOI18N foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); // NOI18N for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + // NOI18N evenRowColorStr + "\"><td><pre>" + // NOI18N (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); // NOI18N } else { sb.append("<tr style=\"background-color: " + // NOI18N oddRowColorStr + "\"><td><pre>" + // NOI18N (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); // NOI18N } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + // NOI18N evenRowColorStr + "\"><td></td></tr>"); // NOI18N } sb.append("</table></body></html>"); // NOI18N arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }
Example 14
Source File: HighlightingManagerTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testChangesInLayerFireEvents() { OffsetsBag bagA = new OffsetsBag(new PlainDocument()); OffsetsBag bagB = new OffsetsBag(new PlainDocument()); OffsetsBag bagC = new OffsetsBag(new PlainDocument()); OffsetsBag bagD = new OffsetsBag(new PlainDocument()); MemoryMimeDataProvider.reset(null); MemoryMimeDataProvider.addInstances("text/plain", new SingletonLayerFactory("layerB", ZOrder.DEFAULT_RACK.forPosition(2), false, bagB), new SingletonLayerFactory("layerD", ZOrder.DEFAULT_RACK.forPosition(6), true, bagD), new SingletonLayerFactory("layerA", ZOrder.DEFAULT_RACK, true, bagA), new SingletonLayerFactory("layerC", ZOrder.DEFAULT_RACK.forPosition(4), true, bagC) ); JEditorPane pane = new JEditorPane(); pane.putClientProperty("HighlightsLayerExcludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\..*$"); pane.setContentType("text/plain"); assertEquals("The pane has got wrong mime type", "text/plain", pane.getContentType()); HighlightingManager hm = HighlightingManager.getInstance(pane); // Test the variable-size layers - A,B Listener variableL = new Listener(); HighlightsContainer variableHC = hm.getHighlights(VARIABLE_SIZE_LAYERS); assertNotNull("Can't get variable HighlightsContainer", variableHC); assertFalse("There should be no variable highlights", variableHC.getHighlights(0, Integer.MAX_VALUE).moveNext()); variableHC.addHighlightsChangeListener(variableL); bagA.addHighlight(10, 20, SimpleAttributeSet.EMPTY); assertEquals("Wrong number of events", 1, variableL.eventsCnt); assertEquals("Wrong change start offset", 10, variableL.lastStartOffset); assertEquals("Wrong change end offset", 20, variableL.lastEndOffset); variableL.reset(); bagB.addHighlight(5, 15, SimpleAttributeSet.EMPTY); assertEquals("Wrong number of events", 1, variableL.eventsCnt); assertEquals("Wrong change start offset", 5, variableL.lastStartOffset); assertEquals("Wrong change end offset", 15, variableL.lastEndOffset); // Test the fixed-size layers Listener fixedL = new Listener(); HighlightsContainer fixedHC = hm.getHighlights(FIXED_SIZE_LAYERS); assertNotNull("Can't get fixed HighlightsContainer", fixedHC); assertFalse("There should be no fixed highlights", fixedHC.getHighlights(0, Integer.MAX_VALUE).moveNext()); fixedHC.addHighlightsChangeListener(fixedL); bagC.addHighlight(20, 50, SimpleAttributeSet.EMPTY); assertEquals("Wrong number of events", 1, fixedL.eventsCnt); assertEquals("Wrong change start offset", 20, fixedL.lastStartOffset); assertEquals("Wrong change end offset", 50, fixedL.lastEndOffset); fixedL.reset(); bagD.addHighlight(0, 30, SimpleAttributeSet.EMPTY); assertEquals("Wrong number of events", 1, fixedL.eventsCnt); assertEquals("Wrong change start offset", 0, fixedL.lastStartOffset); assertEquals("Wrong change end offset", 30, fixedL.lastEndOffset); }
Example 15
Source File: XArrayDataViewer.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection<?>) value).toArray(); } else if (value instanceof Map) { arr = ((Map<?,?>) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + oddRowColor.getGreen() + "," + oddRowColor.getBlue() + ")"; Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } else { sb.append("<tr style=\"background-color: " + oddRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td></td></tr>"); } sb.append("</table></body></html>"); arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }
Example 16
Source File: ControlWindow.java From ChatGameFontificator with The Unlicense | 4 votes |
private void setupHelp() { final String helpTitle = "Chat Game Fontificator Help"; help = new JDialog(this, true); help.setTitle(helpTitle); help.setSize(640, 480); help.setLayout(new GridBagLayout()); JEditorPane helpPane = new JEditorPane(); helpPane.setContentType("text/html"); helpPane.setText(helpText); helpPane.setEditable(false); JScrollPane scrollHelp = new JScrollPane(helpPane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JButton ok = new JButton("Close"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { help.setVisible(false); } }); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy = 0; gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.NORTH; help.add(new JLabel("The function of each option available in the Control Window tabs is explained below"), gbc); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.gridy = 1; help.add(scrollHelp, gbc); gbc.gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.SOUTH; gbc.weighty = 0.0; help.add(ok, gbc); help.setResizable(false); }
Example 17
Source File: ToolTipSupport.java From netbeans with Apache License 2.0 | 4 votes |
private JEditorPane createHtmlTextToolTip() { class HtmlTextToolTip extends JEditorPane { public @Override void setSize(int width, int height) { Dimension prefSize = getPreferredSize(); if (width >= prefSize.width) { width = prefSize.width; } else { // smaller available width super.setSize(width, 10000); // the height is unimportant prefSize = getPreferredSize(); // re-read new pref width } if (height >= prefSize.height) { // enough height height = prefSize.height; } super.setSize(width, height); } @Override public void setKeymap(Keymap map) { //#181722: keymaps are shared among components with the same UI //a default action will be set to the Keymap of this component below, //so it is necessary to use a Keymap that is not shared with other components super.setKeymap(addKeymap(null, map)); } } JEditorPane tt = new HtmlTextToolTip(); /* See NETBEANS-403. It still appears possible to use Escape to close the popup when the focus is in the editor. */ tt.putClientProperty(SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY, true); // setup tooltip keybindings filterBindings(tt.getActionMap()); tt.getActionMap().put(HIDE_ACTION.getValue(Action.NAME), HIDE_ACTION); tt.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), HIDE_ACTION.getValue(Action.NAME)); tt.getKeymap().setDefaultAction(NO_ACTION); Font font = UIManager.getFont(UI_PREFIX + ".font"); // NOI18N Color backColor = UIManager.getColor(UI_PREFIX + ".background"); // NOI18N Color foreColor = UIManager.getColor(UI_PREFIX + ".foreground"); // NOI18N if (font != null) { tt.setFont(font); } if (foreColor != null) { tt.setForeground(foreColor); } if (backColor != null) { tt.setBackground(backColor); } tt.setOpaque(true); tt.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(tt.getForeground()), BorderFactory.createEmptyBorder(0, 3, 0, 3) )); tt.setContentType("text/html"); //NOI18N return tt; }
Example 18
Source File: XArrayDataViewer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection<?>) value).toArray(); } else if (value instanceof Map) { arr = ((Map<?,?>) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + oddRowColor.getGreen() + "," + oddRowColor.getBlue() + ")"; Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } else { sb.append("<tr style=\"background-color: " + oddRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td></td></tr>"); } sb.append("</table></body></html>"); arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }
Example 19
Source File: XArrayDataViewer.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection<?>) value).toArray(); } else if (value instanceof Map) { arr = ((Map<?,?>) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + oddRowColor.getGreen() + "," + oddRowColor.getBlue() + ")"; Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } else { sb.append("<tr style=\"background-color: " + oddRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td></td></tr>"); } sb.append("</table></body></html>"); arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }
Example 20
Source File: XArrayDataViewer.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection<?>) value).toArray(); } else if (value instanceof Map) { arr = ((Map<?,?>) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + oddRowColor.getGreen() + "," + oddRowColor.getBlue() + ")"; Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } else { sb.append("<tr style=\"background-color: " + oddRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td></td></tr>"); } sb.append("</table></body></html>"); arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }