javauis/lcdui_akn/javalcdui/javasrc.nokialcdui/com/nokia/mid/ui/TextEditor.java
branchRCL_3
changeset 23 e5618cc85d74
parent 14 04becd199f91
child 24 6c158198356e
equal deleted inserted replaced
21:4376525cdefb 23:e5618cc85d74
   147     private int iMaxSize;
   147     private int iMaxSize;
   148 
   148 
   149     // The current font of this text editor component
   149     // The current font of this text editor component
   150     private Font iFont;
   150     private Font iFont;
   151 
   151 
   152     // Indicates receiving of pointer events by the editor
       
   153     private boolean iTouchEnabled;
       
   154 
       
   155     // Text editor container for handling editor focusing.
   152     // Text editor container for handling editor focusing.
   156     private static TextEditorContainer iEditorContainer;
   153     private static TextEditorContainer iEditorContainer;
   157 
   154 
   158     // Color indicators. Must be in sync with MMIDTextEditor::TColorType
   155     // Color indicators. Must be in sync with MMIDTextEditor::TColorType
   159     private static final int COLOR_BACKGROUND = 0;
   156     private static final int COLOR_BACKGROUND = 0;
   193      * newly assigned maximum size, the contents are truncated from the end in
   190      * newly assigned maximum size, the contents are truncated from the end in
   194      * order to fit, and no exception is thrown.
   191      * order to fit, and no exception is thrown.
   195      * </P>
   192      * </P>
   196      *
   193      *
   197      * <P>
   194      * <P>
   198      * On Series60-devices, if the MIDlet is manufacturer or operator-signed,
   195      * On Series60-devices the object returned by this method will also
   199      * the object returned by this method will also implement the
   196      * implement the com.nokia.mid.ui.S60TextEditor.
   200      * com.nokia.mid.ui.s60.TextEditor
       
   201      * </P>
   197      * </P>
   202      *
   198      *
   203      * @param text
   199      * @param text
   204      *            the initial contents, or <code>null</code> if the
   200      *            the initial contents, or <code>null</code> if the
   205      *            <code>TextEditor</code> is to be created empty
   201      *            <code>TextEditor</code> is to be created empty
   257      * newly assigned maximum size, the contents are truncated from the end in
   253      * newly assigned maximum size, the contents are truncated from the end in
   258      * order to fit, and no exception is thrown.
   254      * order to fit, and no exception is thrown.
   259      * </P>
   255      * </P>
   260      *
   256      *
   261      * <P>
   257      * <P>
   262      * On Series60-devices, if the MIDlet is manufacturer or operator-signed,
   258      * On Series60-devices the object returned by this method will also
   263      * the object returned by this method will also implement the
   259      * implement the com.nokia.mid.ui.S60TextEditor.
   264      * com.nokia.mid.ui.s60.TextEditor
       
   265      * </P>
   260      * </P>
   266      *
   261      *
   267      * @param maxSize
   262      * @param maxSize
   268      *            the maximum capacity in characters
   263      *            the maximum capacity in characters
   269      * @param constraints
   264      * @param constraints
   617             NativeError.check(_setZPosition(getToolkitHandle(), iHandle, z));
   612             NativeError.check(_setZPosition(getToolkitHandle(), iHandle, z));
   618         }
   613         }
   619     }
   614     }
   620 
   615 
   621     /**
   616     /**
   622      * Specifies whether or not the editor will receive touch-events.
       
   623      * <p>
       
   624      * This is enabled by default.
       
   625      * An editor with touch-event disabled won't be able to perform any
       
   626      * touch-related functionality such as scrolling or positioning the
       
   627      * cursor. It may however still be controlled via the
       
   628      * virtual keypad/control-panel if that is enabled, or receive other +
       
   629      * input e.g. via physical keys
       
   630      * <p>
       
   631      * @param enabled
       
   632      *              true to enabled touch-event, false to disable
       
   633      */
       
   634     public void setTouchEnabled(boolean enabled)
       
   635     {
       
   636         if (iTouchEnabled != enabled)
       
   637         {
       
   638             synchronized (iToolkit)
       
   639             {
       
   640                 _setTouchEnabled(getToolkitHandle(), iHandle, enabled);
       
   641                 iTouchEnabled = enabled;
       
   642             }
       
   643         }
       
   644     }
       
   645 
       
   646     /**
       
   647      * Gets the current touch-enabled state
       
   648      * <p>
       
   649      * @return true if the editor is touch-enabled, false otherwise
       
   650      */
       
   651     public boolean isTouchEnabled()
       
   652     {
       
   653         return iTouchEnabled;
       
   654     }
       
   655 
       
   656     /**
       
   657      * <P>
   617      * <P>
   658      * Returns the Z-position, or the elevation, of the item. The Z-position
   618      * Returns the Z-position, or the elevation, of the item. The Z-position
   659      * decides the stacking order of neighboring items.
   619      * decides the stacking order of neighboring items.
   660      * </P>
   620      * </P>
   661      *
   621      *
   883         if (font == null)
   843         if (font == null)
   884         {
   844         {
   885             font = Font.getDefaultFont();
   845             font = Font.getDefaultFont();
   886         }
   846         }
   887 
   847 
   888         int[] newSize = new int[2];
   848         synchronized (iToolkit)
   889 
   849         {
   890         synchronized (iToolkit)
   850             NativeError.check(_setFont(getToolkitHandle(),
   891         {
   851                                        iHandle,
   892             NativeError.check(_setFont(getToolkitHandle(), iHandle,
   852                                        iLCDUIPackageInvoker.getFontHandle(font)));
   893                                        iLCDUIPackageInvoker.getFontHandle(font), newSize));
       
   894 
       
   895             iFont = font;
   853             iFont = font;
   896 
       
   897             iWidth = newSize[0];
       
   898             iHeight = newSize[1];
       
   899         }
   854         }
   900     }
   855     }
   901 
   856 
   902     /**
   857     /**
   903      * Gets the background color and alpha of this <code>TextEditor</code>.
   858      * Gets the background color and alpha of this <code>TextEditor</code>.
   974      * for the selected text.
   929      * for the selected text.
   975      * The text in a current selection range will be
   930      * The text in a current selection range will be
   976      * rendered using given color value. The default highlight background
   931      * rendered using given color value. The default highlight background
   977      * color is fully opaque black.
   932      * color is fully opaque black.
   978      *
   933      *
   979      * This method is not supported on S40 platform.
       
   980      *
       
   981      * @param color
   934      * @param color
   982      *            the color
   935      *            the color
   983      */
   936      */
   984     public void setHighlightBackgroundColor(int color)
   937     public void setHighlightBackgroundColor(int color)
   985     {
   938     {
   995      * Sets the highlight foreground color. This impacts text color for the
   948      * Sets the highlight foreground color. This impacts text color for the
   996      * selected text.
   949      * selected text.
   997      * The text in a current selection range will be rendered
   950      * The text in a current selection range will be rendered
   998      * using given color value. The default highlight foreground color is fully
   951      * using given color value. The default highlight foreground color is fully
   999      * opaque white.
   952      * opaque white.
  1000      *
       
  1001      * This method is not supported on S40 platform.
       
  1002      *
   953      *
  1003      * @param color
   954      * @param color
  1004      *            the color
   955      *            the color
  1005      */
   956      */
  1006     public void setHighlightForegroundColor(int color)
   957     public void setHighlightForegroundColor(int color)
  1440             NativeError.check(_setMultiline(getToolkitHandle(), iHandle,
  1391             NativeError.check(_setMultiline(getToolkitHandle(), iHandle,
  1441                                             aMultiline));
  1392                                             aMultiline));
  1442         }
  1393         }
  1443     }
  1394     }
  1444 
  1395 
       
  1396     /**
       
  1397      * Gets the height of this <code>TextEditor</code> in pixels.
       
  1398      *
       
  1399      * @return height in pixels
       
  1400      */
       
  1401     public int getHeight()
       
  1402     {
       
  1403         int[] size = doGetSize();
       
  1404         return size[1];
       
  1405     }
       
  1406 
       
  1407     /**
       
  1408      * Gets the width of this <code>TextEditor</code> in pixels.
       
  1409      *
       
  1410      * @return width in pixels
       
  1411      */
       
  1412     public int getWidth()
       
  1413     {
       
  1414         int[] size = doGetSize();
       
  1415         return size[0];
       
  1416     }
       
  1417 
       
  1418     /*
       
  1419      * Gets TextEditor size in pixels - width, height. 
       
  1420      */
       
  1421     private int[] doGetSize()
       
  1422     {
       
  1423         int[] size = new int[2];
       
  1424         synchronized (iToolkit)
       
  1425         {
       
  1426             NativeError.check(_getSize(getToolkitHandle(), iHandle,
       
  1427                 size));
       
  1428         }
       
  1429         return size;
       
  1430     }
       
  1431 
  1445     /*
  1432     /*
  1446      * Disposes the Landmark native peer object, if the handles are valid.
  1433      * Disposes the Landmark native peer object, if the handles are valid.
  1447      * Invalid (negative) handles indicate that their creation failed in the
  1434      * Invalid (negative) handles indicate that their creation failed in the
  1448      * first place.
  1435      * first place.
  1449      */
  1436      */
  1527         iToolkitInvoker = ToolkitInvoker.getToolkitInvoker();
  1514         iToolkitInvoker = ToolkitInvoker.getToolkitInvoker();
  1528         iToolkit = iToolkitInvoker.getToolkit();
  1515         iToolkit = iToolkitInvoker.getToolkit();
  1529 
  1516 
  1530         int handle = 0;
  1517         int handle = 0;
  1531 
  1518 
  1532         // The size of the editor must be known after construction. Use return
       
  1533         // values to store the height and width of the editor after
       
  1534         // construction.
       
  1535         int[] size = new int[2];
       
  1536 
       
  1537         synchronized (iToolkit)
  1519         synchronized (iToolkit)
  1538         {
  1520         {
  1539             // Create native peer object for this Java object.
  1521             // Create native peer object for this Java object.
  1540             handle =
  1522             handle =
  1541                 _createNativePeer(getToolkitHandle(), maxSize, aWidth, aHeight,
  1523                 _createNativePeer(getToolkitHandle(), maxSize, aWidth, aHeight,
  1542                                   aHeightInRows, size);
  1524                                   aHeightInRows);
  1543         }
  1525         }
  1544 
  1526 
  1545         // Check if construction failed and throw out of memory error.
  1527         // Check if construction failed and throw out of memory error.
  1546         if (handle <= NativeError.KErrNone)
  1528         if (handle <= NativeError.KErrNone)
  1547         {
  1529         {
  1548             throw new OutOfMemoryError();
  1530             throw new OutOfMemoryError();
  1549         }
  1531         }
  1550 
       
  1551         // Operation was a success, store size.
       
  1552         iWidth = size[0];
       
  1553         iHeight = size[1];
       
  1554         iMaxSize = maxSize;
       
  1555 
       
  1556         // Enabling receiving pointer events
       
  1557         iTouchEnabled = true;
       
  1558 
  1532 
  1559         // Sets parent to null
  1533         // Sets parent to null
  1560         iParent = null;
  1534         iParent = null;
  1561 
  1535 
  1562         // Construction was successful. Store handle and register for
  1536         // Construction was successful. Store handle and register for
  1571         };
  1545         };
  1572 
  1546 
  1573         // Set the constraints of the editor. The content is now empty.
  1547         // Set the constraints of the editor. The content is now empty.
  1574         setConstraints(constraints);
  1548         setConstraints(constraints);
  1575 
  1549 
  1576         // Set font to Java default font.
  1550         // Store the maxSize of the editor
  1577         setFont(Font.getDefaultFont());
  1551         iMaxSize = maxSize;
  1578 
  1552         
  1579         // Set the text. This now throws an exception if the content is not
  1553         // Set the text. This now throws an exception if the content is not
  1580         // valid for the current set of constraints.
  1554         // valid for the current set of constraints.
  1581         setContent(aContent);
  1555         setContent(aContent);
       
  1556         
       
  1557         // Set font to Java default font.
       
  1558         setFont(Font.getDefaultFont());
  1582     }
  1559     }
  1583 
  1560 
  1584     // Private methods.
  1561     // Private methods.
  1585 
  1562 
  1586     /*
  1563     /*
  1676     private native int _createNativePeer(
  1653     private native int _createNativePeer(
  1677         int aToolkitHandle,
  1654         int aToolkitHandle,
  1678         int maxSize,
  1655         int maxSize,
  1679         int aWidth,
  1656         int aWidth,
  1680         int aHeight,
  1657         int aHeight,
  1681         boolean aHeightInRows,
  1658         boolean aHeightInRows);
  1682         int[] aSize);
       
  1683 
  1659 
  1684     /*
  1660     /*
  1685      * Disposes the native side peer object.
  1661      * Disposes the native side peer object.
  1686      *
  1662      *
  1687      * @param aToolkitHandle A handle to the LCDUI toolkit.
  1663      * @param aToolkitHandle A handle to the LCDUI toolkit.
  2112      * @param aNativePeerHandle A handle to the native side peer object.
  2088      * @param aNativePeerHandle A handle to the native side peer object.
  2113      *
  2089      *
  2114      * @param aFont The application preferred font to be used in this
  2090      * @param aFont The application preferred font to be used in this
  2115      * TextEditor.
  2091      * TextEditor.
  2116      *
  2092      *
  2117      * @param aNewSize On return, contains the new size of the editor.
       
  2118      *
       
  2119      * @return NativeError.KErrNone if the operation was successful. Otherwise,
  2093      * @return NativeError.KErrNone if the operation was successful. Otherwise,
  2120      * a system-wide error code is returned.
  2094      * a system-wide error code is returned.
  2121      */
  2095      */
  2122     private native int _setFont(
  2096     private native int _setFont(
  2123         int aToolkitHandle,
  2097         int aToolkitHandle,
  2124         int aNativePeerHandle,
  2098         int aNativePeerHandle,
  2125         int aFont,
  2099         int aFont);
  2126         int[] aNewSize);
       
  2127 
  2100 
  2128     /*
  2101     /*
  2129      * Sets a listener for this text editor.
  2102      * Sets a listener for this text editor.
  2130      *
  2103      *
  2131      * @param aToolkitHandle A handle to the LCDUI toolkit.
  2104      * @param aToolkitHandle A handle to the LCDUI toolkit.
  2170      * system-wide error code is returned.
  2143      * system-wide error code is returned.
  2171      */
  2144      */
  2172     private native int _getZPosition(int aToolkitHandle, int aNativePeerHandle);
  2145     private native int _getZPosition(int aToolkitHandle, int aNativePeerHandle);
  2173 
  2146 
  2174     /*
  2147     /*
  2175      * Specifies whether or not the editor will receive touch-events.
  2148      * Gets the size of the text editor.
  2176      *
  2149      *
  2177      * This is enabled by default.
  2150      * @param aToolkitHandle A handle to the LCDUI toolkit.
  2178      * An editor with touch-event disabled won't be able to perform any
  2151      *
  2179      * touch-related functionality such as scrolling or positioning the
  2152      * @param aNativePeerHandle A handle to the native side peer object.
  2180      * cursor. It may however still be controlled via the
  2153      *
  2181      * virtual keypad/control-panel if that is enabled, or receive other +
  2154      * @return The size of the TextEditor in pixels.
  2182      * input e.g. via physical keys
  2155      */
  2183      *
  2156     private native int _getSize(int aToolkitHandle, int aNativePeerHandle, 
  2184      * @param aEnabled
  2157         int[] aSize);
  2185      *              true to enabled touch-event, false to disable
       
  2186      */
       
  2187     private native int _setTouchEnabled(int aToolkitHandle,
       
  2188                                         int aNativePeerHandle, boolean aEnabled);
       
  2189 
       
  2190 }
  2158 }
  2191 
  2159 
  2192 // End of file
  2160 // End of file