⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 previewproxybase.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    toolbar.add(createButton(nextPageAction));
    toolbar.add(createButton(lastPageAction));
    toolbar.addSeparator();
    toolbar.add(createButton(zoomInAction));
    toolbar.add(createButton(zoomOutAction));
    toolbar.addSeparator();
    toolbar.add(createZoomPane());
    toolbar.addSeparator();
    toolbar.add(createButton(aboutAction));

    return toolbar;
  }

  /**
   * Returns true, if the toolbar is floatable, false otherwise.
   *
   * @return true when the toolbar is floatable.
   */
  public boolean isToolbarFloatable()
  {
    return toolbar.isFloatable();
  }

  /**
   * Defines whether the toolbar is floatable.
   *
   * @param b  a flag that indicates whether or not the toolbar is floatable.
   */
  public void setToolbarFloatable(final boolean b)
  {
    toolbar.setFloatable(b);
  }

  /**
   * Creates a panel containing a combobox with available zoom-values.
   *
   * @return a panel containing a combobox with zoom values.
   */
  protected JComponent createZoomPane()
  {
    final DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (int i = 0; i < ZOOM_FACTORS.length; i++)
    {
      model.addElement(String.valueOf((int) (ZOOM_FACTORS[i] * 100)) + " %");
    }
    zoomSelect = new JComboBox(model);
    zoomSelect.setActionCommand("ZoomSelect");
    zoomSelect.setSelectedIndex(DEFAULT_ZOOM_INDEX);
    zoomSelect.addActionListener(createZoomSelectAction());
    zoomSelect.setAlignmentX(Component.RIGHT_ALIGNMENT);

    final JPanel zoomPane = new JPanel();
    zoomPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    zoomPane.add(zoomSelect);

    return zoomPane;
  }

  /**
   * Updates the states of all buttons to reflect the state of the assigned ReportPane.
   */
  protected void validateButtons()
  {
    if (lockInterface == true)
    {
      // do not reenable any buttons.
      // but make sure they remain locked.
      disableButtons();
      return;
    }

    final int pn = reportPane.getPageNumber();
    final int mp = reportPane.getNumberOfPages();

    getLastPageAction().setEnabled(pn < mp);
    getNextPageAction().setEnabled(pn < mp);
    getGotoAction().setEnabled(pn <  mp);

    // no previous page, so dont enable
    getPreviousPageAction().setEnabled(pn > 1);
    getFirstPageAction().setEnabled(pn > 1);
    // no goto, if there is only one page
    getGotoAction().setEnabled(mp > 1);

    final Iterator it = exportPlugIns.iterator();
    while (it.hasNext())
    {
      final ExportPlugin ep = (ExportPlugin) it.next();
      final ExportAction ea = (ExportAction) pluginActions.get(ep);
      if (ep.isControlPlugin())
      {
        ea.setEnabled(true);
      }
      else
      {
        ea.setEnabled(mp > 0);
      }
    }

    zoomSelect.setEnabled(true);
    zoomActionConcentrator.setEnabled(true);
    getZoomOutAction().setEnabled(zoomSelect.getSelectedIndex() != 0);
    getZoomInAction().setEnabled(zoomSelect.getSelectedIndex() != (ZOOM_FACTORS.length - 1));
  }

  /**
   * Returns the zoom selection combobox. Use this to enable or diable
   * it, but dont modify it, or be doomed.
   * @return the zoom selection combobox.
   */
  protected JComboBox getZoomSelect()
  {
    return zoomSelect;
  }

  /**
   * Disables the buttons.
   */
  protected void disableButtons()
  {
    getGotoAction().setEnabled(false);
    getLastPageAction().setEnabled(false);
    getNextPageAction().setEnabled(false);
    getPreviousPageAction().setEnabled(false);
    getFirstPageAction().setEnabled(false);
    zoomActionConcentrator.setEnabled(false);
    zoomSelect.setEnabled(false);

    final Iterator it = pluginActions.values().iterator();
    while (it.hasNext())
    {
      final ExportAction ea = (ExportAction) it.next();
      ea.setEnabled(false);
    }
  }

  /**
   * Returns the action concentrator used to collect all zoom-related
   * actions.
   *
   * @return the zoom action concentrator.
   */
  protected ActionConcentrator getZoomActionConcentrator()
  {
    return zoomActionConcentrator;
  }

  /**
   * Returns the repagination report progress dialog.
   * @return the repaginiation progress dialog.
   */
  protected ReportProgressDialog getProgressDialog()
  {
    return progressDialog;
  }

  /**
   * Returns true if large icons are enabled for the toolbar.
   *
   * @return true if large icons are enabled.
   */
  public boolean isLargeIconsEnabled()
  {
    return largeIconsEnabled;
  }

  /**
   * Sets a flag that controls whether or not large icons are used in the toolbar.
   *
   * @param b  the new value of the flag.
   */
  public void setLargeIconsEnabled(final boolean b)
  {
    largeIconsEnabled = b;
  }

  /**
   * Disposes the preview frame.
   */
  public void dispose()
  {
    // cleanup the report pane, removes some cached resources ...
    reportPane.dispose();

    // Silly Swing keeps at least one reference in the RepaintManager to support DoubleBuffering
    // I dont want this here, as PreviewFrames are evil and resource expensive ...
    RepaintManager.setCurrentManager(null);
  }

  public void close ()
  {
    dispose();
    exportWorker.finish();
    paginationWorker.finish();
  }

  /**
   * Called by the garbage collector on an object when garbage collection
   * determines that there are no more references to the object.
   * A subclass overrides the <code>finalize</code> method to dispose of
   * system resources or to perform other cleanup.
   *
   * @throws Throwable the <code>Exception</code> raised by this method
   */
  public void finalize() throws Throwable
  {
    super.finalize();
    exportWorker.finish();
    paginationWorker.finish();
  }

  /**
   * Returns the 'About' action.
   *
   * @return the 'About' action.
   */
  public Action getAboutAction()
  {
    return aboutAction.getParent();
  }

  /**
   * Sets the 'About' action.
   *
   * @param aboutAction  the 'About' action.
   */
  public void setAboutAction(final Action aboutAction)
  {
    this.aboutAction.setParent(aboutAction);
  }

  /**
   * Returns the 'Close' action.
   *
   * @return the 'Close' action.
   */
  public Action getCloseAction()
  {
    return closeAction.getParent();
  }

  /**
   * Sets the 'Close' action.
   *
   * @param closeAction  the 'Close' action.
   */
  public void setCloseAction(final Action closeAction)
  {
    this.closeAction.setParent(closeAction);
  }

  /**
   * Returns the 'First Page' action.
   *
   * @return the 'First Page' action.
   */
  public Action getFirstPageAction()
  {
    return firstPageAction.getParent();
  }

  /**
   * Sets the 'First Page' action.
   *
   * @param firstPageAction  the 'First Page' action.
   */
  public void setFirstPageAction(final Action firstPageAction)
  {
    this.firstPageAction.setParent(firstPageAction);
  }

  /**
   * Returns the 'Last Page' action.
   *
   * @return the 'Last Page' action.
   */
  public Action getLastPageAction()
  {
    return lastPageAction.getParent();
  }

  /**
   * Sets the 'Last Page' action.
   *
   * @param lastPageAction  the 'Last Page' action.
   */
  public void setLastPageAction(final Action lastPageAction)
  {
    this.lastPageAction.setParent(lastPageAction);
  }

  /**
   * Returns the 'Next Page' action.
   *
   * @return the 'Next Page' action.
   */
  public Action getNextPageAction()
  {
    return nextPageAction.getParent();
  }

  /**
   * Sets the 'Next Page' action.
   *
   * @param nextPageAction  the 'Next Page' action.
   */
  public void setNextPageAction(final Action nextPageAction)
  {
    this.nextPageAction.setParent(nextPageAction);
  }

  /**
   * Returns the 'Previous Page' action.
   *
   * @return the 'Previous Page' action.
   */
  public Action getPreviousPageAction()
  {
    return previousPageAction.getParent();
  }

  /**
   * Sets the 'Previous Page' action.
   *
   * @param previousPageAction  the 'Previous Page' action.
   */
  public void setPreviousPageAction(final Action previousPageAction)
  {
    this.previousPageAction.setParent(previousPageAction);
  }

  /**
   * Returns the 'Zoom In' action.
   *
   * @return the 'Zoom In' action.
   */
  public Action getZoomInAction()
  {
    return zoomInAction.getParent();
  }

  /**
   * Sets the 'Zoom In' action.
   *
   * @param zoomInAction  the 'Zoom In' action.
   */
  public void setZoomInAction(final Action zoomInAction)
  {
    this.zoomInAction.setParent(zoomInAction);
  }

  /**
   * Returns the 'Zoom Out' action.
   *
   * @return the 'Zoom Out' action.
   */
  public Action getZoomOutAction()
  {
    return zoomOutAction.getParent();
  }

  /**
   * Sets the 'Zoom Out' action.
   *
   * @param zoomOutAction  the 'Zoom Out' action.
   */
  public void setZoomOutAction(final Action zoomOutAction)
  {
    this.zoomOutAction.setParent(zoomOutAction);
  }

  /**
   * Returns the 'Goto' action.
   *
   * @return the 'Goto' action.
   */
  public Action getGotoAction()
  {
    return gotoAction.getParent();
  }

  /**
   * Sets the 'Goto' action.
   *
   * @param gotoAction  the 'Goto' action.
   */
  public void setGotoAction(final Action gotoAction)
  {
    this.gotoAction.setParent(gotoAction);
  }

  /**
   * Updates the pageformat of the ReportPane.
   *
   * @param pf the new page format object.
   */
  public void updatePageFormat(final PageFormat pf)
  {
    reportPane.setVisible(false);
    performPagination(pf);
  }

  /**
   * Paginates the report.
   */
  protected void performPagination(final PageFormat format)
  {
    setLockInterface(true);
    setStatusText(getResources().getString("statusline.repaginate"));
    progressDialog.setTitle(getResources().getString("statusline.repaginate"));
    progressDialog.setMessage(getResources().getString("statusline.repaginate"));
    progressDialog.pack();

    final Worker worker = getWorker();
    synchronized (worker)
    {
      while (worker.isAvailable() == false)
      {
        // wait until the worker is done with his current job
        try
        {
          worker.wait();
        }
        catch (InterruptedException ie)
        {
        }
      }
      getWorker().setWorkload(new Runnable()
      {
        public void run()
        {
          final ReportPane reportPane = getReportPane();
          try
          {
            reportPane.addRepaginationListener(progressDialog);
            RefineryUtilities.positionFrameRandomly(progressDialog);
            progressDialog.setVisible(true);
            reportPane.setHandleInterruptedState(true);
            reportPane.setVisible(false);
            reportPane.setPageFormat(format);
            reportPane.repaginate();
            reportPane.setVisible(true);
            reportPane.setHandleInterruptedState(false);
            progressDialog.setVisible(false);
            reportPane.removeRepaginationListener(progressDialog);
            setLockInterface(false);
          }
          catch (Exception e)
          {
            Log.warn("Failed to repaginate", e);
            reportPane.setError(e);
          }
        }
      });
    }
  }

  public boolean isLockInterface()
  {
    return lockInterface;
  }

  public void setLockInterface(boolean lockInterface)
  {
    this.lockInterface = lockInterface;
    if (lockInterface == true)
    {
      disableButtons();
    }
    else
    {
      validateButtons();
    }
  }

  public void addRepaginationListener (RepaginationListener listener)
  {
    reportPane.addRepaginationListener(listener);
  }

  public void removeRepaginationListener (RepaginationListener listener)
  {
    reportPane.removeRepaginationListener(listener);
  }
}

⌨️ 快捷键说明

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