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

📄 mutablelistmodel.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }
      });
      moveUp.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui().getString(
        "list.moveUp"));
      return moveUp;
    }

    public static Action createMoveUpAction(final JTable table) {
      final Action moveUp = new AbstractAction(ResourceManager.ui().getString(
        "list.moveUp")) {

        public void actionPerformed(ActionEvent event) {
          int selected = table.getSelectedRow();
          ((MutableListModel)table.getModel()).moveUp(selected);
          table.getSelectionModel().setSelectionInterval(selected - 1,
            selected - 1);
        }
      };
      setupAction(moveUp, table, new Updater() {

        public void update(Action action, Component p_Target) {
          action.setEnabled(((JTable)p_Target).getModel().getRowCount() > 0
            && ((JTable)p_Target).getSelectedRow() > 0);
        }
      });
      moveUp.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui().getString(
        "list.moveUp"));
      return moveUp;
    }

    public static Action createMoveDownAction(final JList list) {
      final Action moveDown = new AbstractAction(ResourceManager.ui()
        .getString("list.moveDown")) {

        public void actionPerformed(ActionEvent event) {
          int selected = list.getSelectedIndex();
          ((MutableListModel)list.getModel()).moveDown(selected);
          list.setSelectedIndex(selected + 1);
        }
      };
      setupAction(moveDown, list, new Updater() {

        public void update(Action action, Component p_Target) {
          int selected = ((JList)p_Target).getSelectedIndex();
          action.setEnabled(((JList)p_Target).getModel().getSize() > 0
            && selected != -1
            && selected < (((JList)p_Target).getModel().getSize() - 1));
        }
      });
      moveDown.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui()
        .getString("list.moveDown"));
      return moveDown;
    }

    public static Action createMoveDownAction(final JTable table) {
      final Action moveDown = new AbstractAction(ResourceManager.ui()
        .getString("list.moveDown")) {

        public void actionPerformed(ActionEvent event) {
          int selected = table.getSelectedRow();
          ((MutableListModel)table.getModel()).moveDown(selected);
          table.getSelectionModel().setSelectionInterval(selected + 1,
            selected + 1);
        }
      };
      setupAction(moveDown, table, new Updater() {

        public void update(Action action, Component p_Target) {
          int selected = ((JTable)p_Target).getSelectedRow();
          action.setEnabled(((JTable)p_Target).getModel().getRowCount() > 0
            && selected != -1
            && selected < (((JTable)p_Target).getModel().getRowCount() - 1));
        }
      });
      moveDown.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui()
        .getString("list.moveDown"));
      return moveDown;
    }

    public static Action createMoveToBottomAction(final JList list) {
      final Action moveToBottom = new AbstractAction(ResourceManager.ui()
        .getString("list.moveBottom")) {

        public void actionPerformed(ActionEvent event) {
          ((MutableListModel)list.getModel()).moveToBottom(list
            .getSelectedIndex());
          list.setSelectedIndex(list.getModel().getSize() - 1);
        }
      };
      setupAction(moveToBottom, list, new Updater() {

        public void update(Action action, Component p_Target) {
          int selected = ((JList)p_Target).getSelectedIndex();
          action.setEnabled(((JList)p_Target).getModel().getSize() > 0
            && selected != -1
            && selected < (((JList)p_Target).getModel().getSize() - 1));
        }
      });
      moveToBottom.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui()
        .getString("list.moveBottom"));
      return moveToBottom;
    }

    public static Action createRemoveAction(final JList list) {
      final Action remove = new AbstractAction(ResourceManager.ui().getString(
        "list.remove")) {

        public void actionPerformed(ActionEvent event) {
          int selected = list.getSelectedIndex();
          if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(list,
            ResourceManager.ui().getString("list.removeWarning"),
            ResourceManager.ui().getString("list.removeWarningTitle"),
            JOptionPane.YES_NO_OPTION)) {
            ((MutableListModel)list.getModel()).remove(selected);
            selected = Math.min(list.getModel().getSize() - 1, selected);
            list.setSelectedIndex(selected);
          }
        }
      };
      setupAction(remove, list, new Updater() {

        public void update(Action action, Component p_Target) {
          action.setEnabled(((JList)p_Target).getModel().getSize() > 0
            && ((JList)p_Target).getSelectedIndex() != -1);
        }
      });
      remove.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui().getString(
        "list.remove"));
      return remove;
    }

    public static Action createRemoveAction(final JTable table) {
      final Action remove = new AbstractAction(ResourceManager.ui().getString(
        "list.remove")) {

        public void actionPerformed(ActionEvent event) {
          int selected = table.getSelectedRow();
          ((MutableListModel)table.getModel()).remove(selected);
          selected = Math.min(table.getModel().getRowCount() - 1, selected);
          if (selected >= 0) {
            table.setRowSelectionInterval(selected, selected);
          }
        }
      };
      setupAction(remove, table, new Updater() {

        public void update(Action action, Component p_Target) {
          action.setEnabled(((JTable)p_Target).getModel().getRowCount() > 0
            && ((JTable)p_Target).getSelectedRow() != -1);
        }
      });
      remove.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui().getString(
        "list.remove"));
      return remove;
    }

    public static Action createRemoveAllAction(final JList list) {
      final Action removeAll = new AbstractAction(ResourceManager.ui()
        .getString("list.removeAll")) {

        public void actionPerformed(ActionEvent event) {
          if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(list,
            ResourceManager.ui().getString("list.removeAllWarning"),
            ResourceManager.ui().getString("list.removeAllWarningTitle"),
            JOptionPane.YES_NO_OPTION)) {
            ((MutableListModel)list.getModel()).removeAll();
          }
        }
      };
      setupAction(removeAll, list, new Updater() {

        public void update(Action action, Component p_Target) {
          action.setEnabled(((JList)p_Target).getModel().getSize() > 0);
        }
      });
      removeAll.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui()
        .getString("list.removeAll"));
      return removeAll;
    }

    public static Action createRemoveAllAction(final JTable table) {
      final Action removeAll = new AbstractAction(ResourceManager.ui()
        .getString("list.removeAll")) {

        public void actionPerformed(ActionEvent event) {
          if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(table,
            ResourceManager.ui().getString("list.removeAllWarning"),
            ResourceManager.ui().getString("list.removeAllWarningTitle"),
            JOptionPane.YES_NO_OPTION)) {
            ((MutableListModel)table.getModel()).removeAll();
          }
        }
      };
      setupAction(removeAll, table, new Updater() {

        public void update(Action action, Component p_Target) {
          action.setEnabled(((JTable)p_Target).getModel().getRowCount() > 0);
        }
      });
      removeAll.putValue(Action.SHORT_DESCRIPTION, ResourceManager.ui()
        .getString("list.removeAll"));
      return removeAll;
    }

    public static Action createActionListAction(final JList list, String text,
      final ActionList _action) {
      final Action result = new AbstractAction(text) {

        public void actionPerformed(ActionEvent event) {
          _action.actionOnListPerformed(event, list);
        }
      };
      setupAction(result, list, new Updater() {

        public void update(Action action, Component p_Target) {
          action.setEnabled(((JList)p_Target).getModel().getSize() > 0
            && ((JList)p_Target).getSelectedIndex() >= 0);
        }
      });
      result.putValue(Action.SHORT_DESCRIPTION, text);
      return result;
    }

  } // Actions

}

⌨️ 快捷键说明

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