Friday 30 August 2013

Swing: Drawing Arcs Between Adjacent Edges of Triangle






import javax.swing.JComponent;
import javax.swing.JFrame;
import java.awt.geom.*;
import java.awt.*;
import java.util.*;

class MyCanvas extends JComponent {
    int a, supb, b, c, length, r;
    double x1, y1, x2, y2, x3, y3;
    Random random = new Random();

    public MyCanvas() {
            a = random.nextInt(80 - 30) + 30;
            supb = random.nextInt(120 - 70) + 100;
            b = 180 - supb;
            c = 180 - a - b;
            length = random.nextInt(150 - 100) + 100;
            x1 = 0;
            y1 = 0;
            r = 20;
            x2 = x1 + length;
            y2 = y1;
            x3 = (x1 + Math.cos(Math.toRadians(-a)) * length);
            y3 = (y1 + Math.sin(Math.toRadians(-a)) * length);
    }

    public void paintComponent(Graphics g2) {
            float dx1, dy1, ang1, dx2, dy2, ang2, ang3;
            Graphics2D g = (Graphics2D) g2;
            AffineTransform oldt = g.getTransform();

            Shape shape = getTriangle(x1, y1, x2, y2, x3, y3);

            Rectangle2D bounds = shape.getBounds2D();

            double height = bounds.getHeight();
            double width = bounds.getWidth();
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
            g.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_BUTT,
                            BasicStroke.JOIN_BEVEL));
            g.translate((this.getWidth() - width) / 2,
                            (this.getHeight() - height) / 2);
            g.translate(-bounds.getX(), -bounds.getY());

            dy1 = (float) (y3 - y1);
            dx1 = (float) (x3 - x1);
            ang1 = (float) (Math.atan((float)(dy1 / dx1)) * 180 / Math.PI);

            ang1 = (float) Math.abs(ang1);

            dy2 = (float) (y2 - y3);
            dx2 = (float) (x2 - x3);
            ang2 = (float) (Math.atan((float)(dy2 / dx2)) * 180 / Math.PI);

            ang2 = (float) Math.abs(ang2);

    ang3 = (float) (180-ang2-ang1);

            g.setColor(Color.BLACK);
            g.draw(shape);
            g.setColor(Color.RED);
            g.draw(new Arc2D.Double(x1 - r, y1 - r, 2 * r, 2 * r, 0, ang1, Arc2D.OPEN));
            g.setColor(Color.GREEN);
            g.draw(new Arc2D.Double(x2 - r, y2 - r, 2 * r, 2 * r, (180 - ang2), ang2,
                            Arc2D.OPEN));
            g.setColor(Color.RED);
            g.draw(new Arc2D.Double(x3 - r, y3 - r, 2 * r, 2 * r, -180 + a, ang3,
                            Arc2D.OPEN));
            g.setTransform(oldt);
    }

    private Shape getTriangle(double x1, double y1, double x2, double y2,
                    double x3, double y3) {
            GeneralPath gp = new GeneralPath();
            gp.moveTo(x1, y1);
            gp.lineTo(x2, y2);
            gp.lineTo(x3, y3);
            gp.closePath();
            return gp;
    }
}

public class TrianglePanel {
        public static void main(String[] a) {
                JFrame window = new JFrame();
                window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                window.setBounds(30, 30, 300, 300);
                window.getContentPane().add(new MyCanvas());
                window.setVisible(true);
        }
}

How JSP Life-cycle work


JAVAFX: Draw polygon by mouse click and re-size shape by anchor points







Thursday 29 August 2013

No Image Reader of class com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader available for format:jpeg

we have to modify the $DCM4CHEE_HOME/server/default/lib/dcm4che.jar file (expand it), in particular the

org/dcm4cheri/image/ImageReaderFactory.properties

file, changing the lines with "com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader" with
"com.sun.imageio.plugins.jpeg.JPEGImageReader".
Same thing with the ImageWriterFactory.properties with "com.sun.imageio.plugins.jpeg.JPEGImageWriter"

After that, we have to create the new dcm4che.jar file using this command (run it in the folder containing the dcm4che.jar files previously extracted):

jar cvf dcm4che.jar *

Sobstitute the old jar file with the new one.
Start the server and wado service works with the web interface!

That's all!

Monday 26 August 2013

Listing DICOM Header information with dcm4che 2

Hi All,

Some readers have asked me questions regarding how to access DICOM header information by DICOM Tag parameters. On this post I present you a quick tutorial on how to list all header information, including the Tag value, VR (value representation), Tag description, and the values of each field using the great dcm4che 2 toolkit.

(0008,0005) [CS] Specific Character Set [ISO_IR 100]
(0008,0008) [CS] Image Type [ORIGINAL]
(0008,0016) [UI] SOP Class UID [1.2.840.10008.5.1.4.1.1.2]
(0008,0020) [DA] Study Date [20040827]
(0008,0021) [DA] Series Date [20040827]
(0008,0022) [DA] Acquisition Date [20040827]
(0008,0023) [DA] Content Date [20040827]
(0008,0030) [TM] Study Time [100357.953000]
(0008,0031) [TM] Series Time [100607.062000]
(0008,0032) [TM] Acquisition Time [100622.688476]
(0008,0033) [TM] Content Time [100622.688476]
(0008,0050) [SH] Accession Number [null]
(0008,0060) [CS] Modality [CT]
(0008,0070) [LO] Manufacturer [SIEMENS]

Like the previous posts, we start coding a simple class with the default constructor. Let's name itListDicomHeader.


public class ListDicomHeader {

   public ListDicomHeader() {
      // TODO Auto-generated method stub
   }
   
   public static void main(String[] args) {
      // TODO Auto-generated method stub
   }
}

The next step is to code the method responsible for extracting the header info. Note that this method is recursive. This is done because some DICOM files bring encoded Items that may hold other DICOM objects denoted by de value representation SQ. So, we are handling also sequence information with this code. The method is written as follows:


public void listHeader(DicomObject object) {
   Iterator iter = object.datasetIterator();
   while(iter.hasNext()) {
      DicomElement element = iter.next();
      int tag = element.tag();
      try {
         String tagName = object.nameOf(tag);
         String tagAddr = TagUtils.toString(tag);
         String tagVR = object.vrOf(tag).toString();
         if (tagVR.equals("SQ")) {
            if (element.hasItems()) {
               System.out.println(tagAddr +" ["+  tagVR +"] "+ tagName);
               listHeader(element.getDicomObject());
               continue;
            }
         }    
         String tagValue = object.getString(tag);    
         System.out.println(tagAddr +" ["+ tagVR +"] "+ tagName +" ["+ tagValue+"]");
      } catch (Exception e) {
         e.printStackTrace();
      }
   }  
}

Looking at the code, first we get an iterator to go through our DICOM dataset. Then we code a while loop to get each DICOM element present in the header. At each iteration a new DicomElement is kept so we can access its values. The tag variable holds the current Tag value. From then on there are some useful functions that may help us a lot. We can use the nameOf method fromDicomObject class to get the Tag description as a String. I also suggest you to have a look at the TagUtils class for other great functions. The vrOf function will return the value representation to the current element. 


Then comes the recursive part. We test the VR to see if it's a sequence (SQ), if so then we check if this element has any Items. Then if the answer is true we get the new object and call thelistHeader function again, starting the recursive loop. Each iteration then prints out the desired information.

Finally, to test this program we must a main method for this class. The method may be written as follows:


public static void main(String[] args) {
   DicomObject object = null;  
   try {
      DicomInputStream dis = new DicomInputStream(new File("c:/image.dcm"));
      object = dis.readDicomObject();
      dis.close();
   } catch (Exception e) {
      System.out.println(e.getMessage());
      System.exit(0);
   }
   ListDicomHeader list = new ListDicomHeader();
   list.listHeader(object);
}


That's it! Now we have a lot of information from our DICOM file header! Enjoy :)

Styling FX Buttons with CSS

A number of people have asked me recently can I create this look or that look using CSS in JavaFX. Or they have said that you could never do that! So I thought I would do a little experiment and try recreating a bunch of common button styles purely using CSS. So without further ado, here is the result:


Friday 16 August 2013

Argo - Themeforest Modern OnePage Metro UI Wordpress Theme






ARGO is a unique and creative Wordpress Theme with clean and modern design. It is perfect choice for your corporate agency, creative studio or for portfolio. It can be customized easily to suit your wishes.

Demo: http://themeforest.net/item/argo-modern-onepage-metro-ui-wordpress-theme/4589714

http://www.hotfiles.ro/download/argo112.rar/918760
http://www.mirrorcreator.com/files/RNDNWKKC/argo112.rar_links
http://dfiles.eu/files/xs301nq3m
http://www.myuplbox.com/file/download/858280
http://www10.zippyshare.com/v/62427134/file.html
http://www.share-byte.net/9fUMHI
http://www.nowdownload.eu/dl/7ahbqynryu2bh
http://www.upl.me/oAo7rn
http://ul.to/h7mq2xnr

Start – Metro UI Themeforest Responsive Admin Template

Start is a new responsive admin template based on latest Windows 8 interface. This one, called Metro UI, has its roots in the design principles of classic Swiss graphic design – minimal, bold, high contrast and flat colors are some of its great features.

http://www.hotfiles.ro/download/startmetro.rar/823962
http://www.mirrorcreator.com/files/L8ID7ZA3/startmetro.rar_links
http://dfiles.eu/files/gr19dol9r
http://www.myUplBox.com/file/download/751843
http://www72.zippyshare.com/v/76904331/file.html
http://www.upl.me/T3pnwy
http://www.share-byte.net/xxM1xC

JDBC - CallableStatement Object Example

Following is the example which makes use of CallableStatement along with the followinggetEmpName() MySQL stored procedure:
Make sure you have created this stored procedure in your EMP Database. You can use MySQL Query Browser to get it done.
DELIMITER $$

DROP PROCEDURE IF EXISTS
`EMP`.`getEmpName` $$
CREATE PROCEDURE
`EMP`.`getEmpName`
(IN EMP_ID INT, OUT EMP_FIRST VARCHAR(255))
BEGIN
SELECT first INTO EMP_FIRST
FROM
Employees
WHERE ID
= EMP_ID;
END $$

DELIMITER
;
This sample code has been written based on the environment and database setup done in previous chapters.
Copy and past following example in JDBCExample.java, compile and run as follows:
//STEP 1. Import required packages
import java.sql.*;

public class JDBCExample {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/EMP";

// Database credentials
static final String USER = "username";
static final String PASS = "password";

public static void main(String[] args) {
Connection conn = null;
CallableStatement stmt = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn
= DriverManager.getConnection(DB_URL,USER,PASS);

//STEP 4: Execute a query
System.out.println("Creating statement...");
String sql = "{call getEmpName (?, ?)}";
stmt
= conn.prepareCall(sql);

//Bind IN parameter first, then bind OUT parameter
int empID = 102;
stmt
.setInt(1, empID); // This would set ID as 102
// Because second parameter is OUT so register it
stmt
.registerOutParameter(2, java.sql.Types.VARCHAR);

//Use execute method to run stored procedure.
System.out.println("Executing stored procedure..." );
stmt
.execute();

//Retrieve employee name with getXXX method
String empName = stmt.getString(2);
System.out.println("Emp Name with ID:" +
empID
+ " is " + empName);
stmt
.close();
conn
.close();
}catch(SQLException se){
//Handle errors for JDBC
se
.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e
.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt
.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn
.close();
}catch(SQLException se){
se
.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end JDBCExample
Now let us compile above example as follows:
C:\>javac JDBCExample.java
C
:\>
When you run JDBCExample, it produces following result:
C:\>java JDBCExample
Connecting to database...
Creating statement...
Executing stored procedure...
Emp Name with ID:102 is Zaid
Goodbye!
C
:\>

JDBC - PreparedStatement Object Example

Following is the example which makes use of PreparedStatement along with opening and closing statments:
This sample code has been written based on the environment and database setup done in previous chapters.
Copy and past following example in JDBCExample.java, compile and run as follows:
//STEP 1. Import required packages
import java.sql.*;

public class JDBCExample {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/EMP";

// Database credentials
static final String USER = "username";
static final String PASS = "password";

public static void main(String[] args) {
Connection conn = null;
PreparedStatement stmt = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn
= DriverManager.getConnection(DB_URL,USER,PASS);

//STEP 4: Execute a query
System.out.println("Creating statement...");
String sql = "UPDATE Employees set age=? WHERE id=?";
stmt
= conn.prepareStatement(sql);

//Bind values into the parameters.
stmt
.setInt(1, 35); // This would set age
stmt
.setInt(2, 102); // This would set ID

// Let us update age of the record with ID = 102;
int rows = stmt.executeUpdate();
System.out.println("Rows impacted : " + rows );

// Let us select all the records and display them.
sql
= "SELECT id, first, last, age FROM Employees";
ResultSet rs = stmt.executeQuery(sql);

//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last");

//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
//STEP 6: Clean-up environment
rs
.close();
stmt
.close();
conn
.close();
}catch(SQLException se){
//Handle errors for JDBC
se
.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e
.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt
.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn
.close();
}catch(SQLException se){
se
.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end JDBCExample
Now let us compile above example as follows:
C:\>javac JDBCExample.java
C
:\>
When you run JDBCExample, it produces following result:
C:\>java JDBCExample
Connecting to database...
Creating statement...
Rows impacted : 1
ID
: 100, Age: 18, First: Zara, Last: Ali
ID
: 101, Age: 25, First: Mahnaz, Last: Fatma
ID
: 102, Age: 35, First: Zaid, Last: Khan
ID
: 103, Age: 30, First: Sumit, Last: Mittal
Goodbye!
C
:\>