Esempio n. 1
0
  public void toggleBreakpoint() {
    if (isEnabled()) {
      try {
        int position = lastClickPoint != null ? viewToModel(lastClickPoint) : getCaretPosition();
        lastClickPoint = null;
        if (position >= 0) {
          String textToCaret = getDocument().getText(0, position);
          int lineCount = 0;
          for (int i = 0; i < textToCaret.length(); i++) {
            if (textToCaret.charAt(i) == '\n') {
              lineCount++;
            }
          }
          if (breakpoints.isThereBreakpoint(lineCount)) {
            breakpoints.removeBreakpoint(lineCount);
          } else {
            breakpoints.addBreakpoint(new BreakpointInfo(lineCount));
          }
        }
      } catch (BadLocationException e) {
        e.printStackTrace();
      }

      Component parent = GuiUtils.getParentOfType(this, XmlEditorScrollPane.class);
      if (parent != null) {
        ((XmlEditorScrollPane) parent).onDocChanged();
      }
      repaint();
    }
  }
Esempio n. 2
0
 /** _more_ */
 public void checkPattern() {
   String pattern = getPatternWidget().getText().trim();
   File dir = new File(getFilePathWidget().getText().trim());
   File[] list =
       dir.listFiles(
           (java.io.FileFilter)
               new PatternFileFilter(pattern, false, getHiddenWidget().isSelected()));
   StringBuffer sb = new StringBuffer("<html>");
   if ((list == null) || (list.length == 0)) {
     sb.append("<h3><center><font color=\"red\">No files match the pattern</font></center></h3>");
     sb.append("Pattern: " + pattern + "<br>");
     list = dir.listFiles();
     if (list != null) {
       for (int i = 0; i < list.length; i++) {
         if (i == 0) {
           sb.append("<hr>Example Files:<br>");
         }
         if (i > 20) {
           sb.append("&nbsp;&nbsp;...<br>\n");
           break;
         }
         sb.append("&nbsp;&nbsp;" + list[i] + "<br>\n");
       }
     }
   } else {
     for (int i = 0; i < list.length; i++) {
       if (i == 0) {
         sb.append("<h3><center>Files that match</center></h3>\n");
       }
       if (i > 20) {
         sb.append("&nbsp;&nbsp;...<br>\n");
         break;
       }
       sb.append("&nbsp;&nbsp;" + list[i] + "<br>\n");
     }
   }
   sb.append("</html>");
   GuiUtils.showDialog("Sample files", GuiUtils.inset(new JLabel(sb.toString()), 5));
 }
  /**
   * Updates progress bar progress line every time a progress event has been received.
   *
   * @param event the <tt>FileTransferProgressEvent</tt> that notified us
   */
  public void progressChanged(FileTransferProgressEvent event) {
    progressBar.setValue((int) event.getProgress());

    long transferredBytes = event.getFileTransfer().getTransferedBytes();
    long progressTimestamp = event.getTimestamp();

    ByteFormat format = new ByteFormat();
    String bytesString = format.format(transferredBytes);

    if ((progressTimestamp - lastSpeedTimestamp) >= SPEED_CALCULATE_DELAY) {
      lastProgressSpeed = Math.round(calculateProgressSpeed(transferredBytes));

      this.lastSpeedTimestamp = progressTimestamp;
      this.lastTransferredBytes = transferredBytes;
    }

    if ((progressTimestamp - lastEstimatedTimeTimestamp) >= SPEED_CALCULATE_DELAY
        && lastProgressSpeed > 0) {
      lastEstimatedTime =
          Math.round(
              calculateEstimatedTransferTime(
                  lastProgressSpeed, transferredFileSize - transferredBytes));

      lastEstimatedTimeTimestamp = progressTimestamp;
    }

    progressBar.setString(getProgressLabel(bytesString));

    if (lastProgressSpeed > 0) {
      progressSpeedLabel.setText(
          resources.getI18NString("service.gui.SPEED") + format.format(lastProgressSpeed) + "/sec");
      progressSpeedLabel.setVisible(true);
    }

    if (lastEstimatedTime > 0) {
      estimatedTimeLabel.setText(
          resources.getI18NString("service.gui.ESTIMATED_TIME")
              + GuiUtils.formatSeconds(lastEstimatedTime * 1000));
      estimatedTimeLabel.setVisible(true);
    }
  }
  void jButtonOK_actionPerformed(ActionEvent e) {
    logger.logComment("OK button pressed");
    cancelled = false;

    double threshold;

    try {
      threshold = Double.parseDouble(jTextFieldThreshold.getText());
    } catch (NumberFormatException ex) {
      GuiUtils.showErrorMessage(
          logger,
          "Please enter a number (usually -50 -> 0) for the millivolt value of the firing threshold",
          ex,
          this);
      return;
    }
    mySynProps.setThreshold(threshold);

    String selectedSynapse = (String) jComboBoxSynapseType.getSelectedItem();

    mySynProps.setSynapseType(selectedSynapse);

    this.dispose();
  }
  public LibraryBundlingEditorComponent(@NotNull Project project) {
    myProject = project;
    GuiUtils.replaceJSplitPaneWithIDEASplitter(myMainPanel);
    ((JBSplitter) myMainPanel.getComponent(0)).setProportion(0.4f);

    myRulesPanel.add(
        ToolbarDecorator.createDecorator(myRulesList)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    updateCurrentRule();
                    myRulesModel.add(new LibraryBundlificationRule());
                    myRulesList.setSelectedIndex(myRulesModel.getSize() - 1);
                    updateFields();
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    myLastSelected = -1;
                    if (myRulesModel.getSize() == 1) {
                      myRulesModel.setElementAt(new LibraryBundlificationRule(), 0);
                      myRulesList.setSelectedIndex(0);
                    } else {
                      int index = myRulesList.getSelectedIndex();
                      myRulesModel.remove(index);
                      myRulesList.setSelectedIndex(index > 0 ? index - 1 : 0);
                    }
                    updateFields();
                  }
                })
            .setMoveUpAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    updateCurrentRule();
                    myLastSelected = -1;
                    ListUtil.moveSelectedItemsUp(myRulesList);
                    updateFields();
                  }
                })
            .setMoveDownAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    updateCurrentRule();
                    myLastSelected = -1;
                    ListUtil.moveSelectedItemsDown(myRulesList);
                    updateFields();
                  }
                })
            .addExtraAction(
                new AnActionButton("Copy", PlatformIcons.COPY_ICON) {
                  @Override
                  public void actionPerformed(AnActionEvent e) {
                    updateCurrentRule();
                    int index = myRulesList.getSelectedIndex();
                    if (index >= 0) {
                      myRulesModel.add(myRulesModel.getElementAt(index).copy());
                      myRulesList.setSelectedIndex(myRulesModel.getSize() - 1);
                      updateFields();
                    }
                  }

                  @Override
                  public boolean isEnabled() {
                    return myRulesList.getSelectedIndex() >= 0;
                  }
                })
            .createPanel(),
        BorderLayout.CENTER);

    myRulesModel = new CollectionListModel<>();
    //noinspection unchecked
    myRulesList.setModel(myRulesModel);
    myRulesList.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            updateCurrentRule();
            updateFields();
          }
        });
  }
Esempio n. 6
0
  protected void reInitWholePanelIfNeeded() {
    if (!myToReInitWholePanel) return;

    myWholePanel =
        new JPanel(new BorderLayout()) {
          public void addNotify() {
            super.addNotify();
            MasterDetailsComponent.this.addNotify();

            TreeModel m = myTree.getModel();
            if (m instanceof DefaultTreeModel) {
              DefaultTreeModel model = (DefaultTreeModel) m;
              for (int eachRow = 0; eachRow < myTree.getRowCount(); eachRow++) {
                TreePath eachPath = myTree.getPathForRow(eachRow);
                Object component = eachPath.getLastPathComponent();
                if (component instanceof TreeNode) {
                  model.nodeChanged((TreeNode) component);
                }
              }
            }
          }
        };
    mySplitter.setHonorComponentsMinimumSize(true);
    myWholePanel.add(mySplitter, BorderLayout.CENTER);

    JPanel left =
        new JPanel(new BorderLayout()) {
          public Dimension getMinimumSize() {
            final Dimension original = super.getMinimumSize();
            return new Dimension(Math.max(original.width, 100), original.height);
          }
        };

    if (isNewProjectSettings()) {
      ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree);
      DefaultActionGroup group = createToolbarActionGroup();
      if (group != null) {
        decorator.setActionGroup(group);
      }
      // left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster =
          decorator.setAsUsualTopToolbar().setPanelBorder(JBUI.Borders.empty()).createPanel();
      myNorthPanel.setVisible(false);
    } else {
      left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster = ScrollPaneFactory.createScrollPane(myTree);
    }
    left.add(myMaster, BorderLayout.CENTER);
    mySplitter.setFirstComponent(left);

    final JPanel right = new JPanel(new BorderLayout());
    right.add(myDetails.getComponent(), BorderLayout.CENTER);
    if (!isNewProjectSettings()) {
      myWholePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    }

    mySplitter.setSecondComponent(right);

    GuiUtils.replaceJSplitPaneWithIDEASplitter(myWholePanel);

    myToReInitWholePanel = false;
  }
Esempio n. 7
0
  /** Constructor - creates layout. */
  public HelpFrame() {
    setTitle("Web-Harvest Help");
    setIconImage(((ImageIcon) ResourceManager.HELP32_ICON).getImage());

    this.topNode = new DefaultMutableTreeNode();
    this.treeModel = new DefaultTreeModel(this.topNode);
    try {
      String helpContent = CommonUtil.readStringFromUrl(ResourceManager.getHelpContentUrl());
      XmlNode xmlNode = XmlParser.parse(new InputSource(new StringReader(helpContent)));
      createNodes(topNode, xmlNode);
    } catch (Exception e) {
      e.printStackTrace();
      GuiUtils.showErrorMessage("Error reading help content!");
    }

    tree = new JTree(topNode);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setBorder(new EmptyBorder(5, 5, 5, 5));
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            DefaultTreeCellRenderer renderer =
                (DefaultTreeCellRenderer)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) value;
              Object userObject = defaultMutableTreeNode.getUserObject();
              if (userObject instanceof TopicInfo) {
                TopicInfo topicInfo = (TopicInfo) userObject;
                renderer.setIcon(
                    topicInfo.subtopicCount == 0
                        ? ResourceManager.HELPTOPIC_ICON
                        : ResourceManager.HELPDIR_ICON);
              }
            }
            return renderer;
          }
        });
    tree.addTreeSelectionListener(this);

    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    htmlPane.setContentType("text/html");
    htmlPane.setEditorKit(new HTMLEditorKit());
    htmlPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    JSplitPane splitPane = new ProportionalSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setResizeWeight(0.0d);
    splitPane.setBorder(null);

    JScrollPane treeScrollPane = new WHScrollPane(tree);
    treeScrollPane.getViewport().setBackground(Color.white);
    treeScrollPane.setBackground(Color.white);
    splitPane.setLeftComponent(treeScrollPane);
    splitPane.setRightComponent(new WHScrollPane(htmlPane));
    splitPane.setDividerLocation(0.3d);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(splitPane, BorderLayout.CENTER);

    pack();
  }
Esempio n. 8
0
  /**
   * _more_
   *
   * @param comps _more_
   * @param includeName _more_
   * @param includeFileCount _more_
   */
  public void getPropertyComponents(List comps, boolean includeName, boolean includeFileCount) {
    JButton directoryBtn = new JButton("Select");
    boolean isFile = false;
    if (getFile() != null) {
      File f = new File(getFile());
      isFile = f.isFile();
    }
    GuiUtils.setupFileChooser(directoryBtn, getFilePathWidget(), !isFile);
    if (isFile) {
      comps.add(GuiUtils.rLabel("File: "));
    } else {
      comps.add(GuiUtils.rLabel("Directory: "));
    }
    comps.add(
        GuiUtils.left(
            GuiUtils.centerRight(
                GuiUtils.wrap(getFilePathWidget()),
                GuiUtils.inset(directoryBtn, new Insets(0, 5, 0, 0)))));

    if (includeName) {
      comps.add(GuiUtils.rLabel("Name: "));
      comps.add(GuiUtils.left(getNameWidget()));
    }

    comps.add(GuiUtils.rLabel("File Pattern:"));
    comps.add(
        GuiUtils.left(
            GuiUtils.hbox(
                GuiUtils.wrap(GuiUtils.hbox(getPatternWidget(), getHiddenWidget())),
                GuiUtils.makeButton("Verify", this, "checkPattern"))));

    if (includeFileCount) {
      ActionListener actionListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              checkModeEnabled();
            }
          };
      comps.add(GuiUtils.rLabel("Files:"));
      fileCountButton = new JRadioButton("", mode == MODE_COUNT);
      dateRangeButton = new JRadioButton("All files in last:", mode == MODE_ABSDATERANGE);
      fileCountButton.addActionListener(actionListener);
      dateRangeButton.addActionListener(actionListener);
      ButtonGroup bg = GuiUtils.buttonGroup(fileCountButton, dateRangeButton);
      List modeComps = new ArrayList();
      modeComps.add(fileCountButton);
      modeComps.add(getFileCountWidget());
      modeComps.add(new JLabel("  "));
      modeComps.add(dateRangeButton);
      modeComps.add(getDateRangeWidget());
      modeComps.add(new JLabel(" minutes"));
      checkModeEnabled();
      comps.add(GuiUtils.left(GuiUtils.hbox(modeComps)));
    }

    comps.add(GuiUtils.rLabel("Polling:"));
    comps.add(
        GuiUtils.left(
            GuiUtils.hbox(
                getActiveWidget(),
                GuiUtils.lLabel("     Check every: "),
                GuiUtils.wrap(getIntervalWidget()),
                GuiUtils.lLabel(" minutes"))));
  }