<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
- <toolWindow id="Sample Calendar" icon="/com/intellij/openapi/toolWindow/plus.png" anchor="right" factoryClass="com.intellij.openapi.toolWindow.MyToolWindowFactory" >
+ <toolWindow id="Sample Calendar" secondary="true" icon="/com/intellij/openapi/toolWindow/plus.png" anchor="right" factoryClass="com.intellij.openapi.toolWindow.MyToolWindowFactory" >
</toolWindow>
</extensions>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.toolWindow.MyToolWindowFactory">
+ <grid id="27dc6" binding="myToolWindowContent" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
+ <constraints>
+ <xy x="20" y="20" width="500" height="400"/>
+ </constraints>
+ <properties/>
+ <border type="none"/>
+ <children>
+ <component id="9aa3f" class="javax.swing.JLabel" binding="currentDate">
+ <constraints>
+ <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Date"/>
+ </properties>
+ </component>
+ <component id="44be3" class="javax.swing.JLabel" binding="timeZone">
+ <constraints>
+ <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="TimeZone"/>
+ </properties>
+ </component>
+ <component id="f02af" class="javax.swing.JLabel" binding="currentTime">
+ <constraints>
+ <grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Time"/>
+ </properties>
+ </component>
+ <component id="5fceb" class="javax.swing.JButton" binding="refreshToolWindowButton">
+ <constraints>
+ <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Refresh"/>
+ </properties>
+ </component>
+ <component id="3edc1" class="javax.swing.JButton" binding="hideToolWindowButton">
+ <constraints>
+ <grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Hide"/>
+ </properties>
+ </component>
+ <hspacer id="8bf9c">
+ <constraints>
+ <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ </hspacer>
+ <hspacer id="26841">
+ <constraints>
+ <grid row="1" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ </hspacer>
+ </children>
+ </grid>
+</form>
import com.intellij.ui.content.ContentFactory;
import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Calendar;
/**
* Created by IntelliJ IDEA.
*/
public class MyToolWindowFactory implements ToolWindowFactory {
- // Creates the tool window content.
+ private JButton refreshToolWindowButton;
+ private JButton hideToolWindowButton;
+ private JLabel currentDate;
+ private JLabel currentTime;
+ private JLabel timeZone;
+ private JPanel myToolWindowContent;
+ private ToolWindow myToolWindow;
+
+
+ public MyToolWindowFactory() {
+ hideToolWindowButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ myToolWindow.hide(null);
+ }
+ });
+ refreshToolWindowButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ MyToolWindowFactory.this.currentDateTime();
+ }
+ });
+ }
+
+ // Create the tool window content.
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
- ToolDialog myDialog = new ToolDialog();
- myDialog.toolWin = toolWindow;
- myDialog.currentDateTime();
- JPanel myContentPanel = myDialog.getPanel();
+ myToolWindow = toolWindow;
+ this.currentDateTime();
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
- Content content = contentFactory.createContent(myContentPanel, "", false);
+ Content content = contentFactory.createContent(myToolWindowContent, "", false);
toolWindow.getContentManager().addContent(content);
}
+ public void currentDateTime() {
+ // Get current date and time
+ Calendar instance = Calendar.getInstance();
+ currentDate.setText(String.valueOf(instance.get(Calendar.DAY_OF_MONTH)) + "/"
+ + String.valueOf(instance.get(Calendar.MONTH) + 1) + "/" + String.valueOf(instance.get(Calendar.YEAR)));
+ currentDate.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Calendar-icon.png")));
+ int min = instance.get(Calendar.MINUTE);
+ String strMin;
+ if (min < 10) {
+ strMin = "0" + String.valueOf(min);
+ } else {
+ strMin = String.valueOf(min);
+ }
+ currentTime.setText(instance.get(Calendar.HOUR_OF_DAY) + ":" + strMin);
+ currentTime.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-icon.png")));
+ // Get time zone
+ long gmt_Offset = instance.get(Calendar.ZONE_OFFSET); // offset from GMT in milliseconds
+ String str_gmt_Offset = String.valueOf(gmt_Offset / 3600000);
+ str_gmt_Offset = (gmt_Offset > 0) ? "GMT + " + str_gmt_Offset : "GMT - " + str_gmt_Offset;
+ timeZone.setText(str_gmt_Offset);
+ timeZone.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-zone-icon.png")));
+
+
+ }
+
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.toolWindow.ToolDialog">
- <grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="10" left="10" bottom="10" right="10"/>
- <constraints>
- <xy x="48" y="54" width="436" height="297"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <component id="e7465" class="javax.swing.JButton" binding="buttonRefresh">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="Refresh"/>
- </properties>
- </component>
- <component id="5723f" class="javax.swing.JButton" binding="buttonHide">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="Hide"/>
- </properties>
- </component>
- </children>
- </grid>
- </children>
- </grid>
- <grid id="e3588" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <component id="d6483" class="javax.swing.JLabel" binding="currentTime">
- <constraints>
- <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="Time:"/>
- </properties>
- </component>
- <component id="e7494" class="javax.swing.JLabel" binding="cirrentDate">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="Date: "/>
- </properties>
- </component>
- <component id="575f3" class="javax.swing.JLabel" binding="timeZone">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value="Time zone"/>
- </properties>
- </component>
- </children>
- </grid>
- </children>
- </grid>
-</form>
+++ /dev/null
-package com.intellij.openapi.toolWindow;
-
-import com.intellij.openapi.wm.ToolWindow;
-
-import javax.swing.*;
-import java.awt.event.*;
-import java.util.Calendar;
-
-public class ToolDialog extends JDialog {
- private JPanel contentPane;
- private JButton buttonRefresh;
- private JButton buttonHide;
-
- private JLabel cirrentDate;
- private JLabel currentTime;
- private JLabel timeZone;
- public ToolWindow toolWin;
-
-
- public ToolDialog() {
- setContentPane(contentPane);
- setModal(true);
- getRootPane().setDefaultButton(buttonRefresh);
-
-
- buttonRefresh.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onOK();
- }
- });
-
- buttonHide.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onCancel();
- }
- });
-
-// call onCancel() when cross is clicked
- setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- onCancel();
- }
- });
-
-// call onCancel() on ESCAPE
- contentPane.registerKeyboardAction(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onCancel();
- }
- }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
- }
-
- private void onOK() {
-// Refresh tool window.
- this.currentDateTime();
- dispose();
- }
-
- private void onCancel() {
-// Hide tool window.
- toolWin.hide(null);
- dispose();
- }
-
- public JPanel getPanel() {
- return contentPane;
- }
-
- public void currentDateTime() {
- // Get current date and time
- Calendar instance = Calendar.getInstance();
- cirrentDate.setText(String.valueOf(instance.get(Calendar.DAY_OF_MONTH)) + "/"
- + String.valueOf(instance.get(Calendar.MONTH) + 1) + "/" + String.valueOf(instance.get(Calendar.YEAR)));
- cirrentDate.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Calendar-icon.png")));
- int min = instance.get(Calendar.MINUTE);
- String strMin;
- if (min < 10) {
- strMin = "0" + String.valueOf(min);
- } else {
- strMin = String.valueOf(min);
- }
- currentTime.setText(instance.get(Calendar.HOUR_OF_DAY) + ":" + strMin);
- currentTime.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-icon.png")));
- // Get time zone
- long gmt_Offset = instance.get(Calendar.ZONE_OFFSET); // offset from GMT in milliseconds
- String str_gmt_Offset = String.valueOf(gmt_Offset / 3600000);
- str_gmt_Offset = (gmt_Offset > 0) ? "GMT + " + str_gmt_Offset : "GMT - " + str_gmt_Offset;
- timeZone.setText(str_gmt_Offset);
- timeZone.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-zone-icon.png")));
-
-
- }
-}