Search in sources :

Example 41 with Color

use of java.awt.Color in project jfinal by jfinal.

the class CaptchaRender method drawGraphic.

private String drawGraphic(BufferedImage image) {
    // 获取图形上下文
    Graphics g = image.createGraphics();
    // 生成随机类
    Random random = new Random();
    // 设定背景色
    g.setColor(getRandColor(200, 250));
    g.fillRect(0, 0, WIDTH, HEIGHT);
    // 设定字体
    g.setFont(new Font("Times New Roman", Font.PLAIN, 18));
    // 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
    g.setColor(getRandColor(160, 200));
    for (int i = 0; i < 155; i++) {
        int x = random.nextInt(WIDTH);
        int y = random.nextInt(HEIGHT);
        int xl = random.nextInt(12);
        int yl = random.nextInt(12);
        g.drawLine(x, y, x + xl, y + yl);
    }
    // 取随机产生的认证码(4位数字)
    String sRand = "";
    for (int i = 0; i < 4; i++) {
        String rand = String.valueOf(strArr[random.nextInt(strArr.length)]);
        sRand += rand;
        // 将认证码显示到图象中
        g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        // 调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
        g.drawString(rand, 16 * i + 11, 19);
    }
    // 图象生效
    g.dispose();
    return sRand;
}
Also used : Graphics(java.awt.Graphics) Random(java.util.Random) Color(java.awt.Color) Font(java.awt.Font)

Example 42 with Color

use of java.awt.Color in project jfinal by jfinal.

the class CaptchaRender method getRandColor.

/*
	 * 给定范围获得随机颜色
	 */
private Color getRandColor(int fc, int bc) {
    Random random = new Random();
    if (fc > 255)
        fc = 255;
    if (bc > 255)
        bc = 255;
    int r = fc + random.nextInt(bc - fc);
    int g = fc + random.nextInt(bc - fc);
    int b = fc + random.nextInt(bc - fc);
    return new Color(r, g, b);
}
Also used : Random(java.util.Random) Color(java.awt.Color)

Example 43 with Color

use of java.awt.Color in project jersey by jersey.

the class MainWindow method createRequestStatusLabel.

private JLabel createRequestStatusLabel() {
    final JLabel label = new JLabel("   ");
    invokeAndWait(new Runnable() {

        @Override
        public void run() {
            label.setBackground(PROGRESS_COLOR);
            label.setToolTipText("Running...");
            label.setBorder(javax.swing.BorderFactory.createLineBorder(new Color(0, 0, 0)));
            label.setOpaque(true);
            messagePanel.add(label);
            messagePanel.revalidate();
        }
    });
    return label;
}
Also used : Color(java.awt.Color) JLabel(javax.swing.JLabel)

Example 44 with Color

use of java.awt.Color in project apjp by jvansteirteghem.

the class Main method main.

public static void main(final String[] args) {
    EventQueue.invokeLater(new Runnable() {

        public void run() {
            try {
                System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
                Security.addProvider(new IAIK());
                Properties properties = new Properties();
                properties.load(new FileInputStream("APJP_LOCAL.properties"));
                APJP.APJP_KEY = properties.getProperty("APJP_KEY", "");
                APJP.APJP_LOGGER_ID = "APJP";
                APJP.APJP_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_PROXY_SERVER";
                APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_PROXY_SERVER";
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTP_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTP_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTP_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_SERVER";
                APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL = new String[10];
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
                for (int i = 0; i < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
                    APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_URL", "");
                    for (int j = 0; j < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
                    }
                }
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_PROXY_SERVER";
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTPS_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTPS_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_SERVER";
                APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL = new String[10];
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
                for (int i = 0; i < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
                    APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_URL", "");
                    for (int j = 0; j < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
                    }
                }
                APJP.APJP_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTP_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTP_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_HTTP_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_HTTP_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTP_PROXY_SERVER_USERNAME", "");
                APJP.APJP_HTTP_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTP_PROXY_SERVER_PASSWORD", "");
                APJP.APJP_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTPS_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTPS_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_HTTPS_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_HTTPS_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTPS_PROXY_SERVER_USERNAME", "");
                APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTPS_PROXY_SERVER_PASSWORD", "");
                Authenticator.setDefault(new Authenticator() {

                    protected PasswordAuthentication getPasswordAuthentication() {
                        PasswordAuthentication passwordAuthentication = null;
                        if (this.getRequestorType() == Authenticator.RequestorType.PROXY) {
                            if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTP") == true) {
                                passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTP_PROXY_SERVER_USERNAME, APJP.APJP_HTTP_PROXY_SERVER_PASSWORD.toCharArray());
                            } else {
                                if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTPS") == true) {
                                    passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTPS_PROXY_SERVER_USERNAME, APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD.toCharArray());
                                }
                            }
                        }
                        return passwordAuthentication;
                    }
                });
                logger = Logger.getLogger(APJP.APJP_LOGGER_ID);
                final ProxyServer proxyServer = new ProxyServer();
                final JTextArea outputTextArea = new JTextArea();
                outputTextArea.setEditable(false);
                outputTextArea.setLineWrap(true);
                outputTextArea.setBackground(new Color(0, 0, 0));
                outputTextArea.setForeground(new Color(255, 255, 255));
                outputTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
                final JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
                final OutputStream outputStream = new OutputStream() {

                    public void write(final int b) throws IOException {
                        outputTextArea.append(new String(new char[] { (char) b }));
                    }

                    public void write(final byte[] b, final int off, final int len) throws IOException {
                        outputTextArea.append(new String(b, off, len));
                    }
                };
                final PrintStream printStream = new PrintStream(outputStream, true);
                System.setOut(printStream);
                final JButton startButton = new JButton();
                startButton.setText("Start");
                startButton.setPreferredSize(new Dimension(100, 30));
                startButton.addActionListener(new ActionListener() {

                    public void actionPerformed(final ActionEvent actionEvent) {
                        outputTextArea.setText("");
                        logger.log(1, "START_PROXY_SERVER");
                        try {
                            proxyServer.start();
                            logger.log(1, "START_PROXY_SERVER: OK");
                        } catch (Exception e) {
                            logger.log(1, "START_PROXY_SERVER: EXCEPTION", e);
                            logger.log(1, "START_PROXY_SERVER: NOT OK");
                        }
                        HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
                        logger.log(1, "TEST_HTTP_REQUESTS");
                        try {
                            httpRequests.test();
                            logger.log(1, "TEST_HTTP_REQUESTS: OK");
                        } catch (Exception e) {
                            logger.log(1, "TEST_HTTP_REQUESTS: EXCEPTION", e);
                            logger.log(1, "TEST_HTTP_REQUESTS: NOT OK");
                        }
                        HTTPSRequests httpsRequests = HTTPSRequests.getHTTPSRequests();
                        logger.log(1, "TEST_HTTPS_REQUESTS");
                        try {
                            httpsRequests.test();
                            logger.log(1, "TEST_HTTPS_REQUESTS: OK");
                        } catch (Exception e) {
                            logger.log(1, "TEST_HTTPS_REQUESTS: EXCEPTION", e);
                            logger.log(1, "TEST_HTTPS_REQUESTS: NOT OK");
                        }
                    }
                });
                final JButton stopButton = new JButton();
                stopButton.setText("Stop");
                stopButton.setPreferredSize(new Dimension(100, 30));
                stopButton.addActionListener(new ActionListener() {

                    public void actionPerformed(final ActionEvent actionEvent) {
                        outputTextArea.setText("");
                        logger.log(1, "STOP_PROXY_SERVER");
                        try {
                            proxyServer.stop();
                            logger.log(1, "STOP_PROXY_SERVER: OK");
                        } catch (Exception e) {
                            logger.log(1, "STOP_PROXY_SERVER: EXCEPTION", e);
                            logger.log(1, "STOP_PROXY_SERVER: NOT OK");
                        }
                    }
                });
                final Panel buttonPanel = new Panel();
                buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
                buttonPanel.add(startButton);
                buttonPanel.add(stopButton);
                final ImageIcon imageIcon = new ImageIcon("APJP_LOCAL.png");
                final JFrame frame = new JFrame();
                frame.setIconImage(imageIcon.getImage());
                frame.setSize(675, 375);
                frame.setResizable(false);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(buttonPanel, BorderLayout.NORTH);
                frame.add(outputScrollPane, BorderLayout.CENTER);
                if (SystemTray.isSupported()) {
                    final TrayIcon trayIcon = new TrayIcon(imageIcon.getImage());
                    trayIcon.setImageAutoSize(true);
                    trayIcon.addActionListener(new ActionListener() {

                        public void actionPerformed(final ActionEvent actionEvent) {
                            frame.setVisible(!frame.isVisible());
                        }
                    });
                    SystemTray.getSystemTray().add(trayIcon);
                }
                frame.setVisible(true);
            } catch (Exception e) {
                logger.log(1, "EXCEPTION", e);
            }
        }
    });
}
Also used : ImageIcon(javax.swing.ImageIcon) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) OutputStream(java.io.OutputStream) JButton(javax.swing.JButton) HTTPRequests(APJP.HTTP11.HTTPRequests) Properties(java.util.Properties) Font(java.awt.Font) HTTPSRequests(APJP.HTTP11.HTTPSRequests) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) TrayIcon(java.awt.TrayIcon) IAIK(iaik.security.provider.IAIK) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication) JScrollPane(javax.swing.JScrollPane) PrintStream(java.io.PrintStream) Color(java.awt.Color) IOException(java.io.IOException) Dimension(java.awt.Dimension) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ProxyServer(APJP.ProxyServer) Panel(java.awt.Panel) ActionListener(java.awt.event.ActionListener)

Example 45 with Color

use of java.awt.Color in project openblocks by mikaelhg.

the class BlockGenus method loadBlockGenera.

/**
     * Loads the all the initial BlockGenuses and BlockGenus families of this language
     * @param workspace The workspace in use
     * @param root the Element carrying the specifications of the BlockGenuses
     */
public static void loadBlockGenera(Workspace workspace, Element root) {
    WorkspaceEnvironment env = workspace.getEnv();
    Pattern attrExtractor = Pattern.compile("\"(.*)\"");
    Matcher nameMatcher;
    //look for genus
    NodeList genusNodes = root.getElementsByTagName("BlockGenus");
    Node genusNode;
    StringTokenizer col;
    for (int i = 0; i < genusNodes.getLength(); i++) {
        //find them
        genusNode = genusNodes.item(i);
        if (genusNode.getNodeName().equals("BlockGenus")) {
            /// LOAD BLOCK GENUS PROPERTIES ///
            BlockGenus newGenus = new BlockGenus(env);
            //first, parse out the attributes
            nameMatcher = attrExtractor.matcher(genusNode.getAttributes().getNamedItem("name").toString());
            if (nameMatcher.find()) {
                newGenus.genusName = nameMatcher.group(1);
            }
            //assert that no other genus has this name
            assert env.getGenusWithName(newGenus.genusName) == null : "Block genus names must be unique.  A block genus already exists with this name: " + newGenus.genusName;
            nameMatcher = attrExtractor.matcher(genusNode.getAttributes().getNamedItem("color").toString());
            if (nameMatcher.find()) {
                //will be true
                col = new StringTokenizer(nameMatcher.group(1));
                if (col.countTokens() == 3) {
                    newGenus.color = new Color(Integer.parseInt(col.nextToken()), Integer.parseInt(col.nextToken()), Integer.parseInt(col.nextToken()));
                } else {
                    newGenus.color = Color.BLACK;
                }
            }
            nameMatcher = attrExtractor.matcher(genusNode.getAttributes().getNamedItem("kind").toString());
            if (nameMatcher.find()) {
                newGenus.kind = nameMatcher.group(1);
            }
            nameMatcher = attrExtractor.matcher(genusNode.getAttributes().getNamedItem("initlabel").toString());
            if (nameMatcher.find()) {
                //implied that it is global, but it may be redefined
                newGenus.initLabel = nameMatcher.group(1);
            }
            nameMatcher = attrExtractor.matcher(genusNode.getAttributes().getNamedItem("editable-label").toString());
            if (nameMatcher.find()) {
                newGenus.isLabelEditable = nameMatcher.group(1).equals("yes") ? true : false;
            }
            nameMatcher = attrExtractor.matcher(genusNode.getAttributes().getNamedItem("label-unique").toString());
            if (nameMatcher.find()) {
                newGenus.labelMustBeUnique = nameMatcher.group(1).equals("yes") ? true : false;
            }
            //load optional items
            Node opt_item = genusNode.getAttributes().getNamedItem("is-starter");
            if (opt_item != null) {
                nameMatcher = attrExtractor.matcher(opt_item.toString());
                if (nameMatcher.find()) {
                    newGenus.isStarter = nameMatcher.group(1).equals("yes") ? true : false;
                }
            }
            opt_item = genusNode.getAttributes().getNamedItem("is-terminator");
            if (opt_item != null) {
                nameMatcher = attrExtractor.matcher(opt_item.toString());
                if (nameMatcher.find()) {
                    newGenus.isTerminator = nameMatcher.group(1).equals("yes") ? true : false;
                }
            }
            opt_item = genusNode.getAttributes().getNamedItem("is-label-value");
            if (opt_item != null) {
                nameMatcher = attrExtractor.matcher(opt_item.toString());
                if (nameMatcher.find()) {
                    newGenus.isLabelValue = nameMatcher.group(1).equals("yes") ? true : false;
                }
            }
            opt_item = genusNode.getAttributes().getNamedItem("label-prefix");
            if (opt_item != null) {
                nameMatcher = attrExtractor.matcher(opt_item.toString());
                if (nameMatcher.find()) {
                    newGenus.labelPrefix = nameMatcher.group(1);
                }
            }
            opt_item = genusNode.getAttributes().getNamedItem("label-suffix");
            if (opt_item != null) {
                nameMatcher = attrExtractor.matcher(opt_item.toString());
                if (nameMatcher.find()) {
                    newGenus.labelSuffix = nameMatcher.group(1);
                }
            }
            opt_item = genusNode.getAttributes().getNamedItem("page-label-enabled");
            if (opt_item != null) {
                nameMatcher = attrExtractor.matcher(opt_item.toString());
                if (nameMatcher.find()) {
                    newGenus.isPageLabelEnabled = nameMatcher.group(1).equals("yes") ? true : false;
                }
            }
            //in other words, it should not have before and after connectors
            if (newGenus.isDataBlock() || newGenus.isVariableDeclBlock() || newGenus.isFunctionBlock()) {
                newGenus.isStarter = true;
                newGenus.isTerminator = true;
            }
            //next, parse out the elements
            NodeList genusChildren = genusNode.getChildNodes();
            Node genusChild;
            for (int j = 0; j < genusChildren.getLength(); j++) {
                genusChild = genusChildren.item(j);
                if (genusChild.getNodeName().equals("description")) {
                    /// LOAD BLOCK GENUS DESCRIPTION ///
                    loadGenusDescription(genusChild.getChildNodes(), newGenus);
                } else if (genusChild.getNodeName().equals("BlockConnectors")) {
                    /// LOAD BLOCK CONNECTOR INFORMATION ///
                    loadBlockConnectorInformation(workspace, genusChild.getChildNodes(), newGenus);
                    //if genus has two connectors both of bottom position type than this block is an infix operator
                    if (newGenus.sockets != null && newGenus.sockets.size() == 2 && newGenus.sockets.get(0).getPositionType() == BlockConnector.PositionType.BOTTOM && newGenus.sockets.get(1).getPositionType() == BlockConnector.PositionType.BOTTOM) {
                        newGenus.isInfix = true;
                    }
                } else if (genusChild.getNodeName().equals("Images")) {
                    /// LOAD BLOCK IMAGES ///
                    loadBlockImages(genusChild.getChildNodes(), newGenus);
                } else if (genusChild.getNodeName().equals("LangSpecProperties")) {
                    /// LOAD LANGUAGE SPECIFIC PROPERTIES ///
                    loadLangDefProperties(genusChild.getChildNodes(), newGenus);
                } else if (genusChild.getNodeName().equals("Stubs")) {
                    /// LOAD STUBS INFO AND GENERATE GENUSES FOR EACH STUB ///
                    loadStubs(genusChild.getChildNodes(), newGenus);
                }
            }
            // John's code to add command sockets... probably in the wrong place
            if (!newGenus.isStarter) {
                newGenus.before = new BlockConnector(workspace, BlockConnectorShape.getCommandShapeName(), BlockConnector.PositionType.TOP, "", false, false, Block.NULL);
            }
            if (!newGenus.isTerminator) {
                newGenus.after = new BlockConnector(workspace, BlockConnectorShape.getCommandShapeName(), BlockConnector.PositionType.BOTTOM, "", false, false, Block.NULL);
            }
            //System.out.println("Added "+newGenus.toString());
            env.addBlockGenus(newGenus);
        }
    }
    /////////////////////////////////////
    /// LOAD BLOCK FAMILY INFORMATION ///
    /////////////////////////////////////
    NodeList families = root.getElementsByTagName("BlockFamily");
    Node family;
    Node member;
    String name;
    ArrayList<String> famList = new ArrayList<String>();
    for (int i = 0; i < families.getLength(); i++) {
        family = families.item(i);
        for (int j = 0; j < family.getChildNodes().getLength(); j++) {
            member = family.getChildNodes().item(j);
            if (member.getNodeName().equals("FamilyMember")) {
                //a family member entry
                name = member.getTextContent();
                assert env.getGenusWithName(name) != null : "Unknown BlockGenus: " + name;
                assert !env.getGenusWithName(name).isLabelEditable : "Genus " + name + " is in a family, but its name is editable";
                famList.add(name);
            }
        }
        if (famList.size() > 0) {
            for (String memName : famList) {
                ArrayList<String> newFamList = new ArrayList<String>(famList);
                //filter out current memName, so that only
                newFamList.remove(memName);
                //sibling names are included
                env.getGenusWithName(memName).familyList = newFamList;
            }
        }
        famList.clear();
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Color(java.awt.Color) ArrayList(java.util.ArrayList) WorkspaceEnvironment(edu.mit.blocks.workspace.WorkspaceEnvironment) StringTokenizer(java.util.StringTokenizer)

Aggregations

Color (java.awt.Color)895 Graphics2D (java.awt.Graphics2D)117 BufferedImage (java.awt.image.BufferedImage)75 Font (java.awt.Font)63 Dimension (java.awt.Dimension)51 Point (java.awt.Point)47 ArrayList (java.util.ArrayList)46 JLabel (javax.swing.JLabel)41 BasicStroke (java.awt.BasicStroke)38 JPanel (javax.swing.JPanel)38 JScrollPane (javax.swing.JScrollPane)33 GradientPaint (java.awt.GradientPaint)31 Rectangle (java.awt.Rectangle)31 JButton (javax.swing.JButton)31 ActionEvent (java.awt.event.ActionEvent)30 Paint (java.awt.Paint)29 Insets (java.awt.Insets)26 ActionListener (java.awt.event.ActionListener)26 Component (java.awt.Component)24 GridBagConstraints (java.awt.GridBagConstraints)23