⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupoftaskpanegroup.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/**
 * @PROJECT.FULLNAME@ @VERSION@ License.
 *
 * Copyright @YEAR@ L2FProd.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.l2fprod.common.swing;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
 * This class is used to create a multiple-exclusion scope for a set of
 * JTaskPaneGroups. Creating a set of JTaskPaneGroups with the same
 * GroupOfTaskPaneGroup object means that expanding one of those JTaskPaneGroups
 * will collapse all other JTaskPaneGroups in the group.
 * 
 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
 */
public class GroupOfTaskPaneGroup implements PropertyChangeListener {

  private JTaskPaneGroup selection;

  /**
   * Adds a <code>JTaskPaneGroup</code> to this group.
   * 
   * @param taskpaneGroup
   */
  public void add(JTaskPaneGroup taskpaneGroup) {
    register(taskpaneGroup);
    // if we have no selection
    if (selection == null) {
      // and if the taskpane is expanded
      if (taskpaneGroup.isExpanded()) {
        // then the selection becomes the taskpane
        selection = taskpaneGroup;
      }
    } else {
      // we have a selection, so this taskpane must be collapsed
      taskpaneGroup.setExpanded(false);
    }
     
    maybeUpdateSelection(taskpaneGroup);
  }

  /**
   * Removes a <code>JTaskPaneGroup</code> from this group.
   * 
   * @param taskpaneGroup
   */
  public void remove(JTaskPaneGroup taskpaneGroup) {
    unregister(taskpaneGroup);
    // if we are removing the currently selection taskpane, reset the selection
    // to "null" otherwise the taskpane may get modified by us later.
    if (selection == taskpaneGroup) {
      selection = null;
    }
  }

  public void propertyChange(PropertyChangeEvent event) {
    // if a taskpane gets expanded, collapse the previously expanded one if any
    JTaskPaneGroup taskpaneGroup = (JTaskPaneGroup) event.getSource();
    maybeUpdateSelection(taskpaneGroup);
  }

  private void maybeUpdateSelection(JTaskPaneGroup taskpaneGroup) {
    if (selection != taskpaneGroup && taskpaneGroup.isExpanded()) {
      if (selection != null) {
        selection.setExpanded(false);
      }
      selection = taskpaneGroup;
    }
  }

  private void register(JTaskPaneGroup taskpaneGroup) {
    taskpaneGroup.addPropertyChangeListener(
        JTaskPaneGroup.EXPANDED_CHANGED_KEY, this);
  }

  private void unregister(JTaskPaneGroup taskpaneGroup) {
    taskpaneGroup.removePropertyChangeListener(
        JTaskPaneGroup.EXPANDED_CHANGED_KEY, this);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -