use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class CertificateManager method showAcceptDialog.
public static boolean showAcceptDialog(@NotNull final Callable<? extends DialogWrapper> dialogFactory) {
Application app = ApplicationManager.getApplication();
final CountDownLatch proceeded = new CountDownLatch(1);
final AtomicBoolean accepted = new AtomicBoolean();
final AtomicReference<DialogWrapper> dialogRef = new AtomicReference<>();
Runnable showDialog = () -> {
// skip if certificate was already rejected due to timeout or interrupt
if (proceeded.getCount() == 0) {
return;
}
try {
DialogWrapper dialog = dialogFactory.call();
dialogRef.set(dialog);
accepted.set(dialog.showAndGet());
} catch (Exception e) {
LOG.error(e);
} finally {
proceeded.countDown();
}
};
if (app.isDispatchThread()) {
showDialog.run();
} else {
app.invokeLater(showDialog, ModalityState.any());
}
try {
// IDEA-123467 and IDEA-123335 workaround
boolean inTime = proceeded.await(DIALOG_VISIBILITY_TIMEOUT, TimeUnit.MILLISECONDS);
if (!inTime) {
DialogWrapper dialog = dialogRef.get();
if (dialog == null || !dialog.isShowing()) {
LOG.debug("After " + DIALOG_VISIBILITY_TIMEOUT + " ms dialog was not shown. " + "Rejecting certificate. Current thread: " + Thread.currentThread().getName());
proceeded.countDown();
return false;
} else {
// if dialog is already shown continue waiting
proceeded.await();
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
proceeded.countDown();
}
return accepted.get();
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class CreatePatchFromChangesAction method createPatch.
public static void createPatch(Project project, String commitMessage, List<Change> changeCollection) {
project = project == null ? ProjectManager.getInstance().getDefaultProject() : project;
final CreatePatchCommitExecutor executor = CreatePatchCommitExecutor.getInstance(project);
CommitSession commitSession = executor.createCommitSession();
if (commitSession instanceof CommitSessionContextAware) {
((CommitSessionContextAware) commitSession).setContext(new CommitContext());
}
DialogWrapper sessionDialog = new SessionDialog(executor.getActionText(), project, commitSession, changeCollection, commitMessage);
if (!sessionDialog.showAndGet()) {
return;
}
preloadContent(project, changeCollection);
commitSession.execute(changeCollection, commitMessage);
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class PluginHeaderPanel method createUIComponents.
private void createUIComponents() {
myInstallButton = new JButton() {
private final int TOP_BOTTOM_BORDER = JBUI.scale(2);
private final int LEFT_RIGHT_BORDER = JBUI.scale(8);
private final int H_GAP = JBUI.scale(4);
private final int ICON_SIZE = getIcon().getIconWidth();
{
setOpaque(false);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
@Override
public Dimension getPreferredSize() {
final FontMetrics metrics = getFontMetrics(getFont());
final int textWidth = metrics.stringWidth(getText());
final int width = LEFT_RIGHT_BORDER + ICON_SIZE + H_GAP + textWidth + LEFT_RIGHT_BORDER;
final int height = TOP_BOTTOM_BORDER + Math.max(ICON_SIZE, metrics.getHeight()) + TOP_BOTTOM_BORDER;
return new Dimension(width, height);
}
@Override
public void paint(Graphics g2) {
final Graphics2D g = (Graphics2D) g2;
final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
final int w = g.getClipBounds().width;
final int h = g.getClipBounds().height;
int borderArc = JBUI.scale(7);
int border = JBUI.scale(1);
int buttonArc = borderArc - border;
g.setPaint(getBackgroundBorderPaint());
g.fillRoundRect(0, 0, w, h, borderArc, borderArc);
g.setPaint(getBackgroundPaint());
g.fillRoundRect(border, border, w - 2 * border, h - 2 * border, buttonArc, buttonArc);
g.setColor(getButtonForeground());
g.drawString(getText(), LEFT_RIGHT_BORDER + ICON_SIZE + H_GAP, getBaseline(w, h));
getIcon().paintIcon(this, g, LEFT_RIGHT_BORDER, (getHeight() - getIcon().getIconHeight()) / 2);
config.restore();
}
private Color getButtonForeground() {
switch(myActionId) {
case UPDATE:
return new JBColor(Gray._240, Gray._210);
case INSTALL:
return new JBColor(Gray._240, Gray._210);
case RESTART:
case UNINSTALL:
return new JBColor(Gray._0, Gray._210);
}
return new JBColor(Gray._80, Gray._60);
}
private Paint getBackgroundPaint() {
switch(myActionId) {
case UPDATE:
return new JBGradientPaint(this, new JBColor(0x629ee1, 0x629ee1), new JBColor(0x3a5bb5, 0x3a5bb5));
case INSTALL:
return new JBGradientPaint(this, new JBColor(0x60cc69, 0x519557), new JBColor(0x326529, 0x28462f));
case RESTART:
case UNINSTALL:
return UIUtil.isUnderDarcula() ? new JBGradientPaint(this, UIManager.getColor("Button.darcula.color1"), UIManager.getColor("Button.darcula.color2")) : Gray._240;
}
return Gray._238;
}
private Paint getBackgroundBorderPaint() {
switch(myActionId) {
case UPDATE:
return new JBColor(new Color(0xa6b4cd), Gray._85);
case INSTALL:
return new JBColor(new Color(201, 223, 201), Gray._70);
case RESTART:
case UNINSTALL:
return new JBColor(Gray._220, Gray._100.withAlpha(180));
}
return Gray._208;
}
@Override
public String getText() {
switch(myActionId) {
case UPDATE:
return "Update";
case INSTALL:
return "Install";
case UNINSTALL:
return "Uninstall";
case RESTART:
return "Restart " + ApplicationNamesInfo.getInstance().getFullProductName();
}
return super.getText();
}
@Override
public Icon getIcon() {
switch(myActionId) {
case UPDATE:
return AllIcons.General.DownloadPlugin;
case INSTALL:
return AllIcons.General.DownloadPlugin;
case UNINSTALL:
return AllIcons.Actions.Delete;
case RESTART:
return AllIcons.Actions.Restart;
}
return super.getIcon();
}
};
myInstallButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
switch(myActionId) {
case UPDATE:
case INSTALL:
Runnable setPlugin = () -> setPlugin(myPlugin);
new InstallPluginAction(myManager.getAvailable(), myManager.getInstalled()).install(setPlugin, setPlugin, true);
break;
case UNINSTALL:
UninstallPluginAction.uninstall(myManager.getInstalled(), true, myPlugin);
break;
case RESTART:
if (myManager != null) {
myManager.apply();
}
final DialogWrapper dialog = DialogWrapper.findInstance(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
if (dialog != null && dialog.isModal()) {
dialog.close(DialogWrapper.OK_EXIT_CODE);
}
TransactionGuard.getInstance().submitTransactionLater(ApplicationManager.getApplication(), () -> {
DialogWrapper settings = DialogWrapper.findInstance(IdeFocusManager.findInstance().getFocusOwner());
if (settings instanceof SettingsDialog) {
((SettingsDialog) settings).doOKAction();
}
ApplicationManager.getApplication().restart();
});
break;
}
setPlugin(myPlugin);
}
});
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class AppUIUtil method showPrivacyPolicyAgreement.
/**
* @param htmlText Updated version of Privacy Policy text if any.
* If it's {@code null}, the standard text from bundled resources would be used.
*/
public static void showPrivacyPolicyAgreement(@NotNull String htmlText) {
DialogWrapper dialog = new DialogWrapper(true) {
@Nullable
@Override
protected JComponent createCenterPanel() {
JPanel centerPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
viewer.setFocusable(true);
viewer.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
URL url = e.getURL();
if (url != null) {
BrowserUtil.browse(url);
} else {
SwingHelper.scrollToReference(viewer, e.getDescription());
}
}
});
viewer.setText(htmlText);
StyleSheet styleSheet = ((HTMLDocument) viewer.getDocument()).getStyleSheet();
styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
styleSheet.addRule("body {margin-top:0;padding-top:0;}");
styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
styleSheet.addRule("p, h1 {margin-top:0;padding-top:" + JBUI.scaleFontSize(6) + "pt;}");
styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
styleSheet.addRule("h2 {margin-top:0;padding-top:" + JBUI.scaleFontSize(13) + "pt;}");
viewer.setCaretPosition(0);
viewer.setBorder(JBUI.Borders.empty(0, 5, 5, 5));
centerPanel.add(new JLabel("Please read and accept these terms and conditions:"), BorderLayout.NORTH);
centerPanel.add(new JBScrollPane(viewer, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
return centerPanel;
}
@Override
protected void createDefaultActions() {
super.createDefaultActions();
init();
setOKButtonText("Accept");
setCancelButtonText("Reject and Exit");
setAutoAdjustable(false);
}
@Override
public void doCancelAction() {
super.doCancelAction();
ApplicationEx application = ApplicationManagerEx.getApplicationEx();
if (application == null) {
System.exit(Main.PRIVACY_POLICY_REJECTION);
} else {
((ApplicationImpl) application).exit(true, true, false);
}
}
};
dialog.setModal(true);
dialog.setTitle(ApplicationNamesInfo.getInstance().getFullProductName() + " Privacy Policy Agreement");
dialog.setSize(JBUI.scale(509), JBUI.scale(395));
dialog.show();
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class ChangeProjectIconAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
List<AnAction> elements = getSelectedElements(e);
String path = ((ReopenProjectAction) elements.get(0)).getProjectPath();
final ChangeProjectIconForm form = new ChangeProjectIconForm(path);
DialogWrapper dialog = new DialogWrapper(null) {
{
init();
}
@Nullable
@Override
protected JComponent createCenterPanel() {
return form.myRootPanel;
}
};
dialog.show();
if (dialog.isOK()) {
try {
form.apply();
} catch (IOException e1) {
System.out.println(e1);
}
}
}
Aggregations