-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathTabCard.java
More file actions
114 lines (109 loc) · 3.14 KB
/
Copy pathTabCard.java
File metadata and controls
114 lines (109 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package openblocks.codeblockutil;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import openblocks.codeblockutil.CScrollPane.ScrollPolicy;
/**
* A Tab Card is used by glass explorers explorers as a
* mediator to their canvases.
*
* It wraps a button, a scrollpane, and a invoker.
*
* The button uses information about the current color
* and highlight of the canvas to dipict itself. The
* scrollpane takes the canvas and puts it inside a scroll
* pane so that users can navigate a very large canvas
* in small space. The invoker respnds to button presses
* and invokes the right method in the explorer.
*
* A tabbed pane does more than just store the scroll, button,
* and canvas, it also holds information about the menuitem
* for the tab oane's drop down menu.
*/
public class TabCard implements PropertyChangeListener{
/** The index of this card's tab location */
private int index;
/** the canvas to be shown in the tabbed pane */
private Canvas canvas;
/** the parent explorer */
private TabbedExplorer explorer;
/** the scroll viewport of the tab pane */
private JComponent scroll;
/** the tab */
private CButton button;
/** The menu item for its tab */
private JMenuItem menuItem;
/**
* Constructor
* @param i
* @param canvas
* @param ex
* @param scrollable
*/
TabCard(int i, Canvas canvas, TabbedExplorer ex, boolean scrollable){
this.index = i;
this.canvas = canvas;
this.explorer = ex;
if(scrollable){
this.scroll = new CHoverScrollPane(
canvas.getJComponent(),
ScrollPolicy.VERTICAL_BAR_AS_NEEDED,
ScrollPolicy.HORIZONTAL_BAR_AS_NEEDED,
18, canvas.getColor(), Color.darkGray);
}else{
this.scroll = canvas.getJComponent();
}
button = new CTabButton(canvas.getName());
menuItem = new JMenuItem(button.getText());
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
explorer.selectCanvas(index);
}
});
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
explorer.selectCanvas(index);
explorer.scrollToWheelItem(index);
}
});
canvas.getJComponent().addPropertyChangeListener(this);
}
/**
* @return the canvas
*/
Canvas getCanvas() {
return canvas;
}
/**
* @return the scroll pane
*/
JComponent getScroll() {
return scroll;
}
/**
* @return the button
*/
CButton getButton() {
return button;
}
/**
* @return the menu item
*/
JMenuItem getMenuItem(){
return menuItem;
}
public void propertyChange(PropertyChangeEvent e){
if (e.getPropertyName().equals(Canvas.LABEL_CHANGE)){
button.setText(canvas.getName());
menuItem.setText(canvas.getName());
}
}
}