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); }
void saveButton_actionPerformed(ActionEvent e) { updateEditableTemplate(selectedPane); originalTemplate.setFormat(editableTemplate.m_format); originalTemplate.setTokens(editableTemplate.m_tokens); m_data.updateTemplateData(originalTemplate); setVisible(false); }
protected void setTemplate(PrintfTemplate template) { originalTemplate = template; editableTemplate.setFormat(template.m_format); editableTemplate.setTokens(template.m_tokens); updatePane(selectedPane); }
private void updateTemplateFromPrintf() { String format = formatTextArea.getText(); String parameters = parameterTextArea.getText(); editableTemplate.setFormat(format); editableTemplate.setParameters(parameters); }