View Javadoc

1   /***
2    * 
3    */
4   package org.telscenter.pas.ui.sidebar;
5   
6   import java.awt.Color;
7   import java.awt.Cursor;
8   import java.awt.Dimension;
9   import java.awt.Font;
10  import java.awt.event.ActionEvent;
11  
12  import javax.swing.AbstractAction;
13  import javax.swing.Action;
14  import javax.swing.BorderFactory;
15  import javax.swing.ImageIcon;
16  import javax.swing.JButton;
17  import javax.swing.JPanel;
18  import javax.swing.UIManager;
19  
20  import org.telscenter.pas.common.ui.button.VerticalTextIcon;
21  import org.telscenter.pas.ui.frames.PasFrame;
22  
23  /***
24   * @author aperritano
25   *
26   */
27  public class SidebarMeditor implements Meditor {
28  
29  	private JPanel wholePanel;
30  	private int lastDividerLocation;
31  	private PasFrame pasFrame;
32  
33  	/***
34  	 * @param wholePanel
35  	 * @param splitPane
36  	 * @param pasProjectNavigationPanel 
37  	 */
38  	public SidebarMeditor(PasFrame pasFrame) {
39  		this.pasFrame = pasFrame;
40  	}
41  	
42  	public void collapseView() {
43  		this.pasFrame.getCompactNavigationViewPanel().setPreferredSize(new Dimension(0,this.pasFrame.getCompactViewPreferredSize().height));
44  		this.pasFrame.getCompactNavigationViewPanel().revalidate();
45  		
46  		pasFrame.getSplitPane().setDividerLocation(lastDividerLocation);
47  		
48  		this.pasFrame.getSplitPane().updateUI();
49  		
50  	}
51  	
52  	public void expandView() {
53  		lastDividerLocation = this.pasFrame.getSplitPane().getDividerLocation();
54  		this.pasFrame.getCompactNavigationViewPanel().setVisible(true);
55  		this.pasFrame.getCompactNavigationViewPanel().setPreferredSize(this.pasFrame.getCompactViewPreferredSize());
56  		this.pasFrame.getCompactNavigationViewPanel().revalidate();
57  		this.pasFrame.getSplitPane().setDividerLocation(0);
58  		this.pasFrame.getSplitPane().updateUI();
59  	}
60  	
61  	public JButton getCollapseCompactViewButton() {
62  		
63  		Font font = UIManager.getFont("Label.font");
64  		Font verticalFont = font.deriveFont(Font.BOLD, 10.0f);
65  		
66  		final VerticalTextIcon turnOnIcon = new VerticalTextIcon(
67  				"Switch Sidebar On", true, Color.WHITE, verticalFont);
68  
69  		
70  		JButton collapseViewButton = new JButton();
71  		
72  		collapseViewButton.setAction(collapseCompactView);
73  		collapseViewButton.setRolloverEnabled(true);
74  		collapseViewButton.setIcon(new ImageIcon(this.getClass().getResource("icons/expandButtonNormal.png")));
75  		collapseViewButton.setRolloverIcon(new ImageIcon(this.getClass().getResource("icons/expandButtonRollover.png")));
76  		
77  		collapseViewButton.setBorder(BorderFactory.createEmptyBorder()); 
78  		collapseViewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 
79  		collapseViewButton.setFocusPainted(false); 
80  		collapseViewButton.setRequestFocusEnabled(false); 
81  		collapseViewButton.setToolTipText("Expand the Navigation Bar");
82  		return collapseViewButton;
83  	}
84  	
85  	public JButton getExpandCompactViewButton() {
86  		JButton expandViewButton = new JButton();
87  		
88  		expandViewButton.setAction(expandCompactView);
89  		expandViewButton.setRolloverEnabled(true);
90  		expandViewButton.setIcon(new ImageIcon(this.getClass().getResource("icons/shrinkButtonNormal.png")));
91  		expandViewButton.setRolloverIcon(new ImageIcon(this.getClass().getResource("icons/shrinkButtonRollover.png")));
92  		
93  		expandViewButton.setBorder(BorderFactory.createEmptyBorder()); 
94  		expandViewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 
95  		expandViewButton.setFocusPainted(false); 
96  		expandViewButton.setRequestFocusEnabled(false); 
97  		expandViewButton.setToolTipText("Shrink the Navigation Bar");
98  		return expandViewButton;
99  	}
100 	
101 
102 	
103 	Action expandCompactView = new AbstractAction() {
104 
105 		private int lastDividerLocation;
106 
107 		public void actionPerformed(ActionEvent e) {
108 			expandView();
109 			
110 		}
111 	};
112 	
113 	Action collapseCompactView = new AbstractAction() {
114 
115 		private int lastDividerLocation;
116 
117 		public void actionPerformed(ActionEvent e) {
118 			collapseView();
119 			
120 		}
121 	};
122 }