Skip to content

Instantly share code, notes, and snippets.

@kompiro
Created Jun 10, 2012
Embed
What would you like to do?
astahの図にカレンダーの画像を貼るプラグイン。マインドマップを書くとき、カレンダーを貼ると議事録などに重宝したので作成中。
package com.change_vision.astah.calendar;
import java.awt.FlowLayout
import java.awt.Graphics2D
import java.awt.MouseInfo
import java.awt.Point
import java.awt.RenderingHints
import java.awt.image.BufferedImage
import javax.swing.JDialog
import org.jdesktop.swingx.JXMonthView
import org.jdesktop.swingx.event.DateSelectionEvent
import org.jdesktop.swingx.event.DateSelectionListener
import com.change_vision.jude.api.inf.editor.IDiagramEditorFactory
import com.change_vision.jude.api.inf.editor.MindmapEditor
import com.change_vision.jude.api.inf.model.IDiagram
import com.change_vision.jude.api.inf.project.ProjectAccessor
import com.change_vision.jude.api.inf.project.ProjectAccessorFactory
import com.change_vision.jude.api.inf.ui.IPluginActionDelegate
import com.change_vision.jude.api.inf.ui.IWindow
import com.change_vision.jude.api.inf.view.IDiagramViewManager
import com.change_vision.jude.api.inf.view.IViewManager
class CalendarImageAction implements IPluginActionDelegate {
def run(IWindow window){
def frame = new JDialog(window.getParent(),"Calendar");
frame.setModal(true)
frame.setLayout(new FlowLayout())
frame.setLocationRelativeTo(window.getParent())
def monthView = new JXMonthView();
monthView.setTraversable(true);
monthView.setPreferredRowCount(1);
def listener = {DateSelectionEvent event ->
if(!event.eventType.is(DateSelectionEvent.EventType.DATES_SET)) return;
def ps = monthView.getPreferredSize()
def image = new BufferedImage((int)ps.width, (int)ps.height, BufferedImage.TYPE_INT_ARGB)
def g2 = (Graphics2D)image.getGraphics()
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR)
monthView.paint(g2)
g2.dispose()
ProjectAccessor accessor = ProjectAccessorFactory.getProjectAccessor()
IDiagramEditorFactory diagramEditorFactory = accessor.getDiagramEditorFactory()
MindmapEditor mmEditor = diagramEditorFactory.getMindmapEditor()
IViewManager viewManager = accessor.getViewManager()
IDiagramViewManager dvm = viewManager.getDiagramViewManager()
IDiagram diagram = dvm.getCurrentDiagram()
mmEditor.diagram = diagram
def tm = accessor.transactionManager
tm.beginTransaction()
def ml = MouseInfo.getPointerInfo().getLocation()
mmEditor.createImage(image,new Point((int)(dvm.toWorldCoordX((int)ml.x)),(int)(dvm.toWorldCoordY((int)ml.y))))
tm.endTransaction()
frame.setVisible(false)
} as DateSelectionListener
monthView.getSelectionModel().addDateSelectionListener(listener)
frame.add(monthView)
frame.pack()
frame.setVisible(true)
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment