Relates :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : PC version: 1.5.0_08 Java 2 standard edition PDA version: Jeode EVM Version 1.10.2, Supported Java Platforms: Personal Java 1.2, Requires JeodeClass: 1.10.2 ADDITIONAL OS VERSION INFORMATION : PC showing bug: Microsoft Windows XP [Version 5.1.2600] PDA Device not showing bug: Sharp Zaurus SL-5500 ROM 2.38, Linux 2.4.6-rmk1-np2-embedix with Qtopia Embedix Plus PDA 1.5.0, Insignia Jeode JVM (PersonalJava 1.2) A DESCRIPTION OF THE PROBLEM : There are two specific methods that work correctly on my PDA (Zaurus with Jeode) but do not work on the PC using the same code. First: private void selectNext() { if (current==null) return; if (canUndo) synchText(false); String s = (caseBtn.getLabel().equals("Aa"))?lowerCase:current.getText(); int pos = ta.getCaretPosition(); int ptr = s.indexOf(find.getText(),pos); if (ptr==-1) ptr = s.indexOf(find.getText()); if (ptr!=-1) { ta.select(ptr,ptr+find.getText().length()); System.out.println(ta.getSelectedText()); } } On the PDA, it will select the segment of text that is found to be a match to whatever is typed into TextField find. On the PC, it correctly selects the text internally (the System.out.println method shows that selectedText is what I expected it to be), however, no selection is displayed. On the PC, I used my program's internal Edit->Copy command, which uses TextArea.getSelectedText() to save a copy of the selected String. This correctly saves the selection and then later on when I paste it, it pastes the correct String, although we run into the second bug ... it puts the pasted text into the wrong location. public void setClip(boolean toClip, boolean delete) { if (toClip) clip = ta.getSelectedText(); if (delete) ta.replaceRange("",ta.getSelectionStart(),ta.getSelectionEnd()); } public void putClip() { setClip(false,true); ta.insert(clip,ta.getCaretPosition()); } These two are supposed to implement cut/copy/paste. If you select some text on the PDA and click on Edit->Cut (which calls: setClip(true,true)), the selected text is removed. On the PC, if you click on Edit->Cut, something below the selected text is removed. The same thing happens when you paste. Edit->Paste (which calls: putClip()) inserts the text below the current caret position. One more note: using control+c, control+x, control+v, and delete work properly on the PC using this code (the text changes happen internally on the TextArea and are not monitored or tampered with in my code). I hope this is not just a problem with how I wrote it. I would assume if it works on an older, more compact VM that it should work the same on a newer VM? It seems, according to the documentation, that this is supposed to work how I've written it. I've also been using a Solaris computer with JVM 1.2 installed on it, and it works there, just not the PC. For this program to be the most valuable to me, it should work properly on the various VMs. I checked Java 5 API documentation, and it isn't indicating any changes in how select, insert, getCaretPosition, etc are intended to work. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Here's a scaled-down test case that produces the problem on the PC but does not on the PDA. Two class files (TestEditor.java and ToggleButton.java) are needed. Steps: 1. Compile, run. 2. Type something in, like "public class Blah { }" 3. Click on the button on the bottom of the window to open the find bar. 4. Type in "public" on the first TextField (left of the "F" button) 5. Click on the "F" button. In your terminal/console, "public" will be sent to System.out, but nothing is selected. 6. Click on the menu Edit->Copy. (If you Edit->Cut, notice it cuts the correct text) 7. Click anywhere else in the TextArea then Edit->Paste. It will probably put "public" into the wrong location. import java.awt.*; import java.awt.event.*; import java.io.*; final public class TestEditor extends WindowAdapter implements ActionListener, TextListener, MouseListener { // * FIELDS * // *** CONSTANTS public static final int BUTTON_MAX = 4; public static final int BUTTON_CTR = 2; public static final int ROWS = 14; public static final int COLUMNS = 36; // *** GUI REFERENCES private Frame f; private TextArea ta; private Font taf; private MenuItem[][] MENU_ITEMS; private Menu[] MENUS; private ToggleButton clicky; private Panel clickyPanel; private Panel cp; private TextField find; private Button findBtn; private TextField replace; private Button replaceBtn; private Button caseBtn; private Label status; // *** TRANSIENT private String clip = ""; private String lowerCase = ""; // * MAIN * public static void main(String[] args) { new TestEditor(); } // * CONSTRUCTOR * public TestEditor() { MenuBar mb = new MenuBar(); f = new Frame("Untitled - Project"); f.setMenuBar(mb); MENUS = new Menu[MENU_TEXTS.length]; MENU_ITEMS = new MenuItem[MENU_TEXTS.length][]; for (int i=0;i<MENU_TEXTS.length;i++) { MENU_ITEMS[i] = new MenuItem[MENU_TEXTS[i].length-1]; MENUS[i] = new Menu(MENU_TEXTS[i][0]); for (int j=1;j<MENU_TEXTS[i].length;j++) { MENU_ITEMS[i][j-1] = new MenuItem(MENU_TEXTS[i][j]); MENU_ITEMS[i][j-1].addActionListener(this); MENUS[i].add(MENU_ITEMS[i][j-1]); } mb.add(MENUS[i]); } clickyPanel = new Panel(new BorderLayout()); clicky = new ToggleButton(10,10,20); clicky.addActionListener(this); clickyPanel.add(clicky,BorderLayout.WEST); cp = new Panel(new GridLayout(1,0)); find = new TextField("",20); TextField replace = new TextField("",20); findBtn = new Button("F"); findBtn.addActionListener(this); replaceBtn = new Button("R"); caseBtn = new Button("Aa"); caseBtn.addActionListener(this); status = new Label(" Line 60"); Panel fp = new Panel(new BorderLayout()); fp.add(find,BorderLayout.CENTER); fp.add(findBtn,BorderLayout.EAST); Panel rp = new Panel(new BorderLayout()); rp.add(replace,BorderLayout.CENTER); rp.add(replaceBtn,BorderLayout.EAST); Panel sp = new Panel(new BorderLayout()); sp.add(status,BorderLayout.CENTER); sp.add(caseBtn,BorderLayout.WEST); cp.add(fp); cp.add(rp); cp.add(sp); clickyPanel.add(cp,BorderLayout.CENTER); findBar(); Panel content = new Panel(new BorderLayout()); ta = new TextArea(ROWS,COLUMNS); ta.addMouseListener(this); taf = new Font("fixed",Font.PLAIN,11); System.out.println("Font: "+taf); ta.setFont(taf); ta.addTextListener(this); content.add(ta,BorderLayout.CENTER); content.add(clickyPanel,BorderLayout.SOUTH); content.setVisible(true); f.add(content); f.addWindowListener(this); f.setSize(237,285); f.setVisible(true); f.setResizable(true); } // * INPUT INTERPRETING * /* MENU_TEXTS and action enums need to match for the actionListener to work */ public static final String[][] MENU_TEXTS = { { "File", "Exit" }, { "Edit", "Cut", "Copy", "Paste" } }; public static final int PROJEXIT = 0, EDITCUT = 1, EDITCOPY = 2, EDITPASTE = 3; public void performAction(int which) { switch (which) { case PROJEXIT: endProgram(); break; case EDITCUT: setClip(true,true); break; case EDITCOPY: setClip(true,false); break; case EDITPASTE: putClip(); break; } } // * METHODS * // *** MAIN ACTIONS public void endProgram() { System.exit(0); } public void setClip(boolean toClip, boolean delete) { if (toClip) clip = ta.getSelectedText(); if (delete) ta.replaceRange("",ta.getSelectionStart(),ta.getSelectionEnd()); } public void putClip() { setClip(false,true); ta.insert(clip,ta.getCaretPosition()); } public void findBar() { clicky.toggle(); if (clicky.open()) { clickyPanel.add(cp,BorderLayout.CENTER); } else { clickyPanel.remove(cp); } clickyPanel.setSize(clickyPanel.getSize().width,clicky.getSize().height); f.validate(); } public void updateStatus() { int end = ta.getCaretPosition(); String s = ta.getText(); String pattern = "\n"; int width = 0; int height = 1; int lastPtr = 0; int nowPtr = 0; nowPtr = (s!=null)?s.indexOf(pattern,lastPtr):-1; while (nowPtr!=-1&&nowPtr<end) { lastPtr = nowPtr+1; height++; nowPtr = s.indexOf(pattern,lastPtr); } status.setText("R:"+height+" C:"+(end-lastPtr)); } private void selectNext() { String s = (caseBtn.getLabel().equals("Aa"))?ta.getText().toLowerCase():ta.getText(); int pos = ta.getCaretPosition(); int ptr = s.indexOf(find.getText(),pos); if (ptr==-1) ptr = s.indexOf(find.getText()); if (ptr!=-1) { ta.select(ptr,ptr+find.getText().length()); System.out.println(ta.getSelectedText()); } } private void replaceText() { if (!ta.getSelectedText().equals(find.getText())) selectNext(); if (ta.getSelectedText().equals(find.getText())) ta.replaceRange(replace.getText(),ta.getSelectionStart(),ta.getSelectionEnd()); } // * LISTENERS * public void windowClosing(WindowEvent e) { Object o = e.getSource(); if (o==f) endProgram(); } public void actionPerformed(ActionEvent e) { Object o = e.getSource(); if (o instanceof Button) { if (o==clicky) { findBar(); return; } if (o==findBtn) { selectNext(); return; } if (o==replaceBtn) { replaceText(); return; } if (o==caseBtn) { caseBtn.setLabel((caseBtn.getLabel().charAt(0)=='A')?"aa":"Aa"); return; } } else { int whichAction = 0; int i=0; int j=0; while (o!=MENU_ITEMS[i][j]&&i<MENU_ITEMS.length) { whichAction++; j++; if (j>=MENU_ITEMS[i].length) { j=0; i++; } } if (i<MENU_ITEMS.length) { // System.out.println("Clicked: "+MENU_TEXTS[i][j+1]+","+whichAction); performAction(whichAction); } else { whichAction=-1; System.out.println("Invalid pick."); } } } public void textValueChanged(TextEvent e) { updateStatus(); } public void mouseClicked(MouseEvent e) { updateStatus(); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} } import java.awt.*; public class ToggleButton extends Button { int width; int heightOpen; int heightClosed; boolean isOpen; public ToggleButton(int w, int hClosed, int hOpen) { super(""); width=w; heightOpen=hOpen; heightClosed=hClosed; isOpen=true; } public boolean open() { return isOpen; } public void toggle() { isOpen=!isOpen; if (isOpen) setLabel("<"); else setLabel(""); setSize(getPreferredSize()); } public Dimension getPreferredSize() { int h = isOpen?heightOpen:heightClosed; return new Dimension(width,h); } public Dimension getMinimumSize() { return getPreferredSize(); } } EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - See steps to reproduce. I expect when you click on the "F" button to find the text, that it will correctly display as selected. I also expect that when you click on Edit->Copy then Edit->Paste that it will paste into the correct caret position. ACTUAL - See steps to reproduce. select(int,int) doesn't select the text that is reported by getSelectedText() insert(string,caret position) doesn't insert at the caret position ERROR MESSAGES/STACK TRACES THAT OCCUR : No error messages are reported. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- The test case is included in steps to reproduce. I have compiled and tested it, it does show the error on the PC. ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : I tried butchering the code to use javax.swing.JTextArea while still maintaining compatibility with the older JVM on the PDA. It probably had the same error. It wasn't useful and broke the scrollbars (I had to cast the JTextArea as a Container ... I didn't play around with it much after find didn't work on it either).
|