Ticket #323 (closed enhancement: fixed)

Opened 12 years ago

Last modified 12 years ago

SpeechSubmission App: Word Wrapping JLabel text

Reported by: kmaclean Owned by: kmaclean
Priority: major Milestone: SpeechSubmission 0.1.4
Component: SpeechSubmission Version: SpeechSubmission0.1.3
Keywords: Cc:

Description


Change History

comment:1 Changed 12 years ago by kmaclean

  • Status changed from new to assigned

Problem with getting line wrapping to work with SpeechSubmission app

comment:2 Changed 12 years ago by kmaclean

A quick and dirty way to get this to work is to modify the text of a line as follows:

ru_0001 <html> this is supposed to be the first line, <br> this is supposed to be the second line.

comment:3 Changed 12 years ago by kmaclean

One very cludgy approach modifying prompts.java:

private void getPromptLine(int nextPrompt, int idx) {
    String promptID;
    StringBuffer prompt = new StringBuffer();
    
	StringTokenizer st = new StringTokenizer(promptList[nextPrompt]);
    String [] words= new String [st.countTokens()];
	int i = 0;
	while (st.hasMoreTokens()) { 
		words[i] = st.nextToken(); i++; 
	}
	promptID = words[0];

	// !!!!!!
	int j = 0;	
    if (words.length > 0) {
    	if (words.length > 10) {
        	prompt.append("<html>");
    	}
    	//for (i=1; i<words.length; i++) {  	
    	for (i=1; i<words.length; i++,j++) {
        	if (j > 15) {
            	prompt.append("<br>");
            	j=1;
        	}
        	prompt.append(words[i]);
        	prompt.append(" ");
        }
    }
    // !!!!!!

    promptSubset [0][idx] = promptID;
    promptSubset [1][idx] = prompt.toString();
}	

comment:4 Changed 12 years ago by kmaclean

should be:

private void getPromptLine(int nextPrompt, int idx) {
    String promptID;
    StringBuffer prompt = new StringBuffer();
    
	StringTokenizer st = new StringTokenizer(promptList[nextPrompt]);
    String [] words= new String [st.countTokens()];
	int i = 0;
	while (st.hasMoreTokens()) { 
		words[i] = st.nextToken(); i++; 
	}
	promptID = words[0];

	// !!!!!!
	int j = 0;	
	int sentenceLength = 17;
    if (words.length > 0) {
    	if (words.length > sentenceLength) {
        	prompt.append("<html>");
    	}
    	//for (i=1; i<words.length; i++) {  	
    	for (i=1; i<words.length; i++,j++) {
        	if (j > sentenceLength) {
            	prompt.append("<br>");
            	j=1;
        	}
        	prompt.append(words[i]);
        	prompt.append(" ");
        }
    }
    // !!!!!!

    promptSubset [0][idx] = promptID;
    promptSubset [1][idx] = prompt.toString();
}	

comment:5 Changed 12 years ago by kmaclean

see this post by sindisil:

import java.awt.Container;
import javax.swing.JLabel;
import javax.swing.JTextArea;

public class MultiLineLabel extends JTextArea {

    public MultiLineLabel(Container parent, String text,
                           int maxWidth, boolean labelFont) {
        super();
        JLabel lbl = new JLabel();
        setFocusable(false);
        setEditable(false);
        setBackground(lbl.getBackground());
        setLineWrap(true);
        setWrapStyleWord(true);
        if (labelFont) {
            setFont(lbl.getFont());
        }
        setHighlighter(null);
        if (maxWidth > 0) {
            setColumns(Math.min(maxWidth, text.length()));
        }
        append((text == null || text.length() == 0) ? " " : text);
    }

    public MultiLineLabel(Container parent, String text) {
        this(parent, text, 0, true);
    }

    public MultiLineLabel(Container parent, String text, boolean labelFont) {
        this(parent, text, 0, labelFont);
    }

    public MultiLineLabel(Container parent, String text, int maxWidth) {
        this(parent, text, maxWidth, true);
    }
}

comment:6 Changed 12 years ago by kmaclean

  • Summary changed from Russian translations to SpeechSubmission App: Setting up Line Wrapping

comment:7 Changed 12 years ago by kmaclean

  • Summary changed from SpeechSubmission App: Setting up Line Wrapping to SpeechSubmission App: Word Wrapping JLabel text

comment:8 Changed 12 years ago by kmaclean

  • Status changed from assigned to closed
  • Resolution set to fixed

by sindisil see this post:

public  class MultiLineLabel extends JTextArea {

 public MultiLineLabel(Container parent, String text,
                        int maxWidth, boolean labelFont) {
     super();
     JLabel lbl = new JLabel();
     setFocusable(false);
     setEditable(false);
     setBackground(lbl.getBackground());
     setLineWrap(true);
     setWrapStyleWord(true);
     if (labelFont) {
         setFont(lbl.getFont());
     }
     setHighlighter(null);
     if (maxWidth > 0) {
         //setColumns(Math.min(maxWidth, text.length()));
         setColumns(Math.min(maxWidth, 100));
     }
     append((text == null || text.length() == 0) ? " " : text);
 }

 public MultiLineLabel(Container parent, String text) {
     this(parent, text, 0, true);
 }

 public MultiLineLabel(Container parent, String text, boolean labelFont) {
     this(parent, text, 0, labelFont);
 }

 public MultiLineLabel(Container parent, String text, int maxWidth) {
     this(parent, text, maxWidth, true);
 }
Note: See TracTickets for help on using tickets.