Search Results

Search found 2845 results on 114 pages for 'michael cheng'.

Page 13/114 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • xstream handles non-english character

    - by Yan Cheng CHEOK
    I have the following code : /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package helloworld; import com.thoughtworks.xstream.XStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import javax.swing.JOptionPane; /** * * @author yccheok */ public class Test { @SuppressWarnings("unchecked") public static <A> A fromXML(Class c, File file) { XStream xStream = new XStream(); InputStream inputStream = null; try { inputStream = new java.io.FileInputStream(file); Object object = xStream.fromXML(inputStream); if (c.isInstance(object)) { return (A)object; } } catch (Exception exp) { exp.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); inputStream = null; } catch (java.io.IOException exp) { exp.printStackTrace(); return null; } } } return null; } @SuppressWarnings("unchecked") public static <A> A fromXML(Class c, String filePath) { return (A)fromXML(c, new File(filePath)); } public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; try { outputStream = new FileOutputStream(file); xStream.toXML(object, outputStream); } catch (Exception exp) { exp.printStackTrace(); return false; } finally { if (outputStream != null) { try { outputStream.close(); outputStream = null; } catch (java.io.IOException exp) { exp.printStackTrace(); return false; } } } return true; } public static boolean toXML(Object object, String filePath) { return toXML(object, new File(filePath)); } public static void main(String args[]) { String s = "\u6210\u4EA4\u91CF"; // print ??? System.out.println(s); // fine! show ??? JOptionPane.showMessageDialog(null, s); toXML(s, "C:\\A.XML"); String o = fromXML(String.class, "C:\\A.XML"); // show ??? JOptionPane.showMessageDialog(null, o); } } I run the following code through command prompt in Windows Vista. 1) May I know why System.out.println unable to print out Chinese Character in console? 2) I open up the xstream file. The saved value is <string>???</string> How can I make xstream save Chinese Character correctly? Thanks.

    Read the article

  • How can i handle mouse double click event on textbox?

    - by Kar Cheng
    Hello, I want to open one child window on mouse double click of textbox. I know the only event available in Silverlight is MouseLeftButtonDown and you have to simulate double click. However it still doesn't work when i click in the middle of the textbox. It only works when i double click on the border of the textbox. Anybody has any ideas of how can i do this? If any 3rd party library is available then also it's fine. Thanks in advance:)

    Read the article

  • vagrant box add: where does .box file get downloaded to?

    - by Calvin Cheng
    What actually happens to the .box file (which according to the docs is simply a vbox image in tar form, in a particular format) after the first command vagrant box add lucid32 http://files.vagrantup.com/lucid32.box is executed? I can't seem to find the filesystem location of lucid32.box after the download has successfully completed... I am aware it doesn't really matter as vagrant init lucid32 vagrant up vagrant ssh will get me into the vm irregardless. But I am curious where .box is located.

    Read the article

  • ListView causing OutOfMemory Error

    - by Michael
    So I am not really given a reason to the right of this error message. I am not exactly sure why this is happening but my guess though is that it has to do with the fact that there are around ~50 good quality drawables. Upon scrolling really fast, the app crashes. I feel as if I am mitigating most common issues with ListView and crashing such as using View Holders as well as only initiating the inflater once. Process: com.example.michael.myandroidappactivity, PID: 20103 java.lang.OutOfMemoryError at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) Here is the code public class ImageAdapter extends BaseAdapter { private Context context; private ArrayList<Integer> imageIds; private static LayoutInflater inflater; public ImageAdapter(Context _context, ArrayList<Integer> _imageIds) { context = _context; imageIds = _imageIds; } @Override public int getCount() { return imageIds.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } static class ViewHolder{ ImageView img; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; View rowView = null; if(rowView==null) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); rowView = inflater.inflate(R.layout.listview_layout, parent, false); holder = new ViewHolder(); holder.img = (ImageView) rowView.findViewById(R.id.flag); rowView.setTag(holder); } else { holder = (ViewHolder) rowView.getTag(); } holder.img.setImageResource(imageIds.get(position)); return rowView; } }

    Read the article

  • C++ Static Initializer - Is it thread safe

    - by Yan Cheng CHEOK
    Usually, when I try to initialize a static variable class Test2 { public: static vector<string> stringList; private: static bool __init; static bool init() { stringList.push_back("string1"); stringList.push_back("string2"); stringList.push_back("string3"); return true; } }; // Implement vector<string> Test2::stringList; bool Test2::__init = Test2::init(); Is the following code thread safe, during static variable initialization? Is there any better way to static initialize stringlist, instead of using a seperate static function (init)?

    Read the article

  • Various way to stop a thread - which is the correct way

    - by Yan Cheng CHEOK
    I had came across different suggestion of stopping a thread. May I know, which is the correct way? Or it depends? Using Thread Variable http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html private volatile Thread blinker; public void stop() { blinker = null; } public void run() { Thread thisThread = Thread.currentThread(); while (blinker == thisThread) { try { thisThread.sleep(interval); } catch (InterruptedException e){ } repaint(); } } Using boolean flag private volatile boolean flag; public void stop() { flag = false; } public void run() { while (flag) { try { thisThread.sleep(interval); } catch (InterruptedException e){ } repaint(); } } Using Thread Variable together with interrupt private volatile Thread blinker; public void stop() { blinker.interrupt(); blinker = null; } public void run() { Thread thisThread = Thread.currentThread(); while (!thisThread.isInterrupted() && blinker == thisThread) { try { thisThread.sleep(interval); } catch (InterruptedException e){ } repaint(); } }

    Read the article

  • Why Windows Live Spaces Fetch Image Through HTTPS?

    - by Morgan Cheng
    I happens to find that, when a live space page is loaded, inline images are fetched by https protocol instead of http protocol. This doesn't make sense. The text part of live space is not fetched by https, why images are fetched with https? I bet the https way to fetch image just make the page loaded slower. Is there any special advantage to choose https over http in this case?

    Read the article

  • How to implement a collection (list, map?) of complicated strings in Java?

    - by Alex Cheng
    Hi all. I'm new here. Problem -- I have something like the following entries, 1000 of them: args1=msg args2=flow args3=content args4=depth args6=within ==> args5=content args1=msg args2=flow args3=content args4=depth args6=within args7=distance ==> args5=content args1=msg args2=flow args3=content args6=within ==> args5=content args1=msg args2=flow args3=content args6=within args7=distance ==> args5=content args1=msg args2=flow args3=flow ==> args4=flowbits args1=msg args2=flow args3=flow args5=content ==> args4=flowbits args1=msg args2=flow args3=flow args6=depth ==> args4=flowbits args1=msg args2=flow args3=flow args6=depth ==> args5=content args1=msg args2=flow args4=depth ==> args3=content args1=msg args2=flow args4=depth args5=content ==> args3=content args1=msg args2=flow args4=depth args5=content args6=within ==> args3=content args1=msg args2=flow args4=depth args5=content args6=within args7=distance ==> args3=content I'm doing some sort of suggestion method. Say, args1=msg args2=flow args3=flow == args4=flowbits If the sentence contains msg, flow, and another flow, then I should return the suggestion of flowbits. How can I go around doing it? I know I should scan (whenever a character is pressed on the textarea) a list or array for a match and return the result, but, 1000 entries, how should I implement it? I'm thinking of HashMap, but can I do something like this? <"msg,flow,flow","flowbits" Also, in a sentence the arguments might not be in order, so assuming that it's flow,flow,msg then I can't match anything in the HashMap as the key is "msg,flow,flow". What should I do in this case? Please help. Thanks a million!

    Read the article

  • Complete list of Fonts which support

    - by Yan Cheng CHEOK
    Currently, if I change the locale setting of my application by Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.SIMPLIFIED_CHINESE); What I understand from this JFreeChart forum is that, I am not using correct font. Once you get the reference of the LegentTitle, you can set it to any font. Apparently, JFreeChart's default is "Tahoma" and it doesn't support Chinese characters. May I know, how I can programmatic determine, as list of available Fonts in my system, which support Chinese? I can hard code it to Serif (It fully support Chinese, doesn't it?), its look n feel doesn't looks good to me. I would like to have more choices.

    Read the article

  • drupal display submenu when parent has been selected

    - by Steven Cheng
    I've have a menu structure that has a depth of 3 levels on a drupal 6 CMS. When I click on a level 1 that has children, the level 2 menu items display fine. If the level 2 has children, it is not showing the level 3. If I check the expanded box the level 3 is displayed however, it displays all the time irrespective of the level 2 that has been selected. It seems to display whenever it's parent level 1 is selected. For further information, the menu items are a mixture of custom links & content links. i.e. Links I've enetered manually when creating the menu and others generated by when creating a node or view display. All I want is to show the children if there are any for the selected parent. Am I missing something fundamental here? Thanks Steve

    Read the article

  • Why can't we have an immutable version of operator[] for map

    - by Yan Cheng CHEOK
    The following code works fine : std::map<int, int>& m = std::map<int, int>(); int i = m[0]; But not the following code : // error C2678: binary '[' : no operator... const std::map<int, int>& m = std::map<int, int>(); int i = m[0]; Most of the time, I prefer to make most of my stuff to become immutable, due to reason : http://www.javapractices.com/topic/TopicAction.do?Id=29 I look at map source code. It has mapped_type& operator[](const key_type& _Keyval) Is there any reason, why std::map unable to provide const mapped_type& operator[](const key_type& _Keyval) const

    Read the article

  • Is this a correct way to stop Execution Task

    - by Yan Cheng CHEOK
    I came across code to stop execution's task. private final ExecutorService executor = Executors.newSingleThreadExecutor(); public void stop() { executor.shutdownNow(); try { executor.awaitTermination(100, TimeUnit.DAYS); } catch (InterruptedException ex) { log.error(null, ex); } } public Runnable getRunnable() { return new Runnable() { public void run() { while (!Thread.currentThread().isInterrupted()) { // What if inside fun(), someone try to clear the interrupt flag? // Say, through Thread.interrupted(). We will stuck in this loop // forever. fun(); } } }; } I realize that, it is possible for Runnable to be in forever loop, as Unknown fun may Thread.sleep, clear the interrupt flag and ignore the InterruptedException Unknown fun may Thread.interrupted, clear the interrupt flag. I was wondering, is the following way correct way to fix the code? private final ExecutorService executor = Executors.newSingleThreadExecutor(); private volatile boolean flag = true; public void stop() { flag = false; executor.shutdownNow(); try { executor.awaitTermination(100, TimeUnit.DAYS); } catch (InterruptedException ex) { log.error(null, ex); } } public Runnable getRunnable() { return new Runnable() { public void run() { while (flag && !Thread.currentThread().isInterrupted()) { // What if inside fun(), someone try to clear the interrupt flag? // Say, through Thread.interrupted(). We will stuck in this loop // forever. fun(); } } }; }

    Read the article

  • Is It Possible to Make Close Sourced PHP Product?

    - by Morgan Cheng
    I'm curious that whether all PHP product must be open sourced if it is to be deployed to other's web site. Since PHP code is executed by interpretation, if I have PHP product to be deployed on other's host, it seems no reason to prevent others view the source code. So, PHP product is destined to be open source, right?

    Read the article

  • How to set JComboBox not to select an element when created? (Java)

    - by Alex Cheng
    Hi all. Problem: I am using JComboBox, and tried using setSelectionIndex(-1) in my code (this code is placed in caretInvoke()) suggestionComboBox.removeAllItems(); for (int i = 0; i < suggestions.length; i++) { suggestionComboBox.addItem(suggestions[i]); } suggestionComboBox.setSelectedIndex(-1); suggestionComboBox.setEnabled(true); This is the initial setting when it was added to a pane: suggestionComboBox = new JComboBox(); suggestionComboBox.setEditable(false); suggestionComboBox.setPreferredSize(new Dimension(25, 25)); suggestionComboBox.addActionListener(new SuggestionComboBoxListener()); When the caretInvoke triggers the ComboBox initialisation, even before the user selects an element, the actionPerformed is already triggered (I tried a JOptionPane here): First popup (notice that "flow byte_jump" is selected): Second popup (I think the setSelectionIndex is executed) Then in the end: The problem is: My program autoinserts the selected text when the user selects an element from the ComboBox. So without the user selecting anything, it is automatically inserted already. How can I overcome the problem in this situation? Thanks.

    Read the article

  • Is It Safe to Cast Away volatile?

    - by Yan Cheng CHEOK
    Most of the time, I am doing this way. class a { public: ~ a() { i = 100; // OK delete (int *)j; // Compiler happy. But, is it safe? // Error : delete j; } private: volatile int i; volatile int *j; }; int main() { a aa; } However, I saw an article here: https://www.securecoding.cert.org/confluence/display/seccode/EXP32-C.+Do+not+access+a+volatile+object+through+a+non-volatile+reference Casting away volatile allows access to an object through a non-volatile reference. This can result in undefined and perhaps unintended program behavior. So, what will be the workaround for my above code example?

    Read the article

  • why multipart/x-mixed-replace is needed for Comet?

    - by Morgan Cheng
    I'm reading this article about Comet http://en.wikipedia.org/wiki/Comet_(programming). It mentions that browser should support multipart/x-mixed-replace to make XmlHttpRequest Streaming possible. Why this multipart/x-mixed-replace is necessary? Without this header, HTTP response can still be chunked and sent piece by piece to browser, right?

    Read the article

  • Trying to get focus onto JTextPane after doubleclicking on JList element (Java)

    - by Alex Cheng
    Hi all. Problem: I have the following JList which I add to the textPane, and show it upon the caret moving. However, after double clicking on the Jlist element, the text gets inserted, but the caret is not appearing on the JTextPane. This is the following code: listForSuggestion = new JList(str.toArray()); listForSuggestion.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listForSuggestion.setSelectedIndex(0); listForSuggestion.setVisibleRowCount(visibleRowCount); listScrollPane = new JScrollPane(listForSuggestion); MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); //System.out.println("Double-clicked on: " + o.toString()); //Set the double clicked text to appear on textPane String completion = o.toString(); int num= textPane.getCaretPosition(); textPane.select(num, num); textPane.replaceSelection(completion); textPane.setCaretPosition(num + completion.length()); int pos = textPane.getSelectionEnd(); textPane.select(pos, pos); textPane.replaceSelection(""); textPane.setCaretPosition(pos); textPane.moveCaretPosition(pos); } } theList.clearSelection(); Any idea on how to "de-focus" the selection on the Jlist, or make the caret appear on the JTextPane after the text insertion? I'll elaborate more if this is not clear enough. Please help, thanks!

    Read the article

  • Is Form Tag Necessary in AJAX Web Application?

    - by Morgan Cheng
    I read some AJAX-Form tutorial like this. The tag form is used in HTML code. However, I believed that it is not necessary. Since we send HTTP request through XmlHttpRequest, the sent data can be anything, not necessary input in form. So, is there any reason to have form tag in HTML for AJAX application?

    Read the article

  • Is there any need for me to use wstring in the following case

    - by Yan Cheng CHEOK
    Currently, I am developing an app for a China customer. China customer are mostly switch to GB2312 language in their OS encoding. I need to write a text file, which will be encoded using GB2312. I use std::ofstream file I compile my application under MBCS mode, not unicode. I use the following code, to convert CString to std::string, and write it to file using ofstream std::string Utils::ToString(CString& cString) { /* Will not work correctly, if we are compiled under unicode mode. */ return (LPCTSTR)cString; } To my surprise. It just works. I thought I need to at least make use of wstring. I try to do some investigation. Here is the MBCS.txt generated. I try to print a single character named ? (its value is 0xBDC5) When I use CString to carry this character, its length is 2. When I use Utils::ToString to perform conversion to std::string, the returned string length is 2. I write to file using std::ofstream My question is : When I exam MBCS.txt using a hex editor, the value is displayed as BD (LSB) and C5 (MSB). But I am using little endian machine. Isn't hex editor should show me C5 (LSB) and BD (MSB)? I check from wikipedia. GB2312 seems doesn't specific endianness. It seems that using std::string + CString just work fine for my case. May I know in what case, the above methodology will not work? and when I should start to use wstring?

    Read the article

  • Java Font Display Problem

    - by Yan Cheng CHEOK
    I realize that, in my certain customer side, when I use the font provided by Graphics2D itself, and decrease the size by 1, it cannot display properly. private void drawInformationBox(Graphics2D g2, JXLayer<? extends V> layer) { if (MainFrame.getInstance().getJStockOptions().getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Hide) { return; } final Font oldFont = g2.getFont(); final Font paramFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize()); final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont); final Font valueFont = new Font(oldFont.getFontName(), oldFont.getStyle() | Font.BOLD, oldFont.getSize() + 1); final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont); /* * This date font cannot be displayed properly. Why? */ final Font dateFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() - 1); final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont); Rest of the font is OK. Here is the screen shoot (See the yellow box. There are 3 type of different font within the yellow box) :

    Read the article

  • How to Implement Dynamic Timestamp in Web Page?

    - by Morgan Cheng
    In Facebook and twitter, we can see that there is a timestamp like "23 seconds ago" or "1 hour ago" for each event & tweet. If we leave the page for some time, the timestamp changes accordingly. Since it is possible that user machine doesn't have same system time as server machine, how to make the dynamic timestamp accurate? My idea is: It is always based on server time. When request is sent to server for the web page, timestamp T1 (seconds to 1970/1/1) is rendered into inline javascript variable. The displayed timestamp ("23 seconds ago") is calculated by T1 instead of local time. I'm not sure whether this is how Facebook/Twitter do it. Is there any better idea?

    Read the article

  • Transferring binary file from web server to client

    - by Yan Cheng CHEOK
    Usually, when I want to transfer a web server text file to client, here is what I did import cgi print "Content-Type: text/plain" print "Content-Disposition: attachment; filename=TEST.txt" print filename = "C:\\TEST.TXT" f = open(filename, 'r') for line in f: print line Works very fine for ANSI file. However, say, I have a binary file a.exe (This file is in web server secret path, and user shall not have direct access to that directory path). I wish to use the similar method to transfer. How I can do so? What content-type I should use? Using print seems to have corrupted content received at client side. What is the correct method?

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >