java.awt.dnd.DragSourceEvent#com.alee.utils.SwingUtils源码实例Demo

下面列出了java.awt.dnd.DragSourceEvent#com.alee.utils.SwingUtils 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: weblaf   文件: WebAccordionModel.java
/**
 * Collapses {@link AccordionPane} with the specified identifier without any additional checks.
 * This method is intended for internal use only to avoid issues with overlapping minimum/maximum conditions.
 *
 * @param id {@link AccordionPane} identifier
 */
protected void collapseUnconditionally ( @NotNull final String id )
{
    getPaneState ( id ).setExpanded ( false );

    final WebAccordion accordion = getAccordion ();
    final AccordionPane pane = accordion.getPane ( id );

    final AccordionLayout layout = accordion.getLayout ();
    if ( layout != null )
    {
        layout.collapsePane ( accordion, id );
    }
    else
    {
        pane.fireCollapsing ( accordion );
        accordion.fireCollapsing ( pane );
        SwingUtils.update ( accordion );
        pane.fireCollapsed ( accordion );
        accordion.fireCollapsed ( pane );
    }
}
 
源代码2 项目: weblaf   文件: UISystemProxyConfirmationSupport.java
@Override
public boolean shouldUseSystemProxy ()
{
    // Whether should save the choice or not
    alwaysDoTheSame = new WebCheckBox ();
    alwaysDoTheSame.setLanguage ( "weblaf.proxy.use.system.save" );
    alwaysDoTheSame.setSelected ( false );
    alwaysDoTheSame.setFocusable ( false );

    // Ask for settings replacement with system ones
    final String message = LM.get ( "weblaf.proxy.use.system.text" );
    final String title = LM.get ( "weblaf.proxy.use.system.title" );
    final int options = WebExtendedOptionPane.YES_NO_OPTION;
    final int type = WebExtendedOptionPane.QUESTION_MESSAGE;
    final WebExtendedOptionPane dialog =
            WebExtendedOptionPane.showConfirmDialog ( SwingUtils.getActiveWindow (), message, alwaysDoTheSame, title, options, type );

    return dialog.getResult () == WebOptionPane.YES_OPTION;
}
 
源代码3 项目: weblaf   文件: WebDateFieldUI.java
/**
 * Uninstalls date field UI elements.
 */
protected void uninstallComponents ()
{
    dateField.removeAll ();
    dateField.revalidate ();
    dateField.repaint ();

    if ( calendar != null )
    {
        calendar.resetStyleId ();
        calendar = null;
    }
    if ( popup != null )
    {
        popup.resetStyleId ();
        popup = null;
    }
    button.resetStyleId ();
    button = null;
    field.resetStyleId ();
    field = null;

    SwingUtils.removeHandlesEnableStateMark ( dateField );
}
 
源代码4 项目: weblaf   文件: WSplitPaneInputListener.java
/**
 * Toggles focus between split pane sides.
 *
 * @param splitPane {@link JSplitPane}
 */
protected void toggleFocus ( @NotNull final S splitPane )
{
    final Component left = splitPane.getLeftComponent ();
    final Component right = splitPane.getRightComponent ();
    final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
    final Component focus = manager.getFocusOwner ();
    final Component focusOn = getNextSide ( splitPane, focus );
    if ( focusOn != null )
    {
        /**
         * Don't change the focus if the new focused component belongs to the same splitpane and the same side.
         */
        if ( focus == null ||
                !( SwingUtilities.isDescendingFrom ( focus, left ) && SwingUtilities.isDescendingFrom ( focusOn, left ) ||
                        SwingUtilities.isDescendingFrom ( focus, right ) && SwingUtilities.isDescendingFrom ( focusOn, right ) ) )
        {
            SwingUtils.compositeRequestFocus ( focusOn );
        }
    }
}
 
源代码5 项目: weblaf   文件: SizeCache.java
/**
 * Returns maximum {@link Dimension} combined from maximum sizes of all {@link Container}'s children.
 *
 * @param container {@link Container}
 * @param cache     {@link SizeCache} to reuse sizes from
 * @return maximum {@link Dimension} combined from maximum sizes of all {@link Container}'s children
 */
public Dimension maxMaximum ( @NotNull final Container container, @NotNull final SizeCache cache )
{
    if ( preferred == null )
    {
        preferred = new Dimension ( 0, 0 );
        for ( int index = 0; index < container.getComponentCount (); index++ )
        {
            preferred = SwingUtils.maxNonNull (
                    preferred,
                    cache.maximum ( container, index )
            );
        }
    }
    return preferred;
}
 
源代码6 项目: weblaf   文件: EventMethodsImpl.java
/**
 * Shortcut method for double-click mouse event.
 *
 * @param component component to handle events for
 * @param runnable  mouse event runnable
 * @return created {@link MouseAdapter}
 */
@NotNull
public static MouseAdapter onDoubleClick ( @NotNull final Component component, @NotNull final MouseEventRunnable runnable )
{
    final MouseAdapter mouseAdapter = new MouseAdapter ()
    {
        @Override
        public void mouseClicked ( @NotNull final MouseEvent e )
        {
            if ( SwingUtils.isDoubleClick ( e ) )
            {
                runnable.run ( e );
            }
        }
    };
    component.addMouseListener ( mouseAdapter );
    return mouseAdapter;
}
 
源代码7 项目: weblaf   文件: EventMethodsImpl.java
/**
 * Shortcut method for mouse event triggering popup menu.
 *
 * @param component component to handle events for
 * @param runnable  mouse event runnable
 * @return created {@link MouseAdapter}
 */
@NotNull
public static MouseAdapter onMenuTrigger ( @NotNull final Component component, @NotNull final MouseEventRunnable runnable )
{
    final MouseAdapter mouseAdapter = new MouseAdapter ()
    {
        @Override
        public void mousePressed ( @NotNull final MouseEvent e )
        {
            if ( SwingUtils.isRightMouseButton ( e ) )
            {
                runnable.run ( e );
            }
        }
    };
    component.addMouseListener ( mouseAdapter );
    return mouseAdapter;
}
 
源代码8 项目: weblaf   文件: WebDockableFrameUI.java
/**
 * Requests focus for frame content if possible.
 */
protected void requestFocusInFrame ()
{
    CoreSwingUtils.invokeLater ( new Runnable ()
    {
        @Override
        public void run ()
        {
            if ( !SwingUtils.hasFocusOwner ( frame ) )
            {
                final Component component = SwingUtils.findFocusableComponent ( frame );
                if ( component != null )
                {
                    // Pass focus to the first focusable component within container
                    component.requestFocusInWindow ();
                }
                else
                {
                    // Pass focus onto the frame itself
                    // Normally focus will never get onto the frame, but we can still use it when we have no other options
                    frame.requestFocusInWindow ();
                }
            }
        }
    } );
}
 
源代码9 项目: weblaf   文件: DynamicMenuLayout.java
protected void layoutPlainMenu ( final WebDynamicMenu menu, final float displayProgress, final DynamicMenuType type )
{
    final Dimension max = SwingUtils.maxPreferredSize ( menu.getComponents () );
    final int itemsCount = menu.getComponentCount ();

    switch ( type )
    {
        case list:
        {
            final int x = 0;
            int y = 0;
            for ( int i = 0; i < itemsCount; i++ )
            {
                placePlainElement ( menu, i, x, y );
                y += max.height * displayProgress;
            }
        }
        break;
    }
}
 
源代码10 项目: weblaf   文件: DictionariesTransferHandler.java
public DictionariesTransferHandler ( final DictionariesTree tree )
{
    super ();
    this.tree = tree;

    tree.addMouseMotionListener ( new MouseAdapter ()
    {
        @Override
        public void mouseDragged ( final MouseEvent e )
        {
            if ( SwingUtilities.isLeftMouseButton ( e ) )
            {
                exportAsDrag ( DictionariesTransferHandler.this.tree, e,
                        SwingUtils.isCtrl ( e ) ? TransferHandler.COPY : TransferHandler.MOVE );
            }
        }
    } );
}
 
源代码11 项目: weblaf   文件: ProgressBarPainter.java
@NotNull
@Override
public Dimension getPreferredSize ()
{
    // Minimum size
    final Dimension min = getMinimumContentSize ();
    int w = min.width;
    int h = min.height;

    // Text size
    // todo Retrieve size from painter
    if ( component.isStringPainted () )
    {
        final boolean hor = isHorizontal ();
        final FontMetrics fontSizer = component.getFontMetrics ( component.getFont () );
        final String progString = component.getString ();
        final int stringWidth = SwingUtils.stringWidth ( fontSizer, progString );
        final int stringHeight = fontSizer.getHeight () + fontSizer.getDescent ();
        w = Math.max ( w, hor ? stringWidth : stringHeight );
        h = Math.max ( h, hor ? stringHeight : stringWidth );
    }

    // Final size
    final Insets border = component.getInsets ();
    return new Dimension ( border.left + w + border.right, border.top + h + border.bottom );
}
 
源代码12 项目: weblaf   文件: WLabelInputListener.java
/**
 * Performs on-release action.
 *
 * @param label {@link JLabel}
 */
protected void doRelease ( final L label )
{
    final Component labelFor = label.getLabelFor ();
    if ( labelFor != null && labelFor.isEnabled () )
    {
        final InputMap inputMap = SwingUtilities.getUIInputMap ( label, JComponent.WHEN_FOCUSED );
        if ( inputMap != null )
        {
            inputMap.remove ( KeyStroke.getKeyStroke ( label.getDisplayedMnemonic (), ActionEvent.ALT_MASK, true ) );
            inputMap.remove ( KeyStroke.getKeyStroke ( KeyEvent.VK_ALT, 0, true ) );
        }

        if ( labelFor instanceof Container && ( ( Container ) labelFor ).isFocusCycleRoot () )
        {
            labelFor.requestFocus ();
        }
        else
        {
            SwingUtils.compositeRequestFocus ( labelFor );
        }
    }
}
 
源代码13 项目: weblaf   文件: AccordionPane.java
/**
 * Replaces content {@link Component}.
 *
 * @param content new content {@link Component}
 */
public void setContent ( @Nullable final Component content )
{
    if ( this.content != content )
    {
        if ( this.content != null )
        {
            remove ( this.content );
        }
        this.content = content;
        if ( this.content != null )
        {
            add ( this.content );
        }
        SwingUtils.update ( this );
    }
}
 
源代码14 项目: weblaf   文件: WebGradientColorChooser.java
@Override
public void mouseClicked ( final MouseEvent e )
{
    if ( !isEnabled () )
    {
        return;
    }

    // Displaying color chooser dialog on double-click
    if ( SwingUtils.isDoubleClick ( e ) )
    {
        final GradientColorData colorData = getColorDataUnderPoint ( e.getPoint () );
        if ( colorData != null )
        {
            final Color newColor = WebColorChooser.showDialog ( WebGradientColorChooser.this, colorData.getColor () );
            if ( newColor != null )
            {
                // Updating color
                colorData.setColor ( newColor );

                fireStateChanged ();
                repaint ();
            }
        }
    }
}
 
源代码15 项目: weblaf   文件: AbstractListCellEditor.java
/**
 * Installs start edit actions in the list.
 *
 * @param list list to process
 */
protected void installStartEditActions ( final JList list )
{
    mouseAdapter = new MouseAdapter ()
    {
        @Override
        public void mouseClicked ( final MouseEvent e )
        {
            if ( getClicksToEdit () > 0 && e.getClickCount () == getClicksToEdit () && SwingUtils.isLeftMouseButton ( e ) )
            {
                final Point point = e.getPoint ();
                final int index = list.getUI ().locationToIndex ( list, point );
                if ( index >= 0 && index < list.getModel ().getSize () )
                {
                    final Rectangle cell = list.getCellBounds ( index, index );
                    if ( cell.contains ( point ) )
                    {
                        startEdit ( list, index );
                    }
                }
            }
        }
    };
    list.addMouseListener ( mouseAdapter );

    keyAdapter = new KeyAdapter ()
    {
        @Override
        public void keyReleased ( final KeyEvent e )
        {
            if ( Hotkey.F2.isTriggered ( e ) )
            {
                startEdit ( list, list.getSelectedIndex () );
            }
        }
    };
    list.addKeyListener ( keyAdapter );
}
 
源代码16 项目: weblaf   文件: WebAccordion.java
/**
 * Adds specified {@link AccordionPane} to this accordion.
 *
 * @param pane  {@link AccordionPane} to add
 * @param index {@link AccordionPane} index
 * @return added {@link AccordionPane}
 */
@NotNull
public AccordionPane addPane ( final int index, @NotNull final AccordionPane pane )
{
    add ( pane, index );
    SwingUtils.update ( this );
    return pane;
}
 
源代码17 项目: weblaf   文件: AbstractTitledPreview.java
@Override
public void applyEnabled ( final boolean enabled )
{
    for ( final JComponent component : getPreviewElements () )
    {
        SwingUtils.setEnabledRecursively ( component, enabled );
    }
}
 
源代码18 项目: weblaf   文件: GroupPaneExample.java
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
    final WebButton e1 = new WebButton ( "First" );
    final WebComboBox e2 = new WebComboBox ( new String[]{ "First", "Second", "Third" }, 1 );
    final WebTextField e3 = new WebTextField ( "Third" );
    final WebButton e4 = new WebButton ( "Last" );
    final GroupPane groupPane = new GroupPane ( getStyleId (), e1, e2, e3, e4 );
    SwingUtils.equalizeComponentsWidth ( groupPane.getComponents () );
    return CollectionUtils.asList ( groupPane );
}
 
源代码19 项目: weblaf   文件: TreeEventMethodsImpl.java
/**
 * Shortcut method for double-click mouse event on specific tree node with condition.
 *
 * @param tree      tree to handle events for
 * @param condition node condition
 * @param runnable  tree node event runnable
 * @param <N>       {@link MutableTreeNode} type
 * @return used mouse adapter
 */
@NotNull
public static <N extends MutableTreeNode> MouseAdapter onNodeDoubleClick ( @NotNull final WebTree<N> tree,
                                                                           @Nullable final Predicate<N> condition,
                                                                           @NotNull final TreeNodeEventRunnable<N> runnable )
{
    final MouseAdapter mouseAdapter = new MouseAdapter ()
    {
        @Override
        public void mouseClicked ( @NotNull final MouseEvent e )
        {
            if ( SwingUtils.isDoubleClick ( e ) )
            {
                final int row = tree.getUI ().getExactRowForLocation ( e.getPoint () );
                if ( row != -1 )
                {
                    final N node = tree.getNodeForRow ( row );
                    if ( node != null && ( condition == null || condition.test ( node ) ) )
                    {
                        runnable.run ( node );
                    }
                }
            }
        }
    };
    tree.addMouseListener ( mouseAdapter );
    return mouseAdapter;
}
 
源代码20 项目: weblaf   文件: GroupPaneExample.java
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
    final WebToggleButton b1 = new WebToggleButton ( "First", true );
    final WebToggleButton b2 = new WebToggleButton ( "Second" );
    final WebToggleButton b3 = new WebToggleButton ( "Third" );
    final WebToggleButton b4 = new WebToggleButton ( "Last" );
    final GroupPane groupPane = new GroupPane ( getStyleId (), b1, b2, b3, b4 );
    SwingUtils.equalizeComponentsWidth ( groupPane.getComponents () );
    return CollectionUtils.asList ( groupPane );
}
 
源代码21 项目: weblaf   文件: TableHeaderPainter.java
/**
 * Paints single table header cell (column).
 *
 * @param g2d           graphics context
 * @param c             table header
 * @param rect          cell bounds
 * @param columnIndex   column index
 * @param column        table column
 * @param draggedColumn currently dragged table column
 * @param columnModel   table column model
 */
protected void paintCell ( final Graphics2D g2d, final C c, final Rectangle rect, final int columnIndex, final TableColumn column,
                           final TableColumn draggedColumn, final TableColumnModel columnModel )
{
    // Table reference
    final JTable table = c.getTable ();

    // Complex check for the cases when trailing border should be painted
    // It can be painted for middle columns, dragged column or when table is smaller than viewport
    final JScrollPane scrollPane = SwingUtils.getScrollPane ( table );
    final boolean paintTrailingBorder = scrollPane != null && ( column == draggedColumn ||
            table.getAutoResizeMode () == JTable.AUTO_RESIZE_OFF && scrollPane.getViewport ().getWidth () > table.getWidth () ||
            ( ltr ? columnIndex != columnModel.getColumnCount () - 1 : columnIndex != 0 ) );

    // Left side border
    if ( ltr || paintTrailingBorder )
    {
        g2d.setColor ( gridColor );
        g2d.drawLine ( rect.x - 1, rect.y + 2, rect.x - 1, rect.y + rect.height - 4 );
    }

    // Painting dragged cell renderer
    final JComponent headerRenderer = ( JComponent ) getHeaderRenderer ( columnIndex );
    headerRenderer.setOpaque ( false );
    headerRenderer.setEnabled ( table == null || table.isEnabled () );
    rendererPane.paintComponent ( g2d, headerRenderer, component, rect.x, rect.y, rect.width, rect.height, true );

    // Right side border
    if ( !ltr || paintTrailingBorder )
    {
        g2d.setColor ( gridColor );
        g2d.drawLine ( rect.x + rect.width - 1, rect.y + 2, rect.x + rect.width - 1, rect.y + rect.height - 4 );
    }
}
 
源代码22 项目: weblaf   文件: WebGlassPane.java
/**
 * Displays single component on glass pane.
 *
 * @param component component to display
 */
public void showComponent ( @NotNull final JComponent component )
{
    // Updating added component and its children orientation
    SwingUtils.copyOrientation ( WebGlassPane.this, component );

    // Adding with 0 index to put component on top of all existing
    WebGlassPane.this.add ( component, 0 );
    WebGlassPane.this.revalidate ();
    WebGlassPane.this.repaint ( component.getBounds () );
}
 
源代码23 项目: weblaf   文件: AbstractSimpleStyledTextContent.java
/**
 * Performs style caches update.
 *
 * @param c painted component
 * @param d painted decoration state
 */
protected void initializeContentCache ( @NotNull final C c, @NotNull final D d )
{
    // Updating styled text
    styleRanges = new StyleRanges ( getComponentText ( c, d ) );

    // Updating painted mnemonic index
    // We cannot use button mnemonic index since it doesn't exclude style syntax from calculations
    mnemonicIndex = SwingUtils.getMnemonicIndex ( styleRanges.getPlainText (), getComponentMnemonic ( c, d ) );
}
 
源代码24 项目: weblaf   文件: AbstractComponentPreview.java
/**
 * Creates and returns {@link Insets} text.
 *
 * @param insets {@link Insets} to render
 * @param color  text color
 * @return {@link Insets} text
 */
@NotNull
protected String renderInsets ( @Nullable final Insets insets, @NotNull final String color )
{
    final String text;
    if ( !SwingUtils.isEmpty ( insets ) )
    {
        text = " {[ " + InsetsConverter.insetsToString ( insets ) + " ]:b;c(" + color + ")}";
    }
    else
    {
        text = "";
    }
    return text;
}
 
源代码25 项目: weblaf   文件: HotkeyData.java
/**
 * Constructs hotkey using the specified key stroke.
 *
 * @param keyStroke key stroke
 */
public HotkeyData ( @NotNull final KeyStroke keyStroke )
{
    this (
            SwingUtils.isCtrl ( keyStroke.getModifiers () ),
            SwingUtils.isAlt ( keyStroke.getModifiers () ),
            SwingUtils.isShift ( keyStroke.getModifiers () ),
            keyStroke.getKeyCode ()
    );
}
 
源代码26 项目: weblaf   文件: HotkeyData.java
/**
 * Returns whether hotkey controls are triggered by the key event or not.
 *
 * @param event processed key event
 * @return true if hotkey controls are triggered by the key event, false otherwise
 */
public boolean areControlsTriggered ( @NotNull final KeyEvent event )
{
    return SwingUtils.isShortcut ( event ) == isCtrl &&
            SwingUtils.isAlt ( event ) == isAlt &&
            SwingUtils.isShift ( event ) == isShift;
}
 
源代码27 项目: weblaf   文件: HighlightManager.java
/**
 * Highlights components with specified text on window
 */

public static List<Component> highlightComponentsWithText ( final String text, final Component highlightBase )
{
    final List<Component> found = SwingUtils.findComponentsWithText ( text, highlightBase );
    if ( found.size () > 0 )
    {
        setHiglightedComponents ( found, highlightBase );
    }
    else
    {
        clearHighlightedComponents ( highlightBase );
    }
    return found;
}
 
源代码28 项目: weblaf   文件: WebStepProgress.java
@Override
public void mousePressed ( final MouseEvent e )
{
    if ( isEnabled () && isSelectionEnabled () && SwingUtils.isLeftMouseButton ( e ) )
    {
        selecting = true;
        updateProgress ( e.getPoint () );
    }
}
 
源代码29 项目: weblaf   文件: SlidingLayout.java
public void slideIn ()
{
    if ( animator != null && animator.isRunning () )
    {
        animator.stop ();
    }

    slideY = 0;
    animator = new WebTimer ( "SlidingLayout.slideInTimer", SwingUtils.frameRateDelay ( 36 ), new ActionListener ()
    {
        @Override
        public void actionPerformed ( final ActionEvent e )
        {
            if ( slideY < height )
            {
                slideY += slideSpeed;
                container.revalidate ();
            }
            else
            {
                slideY = height;
                animator.stop ();
            }
        }
    } );
    animator.start ();
}
 
源代码30 项目: weblaf   文件: WebPopupMenuUI.java
@Override
public void uninstallUI ( @NotNull final JComponent c )
{
    // Uninstalling applied skin
    StyleManager.uninstallSkin ( popupMenu );

    // Uninstalling enabled state handling marker
    SwingUtils.removeHandlesEnableStateMark ( popupMenu );

    // Uninstalling UI
    super.uninstallUI ( c );
}