filedetaildialog.java

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

JAVA
466
字号
        commentText.setText(SResources.S_ES);      }    });  }  public void addComment(String string) {    if (string != null)      file.setComment(string);  }  private void createMirrorGroup(Composite parent) {    Label l = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);    l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));    Composite renameComposite = new Composite(parent, SWT.NONE);    renameComposite.setLayout(WidgetFactory.createGridLayout(2, 0, 0, 4, 0, false));    renameComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));    final Text mirrorText = new Text(renameComposite, SWT.BORDER);    mirrorText.setFont(PreferenceLoader.loadFont("consoleFontData"));    GridData data = new GridData(GridData.FILL_HORIZONTAL);    data.widthHint = 1;    mirrorText.setLayoutData(data);    mirrorText.addKeyListener(new KeyAdapter() {      public void keyPressed(KeyEvent e) {        if (e.character == SWT.CR) {          addMirror(mirrorText.getText());          mirrorText.setText(SResources.S_ES);        }      }    });    Button mirrorButton = new Button(renameComposite, SWT.NONE);    mirrorButton.setText(SResources.getString("dd.f.addMirror"));    mirrorButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));    mirrorButton.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent s) {        addMirror(mirrorText.getText());        mirrorText.setText(SResources.S_ES);      }    });  }  public void addMirror(String string) {    if (string != null && string.length() > 3)      Sancho.send(OpCodes.S_CONSOLE_MESSAGE, "mirror " + file.getId() + " " + string);  }  private void createRenameGroup(Composite parent) {    Group renameGroup = new Group(parent, SWT.SHADOW_ETCHED_OUT);    renameGroup.setText(SResources.getString("dd.f.alternativeFilenames"));    renameGroup.setLayout(WidgetFactory.createGridLayout(1, 1, 1, 0, 0, false));    renameGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));    Arrays.sort(file.getNames(), String.CASE_INSENSITIVE_ORDER);    renameList = new List(renameGroup, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);    for (int i = 0; i < file.getNames().length; i++)      renameList.add(file.getNames()[i]);    GridData listGD = new GridData(GridData.FILL_HORIZONTAL);    listGD.heightHint = 80;    listGD.widthHint = 1;    renameList.setLayoutData(listGD);    renameList.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent s) {        String lItem = renameList.getSelection()[0];        renameText.setText(lItem);      }    });    Composite renameComposite = new Composite(parent, SWT.NONE);    renameComposite.setLayout(WidgetFactory.createGridLayout(2, 0, 0, 4, 0, false));    renameComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));    renameText = new Text(renameComposite, SWT.BORDER);    renameText.setText(file.getName());    renameText.setFont(PreferenceLoader.loadFont("consoleFontData"));    GridData data = new GridData(GridData.FILL_HORIZONTAL);    data.widthHint = 1;    renameText.setLayoutData(data);    renameText.addKeyListener(new KeyAdapter() {      public void keyPressed(KeyEvent e) {        if (e.character == SWT.CR) {          renameFile();          renameText.setText(SResources.S_ES);        }      }    });    Button renameButton = new Button(renameComposite, SWT.NONE);    renameButton.setText(SResources.getString("dd.f.renameFile"));    renameButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));    renameButton.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent s) {        renameFile();      }    });  }  protected Control createButtonBar(Composite parent) {    Composite mainComposite = new Composite(parent, SWT.NONE);    mainComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));    mainComposite.setLayout(WidgetFactory.createGridLayout(2, 5, 5, 0, 0, false));    Composite blankComposite = new Composite(mainComposite, SWT.NONE);    GridData gd = new GridData(GridData.FILL_HORIZONTAL);    gd.heightHint = 5;    blankComposite.setLayoutData(gd);    Composite buttonComposite = new Composite(mainComposite, SWT.NONE);    buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));    buttonComposite.setLayout(WidgetFactory.createRowLayout(false, false, false, SWT.HORIZONTAL, 0, 0, 0, 0,        5));    if ((file.getFileStateEnum() == EnumFileState.PAUSED)        || (file.getFileStateEnum() == EnumFileState.DOWNLOADING)        || (file.getFileStateEnum() == EnumFileState.QUEUED)) {      fileCancelButton = new Button(buttonComposite, SWT.NONE);      fileCancelButton.setLayoutData(new RowData());      fileCancelButton.setText(SResources.getString("dd.f.cancelFile"));      fileCancelButton.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent s) {          MessageBox reallyCancel = new MessageBox(fileCancelButton.getShell(), SWT.YES | SWT.NO              | SWT.ICON_QUESTION);          reallyCancel.setMessage(SResources.getString("dd.f.reallyCancel"));          if (reallyCancel.open() == SWT.YES) {            file.setState(EnumFileState.CANCELLED);            fileCancelButton.setEnabled(false);            fileActionButton.setEnabled(false);          }        }      });    }    fileActionButton = new Button(buttonComposite, SWT.NONE);    fileActionButton.setLayoutData(new RowData());    if ((file.getFileStateEnum() == EnumFileState.PAUSED)        || (file.getFileStateEnum() == EnumFileState.QUEUED)) {      fileActionButton.setText(SResources.getString("dd.f.resumeFile"));    } else if (file.getFileStateEnum() == EnumFileState.DOWNLOADING) {      fileActionButton.setText("  " + SResources.getString("dd.f.pauseFile"));    } else if (file.getFileStateEnum() == EnumFileState.DOWNLOADED) {      fileActionButton.setText(SResources.getString("dd.f.commitFile"));    }    // until we have an unQueue function..    if (file.getFileStateEnum() == EnumFileState.QUEUED)      fileActionButton.setEnabled(false);    fileActionButton.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent s) {        if (file.getFileStateEnum() == EnumFileState.PAUSED) {          file.setState(EnumFileState.DOWNLOADING);          fileActionButton.setText(SResources.getString("dd.f.pauseFile"));        } else if (file.getFileStateEnum() == EnumFileState.DOWNLOADING) {          file.setState(EnumFileState.PAUSED);          fileActionButton.setText(SResources.getString("dd.f.resumeFile"));        } else if (file.getFileStateEnum() == EnumFileState.DOWNLOADED) {          if (renameText.getText().equals(SResources.S_ES)) {            file.saveFileAs(file.getName());          } else {            file.saveFileAs(renameText.getText());          }          fileActionButton.setText(SResources.getString("b.ok"));          fileActionButton.setEnabled(false);        }      }    });    Button closeButton = new Button(buttonComposite, SWT.NONE);    closeButton.setFocus();    closeButton.setLayoutData(new RowData());    closeButton.setText(SResources.getString("b.close"));    closeButton.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent s) {        close();      }    });    return mainComposite;  }  /**   * Update the labels   */  public void updateLabels() {    updateLabel(clFileName, file.getName());    updateLabel(clHash, file.getMd4().toUpperCase());    updateLabel(clSize, file.getSizeString());    updateLabel(clAge, file.getAgeString());    updateLabel(clSources, Integer.toString(file.getSources()));    updateLabel(clChunks, Integer.toString(file.getNumChunks()) + " / "        + Integer.toString(file.getChunks().length()));    updateLabel(clTransferred, file.getDownloadedString());    updateLabel(clRelativeAvail, file.getRelativeAvail() + "%");    updateLabel(clLast, file.getLastSeenString());    updateLabel(clPriority, file.getPriorityString());    updateLabel(clComment, file.getComment());    if (file.getFileStateEnum() == EnumFileState.PAUSED || file.getFileStateEnum() == EnumFileState.QUEUED) {      updateLabel(clRate, file.getFileStateEnum().getName());    } else {      updateLabel(clRate, (Math.round(100.0 * (file.getRate() / 1000f)) / 100.0) + " KB/s");    }    updateLabel(clETA, file.getEtaString());  }  /*   * (non-Javadoc)   *    * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)   */  public boolean close() {    file.deleteObserver(this);    return super.close();  }}

⌨️ 快捷键说明

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