Example #1
0
 public ComponentTitledBorder(Component comp, JComponent container, Border border) {
   this.comp = comp;
   this.border = border;
   if (comp instanceof JComponent) {
     ((JComponent) comp).setOpaque(true);
   }
   container.addMouseListener(this);
   container.addMouseMotionListener(this);
 }
  @Override
  protected JComponent createChangePanel() {
    final JComponent primaryPanel = new JPanel(new BorderLayout());
    JComponent propertyPanel = new JPanel(new BorderLayout());
    JComponent nameAndRandomizePanel = new JPanel(new BorderLayout());
    JComponent propertySetterPanel = createPropertyPanel();
    JComponent centerPanel = createCenterPanel();
    if (canRandomize) {
      shouldRandomizeCheckBox = new JCheckBox();
      shouldRandomizeCheckBox.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              shouldRandomize = shouldRandomizeCheckBox.isSelected();
            }
          });
      nameAndRandomizePanel.add(shouldRandomizeCheckBox, BorderLayout.LINE_START);
      final MouseListener unrandomizer =
          new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
              if (e.getComponent().contains(e.getPoint())
                  && !shouldRandomizeCheckBox.contains(e.getPoint())) {
                shouldRandomizeCheckBox.setSelected(false);
                shouldRandomize = false;
              } else {
                System.out.println(e.getPoint() + "Is out of bounds");
              }
            }
          };
      ContainerListener mouseListenerAdder =
          new ContainerAdapter() {
            @Override
            public void componentAdded(ContainerEvent e) {
              addListeners(e.getChild());
            }

            public void addListeners(Component c) {
              c.addMouseListener(unrandomizer);
              if (c instanceof Container) {
                ((Container) c).addContainerListener(this);
                for (Component child : ((Container) c).getComponents()) {
                  addListeners(child);
                }
              }
            }
          };
      primaryPanel.addMouseListener(unrandomizer);
      primaryPanel.addContainerListener(mouseListenerAdder);
    }
    if (centerPanel != null) primaryPanel.add(centerPanel, BorderLayout.CENTER);
    nameAndRandomizePanel.add(new JLabel(name), BorderLayout.CENTER);
    propertyPanel.add(nameAndRandomizePanel, BorderLayout.LINE_START);
    propertyPanel.add(propertySetterPanel, BorderLayout.LINE_END);
    primaryPanel.add(propertyPanel, BorderLayout.PAGE_START);
    return primaryPanel;
  }
  /**
   * Creates a new {@code SwingTerminalImplementation}
   *
   * @param component JComponent that is the Swing terminal surface
   * @param fontConfiguration Font configuration to use
   * @param initialTerminalSize Initial size of the terminal
   * @param deviceConfiguration Device configuration
   * @param colorConfiguration Color configuration
   * @param scrollController Controller to be used when inspecting scroll status
   */
  SwingTerminalImplementation(
      JComponent component,
      SwingTerminalFontConfiguration fontConfiguration,
      TerminalSize initialTerminalSize,
      TerminalEmulatorDeviceConfiguration deviceConfiguration,
      TerminalEmulatorColorConfiguration colorConfiguration,
      TerminalScrollController scrollController) {

    super(initialTerminalSize, deviceConfiguration, colorConfiguration, scrollController);
    this.component = component;
    this.fontConfiguration = fontConfiguration;

    // Prevent us from shrinking beyond one character
    component.setMinimumSize(
        new Dimension(fontConfiguration.getFontWidth(), fontConfiguration.getFontHeight()));

    //noinspection unchecked
    component.setFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.<AWTKeyStroke>emptySet());
    //noinspection unchecked
    component.setFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.<AWTKeyStroke>emptySet());

    // Make sure the component is double-buffered to prevent flickering
    component.setDoubleBuffered(true);

    component.addKeyListener(new TerminalInputListener());
    component.addMouseListener(
        new TerminalMouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            SwingTerminalImplementation.this.component.requestFocusInWindow();
          }
        });
    component.addHierarchyListener(
        new HierarchyListener() {
          @Override
          public void hierarchyChanged(HierarchyEvent e) {
            if (e.getChangeFlags() == HierarchyEvent.DISPLAYABILITY_CHANGED) {
              if (e.getChanged().isDisplayable()) {
                onCreated();
              } else {
                onDestroyed();
              }
            }
          }
        });
  }
  public Java2DWindow(Core core, int width, int height) {
    this.core = core;
    this._frame = new JFrame();
    this._frame.setSize(width, height);
    this._frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this._rootcomp =
        new JComponent() {
          @Override
          protected void paintComponent(Graphics graphics) {
            Graphics2D gfx = (Graphics2D) graphics;
            _update(gfx, this);
          }
        };
    this._frame.add(_rootcomp);

    MasterListener ml = new MasterListener(_rootcomp, this);
    _rootcomp.addMouseListener(ml);
    _rootcomp.addMouseMotionListener(ml);
    _rootcomp.addKeyListener(ml);
  }
Example #5
0
 private static void addMouseListeners(JComponent control, List<MouseListener> mouseListeners) {
   for (int i = 0; i < mouseListeners.size(); i++) {
     MouseListener mouseListener = mouseListeners.get(i);
     control.addMouseListener(mouseListener);
   }
 }
  protected AbstractExpandableItemsHandler(@NotNull final ComponentType component) {
    myComponent = component;
    myComponent.add(myRendererPane);
    myComponent.validate();
    myPopup = new MovablePopup(myComponent, myTipComponent);

    myTipComponent.addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(MouseWheelEvent e) {
            dispatchEvent(myComponent, e);
          }
        });

    myTipComponent.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mousePressed(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseEntered(MouseEvent e) {}

          @Override
          public void mouseExited(MouseEvent e) {
            // don't hide the hint if mouse exited to owner component
            if (myComponent.getMousePosition() == null) {
              hideHint();
            }
          }
        });

    myTipComponent.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseMoved(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseDragged(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }
        });

    myComponent.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseEntered(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseExited(MouseEvent e) {
            // don't hide the hint if mouse exited to it
            if (myTipComponent.getMousePosition() == null) {
              hideHint();
            }
          }

          @Override
          public void mouseClicked(MouseEvent e) {}

          @Override
          public void mousePressed(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            handleMouseEvent(e);
          }
        });

    myComponent.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseDragged(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseMoved(MouseEvent e) {
            handleMouseEvent(e, false);
          }
        });

    myComponent.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            onFocusLost();
          }

          @Override
          public void focusGained(FocusEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentHidden(ComponentEvent e) {
            hideHint();
          }

          @Override
          public void componentMoved(ComponentEvent e) {
            updateCurrentSelection();
          }

          @Override
          public void componentResized(ComponentEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addHierarchyBoundsListener(
        new HierarchyBoundsAdapter() {
          @Override
          public void ancestorMoved(HierarchyEvent e) {
            updateCurrentSelection();
          }

          @Override
          public void ancestorResized(HierarchyEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addHierarchyListener(
        new HierarchyListener() {
          @Override
          public void hierarchyChanged(HierarchyEvent e) {
            hideHint();
          }
        });
  }
 public ComponentTitledBorder(Component comp, JComponent container, Border border) {
   this.comp = comp;
   this.container = container;
   this.border = border;
   container.addMouseListener(this);
 }
  ImageEditorUI(@Nullable ImageEditor editor) {
    this.editor = editor;

    Options options = OptionsManager.getInstance().getOptions();
    EditorOptions editorOptions = options.getEditorOptions();
    options.addPropertyChangeListener(optionsChangeListener);

    final PsiActionSupportFactory factory = PsiActionSupportFactory.getInstance();
    if (factory != null && editor != null) {
      copyPasteSupport =
          factory.createPsiBasedCopyPasteSupport(
              editor.getProject(),
              this,
              new PsiActionSupportFactory.PsiElementSelector() {
                public PsiElement[] getSelectedElements() {
                  PsiElement[] data = LangDataKeys.PSI_ELEMENT_ARRAY.getData(ImageEditorUI.this);
                  return data == null ? PsiElement.EMPTY_ARRAY : data;
                }
              });
    } else {
      copyPasteSupport = null;
    }

    deleteProvider = factory == null ? null : factory.createPsiBasedDeleteProvider();

    ImageDocument document = imageComponent.getDocument();
    document.addChangeListener(changeListener);

    // Set options
    TransparencyChessboardOptions chessboardOptions =
        editorOptions.getTransparencyChessboardOptions();
    GridOptions gridOptions = editorOptions.getGridOptions();
    imageComponent.setTransparencyChessboardCellSize(chessboardOptions.getCellSize());
    imageComponent.setTransparencyChessboardWhiteColor(chessboardOptions.getWhiteColor());
    imageComponent.setTransparencyChessboardBlankColor(chessboardOptions.getBlackColor());
    imageComponent.setGridLineZoomFactor(gridOptions.getLineZoomFactor());
    imageComponent.setGridLineSpan(gridOptions.getLineSpan());
    imageComponent.setGridLineColor(gridOptions.getLineColor());

    // Create layout
    ImageContainerPane view = new ImageContainerPane(imageComponent);
    view.addMouseListener(new EditorMouseAdapter());
    view.addMouseListener(new FocusRequester());

    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(view);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // Zoom by wheel listener
    scrollPane.addMouseWheelListener(wheelAdapter);

    // Construct UI
    setLayout(new BorderLayout());

    ActionManager actionManager = ActionManager.getInstance();
    ActionGroup actionGroup =
        (ActionGroup) actionManager.getAction(ImageEditorActions.GROUP_TOOLBAR);
    ActionToolbar actionToolbar =
        actionManager.createActionToolbar(ImageEditorActions.ACTION_PLACE, actionGroup, true);

    // Make sure toolbar is 'ready' before it's added to component hierarchy
    // to prevent ActionToolbarImpl.updateActionsImpl(boolean, boolean) from increasing popup size
    // unnecessarily
    actionToolbar.updateActionsImmediately();

    actionToolbar.setTargetComponent(this);

    JComponent toolbarPanel = actionToolbar.getComponent();
    toolbarPanel.addMouseListener(new FocusRequester());

    JLabel errorLabel =
        new JLabel(
            ImagesBundle.message("error.broken.image.file.format"),
            Messages.getErrorIcon(),
            SwingConstants.CENTER);

    JPanel errorPanel = new JPanel(new BorderLayout());
    errorPanel.add(errorLabel, BorderLayout.CENTER);

    contentPanel = new JPanel(new CardLayout());
    contentPanel.add(scrollPane, IMAGE_PANEL);
    contentPanel.add(errorPanel, ERROR_PANEL);

    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(toolbarPanel, BorderLayout.WEST);
    infoLabel = new JLabel((String) null, SwingConstants.RIGHT);
    infoLabel.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 0, 2));
    topPanel.add(infoLabel, BorderLayout.EAST);

    add(topPanel, BorderLayout.NORTH);
    add(contentPanel, BorderLayout.CENTER);

    updateInfo();
  }
  /** Sets up listeners */
  protected void setupListeners() {
    // Check to see if we need to close
    // the popup when a click outside of
    // it's area has been detected. Also,
    // we may need to propagte the events to
    // components below the glass pane
    glassPane.addMouseListener(
        new MouseListener() {
          /**
           * Invoked when the mouse button has been clicked (pressed and released) on a component.
           */
          public void mouseClicked(MouseEvent e) {
            propagateMouseListenerEvent(e);
          }

          /** Invoked when a mouse button has been pressed on a component. */
          public void mousePressed(MouseEvent e) {
            // Might need to hide the popup if the mouse
            // has been pressed on the glass pane
            handleHidePopup(e);

            propagateMouseListenerEvent(e);
          }

          /** Invoked when a mouse button has been released on a component. */
          public void mouseReleased(MouseEvent e) {
            propagateMouseListenerEvent(e);
          }

          /** Invoked when the mouse enters a component. */
          public void mouseEntered(MouseEvent e) {
            // Don't propagate here
            mouseOverGlassPane = true;
          }

          /** Invoked when the mouse exits a component. */
          public void mouseExited(MouseEvent e) {
            // Don't propagate
            mouseOverGlassPane = false;
          }

          /**
           * Checks to see if a mouse event on the glass pane should cause the popup to be hidden,
           * and if so, hides it.
           *
           * @param e The mouse event.
           */
          private void handleHidePopup(MouseEvent e) {
            if (HIDE_ON_CLICK == true) {
              hidePopup();
            }
          }
        });

    glassPane.addMouseMotionListener(
        new MouseMotionListener() {
          /**
           * Invoked when a mouse button is pressed on a component and then dragged. <code>
           * MOUSE_DRAGGED</code> events will continue to be delivered to the component where the
           * drag originated until the mouse button is released (regardless of whether the mouse
           * position is within the bounds of the component).
           *
           * <p>Due to platform-dependent Drag&Drop implementations, <code>MOUSE_DRAGGED</code>
           * events may not be delivered during a native Drag&Drop operation.
           */
          public void mouseDragged(MouseEvent e) {
            propagateMouseMotionListenerEvents(e);
          }

          /**
           * Invoked when the mouse cursor has been moved onto a component but no buttons have been
           * pushed.
           */
          public void mouseMoved(MouseEvent e) {
            propagateMouseMotionListenerEvents(e);
          }
        });
  }