use of java.awt.event.HierarchyEvent in project freeplane by freeplane.
the class SurveyRunner method runServey.
public void runServey(String id, String title, String question, String surveyUrl) {
if (!freeplaneSurveyProperties.mayAskUserToFillSurvey(surveyId))
return;
this.surveyId = id;
freeplaneSurveyProperties.setNextSurveyDay(MINIMAL_DAYS_BETWEEN_SURVEYS);
final JButton go = new JButton("With pleasure");
go.setToolTipText("Thank you so much!");
final JButton notInterested = new JButton("Not interested");
notInterested.setToolTipText("We shall not repeat this question, but may be ask you another one.");
final JButton remindMeLater = new JButton("Remind me later");
remindMeLater.setToolTipText("The same question can be repeated some days later.");
final JButton never = new JButton("Don't ask me anything again");
never.setToolTipText("We are sorry! We shall never ask you any question like this again.");
final JButton[] options = new JButton[] { go, notInterested, remindMeLater, never };
final OptionButtonListener optionButtonListener = new OptionButtonListener();
for (JButton button : options) button.addActionListener(optionButtonListener);
final List<Image> iconImages = UITools.getFrame().getIconImages();
final JEditorPane messageComponent = new JEditorPane("text/html", question);
messageComponent.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
messageComponent.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
final URL url = e.getURL();
openSurvey(url);
} catch (Exception ex) {
}
userVisitedVotingLink = true;
SwingUtilities.getWindowAncestor(messageComponent).setVisible(false);
}
}
});
messageComponent.setEditable(false);
messageComponent.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if (messageComponent.isShowing()) {
messageComponent.removeHierarchyListener(this);
final Window window = SwingUtilities.getWindowAncestor(messageComponent);
if (window instanceof JDialog)
((JDialog) window).setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
window.setIconImages(iconImages);
}
}
});
final int userDecision = JOptionPane.showOptionDialog(UITools.getCurrentFrame(), messageComponent, title, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, remindMeLater);
switch(userDecision) {
case JOptionPane.CLOSED_OPTION:
if (userVisitedVotingLink)
freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
break;
default:
switch(Options.values()[userDecision]) {
case GO_OPTION:
try {
freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
final URL survey = new URL(surveyUrl);
openSurvey(survey);
} catch (Exception e) {
}
break;
case NOT_INTERESTED_OPTION:
freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
break;
case REMIND_ME_LATER_OPTION:
freeplaneSurveyProperties.setNextSurveyDay(MINIMAL_DAYS_BETWEEN_SURVEY_REMINDERS);
freeplaneSurveyProperties.activateRemindMeLater();
break;
case NEVER_OPTION:
freeplaneSurveyProperties.setNeverShowSurvey();
break;
}
}
}
use of java.awt.event.HierarchyEvent in project CIM-Identities by epri-dev.
the class Splash method jButton1ActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
this.dispose();
String URL = "jdbc:postgresql://localhost:5432/CIMIdentity";
String LoginID = "postgres";
JPasswordField pwd = new JPasswordField(10);
pwd.addHierarchyListener(new HierarchyListener() {
public void hierarchyChanged(HierarchyEvent e) {
final Component c = e.getComponent();
if (c.isShowing() && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
Window toplevel = SwingUtilities.getWindowAncestor(c);
toplevel.addWindowFocusListener(new WindowAdapter() {
public void windowGainedFocus(WindowEvent e) {
c.requestFocus();
}
});
}
}
});
int action = JOptionPane.showConfirmDialog(null, pwd, "Enter Password", JOptionPane.OK_CANCEL_OPTION);
if (action < 0)
JOptionPane.showMessageDialog(null, "Cancel, X or escape key selected");
String passw = new String(pwd.getPassword());
Connection c = null;
Statement stmt = null;
Connection cc = null;
try {
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/", LoginID, passw);
/* Now that we are connected to PostgreSQL, let's create
the database */
stmt = c.createStatement();
String sql = "CREATE DATABASE \"CIMIdentity\";";
stmt.executeUpdate(sql);
stmt.close();
c.close();
System.out.println("Opened database successfully");
stmt = null;
cc = DriverManager.getConnection(URL, LoginID, passw);
stmt = cc.createStatement();
String usql = "CREATE EXTENSION pgcrypto; " + "CREATE TABLE public.\"Identity\" " + "(id_pkey uuid NOT NULL DEFAULT gen_random_uuid(), " + " entry serial NOT NULL, " + "CONSTRAINT id_pkey PRIMARY KEY (id_pkey) )" + " WITH ( OIDS = FALSE); " + " ALTER TABLE public.\"Identity\"" + " OWNER to postgres;" + "CREATE TABLE public.\"IdentifiedObject\"" + "( io_pkey uuid NOT NULL, " + "CONSTRAINT io_pkey PRIMARY KEY (io_pkey), " + "CONSTRAINT io_idkey FOREIGN KEY (io_pkey) " + "REFERENCES public.\"Identity\" (id_pkey) MATCH SIMPLE " + "ON UPDATE CASCADE ON DELETE CASCADE )" + "WITH ( OIDS = FALSE);" + "ALTER TABLE public.\"IdentifiedObject\"" + "OWNER TO postgres;" + "CREATE TABLE public.\"Name\"" + "( n_pkey uuid NOT NULL, " + "n_name character varying NOT NULL, " + "CONSTRAINT n_pkey PRIMARY KEY (n_pkey), " + "CONSTRAINT n_idkey FOREIGN KEY (n_pkey)" + " REFERENCES public.\"Identity\" (id_pkey) MATCH SIMPLE" + " ON UPDATE CASCADE ON DELETE CASCADE" + ") WITH ( OIDS = FALSE );" + " ALTER TABLE public.\"Name\" OWNER TO postgres;" + " CREATE TABLE public.\"NameType\" " + " ( nt_pkey uuid NOT NULL, " + " nt_description character varying NOT NULL, " + " nt_name character varying NOT NULL, " + " CONSTRAINT nt_pkey PRIMARY KEY (nt_pkey), " + " CONSTRAINT nt_nkey FOREIGN KEY (nt_pkey) " + " REFERENCES public.\"Name\" (n_pkey) MATCH SIMPLE " + " ON UPDATE CASCADE ON DELETE CASCADE ) " + " WITH ( OIDS = FALSE ); " + " ALTER TABLE public.\"NameType\" OWNER TO postgres; " + " CREATE TABLE public.\"NameTypeAuthority\"" + " ( nta_pkey uuid NOT NULL, " + " nta_name character varying, " + " nta_description character varying NOT NULL, " + " CONSTRAINT nta_pkey PRIMARY KEY (nta_pkey), " + " CONSTRAINT nta_ntkey FOREIGN KEY (nta_pkey) " + " REFERENCES public.\"NameType\" (nt_pkey) MATCH SIMPLE " + " ON UPDATE CASCADE ON DELETE CASCADE )" + " WITH ( OIDS = FALSE ); " + " ALTER TABLE public.\"NameTypeAuthority\" " + " OWNER TO postgres;";
stmt.executeUpdate(usql);
stmt.close();
c.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
JOptionPane.showMessageDialog(null, "Table created successfully!");
}
use of java.awt.event.HierarchyEvent in project omegat by omegat-org.
the class SecureStoreController method initGui.
private void initGui() {
panel = new SecureStorePanel();
panel.resetPasswordButton.addActionListener(e -> resetMasterPassword());
panel.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
updateMasterPasswordStatus();
}
}
});
}
use of java.awt.event.HierarchyEvent in project netbeans-mmd-plugin by raydac.
the class UiUtils method makeOwningDialogResizable.
public static void makeOwningDialogResizable(@Nonnull final Component component, @Nonnull @MustNotContainNull final Runnable... extraActions) {
final HierarchyListener listener = new HierarchyListener() {
@Override
public void hierarchyChanged(@Nonnull final HierarchyEvent e) {
final Window window = SwingUtilities.getWindowAncestor(component);
if (window instanceof Dialog) {
final Dialog dialog = (Dialog) window;
if (!dialog.isResizable()) {
dialog.setResizable(true);
component.removeHierarchyListener(this);
for (final Runnable r : extraActions) {
r.run();
}
}
}
}
};
component.addHierarchyListener(listener);
}
use of java.awt.event.HierarchyEvent in project mylizzie by aerisnju.
the class Lizzie method setFileChooserAutoFocusOnTextField.
private static void setFileChooserAutoFocusOnTextField(JFileChooser chooser) {
chooser.addHierarchyListener(new HierarchyListener() {
public void hierarchyChanged(HierarchyEvent he) {
grabFocusForTextField(chooser.getComponents());
}
// Loop to find the JTextField, the first
// JTextField in JFileChooser
// Even if you setAccessory which contains a JTextField
// or which is JTextField itself, it will not get focus
private void grabFocusForTextField(Component[] components) {
for (Component component : components) {
if (component instanceof JTextField) {
JTextField textField = (JTextField) component;
textField.grabFocus();
break;
} else if (component instanceof JPanel) {
JPanel panel = (JPanel) component;
grabFocusForTextField(panel.getComponents());
}
}
}
});
}
Aggregations