Esempio n. 1
0
  private javax.swing.JToolBar getPanelToolbar() {
    if (panelToolbar == null) {

      panelToolbar = new javax.swing.JToolBar();
      panelToolbar.setLayout(new GridBagLayout());
      panelToolbar.setEnabled(true);
      panelToolbar.setFloatable(false);
      panelToolbar.setRollover(true);
      panelToolbar.setPreferredSize(new java.awt.Dimension(800, 30));
      panelToolbar.setName(prefix + ".toolbar");

      int x = 0;

      x = this.addToolBarElements(panelToolbar, Location.start, x);

      newScanButton = getNewScanButton();

      if (newScanButton != null) {
        panelToolbar.add(newScanButton, getGBC(x++, 0));
        newScanButton.setEnabled(!Mode.safe.equals(mode));
        panelToolbar.addSeparator();
        x++;
      }

      panelToolbar.add(
          new JLabel(Constant.messages.getString(prefix + ".toolbar.progress.label")),
          getGBC(x++, 0));
      panelToolbar.add(getProgressSelect(), getGBC(x++, 0));

      x = this.addToolBarElements(panelToolbar, Location.beforeButtons, x);

      panelToolbar.add(getPauseScanButton(), getGBC(x++, 0));
      panelToolbar.add(getStopScanButton(), getGBC(x++, 0));

      x = this.addToolBarElements(panelToolbar, Location.beforeProgressBar, x);

      panelToolbar.add(getProgressBar(), getGBC(x++, 0, 1.0, new Insets(0, 5, 0, 5)));

      panelToolbar.add(getClearScansButton(), getGBC(x++, 0));

      panelToolbar.add(getActiveScansNameLabel(), getGBC(x++, 0));
      panelToolbar.add(getActiveScansValueLabel(), getGBC(x++, 0));

      x = this.addToolBarElements(panelToolbar, Location.afterProgressBar, x);

      panelToolbar.add(new JLabel(), getGBC(x++, 0, 1.0, new Insets(0, 0, 0, 0))); // Spacer
      panelToolbar.add(getOptionsButton(), getGBC(x++, 0));
    }
    return panelToolbar;
  }
Esempio n. 2
0
  private void setupToolBar() // {{{
      {
    toolbar.setFloatable(false);
    toolbar.setRollover(true);
    toolbar.setName("listToolbar"); // NOI18N
    toolbar.setPreferredSize(new java.awt.Dimension(100, 18));

    btnPrev.setIcon(resourceMap.getIcon("btnPrev.icon")); // NOI18N
    btnPrev.setText(resourceMap.getString("btnPrev.text")); // NOI18N
    btnPrev.setToolTipText(resourceMap.getString("btnPrev.toolTipText")); // NOI18N
    btnPrev.setFocusable(false);
    btnPrev.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btnPrev.setMargin(new java.awt.Insets(2, 2, 2, 2));
    btnPrev.setName("btnPrev"); // NOI18N
    btnPrev.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    toolbar.add(btnPrev);

    jSeparator3.setMaximumSize(new java.awt.Dimension(1000, 10));
    jSeparator3.setName("jSeparator3"); // NOI18N
    toolbar.add(jSeparator3);

    btnAddList.setAction(actionMap.get("addNewList"));
    btnAddList.setText(resourceMap.getString("btnAddList.text"));
    btnAddList.setIcon(resourceMap.getIcon("btnAddList.icon"));
    btnAddList.setToolTipText(resourceMap.getString("btnAddList.toolTipText"));
    btnAddList.setMargin(new java.awt.Insets(2, 2, 2, 2));
    toolbar.add(btnAddList);

    btnDeleteList.setAction(actionMap.get("deleteList"));
    btnDeleteList.setText(resourceMap.getString("btnDeleteList.text"));
    btnDeleteList.setIcon(resourceMap.getIcon("btnDeleteList.icon"));
    btnDeleteList.setToolTipText(resourceMap.getString("btnDeleteList.toolTipText"));
    btnDeleteList.setMargin(new java.awt.Insets(2, 2, 2, 2));
    toolbar.add(btnDeleteList);

    separatorRight.setMaximumSize(new java.awt.Dimension(1000, 10));
    separatorRight.setName("separatorRight"); // NOI18N
    toolbar.add(separatorRight);

    btnNext.setIcon(resourceMap.getIcon("btnNext.icon")); // NOI18N
    btnNext.setToolTipText(resourceMap.getString("btnNext.toolTipText")); // NOI18N
    btnNext.setFocusable(false);
    btnNext.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btnNext.setLabel(resourceMap.getString("btnNext.label")); // NOI18N
    btnNext.setMargin(new java.awt.Insets(2, 2, 2, 2));
    btnNext.setName("btnNext"); // NOI18N
    btnNext.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    toolbar.add(btnNext);
  } // }}}
Esempio n. 3
0
  private javax.swing.JToolBar getPanelToolbar() {
    if (panelToolbar == null) {

      panelToolbar = new javax.swing.JToolBar();
      panelToolbar.setLayout(new java.awt.GridBagLayout());
      panelToolbar.setEnabled(true);
      panelToolbar.setFloatable(false);
      panelToolbar.setRollover(true);
      panelToolbar.setPreferredSize(new java.awt.Dimension(800, 30));
      panelToolbar.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
      panelToolbar.setName("Search Toolbar");

      GridBagConstraints gridBagConstraintsX = new GridBagConstraints();
      gridBagConstraintsX.gridx = 6;
      gridBagConstraintsX.gridy = 0;
      gridBagConstraintsX.weightx = 1.0;
      gridBagConstraintsX.weighty = 1.0;
      gridBagConstraintsX.insets = new java.awt.Insets(0, 0, 0, 0);
      gridBagConstraintsX.anchor = java.awt.GridBagConstraints.EAST;
      gridBagConstraintsX.fill = java.awt.GridBagConstraints.HORIZONTAL;

      JLabel t1 = new JLabel();
      JLabel inverseTooltip =
          new JLabel(Constant.messages.getString("search.toolbar.label.inverse"));
      inverseTooltip.setToolTipText(Constant.messages.getString("search.toolbar.tooltip.inverse"));

      panelToolbar.add(getRegExField(), newGBC(0));
      panelToolbar.add(getSearchType(), newGBC(1));
      panelToolbar.add(inverseTooltip, newGBC(2));
      panelToolbar.add(getChkInverse(), newGBC(3));
      panelToolbar.add(getBtnSearch(), newGBC(4));
      panelToolbar.add(getBtnNext(), newGBC(5));
      panelToolbar.add(getBtnPrev(), newGBC(6));
      panelToolbar.add(t1, gridBagConstraintsX);
    }
    return panelToolbar;
  }
Esempio n. 4
0
  /**
   * Constructor for the CakeGUI
   *
   * @param c The CakeCal to use for this GUI.
   */
  public CakeGUI(CakeCal c) {
    topRight = new CardLayout();
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {

    }

    openState = false;

    // window = new JFrame("Cake Calendar - " + fileName);
    calendar = c;

    // ed = new EventDialog(this);
    // panelEvent = new EventDialog(this);
    panelEvent = new AddEventDialog(this);
    // updateEv = new UpdateEventDialog(this);
    updateEv = new UpdateEventDialog(this);

    set = new SettingsDialog(this);

    // initialize the classes for the different views
    mview = new MonthView(this);
    weekView = new WeekView(this);
    dayView = new DayView(true, this);

    // initialize the three JPanels which will swap out of the center
    initializeCenter();

    // Initialize the buttons in the top right panel
    JButton today = new JButton("Today");
    JButton day = new JButton("Day");
    JButton week = new JButton("Week");
    JButton month = new JButton("Month");
    JButton addEvent = new JButton("Add Event");

    // add action listeners to the buttons
    today.addActionListener(this);
    day.addActionListener(this);
    week.addActionListener(this);
    month.addActionListener(this);
    addEvent.addActionListener(this);

    // add the cards to the top right panel
    topRightPanel = new JPanel(this.topRight);
    topRightPanel.add(panelEvent.thePane, "Add Event");
    topRightPanel.add(updateEv.thePane, "Update Event");
    topRight.show(topRightPanel, DAY);

    FlowLayout f = new FlowLayout();
    f.setAlignment(FlowLayout.LEFT);
    JPanel top = new JPanel(f);
    buttonToolBar.add(month);
    buttonToolBar.add(week);
    buttonToolBar.add(day);
    buttonToolBar.add(today);
    buttonToolBar.setLayout(new GridLayout());
    top.add(buttonToolBar);
    buttonToolBar.setPreferredSize(new Dimension(900, 32));

    // initialize the bottom right panel
    bottomRight = new JPanel();
    bottomRight.setLayout(new BorderLayout());

    // initialize the top part of the bottom right panel
    JPanel bottomRightTop = new JPanel();
    bottomRightTop.setLayout(new BorderLayout());

    JButton monthPrevious = new JButton("<");
    monthPrevious.addActionListener(this);
    JButton monthNext = new JButton(">");
    monthNext.addActionListener(this);
    JButton yearPrevious = new JButton("<<");
    yearPrevious.addActionListener(this);
    JButton yearNext = new JButton(">>");
    yearNext.addActionListener(this);

    JPanel leftButtons = new JPanel();
    leftButtons.setLayout(new GridLayout(1, 2));
    leftButtons.add(yearPrevious);
    leftButtons.add(monthPrevious);
    bottomRightTop.add(leftButtons, BorderLayout.WEST);

    JPanel rightButtons = new JPanel();
    rightButtons.setLayout(new GridLayout(1, 2));
    rightButtons.add(monthNext);
    rightButtons.add(yearNext);
    bottomRightTop.add(rightButtons, BorderLayout.EAST);

    yearField = new JTextField();
    yearField.setFont(new Font("Verdana", Font.BOLD, 12));
    yearField.setHorizontalAlignment(JTextField.CENTER);
    yearField.setDocument(new JTextFieldLimit(4));
    yearField.setText("YYYY");
    yearField.setActionCommand("YYYY");
    yearField.addActionListener(this);

    bottomRightTop.add(yearField, BorderLayout.CENTER);

    // ------------TITLED BORDER-------------
    String shortDate = " " + curMonths[currentMonth - 1] + ", " + currentYear + " ";

    Border line = BorderFactory.createLineBorder(Color.BLACK);
    title = BorderFactory.createTitledBorder(line, shortDate);
    title.setTitleJustification(TitledBorder.RIGHT);
    title.setTitleFont(new Font("Verdana", Font.BOLD, 12));

    bottomRight.setBorder(title);
    // ------------END OF---TITLED BORDER-------------

    bottomRight.add(bottomRightTop, BorderLayout.NORTH);
    bottomRight.add(this.smallMonth, BorderLayout.CENTER);

    JPanel right = new JPanel();

    right.setLayout(new GridBagLayout());
    GridBagConstraints g = new GridBagConstraints();
    g.gridx = 0;
    g.gridy = 0;
    g.weighty = 1;
    g.weightx = 1;
    g.fill = GridBagConstraints.BOTH;
    right.add(topRightPanel, g);
    g = new GridBagConstraints();
    g.gridx = 0;
    g.gridy = 1;
    g.weightx = 1;
    g.weighty = 0;
    g.fill = GridBagConstraints.HORIZONTAL;
    right.add(bottomRight, g);

    p.setLayout(new BorderLayout());
    p.add(top, BorderLayout.NORTH);
    p.add(BorderLayout.EAST, right);
    p.add(BorderLayout.CENTER, this.center);
    buttonToolBar.setFloatable(false);

    viewChanger.show(center, MONTH);
    updateCurrentEvents();
    updateDays();
    mview.updateDays();
  }
Esempio n. 5
0
  private void setupRightSideToolBar() {
    JToolBar fixedTools = new JToolBar();
    fixedTools.setOrientation(JToolBar.HORIZONTAL);

    JButton cutB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "cut.png").getImage()));
    cutB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    cutB.setToolTipText("Cut selected (Ctrl+X)");
    JButton copyB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "page_copy.png").getImage()));
    copyB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    copyB.setToolTipText("Copy selected (Ctrl+C)");
    JButton pasteB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "paste_plain.png").getImage()));
    pasteB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    pasteB.setToolTipText("Paste from clipboard (Ctrl+V)");
    JButton deleteB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "delete.png").getImage()));
    deleteB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    deleteB.setToolTipText("Delete selected (DEL)");
    final JToggleButton snapToGridB =
        new JToggleButton(new ImageIcon(loadIcon(ICON_PATH + "shape_handles.png").getImage()));
    // m_snapToGridB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    snapToGridB.setToolTipText("Snap to grid (Ctrl+G)");
    JButton saveB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "disk.png").getImage()));
    saveB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    saveB.setToolTipText("Save layout (Ctrl+S)");
    JButton saveBB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "disk_multiple.png").getImage()));
    saveBB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    saveBB.setToolTipText("Save layout with new name");
    JButton loadB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "folder_add.png").getImage()));
    loadB.setToolTipText("Open (Ctrl+O)");
    loadB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    JButton newB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "page_add.png").getImage()));
    newB.setToolTipText("New layout (Ctrl+N)");
    newB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    newB.setEnabled(m_mainPerspective.getAllowMultipleTabs());
    final JButton helpB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "help.png").getImage()));
    helpB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    helpB.setToolTipText("Display help (Ctrl+H)");
    JButton togglePerspectivesB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "cog_go.png").getImage()));
    togglePerspectivesB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    togglePerspectivesB.setToolTipText("Show/hide perspectives toolbar (Ctrl+P)");
    final JButton templatesB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "application_view_tile.png").getImage()));
    templatesB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    templatesB.setToolTipText("Load a template layout");
    JButton noteB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "note_add.png").getImage()));
    noteB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    noteB.setToolTipText("Add a note to the layout (Ctrl+I)");
    JButton selectAllB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "shape_group.png").getImage()));
    selectAllB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    selectAllB.setToolTipText("Select all (Ctrl+A)");
    final JButton zoomInB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "zoom_in.png").getImage()));
    zoomInB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    zoomInB.setToolTipText("Zoom in (Ctrl++)");
    final JButton zoomOutB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "zoom_out.png").getImage()));
    zoomOutB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    zoomOutB.setToolTipText("Zoom out (Ctrl+-)");
    JButton undoB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "arrow_undo.png").getImage()));
    undoB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    undoB.setToolTipText("Undo (Ctrl+U)");

    // actions
    final Action saveAction =
        new AbstractAction("Save") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentTabIndex() >= 0) {
              m_mainPerspective.saveLayout(m_mainPerspective.getCurrentTabIndex(), false);
            }
          }
        };
    KeyStroke saveKey = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Save", saveAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(saveKey, "Save");
    saveB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveAction.actionPerformed(e);
          }
        });

    KeyStroke saveAsKey = KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK);
    final Action saveAsAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.saveLayout(m_mainPerspective.getCurrentTabIndex(), true);
          }
        };
    m_mainPerspective.getActionMap().put("SaveAS", saveAsAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(saveAsKey, "SaveAS");

    saveBB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveAsAction.actionPerformed(e);
          }
        });

    final Action openAction =
        new AbstractAction("Open") {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.loadLayout();
          }
        };
    KeyStroke openKey = KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Open", openAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(openKey, "Open");
    loadB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            openAction.actionPerformed(e);
          }
        });

    final Action newAction =
        new AbstractAction("New") {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.addUntitledTab();
          }
        };
    KeyStroke newKey = KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("New", newAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(newKey, "New");
    newB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            newAction.actionPerformed(ae);
          }
        });

    final Action selectAllAction =
        new AbstractAction("SelectAll") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getCurrentLayout().numSteps() > 0) {
              List<StepVisual> newSelected = newSelected = new ArrayList<StepVisual>();
              newSelected.addAll(m_mainPerspective.getCurrentLayout().getRenderGraph());

              // toggle
              if (newSelected.size()
                  == m_mainPerspective.getCurrentLayout().getSelectedSteps().size()) {
                // unselect all
                m_mainPerspective.getCurrentLayout().setSelectedSteps(new ArrayList<StepVisual>());
              } else {
                // select all
                m_mainPerspective.getCurrentLayout().setSelectedSteps(newSelected);
              }
              m_mainPerspective.revalidate();
              m_mainPerspective.repaint();
              m_mainPerspective.notifyIsDirty();
            }
          }
        };
    KeyStroke selectAllKey = KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("SelectAll", selectAllAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(selectAllKey, "SelectAll");
    selectAllB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            selectAllAction.actionPerformed(e);
          }
        });

    final Action zoomInAction =
        new AbstractAction("ZoomIn") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              int z = m_mainPerspective.getCurrentLayout().getZoomSetting();
              z += 25;
              zoomOutB.setEnabled(true);
              if (z >= 200) {
                z = 200;
                zoomInB.setEnabled(false);
              }
              m_mainPerspective.getCurrentLayout().setZoomSetting(z);
              m_mainPerspective.revalidate();
              m_mainPerspective.repaint();
              m_mainPerspective.notifyIsDirty();
            }
          }
        };
    KeyStroke zoomInKey = KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("ZoomIn", zoomInAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(zoomInKey, "ZoomIn");
    zoomInB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            zoomInAction.actionPerformed(e);
          }
        });

    final Action zoomOutAction =
        new AbstractAction("ZoomOut") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              int z = m_mainPerspective.getCurrentLayout().getZoomSetting();
              z -= 25;
              zoomInB.setEnabled(true);
              if (z <= 50) {
                z = 50;
                zoomOutB.setEnabled(false);
              }
              m_mainPerspective.getCurrentLayout().setZoomSetting(z);
              m_mainPerspective.revalidate();
              m_mainPerspective.repaint();
              m_mainPerspective.notifyIsDirty();
            }
          }
        };
    KeyStroke zoomOutKey = KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("ZoomOut", zoomOutAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(zoomOutKey, "ZoomOut");
    zoomOutB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            zoomOutAction.actionPerformed(e);
          }
        });

    final Action cutAction =
        new AbstractAction("Cut") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getCurrentLayout().getSelectedSteps().size() > 0) {
              try {
                m_mainPerspective.getCurrentLayout().copySelectedStepsToClipboard();
                m_mainPerspective.getCurrentLayout().removeSelectedSteps();
              } catch (WekaException e1) {
                m_mainPerspective.showErrorDialog(e1);
              }
            }
          }
        };
    KeyStroke cutKey = KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Cut", cutAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(cutKey, "Cut");
    cutB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            cutAction.actionPerformed(e);
          }
        });

    final Action deleteAction =
        new AbstractAction("Delete") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              try {
                m_mainPerspective.getCurrentLayout().removeSelectedSteps();
              } catch (WekaException e1) {
                m_mainPerspective.showErrorDialog(e1);
              }
            }
          }
        };
    KeyStroke deleteKey = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
    m_mainPerspective.getActionMap().put("Delete", deleteAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(deleteKey, "Delete");
    deleteB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            deleteAction.actionPerformed(e);
          }
        });

    final Action copyAction =
        new AbstractAction("Copy") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getCurrentLayout().getSelectedSteps().size() > 0) {
              try {
                m_mainPerspective.getCurrentLayout().copySelectedStepsToClipboard();
                m_mainPerspective.getCurrentLayout().setSelectedSteps(new ArrayList<StepVisual>());
              } catch (WekaException e1) {
                m_mainPerspective.showErrorDialog(e1);
              }
            }
          }
        };
    KeyStroke copyKey = KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Copy", copyAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(copyKey, "Copy");
    copyB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            copyAction.actionPerformed(e);
          }
        });

    final Action pasteAction =
        new AbstractAction("Paste") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null
                && m_mainPerspective.getPasteBuffer().length() > 0) {
              m_mainPerspective.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
              m_mainPerspective
                  .getCurrentLayout()
                  .setFlowLayoutOperation(VisibleLayout.LayoutOperation.PASTING);
            }
          }
        };
    KeyStroke pasteKey = KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Paste", pasteAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(pasteKey, "Paste");
    pasteB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            pasteAction.actionPerformed(e);
          }
        });

    final Action snapAction =
        new AbstractAction("Snap") {
          @Override
          public void actionPerformed(ActionEvent e) {
            // toggle first
            // snapToGridB.setSelected(!snapToGridB.isSelected());
            if (snapToGridB.isSelected()) {
              if (m_mainPerspective.getCurrentLayout() != null) {
                m_mainPerspective.getCurrentLayout().snapSelectedToGrid();
              }
            }
          }
        };
    KeyStroke snapKey = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Snap", snapAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(snapKey, "Snap");
    snapToGridB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (snapToGridB.isSelected()) {
              snapAction.actionPerformed(e);
            }
          }
        });

    final Action noteAction =
        new AbstractAction("Note") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective.getCurrentLayout().initiateAddNote();
            }
          }
        };
    KeyStroke noteKey = KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Note", noteAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(noteKey, "Note");
    noteB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            noteAction.actionPerformed(e);
          }
        });

    final Action undoAction =
        new AbstractAction("Undo") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective.getCurrentLayout().popAndLoadUndo();
            }
          }
        };
    KeyStroke undoKey = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Undo", undoAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(undoKey, "Undo");
    undoB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            undoAction.actionPerformed(e);
          }
        });

    final Action helpAction =
        new AbstractAction("Help") {
          @Override
          public void actionPerformed(ActionEvent e) {
            popupHelp(helpB);
          }
        };
    KeyStroke helpKey = KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Help", helpAction);
    m_mainPerspective.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(helpKey, "Help");
    helpB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae) {
            helpAction.actionPerformed(ae);
          }
        });

    templatesB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            // createTemplateMenuPopup();
            PopupMenu popupMenu = new PopupMenu();
            List<String> builtinTemplates =
                m_mainPerspective.getTemplateManager().getBuiltinTemplateDescriptions();
            List<String> pluginTemplates =
                m_mainPerspective.getTemplateManager().getPluginTemplateDescriptions();

            for (final String desc : builtinTemplates) {
              MenuItem menuItem = new MenuItem(desc);
              menuItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      try {
                        Flow templateFlow =
                            m_mainPerspective.getTemplateManager().getTemplateFlow(desc);
                        m_mainPerspective.addTab(desc);
                        m_mainPerspective.getCurrentLayout().setFlow(templateFlow);
                      } catch (WekaException ex) {
                        m_mainPerspective.showErrorDialog(ex);
                      }
                    }
                  });
              popupMenu.add(menuItem);
            }
            if (builtinTemplates.size() > 0 && pluginTemplates.size() > 0) {
              popupMenu.addSeparator();
            }
            for (final String desc : pluginTemplates) {
              MenuItem menuItem = new MenuItem(desc);
              menuItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      try {
                        Flow templateFlow =
                            m_mainPerspective.getTemplateManager().getTemplateFlow(desc);
                        m_mainPerspective.addTab(desc);
                        m_mainPerspective.getCurrentLayout().setFlow(templateFlow);
                      } catch (WekaException ex) {
                        m_mainPerspective.showErrorDialog(ex);
                      }
                    }
                  });
              popupMenu.add(menuItem);
            }
            templatesB.add(popupMenu);
            popupMenu.show(templatesB, 0, 0);
          }
        });
    templatesB.setEnabled(m_mainPerspective.getTemplateManager().numTemplates() > 0);

    final Action togglePerspectivesAction =
        new AbstractAction("Toggle perspectives") {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (!Utils.getDontShowDialog("weka.gui.knowledgeflow.PerspectiveInfo")) {
              JCheckBox dontShow = new JCheckBox("Do not show this message again");
              Object[] stuff = new Object[2];
              stuff[0] =
                  "Perspectives are environments that take over the\n"
                      + "Knowledge Flow UI and provide major additional functionality.\n"
                      + "Many perspectives will operate on a set of instances. Instances\n"
                      + "Can be sent to a perspective by placing a DataSource on the\n"
                      + "layout canvas, configuring it and then selecting \"Send to perspective\"\n"
                      + "from the contextual popup menu that appears when you right-click on\n"
                      + "it. Several perspectives are built in to the Knowledge Flow, others\n"
                      + "can be installed via the package manager.\n";
              stuff[1] = dontShow;

              JOptionPane.showMessageDialog(
                  m_mainPerspective, stuff, "Perspective information", JOptionPane.OK_OPTION);

              if (dontShow.isSelected()) {
                try {
                  Utils.setDontShowDialog("weka.gui.Knowledgeflow.PerspectiveInfo");
                } catch (Exception ex) {
                  // quietly ignore
                }
              }
            }
            if (m_mainPerspective.getMainApplication().isPerspectivesToolBarVisible()) {
              m_mainPerspective.getMainApplication().hidePerspectivesToolBar();
            } else {
              m_mainPerspective.getMainApplication().showPerspectivesToolBar();
            }
            m_mainPerspective.revalidate();
            m_mainPerspective.notifyIsDirty();
          }
        };
    KeyStroke togglePerspectivesKey =
        KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK);
    m_mainPerspective.getActionMap().put("Toggle perspectives", togglePerspectivesAction);
    m_mainPerspective
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(togglePerspectivesKey, "Toggle perspectives");
    togglePerspectivesB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            togglePerspectivesAction.actionPerformed(e);
          }
        });

    addWidgetToToolBar(fixedTools, Widgets.ZOOM_IN_BUTTON.toString(), zoomInB);
    addMenuItemToMenu("View", Widgets.ZOOM_IN_BUTTON.toString(), zoomInAction, zoomInKey);
    addWidgetToToolBar(fixedTools, Widgets.ZOOM_OUT_BUTTON.toString(), zoomOutB);
    addMenuItemToMenu("View", Widgets.ZOOM_OUT_BUTTON.toString(), zoomOutAction, zoomOutKey);
    fixedTools.addSeparator();
    addWidgetToToolBar(fixedTools, Widgets.SELECT_ALL_BUTTON.toString(), selectAllB);
    addWidgetToToolBar(fixedTools, Widgets.CUT_BUTTON.toString(), cutB);
    addMenuItemToMenu("Edit", Widgets.CUT_BUTTON.toString(), cutAction, cutKey);
    addWidgetToToolBar(fixedTools, Widgets.COPY_BUTTON.toString(), copyB);
    addMenuItemToMenu("Edit", Widgets.COPY_BUTTON.toString(), copyAction, copyKey);
    addMenuItemToMenu("Edit", Widgets.PASTE_BUTTON.toString(), pasteAction, pasteKey);
    addWidgetToToolBar(fixedTools, Widgets.DELETE_BUTTON.toString(), deleteB);
    addMenuItemToMenu("Edit", Widgets.DELETE_BUTTON.toString(), deleteAction, deleteKey);
    addWidgetToToolBar(fixedTools, Widgets.PASTE_BUTTON.toString(), pasteB);
    addWidgetToToolBar(fixedTools, Widgets.UNDO_BUTTON.toString(), undoB);
    addMenuItemToMenu("Edit", Widgets.UNDO_BUTTON.toString(), undoAction, undoKey);
    addWidgetToToolBar(fixedTools, Widgets.NOTE_BUTTON.toString(), noteB);
    addMenuItemToMenu("Insert", Widgets.NOTE_BUTTON.toString(), noteAction, noteKey);
    fixedTools.addSeparator();
    addWidgetToToolBar(fixedTools, Widgets.SNAP_TO_GRID_BUTTON.toString(), snapToGridB);
    fixedTools.addSeparator();
    addWidgetToToolBar(fixedTools, Widgets.NEW_FLOW_BUTTON.toString(), newB);
    addMenuItemToMenu("File", Widgets.NEW_FLOW_BUTTON.toString(), newAction, newKey);
    addWidgetToToolBar(fixedTools, Widgets.SAVE_FLOW_BUTTON.toString(), saveB);
    addMenuItemToMenu("File", Widgets.LOAD_FLOW_BUTTON.toString(), openAction, openKey);
    addMenuItemToMenu("File", Widgets.SAVE_FLOW_BUTTON.toString(), saveAction, saveKey);
    addWidgetToToolBar(fixedTools, Widgets.SAVE_FLOW_AS_BUTTON.toString(), saveBB);
    addMenuItemToMenu("File", Widgets.SAVE_FLOW_AS_BUTTON.toString(), saveAction, saveAsKey);
    addWidgetToToolBar(fixedTools, Widgets.LOAD_FLOW_BUTTON.toString(), loadB);
    addWidgetToToolBar(fixedTools, Widgets.TEMPLATES_BUTTON.toString(), templatesB);
    fixedTools.addSeparator();
    addWidgetToToolBar(
        fixedTools, Widgets.TOGGLE_PERSPECTIVES_BUTTON.toString(), togglePerspectivesB);
    addWidgetToToolBar(fixedTools, Widgets.HELP_BUTTON.toString(), helpB);
    Dimension d = undoB.getPreferredSize();
    Dimension d2 = fixedTools.getMinimumSize();
    Dimension d3 = new Dimension(d2.width, d.height + 4);
    fixedTools.setPreferredSize(d3);
    fixedTools.setMaximumSize(d3);
    fixedTools.setFloatable(false);
    add(fixedTools, BorderLayout.EAST);
  }
Esempio n. 6
0
  private void setupLeftSideToolBar() {
    JToolBar fixedTools2 = new JToolBar();
    fixedTools2.setOrientation(JToolBar.HORIZONTAL);
    fixedTools2.setFloatable(false);

    JButton playB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "resultset_next.png").getImage()));
    playB.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    playB.setToolTipText("Run this flow (all start points launched in parallel)");
    final Action playParallelAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              boolean proceed = true;
              if (m_mainPerspective.isMemoryLow()) {
                proceed = m_mainPerspective.showMemoryIsLow();
              }
              if (proceed) {
                try {
                  m_mainPerspective.getCurrentLayout().executeFlow(false);
                } catch (WekaException e1) {
                  m_mainPerspective.showErrorDialog(e1);
                }
              }
            }
          }
        };
    playB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            playParallelAction.actionPerformed(e);
          }
        });

    JButton playBB =
        new JButton(new ImageIcon(loadIcon(ICON_PATH + "resultset_last.png").getImage()));
    playBB.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    playBB.setToolTipText("Run this flow (start points launched sequentially)");
    final Action playSequentialAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              if (!Utils.getDontShowDialog("weka.gui.knowledgeflow.SequentialRunInfo")) {
                JCheckBox dontShow = new JCheckBox("Do not show this message again");
                Object[] stuff = new Object[2];
                stuff[0] =
                    "The order that data sources are launched in can be\n"
                        + "specified by setting a custom name for each data source that\n"
                        + "that includes a number. E.g. \"1:MyArffLoader\". To set a name,\n"
                        + "right-click over a data source and select \"Set name\"\n\n"
                        + "If the prefix is not specified, then the order of execution\n"
                        + "will correspond to the order that the components were added\n"
                        + "to the layout. Note that it is also possible to prevent a data\n"
                        + "source from executing by prefixing its name with a \"!\". E.g\n"
                        + "\"!:MyArffLoader\"";
                stuff[1] = dontShow;

                JOptionPane.showMessageDialog(
                    m_mainPerspective,
                    stuff,
                    "Sequential execution information",
                    JOptionPane.OK_OPTION);

                if (dontShow.isSelected()) {
                  try {
                    Utils.setDontShowDialog("weka.gui.knowledgeFlow.SequentialRunInfo");
                  } catch (Exception e1) {
                  }
                }
              }

              boolean proceed = true;
              if (m_mainPerspective.isMemoryLow()) {
                proceed = m_mainPerspective.showMemoryIsLow();
              }
              if (proceed) {
                try {
                  m_mainPerspective.getCurrentLayout().executeFlow(true);
                } catch (WekaException e1) {
                  m_mainPerspective.showErrorDialog(e1);
                }
              }
            }
          }
        };
    playBB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            playSequentialAction.actionPerformed(e);
          }
        });

    JButton stopB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "shape_square.png").getImage()));
    stopB.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
    stopB.setToolTipText("Stop all execution");
    final Action stopAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective
                  .getCurrentLayout()
                  .getLogPanel()
                  .statusMessage("@!@[KnowledgeFlow]|Attempting to stop all components...");
              m_mainPerspective.getCurrentLayout().stopFlow();
              m_mainPerspective
                  .getCurrentLayout()
                  .getLogPanel()
                  .statusMessage("@!@[KnowledgeFlow]|OK.");
            }
          }
        };

    stopB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            stopAction.actionPerformed(e);
          }
        });

    JButton pointerB = new JButton(new ImageIcon(loadIcon(ICON_PATH + "cursor.png").getImage()));
    pointerB.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    pointerB.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_mainPerspective.setPalleteSelectedStep(null);
            m_mainPerspective.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

            m_mainPerspective.clearDesignPaletteSelection();

            if (m_mainPerspective.getCurrentLayout() != null) {
              m_mainPerspective
                  .getCurrentLayout()
                  .setFlowLayoutOperation(VisibleLayout.LayoutOperation.NONE);
            }
          }
        });

    addWidgetToToolBar(fixedTools2, Widgets.POINTER_BUTTON.toString(), pointerB);
    addWidgetToToolBar(fixedTools2, Widgets.PLAY_PARALLEL_BUTTON.toString(), playB);
    addWidgetToToolBar(fixedTools2, Widgets.PLAY_SEQUENTIAL_BUTTON.toString(), playBB);
    addWidgetToToolBar(fixedTools2, Widgets.STOP_BUTTON.toString(), stopB);
    Dimension d = playB.getPreferredSize();
    Dimension d2 = fixedTools2.getMinimumSize();
    Dimension d3 = new Dimension(d2.width, d.height + 4);
    fixedTools2.setPreferredSize(d3);
    fixedTools2.setMaximumSize(d3);
    add(fixedTools2, BorderLayout.WEST);
  }