previewproxybase.java

来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 2,255 行 · 第 1/5 页

JAVA
2,255
字号
     * @param e The action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      decreaseZoom();
    }
  }

  /**
   * Default 'about' action (does nothing).
   */
  private class DefaultAboutAction extends AboutAction
  {
    /**
     * Creates an 'about' action.
     */
    public DefaultAboutAction()
    {
      super(getResources());
    }

    /**
     * Does nothing (should show an 'about' dialog).
     *
     * @param e The action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
    }
  }

  /**
   * Default 'goto' action for the frame.
   */
  private class DefaultGotoAction extends GotoPageAction
  {
    /**
     * Creates a 'goto' action.
     */
    public DefaultGotoAction()
    {
      super(getResources());
    }

    /**
     * Jump to a page.
     *
     * @param e The action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      final String result = JOptionPane.showInputDialog(PreviewProxyBase.this,
          getResources().getString("dialog.gotopage.title"),
          getResources().getString("dialog.gotopage.message"),
          JOptionPane.OK_CANCEL_OPTION);
      if (result == null)
      {
        return;
      }
      try
      {
        final int page = Integer.parseInt(result);

        final ReportPane reportPane = getReportPane();
        if (page > 0 && page <= reportPane.getNumberOfPages())
        {
          reportPane.setPageNumber(page);
        }
      }
      catch (Exception ex)
      {
        Log.info("DefaultGotoAction: swallowed an exception");
      }
    }
  }

  /**
   * A zoom select action.
   */
  private class ZoomSelectAction extends AbstractAction
  {
    /**
     * Creates a new action.
     */
    public ZoomSelectAction()
    {
    }

    /**
     * Invoked when an action occurs.
     *
     * @param e  the event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      setZoomFactor(getZoomSelect().getSelectedIndex());
    }
  }

  /**
   * A zoom set action.
   */
  protected class ZoomSetAction extends AbstractActionDowngrade
  {
    /** The zoom factor index. */
    private final int zoomFactor;

    /**
     * Creates a new action.
     *
     * @param factorIndex  the zoom factor index.
     */
    public ZoomSetAction(final int factorIndex)
    {
      zoomFactor = factorIndex;
      this.putValue(Action.NAME, String.valueOf((int) (ZOOM_FACTORS[factorIndex] * 100)) + " %");
      this.putValue(SMALL_ICON, ImageUtils.createTransparentIcon(16, 16));
      this.putValue("ICON24", ImageUtils.createTransparentIcon(24, 24));
    }

    /**
     * Invoked when an action occurs.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      setZoomFactor(zoomFactor);
    }
  }

  /** The base class for localised resources. */
  public static final String BASE_RESOURCE_CLASS =
      JFreeReportResources.class.getName();

  /** The worker thread which is used to perform the repagination. */
  private Worker repaginationWorker;

  /** The worker thread which is used to perform the repagination. */
  private WorkerPool exportWorkerPool;
  /** An action map storing all basic actions. */
  private DowngradeActionMap baseActionMap;
  /** An action map storing all navigation related actions. */
  private DowngradeActionMap navigationActionMap;
  /** An action map storing all zoom related actions. */
  private DowngradeActionMap zoomActionMap;
  /** An action map storing all export related actions. */
  private DowngradeActionMap exportActionMap;

  /** The available zoom factors. */
  protected static final float[]
      ZOOM_FACTORS = {0.25f, 0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 2.0f, 3.0f, 4.0f};

  /** The default zoom index (corresponds to a zoomFactor of 1.0. */
  private static final int DEFAULT_ZOOM_INDEX = 3;

  /** The combobox enables a direct selection of the desired zoomFactor. */
  private JComboBox zoomSelect;

  /** The current zoom index (indexes into the zoomFactors array). */
  private int zoomIndex;

  /** The pane that displays the report within the frame. */
  private ReportPane reportPane;

  /** Locale-specific resources. */
  private ResourceBundle resources;

  /** Defines whether to use 24x24 icons or 16x16 icons. */
  private boolean largeIconsEnabled;

  /** Label for status. */
  private JLabel statusHolder;

  /** Toolbar. */
  private JToolBar toolbar;
  /** Whether the toolbar will be floatable. */
  private boolean toolbarFloatable;

  /** A preview proxy. */
  private PreviewProxy proxy;

  /** A list of all export plugins known to this preview proxy base. */
  private ArrayList exportPlugIns;

  /** A collection of actions, keyed by the export plugin. */
  private HashMap pluginActions;

  /** The progress monitor dialog used to visualize the pagination progress. */
  private ReportProgressDialog progressDialog;
  
  /** A flag to define whether the interface should be the locked state. */
  private boolean lockInterface;
  /** A flag that defines, whether the preview component is closed. */
  private boolean closed;

  public static final String CONF_TOOLBAR_ENABLED = "toolbar";
  public static final String CONF_ALL_ENABLED = "enable";
  public static final String CONF_ALL_DISABLED = "disable";
  public static final String CONF_MENUBAR_ENABLED = "menubar";
  public static final String REPORT_PANE_PROPERTY = "reportPane";

  private JPanel reportPaneHolder;
  private ReportPanePropertyChangeListener reportPanePropertyChangeListener;
  /**
   * Creates a preview proxy.
   *
   * @param proxy  the proxy.
   */
  public PreviewProxyBase(final PreviewProxy proxy)
  {
    if (proxy == null)
    {
      throw new NullPointerException("Proxy must not be null.");
    }
    baseActionMap = new DowngradeActionMap();

    exportActionMap = new DowngradeActionMap();
    exportActionMap.setParent(baseActionMap);

    navigationActionMap = new DowngradeActionMap();
    navigationActionMap.setParent(baseActionMap);

    zoomActionMap = new DowngradeActionMap();
    zoomActionMap.setParent(baseActionMap);

    this.proxy = proxy;
    progressDialog = new ReportProgressDialog();
    progressDialog.setDefaultCloseOperation(ReportProgressDialog.DO_NOTHING_ON_CLOSE);
    reportPanePropertyChangeListener = new ReportPanePropertyChangeListener();

    setLayout(new BorderLayout());
    setDoubleBuffered(false);

    // handle a JDK bug: windows are not garbage collected if dispose is not called manually.
    // DisposedState is undone when show() or pack() is called, so this does no harm.
    proxy.addComponentListener(new ComponentAdapter()
    {
      public void componentHidden(final ComponentEvent e)
      {
        final Component c = e.getComponent();
        if (c instanceof Window)
        {
          final Window w = (Window) c;
          w.dispose();
          dispose();
        }
      }
    });

    this.exportWorkerPool = new WorkerPool
      (10, "preview-dialog-export-worker");

    createDefaultActions();

    reportPaneHolder = new JPanel(new CenterLayout());
    reportPaneHolder.setDoubleBuffered(false);
    reportPaneHolder.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    final JScrollPane s1 = new JScrollPane(reportPaneHolder);
    s1.setDoubleBuffered(false);
    s1.getVerticalScrollBar().setUnitIncrement(20);

    final JPanel scrollPaneHolder = new JPanel();
    scrollPaneHolder.setLayout(new BorderLayout());
    scrollPaneHolder.add(s1, BorderLayout.CENTER);
    scrollPaneHolder.setDoubleBuffered(false);

    scrollPaneHolder.add(createStatusBar(), BorderLayout.SOUTH);
    add(scrollPaneHolder);

    zoomSelect = createZoomSelector();
    // todo
  }

  /**
   * Builds the export plugins and fills the plug in collections.
   *
   * @param report the report for which to build the plugins
   */
  private void buildExportPlugins (final JFreeReport report)
  {
    final ExportPluginFactory factory = ExportPluginFactory.getInstance();
    exportPlugIns = factory.createExportPlugIns
      (proxy, report.getReportConfiguration(), exportWorkerPool);
    pluginActions = new HashMap(exportPlugIns.size());
    final Iterator it = exportPlugIns.iterator();
    while (it.hasNext())
    {
      final ExportPlugin ep = (ExportPlugin) it.next();
      final ExportAction ea = new ExportAction(ep);
      ea.setReport(report);
      pluginActions.put(ep, ea);
    }
  }

  /**
   * Returns the list of export plugins available to the report.
   *
   * @return the list of export plugins.
   */
  protected List getExportPlugins ()
  {
    return exportPlugIns;
  }

  /**
   * Returns the map of export plugins available to the report.
   * Using a plugin as key you can query the assigned action for that
   * plugin.
   *
   * @return the list of export plugins.
   */
  protected HashMap getExportActions ()
  {
    return pluginActions;
  }

  /**
   * Returns the export worker used for exporting.
   *
   * @return the worker.
   */
  protected WorkerPool getExportWorkerPool ()
  {
    return exportWorkerPool;
  }

  /**
   * Returns the pagination worker used when paginating the report.
   *
   * @return the worker.
   */
  protected Worker getRepaginationWorker ()
  {
    if (repaginationWorker == null)
    {
      repaginationWorker = new Worker();
      repaginationWorker.setPriority(Thread.MIN_PRIORITY);
      repaginationWorker.setName("Repagination-Worker");
    }
    return repaginationWorker;
  }

  private void closeToolbar ()
  {
    if (toolbar.getParent() != this)
    {
      // ha!, we detected that the toolbar is floating ...
      // Log.debug (currentToolbar.getParent());
      Window w = SwingUtilities.windowForComponent(toolbar);
      if (w != null)
      {
        w.setVisible(false);
        w.dispose();
      }
    }
    toolbar.setVisible(false);
  }


  /**
   * Initialises the preview dialog.
   *
   * @param report  the report.
   *
   * @throws ReportProcessingException if there is a problem processing the report.
   * @deprecated use setReport(..) instead.
   */
  public void init(final JFreeReport report) throws ReportProcessingException
  {
    setReport(report);
  }

  private boolean isPropertySet (String property, boolean defaultValue)
  {
    String value =
        ReportConfiguration.getGlobalConfig().getConfigProperty(property);
    if (value == null)
    {
      return defaultValue;
    }
    return (value.equals(String.valueOf(defaultValue)));
  }

  /**
   * Call this method, whenever actions have changed. The menu and toolbar
   * will be rebuild.
   */
  protected void reinitialize ()
  {
    initializeToolBar();
    // set up the menu
    if (isPropertySet(CREATE_MENUBAR_PROPERTY, true))
    {
      proxy.setJMenuBar(createMenuBar());
    }
  }

  /**
   * Creates an empty toolbar. The toolbar will be inizialized later by
   * calling inizializeToolbar().
   *
   * @return the created toolbar.
   */
  protected JToolBar createToolBar ()
  {
    final JToolBar toolbar = new JToolBar();
    return toolbar;
  }

  protected boolean isMenuActionEnabled (String property)
  {
    String value = ReportConfiguration.getGlobalConfig().getConfigProperty(property);
    if (value == null)
    {
      return true;
    }
    if (value.equals(CONF_MENUBAR_ENABLED))
    {
      return true;
    }
    if (value.equals(CONF_ALL_ENABLED))
    {
      return true;
    }
    return false;
  }

  protected boolean isToolbarActionEnabled (String property)
  {
    String value = ReportConfiguration.getGlobalConfig().getConfigProperty(property);
    if (value == null)
    {
      return true;
    }
    if (value.equals(CONF_TOOLBAR_ENABLED))
    {
      return true;
    }
    if (value.equals(CONF_ALL_ENABLED))
    {
      return true;
    }
    return false;
  }

  /**
   * Read the defined dimensions from the report's configuration and set them to
   * the Dialog. If a maximum size is defined, add a WindowSizeLimiter to check the
   * maximum size

⌨️ 快捷键说明

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