public boolean pasteTopicsFromClipboard ( ) { boolean result = false ; if ( this . lockIfNotDisposed ( ) ) { try { final Clipboard clipboard = Toolkit . getDefaultToolkit ( ) . getSystemClipboard ( ) ; if ( Utils . isDataFlavorAvailable ( clipboard , MMDTopicsTransferable . MMD_DATA_FLAVOR ) ) { try { final NBMindMapTopicsContainer container = ( NBMindMapTopicsContainer ) clipboard . getData ( MMDTopicsTransferable . MMD_DATA_FLAVOR ) ; if ( container != null && ! container . isEmpty ( ) ) { final Topic [ ] selected = this . getSelectedTopics ( ) ; if ( selected . length > 0 ) { for ( final Topic s : selected ) { for ( final Topic t : container . getTopics ( ) ) { final Topic newTopic = new Topic ( this . model , t , true ) ; newTopic . removeExtra ( Extra . ExtraType . TOPIC ) ; newTopic . moveToNewParent ( s ) ; MindMapUtils . ensureVisibility ( newTopic ) ; } } } doLayout ( ) ; revalidate ( ) ; repaint ( ) ; fireNotificationMindMapChanged ( true ) ; result = true ; } } catch ( final Exception ex ) { LOGGER . error ( "Can't get clipboard data" , ex ) ; } } else if ( Utils . isDataFlavorAvailable ( clipboard , DataFlavor . stringFlavor ) ) { try { final int MAX_TEXT_LEN = 96 ; String clipboardText = ( String ) clipboard . getContents ( null ) . getTransferData ( DataFlavor . stringFlavor ) ; if ( clipboardText != null ) { clipboardText = clipboardText . trim ( ) ; final String topicText ; final String extraNoteText ; if ( clipboardText . length ( ) > MAX_TEXT_LEN ) { topicText = clipboardText . substring ( 0 , MAX_TEXT_LEN ) + "..." ; extraNoteText = clipboardText ; } else { topicText = clipboardText ; extraNoteText = null ; } final Topic [ ] selectedTopics = this . getSelectedTopics ( ) ; if ( selectedTopics . length > 0 ) { for ( final Topic s : selectedTopics ) { final Topic newTopic ; if ( extraNoteText == null ) { newTopic = new Topic ( this . model , s , topicText ) ; } else { newTopic = new Topic ( this . model , s , topicText , new ExtraNote ( extraNoteText ) ) ; } MindMapUtils . ensureVisibility ( newTopic ) ; } doLayout ( ) ; revalidate ( ) ; repaint ( ) ; fireNotificationMindMapChanged ( true ) ; result = true ; } } } catch ( Exception ex ) { LOGGER . error ( "Can't get clipboard text" , ex ) ; } } } finally { this . unlock ( ) ; } } return result ; }
Paste topics from clipboard to currently selected ones .