Search in sources :

Example 36 with JDialog

use of javax.swing.JDialog in project jabref by JabRef.

the class GroupAddRemoveDialog method action.

@Override
public void action() throws Exception {
    Optional<GroupTreeNode> groups = panel.getBibDatabaseContext().getMetaData().getGroups();
    if (!groups.isPresent()) {
        return;
    }
    selection = panel.getSelectedEntries();
    final JDialog diag = new JDialog(panel.frame(), (add ? (move ? Localization.lang("Move to group") : Localization.lang("Add to group")) : Localization.lang("Remove from group")), true);
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    tree = new JTree(new GroupTreeNodeViewModel(groups.get()));
    tree.setCellRenderer(new AddRemoveGroupTreeCellRenderer());
    tree.setVisibleRowCount(22);
    //        tree.setPreferredSize(new Dimension(200, tree.getPreferredSize().height));
    //      The scrollbar appears when the preferred size of a component is greater than the size of the viewport. If one hard coded the preferred size, it will never change according to the expansion/collapse. Thus the scrollbar cannot appear accordingly.
    //tree.setSelectionModel(new VetoableTreeSelectionModel());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(e -> {
        GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) e.getNewLeadSelectionPath().getLastPathComponent();
        ok.setEnabled(checkGroupEnable(node));
    });
    //STA add expand and collapse all buttons
    JButton jbExpandAll = new JButton("Expand All");
    jbExpandAll.addActionListener(e -> expandAll(tree, true));
    JButton jbCollapseAll = new JButton("Collapse All");
    jbCollapseAll.addActionListener(e -> expandAll(tree, false));
    //END add expand and collapse all buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addButton(jbExpandAll);
    bb.addButton(jbCollapseAll);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    ok.addActionListener(actionEvent -> {
        if (doAddOrRemove()) {
            diag.dispose();
        }
    });
    cancel.addActionListener(actionEvent -> diag.dispose());
    ok.setEnabled(false);
    JScrollPane sp = new JScrollPane(tree);
    // Key bindings:
    ActionMap am = sp.getActionMap();
    InputMap im = sp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            diag.dispose();
        }
    });
    diag.getContentPane().add(sp, BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();
    diag.setLocationRelativeTo(panel.frame());
    diag.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) JTree(javax.swing.JTree) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 37 with JDialog

use of javax.swing.JDialog in project jabref by JabRef.

the class OpenOfficePanel method showManualConnectionDialog.

private void showManualConnectionDialog() {
    dialogOkPressed = false;
    final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);
    final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
    final DialogService dirDialog = new FXDialogService();
    DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
    DialogService fileDialog = new FXDialogService();
    // Path fields
    final JTextField ooPath = new JTextField(30);
    JButton browseOOPath = new JButton(Localization.lang("Browse"));
    ooPath.setText(preferences.getInstallationPath());
    browseOOPath.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooPath.setText(f.toAbsolutePath().toString())));
    final JTextField ooExec = new JTextField(30);
    JButton browseOOExec = new JButton(Localization.lang("Browse"));
    ooExec.setText(preferences.getExecutablePath());
    browseOOExec.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> fileDialog.showFileOpenDialog(fileDialogConfiguration)).ifPresent(f -> ooExec.setText(f.toAbsolutePath().toString())));
    final JTextField ooJars = new JTextField(30);
    ooJars.setText(preferences.getJarsPath());
    JButton browseOOJars = new JButton(Localization.lang("Browse"));
    browseOOJars.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooJars.setText(f.toAbsolutePath().toString())));
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "pref"));
    if (OS.WINDOWS || OS.OS_X) {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice directory")).xy(1, 1);
        builder.add(ooPath).xy(3, 1);
        builder.add(browseOOPath).xy(5, 1);
    } else {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice executable")).xy(1, 1);
        builder.add(ooExec).xy(3, 1);
        builder.add(browseOOExec).xy(5, 1);
        builder.appendRows("4dlu, pref");
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice library dir")).xy(1, 3);
        builder.add(ooJars).xy(3, 3);
        builder.add(browseOOJars).xy(5, 3);
    }
    builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
    cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    // Buttons
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(e -> {
        if (OS.WINDOWS || OS.OS_X) {
            preferences.updateConnectionParams(ooPath.getText(), ooPath.getText(), ooPath.getText());
        } else {
            preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
        }
        dialogOkPressed = true;
        cDiag.dispose();
    });
    cancel.addActionListener(e -> cDiag.dispose());
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addRelatedGap();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.padding("5dlu, 5dlu, 5dlu, 5dlu");
    cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    // Finish and show dirDialog
    cDiag.pack();
    cDiag.setLocationRelativeTo(frame);
    cDiag.setVisible(true);
}
Also used : JDialog(javax.swing.JDialog) OpenOfficePreferences(org.jabref.logic.openoffice.OpenOfficePreferences) URL(java.net.URL) BibDatabase(org.jabref.model.database.BibDatabase) AbstractWorker(org.jabref.gui.worker.AbstractWorker) IconTheme(org.jabref.gui.IconTheme) NativeDesktop(org.jabref.gui.desktop.os.NativeDesktop) BasePanel(org.jabref.gui.BasePanel) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) URLClassLoader(java.net.URLClassLoader) JabRefFrame(org.jabref.gui.JabRefFrame) SidePaneManager(org.jabref.gui.SidePaneManager) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) Method(java.lang.reflect.Method) Path(java.nio.file.Path) HelpFile(org.jabref.logic.help.HelpFile) PropertyVetoException(com.sun.star.beans.PropertyVetoException) BibEntry(org.jabref.model.entry.BibEntry) IllegalTypeException(com.sun.star.beans.IllegalTypeException) Icon(javax.swing.Icon) FXDialogService(org.jabref.gui.FXDialogService) StyleLoader(org.jabref.logic.openoffice.StyleLoader) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) Dimension(java.awt.Dimension) List(java.util.List) WrappedTargetException(com.sun.star.lang.WrappedTargetException) AbstractAction(javax.swing.AbstractAction) BibtexKeyPatternUtil(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil) FormLayout(com.jgoodies.forms.layout.FormLayout) OS(org.jabref.logic.util.OS) Optional(java.util.Optional) BootstrapException(com.sun.star.comp.helper.BootstrapException) LogFactory(org.apache.commons.logging.LogFactory) UndoableKeyChange(org.jabref.gui.undo.UndoableKeyChange) JPanel(javax.swing.JPanel) KeyBinding(org.jabref.gui.keyboard.KeyBinding) HelpAction(org.jabref.gui.help.HelpAction) NamedCompound(org.jabref.gui.undo.NamedCompound) JTextField(javax.swing.JTextField) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop) DialogService(org.jabref.gui.DialogService) Action(javax.swing.Action) SidePaneComponent(org.jabref.gui.SidePaneComponent) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) OOBibStyle(org.jabref.logic.openoffice.OOBibStyle) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) Localization(org.jabref.logic.l10n.Localization) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileUtil(org.jabref.logic.util.io.FileUtil) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) NoSuchElementException(com.sun.star.container.NoSuchElementException) ButtonGroup(javax.swing.ButtonGroup) JPopupMenu(javax.swing.JPopupMenu) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) NotRemoveableException(com.sun.star.beans.NotRemoveableException) ActionEvent(java.awt.event.ActionEvent) Globals(org.jabref.Globals) Paths(java.nio.file.Paths) PropertyExistException(com.sun.star.beans.PropertyExistException) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) Log(org.apache.commons.logging.Log) Defaults(org.jabref.model.Defaults) BibtexKeyPatternPreferences(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FXDialogService(org.jabref.gui.FXDialogService) DialogService(org.jabref.gui.DialogService) NativeDesktop(org.jabref.gui.desktop.os.NativeDesktop) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) FXDialogService(org.jabref.gui.FXDialogService) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) JDialog(javax.swing.JDialog)

Example 38 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class LEConnectivityTest method testShowAndClose.

@SuppressWarnings("unchecked")
public void testShowAndClose() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // Can't Assume in TestCase
        return;
    }
    jmri.configurexml.ConfigXmlManager cm = new jmri.configurexml.ConfigXmlManager() {
    };
    // load and display test panel file
    java.io.File f = new java.io.File("java/test/jmri/jmrit/display/layoutEditor/valid/LEConnectTest.xml");
    cm.load(f);
    // time for internal listeners to calm down
    sleep(100);
    // Find new window by name (should be more distinctive, comes from sample file)
    LayoutEditor le = (LayoutEditor) jmri.util.JmriJFrame.getFrame("Connectivity Test");
    Assert.assertNotNull(le);
    // Panel is up, continue set up for tests.
    ConnectivityUtil cu = new ConnectivityUtil(le);
    Assert.assertNotNull(cu);
    BlockManager bm = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
    Assert.assertNotNull(bm);
    // Test right-handed crossover connectivity turnout settings
    Block cBlock = bm.getBlock("4");
    Block pBlock = bm.getBlock("6");
    Block nBlock = bm.getBlock("5");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    ArrayList<Integer> tsList = cu.getTurnoutSettingList();
    int setting = tsList.get(0).intValue();
    Assert.assertEquals("6_4_5Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("5");
    nBlock = bm.getBlock("6");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("5_4_6Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("5");
    nBlock = bm.getBlock("2");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("5_4_2Connect", setting, Turnout.THROWN);
    cBlock = bm.getBlock("2");
    pBlock = bm.getBlock("1");
    nBlock = bm.getBlock("3");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("1_2_3Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("3");
    nBlock = bm.getBlock("1");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("3_2_1Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("1");
    nBlock = bm.getBlock("4");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("1_2_4Connect", setting, Turnout.THROWN);
    // Test left-handed crossover connectivity turnout settings
    cBlock = bm.getBlock("14");
    pBlock = bm.getBlock("13");
    nBlock = bm.getBlock("17");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("13_14_17Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("17");
    nBlock = bm.getBlock("13");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("17_14_13Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("17");
    nBlock = bm.getBlock("12");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("17_14_12Connect", setting, Turnout.THROWN);
    cBlock = bm.getBlock("12");
    pBlock = bm.getBlock("11");
    nBlock = bm.getBlock("15");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("11_12_15Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("15");
    nBlock = bm.getBlock("11");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("15_12_11Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("15");
    nBlock = bm.getBlock("14");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("15_12_14Connect", setting, Turnout.THROWN);
    // Test double crossover connectivity turnout settings
    cBlock = bm.getBlock("21");
    pBlock = bm.getBlock("20");
    nBlock = bm.getBlock("22");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("20_21_22Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("22");
    nBlock = bm.getBlock("20");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("22_21_20Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("20");
    nBlock = bm.getBlock("26");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("20_21_26Connect", setting, Turnout.THROWN);
    cBlock = bm.getBlock("22");
    pBlock = bm.getBlock("23");
    nBlock = bm.getBlock("21");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("23_22_21Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("21");
    nBlock = bm.getBlock("23");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("21_22_23Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("23");
    nBlock = bm.getBlock("25");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("23_22_25Connect", setting, Turnout.THROWN);
    cBlock = bm.getBlock("26");
    pBlock = bm.getBlock("27");
    nBlock = bm.getBlock("25");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("27_26_25Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("25");
    nBlock = bm.getBlock("27");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("25_26_27Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("27");
    nBlock = bm.getBlock("21");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("27_26_21Connect", setting, Turnout.THROWN);
    cBlock = bm.getBlock("25");
    pBlock = bm.getBlock("24");
    nBlock = bm.getBlock("26");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("24_25_26Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("26");
    nBlock = bm.getBlock("24");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("26_25_24Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("24");
    nBlock = bm.getBlock("22");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("24_25_22Connect", setting, Turnout.THROWN);
    // Test right handed turnout (with "wings" in same block) connectivity turnout settings
    cBlock = bm.getBlock("62");
    pBlock = bm.getBlock("64");
    nBlock = bm.getBlock("61");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("64_62_61Connect", setting, Turnout.THROWN);
    pBlock = bm.getBlock("61");
    nBlock = bm.getBlock("64");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("61_62_64Connect", setting, Turnout.THROWN);
    pBlock = bm.getBlock("63");
    nBlock = bm.getBlock("61");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("63_62_61Connect", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("61");
    nBlock = bm.getBlock("63");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("61_62_63Connect", setting, Turnout.CLOSED);
    // Test extended track following connectivity turnout settings
    //   Each path must go through two turnouts, whose settings are tested in order
    cBlock = bm.getBlock("32");
    pBlock = bm.getBlock("31");
    nBlock = bm.getBlock("33");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("31_32_33ConnectA", setting, Turnout.CLOSED);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("31_32_33ConnectB", setting, Turnout.THROWN);
    pBlock = bm.getBlock("33");
    nBlock = bm.getBlock("31");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("33_32_31ConnectA", setting, Turnout.THROWN);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("33_32_31ConnectB", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("31");
    nBlock = bm.getBlock("34");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("31_32_34ConnectA", setting, Turnout.CLOSED);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("31_32_34ConnectB", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("34");
    nBlock = bm.getBlock("31");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("34_32_31ConnectA", setting, Turnout.CLOSED);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("34_32_31ConnectB", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("31");
    nBlock = bm.getBlock("35");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("31_32_35ConnectA", setting, Turnout.THROWN);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("31_32_35ConnectB", setting, Turnout.CLOSED);
    pBlock = bm.getBlock("35");
    nBlock = bm.getBlock("31");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("35_32_31ConnectA", setting, Turnout.CLOSED);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("35_32_31ConnectB", setting, Turnout.THROWN);
    pBlock = bm.getBlock("31");
    nBlock = bm.getBlock("36");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("31_32_36ConnectA", setting, Turnout.THROWN);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("31_32_36ConnectB", setting, Turnout.THROWN);
    pBlock = bm.getBlock("36");
    nBlock = bm.getBlock("31");
    cu.getTurnoutList(cBlock, pBlock, nBlock);
    tsList = cu.getTurnoutSettingList();
    setting = tsList.get(0).intValue();
    Assert.assertEquals("36_32_31ConnectA", setting, Turnout.THROWN);
    setting = tsList.get(1).intValue();
    Assert.assertEquals("36_32_31ConnectB", setting, Turnout.THROWN);
    // Ask to close window
    TestHelper.disposeWindow(le, this);
    // Dialog has popped up, so handle that. First, locate it.
    List<JDialog> dialogList = new DialogFinder(null).findAll(le);
    JDialog d = dialogList.get(0);
    // Find the button that deletes the panel
    AbstractButtonFinder finder = new AbstractButtonFinder("Delete Panel");
    JButton button = (JButton) finder.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // another dialog has popped up, so handle that by finding the "Yes - Delete" button.
    dialogList = new DialogFinder(null).findAll(le);
    d = dialogList.get(0);
    finder = new AbstractButtonFinder("Yes - Delete");
    button = (JButton) finder.find(d, 0);
    Assert.assertNotNull(button);
    // Click to say yes, I really mean it.
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    le.dispose();
}
Also used : JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) BlockManager(jmri.BlockManager) Block(jmri.Block) JDialog(javax.swing.JDialog)

Example 39 with JDialog

use of javax.swing.JDialog in project jabref by JabRef.

the class ExternalFileTypeEntryEditor method init.

private void init(ExternalFileType inEntry) {
    entry = inEntry;
    icon.setText(null);
    ButtonGroup bg = new ButtonGroup();
    bg.add(useDefault);
    bg.add(other);
    FormBuilder builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"));
    builder.add(Localization.lang("Icon")).xy(1, 1);
    builder.add(icon).xy(3, 1);
    builder.add(Localization.lang("Name")).xy(1, 3);
    builder.add(name).xy(3, 3);
    builder.add(Localization.lang("Extension")).xy(1, 5);
    builder.add(extension).xy(3, 5);
    builder.add(Localization.lang("MIME type")).xy(1, 7);
    builder.add(mimeType).xy(3, 7);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.add(Localization.lang("Application")).xy(1, 9);
    JButton browseBut = new JButton(Localization.lang("Browse"));
    if (OS.WINDOWS) {
        builder.add(useDefault).xy(3, 9);
        builder.appendRows("2dlu, p");
        JPanel p1 = new JPanel();
        builder.add(p1).xy(1, 11);
        JPanel p2 = new JPanel();
        application.setPreferredSize(new Dimension(300, application.getPreferredSize().height));
        BorderLayout bl = new BorderLayout();
        bl.setHgap(4);
        p2.setLayout(bl);
        p2.add(other, BorderLayout.WEST);
        p2.add(application, BorderLayout.CENTER);
        builder.add(p2).xy(3, 11);
        builder.add(browseBut).xy(5, 11);
    } else {
        builder.add(application).xy(3, 9);
        builder.add(browseBut).xy(5, 9);
    }
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    ok.addActionListener(e -> {
        okPressed = true;
        storeSettings(ExternalFileTypeEntryEditor.this.entry);
        diag.dispose();
    });
    cancel.addActionListener(e -> diag.dispose());
    if (OS.WINDOWS) {
        application.getDocument().addDocumentListener(new DocumentListener() {

            private void handle() {
                if (application.getText().isEmpty()) {
                    useDefault.setSelected(true);
                } else {
                    other.setSelected(true);
                }
            }

            @Override
            public void insertUpdate(DocumentEvent documentEvent) {
                handle();
            }

            @Override
            public void removeUpdate(DocumentEvent documentEvent) {
                handle();
            }

            @Override
            public void changedUpdate(DocumentEvent documentEvent) {
                handle();
            }
        });
    }
    String title = editFileTitle;
    if (entry.getName().isEmpty()) {
        title = newFileTitle;
    }
    if (dParent == null) {
        diag = new JDialog(fParent, title, true);
    } else {
        diag = new JDialog(dParent, title, true);
    }
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();
    browseBut.addActionListener(browsePressed);
    if (dParent == null) {
        diag.setLocationRelativeTo(fParent);
    } else {
        diag.setLocationRelativeTo(dParent);
    }
    setValues(entry);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) BorderLayout(java.awt.BorderLayout) ButtonGroup(javax.swing.ButtonGroup) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JDialog(javax.swing.JDialog)

Example 40 with JDialog

use of javax.swing.JDialog in project jabref by JabRef.

the class DetectOpenOfficeInstallation method showProgressDialog.

public JDialog showProgressDialog(JDialog progressParent, String title, String message) {
    JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL);
    final JDialog progressDialog = new JDialog(progressParent, title, false);
    bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    bar.setIndeterminate(true);
    progressDialog.add(new JLabel(message), BorderLayout.NORTH);
    progressDialog.add(bar, BorderLayout.CENTER);
    progressDialog.pack();
    progressDialog.setLocationRelativeTo(null);
    progressDialog.setVisible(true);
    return progressDialog;
}
Also used : JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) JDialog(javax.swing.JDialog)

Aggregations

JDialog (javax.swing.JDialog)181 JButton (javax.swing.JButton)70 JPanel (javax.swing.JPanel)61 ActionEvent (java.awt.event.ActionEvent)51 ActionListener (java.awt.event.ActionListener)39 JLabel (javax.swing.JLabel)39 JOptionPane (javax.swing.JOptionPane)34 BorderLayout (java.awt.BorderLayout)30 Dimension (java.awt.Dimension)27 JScrollPane (javax.swing.JScrollPane)27 JFrame (javax.swing.JFrame)23 BoxLayout (javax.swing.BoxLayout)21 FlowLayout (java.awt.FlowLayout)19 JCheckBox (javax.swing.JCheckBox)15 AbstractAction (javax.swing.AbstractAction)14 WindowEvent (java.awt.event.WindowEvent)13 JComponent (javax.swing.JComponent)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 WindowAdapter (java.awt.event.WindowAdapter)11 IOException (java.io.IOException)10