Java Code Examples for com.intellij.openapi.wm.ToolWindowAnchor#LEFT

The following examples show how to use com.intellij.openapi.wm.ToolWindowAnchor#LEFT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
DesktopStripePanelImpl getStripeFor(String id) {
  ToolWindow window = myManager.getToolWindow(id);
  if (window == null) {
    return null;
  }

  final ToolWindowAnchor anchor = myManager.getToolWindow(id).getAnchor();
  if (ToolWindowAnchor.TOP == anchor) {
    return myTopStripe;
  }
  if (ToolWindowAnchor.BOTTOM == anchor) {
    return myBottomStripe;
  }
  if (ToolWindowAnchor.LEFT == anchor) {
    return myLeftStripe;
  }
  if (ToolWindowAnchor.RIGHT == anchor) {
    return myRightStripe;
  }

  throw new IllegalArgumentException("Anchor=" + anchor);
}
 
Example 2
Source File: DesktopStripePanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintComponent(final Graphics g) {
  super.paintComponent(g);
  if (!myFinishingDrop && isDroppingButton() && myDragButton.getParent() != this) {
    g.setColor(getBackground().brighter());
    g.fillRect(0, 0, getWidth(), getHeight());
  }
  if (UIUtil.isUnderDarcula()) return;
  ToolWindowAnchor anchor = getAnchor();
  g.setColor(new Color(255, 255, 255, 40));
  Rectangle r = getBounds();
  if (anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT) {
    g.drawLine(0, 0, 0, r.height);
    g.drawLine(r.width - 2, 0, r.width - 2, r.height);
  }
  else {
    g.drawLine(0, 1, r.width, 1);
    g.drawLine(0, r.height - 1, r.width, r.height - 1);
  }
}
 
Example 3
Source File: DesktopStripePanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Insets getBorderInsets(Component c) {
  DesktopStripePanelImpl stripe = (DesktopStripePanelImpl)c;
  ToolWindowAnchor anchor = stripe.getAnchor();

  Insets result = new Insets(0, 0, 0, 0);
  final int off = UIUtil.isUnderDarcula() ? 1 : 0;
  if (anchor == ToolWindowAnchor.LEFT) {
    result.top = 1;
    result.right = 1 + off;
  }
  else if (anchor == ToolWindowAnchor.RIGHT) {
    result.left = 1 + off;
    result.top = 1;
  }
  else if (anchor == ToolWindowAnchor.TOP) {
    result.bottom = 0;
    //result.bottom = 1;
    result.top = 1;
  }
  else {
    result.top = 1 + off;
  }

  return result;
}
 
Example 4
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
final void setBoundsInPaletteLayer(@Nonnull Component component, @Nonnull ToolWindowAnchor anchor, float weight) {
  if (weight < .0f) {
    weight = WindowInfoImpl.DEFAULT_WEIGHT;
  }
  else if (weight > 1.0f) {
    weight = 1.0f;
  }
  if (ToolWindowAnchor.TOP == anchor) {
    component.setBounds(0, 0, getWidth(), (int)(getHeight() * weight + .5f));
  }
  else if (ToolWindowAnchor.LEFT == anchor) {
    component.setBounds(0, 0, (int)(getWidth() * weight + .5f), getHeight());
  }
  else if (ToolWindowAnchor.BOTTOM == anchor) {
    final int height = (int)(getHeight() * weight + .5f);
    component.setBounds(0, getHeight() - height, getWidth(), height);
  }
  else if (ToolWindowAnchor.RIGHT == anchor) {
    final int width = (int)(getWidth() * weight + .5f);
    component.setBounds(getWidth() - width, 0, width, getHeight());
  }
  else {
    LOG.error("unknown anchor " + anchor);
  }
}
 
Example 5
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public final void run() {
  try {
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    if (ToolWindowAnchor.TOP == anchor) {
      myTopStripe.removeButton(myButton);
    }
    else if (ToolWindowAnchor.LEFT == anchor) {
      myLeftStripe.removeButton(myButton);
    }
    else if (ToolWindowAnchor.BOTTOM == anchor) {
      myBottomStripe.removeButton(myButton);
    }
    else if (ToolWindowAnchor.RIGHT == anchor) {
      myRightStripe.removeButton(myButton);
    }
    else {
      LOG.error("unknown anchor: " + anchor);
    }
    validate();
    repaint();
  }
  finally {
    finish();
  }
}
 
Example 6
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public final void run() {
  try {
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    if (ToolWindowAnchor.TOP == anchor) {
      myTopStripe.addButton(myButton, myComparator);
    }
    else if (ToolWindowAnchor.LEFT == anchor) {
      myLeftStripe.addButton(myButton, myComparator);
    }
    else if (ToolWindowAnchor.BOTTOM == anchor) {
      myBottomStripe.addButton(myButton, myComparator);
    }
    else if (ToolWindowAnchor.RIGHT == anchor) {
      myRightStripe.addButton(myButton, myComparator);
    }
    else {
      LOG.error("unknown anchor: " + anchor);
    }
    validate();
    repaint();
  }
  finally {
    finish();
  }
}
 
Example 7
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private JComponent getComponentAt(@Nonnull ToolWindowAnchor anchor) {
  if (ToolWindowAnchor.TOP == anchor) {
    return myVerticalSplitter.getFirstComponent();
  }
  else if (ToolWindowAnchor.LEFT == anchor) {
    return myHorizontalSplitter.getFirstComponent();
  }
  else if (ToolWindowAnchor.BOTTOM == anchor) {
    return myVerticalSplitter.getLastComponent();
  }
  else if (ToolWindowAnchor.RIGHT == anchor) {
    return myHorizontalSplitter.getLastComponent();
  }
  else {
    LOG.error("unknown anchor: " + anchor);
    return null;
  }
}
 
Example 8
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Sets (docks) specified component to the specified anchor.
 */
private void setComponent(final JComponent component, @Nonnull ToolWindowAnchor anchor, final float weight) {
  if (ToolWindowAnchor.TOP == anchor) {
    myVerticalSplitter.setFirstComponent(component);
    myVerticalSplitter.setFirstSize((int)(myLayeredPane.getHeight() * weight));
  }
  else if (ToolWindowAnchor.LEFT == anchor) {
    myHorizontalSplitter.setFirstComponent(component);
    myHorizontalSplitter.setFirstSize((int)(myLayeredPane.getWidth() * weight));
  }
  else if (ToolWindowAnchor.BOTTOM == anchor) {
    myVerticalSplitter.setLastComponent(component);
    myVerticalSplitter.setLastSize((int)(myLayeredPane.getHeight() * weight));
  }
  else if (ToolWindowAnchor.RIGHT == anchor) {
    myHorizontalSplitter.setLastComponent(component);
    myHorizontalSplitter.setLastSize((int)(myLayeredPane.getWidth() * weight));
  }
  else {
    LOG.error("unknown anchor: " + anchor);
  }
}
 
Example 9
Source File: WebToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setComponent(@Nullable ToolWindowInternalDecorator d, @Nonnull ToolWindowAnchor anchor, final float weight) {
  WebToolWindowInternalDecorator decorator = (WebToolWindowInternalDecorator)d;

  consulo.ui.Component component = decorator == null ? null : decorator.getComponent();

  if (ToolWindowAnchor.TOP == anchor) {
    //myVerticalSplitter.setFirstComponent(component);
    //myVerticalSplitter.setFirstSize((int)(myLayeredPane.getHeight() * weight));
  }
  else if (ToolWindowAnchor.LEFT == anchor) {
    myHorizontalSplitter.setFirstComponent(component);
    //myHorizontalSplitter.setFirstSize((int)(myLayeredPane.getWidth() * weight));
  }
  else if (ToolWindowAnchor.BOTTOM == anchor) {
    //myVerticalSplitter.setLastComponent(component);
    //myVerticalSplitter.setLastSize((int)(myLayeredPane.getHeight() * weight));
  }
  else if (ToolWindowAnchor.RIGHT == anchor) {
    myHorizontalSplitter.setSecondComponent(component);
    //myHorizontalSplitter.setLastSize((int)(myLayeredPane.getWidth() * weight));
  }
  else {
    //LOG.error("unknown anchor: " + anchor);
  }
}
 
Example 10
Source File: WebToolWindowPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public final void run() {
  try {
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    if (ToolWindowAnchor.TOP == anchor) {
      myTopStripe.addButton(myButton, myComparator);
    }
    else if (ToolWindowAnchor.LEFT == anchor) {
      myLeftStripe.addButton(myButton, myComparator);
    }
    else if (ToolWindowAnchor.BOTTOM == anchor) {
      myBottomStripe.addButton(myButton, myComparator);
    }
    else if (ToolWindowAnchor.RIGHT == anchor) {
      myRightStripe.addButton(myButton, myComparator);
    }
    else {
      LOGGER.error("unknown anchor: " + anchor);
    }
    getVaadinComponent().markAsDirtyRecursive();
  }
  finally {
    finish();
  }
}
 
Example 11
Source File: StripeTabPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredUIAccess
public TabInfo addTab(@Nonnull String tabName, @Nonnull JComponent component, @Nullable JComponent preferredFocusableComponent) {
  StaticAnchoredButton button = new StaticAnchoredButton(tabName, ToolWindowAnchor.LEFT);

  button.addItemListener(myItemListener);
  button.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
  button.setBackground(new Color(247, 243, 239));
  button.setUI((ButtonUI)DesktopStripeButtonUI.createUI(button));

  myTabPanel.add(button);

  TabInfo tabInfo = new TabInfo(button, component, preferredFocusableComponent);
  button.putClientProperty(TabInfo.class, tabInfo);

  myButtonGroup.add(button);
  myContentPanel.add(component, tabName);
  if(myButtonGroup.getSelection() == null) {
    tabInfo.select();
  }
  return tabInfo;
}
 
Example 12
Source File: DesktopStripeButtonUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Dimension getPreferredSize(final JComponent c) {
  final AnchoredButton button = (AnchoredButton)c;
  final Dimension dim = super.getPreferredSize(button);

  dim.width = (int)(JBUI.scale(4) + dim.width * 1.1f);
  dim.height += JBUI.scale(2);

  final ToolWindowAnchor anchor = button.getAnchor();
  if (ToolWindowAnchor.LEFT == anchor || ToolWindowAnchor.RIGHT == anchor) {
    return new Dimension(dim.height, dim.width);
  }
  else {
    return dim;
  }
}
 
Example 13
Source File: WebToolWindowPanelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  try {
    WebToolWindowStripeButtonImpl stripeButton = getButtonById(myId);
    if (stripeButton == null) {
      return;
    }

    WindowInfo info = stripeButton.getWindowInfo();
    ToolWindowAnchor anchor = info.getAnchor();

    if (ToolWindowAnchor.TOP == anchor) {
      myTopStripe.markAsDirtyRecursive();
    }
    else if (ToolWindowAnchor.LEFT == anchor) {
      myLeftStripe.markAsDirtyRecursive();
    }
    else if (ToolWindowAnchor.BOTTOM == anchor) {
      myBottomStripe.markAsDirtyRecursive();
    }
    else if (ToolWindowAnchor.RIGHT == anchor) {
      myRightStripe.markAsDirtyRecursive();
    }
    else {
      LOGGER.error("unknown anchor: " + anchor);
    }
  }
  finally {
    finish();
  }
}
 
Example 14
Source File: RoutesView.java    From railways with MIT License 5 votes vote down vote up
private void updateToolWindowOrientation(ToolWindow toolWindow) {
    if (toolWindow.isDisposed())
        return;

    ToolWindowAnchor anchor = toolWindow.getAnchor();
    boolean isVertical = (anchor == ToolWindowAnchor.LEFT ||
            anchor == ToolWindowAnchor.RIGHT);

    mainPanel.setOrientation(isVertical);
}
 
Example 15
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void stretch(@Nonnull ToolWindow wnd, int value) {
  Pair<Resizer, Component> pair = findResizerAndComponent(wnd);
  if (pair == null) return;

  boolean vertical = wnd.getAnchor() == ToolWindowAnchor.TOP || wnd.getAnchor() == ToolWindowAnchor.BOTTOM;
  int actualSize = (vertical ? pair.second.getHeight() : pair.second.getWidth()) + value;
  boolean first = wnd.getAnchor() == ToolWindowAnchor.LEFT || wnd.getAnchor() == ToolWindowAnchor.TOP;
  int maxValue = vertical ? myVerticalSplitter.getMaxSize(first) : myHorizontalSplitter.getMaxSize(first);
  int minValue = vertical ? myVerticalSplitter.getMinSize(first) : myHorizontalSplitter.getMinSize(first);

  pair.first.setSize(Math.max(minValue, Math.min(maxValue, actualSize)));
}
 
Example 16
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  try {
    DesktopStripeButton stripeButton = getButtonById(myId);
    if (stripeButton == null) {
      return;
    }

    WindowInfoImpl info = stripeButton.getWindowInfo();
    ToolWindowAnchor anchor = info.getAnchor();

    if (ToolWindowAnchor.TOP == anchor) {
      myTopStripe.revalidate();
    }
    else if (ToolWindowAnchor.LEFT == anchor) {
      myLeftStripe.revalidate();
    }
    else if (ToolWindowAnchor.BOTTOM == anchor) {
      myBottomStripe.revalidate();
    }
    else if (ToolWindowAnchor.RIGHT == anchor) {
      myRightStripe.revalidate();
    }
    else {
      LOG.error("unknown anchor: " + anchor);
    }
  }
  finally {
    finish();
  }
}
 
Example 17
Source File: DesktopStripeButton.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean is(boolean first) {
  Container parent = getParent();
  if (parent == null) return false;

  int max = first ? Integer.MAX_VALUE : 0;
  ToolWindowAnchor anchor = getAnchor();
  Component c = null;
  int count = parent.getComponentCount();
  for (int i = 0; i < count; i++) {
    Component component = parent.getComponent(i);
    if (!component.isVisible()) continue;
    Rectangle r = component.getBounds();
    if (anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT) {
      if (first && max > r.y || !first && max < r.y) {
        max = r.y;
        c = component;
      }
    } else {
      if (first && max > r.x || !first && max < r.x) {
        max = r.x;
        c = component;
      }
    }
  }


  return c == this;
}
 
Example 18
Source File: Surface.java    From consulo with Apache License 2.0 5 votes vote down vote up
public final void runMovement() {
  if(!isShowing()){
    return;
  }
  final int distance;
  final Rectangle bounds = getBounds();
  if (myAnchor == ToolWindowAnchor.LEFT || myAnchor == ToolWindowAnchor.RIGHT) {
    distance = bounds.width;
  }
  else {
    distance = bounds.height;
  }
  final double desiredTime = distance / myPixelsPerSec * 1000;
  final long startTime = System.currentTimeMillis();
  int count = 0;
  myOffset = 0;


  while(true){
    paintImmediately(0,0,getWidth(),getHeight());
    final long timeSpent = System.currentTimeMillis() - startTime;
    count++;
    if (timeSpent >= desiredTime) break;
    final double onePaintTime = (double)timeSpent / count;
    int iterations = (int)((desiredTime - timeSpent) / onePaintTime);
    iterations = Math.max(1, iterations);
    myOffset += (distance - myOffset) / iterations;
  }
}
 
Example 19
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private Pair<Resizer, Component> findResizerAndComponent(@Nonnull ToolWindow wnd) {
  if (!wnd.isVisible()) return null;

  Resizer resizer = null;
  Component cmp = null;

  if (wnd.getType() == ToolWindowType.DOCKED) {
    cmp = getComponentAt(wnd.getAnchor());

    if (cmp != null) {
      if (wnd.getAnchor().isHorizontal()) {
        resizer = myVerticalSplitter.getFirstComponent() == cmp ? new Resizer.Splitter.FirstComponent(myVerticalSplitter) : new Resizer.Splitter.LastComponent(myVerticalSplitter);
      }
      else {
        resizer = myHorizontalSplitter.getFirstComponent() == cmp ? new Resizer.Splitter.FirstComponent(myHorizontalSplitter) : new Resizer.Splitter.LastComponent(myHorizontalSplitter);
      }
    }
  }
  else if (wnd.getType() == ToolWindowType.SLIDING) {
    cmp = wnd.getComponent();
    while (cmp != null) {
      if (cmp.getParent() == myLayeredPane) break;
      cmp = cmp.getParent();
    }

    if (cmp != null) {
      if (wnd.getAnchor() == ToolWindowAnchor.TOP) {
        resizer = new Resizer.LayeredPane.Top(cmp);
      }
      else if (wnd.getAnchor() == ToolWindowAnchor.BOTTOM) {
        resizer = new Resizer.LayeredPane.Bottom(cmp);
      }
      else if (wnd.getAnchor() == ToolWindowAnchor.LEFT) {
        resizer = new Resizer.LayeredPane.Left(cmp);
      }
      else if (wnd.getAnchor() == ToolWindowAnchor.RIGHT) {
        resizer = new Resizer.LayeredPane.Right(cmp);
      }
    }
  }

  return resizer != null ? Pair.create(resizer, cmp) : null;
}
 
Example 20
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  try {
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    class MySplitter extends Splitter implements UISettingsListener {
      @Override
      public void uiSettingsChanged(UISettings uiSettings) {
        if (anchor == ToolWindowAnchor.LEFT) {
          setOrientation(!uiSettings.getLeftHorizontalSplit());
        }
        else if (anchor == ToolWindowAnchor.RIGHT) {
          setOrientation(!uiSettings.getRightHorizontalSplit());
        }
      }
    }
    Splitter splitter = new MySplitter();
    splitter.setOrientation(anchor.isSplitVertically());
    if (!anchor.isHorizontal()) {
      splitter.setAllowSwitchOrientationByMouseClick(true);
      splitter.addPropertyChangeListener(evt -> {
        if (!Splitter.PROP_ORIENTATION.equals(evt.getPropertyName())) return;
        boolean isSplitterHorizontalNow = !splitter.isVertical();
        UISettings settings = UISettings.getInstance();
        if (anchor == ToolWindowAnchor.LEFT) {
          if (settings.getLeftHorizontalSplit() != isSplitterHorizontalNow) {
            settings.setLeftHorizontalSplit(isSplitterHorizontalNow);
            settings.fireUISettingsChanged();
          }
        }
        if (anchor == ToolWindowAnchor.RIGHT) {
          if (settings.getRightHorizontalSplit() != isSplitterHorizontalNow) {
            settings.setRightHorizontalSplit(isSplitterHorizontalNow);
            settings.fireUISettingsChanged();
          }
        }
      });
    }
    JComponent c = getComponentAt(anchor);
    float newWeight;
    if (c instanceof DesktopInternalDecorator) {
      DesktopInternalDecorator oldComponent = (DesktopInternalDecorator)c;
      if (myInfo.isSplit()) {
        splitter.setFirstComponent(oldComponent);
        splitter.setSecondComponent(myNewComponent);
        float proportion = getPreferredSplitProportion(oldComponent.getWindowInfo().getId(), WindowInfoImpl
                .normalizeWeigh(oldComponent.getWindowInfo().getSideWeight() / (oldComponent.getWindowInfo().getSideWeight() + myInfo.getSideWeight())));
        splitter.setProportion(proportion);
        if (!anchor.isHorizontal() && !anchor.isSplitVertically()) {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight());
        }
        else {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight());
        }
      }
      else {
        splitter.setFirstComponent(myNewComponent);
        splitter.setSecondComponent(oldComponent);
        splitter.setProportion(WindowInfoImpl.normalizeWeigh(myInfo.getSideWeight()));
        if (!anchor.isHorizontal() && !anchor.isSplitVertically()) {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight());
        }
        else {
          newWeight = WindowInfoImpl.normalizeWeigh(myInfo.getWeight());
        }
      }
    }
    else {
      newWeight = WindowInfoImpl.normalizeWeigh(myInfo.getWeight());
    }
    setComponent(splitter, anchor, newWeight);

    if (!myDirtyMode) {
      myLayeredPane.validate();
      myLayeredPane.repaint();
    }
  }
  finally {
    finish();
  }
}