2009. 11. 15. 20:07
Posted by TIMEC
2009. 11. 15. 20:03
Posted by TIMEC
2009. 11. 15. 20:00
Posted by TIMEC
2009. 11. 15. 19:53

package layout;

import java.awt.*;
import java.util.*;

public class PositionLayout implements LayoutManager {
    Vector  positions = new Vector(10);
    Vector  components = new Vector(10);
    private  boolean   leftRatio;
    private  boolean   topRatio;
    private  boolean   rightRatio;
    private  boolean   bottomRatio;

    public void addLayoutComponent(String p, Component c) {
        positions.addElement(p);
        components.addElement(c);
    }


    public void removeLayoutComponent(Component c) {

        int i = components.indexOf(c);
        if(i != -1) {
            positions.removeElementAt(i);
            components.removeElementAt(i);
        }
    }


    public Dimension preferredLayoutSize(Container parent) {
        Dimension dim = new Dimension(0,0);
        int ncomponents = parent.getComponentCount();
        Insets  insets = parent.getInsets();
        dim.width += insets.left + insets.right;
        dim.height += insets.top + insets.bottom;

        int maxW = dim.width;
        int maxH = dim.height;
        for(int i = 0; i < ncomponents; i++) {
            Component  com = parent.getComponent(i);
            if(com.isVisible() == false)
                continue;
            int  w = com.getPreferredSize().width + dim.width;
            int  h = com.getPreferredSize().height + dim.height;
            if( w > maxW )
                maxW = w;
            if( h > maxH )
                maxH = h;
        }
        //System.out.println("prefer Size: width="+maxW+"\t\theight="+maxH);
        return  new Dimension(maxW, maxH);
    }


    public Dimension minimumLayoutSize(Container target) {
        return  target.getSize();
    }


    public void layoutContainer(Container target) {
        Insets insets = target.getInsets();
        int    ncomponents = target.getComponentCount();
        Dimension d = target.getSize();
        d.width  -= insets.left + insets.right;
        d.height  -= insets.top + insets.bottom;
        int  startX =0, startY =0, endX =0, endY =0;
        int  left = 0, top =0, right = 0, bottom =0;
        for(int i=0; i< ncomponents; i++) {
            Component comp = target.getComponent(i);
         StringTokenizer token = new StringTokenizer((String)positions.elementAt(i), ", \t");
            String  leftSt = token.nextToken();
            if(leftSt.endsWith("%")) {
                leftRatio = true;
                left  = Integer.parseInt(leftSt.substring(0, leftSt.length()-1));
            } else {
                left  = Integer.parseInt(leftSt);
            }

            String  topSt = token.nextToken();
            if(topSt.endsWith("%")) {
                topRatio = true;
                top  = Integer.parseInt(topSt.substring(0, topSt.length()-1));
            } else {
                top  = Integer.parseInt(topSt);
            }

            String  rightSt = token.nextToken();
            if(rightSt.endsWith("%")) {
                rightRatio = true;
                right  = Integer.parseInt(rightSt.substring(0, rightSt.length()-1));
            } else {
                right  = Integer.parseInt(rightSt);
            }

            String  bottomSt = token.nextToken();
            if(bottomSt.endsWith("%")) {
                bottomRatio = true;
                bottom  = Integer.parseInt(bottomSt.substring(0, bottomSt.length()-1));
            } else {
                bottom  = Integer.parseInt(bottomSt);
            }

            if(leftRatio)
                startX = (d.width * left)/100;
            else
                startX = left;

            if(topRatio)
                startY = (d.height * top)/100;
            else
                startY = top;

            if(rightRatio)
                endX = (d.width * right)/100;
            else
                endX = right;

            if(bottomRatio)
                endY = (d.height * bottom)/100;
            else
                endY = bottom;

            if(startX > endX) {
                int temp = startX;
                startX = endX;
                endX = temp;
            }
            if(startY > endY) {
                int temp = startY;
                startY = endY;
                endY = temp;
            }
            int  w = endX - startX;
            int  h = endY - startY;
            comp.setBounds(startX+insets.left, startY+insets.top, w, h);
            topRatio = false;
            leftRatio = false;
            rightRatio = false;
            bottomRatio = false;
        }
    }

    public String toString() {
        return getClass().getName();
    }
}

'JAVA 6.0 > GUI (AWT, SWING)' 카테고리의 다른 글

JFreeChart Package Documentation  (0) 2009.11.15
JFreeChart Package File  (0) 2009.11.15
JFreeChart 사용하기 (HistogramChart)  (0) 2009.11.15
JFreeChart 사용하기 (ScatterPlot)  (0) 2009.11.15
JFreeChart 사용하기 (LineChart)  (0) 2009.11.15
Posted by TIMEC
2009. 11. 15. 19:50


package JFreeChart;

import java.awt.*;
import org.jfree.chart.*;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class HistogramChart{
 private XYSeries series = null;
 private XYDataset dataset = null;
 private JFreeChart chart = null;
 private TextTitle subTitle = null;
 
 public HistogramChart(){
  series = new XYSeries("Users");
  series.add(2000, 100.0);
  series.add(2001, 111.0);
  series.add(2002, 120.0);
  series.add(2003, 140.0);
 }
 public ChartPanel getHistogramChart_HistogramChart(){
  ChartPanel chartPanel_HistogramChart = null;
  dataset = new XYSeriesCollection(series);
  chart = ChartFactory.createXYBarChart("Response Time  Monitoring", "Var", false, "Frequence", (IntervalXYDataset) dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
  subTitle = new TextTitle("Thread Test");
  chart.setBackgroundPaint(Color.WHITE);
  chart.addSubtitle(subTitle);
  chartPanel_HistogramChart = new ChartPanel(chart);
  return chartPanel_HistogramChart;
 }
}

Posted by TIMEC
2009. 11. 15. 19:49

package JFreeChart;

import java.awt.*;
import org.jfree.chart.*;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class ScatterPlot {
 private XYSeries series = null;
 private XYDataset dataset = null;
 private JFreeChart chart = null;
 private TextTitle subTitle = null;

 
 public ScatterPlot(){
  series = new XYSeries("Users");
  series.add(2000, 100.0);
  series.add(2001, 111.0);
  series.add(2002, 120.0);
  series.add(2002, 130.0);
  series.add(2001, 110.0);
  series.add(2002, 150.0);
  series.add(2001, 120.0);
  series.add(2003, 170.0);
  series.add(2001, 160.0);
  series.add(2002, 120.0);
  
    }
 public ChartPanel getchartPanel_scatterPlot(){
  ChartPanel chartPanel_scatterPlot = null;
  dataset = new XYSeriesCollection(series);
  chart = ChartFactory.createScatterPlot("JDBC & SQL Monitoring", "Var",  "Frequence", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
  subTitle = new TextTitle("ClientRequirement Test");
  chart.setBackgroundPaint(Color.WHITE);
  chart.addSubtitle(subTitle);
  chartPanel_scatterPlot = new ChartPanel(chart);
  return chartPanel_scatterPlot;
 }
}

 

Posted by TIMEC
2009. 11. 15. 19:48


package JFreeChart;

import java.awt.*;
import org.jfree.chart.*;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class LineChart {
 private XYSeries series = null;
 private XYDataset dataset = null;
 private JFreeChart chart = null;
 private TextTitle subTitle = null;
 
 public LineChart(){
  series = new XYSeries("Users");
  series.add(2000, 100.0);
  series.add(2001, 111.0);
  series.add(2002, 120.0);
  series.add(2003, 140.0);
 }
 public ChartPanel getchartPanel_lineChart(){
  ChartPanel chartPanel_lineChart = null;
  dataset = new XYSeriesCollection(series);
  chart = ChartFactory.createXYLineChart("WebServer Performance Monitoring", "Var",  "Frequence", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
  subTitle = new TextTitle("Heap Memory Usage Test");
  chart.setBackgroundPaint(Color.WHITE);
  chart.addSubtitle(subTitle);
  chartPanel_lineChart = new ChartPanel(chart);
  return chartPanel_lineChart;
 }
 
}

Posted by TIMEC
2009. 11. 15. 19:47

package JFreeChart;

import java.awt.*;
import org.jfree.chart.*;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;


public class AreaChart {
 private XYSeries series = null;
 private XYDataset dataset = null;
 private JFreeChart chart = null;
 private TextTitle subTitle = null;
 
 public AreaChart(){
  series = new XYSeries("Users");
  series.add(2000, 100.0);
  series.add(2001, 111.0);
  series.add(2002, 120.0);
  series.add(2003, 140.0);
    }
 public ChartPanel getchartPanel_areaChart(){
  ChartPanel chartPanel_areaChart = null;
  XYDataset dataset = new XYSeriesCollection(series);
  chart = ChartFactory.createXYAreaChart("Concurrent User  Monitoring", "Var",  "Frequence", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
  subTitle = new TextTitle("Classes Test");
  chart.setBackgroundPaint(Color.WHITE);
  chart.addSubtitle(subTitle);
  chartPanel_areaChart = new ChartPanel(chart);
  return chartPanel_areaChart;
 }
}

Posted by TIMEC