Example usage for weka.gui.visualize VisualizeUtils processColour

List of usage examples for weka.gui.visualize VisualizeUtils processColour

Introduction

In this page you can find the example usage for weka.gui.visualize VisualizeUtils processColour.

Prototype

public static Color processColour(String colourDef, Color defaultColour) 

Source Link

Document

Parses a string containing either a named colour or r,g,b values.

Usage

From source file:org.pentaho.dm.kf.GroovyComponentCustomizer.java

License:Open Source License

public GroovyComponentCustomizer() {
    Properties props;/*from  w  w  w  .j  av  a  2 s.co  m*/

    try {
        props = Utils.readProperties(PROPERTIES_FILE);
    } catch (Exception ex) {
        ex.printStackTrace();
        props = new Properties();
    }

    // check for SyntaxDocument
    boolean syntaxDocAvailable = true;
    try {
        Class.forName("weka.gui.scripting.SyntaxDocument");
    } catch (Exception ex) {
        syntaxDocAvailable = false;
    }

    if (props.getProperty("Syntax", "false").equals("true") && syntaxDocAvailable) {
        try {
            Class syntaxClass = Class.forName("weka.gui.scripting.SyntaxDocument");
            Constructor constructor = syntaxClass.getConstructor(Properties.class);
            Object doc = constructor.newInstance(props);
            // SyntaxDocument doc = new SyntaxDocument(props);
            m_textPane.setDocument((DefaultStyledDocument) doc);
            // m_textPane.setBackground(doc.getBackgroundColor());
            m_textPane.setBackground(
                    VisualizeUtils.processColour(props.getProperty("BackgroundColor", "white"), Color.WHITE));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        m_textPane.setForeground(
                VisualizeUtils.processColour(props.getProperty("ForegroundColor", "black"), Color.BLACK));
        m_textPane.setBackground(
                VisualizeUtils.processColour(props.getProperty("BackgroundColor", "white"), Color.WHITE));
        m_textPane.setFont(new Font(props.getProperty("FontName", "monospaced"), Font.PLAIN,
                Integer.parseInt(props.getProperty("FontSize", "12"))));
    }

    final JFileChooser fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.setMultiSelectionEnabled(false);

    setUpNewScript();

    setLayout(new BorderLayout());
    add(new JScrollPane(m_textPane), BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());
    JPanel newCompile = new JPanel();
    newCompile.setLayout(new BorderLayout());

    JButton newBut = new JButton("New");
    JButton compileBut = new JButton("Compile");
    JButton okBut = new JButton("OK");
    JButton cancelBut = new JButton("Cancel");
    newCompile.add(newBut, BorderLayout.WEST);
    newCompile.add(compileBut, BorderLayout.EAST);

    buttonPanel.add(newCompile, BorderLayout.WEST);
    buttonPanel.add(okBut, BorderLayout.CENTER);
    buttonPanel.add(cancelBut, BorderLayout.EAST);
    add(buttonPanel, BorderLayout.SOUTH);

    newBut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newScript(fileChooser);
        }
    });

    compileBut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doCompile();
        }
    });

    okBut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (m_groovyP != null) {
                m_groovyP.setScript(m_script.getContent());

                if (m_modifyListener != null) {
                    m_modifyListener.setModifiedStatus(GroovyComponentCustomizer.this, true);
                }

                // close the dialog
                m_parentWindow.dispose();
            }
        }
    });

    cancelBut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // just close the dialog
            // TODO if their are mods, ask the user (same if the frame is closed
            // from the close widget)
            if (m_modifyListener != null) {
                m_modifyListener.setModifiedStatus(GroovyComponentCustomizer.this, false);
            }

            m_parentWindow.dispose();
        }
    });

    m_menuBar = new JMenuBar();

    JMenu fileM = new JMenu();
    m_menuBar.add(fileM);
    fileM.setText("File");
    fileM.setMnemonic('F');

    JMenuItem newItem = new JMenuItem();
    fileM.add(newItem);
    newItem.setText("New");
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));
    newItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newScript(fileChooser);
        }
    });

    JMenuItem loadItem = new JMenuItem();
    fileM.add(loadItem);
    loadItem.setText("Open File...");
    loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
    loadItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int retVal = fileChooser.showOpenDialog(GroovyComponentCustomizer.this);
            if (retVal == JFileChooser.APPROVE_OPTION) {
                boolean ok = m_script.open(fileChooser.getSelectedFile());
                if (!ok) {
                    JOptionPane.showMessageDialog(GroovyComponentCustomizer.this,
                            "Couldn't open file '" + fileChooser.getSelectedFile() + "'!");
                }
            }
        }
    });

    JMenuItem saveItem = new JMenuItem();
    fileM.add(saveItem);

    saveItem.setText("Save");
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (m_script.getFilename() != null) {
                save(null);
            } else {
                save(fileChooser);
            }
        }
    });

    JMenuItem saveAsItem = new JMenuItem();
    fileM.add(saveAsItem);

    saveAsItem.setText("Save As...");
    saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK));
    saveAsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            save(fileChooser);
        }
    });

    JMenu scriptM = new JMenu();
    m_menuBar.add(scriptM);
    scriptM.setText("Script");
    scriptM.setMnemonic('S');

    JMenuItem compileItem = new JMenuItem();
    scriptM.add(compileItem);
    compileItem.setText("Compile");
    compileItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
    compileItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doCompile();
        }
    });

    Dimension d = new Dimension(600, 800);
    m_textPane.setMinimumSize(d);
    m_textPane.setPreferredSize(d);
}