Kalaimaan

Doing simple things to make great life

Posts Tagged ‘Java’

Patterns in JAVA (Design Patterns)

Posted by kalaimaan on February 11, 2009

Creational Patterns

Type of Patterns

1. Creational Patterns

  • The Factory Pattern

  • The Abstract Factory Pattern

  • The Singleton Pattern

  • The Builder Pattern

  • The Prototype Pattern

2. Structural Patterns

  • The Adapter Pattern

  • The Bridge Pattern

  • The Composite Pattern

  • The Decorator Pattern

  • The Façade Pattern

  • The Flyweight Pattern

  • The Proxy Pattern

3. Behavioral Patterns

  • The Command Pattern

  • The Interpreter Pattern

  • The Iterator Pattern

  • The Mediator Pattern

  • The Memento Pattern

  • The Observer Pattern

  • The State Pattern

  • The Strategy Pattern

  • The Template Pattern

  • The Visitor Pattern

Creational Patterns
All of the creational patterns deal with the best way to create instances of objects. This is important because your program should not depend on how objects are created and arranged. In Java, of course, the simplest way to create an instance of an object is by using the new operator.

Fred = new Fred(); //instance of Fred class

However, this really amounts to hard coding, depending on how you create the object within your program. In many cases, the exact nature of the object that is created could vary with the needs of the program and abstracting the creation process into a special “creator” class can make your program more flexible and general.

The Factory Method provides a simple decision making class that returns one of several possible subclasses of an abstract base class depending on the data that are provided.

The Abstract Factory Method provides an interface to create and return one of several families of related objects.

The Builder Pattern separates the construction of a complex object from its representation, so that several different representations can be created depending on the needs of the program.

The Prototype Pattern starts with an initialized and instantiated
class and copies or clones it to make new instances rather than creating new
instances.

The Singleton Pattern is a class of which there can be no more than
one instance. It provides a single global point of access to that instance.

Structural Patterns
Structural patterns describe how classes and objects can be combined to form larger structures. The difference between class patterns and object patterns is that class patterns describe how inheritance can be used to provide more useful program interfaces. Object patterns, on the other hand, describe how objects can be composed into larger structures using object composition, or the inclusion of objects within other objects.

The Adapter pattern, used to change the interface of one class to that of another one.

The Bridge pattern, intended to keep the interface to your client program constant while allowing you to change the actual kind of class you display or use. You can then change the interface and the underlying class separately.

The Composite pattern, a collection of objects, any one of which may be either itself a Composite, or just a primitive object.

The Decorator pattern, a class that surrounds a given class, adds new capabilities to it, and passes all the unchanged methods to the underlying class.

The Façade pattern, which groups a complex object hierarchy and provides a new, simpler interface to access those data.

The Flyweight pattern, which provides a way to limit the proliferation of small, similar class instances by moving some of the class data outside the class and passing it in during various execution methods.

The Proxy pattern, which provides a simple place-holder class for a more complex class which is expensive to instantiate.

Behavioral Patterns
Behavioral patterns are those patterns that are most specifically concerned with communication between objects.

The Observer pattern defines the way a number of classes can be notified of a change,

The Mediator defines how communication between classes can be simplified by using another class to keep all classes from having to know about each other. The Chain of Responsibility allows an even further decoupling between classes, by passing a request between classes until it is recognized.

The Template pattern provides an abstract definition of an algorithm.

The Interpreter provides a definition of how to include language elements in a program.

The Strategy pattern encapsulates an algorithm inside a class

The Visitor pattern adds function to a class

The State pattern provides a memory for a class’s instance variables.

The Command pattern provides a simple way to separate execution of a command from the interface environment that produced it.

The Iterator pattern formalizes the way we move through a list of data within a class.

Posted in Java, Patterns | Tagged: , , | Leave a Comment »

Calendar properties for Excange server (EWS) java

Posted by kalaimaan on February 11, 2009

The calendar have the follwoing properties to create the appointment (Type of Appointment)

1. Simple Appointment (Required fields)

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • set the Reminder
2. Appointment with Meeting  (Required fields)

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Optional Attendee
  • Required Attendee
  • set the Reminder
Recurrency Appointment : Reflecting the appointment by the given condition in the format of( daily, monthly , Yearly, Weekly) and the required input fields are given below
3. Appointment with Recurrency (Daily).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Set Recurrence type (Daily)
  • Set Intervals ( it is make the interval for the each interval)
  • set Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number Of occurrence ( set the number of repetition of appointment in the consecutive intervals)
4. Appointment with Recurrency (Weekly).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Set the Recurrence type (Weekly)
  • Set the Intervals ( it is make the interval for the each interval)
  • set the day of week list (like monday, wednesday)
  • set the Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number of occurrence ( set the number of repetition of appointment in the consecutive intervals)
5. Appointment with Recurrency  (monthly).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Set the Recurrence type (monthly)
  • Set the Intervals ( it is make the interval for the each interval)
  • set the day of month
  • set the Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number of occurrence ( set the number of repetition of appointment in the consecutive intervals)
6. Appointment with Recurrency  (yearly).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Set the Recurrence type (monthly)
  • set month
  • set the day of month
  • set the Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number of occurrence ( set the number of repetition of appointment in the consecutive intervals)
Recurrency Appointment with meeting:

7. Appointment with Recurrency and meeting (Daily).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Optional Attendee
  • Required Attendee
  • Set Recurrence type (Daily)
  • Set Intervals ( it is make the interval for the each interval)
  • set Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number Of occurrence ( set the number of repetition of appointment in the consecutive intervals)
8. Appointment with Recurrency and meeting (Weekly).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Optional Attendee
  • Required Attendee
  • Set the Recurrence type (Weekly)
  • Set the Intervals ( it is make the interval for the each interval)
  • set the day of week list (like monday, wednesday)
  • set the Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number of occurrence ( set the number of repetition of appointment in the consecutive intervals)
9. Appointment with Recurrency and meeting  (monthly).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Optional Attendee
  • Required Attendee
  • Set the Recurrence type (monthly)
  • Set the Intervals ( it is make the interval for the each interval)
  • set the day of month
  • set the Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number of occurrence ( set the number of repetition of appointment in the consecutive intervals)
10. Appointment with Recurrency and meeting  (yearly).

  • Subject
  • Body of the text
  • Start Date
  • End Date
  • priority (Option)
  • Optional Attendee
  • Required Attendee
  • Set the Recurrence type (monthly)
  • set month
  • set the day of month
  • set the Recurrency start date ( it the mention the date for the recurrency start)
  • Set the Number of occurrence ( set the number of repetition of appointment in the consecutive intervals)

Posted in Exchange Server | Tagged: , , , , | Leave a Comment »

Group and UNGroup the selected element

Posted by kalaimaan on January 28, 2009

Hi Friends,

This is the first post in this blog and i like to share my technical information with you all

The post is related to JGraph and How are could insert, delete , group and ungroup the element in JGraph

We can use the jgraph for mutipurpose. here i am sharing the small bit

Example 1:

public class GUGSample extends JFrame implements ActionListener
{
protected JGraph jGraph = null;
protected DefaultGraphModel jGraphModel = null;

private JButton btnInsert = null;
private JButton btnDelete = null;
private JButton btnGroup = null;
private JButton btnUnGroup = null;

private static int cNum = 0;

private static int gNum = 0;

private HashMap<String, DefaultGraphCell> allCellList = new HashMap<String, DefaultGraphCell>();

private HashMap<String, DefaultGraphCell> groupList = new HashMap<String, DefaultGraphCell>();

public GUGSample()
{
super(“JGraph Demo-kalaimaan”);
initGraph();
}

/**
*
*/
private void initGraph()
{
jGraphModel = new DefaultGraphModel();
jGraph = new JGraph(jGraphModel);

jGraph.setGridColor(Color.lightGray);
jGraph.setGridMode(JGraph.LINE_GRID_MODE);
jGraph.setGridSize(20);
jGraph.setGridEnabled(true);
jGraph.setGridVisible(true);
jGraph.setHandleColor(Color.red);
jGraph.setSelectionEnabled(true);

setLayout(new BorderLayout());

addGraphLayout();
setSize(600, 600);
setVisible(true);
}

/**
*
*/
private void addGraphLayout()
{
jGraphModel.addGraphModelListener(new GraphMode());
add(toolButton(), BorderLayout.NORTH);
add(jGraph, BorderLayout.CENTER);

}

/**
*
* @return
*/
private JPanel toolButton()
{
JPanel temp = new JPanel();
btnInsert = new JButton(“Insert”);
btnInsert.setPreferredSize(new Dimension(100, 25));
btnInsert.addActionListener(this);
temp.add(btnInsert);

btnDelete = new JButton(“Delete”);
btnDelete.setPreferredSize(new Dimension(100, 25));
btnDelete.addActionListener(this);
temp.add(btnDelete);

btnGroup = new JButton(“Group”);
btnGroup.setPreferredSize(new Dimension(100, 25));
btnGroup.addActionListener(this);
temp.add(btnGroup);

btnUnGroup = new JButton(“UnGroup”);
btnUnGroup.setPreferredSize(new Dimension(100, 25));
btnUnGroup.addActionListener(this);
temp.add(btnUnGroup);

return temp;
}

public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
e.printStackTrace();
}
GUGSample gug = new GUGSample();
gug.setDefaultCloseOperation(EXIT_ON_CLOSE);
}

@Override
public void actionPerformed(ActionEvent e)
{
String action = e.getActionCommand();

if (action.equalsIgnoreCase(“Insert”))
insertElement();
else if (action.equalsIgnoreCase(“Delete”))
deleteElement();
else if (action.equalsIgnoreCase(“Group”))
groupElements();
else if (action.equalsIgnoreCase(“UnGroup”))
unGroupElements();
}

/**
*
*/
private void insertElement()
{
String cn = cellNumber();
DefaultGraphCell cell = new DefaultGraphCell(cn);

AttributeMap map = new AttributeMap();
Rectangle rec = new Rectangle(20, 20 , 100,50);
GraphConstants.setBounds(map, rec);
GraphConstants.setGradientColor(map, Color.yellow.brighter());
GraphConstants.setBorderColor(map, Color.blue);
GraphConstants.setBackground(map, Color.white);
GraphConstants.setSizeableAxis(map, 3);
GraphConstants.setOpaque(map, true);
GraphConstants.setEditable(map, false);
cell.setAttributes(map);

jGraph.getGraphLayoutCache().insert(cell);
allCellList.put(cn, cell);
}

/**
*
*/
private void deleteElement()
{
Object[] object = jGraph.getSelectionCells();
for(Object obj : object)
{
if(obj==null)
continue;

String key =  ((DefaultGraphCell)obj).getUserObject().toString();
allCellList.remove(key);
groupList.remove(key);
jGraph.getGraphLayoutCache().remove(new Object[] {obj});
}

}

private void groupElements()
{
Object[] object = jGraph.getSelectionCells();
String gn = groupNumber();

DefaultGraphCell groupCell = new DefaultGraphCell(gn);
AttributeMap map = new AttributeMap();
Rectangle rec = new Rectangle(20, 20 , 100,50);
GraphConstants.setBounds(map, rec);
GraphConstants.setGradientColor(map, Color.white.darker());
GraphConstants.setGroupOpaque(map, true);
GraphConstants.setBorderColor(map, Color.GREEN.darker());
GraphConstants.setDashOffset(map, 2);
GraphConstants.setBackground(map, Color.white);
GraphConstants.setSizeableAxis(map, 3);
GraphConstants.setOpaque(map, true);
GraphConstants.setEditable(map, false);
groupCell.setAttributes(map);

jGraph.getGraphLayoutCache().insertGroup(groupCell, object);
groupList.put(gn, groupCell);

jGraph.clearOffscreen();
}

private void unGroupElements()
{
Object[] object = jGraph.getSelectionCells();
for(Object obj : object)
{
DefaultGraphCell cell = (DefaultGraphCell) obj;
if(cell!=null && cell.getParent()!=null)
{
DefaultGraphCell groupCell = (DefaultGraphCell)cell.getParent();
int childCount =  groupCell.getChildCount();
groupCell.remove(cell);
jGraph.getGraphLayoutCache().ungroup(new Object[]{cell});
jGraph.getGraphLayoutCache().insert(cell);

if(childCount==2)
{
groupList.remove(groupCell.getUserObject().toString());
jGraph.getGraphLayoutCache().remove(new Object[] {cell});
}
}
}

jGraph.clearOffscreen();
}

private String cellNumber()
{
return “Cell-” + cNum++;
}

private String groupNumber()
{
return “Group-” + gNum++;
}

private class GraphMode implements GraphModelListener
{
@Override
public void graphChanged(GraphModelEvent e)
{
jGraph.clearOffscreen();
}
}
}

Sample screen shot

gug-picture1

Posted in JGraph | Tagged: , , , , | Leave a Comment »