示例#1
0
  public void startupMapHook() {
    super.startupMapHook();

    mMyMindMapController = super.getMindMapController();
    getMindMapController().getController().getMapModuleManager().addListener(this);

    // get strings from resources:
    COLUMN_MODIFIED = getResourceString("plugins/TimeList.xml_Modified");
    COLUMN_CREATED = getResourceString("plugins/TimeList.xml_Created");
    COLUMN_ICONS = getResourceString("plugins/TimeList.xml_Icons");
    COLUMN_TEXT = getResourceString("plugins/TimeList.xml_Text");
    COLUMN_DATE = getResourceString("plugins/TimeList.xml_Date");
    COLUMN_NOTES = getResourceString("plugins/TimeList.xml_Notes");

    showAllNodes = Tools.xmlToBoolean(getResourceString("show_all_nodes"));
    dialog = new JDialog(getController().getFrame().getJFrame(), false /* unmodal */);
    String windowTitle;
    if (showAllNodes) {
      windowTitle = "plugins/TimeManagement.xml_WindowTitle_All_Nodes";
    } else {
      windowTitle = "plugins/TimeManagement.xml_WindowTitle";
    }
    dialog.setTitle(getResourceString(windowTitle));
    dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent event) {
            disposeDialog();
          }
        });
    Tools.addEscapeActionToDialog(
        dialog,
        new AbstractAction() {
          public void actionPerformed(ActionEvent arg0) {
            disposeDialog();
          }
        });
    Container contentPane = dialog.getContentPane();
    GridBagLayout gbl = new GridBagLayout();
    gbl.columnWeights = new double[] {1.0f};
    gbl.rowWeights = new double[] {1.0f};
    contentPane.setLayout(gbl);
    contentPane.add(
        new JLabel(getResourceString("plugins/TimeManagement.xml_Find")),
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    mFilterTextSearchField = new JTextField();
    mFilterTextSearchField.getDocument().addDocumentListener(new FilterTextDocumentListener());
    mFilterTextSearchField.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent pEvent) {
            // logger.info("Key event:" + pEvent.getKeyCode());
            if (pEvent.getKeyCode() == KeyEvent.VK_DOWN) {
              logger.info("Set Focus to replace fields");
              mFilterTextReplaceField.requestFocusInWindow();
            }
          }
        });
    contentPane.add(
        /* new JScrollPane */ (mFilterTextSearchField),
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    contentPane.add(
        new JLabel(getResourceString("plugins/TimeManagement.xml_Replace")),
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    mFilterTextReplaceField = new JTextField();
    contentPane.add(
        /* new JScrollPane */ (mFilterTextReplaceField),
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    mFilterTextReplaceField.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent pEvent) {
            if (pEvent.getKeyCode() == KeyEvent.VK_DOWN) {
              logger.info("Set Focus to table");
              timeTable.requestFocusInWindow();
            } else if (pEvent.getKeyCode() == KeyEvent.VK_UP) {
              logger.info("Set Focus to table");
              mFilterTextSearchField.requestFocusInWindow();
            }
          }
        });
    dateRenderer = new DateRenderer();
    nodeRenderer = new NodeRenderer();
    notesRenderer = new NotesRenderer();
    iconsRenderer = new IconsRenderer(getController());
    timeTable = new FlatNodeTable();
    timeTable.addKeyListener(new FlatNodeTableKeyListener());
    // double click = goto.
    timeTable.addMouseListener(new FlatNodeTableMouseAdapter());
    // disable moving:
    timeTable.getTableHeader().setReorderingAllowed(false);
    updateModel();

    sorter.setTableHeader(timeTable.getTableHeader());
    sorter.setColumnComparator(Date.class, TableSorter.COMPARABLE_COMAPRATOR);
    sorter.setColumnComparator(NodeHolder.class, TableSorter.LEXICAL_COMPARATOR);
    sorter.setColumnComparator(NotesHolder.class, TableSorter.LEXICAL_COMPARATOR);
    sorter.setColumnComparator(IconsHolder.class, TableSorter.COMPARABLE_COMAPRATOR);
    // Sort by default by date.
    sorter.setSortingStatus(DATE_COLUMN, TableSorter.ASCENDING);
    JScrollPane pane = new JScrollPane(timeTable);
    contentPane.add(
        pane,
        new GridBagConstraints(
            0,
            4,
            1,
            1,
            1.0,
            10.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    mTreeLabel = new JLabel();
    contentPane.add(
        new JScrollPane(mTreeLabel),
        new GridBagConstraints(
            0,
            5,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    // button bar
    AbstractAction selectAction =
        new AbstractAction(getResourceString("plugins/TimeManagement.xml_Select")) {
          public void actionPerformed(ActionEvent arg0) {
            selectSelectedRows();
          }
        };
    AbstractAction exportAction =
        new AbstractAction(getResourceString("plugins/TimeManagement.xml_Export")) {
          public void actionPerformed(ActionEvent arg0) {
            exportSelectedRowsAndClose();
          }
        };
    AbstractAction replaceAllAction =
        new AbstractAction(getResourceString("plugins/TimeManagement.xml_Replace_All")) {
          public void actionPerformed(ActionEvent arg0) {
            replace(new ReplaceAllInfo());
          }
        };
    AbstractAction replaceSelectedAction =
        new AbstractAction(getResourceString("plugins/TimeManagement.xml_Replace_Selected")) {
          public void actionPerformed(ActionEvent arg0) {
            replace(new ReplaceSelectedInfo());
          }
        };
    AbstractAction gotoAction =
        new AbstractAction(getResourceString("plugins/TimeManagement.xml_Goto")) {
          public void actionPerformed(ActionEvent arg0) {
            selectSelectedRows();
            disposeDialog();
          }
        };
    AbstractAction disposeAction =
        new AbstractAction(getResourceString("plugins/TimeManagement.xml_Cancel")) {
          public void actionPerformed(ActionEvent arg0) {
            disposeDialog();
          }
        };

    AbstractAction toggleViewFoldedNodesAction =
        new ToggleViewFoldedNodesAction(
            getResourceString("plugins/TimeManagement.xml_ToggleViewFoldedNodesAction"));

    /** Menu * */
    StructuredMenuHolder menuHolder = new StructuredMenuHolder();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu(getResourceString("plugins/TimeManagement.xml_menu_actions"));
    menuHolder.addMenu(menu, "main/actions/.");
    final JMenuItem selectMenuItem =
        addAccelerator(
            menuHolder.addAction(selectAction, "main/actions/select"),
            "keystroke_plugins/TimeList_select");
    final JMenuItem gotoMenuItem =
        addAccelerator(
            menuHolder.addAction(gotoAction, "main/actions/goto"),
            "keystroke_plugins/TimeList_goto");
    final JMenuItem replaceSelectedMenuItem =
        addAccelerator(
            menuHolder.addAction(replaceSelectedAction, "main/actions/replaceSelected"),
            "keystroke_plugins/TimeList_replaceSelected");
    final JMenuItem replaceAllMenuItem =
        addAccelerator(
            menuHolder.addAction(replaceAllAction, "main/actions/replaceAll"),
            "keystroke_plugins/TimeList_replaceAll");

    final JMenuItem exportMenuItem =
        addAccelerator(
            menuHolder.addAction(exportAction, "main/actions/export"),
            "keystroke_plugins/TimeList_export");
    addAccelerator(
        menuHolder.addAction(disposeAction, "main/actions/dispose"),
        "keystroke_plugins/TimeList_dispose");
    JMenu viewMenu = new JMenu(getResourceString("plugins/TimeManagement.xml_menu_view"));
    menuHolder.addMenu(viewMenu, "main/view/.");
    addAccelerator(
        menuHolder.addAction(toggleViewFoldedNodesAction, "main/view/showFoldedNodes"),
        "keystroke_plugins/TimeList_showFoldedNodes");
    menuHolder.updateMenus(menuBar, "main/");
    dialog.setJMenuBar(menuBar);

    /* Initial State */
    selectMenuItem.setEnabled(false);
    gotoMenuItem.setEnabled(false);
    exportMenuItem.setEnabled(false);
    replaceSelectedMenuItem.setEnabled(false);

    // table selection listeners to enable/disable menu actions:
    ListSelectionModel rowSM = timeTable.getSelectionModel();
    rowSM.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            // Ignore extra messages.
            if (e.getValueIsAdjusting()) return;

            ListSelectionModel lsm = (ListSelectionModel) e.getSource();
            boolean enable = !(lsm.isSelectionEmpty());
            replaceSelectedMenuItem.setEnabled(enable);
            selectMenuItem.setEnabled(enable);
            gotoMenuItem.setEnabled(enable);
            exportMenuItem.setEnabled(enable);
          }
        });
    // table selection listener to display the history of the selected nodes
    rowSM.addListSelectionListener(
        new ListSelectionListener() {
          String getNodeText(MindMapNode node) {
            return Tools.getNodeTextHierarchy(node, getMindMapController());
          }

          public void valueChanged(ListSelectionEvent e) {
            // Ignore extra messages.
            if (e.getValueIsAdjusting()) return;

            ListSelectionModel lsm = (ListSelectionModel) e.getSource();
            if (lsm.isSelectionEmpty()) {
              mTreeLabel.setText("");
              return;
            }
            int selectedRow = lsm.getLeadSelectionIndex();
            MindMapNode mindMapNode = getMindMapNode(selectedRow);
            mTreeLabel.setText(getNodeText(mindMapNode));
          }
        });

    // restore preferences:
    // Retrieve window size and column positions.
    WindowConfigurationStorage storage =
        getMindMapController().decorateDialog(dialog, WINDOW_PREFERENCE_STORAGE_PROPERTY);
    if (storage != null) {
      setTableConfiguration(storage);
    }
    dialog.setVisible(true);
  }
示例#2
0
  /*
   * (non-Javadoc)
   *
   * @see freemind.extensions.HookAdapter#startupMapHook()
   */
  public void startupMapHook() {
    super.startupMapHook();
    if (logger == null) {
      logger = freemind.main.Resources.getInstance().getLogger(this.getClass().getName());
    }
    mMyMindMapController = super.getMindMapController();
    mSimpleFormatter = new SimpleFormatter();
    // retrieve content
    final String pathname =
        getMindMapController().getFrame().getFreemindDirectory()
            + File.separator
            + FreeMind.LOG_FILE_NAME
            + ".0";
    String logFileContents = Tools.getFile(new File(pathname));
    // done.
    getMindMapController().getController().getMapModuleManager().addListener(this);
    mLogFileViewer = new JDialog(getController().getFrame().getJFrame(), false);
    mLogFileViewer.setTitle(getResourceString("LogFileViewer_title") + pathname);
    mLogFileViewer.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    mLogFileViewer.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent event) {
            disposeDialog();
          }
        });
    mCloseAction = new CloseAction();
    // the action title is changed by the following method, thus we create
    // another close action.
    Tools.addEscapeActionToDialog(mLogFileViewer, new CloseAction());

    /** Menu * */
    StructuredMenuHolder menuHolder = new StructuredMenuHolder();
    mMenuBar = new JMenuBar();
    JMenu mainItem = new JMenu(getResourceString("MapControllerPopupDialog.Actions"));
    menuHolder.addMenu(mainItem, "main/actions/.");
    Action printOperationAction = new PrintOperationAction();
    addAccelerator(
        menuHolder.addAction(printOperationAction, "main/actions/printOperationAction"),
        "keystroke_accessories/plugins/LogFileViewer_printOperationAction");
    JMenu loggerItem = new JMenu(getResourceString("MapControllerPopupDialog.LogLevels"));
    menuHolder.addMenu(loggerItem, "main/loglevel/.");
    Level[] levels =
        new Level[] {
          Level.FINEST, Level.FINER, Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.OFF
        };
    for (int i = 0; i < levels.length; i++) {
      Level level = levels[i];
      menuHolder.addAction(
          new SetLogLevelAction(level), "main/loglevel/setLogLevel_" + level.getName());
    }
    menuHolder.updateMenus(mMenuBar, "main/");
    mLogFileViewer.setJMenuBar(mMenuBar);
    mLogFileViewer.setSize(400, 400);
    mLogFileViewer.setLayout(new BorderLayout());
    mTextArea = new JTextArea(logFileContents);
    mTextArea.setEditable(false);
    mTextArea.getCaret().setVisible(true);
    // scroll at the end
    mTextArea.setCaretPosition(logFileContents.length());
    mLogFileViewer.add(new JScrollPane(mTextArea), BorderLayout.CENTER);
    // restore preferences:
    // Retrieve window size and column positions.
    LogFileViewerConfigurationStorage storage =
        (LogFileViewerConfigurationStorage)
            getMindMapController()
                .decorateDialog(mLogFileViewer, WINDOW_PREFERENCE_STORAGE_PROPERTY);
    if (storage != null) {
      // retrieve_additional_data_here
    }
    mLogFileViewer.setVisible(true);
    mUpdateTextAreaThread = new UpdateTextAreaThread();
    mUpdateTextAreaThread.start();
    LogFileLogHandler baseHandler = getBaseHandler();
    if (baseHandler != null) {
      baseHandler.setLogReceiver(this);
    }
  }