Example #1
1
  private void updateTemplateFromEditor(PrintfTemplate template) {
    ArrayList params = new ArrayList();
    String format = null;
    int text_length = editorPane.getDocument().getLength();
    try {
      format = editorPane.getDocument().getText(0, text_length);
    } catch (BadLocationException ex1) {
    }
    Element section_el = editorPane.getDocument().getDefaultRootElement();
    // Get number of paragraphs.
    int num_para = section_el.getElementCount();
    for (int p_count = 0; p_count < num_para; p_count++) {
      Element para_el = section_el.getElement(p_count);
      // Enumerate the content elements
      int num_cont = para_el.getElementCount();
      for (int c_count = 0; c_count < num_cont; c_count++) {
        Element content_el = para_el.getElement(c_count);
        AttributeSet attr = content_el.getAttributes();
        // Get the name of the style applied to this content element; may be null
        String sn = (String) attr.getAttribute(StyleConstants.NameAttribute);
        // Check if style name match
        if (sn != null && sn.startsWith("Parameter")) {
          // we extract the label.
          JLabel l = (JLabel) StyleConstants.getComponent(attr);
          if (l != null) {
            params.add(l.getName());
          }
        }
      }
    }

    template.setFormat(format);
    template.setTokens(params);
  }
  // int jlabel3_state=0;
  public void mouseClicked(MouseEvent e) {
    JLabel source = (JLabel) e.getSource();
    if (label_state.get(source) == 0) {
      if (source.getName() == "jLabel11") {
        if (challenge_file == null) {
          JOptionPane.showMessageDialog(null, "Challenge File Not Loaded");
        } else {
          reset_labelState();
          active_label = (JLabel) source;
          label_state.put(source, 1);
          try {
            ImageIcon icon =
                new javax.swing.ImageIcon(getClass().getResource("resources/images/pause.jpg"));
            jLabel11.setIcon(icon);
          } catch (Exception et) {
            JOptionPane.showMessageDialog(null, et.toString());
          }
        }

      } else {
        reset_labelState();
        active_label = (JLabel) source;
        label_state.put(source, 1);
      }
      source.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLUE));
    } else {
      active_label = null;
      label_state.put(source, 0);
      if (source.getName() == "jLabel11") {
        try {
          ImageIcon icon =
              new javax.swing.ImageIcon(getClass().getResource("resources/images/play.jpg"));
          jLabel11.setIcon(icon);
        } catch (Exception et) {
          JOptionPane.showMessageDialog(null, et.toString());
        }
      }
      source.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, Color.BLUE));
    }
  }