Пример #1
0
 public CloseAction() {
   super(Localization.lang("Close window"), IconTheme.JabRefIcon.CLOSE.getSmallIcon());
   putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close window"));
 }
Пример #2
0
public abstract class SidePaneComponent extends JXTitledPanel {

  protected final JButton close = new JButton(IconTheme.JabRefIcon.CLOSE.getSmallIcon());

  private final SidePaneManager manager;

  protected BasePanel panel;

  public SidePaneComponent(SidePaneManager manager, Icon icon, String title) {
    super(title);
    this.manager = manager;

    this.add(new JLabel(icon));

    setTitleForeground(new Color(79, 95, 143));
    setBorder(BorderFactory.createEmptyBorder());

    close.setMargin(new Insets(0, 0, 0, 0));
    close.setBorder(null);
    close.addActionListener(e -> hideAway());

    JButton up = new JButton(IconTheme.JabRefIcon.UP.getSmallIcon());
    up.setMargin(new Insets(0, 0, 0, 0));
    up.setBorder(null);
    up.addActionListener(e -> moveUp());

    JButton down = new JButton(IconTheme.JabRefIcon.DOWN.getSmallIcon());
    down.setMargin(new Insets(0, 0, 0, 0));
    down.setBorder(null);
    down.addActionListener(e -> moveDown());

    JToolBar tlb = new OSXCompatibleToolbar();
    tlb.add(up);
    tlb.add(down);
    tlb.add(close);
    tlb.setOpaque(false);
    tlb.setFloatable(false);
    this.getUI().getTitleBar().add(tlb);
    setTitlePainter(new MattePainter(Color.lightGray));
  }

  private void hideAway() {
    manager.hideComponent(this);
  }

  private void moveUp() {
    manager.moveUp(this);
  }

  private void moveDown() {
    manager.moveDown(this);
  }

  public void setActiveBasePanel(BasePanel panel) {
    this.panel = panel;
  }

  public BasePanel getActiveBasePanel() {
    return panel;
  }

  /** Override this method if the component needs to make any changes before it can close. */
  public void componentClosing() {
    // Nothing right now
  }

  /** Override this method if the component needs to do any actions when opening. */
  public void componentOpening() {
    // Nothing right now
  }

  @Override
  public Dimension getMinimumSize() {
    return getPreferredSize();
  }

  /**
   * Specifies how to distribute extra vertical space between side pane components. 0: fixed height,
   * 1: fill the remaining space
   */
  public abstract int getRescalingWeight();
}
Пример #3
0
public abstract class SidePaneComponent extends JXTitledPanel {

  protected final JButton close = new JButton(IconTheme.JabRefIcon.CLOSE.getSmallIcon());

  protected final SidePaneManager manager;

  protected BasePanel panel;

  public SidePaneComponent(SidePaneManager manager, Icon icon, String title) {
    super(title);
    this.manager = manager;

    this.add(new JLabel(icon));

    setTitleForeground(new Color(79, 95, 143));
    setBorder(BorderFactory.createEmptyBorder());

    close.setMargin(new Insets(0, 0, 0, 0));
    close.setBorder(null);
    close.addActionListener(e -> hideAway());

    JButton up = new JButton(IconTheme.JabRefIcon.UP.getSmallIcon());
    up.setMargin(new Insets(0, 0, 0, 0));
    up.setBorder(null);
    up.addActionListener(e -> moveUp());

    JButton down = new JButton(IconTheme.JabRefIcon.DOWN.getSmallIcon());
    down.setMargin(new Insets(0, 0, 0, 0));
    down.setBorder(null);
    down.addActionListener(e -> moveDown());

    JToolBar tlb = new OSXCompatibleToolbar();
    tlb.add(up);
    tlb.add(down);
    tlb.add(close);
    tlb.setOpaque(false);
    tlb.setFloatable(false);
    this.getUI().getTitleBar().add(tlb);
    setTitlePainter(new MattePainter(Color.lightGray));
  }

  private void hideAway() {
    manager.hideComponent(this);
  }

  private void moveUp() {
    manager.moveUp(this);
  }

  private void moveDown() {
    manager.moveDown(this);
  }

  public void setActiveBasePanel(BasePanel panel) {
    this.panel = panel;
  }

  public BasePanel getActiveBasePanel() {
    return panel;
  }

  /** Override this method if the component needs to make any changes before it can close. */
  public void componentClosing() {
    // Nothing right now
  }

  /** Override this method if the component needs to do any actions when opening. */
  public void componentOpening() {
    // Nothing right now
  }

  @Override
  public Dimension getMinimumSize() {
    return getPreferredSize();
  }

  /**
   * Specifies how to distribute extra vertical space between side pane components. 0: fixed height,
   * 1: fill the remaining space
   */
  public abstract int getRescalingWeight();

  /** @return the action which toggles this {@link SidePaneComponent} */
  public abstract ToggleAction getToggleAction();

  public class ToggleAction extends AbstractAction {

    public ToggleAction(String text, String description, KeyStroke key, IconTheme.JabRefIcon icon) {
      super(text, icon.getSmallIcon());
      putValue(Action.ACCELERATOR_KEY, key);
      putValue(Action.LARGE_ICON_KEY, icon.getIcon());
      putValue(Action.SHORT_DESCRIPTION, description);
    }

    public ToggleAction(String text, String description, KeyStroke key, Icon icon) {
      super(text, icon);
      putValue(Action.ACCELERATOR_KEY, key);
      putValue(Action.SHORT_DESCRIPTION, description);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
      if (!manager.hasComponent(SidePaneComponent.this.getClass())) {
        manager.register(SidePaneComponent.this);
      }

      // if clicked by mouse just toggle
      if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
        manager.toggle(SidePaneComponent.this.getClass());
      } else {
        manager.toggleThreeWay(SidePaneComponent.this.getClass());
      }
      putValue(Action.SELECTED_KEY, manager.isComponentVisible(SidePaneComponent.this.getClass()));
    }

    public void setSelected(boolean selected) {
      putValue(Action.SELECTED_KEY, selected);
    }

    public boolean isSelected() {
      return Boolean.TRUE.equals(getValue(Action.SELECTED_KEY));
    }
  }
}