<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6250349018455583359</id><updated>2024-10-24T01:07:38.746-07:00</updated><title type='text'>Excerpts World</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-6166997442052238789</id><published>2012-04-22T01:34:00.000-07:00</published><updated>2012-04-22T01:34:16.943-07:00</updated><title type='text'>How to do JUnit testing with servlet filters</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.6 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Preamble&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Download using the download link. Import the eclipse project and run configuration for PublicCryptoKeyFilterTest.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Overview of project&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The web project contain sample servlet filters for mock purpose. The sample implementation calls the filter with in the filter to simulate the testing environment.&lt;br /&gt;
&lt;br /&gt;
This project uses the power of mock objects provided by &lt;a href=&quot;http://mvnrepository.com/artifact/org.springframework/spring-mock/2.0.2&quot;&gt;Spring Mock&lt;/a&gt; , &lt;a href=&quot;http://www.junit.org/&quot;&gt;JUnit4&lt;/a&gt; and some nice tweaking to leverage the mock classes to test filters.&lt;br /&gt;
&lt;br /&gt;
Run the PublicCryptoKeyFilterTest configuration to see the test cases passing by calling the filters for testing.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Unit test case&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;@Test
 public void testCryptoKeyFilter() throws Exception {

  PublicCryptoKeyFilter filter = new PublicCryptoKeyFilter();

  final MockRequestDispatcher requestDispatcher = new MockRequestDispatcher(
    &quot;&quot;);

  // http servlet mocked for mocked dispatcher
  MockHttpServletRequest request = new MockHttpServletRequest() {

   @Override
   public RequestDispatcher getRequestDispatcher(String mappingURI) {
    setAttribute(&quot;mappingURI&quot;, mappingURI);
    return requestDispatcher;
   }
  };

  MockHttpServletResponse response = new MockHttpServletResponse();
  MockFilterConfig config = new MockFilterConfig();
  final PrivateCryptoKeyFilter dsFilter = new PrivateCryptoKeyFilter();

  FilterChain filterChain = new MockFilterChain() {
   @Override
   public void doFilter(ServletRequest req, ServletResponse res) {
    try {
     dsFilter.doFilter(req, res, new MockFilterChain());
    } catch (Exception e) {
    }
   }
  };

  request.setRequestURI(&quot;http://localhost:8080&quot;);

  request.addHeader(&quot;Param1&quot;, &quot;no-header&quot;);

  config.addInitParameter(&quot;init-params&quot;, &quot;config.props&quot;);
  filter.init(config);
  filter.doFilter(request, response, filterChain);
  Assert.assertTrue((request.getAttribute(&quot;mappingURI&quot;).toString()
    .equalsIgnoreCase(&quot;/jsp/error.jsp&quot;)));
 }
 &lt;/pre&gt;Enjoy, if you like it please appreciate!&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/6166997442052238789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2012/04/how-to-do-junit-testing-with-servlet.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6166997442052238789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6166997442052238789'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2012/04/how-to-do-junit-testing-with-servlet.html' title='How to do JUnit testing with servlet filters'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-7957924189793742213</id><published>2011-11-04T15:04:00.001-07:00</published><updated>2012-04-22T16:19:53.217-07:00</updated><title type='text'>How to close a JDialog with ESC key in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;Preamble&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This articles will show how to create a dialog which provides center to parent and ESC key functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.3 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Project overview&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The downloadable zip file contains an eclipse project which has a  MainFrame class for GUI. Clicking on the button will create a new parent centered Dialog with ESC functionality enabled. To close dialog press the ESC key.&lt;br /&gt;
&lt;br /&gt;
Unzip the downloadable and load in the eclipse project. Make a run configuration for MainFrame class and you are all set.&lt;b&gt; &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
Enjoy, if you like it please appreciate!&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;/**
  * Closes the dialog
  */
 protected void closeDialog() {
  this.setVisible(false);
  this.dispose();
 }
 
 //all the components are added to the root pane. This is the real magic.
 protected JRootPane createRootPane() {
  KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  JRootPane rootPane = new JRootPane();
  rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
  return rootPane;
 }
 
 private ActionListener actionListener = new ActionListener() {
  
  public void actionPerformed(ActionEvent actionEvent) {
   closeDialog();
  }
 };
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/7957924189793742213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/11/how-to-create-parent-center-dialog-with.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/7957924189793742213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/7957924189793742213'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/11/how-to-create-parent-center-dialog-with.html' title='How to close a JDialog with ESC key in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-3751244787910258773</id><published>2011-10-16T05:02:00.000-07:00</published><updated>2011-10-16T05:02:32.915-07:00</updated><title type='text'>How to create a Closable Tabbed pane in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;Preamble&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
This article shows how to create a closable tabbed pane in java&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.3 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Project overview&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The downloadable zip file contains an eclipse project which has a MainFrame class for GUI. Clicking on the button will create a new tab in the tabbed pane. To close press the tab close button.&lt;br /&gt;
&lt;br /&gt;
Unzip the downloadable and load in the eclipse project. Make a run configuration for MainFrame class and you are all set.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;final CloseableTabbedPane tabbedPane = new CloseableTabbedPane();
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
//to add a new tab

tabbedPane.addTab(&quot;New tab&quot;, new JComponent());&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBBLfoTO94Yb24AuVJ0ZScQYEjd4Csm78LbjRkfCZRnz4vjInbsHjNQnxlmoCCEHUMSs-YkekuHUGVgurKCeqWbCsDdhzgikah11z5NaweVYzcQcjO5DaHR-XJARyEhNd0w6clMGl58SRB/s1600/Tabbedpane1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;177&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBBLfoTO94Yb24AuVJ0ZScQYEjd4Csm78LbjRkfCZRnz4vjInbsHjNQnxlmoCCEHUMSs-YkekuHUGVgurKCeqWbCsDdhzgikah11z5NaweVYzcQcjO5DaHR-XJARyEhNd0w6clMGl58SRB/s320/Tabbedpane1.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4xeWwE7cmAeOtNJwmu8hsRACR6i0VaHzweCXS3ZCNGKE6zHPAvAQnICagwaqevRiMdPLcAhs5b7UDrPlSFSiGu3UH60oXm7RRH_vIsRJH6fQ2fqNYgQ_mcOtNfVyEY1quXDWhdOk-4sIR/s1600/Tabbedpane2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4xeWwE7cmAeOtNJwmu8hsRACR6i0VaHzweCXS3ZCNGKE6zHPAvAQnICagwaqevRiMdPLcAhs5b7UDrPlSFSiGu3UH60oXm7RRH_vIsRJH6fQ2fqNYgQ_mcOtNfVyEY1quXDWhdOk-4sIR/s320/Tabbedpane2.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/3751244787910258773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-create-closable-tabbed-pane-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/3751244787910258773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/3751244787910258773'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-create-closable-tabbed-pane-in.html' title='How to create a Closable Tabbed pane in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBBLfoTO94Yb24AuVJ0ZScQYEjd4Csm78LbjRkfCZRnz4vjInbsHjNQnxlmoCCEHUMSs-YkekuHUGVgurKCeqWbCsDdhzgikah11z5NaweVYzcQcjO5DaHR-XJARyEhNd0w6clMGl58SRB/s72-c/Tabbedpane1.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-6759707911689194608</id><published>2011-10-16T02:22:00.000-07:00</published><updated>2011-10-16T03:35:46.377-07:00</updated><title type='text'>How to preview image in JFileChooser</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;Preamble&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This article shows how to add image preview to a &lt;a href=&quot;http://download.oracle.com/javase/6/docs/api/javax/swing/JFileChooser.html&quot;&gt;JFileChooser&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.3 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Project overview&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The downloadable zip file contains an eclipse project which has a MainFrame class for GUI. Clicking on the button will launch the file chooser. Selecting an image will display a preview in the right pane.&lt;br /&gt;
&lt;br /&gt;
Unzip the downloadable and load in the eclipse project. Make a run configuration for MainFrame class and you are all set. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code usage&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;//attach image preview to FileChooser
ImagePreview preview = new ImagePreview(chooser);
chooser.setAccessory(preview);

&lt;/pre&gt;Enjoy, if you like it please appreciate!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/6759707911689194608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-preview-image-in-jfilechooser.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6759707911689194608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6759707911689194608'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-preview-image-in-jfilechooser.html' title='How to preview image in JFileChooser'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-2180158588166861335</id><published>2011-10-16T01:33:00.000-07:00</published><updated>2011-10-16T03:36:37.079-07:00</updated><title type='text'>Java ZipInputStream with IBM PC or MS-DOS code page 437 (CP437) support</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;Preamble&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This articles will show how to leverage the existing java &lt;a href=&quot;http://download.oracle.com/javase/6/docs/api/java/util/zip/ZipInputStream.html&quot;&gt;ZipInputStream&lt;/a&gt; to also support &lt;a href=&quot;http://en.wikipedia.org/wiki/Code_page_437&quot;&gt;IBM PC or MS-DOS code page 437&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.4 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Project overview&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;
The downloadable zip file contains an eclipse project which has a MainClass for displaying the sample usage.&lt;br /&gt;
&lt;br /&gt;
The magic lies in ExtendedZipInputStream class which supports all the features provided by java &lt;a href=&quot;http://download.oracle.com/javase/6/docs/api/java/util/zip/ZipInputStream.html&quot;&gt;ZipInputStream&lt;/a&gt; in addition to Extended ASCII file names support.&lt;br /&gt;
&lt;br /&gt;
Unzip the downloadable and load in the eclipse project. Make a run configuration for MainClass and you are all set. The magic resides in the &quot;getString&quot; method.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;/**
     * Read string with UTF-8 if fails use CP437 for the specified byte array
     * 
     * @param b The byte array to read the string from
     * @param off The offset to start reading from
     * @param len The total length to read
     * @return Either UTF-8 or CP437 string
     */
    private String getString(byte[] b, int off, int len) {
        String name;

        try {
            if (this.charset == null) name = (String) Reflect.invoke(this, DEF_READ_UTF8_METHOD, b,
                off, len);
            else name = new String(b, off, len, this.charset);
        }
        catch (Exception e) {
            //Unable to determine UTF-8 file name so use CP437
            name = this.getCP437String(b, off, len);
        }
        return name;
    }
&lt;/pre&gt;Enjoy, if you like it please appreciate!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/2180158588166861335/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-support-ibm-pc-or-ms-dos-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/2180158588166861335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/2180158588166861335'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-support-ibm-pc-or-ms-dos-code.html' title='Java ZipInputStream with IBM PC or MS-DOS code page 437 (CP437) support'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-5677134296017167013</id><published>2011-10-16T01:16:00.000-07:00</published><updated>2011-10-16T03:38:13.579-07:00</updated><title type='text'>How to create an oval icon in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package com.stark;

import java.awt.Component;
import java.awt.Graphics;

import javax.swing.Icon;

/***
&amp;nbsp;* A simple icon implementation that draws ovals.
&amp;nbsp;* 
&amp;nbsp;* @author Noman Naeem
&amp;nbsp;* 
&amp;nbsp;*/
public class OvalIcon implements Icon {

&amp;nbsp;&amp;nbsp;&amp;nbsp; private int width, height;

&amp;nbsp;&amp;nbsp;&amp;nbsp; public OvalIcon(int width, int height) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.width = width;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.height = height;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void paintIcon(Component c, Graphics g, int x, int y) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g.drawOval(x, y, this.width - 1, this.height - 1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getIconWidth() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return this.width;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getIconHeight() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return this.height;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/5677134296017167013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-create-oval-icon-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/5677134296017167013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/5677134296017167013'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/10/how-to-create-oval-icon-in-java.html' title='How to create an oval icon in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-6864617891635008480</id><published>2011-06-27T16:02:00.002-07:00</published><updated>2012-02-27T22:22:04.462-08:00</updated><title type='text'>How to remove line trend in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;Preamble&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This method is equivalent to the detrend method of Matlab. It requires the commons math jar from Apache.&lt;br /&gt;
&lt;a href=&quot;http://commons.apache.org/math/index.html&quot;&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Download link&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://commons.apache.org/math/index.html&quot;&gt;http://commons.apache.org/math/index.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;public static double[] detrend(double[] x, double[] y) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (x.length != y.length)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; throw new IllegalArgumentException(&quot;The x and y data elements needs to be of the same length&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SimpleRegression regression = new SimpleRegression();
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; x.length; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; regression.addData(x[i], y[i]);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double slope = regression.getSlope();
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double intercept = regression.getIntercept();
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; x.length; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //y -= intercept + slope * x 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; y[i] -= intercept + (x[i] * slope);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return y;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/6864617891635008480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/06/how-to-remove-line-trend-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6864617891635008480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6864617891635008480'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/06/how-to-remove-line-trend-in-java.html' title='How to remove line trend in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-3646353046573271122</id><published>2011-06-16T01:28:00.000-07:00</published><updated>2013-09-29T21:54:55.559-07:00</updated><title type='text'>How to draw different signal encodings in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;Preamble&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This articles will show how different signals which include, NRZL, NRZI, Bipolar AMI, Psedoternay, Manchester and Differential Manchester are displayed.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.3 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Project overview&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt; &lt;br /&gt;
The downloadable zip file contains an eclipse project which has a MainFrame class for GUI and a DigitalSignalEncoding class which does all the magic. This project uses Swing for GUI and graphics 2D.for drawing the signals.&lt;br /&gt;
&lt;br /&gt;
Each encoding corresponds to a method in the DigitalSignalEncoding class which makes it fairly simple to understand. However, if you have any question; please post comment.&lt;br /&gt;
&lt;br /&gt;
Unzip the downloadable and load in the eclipse project. Make a run configuration for MainFrame class and you are all set. The input can be given in decimal or binay format based on the selected option. Once the input is provided hitting enter key will display the signal.&lt;br /&gt;
&lt;br /&gt;
If different encoding needs to be displayed for the same given input, the selection in the drop down needs to be changed.&lt;br /&gt;
&lt;br /&gt;
Enjoy, if you like it please appreciate!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/3646353046573271122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/06/how-to-draw-different-signal-encodings.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/3646353046573271122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/3646353046573271122'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/06/how-to-draw-different-signal-encodings.html' title='How to draw different signal encodings in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-6789320635839377614</id><published>2011-06-12T00:52:00.002-07:00</published><updated>2012-02-27T22:22:17.955-08:00</updated><title type='text'>How to do auto source formatting in eclipse (RCP) on Save button</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;a href=&quot;https://docs.google.com/leaf?id=0BxtsUP_AjE20OWRmMzZiOGQtYzNiNy00ZjZkLTllOWMtNDQ5NThmMmQxZmNi&amp;amp;hl=en_US&amp;amp;authkey=CJXnjEA&quot;&gt;Click to download src&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/leaf?id=0BxtsUP_AjE20YmU4YzEzYzktZjkyMC00MzQ0LWFhNjUtMTljNTY3OTk0OWE1&amp;amp;hl=en_US&amp;amp;authkey=CKqZyuwE&quot;&gt;Click to download plugin jar&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.6 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Preamble&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Download using the download link. Drop the jar in eclipse&#39;s plugin folder and restart for changes to take affect. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Overview of plugin&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The plugin provides two functionalities, Save and Save all.&lt;br /&gt;
&lt;br /&gt;
The default is the save option, i.e when Ctrl+S is pressed or clicked through menu or toolbar. The code will be automatically saved in the current view.&lt;br /&gt;
&lt;br /&gt;
In the case of save all, when Ctrl+Shift+S is pressed or clicked through menu or toolbar. The code will be automatically saved in all the dirty editors and the current view is preserved.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Change of Settings&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The settings can be changed by going to &quot;Auto Code Formatter&quot; option in Window-&amp;gt;Preferences section.&lt;br /&gt;
&lt;br /&gt;
Enjoy, if you like it please appreciate!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/6789320635839377614/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2011/06/how-to-do-auto-formatting-in-eclipse-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6789320635839377614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6789320635839377614'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2011/06/how-to-do-auto-formatting-in-eclipse-on.html' title='How to do auto source formatting in eclipse (RCP) on Save button'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-702702975319858965</id><published>2010-04-11T17:31:00.000-07:00</published><updated>2011-06-26T22:54:50.667-07:00</updated><title type='text'>How to create a ThreeStateButton in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;

/**
&amp;nbsp;* A Three State Button Class
&amp;nbsp;* @author Noman Naeem
&amp;nbsp;* @version 1.0
&amp;nbsp;*/

public class ThreeStateButtonBean extends JComponent implements Serializable{

&amp;nbsp;&amp;nbsp;&amp;nbsp; private int state = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private int x = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private int y = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private int height = 30;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private int width = 30;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private final int MIN_WIDTH = 10;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private final int MIN_HEIGHT = 10;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private final int RAISED_OFFSET = -1;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private transient PropertyChangeSupport pcs = new PropertyChangeSupport(this);
&amp;nbsp;&amp;nbsp;&amp;nbsp; private boolean isDown = false;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private transient java.util.Vector actionListeners;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private boolean hasFocus = false;

&amp;nbsp;&amp;nbsp;&amp;nbsp; public ThreeStateButtonBean()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp; &amp;nbsp;this.setOpaque(true);
&amp;nbsp;&amp;nbsp; &amp;nbsp;this.enableEvents(AWTEvent.MOUSE_EVENT_MASK);
&amp;nbsp;&amp;nbsp; &amp;nbsp;this.enableEvents(AWTEvent.KEY_EVENT_MASK);
&amp;nbsp;&amp;nbsp; &amp;nbsp;this.enableEvents(AWTEvent.FOCUS_EVENT_MASK);
&amp;nbsp;&amp;nbsp; &amp;nbsp;actionListeners = new java.util.Vector();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void processMouseEvent(MouseEvent me)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (me.getID()) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case MouseEvent.MOUSE_PRESSED:
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; isDown = true;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; this.requestFocus();
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; repaint();
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; break;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case MouseEvent.MOUSE_RELEASED:
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; isDown = false;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; int s = (state+1)%3;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; setState(s);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; if (actionListeners.size() &amp;gt; 0) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ActionEvent ae = new ActionEvent(this,me.getID(),&quot;Mouse Clicked on Button&quot;);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.fireActionEvent(ae);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; }
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; &amp;nbsp;super.processMouseEvent(me);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void processKeyEvent(KeyEvent ke)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (ke.getID()) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case KeyEvent.KEY_PRESSED:
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (ke.getKeyChar() == &#39; &#39;) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isDown = true;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; repaint();
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case KeyEvent.KEY_RELEASED:
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ke.getKeyChar() == &#39; &#39;) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isDown = false;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int s = (state+1)%3;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setState(s);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (actionListeners.size() &amp;gt; 0) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ActionEvent ae = new ActionEvent(this,ke.getID(),&quot;Space Pressed on Button&quot;);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.fireActionEvent(ae);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;super.processKeyEvent(ke);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void processFocusEvent(FocusEvent fe)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (fe.getID()) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case FocusEvent.FOCUS_GAINED:
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hasFocus = true;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; repaint();
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case FocusEvent.FOCUS_LOST:
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hasFocus = false;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; repaint();
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public synchronized void addPropertyChangeListener(PropertyChangeListener pl)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;pcs.addPropertyChangeListener(pl);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public synchronized void addActionListener(ActionListener al)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;actionListeners.addElement(al);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public synchronized void removeActionListener(ActionListener al)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; actionListeners.removeElement(al);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public synchronized void removePropertyChangeListener(PropertyChangeListener pl)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;pcs.removePropertyChangeListener(pl);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public boolean isFocusTraversable()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void fireActionEvent(ActionEvent ae)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; java.util.Vector actionListenersClone;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;synchronized (this) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; actionListenersClone = (java.util.Vector)actionListeners.clone();
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i=0;i&amp;lt;actionListenersClone.size();i++)
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((ActionListener)actionListenersClone.elementAt(i)).actionPerformed(ae);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void setState(int state)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PropertyChangeEvent pce = new PropertyChangeEvent(this,&quot;state&quot;,new Integer(this.state),new Integer(state));
&amp;nbsp;&amp;nbsp; &amp;nbsp;pcs.firePropertyChange(pce);
&amp;nbsp;&amp;nbsp; &amp;nbsp;this.state = state;
&amp;nbsp;&amp;nbsp; &amp;nbsp;this.repaint();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getState()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return state;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; public void paint(Graphics g)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Graphics2D g2 = (Graphics2D)g;
&amp;nbsp;&amp;nbsp; &amp;nbsp;g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
&amp;nbsp;&amp;nbsp; &amp;nbsp;g2.setColor(getBackground());
&amp;nbsp;&amp;nbsp; &amp;nbsp;g2.fillRect(x,y,width,height);

&amp;nbsp;&amp;nbsp; &amp;nbsp;if (!isDown) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (hasFocus) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g2.draw3DRect(x+1,y+1,width-2,height-2,true);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; javax.swing.border.Border cb = BorderFactory.createEtchedBorder();
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cb.paintBorder(this,g,x,y,width,height);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;else {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.setColor(new Color(160,160,160));
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.fillRect(x,y,width,height);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.setColor(Color.white);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.drawRect(x,y,width-1,height-1);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.setColor(new Color(100,100,100));
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.drawRect(x,y,width-2,height-2);
&amp;nbsp;&amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp;if (state == 1) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.setStroke(new BasicStroke(width/MIN_WIDTH));
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; x = width/16;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.setColor(Color.black);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.drawLine(x+width/5+x/2,y+height/2+height/12,x+width/3,y+height-height/3);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.drawLine(x+width/3,y+height-height/3,x+width-width/3,y+height/3);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; x = 0;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;else if (state == 2) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (!hasFocus)
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = RAISED_OFFSET;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.setStroke(new BasicStroke(width/MIN_WIDTH));
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.setColor(Color.black);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.drawLine(x+width/3,y+height/3,x+width-width/3,y+height-height/3);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; g2.drawLine(x+width-width/3,y+height/3,x+width/3,y+height-height/3);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; x = 0;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getHeight()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return height;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void setHeight(int height)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (height &amp;gt; MIN_HEIGHT) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setPreferredSize(new Dimension(width,height));
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getWidth()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return width;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void setWidth(int width)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (width &amp;gt; MIN_WIDTH) {
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setPreferredSize(new Dimension(width,height));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public Dimension getPreferredSize()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new Dimension(width, height);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void setPreferredSize(Dimension d)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super.setPreferredSize(d);
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;this.height = d.height;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;this.width = d.width;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;revalidate();
&amp;nbsp;&amp;nbsp; &amp;nbsp;if (this.getParent() != null)
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.getParent().repaint();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; private void writeObject(ObjectOutputStream oos) throws IOException
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oos.defaultWriteObject();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ois.defaultReadObject();
&amp;nbsp;&amp;nbsp; &amp;nbsp;actionListeners = new java.util.Vector();
&amp;nbsp;&amp;nbsp; &amp;nbsp;pcs = new PropertyChangeSupport(this);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/702702975319858965/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2010/04/how-to-create-threestatebutton-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/702702975319858965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/702702975319858965'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2010/04/how-to-create-threestatebutton-in-java.html' title='How to create a ThreeStateButton in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-2831434043695614374</id><published>2010-01-18T11:32:00.002-08:00</published><updated>2012-04-22T01:57:08.015-07:00</updated><title type='text'>How to create JUnit test cases dynamically</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * @author Noman Naeem
 */
public class DynamicTestcase extends TestCase {

    private final static String dataPath = System.getProperty(&quot;test.data.dir&quot;);
    private ConfigData configData = null;

    public DynamicTestcase(String name, ConfigData configData) {
        super(name);
        this.configData = configData;
    }

    public static Test suite() throws Exception {

        TestSuite suite = new TestSuite(DynamicTestcase.class.getName());

        // loads the test Config
        List configsData = testConfigs(new File(dataPath));

        // create test cases for the test suite
        for (int i = 0; i &lt; configsData.size(); i++) {
            ConfigData configData = configsData.get(i);

            String testName = &quot;test&quot; + DynamicTestcase.class.getSimpleName()
                    + configData.getName();
            suite.addTest(new DynamicTestcase(testName, configData));
        }

        // create test setup for the test suite
        TestSetup setup = new TestSetup(suite) {
            /**
             * Setup paths called once during life cycle of the test suite
             */
            protected void setUp() throws Exception {
                // TODO: write the setup code here
            }

            /**
             * Cleanup and called once during life cycle of the test suite
             */
            protected void tearDown() throws Exception {
                // TODO: write the teardown code here
            }
        };

        return setup;
    }

    /**
     * Execute the test as configured for each test case
     * 
     * @throws Throwable
     * @see junit.framework.TestCase#runTest()
     */
    protected void runTest() throws Throwable {
        if (configData == null)
            throw new Exception(&quot;Cannot run with null config&quot;);

        //TODO: Write code here to process config for the given test case
        assertTrue(true);
    }

    /***************************************************************************
     * Loads configs from the given input dir
     * 
     * @param path
     *            The path to create the configs for
     * @return List configs to run the test cases on
     */
    private static List testConfigs(File path)
            throws FileNotFoundException {
        File[] inputFiles = null;
        List configs = new ArrayList();

        inputFiles = path.listFiles();

        for (int i = 0; i &lt; inputFiles.length; i++) {
            if (!inputFiles[i].isDirectory()) {
                // construct file name
                configs.add(new ConfigData(inputFiles[i]));
            }
        }

        return configs;
    }

    private static class ConfigData {
        private File inputFile;

        public ConfigData(File inputFile) {
            this.inputFile = inputFile;
        }

        public File getInputFile() {
            return inputFile;
        }

        /**
         * Extracts simple file name
         * 
         * @return The file name excluding the extension
         */
        public String getName() {
            String name = null;
            int index = inputFile.getName().lastIndexOf(&#39;.&#39;);
            if (index != -1) {
                name = inputFile.getName().substring(0, index);
            } else {
                name = inputFile.getName();
            }
            return name;
        }
    }
}

&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/2831434043695614374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2010/01/how-to-create-junit-test-cases.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/2831434043695614374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/2831434043695614374'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2010/01/how-to-create-junit-test-cases.html' title='How to create JUnit test cases dynamically'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-6455848517579614361</id><published>2008-10-15T22:44:00.001-07:00</published><updated>2011-06-12T23:33:07.745-07:00</updated><title type='text'>How to launch a native browser in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;import java.lang.reflect.Method;

/**
&amp;nbsp;* Launches a URL on system default browser. Works on Mac OS X, Windows XP, Unix
&amp;nbsp;* (Solaris) and GNU Linux Command line Usage: java BrowserLauncher URL
&amp;nbsp;* 
&amp;nbsp;*/
public class BrowserLauncher {

&amp;nbsp;&amp;nbsp;&amp;nbsp; private static final String errMsg = &quot;Error attempting to launch web browser&quot;;

&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String args[]) {

&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (args.length &amp;lt; 1) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.err.println(&quot;Usage: java BrowserLauncher URL&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.exit(-1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String url = args[0];

&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String osName = System.getProperty(&quot;os.name&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; try {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (osName.startsWith(&quot;Mac OS&quot;)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Class fileMgr = Class.forName(&quot;com.apple.eio.FileManager&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Method openURL = fileMgr.getDeclaredMethod(&quot;openURL&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; new Class[] { String.class });
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; openURL.invoke(null, new Object[] { url });
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } else if (osName.startsWith(&quot;Windows&quot;))
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Runtime.getRuntime().exec(
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;rundll32 url.dll,FileProtocolHandler &quot; + url);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else { // assume Unix or Linux
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String[] browsers = { &quot;firefox&quot;, &quot;opera&quot;, &quot;konqueror&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;epiphany&quot;, &quot;mozilla&quot;, &quot;netscape&quot; };
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String browser = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (int count = 0; count &amp;lt; browsers.length &amp;amp;&amp;amp; browser == null; count++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (Runtime.getRuntime().exec(
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; new String[] { &quot;which&quot;, browsers[count] })
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .waitFor() == 0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; browser = browsers[count];
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (browser == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; throw new Exception(&quot;Could not find web browser&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Runtime.getRuntime().exec(new String[] { browser, url });
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (Exception e) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.err.println(errMsg + &quot;:&quot; + e.getMessage());
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.exit(-1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/6455848517579614361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-launch-native-browser-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6455848517579614361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6455848517579614361'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-launch-native-browser-in-java.html' title='How to launch a native browser in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-6131193003114814653</id><published>2008-10-15T16:38:00.001-07:00</published><updated>2011-06-12T23:33:21.453-07:00</updated><title type='text'>How to print in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;import java.awt.*;
import javax.swing.*;
import java.awt.print.*;

public class PrintUtilities implements Printable {
&amp;nbsp; private Component componentToBePrinted;

&amp;nbsp; public static void printComponent(Component c) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; new PrintUtilities(c).print();
&amp;nbsp; }

&amp;nbsp; public PrintUtilities(Component componentToBePrinted) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; this.componentToBePrinted = componentToBePrinted;
&amp;nbsp; }

&amp;nbsp; public void print() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; PrinterJob printJob = PrinterJob.getPrinterJob();
&amp;nbsp;&amp;nbsp;&amp;nbsp; printJob.setPrintable(this);
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (printJob.printDialog())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printJob.print();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch(PrinterException pe) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&quot;Error printing: &quot; + pe);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }

&amp;nbsp; public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (pageIndex &amp;gt; 0) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(NO_SUCH_PAGE);
&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Graphics2D g2d = (Graphics2D)g;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; disableDoubleBuffering(componentToBePrinted);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; componentToBePrinted.paint(g2d);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; enableDoubleBuffering(componentToBePrinted);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(PAGE_EXISTS);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }

&amp;nbsp; /** The speed and quality of printing suffers dramatically if
&amp;nbsp;&amp;nbsp; *&amp;nbsp; any of the containers have double buffering turned on.
&amp;nbsp;&amp;nbsp; *&amp;nbsp; So this turns if off globally.
&amp;nbsp;&amp;nbsp; *&amp;nbsp; @see enableDoubleBuffering
&amp;nbsp;&amp;nbsp; */
&amp;nbsp; public static void disableDoubleBuffering(Component c) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; RepaintManager currentManager = RepaintManager.currentManager(c);
&amp;nbsp;&amp;nbsp;&amp;nbsp; currentManager.setDoubleBufferingEnabled(false);
&amp;nbsp; }

&amp;nbsp; /** Re-enables double buffering globally. */

&amp;nbsp; public static void enableDoubleBuffering(Component c) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; RepaintManager currentManager = RepaintManager.currentManager(c);
&amp;nbsp;&amp;nbsp;&amp;nbsp; currentManager.setDoubleBufferingEnabled(true);
&amp;nbsp; }
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/6131193003114814653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-print-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6131193003114814653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6131193003114814653'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-print-in-java.html' title='How to print in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-8887411541912550859</id><published>2008-10-15T15:56:00.001-07:00</published><updated>2011-06-12T23:33:34.804-07:00</updated><title type='text'>How to write a file downloader in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

public class Downloader
&amp;nbsp;&amp;nbsp;&amp;nbsp; implements java.lang.Runnable
{

&amp;nbsp;&amp;nbsp;&amp;nbsp; public Downloader(java.net.URL url, java.io.File destination)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length = -1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; progress = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thread = new Thread(this);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.url = url;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file = destination;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void run()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; java.io.InputStream in = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; java.io.OutputStream out = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; java.net.URLConnection connection = url.openConnection();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in = connection.getInputStream();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out = new FileOutputStream(file);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte data[] = new byte[4096];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length = connection.getContentLength();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int total;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!stop &amp;amp;&amp;amp; (total = in.read(data)) &amp;gt; 0) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out.write(data, 0, total);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; progress += total;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (java.lang.Exception e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in.close();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out.close();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (java.lang.Exception e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (stop)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (file.exists())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file.delete();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (java.lang.Exception e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void start()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop = false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thread.start();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void join()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thread.join();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (java.lang.InterruptedException e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.printStackTrace();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public void cancel()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getLength()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return length;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getProgress()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return progress;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public int getProgressInPercent()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (int)(((double)progress / (double)length) * 100D);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public boolean completed()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return !thread.isAlive() &amp;amp;&amp;amp; progress == length;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public boolean stopped()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return !thread.isAlive() &amp;amp;&amp;amp; stop;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; private java.net.URL url;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private java.io.File file;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private int length;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private int progress;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private java.lang.Thread thread;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private boolean stop;
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/8887411541912550859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-write-file-downloader-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/8887411541912550859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/8887411541912550859'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-write-file-downloader-in-java.html' title='How to write a file downloader in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-3133067407170076234</id><published>2008-10-15T15:54:00.001-07:00</published><updated>2011-06-26T23:17:40.016-07:00</updated><title type='text'>How to get System Icon in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;public Icon getSystemIcon(File f) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; try {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (f != null) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShellFolder sf = ShellFolder.getShellFolder(f);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Image img = sf.getIcon(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (img != null) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new ImageIcon(img, sf.getFolderType());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return UIManager.getIcon(f.isDirectory() ?
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;FileView.directoryIcon&quot; :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;FileView.fileIcon&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (FileNotFoundException ex) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return null;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/3133067407170076234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-get-system-icon-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/3133067407170076234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/3133067407170076234'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-get-system-icon-in-java.html' title='How to get System Icon in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-6815596417073781120</id><published>2008-10-15T15:49:00.001-07:00</published><updated>2011-06-12T23:34:02.409-07:00</updated><title type='text'>How to print DataTable and DataView</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre name=&quot;code&quot; class=&quot;c#&quot;&gt;public void PrintTable(DataTable table)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int j = 0; j &amp;lt; table.Columns.Count; j++)
&amp;nbsp;&amp;nbsp; &amp;nbsp;Console.Write(&quot;{0,-20}&quot;, table.Columns[j].ColumnName);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine();
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; table.Rows.Count; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp; &amp;nbsp;for (int j = 0; j &amp;lt; table.Columns.Count; j++)
&amp;nbsp;&amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.Write(&quot;{0,-20}&quot;,table.Rows[i][j]);
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;Console.WriteLine();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}

private void PrintView(DataView view)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int j = 0; j &amp;lt; view.Table.Columns.Count; j++)
&amp;nbsp;&amp;nbsp; &amp;nbsp;Console.Write(&quot;{0,-15}&quot;, view.Table.Columns[j].ColumnName);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine();
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; //loop thru the dataview
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; view.Table.Rows.Count; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp; &amp;nbsp;for (int j = 0; j &amp;lt; view.Table.Columns.Count; j++)
&amp;nbsp;&amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.Write(&quot;{0,-15}&quot;, view[i][j]);
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;Console.WriteLine();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/6815596417073781120/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-print-datatable-and-dataview.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6815596417073781120'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/6815596417073781120'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-print-datatable-and-dataview.html' title='How to print DataTable and DataView'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-1259194395996647410</id><published>2008-10-15T15:42:00.001-07:00</published><updated>2011-06-12T23:34:14.564-07:00</updated><title type='text'>How to create update command from a DataTable</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;pre name=&quot;code&quot; class=&quot;c#&quot;&gt;protected override DbCommand GetUpdateCommand(DataTable changedRecords)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; StringBuilder query = new StringBuilder(string.Format(&quot;UPDATE {0} SET &quot;,changedRecords.TableName));
&amp;nbsp;&amp;nbsp;&amp;nbsp; List&lt;datacolumn&gt; primary = new List&lt;datacolumn&gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp; primary.AddRange(changedRecords.PrimaryKey);

&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; changedRecords.Columns.Count; i++ )
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; DataColumn column = changedRecords.Columns[i];

&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!primary.Contains(column))
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; query.Append(column.ColumnName + &quot;=@&quot; + column.ColumnName);

&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (i &amp;lt; changedRecords.Columns.Count - changedRecords.PrimaryKey.Length - 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; query.Append(&quot; ,&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; query.Append(&quot; WHERE &quot;);

&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; changedRecords.PrimaryKey.Length; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; DataColumn column = changedRecords.PrimaryKey[i];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; query.Append(column.ColumnName + &quot;=@&quot; + column.ColumnName);

&amp;nbsp;&amp;nbsp;&amp;nbsp; if (i &amp;lt; changedRecords.PrimaryKey.Length - 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; query.Append(&quot; ,&quot;);

&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; SqlCommand command = new SqlCommand(query.ToString());
&amp;nbsp;&amp;nbsp;&amp;nbsp; command.UpdatedRowSource = UpdateRowSource.None;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return command;
}&lt;/datacolumn&gt;&lt;/datacolumn&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/1259194395996647410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-create-update-command-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/1259194395996647410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/1259194395996647410'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-create-update-command-from.html' title='How to create update command from a DataTable'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-669387322525726234</id><published>2008-10-15T14:13:00.001-07:00</published><updated>2011-06-12T23:34:29.075-07:00</updated><title type='text'>How to convert uchar to ubyte in java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;//assume a 16bit value with MSB unsigned
private byte[] encodeUInt8Chars(char[] uchars){

ByteArrayOutputStream stream;
int ui;

stream = new ByteArrayOutputStream();
for(int i=0; i&amp;lt;uchars.length; i++){
ui = uchars[i]&amp;amp;0xFF;    //mask to use the signed bit of int                    
stream.write(ui);
}

return stream.toByteArray();
}

//assume a 8 bit value with MSB being unsigned(was used by the above method)
private char[] decodeUInt8Chars(byte[] uint8){   

CharArrayWriter writer = new CharArrayWriter();
int uc;

for(int i=0; i&amp;lt;uint8.length; i++){
uc = uint8[i]&amp;amp;0xFF;
writer.write(uc);   
}

return writer.toCharArray();
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/669387322525726234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-convert-uchar-to-ubyte-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/669387322525726234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/669387322525726234'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-convert-uchar-to-ubyte-in-java.html' title='How to convert uchar to ubyte in java'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6250349018455583359.post-1121436769480011623</id><published>2008-10-15T13:07:00.002-07:00</published><updated>2012-05-29T16:39:29.984-07:00</updated><title type='text'>How to save/load JTable settings</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;Preamble&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This articles will show how to save JTable preferences as per user preferences.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;JDK and eclipse compatibility&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JDK version 1.3 with eclipse 3.3 is the minimum requirement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Project overview&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The downloadable zip file contains an eclipse project which has a MainFrame class for GUI. By modifying the size of the colums and doing a rerun will create a new Table which will have the saved preferences from the last run.&lt;br /&gt;
&lt;br /&gt;
To save the preferences click the save button or the save menu item. The next load will have the changes reflected.   Unzip the downloadable and load in the eclipse project. Make a run configuration for MainFrame class and you are all set.&lt;br /&gt;
&lt;br /&gt;
Enjoy, if you like it please appreciate!&lt;br /&gt;
&lt;br /&gt;
The snippet below is for sample usage.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;table = new StarkTable(data, columnNames);
table.setName(&quot;Prefs table&quot;);
JTablePrefsPersister prefsTable = JTablePrefsPersister.getInstance();
prefsTable.loadPreferences(System.getProperty(&quot;user.home&quot;)
    + File.separator + &quot;table.pref&quot;);
prefsTable.registerTable(table);
contentPane.add(new JScrollPane(table), BorderLayout.CENTER);
&lt;/pre&gt;&lt;/div&gt;</content><link rel='enclosure' type='application/zip' href='https://docs.google.com/open?id=0BxtsUP_AjE20WE9HVUw5UFJiaVE' length='0'/><link rel='replies' type='application/atom+xml' href='http://excerptsworld.blogspot.com/feeds/1121436769480011623/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-saveload-jtable-settings_15.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/1121436769480011623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6250349018455583359/posts/default/1121436769480011623'/><link rel='alternate' type='text/html' href='http://excerptsworld.blogspot.com/2008/10/how-to-saveload-jtable-settings_15.html' title='How to save/load JTable settings'/><author><name>Noman Naeem</name><uri>http://www.blogger.com/profile/04118278485693067796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>