downloadtabletreemenulistener.java

来自「SANCHO」· Java 代码 · 共 787 行 · 第 1/2 页

JAVA
787
字号
  /**   * PauseAction   */  private class PauseAction extends Action {    public PauseAction() {      super(SResources.getString("m.d.pause"));      setImageDescriptor(SResources.getImageDescriptor("pause"));    }    public void run() {      for (int i = 0; i < selectedObjects.size(); i++) {        File file = (File) selectedObjects.get(i);        if (file.getFileStateEnum() != EnumFileState.PAUSED)          file.setState(EnumFileState.PAUSED);      }    }  }  /**   * CommitAction   */  private class CommitAction extends Action {    private String commitAs;    private boolean manualInput = false;    public CommitAction() {      super(SResources.getString("m.d.commitSelected"));      setImageDescriptor(SResources.getImageDescriptor("commit"));    }    public CommitAction(String commitAs) {      super(commitAs);      setImageDescriptor(SResources.getImageDescriptor("commit"));      this.commitAs = commitAs;    }    public CommitAction(boolean b) {      super(SResources.getString("m.d.commitInput"));      setImageDescriptor(SResources.getImageDescriptor("commit_question"));      manualInput = b;    }    public void run() {      if ((commitAs == null) && !manualInput) {        for (int i = 0; i < selectedObjects.size(); i++) {          File selectedFile = (File) selectedObjects.get(i);          if (selectedFile.getFileStateEnum() == EnumFileState.DOWNLOADED)            selectedFile.saveFileAs(selectedFile.getName());        }      } else {        if (manualInput) {          if (selectedFile == null)            return;          InputDialog inputDialog = new InputDialog(gView.getShell(), SResources.getString("m.d.commitAs"),              SResources.getString("m.d.commitAs"), selectedFile.getName(), null);          if (inputDialog.open() == InputDialog.OK) {            String newFileName = inputDialog.getValue();            if (!newFileName.equals(SResources.S_ES) && selectedFile != null)              selectedFile.saveFileAs(newFileName);          }        } else {          if (selectedFile != null)            selectedFile.saveFileAs(commitAs);        }      }    }  }  private class RenameAction extends Action {    private String renameAs;    private boolean manualInput = false;    public RenameAction(String renameAs) {      super(renameAs);      setImageDescriptor(SResources.getImageDescriptor(selectedFile.getProgramImageString()));      this.renameAs = renameAs;    }    public RenameAction(boolean b) {      super(SResources.getString("m.d.commitInput")); // <input filename>      setImageDescriptor(SResources.getImageDescriptor("commit_question"));      manualInput = b;    }    public void run() {      if (manualInput) {        for (int i = 0; i < selectedObjects.size(); i++) {          File selected = (File) selectedObjects.get(i);          InputDialog inputDialog = new InputDialog(gView.getShell(), SResources.getString("m.d.rename"),              SResources.getString("m.d.rename"), selected.getName(), null);          if (inputDialog.open() == InputDialog.OK) {            String newFileName = inputDialog.getValue();            if (!newFileName.equals(SResources.S_ES) && selected != null)              selected.rename(newFileName);          } else {            break;          }        }      } else {        if (selectedFile != null)          selectedFile.rename(renameAs);      }    }  }  private class EditMP3TagsAction extends Action {    public EditMP3TagsAction() {      super(SResources.getString("m.d.editMP3Tags"));      setImageDescriptor(SResources.getImageDescriptor("preferences"));    }    public void run() {      if (selectedFile == null)        return;      new EditMP3TagsDialog(gView.getShell(), gView.getCore(), selectedFile).open();    }  }  private class RequestFileInfoAction extends Action {    public RequestFileInfoAction() {      super(SResources.getString("m.d.requestFileInfo"));      setImageDescriptor(SResources.getImageDescriptor("rotate"));    }    public void run() {      for (int i = 0; i < selectedObjects.size(); i++) {        File file = (File) selectedObjects.get(i);        file.requestFileInfo();      }    }  }  /**   * ResumeAction   */  private class ResumeAction extends Action {    public ResumeAction() {      super(SResources.getString("m.d.resume"));      setImageDescriptor(SResources.getImageDescriptor("resume"));    }    public void run() {      for (int i = 0; i < selectedObjects.size(); i++) {        File file = (File) selectedObjects.get(i);        if (file.getFileStateEnum() == EnumFileState.PAUSED)          file.setState(EnumFileState.DOWNLOADING);      }    }  }  /**   * CancelAction   */  private class CancelAction extends Action {    public CancelAction() {      super(SResources.getString("m.d.cancel"));      setImageDescriptor(SResources.getImageDescriptor("cancel"));    }    public void run() {      MessageBox reallyCancel = new MessageBox(gView.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);      reallyCancel          .setMessage(SResources.getString("m.d.reallyCancel")              + ((selectedObjects.size() > 1)                  ? (" (" + selectedObjects.size() + " selected)")                  : SResources.S_ES));      int answer = reallyCancel.open();      if (answer == SWT.YES) {        for (int i = 0; i < selectedObjects.size(); i++) {          File file = (File) selectedObjects.get(i);          if (file.getFileStateEnum() != EnumFileState.DOWNLOADED)            file.setState(EnumFileState.CANCELLED);        }        deselectAll();      }    }  }  private class AddMirrorAction extends Action {    File file;    public AddMirrorAction(File file) {      super(SResources.getString("dd.f.addMirror"));      setImageDescriptor(SResources.getImageDescriptor("plus"));      this.file = file;    }    public void run() {      InputDialog dialog = new InputDialog(gView.getShell(), SResources.getString("dd.f.addMirror"),          SResources.getString("dd.f.addMirrorInfo"), SResources.S_ES, null);      dialog.open();      String result = dialog.getValue();      if (result != null)        Sancho.send(OpCodes.S_CONSOLE_MESSAGE, "mirror " + file.getId() + " " + result);    }  }  private class SetBrothersAction extends Action {    public SetBrothersAction() {      super(SResources.getString("dd.f.setBrothers"));      setImageDescriptor(SResources.getImageDescriptor("brothers"));    }    public void run() {      int[] iArray = new int[selectedObjects.size()];      for (int i = 0; i < selectedObjects.size(); i++) {        File file = (File) selectedObjects.get(i);        iArray[i] = file.getId();      }      if (Sancho.hasCollectionFactory())        Sancho.getCore().getFileCollection().setBrothers(iArray);    }  }  /**   * PriorityAction   */  private class PriorityAction extends Action {    private EnumPriority enumPriority;    public PriorityAction(EnumPriority e) {      super(e.getName().toLowerCase(), Action.AS_CHECK_BOX);      enumPriority = e;    }    public void run() {      for (int i = 0; i < selectedObjects.size(); i++) {        File file = (File) selectedObjects.get(i);        if (file.getFileStateEnum() != EnumFileState.DOWNLOADED)          file.sendPriority(enumPriority);      }    }    public boolean isChecked() {      return (selectedFile.getPriorityEnum() == enumPriority);    }  }  /**   * CustomPriorityAction   *     */  private class CustomPriorityAction extends Action {    private boolean relative;    public CustomPriorityAction(boolean relative) {      super(SResources.S_ES, Action.AS_CHECK_BOX);      this.relative = relative;      if (relative)        setText(SResources.getString("m.d.priorityRelative"));      else        setText(SResources.getString("m.d.priorityAbsolute"));    }    public void run() {      String title = SResources.getString("m.d.priority")          + " ("          + (relative ? SResources.getString("m.d.priorityRelative") : SResources              .getString("m.d.priorityAbsolute")) + ")";      PriorityInputDialog priorityInputDialog = new PriorityInputDialog(gView.getShell(), title, (relative          ? 0          : selectedFile.getPriority()));      if (priorityInputDialog.open() == PriorityInputDialog.OK) {        int newPriority = priorityInputDialog.getIntValue();        for (int i = 0; i < selectedObjects.size(); i++) {          File file = (File) selectedObjects.get(i);          if (file.getFileStateEnum() != EnumFileState.DOWNLOADED)            file.sendPriority(relative, newPriority);        }      }    }    public boolean isChecked() {      return false;    }  }  /**   * PriorityInputDialog   */  static class PriorityInputDialog extends Dialog {    int initialValue;    int intValue;    String title;    Spinner spinner;    Button okButton;    public PriorityInputDialog(Shell parentShell, String dialogTitle, int initialValue) {      super(parentShell);      this.initialValue = initialValue;      this.title = dialogTitle;    }    protected void configureShell(Shell newShell) {      super.configureShell(newShell);      newShell.setImage(SResources.getImage("ProgramIcon"));      newShell.setText(title);    }    protected void createButtonsForButtonBar(Composite parent) {      // create OK and Cancel buttons by default      okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);      createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);      spinner.setFocus();    }    protected Button getOkButton() {      return okButton;    }    protected Control createDialogArea(Composite parent) {      Composite composite = (Composite) super.createDialogArea(parent);      composite.setLayout(WidgetFactory.createGridLayout(2, 5, 5, 10, 5, false));      spinner = new Spinner(composite, SWT.NONE);      spinner.setMinimum(-200);      spinner.setMaximum(200);      spinner.setSelection(initialValue);      spinner.getText().addListener(SWT.Traverse, new Listener() {        public void handleEvent(Event event) {          if (event.detail == SWT.TRAVERSE_ESCAPE) {            //           } else if (event.detail == SWT.TRAVERSE_RETURN) {            intValue = spinner.getSelection();            close();          }        }      });      final Scale scale = new Scale(composite, SWT.HORIZONTAL);      scale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));      scale.setMinimum(0);      scale.setMaximum(200);      scale.setIncrement(1);      scale.setPageIncrement(5);      if (initialValue < -100)        scale.setSelection(0);      else if (initialValue > 100)        scale.setSelection(200);      else        scale.setSelection(initialValue + 100);      scale.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent e) {          int intValue = (scale.getSelection() - 100);          spinner.setSelection(intValue);        }      });      return composite;    }    protected void buttonPressed(int buttonId) {      intValue = spinner.getSelection();      super.buttonPressed(buttonId);    }    public int getIntValue() {      return intValue;    }  }}

⌨️ 快捷键说明

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