1
/*FreeMind - A Program for creating and viewing Mindmaps
2
*Copyright (C) 2000-2006 Joerg Mueller, Daniel Polansky, Christian Foltin, Dimitri Polivaev and others.
4
*See COPYING for Details
6
*This program is free software; you can redistribute it and/or
7
*modify it under the terms of the GNU General Public License
8
*as published by the Free Software Foundation; either version 2
9
*of the License, or (at your option) any later version.
11
*This program is distributed in the hope that it will be useful,
12
*but WITHOUT ANY WARRANTY; without even the implied warranty of
13
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
*GNU General Public License for more details.
16
*You should have received a copy of the GNU General Public License
17
*along with this program; if not, write to the Free Software
18
*Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* Created on 26.11.2005
22
* Copyright (C) 2005 Dimitri Polivaev
24
package freemind.view.mindmapview.attributeview;
26
import java.awt.Component;
27
import java.awt.EventQueue;
28
import java.awt.KeyboardFocusManager;
29
import java.awt.Point;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.awt.event.MouseEvent;
33
import java.awt.event.MouseListener;
35
import javax.swing.JComponent;
36
import javax.swing.JMenuItem;
37
import javax.swing.JPopupMenu;
38
import javax.swing.SwingUtilities;
39
import javax.swing.table.JTableHeader;
41
import freemind.main.Resources;
42
import freemind.modes.attributes.AttributeTableLayoutModel;
43
import freemind.modes.attributes.AttributeTableModel;
46
* @author Dimitri Polivaev
49
public class AttributePopupMenu extends JPopupMenu implements MouseListener {
50
private JMenuItem edit = null;
51
private JMenuItem optimalWidth = null;
52
private JMenuItem hide = null;
53
private JMenuItem insert = null;
54
private JMenuItem delete = null;
55
private JMenuItem up = null;
56
private JMenuItem down = null;
57
private AttributeTable table;
61
* @return Returns the optimalWidth.
63
private JMenuItem getOptimalWidth() {
64
if(optimalWidth == null){
65
optimalWidth = new JMenuItem(Resources.getInstance().getResourceString("attributes_popup_optimal_width"));
66
optimalWidth.addActionListener(new ActionListener(){
67
public void actionPerformed(ActionEvent e) {
68
table.setOptimalColumnWidths();
76
* @return Returns the insert.
78
private JMenuItem getInsert() {
80
insert = new JMenuItem(Resources.getInstance().getResourceString("attributes_popup_new"));
81
insert.addActionListener(new ActionListener(){
82
public void actionPerformed(ActionEvent e) {
83
table.insertRow(row + 1);
91
* @return Returns the delete.
93
private JMenuItem getDelete() {
95
delete = new JMenuItem(Resources.getInstance().getResourceString("attributes_popup_delete"));
96
delete.addActionListener(new ActionListener(){
97
public void actionPerformed(ActionEvent e) {
106
* @return Returns the up.
108
private JMenuItem getUp() {
110
up = new JMenuItem(Resources.getInstance().getResourceString("attributes_popup_up"));
111
up.addActionListener(new ActionListener(){
112
public void actionPerformed(ActionEvent e) {
113
table.moveRowUp(row);
121
* @return Returns the down.
123
private JMenuItem getDown() {
125
down = new JMenuItem(Resources.getInstance().getResourceString("attributes_popup_down"));
126
down.addActionListener(new ActionListener(){
127
public void actionPerformed(ActionEvent e) {
128
table.moveRowDown(row);
136
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
138
public void mouseClicked(MouseEvent e) {
141
public void mousePressed(MouseEvent e) {
145
public void mouseReleased(MouseEvent e) {
149
private void maybeShowPopup(MouseEvent e) {
150
if (e.isPopupTrigger()) {
151
selectTable(e.getComponent(), e.getPoint());
153
show(e.getComponent(),
161
private void make() {
162
String attributeViewType = table.getAttributeView().getViewType();
163
AttributeTableModel model = table.getAttributeTableModel();
164
int rowCount = model.getRowCount();
165
if(attributeViewType.equals(AttributeTableLayoutModel.SHOW_ALL)){
167
add(getOptimalWidth());
175
if(row != rowCount - 1){
182
add(getOptimalWidth());
188
private void selectTable(Component component, Point point) throws AssertionError {
189
int componentCount = getComponentCount();
190
for(int i = componentCount; i > 0;){
193
if(component instanceof AttributeTable){
195
table = (AttributeTable)component;
196
row = table.rowAtPoint(point);
197
if(table.getValueAt(row, 0).equals("")){
200
int selectedRow = table.getSelectedRow();
202
else if (component instanceof JTableHeader){
204
JTableHeader header = (JTableHeader)component;
205
table = (AttributeTable)header.getTable();
209
throw new AssertionError();
211
table.requestFocus();
215
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
217
public void mouseEntered(MouseEvent e) {
221
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
223
public void mouseExited(MouseEvent e) {
226
private boolean oldTable;
227
protected void firePopupMenuWillBecomeInvisible() {
229
table.removeRowSelectionInterval(row, row);
232
EventQueue.invokeLater(new Runnable(){
238
final KeyboardFocusManager focusManager = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager();
239
final Component focusOwner = SwingUtilities.getAncestorOfClass(AttributeTable.class, focusManager.getFocusOwner());
240
if(table != focusOwner
241
&& focusOwner instanceof JComponent){
242
table.requestFocus(true);
243
((JComponent)focusOwner).requestFocus();
249
protected void firePopupMenuWillBecomeVisible() {
251
table.addRowSelectionInterval(row, row);
255
public AttributeTable getTable() {