Created
June 10, 2012 04:16
-
-
Save kompiro/2903807 to your computer and use it in GitHub Desktop.
astahの図にカレンダーの画像を貼るプラグイン。マインドマップを書くとき、カレンダーを貼ると議事録などに重宝したので作成中。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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