SwiftGantt development tutorials
##### Jar files(find in SwiftGantt distribution) that SwiftGantt component requires are: commons-collections-3.2.jar commons-lang-2.2.jar commons-io-1.3.2.jar log4j-1.2.15.jar swiftcommon-0.3.x.jar swiftgantt-0.3.x.jar
<1>. SwiftGantt getting started. ##### Here are some common approaches for using SwiftGantt, you can have simple Gantt Chart step by step. 1. Construct the main class com.yuxingwang.gantt.GanttChart of SwiftGantt first, which is inherited from Swing component javax.swing.JScrollPanel. GanttChart gantt = new GanttChart(); 2. Set time unit of Gantt Chart. If the time unit is Week, it means each scale in the time axis is stand for one week: gantt.setTimeUnit(TimeUnit.Week); 3. you can decorate you Gantt Chart through the configuration class "Config", by setting the color, width, height for elements in Gantt Chart. Since version 0.3.0, you can set the span of working days in each week and span of working hours in each day. See more detail in the API documentation. Config config = gantt.getConfig(); config.setWorkingTimeBackColor(Color.YELLOW);//Set background color for working time. config.setTimeUnitWidth(50);//Set width for time unit config.setWorkingDaysSpanOfWeek(new int[]{Calendar.MONDAY, Calendar.THURSDAY})//Set span of working days in each week ... 4. Create data model "GanttModel" for Gantt Chart, all tasks information you want to display in GanttChart componenet are via this model class. GanttModel model = new GanttModel(); 5. Set start time and end time for schedule: model.setKickoffTime(new GregorianCalendar(2008, 0, 1)); model.setDeadline(new GregorianCalendar(2008, 0, 30)); 6. Create basic element for Gantt Chart：Task. A Task object shows as a bar in the Gantt Chart. Each Task object can contains any sub tasks, to form a tree structure. If a Task object contains sub tasks, it will be a Task group, which shows as different shape in Gantt Chart. Following is a Task group "taskGroup" with 2 sub tasks, "task1" and "task2": Task taskGroup = new Task("My Work 1", new GregorianCalendar(2008, 0, 1), new GregorianCalendar(2008, 0, 30)); Task task1 = new Task("Sub-task 1", new GregorianCalendar(2008, 0, 1), new GregorianCalendar(2008, 0, 5)); Task task2 = new Task(); task2.setName("Sub-task 2"); task2.setStart(new GregorianCalendar(2008, 0, 6)); task2.setEnd(new GregorianCalendar(2008, 0, 18));// Since version 0.3.0, the end time set to a task is included in duration of the task taskGroup.add(new Task[]{task1, task2}); 7. Attach the dependency between tasks. If task B must start after task A has completed, you should set task A as predecessor task to task B： task2.addPredecessor(task1); 8. Put the main task group for schedule into model object, and set the model object to GanttChart object： model.addTask(taskGroup); gantt.setModel(model); after that, you can see Gantt Chart displaying in the SwiftGantt component.
<2>. Save Gantt Chart as image files. ##### SwiftGantt is able to export Gantt Chart as png and jpeg files. This functionality is especially useful for web application. You can use SwiftGantt as image file generator at server side, to generator images for you project schedule and display in client browser. static GanttChart gantt = new GanttChart(); Initialize schedule information in Model: GanttModel model = new GanttModel(); ... Set Model to a singleton GanttChart instance: gantt.setModel(model); Specify directory path for exported image file: String filePath = "..."; gantt.generateImageFile(filePath); after that, you will find your GanttChart image file(s) at specified directory: Warnning: The GanttChart compoment is not thread safe, please synchronize method invocation on the singleton GanttChart object. e.g. synchronized(gantt){ gantt.setModel(model); gantt.generateImage(filePath); }