Example usage for javax.swing.text SimpleAttributeSet SimpleAttributeSet

List of usage examples for javax.swing.text SimpleAttributeSet SimpleAttributeSet

Introduction

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

Prototype

public SimpleAttributeSet() 

Source Link

Document

Creates a new attribute set.

Usage

From source file:MainClass.java

public void actionPerformed(ActionEvent e) {
    JTextPane editor = (JTextPane) getEditor(e);
    int p0 = editor.getSelectionStart();
    StyledDocument doc = getStyledDocument(editor);
    Element paragraph = doc.getCharacterElement(p0);
    AttributeSet as = paragraph.getAttributes();

    family = StyleConstants.getFontFamily(as);
    fontSize = StyleConstants.getFontSize(as);

    formatText = new JDialog(new JFrame(), "Font and Size", true);
    formatText.getContentPane().setLayout(new BorderLayout());

    JPanel choosers = new JPanel();
    choosers.setLayout(new GridLayout(2, 1));

    JPanel fontFamilyPanel = new JPanel();
    fontFamilyPanel.add(new JLabel("Font"));

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();

    fontFamilyChooser = new JComboBox();
    for (int i = 0; i < fontNames.length; i++) {
        fontFamilyChooser.addItem(fontNames[i]);
    }/*  w ww  . j ava 2 s .  c o m*/
    fontFamilyChooser.setSelectedItem(family);
    fontFamilyPanel.add(fontFamilyChooser);
    choosers.add(fontFamilyPanel);

    JPanel fontSizePanel = new JPanel();
    fontSizePanel.add(new JLabel("Size"));
    fontSizeChooser = new JComboBox();
    fontSizeChooser.setEditable(true);
    fontSizeChooser.addItem(new Float(4));
    fontSizeChooser.addItem(new Float(8));
    fontSizeChooser.addItem(new Float(12));
    fontSizeChooser.addItem(new Float(16));
    fontSizeChooser.addItem(new Float(20));
    fontSizeChooser.addItem(new Float(24));
    fontSizeChooser.setSelectedItem(new Float(fontSize));
    fontSizePanel.add(fontSizeChooser);
    choosers.add(fontSizePanel);

    JButton ok = new JButton("OK");
    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            accept = true;
            formatText.dispose();
            family = (String) fontFamilyChooser.getSelectedItem();
            fontSize = Float.parseFloat(fontSizeChooser.getSelectedItem().toString());
        }
    });

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

    JPanel buttons = new JPanel();
    buttons.add(ok);
    buttons.add(cancel);
    formatText.getContentPane().add(choosers, BorderLayout.CENTER);
    formatText.getContentPane().add(buttons, BorderLayout.SOUTH);
    formatText.pack();
    formatText.setVisible(true);

    MutableAttributeSet attr = null;
    if (editor != null && accept) {
        attr = new SimpleAttributeSet();
        StyleConstants.setFontFamily(attr, family);
        StyleConstants.setFontSize(attr, (int) fontSize);
        setCharacterAttributes(editor, attr, false);
    }

}

From source file:multiplayer.pong.client.LobbyFrame.java

private void displayHelp(String message) {
    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setBold(set, true);
    StyleConstants.setForeground(set, new Color(48, 140, 38));
    if (message == null)
        appendMessage("Instructions:\n" + "/aide : Affiche ce menu\n"
                + "/ajouter [nom] : Envoie une demande d'ajout  un joueur\n"
                + "/accepterAmi [nom] : Accepte une demande d'ajout reue\n"
                + "/m [nom] [message] : envoie un message priv  un ami connect\n"
                + "/challenge [nom] : Invite un ami  une partie de Pong\n"
                + "/supprimer [nom] : Supprime le joueur de votre liste d'amis\n", set);
    else//from   www.  ja v  a2  s. c  om
        appendMessage(message, set);
}

From source file:multiplayer.pong.client.LobbyFrame.java

private void displayError(String error) {
    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setBold(set, true);
    StyleConstants.setForeground(set, new Color(245, 10, 10));
    appendMessage(error, set);//from   w w w  . j  a v  a 2s  .  co m
}

From source file:multiplayer.pong.client.LobbyFrame.java

private void displayWarning(String message) {
    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setBold(set, true);
    StyleConstants.setForeground(set, new Color(255, 178, 46));
    appendMessage(message, set);/*  w w  w  . ja va2s  .  c o m*/
}

From source file:com.hexidec.ekit.component.HTMLUtilities.java

public SimpleAttributeSet removeAttributeByKey(SimpleAttributeSet sourceAS, String removeKey) {
    SimpleAttributeSet temp = new SimpleAttributeSet();
    temp.addAttribute(removeKey, "NULL");
    return removeAttribute(sourceAS, temp);
}

From source file:multiplayer.pong.client.LobbyFrame.java

private void displayNotification(String message) {
    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setBold(set, true);
    StyleConstants.setForeground(set, new Color(81, 20, 237));
    appendMessage(message, set);/*from w  w  w  .j av  a 2s  .c o m*/
}

From source file:TextComponentDemo.java

protected SimpleAttributeSet[] initAttributes(int length) {
    // Hard-code some attributes.
    SimpleAttributeSet[] attrs = new SimpleAttributeSet[length];

    attrs[0] = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attrs[0], "SansSerif");
    StyleConstants.setFontSize(attrs[0], 16);

    attrs[1] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setBold(attrs[1], true);

    attrs[2] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setItalic(attrs[2], true);

    attrs[3] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[3], 20);

    attrs[4] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[4], 12);

    attrs[5] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setForeground(attrs[5], Color.red);

    return attrs;
}

From source file:com.xilinx.kintex7.MainScreen.java

public void initialize(LandingPage l, String imgName, int mode) {
    lp = l;/*from  ww w.java2  s .c  om*/
    blockDiagram = Toolkit.getDefaultToolkit()
            .getImage(getClass().getResource("/com/xilinx/kintex7/" + imgName));
    led1 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/green.png"));
    led2 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/ledoff.png"));
    led3 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/red.png"));
    this.mode = mode;
    setModeText(mode);
    dataMismatch0 = dataMismatch2 = errcnt0 = errcnt1 = false;
    di = null;
    di = new DriverInfo();
    di.init(mode);
    int ret = di.get_PCIstate();

    //ret = di.get_PowerStats();
    test1_option = DriverInfo.ENABLE_LOOPBACK;
    test2_option = DriverInfo.ENABLE_LOOPBACK;
    // create a new jframe, and pack it
    frame = new JFrame("Kintex-7 Connectivity TRD Control & Monitoring Interface");
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    final int m = mode;
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            // check if tests are running or not
            if ((testStarted || testStarted1)
                    && ((m != LandingPage.APPLICATION_MODE) || (m != LandingPage.APPLICATION_MODE_P2P))) {
                int confirmed = JOptionPane.showConfirmDialog(null,
                        "This will stop the tests and uninstall the drivers. Do you want to continue?", "Exit",
                        JOptionPane.YES_NO_OPTION);
                if (confirmed == JOptionPane.YES_OPTION) {
                    if (testStarted) {
                        di.stopTest(0, test1_option, Integer.parseInt(t1_psize.getText()));
                        testStarted = false;
                    }
                    if (testStarted1) {
                        di.stopTest(1, test2_option, Integer.parseInt(t2_psize.getText()));
                        testStarted1 = false;
                    }

                    timer.cancel();
                    textArea.removeAll();
                    di.flush();
                    di = null;
                    System.gc();
                    lp.uninstallDrivers();
                    showDialog("Removing Device Drivers...Please wait...");
                }
            } else {
                int confirmed = JOptionPane.showConfirmDialog(null,
                        "This will Uninstall the drivers. Do you want to continue?", "Exit",
                        JOptionPane.YES_NO_OPTION);
                if (confirmed == JOptionPane.YES_OPTION) {
                    timer.cancel();
                    textArea.removeAll();
                    di.flush();
                    di = null;
                    System.gc();
                    lp.uninstallDrivers();
                    showDialog("Removing Device Drivers...Please wait...");
                }
            }
        }
    });

    // make the frame half the height and width
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    height = screenSize.height;
    width = screenSize.width;

    minWidth = 1000;
    minHeight = 700;
    minFrameWidth = 1024;
    minFrameHeight = 745;

    reqHeight = 745;
    if (width < 1280)
        reqWidth = 1024;
    else if (width == 1280)
        reqWidth = 1280;
    else if (width < 1600) {
        reqWidth = width - (width * 4) / 100;
        reqHeight = height - (height * 3) / 100;
    } else {
        reqWidth = reqHeight = height = height - (height * 10) / 100;
    }

    frame.setSize(new Dimension(minFrameWidth, minFrameHeight));
    frame.setResizable(true);
    frame.addComponentListener(new ComponentListener() {

        @Override
        public void componentResized(ComponentEvent ce) {
            frame.setSize(new Dimension(Math.max(minFrameWidth, frame.getWidth()),
                    Math.max(minFrameHeight, frame.getHeight())));
        }

        @Override
        public void componentMoved(ComponentEvent ce) {
            //throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void componentShown(ComponentEvent ce) {
            //throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void componentHidden(ComponentEvent ce) {
            //throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    frame.setVisible(true);

    frame.setIconImage(
            Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/kintex7/icon.png")));
    // center the jframe on screen
    frame.setLocationRelativeTo(null);

    frame.setContentPane(createContentPane());

    keyWord = new SimpleAttributeSet();
    StyleConstants.setForeground(keyWord, Color.RED);

    StyleConstants.setBold(keyWord, true);

    logStatus = new SimpleAttributeSet();
    StyleConstants.setForeground(logStatus, Color.BLACK);
    StyleConstants.setBold(logStatus, true);

    if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) {
        testStarted = testStarted1 = true;
    }

    if (mode == LandingPage.PERFORMANCE_MODE_RAW) {
        t1_o1.setSelected(true);
        t1_o2.setEnabled(false);
        t1_o3.setEnabled(false);
        t2_o2.setEnabled(false);
        t2_o3.setEnabled(false);
    }
    if (mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
        t1_o2.setEnabled(false);
        t1_o3.setEnabled(false);
        t2_o2.setEnabled(false);
        t2_o3.setEnabled(false);
        t1_o1.setSelected(true);
    }

    // initialize max packet size
    ret = di.get_EngineState();
    EngState[] engData = di.getEngState();
    maxpkt0 = engData[0].MaxPktSize;
    minpkt0 = engData[0].MinPktSize;

    minpkt1 = engData[2].MinPktSize;
    maxpkt1 = engData[2].MaxPktSize;

    t1_psize.setText(String.valueOf(maxpkt0));
    t2_psize.setText(String.valueOf(maxpkt1));

    t1_psize.setToolTipText(minpkt0 + "-" + maxpkt0);
    t2_psize.setToolTipText(minpkt1 + "-" + maxpkt1);

    updateLog(di.getPCIInfo().getVersionInfo(), logStatus);
    updateLog("Configuration: " + modeText, logStatus);

    // LED status
    di.get_LedStats();
    lstats = di.getLedStats();
    setLedStats(lstats);

    startTimer();
}

From source file:TextComponentDemo.java

protected SimpleAttributeSet[] initAttributes(int length) {
    //Hard-code some attributes.
    SimpleAttributeSet[] attrs = new SimpleAttributeSet[length];

    attrs[0] = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attrs[0], "SansSerif");
    StyleConstants.setFontSize(attrs[0], 16);

    attrs[1] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setBold(attrs[1], true);

    attrs[2] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setItalic(attrs[2], true);

    attrs[3] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[3], 20);

    attrs[4] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setFontSize(attrs[4], 12);

    attrs[5] = new SimpleAttributeSet(attrs[0]);
    StyleConstants.setForeground(attrs[5], Color.red);

    return attrs;
}

From source file:com.hexidec.ekit.component.HTMLUtilities.java

public SimpleAttributeSet removeAttribute(SimpleAttributeSet sourceAS, SimpleAttributeSet removeAS) {
    try {/*from w  w  w  .j  a  v  a2s .  co m*/
        String[] sourceKeys = new String[sourceAS.getAttributeCount()];
        String[] sourceValues = new String[sourceAS.getAttributeCount()];
        Enumeration sourceEn = sourceAS.getAttributeNames();
        int i = 0;
        while (sourceEn.hasMoreElements()) {
            Object temp = new Object();
            temp = sourceEn.nextElement();
            sourceKeys[i] = (String) temp.toString();
            sourceValues[i] = new String();
            sourceValues[i] = (String) sourceAS.getAttribute(temp).toString();
            i++;
        }
        String[] removeKeys = new String[removeAS.getAttributeCount()];
        String[] removeValues = new String[removeAS.getAttributeCount()];
        Enumeration removeEn = removeAS.getAttributeNames();
        int j = 0;
        while (removeEn.hasMoreElements()) {
            removeKeys[j] = (String) removeEn.nextElement().toString();
            removeValues[j] = (String) removeAS.getAttribute(removeKeys[j]).toString();
            j++;
        }
        SimpleAttributeSet result = new SimpleAttributeSet();
        boolean hit = false;
        for (int countSource = 0; countSource < sourceKeys.length; countSource++) {
            hit = false;
            if (sourceKeys[countSource] == "name" | sourceKeys[countSource] == "resolver") {
                hit = true;
            } else {
                for (int countRemove = 0; countRemove < removeKeys.length; countRemove++) {
                    if (removeKeys[countRemove] != "NULL") {
                        if (sourceKeys[countSource].toString() == removeKeys[countRemove].toString()) {
                            if (removeValues[countRemove] != "NULL") {
                                if (sourceValues[countSource].toString() == removeValues[countRemove]
                                        .toString()) {
                                    hit = true;
                                }
                            } else if (removeValues[countRemove] == "NULL") {
                                hit = true;
                            }
                        }
                    } else if (removeKeys[countRemove] == "NULL") {
                        if (sourceValues[countSource].toString() == removeValues[countRemove].toString()) {
                            hit = true;
                        }
                    }
                }
            }
            if (!hit) {
                result.addAttribute(sourceKeys[countSource].toString(), sourceValues[countSource].toString());
            }
        }
        return result;
    } catch (ClassCastException cce) {
        return null;
    }
}