[Schmitzm-commits] r1672 - in trunk/schmitzm-core/src/main: java/de/schmitzm/swing/menu resources/de/schmitzm/swing/resource/icons/small
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Aug 12 00:59:38 CEST 2011
Author: mojays
Date: 2011-08-12 00:59:37 +0200 (Fri, 12 Aug 2011)
New Revision: 1672
Added:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/menu/ToolBarsPanel.java
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/drink_empty.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user_orange.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user_suit.png
Log:
new Icons
new ToolBarsPanel
Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/menu/ToolBarsPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/menu/ToolBarsPanel.java 2011-08-09 23:10:19 UTC (rev 1671)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/menu/ToolBarsPanel.java 2011-08-11 22:59:37 UTC (rev 1672)
@@ -0,0 +1,152 @@
+package de.schmitzm.swing.menu;
+
+import java.awt.Component;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.JComponent;
+
+import net.miginfocom.swing.MigLayout;
+import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.JPanel;
+
+/**
+ * Panel to arrange some other panels in a fixed vertical order,
+ * typically multiple toolbars. If the toolbar becomes invisible
+ * it is automatically removed from this ToolBarsPanel. If it
+ * becomes visible again, it is re-added automatically at its
+ * registered ordering position.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class ToolBarsPanel extends JPanel {
+ // listens to the visibility of the tool bars.
+ private ComponentListener componentListener = new ComponentAdapter() {
+ @Override
+ public void componentHidden(ComponentEvent e) {
+ setVisible(e.getComponent(), false);
+ }
+ @Override
+ public void componentShown(ComponentEvent e) {
+ setVisible(e.getComponent(), true);
+ }
+ };
+
+ /**
+ * Flag to avoid recursive loops in {@link #setVisible(Component, boolean)}.
+ */
+ protected boolean visibiliyIsAdjusting = false;
+
+ /**
+ * Holds the ordering indexes of the toolbars.
+ */
+ protected Map<Component,Integer> toolBarIdx = new HashMap<Component,Integer>();
+
+ /**
+ * Creates a new panel.
+ */
+ public ToolBarsPanel() {
+ this( new MigLayout("wrap 1","2[grow]2","2[min!]") );
+ }
+
+ /**
+ * Creates a new panel.
+ */
+ public ToolBarsPanel(MigLayout layout) {
+ super();
+ setLayout( layout );
+ }
+
+ /**
+ * Adds a toolbar to the panel.
+ * @param toolBar the new toolbar
+ * @param idx ordering index
+ * @param visible initial visibility state of the new bar
+ */
+ public Component add(Component toolBar, int idx, boolean visible) {
+ toolBarIdx.put(toolBar,idx);
+ toolBar.addComponentListener(componentListener);
+ setVisible(toolBar, visible);
+ return toolBar;
+ }
+
+ /**
+ * Adds a toolbar to the panel. Its initial visibility depends
+ * on its current visibility state.
+ * @param toolBar the new toolbar
+ * @param idx ordering index
+ */
+ @Override
+ public Component add(Component toolBar, int idx) {
+ return add(toolBar,idx,toolBar.isVisible());
+ }
+
+ /**
+ * Adds a toolbar to the panel. The ordering index is
+ * generated automatically as a value bigger than every
+ * already registered toolbar.
+ * @param toolBar the new toolbar
+ * @param visible initial visibility state of the new bar
+ */
+ public Component add(Component toolBar, boolean visible) {
+ return add(toolBar,getMaximumComponentIndex()+1,visible);
+ }
+
+ /**
+ * Adds a toolbar to the panel. Its initial visibility depends
+ * on its current visibility state. The ordering index is
+ * generated automatically as a value bigger than every
+ * already registered toolbar.
+ * @param toolBar the new toolbar
+ */
+ @Override
+ public Component add(Component toolBar) {
+ return add(toolBar, getMaximumComponentIndex()+1 );
+ }
+
+ /**
+ * Returns the maximum ordering index for the
+ * registered tool bars.
+ * @return -1 if there is no tool bar registered yet
+ */
+ public int getMaximumComponentIndex() {
+ return LangUtil.max( -1, toolBarIdx.values() );
+ }
+
+ /**
+ * Sets the visibility of a component
+ * @param toolBar toolbar to set the visibility for
+ * @param visible visible state
+ */
+ public void setVisible(Component toolBar, boolean visible) {
+ // if component is not registered yet, add it!
+ if ( !toolBarIdx.containsKey(toolBar) ) {
+ add(toolBar, visible);
+ return;
+ }
+
+ // Avoid recursive calls by toolBar.setVisible(.)
+ if ( visibiliyIsAdjusting )
+ return;
+ visibiliyIsAdjusting = true;
+
+ // bring component visibility to a consistent state
+ if ( visible != toolBar.isVisible() )
+ toolBar.setVisible(visible);
+
+ if ( visible ) {
+ Integer barIdx = toolBarIdx.get(toolBar);
+ add(toolBar, "cell 0 "+barIdx);
+ }
+ else
+ remove(toolBar);
+
+ if ( getParent() != null )
+ getParent().validate();
+
+ visibiliyIsAdjusting = false;
+ }
+
+}
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/drink_empty.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/drink_empty.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user_orange.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user_orange.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user_suit.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/filter_user_suit.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the Schmitzm-commits
mailing list