forked from westlinkin/AndroidLocalizationer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleAlertDialog.java
More file actions
134 lines (119 loc) · 4.97 KB
/
Copy pathGoogleAlertDialog.java
File metadata and controls
134 lines (119 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright 2014-2015 Wesley Lin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ui;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.mac.foundation.MacUtil;
import com.intellij.util.ui.UIUtil;
import data.StorageDataKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created by Wesley Lin on 12/27/14.
*/
public class GoogleAlertDialog extends DialogWrapper {
private String mMessage;
public GoogleAlertDialog(@Nullable Component parent,
boolean canBeParent) {
super(parent, canBeParent);
_init("Information", "Google Translate API is a paid service. The pricing is based on usage. Translation usage is calculated in millions of characters (M), where 1 M = 106 characters");
}
protected void _init(String title, String message) {
setTitle(title);
mMessage = message;
if (Messages.isMacSheetEmulation()) {
setUndecorated(true);
}
setButtonsAlignment(SwingConstants.RIGHT);
setDoNotAskOption(null);
init();
if (Messages.isMacSheetEmulation()) {
MacUtil.adjustFocusTraversal(myDisposable);
}
}
private Action detailAction = new AbstractAction(UIUtil.replaceMnemonicAmpersand("Pricing details")) {
@Override
public void actionPerformed(ActionEvent e) {
try {
Desktop.getDesktop().browse(new URI("https://cloud.google.com/translate/v2/pricing"));
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
close(5, true);
}
};
private Action neverShowAction = new AbstractAction(UIUtil.replaceMnemonicAmpersand("Never show this again")) {
@Override
public void actionPerformed(ActionEvent e) {
PropertiesComponent.getInstance().setValue(StorageDataKey.GoogleAlertMsgShownSetting, String.valueOf(true));
close(6, true);
}
};
@NotNull
@Override
protected Action[] createActions() {
Action[] actions;
if (SystemInfo.isMac) {
actions = new Action[]{myCancelAction, neverShowAction, detailAction, myOKAction};
} else {
actions = new Action[]{myOKAction, detailAction, neverShowAction, myCancelAction};
}
return actions;
}
@Nullable
@Override
protected JComponent createCenterPanel() {
JPanel panel = new JPanel(new BorderLayout(15, 0));
// icon
JLabel iconLabel = new JLabel(Messages.getInformationIcon());
Container container = new Container();
container.setLayout(new BorderLayout());
container.add(iconLabel, BorderLayout.NORTH);
panel.add(container, BorderLayout.WEST);
if (mMessage != null) {
final JTextPane messageComponent = MultiSelectDialog.createMessageComponent(mMessage);
final Dimension screenSize = messageComponent.getToolkit().getScreenSize();
final Dimension textSize = messageComponent.getPreferredSize();
if (mMessage.length() > 100) {
final JScrollPane pane = ScrollPaneFactory.createScrollPane(messageComponent);
pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
final int scrollSize = (int)new JScrollBar(Adjustable.VERTICAL).getPreferredSize().getWidth();
final Dimension preferredSize =
new Dimension(Math.min(textSize.width, screenSize.width / 2) + scrollSize,
Math.min(textSize.height, screenSize.height / 3) + scrollSize);
pane.setPreferredSize(preferredSize);
panel.add(pane, BorderLayout.CENTER);
}
else {
panel.add(messageComponent, BorderLayout.CENTER);
}
}
return panel;
}
}