Author: bobtarling
Date: 2010-09-25 12:59:04-0700
New Revision: 18776
Added:
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/Expandable.java
Modified:
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/LabelledComponent.java
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Log:
Begin moving controls out of RowSelector into LabelledComponent. This will give is more control of layout. This move the expander button. The toolbar will come out next.
Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/Expandable.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/Expandable.java?view=markup&pathrev=18776
==============================================================================
--- (empty file)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/Expandable.java 2010-09-25 12:59:04-0700
@@ -0,0 +1,30 @@
+/* $Id$
+ *******************************************************************************
+ * Copyright (c) 2010 Contributors - see below
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Bob Tarling
+ *******************************************************************************
+ */
+
+package org.argouml.core.propertypanels.ui;
+
+import javax.swing.JComponent;
+
+/**
+ * An interface for components that have the possibility of being expanded and shrunk.
+ * Not all components that implement this interface can actually be expanded, they only
+ * have the possibility if the implementation if isExpandable is true.
+ *
+ * @author Bob Tarling
+ */
+interface Expandable {
+ boolean isExpandable();
+ boolean isExpanded();
+ void toggleExpansion();
+ JComponent getExpansion();
+}
Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/LabelledComponent.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/LabelledComponent.java?view=diff&pathrev=18776&r1=18775&r2=18776
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/LabelledComponent.java (original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/LabelledComponent.java 2010-09-25 12:59:04-0700
@@ -1,13 +1,13 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2010 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * bobtarling
+ * Bob Tarling
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -39,24 +39,49 @@
package org.argouml.core.propertypanels.ui;
import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Cursor;
import java.awt.Dimension;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.swing.BoxLayout;
+import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.JTree;
+import javax.swing.plaf.TreeUI;
+import javax.swing.plaf.basic.BasicTreeUI;
+import javax.swing.plaf.metal.MetalTreeUI;
/**
* A wrapped label and component pair
*
* @author Bob Tarling
*/
-class LabelledComponent extends JPanel {
-
+class LabelledComponent extends JPanel implements MouseListener {
+
/**
* The class uid
*/
private static final long serialVersionUID = -6805892904843209588L;
+
+ private static final Set<String> EXPANDED_CONTROLS = new TreeSet<String>();
+
+ /**
+ * The icon to use when the control is expanded
+ */
+ private static Icon expandedIcon;
+
+ /**
+ * The icon to use when the control is collapsed
+ */
+ private static Icon collapsedIcon;
/**
* The label for the component that might also be wrapped inside this
@@ -65,6 +90,27 @@
private final JLabel label;
private final JComponent component;
+ /**
+ * The label that contains the +/- symbol to indicate
+ * expansion feature to user.
+ */
+ private final JLabel expander;
+
+ static {
+ // Extract the icon that is used by the tree control
+ // for the current look and feel
+ final JTree dummyTree = new JTree();
+
+ final BasicTreeUI btu;
+ if (dummyTree.getUI() instanceof BasicTreeUI) {
+ btu = (BasicTreeUI) dummyTree.getUI();
+ } else {
+ btu = new MetalTreeUI();
+ }
+
+ expandedIcon = btu.getExpandedIcon();
+ collapsedIcon = btu.getCollapsedIcon();
+ }
/**
* Construct a new LabelledComponent
@@ -81,13 +127,47 @@
label = new JLabel(name);
label.setLabelFor(component);
JPanel labelPanel = new JPanel();
- labelPanel.add(label, BorderLayout.NORTH);
- add(labelPanel, BorderLayout.WEST);
+ labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.X_AXIS));
+ labelPanel.add(label);
+ JPanel leftPanel = new JPanel();
+ leftPanel.add(labelPanel, BorderLayout.CENTER);
+ add(leftPanel, BorderLayout.WEST);
+ if (component instanceof Expandable && ((Expandable) component).isExpandable()) {
+ expander = new JLabel();
+ leftPanel.add(expander, BorderLayout.EAST);
+ addMouseListener(this);
+ setIcon();
+ if (EXPANDED_CONTROLS.contains(getId())) {
+ toggleExpansion();
+ }
+ } else {
+ expander = null;
+ }
} else {
label = null;
+ expander = null;
}
}
+ private String getId() {
+ return label.getText();
+ }
+
+ /**
+ * Set the icon according to the current expansion setting
+ */
+ private void setIcon() {
+ if (expander != null) {
+ if (((Expandable) component).isExpanded()) {
+ expander.setIcon(expandedIcon);
+ } else {
+ expander.setIcon(collapsedIcon);
+ }
+ }
+ }
+
+
+
/**
* Get the label created from the component name
* @return the label
@@ -103,4 +183,48 @@
return super.getPreferredSize();
}
}
+
+ public void mouseClicked(MouseEvent e) {
+ if (e.getSource() == this) {
+ toggleExpansion();
+ }
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+
+ public void mousePressed(MouseEvent arg0) {
+ }
+
+ public void mouseReleased(MouseEvent arg0) {
+ }
+
+ /**
+ * Toggle between expansion and contraction of the control
+ */
+ private void toggleExpansion() {
+ ((Expandable) component).toggleExpansion();
+
+ if (((Expandable) component).isExpanded()) {
+ EXPANDED_CONTROLS.add(getId());
+ } else {
+ EXPANDED_CONTROLS.remove(getId());
+ }
+
+ setIcon();
+// if (toolbar != null) {
+// toolbar.setVisible(expanded);
+// }
+//
+// // Force the parent to redraw
+// Component c = getParent();
+// if (c != null) {
+// c.invalidate();
+// c.validate();
+// }
+ }
+
}
Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java?view=diff&pathrev=18776&r1=18775&r2=18776
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java (original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java 2010-09-25 12:59:04-0700
@@ -97,7 +97,7 @@
* @since 0.29.2
*/
class RowSelector extends UmlControl
- implements MouseListener, ListDataListener, ListSelectionListener {
+ implements MouseListener, ListDataListener, ListSelectionListener, Expandable {
/**
* The logger
@@ -129,8 +129,6 @@
*/
private final boolean readonly;
- private static final Set<String> EXPANDED_CONTROLS = new TreeSet<String>();
-
private final ArrayList actions;
static {
@@ -192,12 +190,6 @@
private MovedModelElement movedModelElement = new MovedModelElement();
/**
- * The label that contains the +/- symbol to indicate
- * expansion feature to user.
- */
- private final JLabel expander;
-
- /**
* The toolbar of controls for manipulating items in the list
*/
private final JToolBar toolbar;
@@ -330,7 +322,6 @@
if (!expandable && !expanded) {
jscroll.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_NEVER);
- expander = null;
toolbar = null;
deleteAction = null;
moveUpAction = null;
@@ -471,10 +462,7 @@
JPanel buttonPanel =
new JPanel(new FlexiGridLayout(
2, 1, FlexiGridLayout.ROWCOLPREFERRED));
- expander = new JLabel();
this.addMouseListener(this);
- setIcon();
- buttonPanel.add(expander);
// TODO: In think this will always be true
if (toolbar != null) {
toolbar.setVisible(false);
@@ -504,11 +492,6 @@
getModel().addListDataListener(this);
}
-
- if (EXPANDED_CONTROLS.contains(getId())) {
- toggleExpansion();
- }
-
}
/**
@@ -594,16 +577,9 @@
/**
* Toggle between expansion and contraction of the control
*/
- private void toggleExpansion() {
+ public void toggleExpansion() {
expanded = !expanded;
- if (expanded) {
- EXPANDED_CONTROLS.add(getId());
- } else {
- EXPANDED_CONTROLS.remove(getId());
- }
-
- setIcon();
if (toolbar != null) {
toolbar.setVisible(expanded);
}
@@ -616,6 +592,18 @@
}
}
+ public JComponent getExpansion() {
+ return toolbar;
+ }
+
+ public boolean isExpanded() {
+ return expanded;
+ }
+
+ public boolean isExpandable() {
+ return expandable;
+ }
+
private String getId() {
final String id;
ListModel model = getList().getModel();
@@ -629,17 +617,6 @@
}
/**
- * Set the icon according to the current expansion setting
- */
- private void setIcon() {
- if (expanded) {
- expander.setIcon(expandedIcon);
- } else {
- expander.setIcon(collapsedIcon);
- }
- }
-
- /**
* Remove all the listeners that were added in the constructor
*/
public void removeNotify() {
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2664583
To unsubscribe from this discussion, e-mail: [[email protected]].
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.