Example usage for javax.swing.text StyleConstants setForeground

List of usage examples for javax.swing.text StyleConstants setForeground

Introduction

In this page you can find the example usage for javax.swing.text StyleConstants setForeground.

Prototype

public static void setForeground(MutableAttributeSet a, Color fg) 

Source Link

Document

Sets the foreground color.

Usage

From source file:com.croer.javaorange.diviner.SimpleOrangeTextPane.java

public SimpleOrangeTextPane() {
    CONFIGURATION = Configuration.getCONFIGURATION();

    //Create the style array to show the colors 
    List<Object> colorList = CONFIGURATION.getList("ColorWord");
    styles = new Style[colorList.size()];
    StyleContext sc = new StyleContext();
    for (int i = 0; i < colorList.size(); i++) {
        styles[i] = sc.addStyle((String) colorList.get(i), sc.getStyle(StyleContext.DEFAULT_STYLE));
        StyleConstants.setForeground(styles[i], ColorUtils.getColorByName((String) colorList.get(i)));
        StyleConstants.setBold(styles[i], true);
    }// www  .j a  va  2 s  .  c  o  m

    //Deactive key bindings 
    List<Object> navigationList = CONFIGURATION.getList("PageNavigation");
    for (Object object : navigationList) {
        getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(object.toString()), "none");
    }

    //Get the document for adding a document listener
    dsd = (DefaultStyledDocument) getDocument();
    dsd.addDocumentListener(new DocumentListenerTextPane());

    //...and setting a document filter
    documentFilter = new MyDocumentFilter();
    dsd.setDocumentFilter(documentFilter);
}

From source file:de.codesourcery.jasm16.ide.ui.views.CPUView.java

protected final static SimpleAttributeSet createStyle(Color color) {
    SimpleAttributeSet result = new SimpleAttributeSet();
    StyleConstants.setForeground(result, color);
    return result;
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logError(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setBold(aset, true);
    StyleConstants.setForeground(aset, UI.colorAKABENI);
    appendToPane(message, aset);/*from  ww  w.  ja v a2 s  .c o m*/
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logWaring(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setBold(aset, true);
    StyleConstants.setForeground(aset, UI.colorOrange0);
    appendToPane(message, aset);//  ww  w .ja va2 s.  co m
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logInfo(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setForeground(aset, UI.colorMIDORI);
    StyleConstants.setBold(aset, true);
    appendToPane(message, aset);//  w ww .  jav  a  2s .  c om
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logData(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setForeground(aset, UI.colorMIDORI);
    StyleConstants.setBold(aset, true);
    appendToPane(message, aset);//from  w w w.j  av a 2  s . c om
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void log(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setForeground(aset, UI.colorBlack2);
    StyleConstants.setBold(aset, false);
    appendToPane(message, aset);/*from ww  w  .j  a v  a2 s . c  o m*/
}

From source file:com.eviware.soapui.support.log.JLogList.java

public JLogList(String title) {
    super(new BorderLayout());
    this.title = title;

    model = new LogListModel();
    logList = new JList(model);
    logList.setToolTipText(title);// ww  w . ja v  a  2 s.  c om
    logList.setCellRenderer(new LogAreaCellRenderer());
    logList.setPrototypeCellValue("Testing 123");
    logList.setFixedCellWidth(-1);

    JPopupMenu listPopup = new JPopupMenu();
    listPopup.add(new ClearAction());
    enableAction = new EnableAction();
    enableMenuItem = new JCheckBoxMenuItem(enableAction);
    enableMenuItem.setSelected(true);
    listPopup.add(enableMenuItem);
    listPopup.addSeparator();
    listPopup.add(new CopyAction());
    listPopup.add(new SetMaxRowsAction());
    listPopup.addSeparator();
    listPopup.add(new ExportToFileAction());

    logList.setComponentPopupMenu(listPopup);

    setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    JScrollPane scrollPane = new JScrollPane(logList);
    UISupport.addPreviewCorner(scrollPane, true);
    add(scrollPane, BorderLayout.CENTER);

    requestAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(requestAttributes, Color.BLUE);

    responseAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(responseAttributes, Color.GREEN);

    try {
        maxRows = Long.parseLong(SoapUI.getSettings().getString("JLogList#" + title, "1000"));
    } catch (NumberFormatException e) {
    }
}

From source file:com.clank.launcher.swing.MessageLog.java

/**
 * Get an output stream using the give color.
 * /*w  w w  .jav  a2 s .  c o m*/
 * @param color color to use
 * @return output stream
 */
public ConsoleOutputStream getOutputStream(Color color) {
    SimpleAttributeSet attributes = new SimpleAttributeSet();
    StyleConstants.setForeground(attributes, color);
    return getOutputStream(attributes);
}

From source file:MainClass.java

public void actionPerformed(ActionEvent e) {
    JTextPane editor = (JTextPane) getEditor(e);

    if (editor == null) {
        JOptionPane.showMessageDialog(null,
                "You need to select the editor pane before you can change the color.", "Error",
                JOptionPane.ERROR_MESSAGE);
        return;/*from w w  w  . j  a v a2  s .  c om*/
    }
    int p0 = editor.getSelectionStart();
    StyledDocument doc = getStyledDocument(editor);
    Element paragraph = doc.getCharacterElement(p0);
    AttributeSet as = paragraph.getAttributes();
    fg = StyleConstants.getForeground(as);
    if (fg == null) {
        fg = Color.BLACK;
    }
    colorChooser.setColor(fg);

    JButton accept = new JButton("OK");
    accept.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            fg = colorChooser.getColor();
            dialog.dispose();
        }
    });

    JButton cancel = new JButton("Cancel");
    cancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            cancelled = true;
            dialog.dispose();
        }
    });

    JButton none = new JButton("None");
    none.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            noChange = true;
            dialog.dispose();
        }
    });

    JPanel buttons = new JPanel();
    buttons.add(accept);
    buttons.add(none);
    buttons.add(cancel);

    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(colorChooser, BorderLayout.CENTER);
    dialog.getContentPane().add(buttons, BorderLayout.SOUTH);
    dialog.setModal(true);
    dialog.pack();
    dialog.setVisible(true);

    if (!cancelled) {

        MutableAttributeSet attr = null;
        if (editor != null) {
            if (fg != null && !noChange) {
                attr = new SimpleAttributeSet();
                StyleConstants.setForeground(attr, fg);
                setCharacterAttributes(editor, attr, false);
            }
        }
    } // end if color != null
    noChange = false;
    cancelled = false;
}