View Javadoc

1   /*
2    * TestSizeAction.java
3    *
4    * Created on 27. juni 2005, 15:32
5    */
6   
7   package com.vikash.firsttool.UI;
8   import com.vikash.firsttool.Diagram.*;
9   import javax.swing.*;
10  import java.awt.event.*;
11  import java.util.List;
12  import java.util.*;
13  import java.awt.*;
14  
15  import org.jgraph.JGraph;
16  import org.jgraph.graph.Port;
17  import org.jgraph.graph.CellView;
18  import org.jgraph.graph.AttributeMap;
19  import org.jgraph.graph.DefaultGraphModel;
20  import org.jgraph.graph.GraphConstants;
21  
22  /***
23   *
24   * @author  studajb
25   */
26  public class TextFontSizeAction extends JComboBox {
27      MainFrame frame;
28      ToolGraph graph;
29      AttributeMap map;
30      Map attributemap;
31      /*** Creates a new instance of TestSizeAction */
32      public TextFontSizeAction(MainFrame frame) {
33          this.frame=frame;
34          setEditable(true);
35          setMaximumSize(new Dimension(50, 30));
36          setPreferredSize(new Dimension(50, 30));
37          setToolTipText("Font Size");
38  
39          Object[] items=new Object[]{"8","10","12","14","16","18","20","22","24","26","28","36","48","72"}; 
40          for (int i = 0; i < items.length; i++) {
41  			Object item = items[i];
42  			if (item != null)
43  				addItem(item);
44  		}
45       this.addActionListener(new ActionListener()
46       {
47           public void actionPerformed(ActionEvent e){
48               String fontsize=(String)((JComboBox)e.getSource()).getSelectedItem();
49               changeFontSize(fontsize);
50               
51           }
52       });
53      }
54       public void changeFontSize(String fontvalue) {
55           
56          String fontsize=fontvalue;
57          ToolInternalFrame internalframe=(ToolInternalFrame)frame.getDesktopPane().getSelectedFrame();
58             if(internalframe==null)  return; 
59           graph=internalframe.getGraph();
60          Object[] cells = DefaultGraphModel.getDescendants(graph.getModel(), graph.getSelectionCells()).toArray();
61  		//Filter ports out
62  		java.util.List list = new ArrayList();
63  		for (int i = 0; i < cells.length; i++)
64  			if (!(cells[i] instanceof Port))
65  			list.add(cells[i]);
66  		cells = list.toArray();
67    
68          if (cells.length!=0){
69          
70  		for (int i = 0; i < cells.length; i++) {
71  			CellView view = (CellView)graph.getGraphLayoutCache().getMapping(cells[i],false);
72                          
73  			if (view != null) {
74                                 AttributeMap attributes=new AttributeMap();
75                                  Font font = GraphConstants.getFont(view.getAllAttributes());
76                                  GraphConstants.setFont(attributes, font.deriveFont(Float.parseFloat(fontsize)));
77  				graph.getGraphLayoutCache().editCell(cells[i],attributes);
78                                  graph.startEditingAtCell(cells[i]);
79                                  graph.stopEditing();
80  			}
81                         	}
82          
83  		                
84          }
85  		 
86      }
87      
88  }