void finishInit() { // Create 3 styles associated with the text panes Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(def, "SansSerif"); Style regular0 = jTextPane.addStyle("regular", def); Style regular1 = commentPane.addStyle("regular", def); Style s0 = jTextPane.addStyle("old", regular0); Style s1 = commentPane.addStyle("old", regular1); StyleConstants.setBackground(s0, Color.yellow); StyleConstants.setBackground(s1, Color.yellow); s0 = jTextPane.addStyle("new", regular0); StyleConstants.setBackground(s0, Color.pink); s1 = commentPane.addStyle("new", regular1); StyleConstants.setBackground(s1, Color.pink); }
public void initializeTextPane(JTextPane text_pane) { text_pane.removeStyle("normal"); Style normal = text_pane.addStyle("normal", base_style); text_pane.removeStyle("alternate"); Style alternate = text_pane.addStyle("alternate", normal); int[] rgb = new int[3]; try { String rgb_str = settings_manager.getString("/gui/text windows/alternate background colour", ""); if (rgb_str != "") { rgb = Util.getRGB(rgb_str); StyleConstants.setBackground(alternate, new Color(rgb[0], rgb[1], rgb[2])); } } catch (NumberFormatException e) { } String format; for (int i = 0; i < style_names.length; i++) { format = style_names[i]; int len = format.length(); boolean valid_format = true; // Duplicate the base style, and adjust the new copy to create the new style. text_pane.removeStyle(format); Style style = text_pane.addStyle(format, normal); for (int c = 0; c < len; ) { if (c > len - 2) { valid_format = false; break; } else { String arg; String code = format.substring(c, c + 2); c += 2; if (code.equals(STYLE_FOREGROUND)) { if (c > len - 6) { valid_format = false; break; } arg = format.substring(c, c + 6); c += 6; rgb[0] = 0xff; rgb[1] = 0xff; rgb[2] = 0xff; try { rgb = Util.getRGB(arg); } catch (NumberFormatException e) { valid_format = false; break; } StyleConstants.setForeground(style, new Color(rgb[0], rgb[1], rgb[2])); } else if (code.equals(STYLE_BACKGROUND)) { if (c > len - 6) { valid_format = false; break; } arg = format.substring(c, c + 6); c += 6; rgb[0] = 0; rgb[1] = 0; rgb[2] = 0; try { rgb = Util.getRGB(arg); } catch (NumberFormatException e) { valid_format = false; break; } StyleConstants.setBackground(style, new Color(rgb[0], rgb[1], rgb[2])); } else if (code.equals(STYLE_BOLD)) { StyleConstants.setBold(style, true); } else if (code.equals(STYLE_ITALIC)) { StyleConstants.setItalic(style, true); } else if (code.equals(STYLE_UNDERLINE)) { StyleConstants.setUnderline(style, true); } } } if (!valid_format) { System.err.println(i18n_manager.getString("bad format", new Object[] {style_names[i]})); } } }
private void jbInit() throws Exception { saveButton.setText("Save"); saveButton.addActionListener(new PrintfTemplateEditor_saveButton_actionAdapter(this)); cancelButton.setText("Cancel"); cancelButton.addActionListener(new PrintfTemplateEditor_cancelButton_actionAdapter(this)); this.setTitle(this.getTitle() + " Template Editor"); printfPanel.setLayout(gridBagLayout1); formatLabel.setFont(new java.awt.Font("DialogInput", 0, 12)); formatLabel.setText("Format String:"); buttonPanel.setLayout(flowLayout1); printfPanel.setBorder(BorderFactory.createEtchedBorder()); printfPanel.setMinimumSize(new Dimension(100, 160)); printfPanel.setPreferredSize(new Dimension(380, 160)); parameterPanel.setLayout(gridBagLayout2); parameterLabel.setText("Parameters:"); parameterLabel.setFont(new java.awt.Font("DialogInput", 0, 12)); parameterTextArea.setMinimumSize(new Dimension(100, 25)); parameterTextArea.setPreferredSize(new Dimension(200, 25)); parameterTextArea.setEditable(true); parameterTextArea.setText(""); insertButton.setMaximumSize(new Dimension(136, 20)); insertButton.setMinimumSize(new Dimension(136, 20)); insertButton.setPreferredSize(new Dimension(136, 20)); insertButton.setToolTipText( "insert the format in the format string and add parameter to list."); insertButton.setText("Insert Parameter"); insertButton.addActionListener(new PrintfTemplateEditor_insertButton_actionAdapter(this)); formatTextArea.setMinimumSize(new Dimension(100, 25)); formatTextArea.setPreferredSize(new Dimension(200, 15)); formatTextArea.setText(""); parameterPanel.setBorder(null); parameterPanel.setMinimumSize(new Dimension(60, 40)); parameterPanel.setPreferredSize(new Dimension(300, 40)); insertMatchButton.addActionListener( new PrintfTemplateEditor_insertMatchButton_actionAdapter(this)); insertMatchButton.setText("Insert Match"); insertMatchButton.setToolTipText( "insert the match in the format string and add parameter to list."); insertMatchButton.setPreferredSize(new Dimension(136, 20)); insertMatchButton.setMinimumSize(new Dimension(136, 20)); insertMatchButton.setMaximumSize(new Dimension(136, 20)); matchPanel.setPreferredSize(new Dimension(300, 40)); matchPanel.setBorder(null); matchPanel.setMinimumSize(new Dimension(60, 60)); matchPanel.setLayout(gridBagLayout3); InsertPanel.setLayout(gridLayout1); gridLayout1.setColumns(1); gridLayout1.setRows(2); gridLayout1.setVgap(0); InsertPanel.setBorder(BorderFactory.createEtchedBorder()); InsertPanel.setMinimumSize(new Dimension(100, 100)); InsertPanel.setPreferredSize(new Dimension(380, 120)); editorPane.setText(""); editorPane.addKeyListener(new PrintfEditor_editorPane_keyAdapter(this)); printfTabPane.addChangeListener(new PrintfEditor_printfTabPane_changeAdapter(this)); parameterPanel.add( insertButton, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 6, 13, 8), 0, 10)); parameterPanel.add( paramComboBox, new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(8, 8, 13, 0), 258, 11)); paramComboBox.setRenderer(new MyCellRenderer()); InsertPanel.add(matchPanel, null); InsertPanel.add(parameterPanel, null); buttonPanel.add(cancelButton, null); buttonPanel.add(saveButton, null); this.getContentPane().add(printfTabPane, BorderLayout.NORTH); this.getContentPane().add(InsertPanel, BorderLayout.CENTER); matchPanel.add( insertMatchButton, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 6, 13, 8), 0, 10)); matchPanel.add( matchComboBox, new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(8, 8, 13, 0), 258, 11)); printfPanel.add( parameterLabel, new GridBagConstraints( 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 309, 0)); printfPanel.add( formatLabel, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 5, 0, 5), 288, 0)); printfPanel.add( formatTextArea, new GridBagConstraints( 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 5, 0, 5), 300, 34)); printfPanel.add( parameterTextArea, new GridBagConstraints( 0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 5, 6, 5), 300, 34)); printfTabPane.addTab("Editor View", null, editorPanel, "View in Editor"); printfTabPane.addTab("Printf View", null, printfPanel, "Vies as Printf"); editorPane.setCharacterAttributes(PLAIN_ATTR, true); editorPane.addStyle("PLAIN", editorPane.getLogicalStyle()); editorPanel.getViewport().add(editorPane, null); this.getContentPane().add(buttonPanel, BorderLayout.SOUTH); buttonGroup.add(cancelButton); }