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

📄 visualeditpanel.java

📁 报表设计软件,很好的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    allActions = new DowngradeActionMap();

    deleteElementAction = new DeleteElementAction(this);
    allActions.put(DELETE_ACTION_KEY, deleteElementAction);

    zoomActions = new DowngradeActionMap();
    zoomActions.setParent(allActions);
    zoomActions.put(ZOOM_IN_ACTION_KEY, new ZoomInAction(this));
    zoomActions.put(ZOOM_OUT_ACTION_KEY, new ZoomOutAction(this));

    insertActions = new DowngradeActionMap();
    insertActions.setParent(allActions);
    final ElementPrototypeFactory factory = new ElementPrototypeFactory();
    factory.fill(this, insertActions);

    layoutActions = new DowngradeActionMap();
    layoutActions.setParent(allActions);

    layoutActions.put(LEFT_ALIGNMENT_ACTION_KEY, new LeftAlignmentAction(this));
    layoutActions.put(CENTER_ALIGNMENT_ACTION_KEY, new CenterAlignmentAction(this));
    layoutActions.put(RIGHT_ALIGNMENT_ACTION_KEY, new RightAlignmentAction(this));
    layoutActions.put(TOP_ALIGNMENT_ACTION_KEY, new TopAlignmentAction(this));
    layoutActions.put(MIDDLE_ALIGNMENT_ACTION_KEY, new MiddleAlignmentAction(this));
    layoutActions.put(BOTTOM_ALIGNMENT_ACTION_KEY, new BottomAlignmentAction(this));

    layoutActions.put(SAME_WIDTH_ACTION_KEY, new SameWidthAction(this));
    layoutActions.put(SAME_HEIGHT_ACTION_KEY, new SameHeightAction(this));
    layoutActions.put(SAME_WIDTH_AND_HEIGHT_ACTION_KEY, new SameWidthAndHeightAction(this));

    layoutActions.put(TO_FRONT_ACTION_KEY, new ToFrontAction(this));
    layoutActions.put(TO_BACK_ACTION_KEY, new ToBackAction(this));
  }

  private void validateZoomActions ()
  {
    zoomActions.get(ZOOM_OUT_ACTION_KEY).setEnabled(getZoomLevel() != 0);
    zoomActions.get(ZOOM_IN_ACTION_KEY).setEnabled(getZoomLevel() != (ZOOM_LEVELS.length - 1));
  }

  public final void reportDefinitionChanged ()
  {
    treeModel.initialize();
    revalidate();
  }

  private JToolBar initToolBar ()
  {
    final DowngradeActionMap map = manager.getGlobalActions();

    final JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);
    toolbar.add(createButton(map.get(JFreeReportDesigner.NEW_REPORT_ACTION_KEY)));
    toolbar.add(createButton(map.get(JFreeReportDesigner.OPEN_REPORT_ACTION_KEY)));
    toolbar.add(createButton(map.get(JFreeReportDesigner.SAVE_ACTION_KEY)));
    toolbar.add(createButton(map.get(JFreeReportDesigner.SAVE_AS_ACTION_KEY)));
    toolbar.addSeparator();
    toolbar.add(createButton(map.get(JFreeReportDesigner.REOPEN_REPORT_ACTION_KEY)));
    toolbar.addSeparator();
    toolbar.add(createButton(zoomActions.get(ZOOM_IN_ACTION_KEY)));
    toolbar.add(createButton(zoomActions.get(ZOOM_OUT_ACTION_KEY)));

    final JComboBox zoomSelector = new JComboBox();
    final DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (int i = 0; i < ZOOM_LEVELS.length; i++)
    {
      model.addElement(String.valueOf((int) (ZOOM_LEVELS[i] * 100)) + " %");
    }

    zoomSelector.setModel(model);
    zoomSelector.setSelectedIndex(DEFAULT_ZOOM_INDEX);
    zoomSelector.setToolTipText("Zoom Ratio");
    zoomSelector.setPreferredSize(new Dimension(70, 23));
    zoomSelector.setMinimumSize(new Dimension(70, 23));
    zoomSelector.setMaximumSize(new Dimension(70, 23));
    zoomSelector.addActionListener(new ZoomSelectHandler(this, zoomSelector));

    toolbar.add(zoomSelector);
    return toolbar;
  }

  private void initComponents ()
  {
    setLayout(new BorderLayout());
    setLayout(new BorderLayout());
    toolBar = initToolBar();

    contentPane = new JPanel();
    contentPane.setBackground(Color.white);
    contentPane.setBorder(new EtchedBorder());
    contentPane.setOpaque(true);
    contentPane.setLayout(new VerticalLayout(false));

    reportModelTree = new JTree();
    reportModelTree.addTreeSelectionListener(selectionHandler);
    reportModelTree.setCellRenderer(new ReportTreeRenderer());
    emptyTreeModel = reportModelTree.getModel();

    // Handles the zooming. Any empty space would also be zoomed,
    // so we have to place that componenent on an unzoomed floater ..
    final JPanel floatingCarrier = new JPanel();
    floatingCarrier.setLayout(new FlowLayout());
    floatingCarrier.add(contentPane);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
            new JScrollPane(reportModelTree), new JScrollPane(floatingCarrier));
    splitPane.setOneTouchExpandable(true);

    add(splitPane, BorderLayout.CENTER);
  }

  private JMenu buildEditMenu ()
  {
    final JMenu mInsert = new JMenu("Insert");
    mInsert.setIcon(ImageUtils.createTransparentIcon(16, 16));

    final Object[] keys = insertActions.keys();
    for (int i = 0; i < keys.length; i++)
    {
      mInsert.add(new ActionMenuItem(insertActions.get(keys[i])));
    }

    styleDialogVisibleMenuItem = new ActionCheckBoxMenuItem(new StyleDialogVisibleAction());
    styleDialogVisibleMenuItem.setSelected(false);
    styleDialogVisibleMenuItem.setIcon(ImageUtils.createTransparentIcon(16, 16));

    final JMenu mEditMenu = new JMenu("Edit");
    mEditMenu.add(mInsert);
    mEditMenu.add(new ActionMenuItem(deleteElementAction));
    mEditMenu.add(styleDialogVisibleMenuItem);

    return mEditMenu;
  }

  private void buildInsertPopupMenu ()
  {
    insertPopupMenu = new JPopupMenu();
    final Object[] keys = insertActions.keys();
    for (int i = 0; i < keys.length; i++)
    {
      insertPopupMenu.add(new ActionMenuItem(insertActions.get(keys[i])));
    }
  }

  private JMenu buildLayoutMenu ()
  {
    // menu align (left, right, etc.)
    final JMenu mAlign = new JMenu("Content Alignment");
    mAlign.setIcon(ImageUtils.createTransparentIcon(16, 16));
    mAlign.add(layoutActions.get(LEFT_ALIGNMENT_ACTION_KEY));
    mAlign.add(layoutActions.get(CENTER_ALIGNMENT_ACTION_KEY));
    mAlign.add(layoutActions.get(RIGHT_ALIGNMENT_ACTION_KEY));
    mAlign.addSeparator();
    mAlign.add(layoutActions.get(TOP_ALIGNMENT_ACTION_KEY));
    mAlign.add(layoutActions.get(MIDDLE_ALIGNMENT_ACTION_KEY));
    mAlign.add(layoutActions.get(BOTTOM_ALIGNMENT_ACTION_KEY));

    // same size menu
    final JMenu mSameSize = new JMenu("Resize");
    mSameSize.setIcon(ImageUtils.createTransparentIcon(16, 16));
    mSameSize.add(layoutActions.get(SAME_WIDTH_ACTION_KEY));
    mSameSize.add(layoutActions.get(SAME_HEIGHT_ACTION_KEY));
    mSameSize.add(layoutActions.get(SAME_WIDTH_AND_HEIGHT_ACTION_KEY));

    final JMenu mLayout = new JMenu("Layout");
    mLayout.add(mAlign);
    mLayout.add(mSameSize);
    mLayout.addSeparator();
    mLayout.add(layoutActions.get(TO_FRONT_ACTION_KEY));
    mLayout.add(layoutActions.get(TO_BACK_ACTION_KEY));
    mLayout.addSeparator();
    mLayout.add(new TestLayoutAction(this));
    return mLayout;
  }

  public final JMenu[] getEditorMenus ()
  {
    return editorMenus;
  }

  public final JComponent getEditorComponent ()
  {
    return this;
  }

  public final boolean isActive ()
  {
    return active;
  }

  public final void setActive (final boolean active)
  {
    final boolean oldActive = this.active;
    this.active = active;
    if (active != oldActive)
    {
      if (active == true)
      {
        Log.debug("On Activate called");
        onActivate();
      }
      else
      {
        Log.debug("On Deactivate called");
        onDeactivate();
      }
    }
    else
    {
      Log.debug("Nothing called");
    }
  }

  private void onActivate ()
  {
    if (manager.hasReportDefinitionError())
    {
      setReport(null);
    }
    else
    {
      if (manager.getReport() == null)
      {
        manager.setReport(new JFreeReport());
      }
      setReport(manager.getReport());
    }
  }

  private void onDeactivate ()
  {
    manager.setReport(getReport());
    Log.debug("This is set: " + manager.getReportDefinitionText().length());
    setReport(null);
    setSelectedElement(null);
    // hide the stylesheet dialog ...
    styleSheetDialog.setVisible(false);
    Log.debug("This is set: " + manager.getReportDefinitionText().length());
  }

  private void createBandEditor (final String name, final Band band, final float width)
  {
    final ReportBandEditor rbe = new ReportBandEditor(name, band, width);
    rbe.setRenderer(renderer);
    rbe.setSelectionModel(selectionModel);
    rbe.setDetailLevel(getZoom());
    currentRootBandEditors.add(rbe);
    contentPane.add(rbe);
  }

  public final ReportBandEditor[] getCurrentRootBandEditors ()
  {
    return (ReportBandEditor[]) currentRootBandEditors.toArray
            (new ReportBandEditor[currentRootBandEditors.size()]);
  }


  public final void setReport (final JFreeReport report)
  {
    if (this.report != null)
    {
      dataRow.disconnectDataSources(this.report);
    }

    this.report = report;
    contentPane.removeAll();
    currentRootBandEditors.clear();

    // If there is no report, leave here ...
    if (report == null)
    {
      reportModelTree.setModel(emptyTreeModel);
      treeModel = null;
      return;
    }

    dataRow.connectDataSources(this.report);
    final float width = (float) report.getDefaultPageFormat().getImageableWidth();
    contentPane.setMinimumSize(new Dimension((int) width, 0));

    createBandEditor("PageHeader", report.getPageHeader(), width);
    createBandEditor("ReportHeader", report.getReportHeader(), width);

    final int groupCount = report.getGroupCount();
    for (int i = 0; i < groupCount; i++)
    {
      final Group g = report.getGroup(i);
      createBandEditor("GroupHeader: " + g.getName(), g.getHeader(), width);
    }

    createBandEditor("ItemBand", report.getItemBand(), width);

    for (int i = groupCount - 1; i >= 0; i--)
    {
      final Group g = report.getGroup(i);
      createBandEditor("GroupFooter: " + g.getName(), g.getFooter(), width);
    }

    createBandEditor("ReportFooter", report.getReportFooter(), width);
    createBandEditor("PageFooter", report.getPageFooter(), width);
    contentPane.validate();

    reportModelTree.clearSelection();

    treeModel = new ReportTreeModel(report);
    reportModelTree.setModel(treeModel);
  }

  public final JFreeReport getReport ()
  {
    return report;
  }

  public final void increaseZoom ()
  {
    final int index = getZoomLevel();

    if (index < (ZOOM_LEVELS.length - 1))
    {
      setZoomLevel(index + 1);
    }
  }

  public final void decreaseZoom ()
  {
    final int index = getZoomLevel();

    if (index > 0)
    {
      setZoomLevel(index - 1);
    }
  }

  public final void setZoomLevel (final int zoomLevel)
  {
    final int old = this.zoomLevel;
    this.zoomLevel = zoomLevel;
    firePropertyChange(ZOOM_LEVEL_PROPERTY_NAME, old, zoomLevel);
    validateZoomActions();
    validate();
  }

  public final int getZoomLevel ()
  {
    return zoomLevel;
  }

  public final float getZoom ()
  {
    return ZOOM_LEVELS[getZoomLevel()];
  }

  protected static void setAllActionsEnabled (final DowngradeActionMap map,
                                              final boolean state)
  {
    final Object[] keys = map.keys();
    for (int i = 0; i < keys.length; i++)
    {
      final Action a = map.get(keys[i]);
      a.setEnabled(state);
    }
  }

  public final Element getSelectedElement ()
  {
    return selectedElement;
  }

  protected final void setSelectedElement (final Element selectedElement)
  {
    final Element oldSelectedElement = this.selectedElement;
    this.selectedElement = selectedElement;
    firePropertyChange
            (SELECTED_ELEMENT_PROPERTY_NAME, oldSelectedElement, selectedElement);
  }

  public final boolean isBandStyleDialogVisible ()
  {
    return bandStyleDialogVisible;
  }

  public final void setBandStyleDialogVisible (final boolean bandStyleDialogVisible)
  {
    this.bandStyleDialogVisible = bandStyleDialogVisible;
  }

  public final boolean isElementStyleDialogVisible ()
  {
    return elementStyleDialogVisible;
  }

  public final void setElementStyleDialogVisible (final boolean elementStyleDialogVisible)
  {
    this.elementStyleDialogVisible = elementStyleDialogVisible;
  }

  public final String getEditorName ()
  {
    return "Editor";
  }

  public final PlainDataRow getDataRow ()
  {
    return dataRow;
  }

  public final ReportBandEditor findEditorForElement (Element element)
  {
    Band parent = null;
    while (element.getParent() != null)
    {
      parent = element.getParent();
      element = parent;
    }
    if (parent == null)
    {
      return null;
    }
    for (int i = 0; i < currentRootBandEditors.size(); i++)
    {
      final ReportBandEditor ed = (ReportBandEditor) currentRootBandEditors.get(i);
      if (ed.getBand() == parent)
      {
        return ed;
      }
    }
    return null;
  }

  /**
   * Creates a button using the given action properties for the button's initialisation.
   *
   * @param action the action used to set up the button.
   * @return a button based on the supplied action.
   */
  protected final JButton createButton (final Action action)
  {
    final JButton button = new ActionButton(action);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setText(null);
    FloatingButtonEnabler.getInstance().addButton(button);
    return button;
  }

  public final JToolBar getToolbar ()
  {
    return toolBar;
  }
}

⌨️ 快捷键说明

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