Friday, September 18, 2015

facebook is so bad

        I only use Facebook randomly. Today I try to start using it more but realize it's frustrating. The biggest problem is that your friends like/comments will show up on your Home News Feed. It has two issues:
1. You have no privacy.
When your friends make any comments or like your posts, all his friends can see the whole post and comments/likes.
2. Too many annoying messages
Especially if your friends mother language is not English.

The weird thing is that Facebook has no option to opt it out. You have to install some tools like FB purity to remove it. It's terrible.

Wechat is much better to protect the privacy than Facebook and QQ. Even your different friends all comments on the same post, they cannot see the post each other unless they are friends too. It's so sweet.

Saturday, September 12, 2015

angler fishing

soft plastics: artificial worm s and the like
most light leaders are rigged with a ball-bearing swivel at one end and a snap at the other for connect ing to the lure.
Getting bait to the rught deppth for those fish calls for smart use of singkers and floats.
connectors: swivels and snaps
jig head
hook removers
You can use a knife blade to scale fish, but the numerous scalers available today make the job easier and quicker.
tackle boxes and trays,
tackle bags
pliers for hook Removal
The mesh of many nets now comes with a smooth coating to prevent hook snags and tangles.

Large mouth bass prefers warmer, still water

Friday, September 4, 2015

Extended JComboBox to support multiple JCheckBox elements

Implement JQuery style MultiSelect JComboBox with JCheckBox
Use {@link #getSelectedItems() getSelectedItems} method. to get the selected item list
See  http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/
for the referenced JQuery implementation.

package combo;

import javax.swing.JFrame;

public class MultiCheckComboTEst extends JFrame{

private static final long serialVersionUID = -3578706354915513446L;

public static void main(String[] args) throws Exception {
MultiCheckComboTEst frame = new MultiCheckComboTEst();
        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
        frame.pack();
        frame.setLocationRelativeTo( null );
        frame.setVisible( true );
}

public MultiCheckComboTEst() throws Exception
    {
        String[] ids = { "ALL","FX", "IR", "EQ", "BOND" };
        MultiCheckComboBox comboBox = new MultiCheckComboBox( ids );
        add( comboBox );
    }

}

////////////////////////////
package combo;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.plaf.basic.ComboPopup;

/**
 * Implement JQuery style MultiSelect JComboBox with JCheckBox
 * Use {@link #getSelectedItems() getSelectedItems} method. to get the selected item list
 * <p>
 * See <a href="http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/">Basic Demo</a>
 * for the referenced JQuery implementation.
 * <p>
 * @author pengp2
 *
 */

public class MultiCheckComboBox extends JComboBox {

private static final long serialVersionUID = 4735456197188571568L;
private MultiCheckComboModel[] models;
    public MultiCheckComboBox(final Object items[]) {
    this(items,null);
    }
    public MultiCheckComboBox(final Object items[],Boolean states[]){
    super();
    if(items==null){
    System.err.println("items cannot be null.");
    return;
    }
    if(states==null){
    states = new Boolean[items.length];
    Arrays.fill(states, false);
    }
    if(items.length!=states.length){
        System.err.println("Unexpected parameters for MultiCheckComboBox.");
    return;
    }
        models = new MultiCheckComboModel[items.length];
        for(int i=0;i<items.length;i++){
        models[i] = new MultiCheckComboModel(items[i].toString(),states[i]);
        }
        setModel(new DefaultComboBoxModel(models));
    }
    
    @Override
    public void updateUI() {
    super.updateUI();
    final MultiCheckComboRenderer render = new MultiCheckComboRenderer();
    setRenderer(render);
    setUI(new MultiCheckComboBoxUI());
    addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
       MultiCheckComboModel comboModel = (MultiCheckComboModel) MultiCheckComboBox.this.getModel().getSelectedItem();
       comboModel.setIsSelected(!comboModel.getIsSelected());
       render.getCheckBox().setSelected(comboModel.getIsSelected());

       if (comboModel.getId().equalsIgnoreCase("ALL")){
           for (int i = 0; i < getItemCount(); i++){
               ((MultiCheckComboModel)getItemAt(i)).setIsSelected(render.getCheckBox().isSelected());
           }
       }
       int selectedNum = 1;
           for (int i = 1; i < getItemCount(); i++){
            if(((MultiCheckComboModel)getItemAt(i)).getIsSelected()){
            selectedNum++;
            }
           }
           ((MultiCheckComboModel)getItemAt(0)).setIsSelected(selectedNum==getItemCount());
           getModel().setSelectedItem(selectedNum-1+" selected");
           getEditor().getEditorComponent().repaint();
       repaint();
       ((ComboPopup) getUI().getAccessibleChild(MultiCheckComboBox.this, 0)).getList().repaint();
       
//        MultiCheckComboModel[] selected = MultiCheckComboBox.this.getModels();
//        for(MultiCheckComboModel selectedO:selected){
//         System.out.println("selectedO="+selectedO);
//        }
       
}
});
    }

public MultiCheckComboModel[] getSelectedItems() {
return models;
}

}


///////
package combo;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
import javax.swing.plaf.metal.MetalComboBoxUI;
  
public class MultiCheckComboBoxUI extends MetalComboBoxUI {
  
   @Override
   protected ComboPopup createPopup() {
      return new BasicComboPopup(comboBox) {
private static final long serialVersionUID = -1657533899648565541L;
@Override
    protected MouseListener createListMouseListener() {
             return new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
           if (e.getSource() == list) {
               if (list.getModel().getSize() > 0) {
                   // JList mouse listener
                   if (comboBox.getSelectedIndex() == list.getSelectedIndex()) {
                       comboBox.getEditor().setItem(list.getSelectedValue());
                   }
                   comboBox.setSelectedIndex(list.getSelectedIndex());
               }
//                comboBox.setPopupVisible(false);
               // workaround for cancelling an edited item (bug 4530953)
               if (comboBox.isEditable() && comboBox.getEditor() != null) {
                   comboBox.configureEditor(comboBox.getEditor(),
                                            comboBox.getSelectedItem());
               }
               return;
           }
           // JComboBox mouse listener
           Component source = (Component)e.getSource();
           Dimension size = source.getSize();
           Rectangle bounds = new Rectangle( 0, 0, size.width - 1, size.height - 1 );
           if ( !bounds.contains( e.getPoint() ) ) {
               MouseEvent newEvent = convertMouseEvent( e );
               Point location = newEvent.getPoint();
               Rectangle r = new Rectangle();
               list.computeVisibleRect( r );
               if ( r.contains( location ) ) {
                   if (comboBox.getSelectedIndex() == list.getSelectedIndex()) {
                       comboBox.getEditor().setItem(list.getSelectedValue());
                   }
                   comboBox.setSelectedIndex(list.getSelectedIndex());
               }
//                comboBox.setPopupVisible(false);
           }
           comboBox.setPopupVisible(true);
           hasEntered = false;
           stopAutoScrolling();
}
@Override
public void mousePressed(MouseEvent e) {
           if (e.getSource() == list) {
               return;
           }
           if (!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled())
               return;

           if ( comboBox.isEditable() ) {
               Component comp = comboBox.getEditor().getEditorComponent();
               if ((!(comp instanceof JComponent)) || ((JComponent)comp).isRequestFocusEnabled()) {
                   comp.requestFocus();
               }
           }
           else if (comboBox.isRequestFocusEnabled()) {
               comboBox.requestFocus();
           }
           togglePopup();
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
};
    }
      };
   }
   
}

/////
package combo;

public class MultiCheckComboModel {
    private String id;
    Boolean isSelected;

    public MultiCheckComboModel(String id, Boolean isSelected) {
        this.id = id;
        this.isSelected = isSelected;
    }

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Boolean getIsSelected() {
return isSelected;
}

public void setIsSelected(Boolean isSelected) {
this.isSelected = isSelected;
}
@Override
public String toString() {
return id+(isSelected?" is selected":" is not selected");
}
    
}


///////
package combo;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class MultiCheckComboRenderer implements ListCellRenderer{
private JCheckBox checkBox;
public MultiCheckComboRenderer() {
checkBox = new JCheckBox();
}

@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
    if(value instanceof MultiCheckComboModel){
    MultiCheckComboModel comboModel = (MultiCheckComboModel) value;
            checkBox.setText(comboModel.getId());
            checkBox.setSelected(((Boolean) comboModel.getIsSelected()).booleanValue());
            checkBox.setBackground(isSelected ? Color.LIGHT_GRAY : Color.white);
            checkBox.setForeground(isSelected ? Color.white : Color.black);
            return checkBox;
    }
    return new JLabel(value.toString());
}

public JCheckBox getCheckBox() {
return checkBox;
}

}

Wednesday, September 2, 2015

Eclipse maven Plugin execution not covered by lifecycle configuration error

Eclipse maven Plugin execution not covered by lifecycle configuration error

After checkout the project from SVN, Eclipse complained the below error:
Plugin execution not covered by lifecycle configuration: org.jibx:jibx-maven-plugin:1.2.3:bind (execution: bind, phase: process-classes)
Maven Project Build Lifecycle Mapping Problem

While if I run mvn package from the command line, it has no problem.
It's actually an issue of m2e plugin:
https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html

There are three ways to fix it as I know:
1. Ignore this error by updating Preferences->Maven_Errors/Warnings->Plugin execution not covered by lifecycle configuration
2. Update the phase to any other string like m2eissue to diable it within Eclipse (do not submit)
3. Configure the plugin management to instruct m2e what should it do like:
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-antrun-plugin
</artifactId>
<versionRange>
[1.6,)
</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jibx</groupId>
<artifactId>
jibx-maven-plugin
</artifactId>
<versionRange>
[1.2.3,)
</versionRange>
<goals>
<goal>bind</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>


Wednesday, August 12, 2015

An interesting JDK6 bug about EventDispatchThread

An interesting JDK6 bug about EventDispatchThread

0. Background
Need add read only access control for legacy Java Swing modules.

1. What's the issue
To avoid the changes scattered in many places, ReadonlyException is defined and DefaultUncaughtExceptionHandler is set in one place. It looks good
except for the modal popup dialog. There's a message on console:
Exception occurred during event dispatching:...

2. What's the cause
The message comes from EventDispatchThread.java:
            if (isModal) {
                System.err.println(
                    "Exception occurred during event dispatching:");
                e.printStackTrace();
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException)e;
            } else if (e instanceof Error) {
                throw (Error)e;
            }
    if it's a modal dialog, the exception will be captured by EDT, the problem is that EDT does not pass it to UncaughtExceptionHandler like JDK7 or JDK8:
getUncaughtExceptionHandler().uncaughtException(this, e);

3. How to fix
By debugging/tracking the JDK source code, we can set property "sun.awt.exception.handler" but even after I set the property, issue is still there.
Checking the EventDispatchTread.java source again, and there's a block:
       try {
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                Class c = Class.forName(handlerClassName, true, cl);
                m = c.getMethod("handle", new Class[] { Throwable.class });
                h = c.newInstance();
            } catch (Throwable x) {
                handlerClassName = NO_HANDLER; /* Do not try this again */
                return false;
            }
It means that it will invoke the handler's handle method, and the handler must have a non-parameter construtctor. The worst thing is that it does not print any
error message when the exception happens. Until I checked here, I realized I need add a non-parameter construtctor to the handler.

4. More about the bug:
http://bugs.java.com/view_bug.do?bug_id=6727884
I verified it worked perfect on JDK8 without the workaround and it failed to show the popup message on JDK6 without the workaround.

How to debug JDK source code:
1. Unzip src.zip and create a java project in Eclipse, set the source to the unzipped src folder
2. If there's compilor error (...is not accessible due to restriction...), remove JRE library and add them back to let Eclipse use the right class first
3. Export the jar file and put it into %JDK%\jre\lib\endorsed. Create endorsed folder if it's not there. We don't have permission to operate on the default
JDK home, so need to set JDK home to other place.

JQuery note

jQuery Syntax

1. Basic syntax is: $(selector).action()
Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".

2. It is good practice to wait for the document to be fully loaded and ready before working with it.
$(document).ready(function(){
   // jQuery methods go here...
});
The jQuery team has also created an even shorter method for the document ready event:
$(function(){
   // jQuery methods go here...
});

3. More Examples of jQuery Selectors
$("*") Selects all elements
$(this) Selects the current HTML element
$("p.intro") Selects all <p> elements with class="intro"
$("p:first") Selects the first <p> element
$("ul li:first") Selects the first <li> element of the first <ul>
$("ul li:first-child") Selects the first <li> element of every <ul>
$("[href]") Selects all elements with an href attribute
$("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank"
$("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank"
$(":button") Selects all <button> elements and <input> elements of type="button"
$("tr:even") Selects all even <tr> elements
$("tr:odd") Selects all odd <tr> elements

4. Three simple, but useful, jQuery methods for DOM manipulation are:
text() - Sets or returns the text content of selected elements
html() - Sets or returns the content of selected elements (including HTML markup)
val() - Sets or returns the value of form fields
The jQuery attr() method is used to get attribute values.
four jQuery methods that are used to add new content:
append() - Inserts content at the end of the selected elements
prepend() - Inserts content at the beginning of the selected elements
after() - Inserts content after the selected elements
before() - Inserts content before the selected elements
remove() - Removes the selected element (and its child elements)
empty() - Removes the child elements from the selected element
$("p").css("background-color", "yellow");

5. sample list
http://www.w3schools.com/jquery/jquery_examples.asp

Sunday, August 9, 2015

32位XP 下安装64位win7 双系统

直接安装不了,因为32位系统下不支持64位的系统安装,去网上找一个nt6 hdd installer软件,把你下载的安装版的WIN7解压到你要安装的盘根目录下,再运行nt6 hdd installer,重启就可以自动安装了

http://zhidao.baidu.com/question/175322484.html?qbl=relate_question_2&optimi=4