-package com.intellij.openapi.samples;
+package com.intellij.openapi.toolWindow;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
-import com.intellij.openapi.wm.ToolWindowEP;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
-import com.intellij.util.ui.UIUtil;
import javax.swing.*;
-import java.awt.*;
/**
* Created by IntelliJ IDEA.
// Creates the tool window content.
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
- ToolDialog myDialog = new ToolDialog();
- myDialog.toolWin = toolWindow;
- myDialog.currentDateTime();
- JPanel myContentPanel = myDialog.getPanel();
- ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
- Content content = contentFactory.createContent(myContentPanel, "", false);
- toolWindow.getContentManager().addContent(content);
-
+ ToolDialog myDialog = new ToolDialog();
+ myDialog.toolWin = toolWindow;
+ myDialog.currentDateTime();
+ JPanel myContentPanel = myDialog.getPanel();
+ ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
+ Content content = contentFactory.createContent(myContentPanel, "", false);
+ toolWindow.getContentManager().addContent(content);
+
}
-
+
}
<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.samples.ToolDialog">
+<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>
<properties/>
<border type="none"/>
<children>
- <component id="d6483" class="javax.swing.JLabel" binding="Time22">
+ <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>
<text value="Time:"/>
</properties>
</component>
- <component id="e7494" class="javax.swing.JLabel" binding="Date22">
+ <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>
<text value="Date: "/>
</properties>
</component>
- <component id="575f3" class="javax.swing.JLabel" binding="TimeZone">
+ <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=""/>
+ <text value="Time zone"/>
</properties>
</component>
</children>
-package com.intellij.openapi.samples;
+package com.intellij.openapi.toolWindow;
import com.intellij.openapi.wm.ToolWindow;
private JPanel contentPane;
private JButton buttonRefresh;
private JButton buttonHide;
-
- private JLabel Date22;
- private JLabel Time22;
- private JLabel TimeZone;
+
+ private JLabel cirrentDate;
+ private JLabel currentTime;
+ private JLabel timeZone;
public ToolWindow toolWin;
-
public ToolDialog() {
getRootPane().setDefaultButton(buttonRefresh);
-
-
-
buttonRefresh.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
private void onCancel() {
// Hide tool window.
- toolWin.hide(null);
+ toolWin.hide(null);
dispose();
}
return contentPane;
}
- public void currentDateTime()
- {
- // Get current date and time
- Calendar instance = Calendar.getInstance();
- Date22.setText(String.valueOf(instance.get(Calendar.DAY_OF_MONTH)) + "/"
- + String.valueOf(instance.get(Calendar.MONTH)+1) + "/" + String.valueOf(instance.get(Calendar.YEAR)) );
- Date22.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/samples/Calendar-icon.png")));
- int min = instance.get(Calendar.MINUTE);
- String strMin;
- if ( min < 10) {strMin = "0" + String.valueOf(min);}
- else { strMin = String.valueOf(min);}
- Time22.setText(instance.get(Calendar.HOUR_OF_DAY) + ":" + strMin);
- Time22.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/samples/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/samples/Time-zone-icon.png")));
-
-
-
-
+ 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")));
+
+
}
}