List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:io.github.jeremgamer.editor.panels.Buttons.java
public Buttons(final JFrame frame, final ButtonPanel be, final PanelSave ps) { this.setBorder(BorderFactory.createTitledBorder("")); this.frame = frame; JButton add = null;/*from w w w .ja v a2 s .c o m*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog(null, "Nommez le bouton :", "Crer un bouton", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new ButtonSave(name); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (buttonList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/buttons/" + buttonList.getSelectedValue() + "/" + buttonList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer ce bouton?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } for (String section : ps .getSectionsContaining(buttonList.getSelectedValue() + " (Bouton)")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (buttonList.getSelectedValue().equals(be.getFileName())) { be.setFileName(""); } be.hide(); file.delete(); File parent = new File(file.getParent()); for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { img.delete(); } parent.delete(); data.remove(buttonList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); buttonList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); be.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { be.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { be.hideThenShow(); previousSelection = list.getSelectedValue(); be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { be.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); be.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { be.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { be.hideThenShow(); previousSelection = list.getSelectedValue(); be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { be.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(buttonList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); }
From source file:sim.util.media.chart.SeriesAttributes.java
void buildManipulators() { JButton removeButton = new JButton(I_CLOSE); removeButton.setPressedIcon(I_CLOSE_PRESSED); removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4)); removeButton.setBorderPainted(false); removeButton.setContentAreaFilled(false); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Remove", "Cancel" }, null) == 0) // remove getGenerator().removeSeries(getSeriesIndex()); }//from w w w .j a v a2 s .c o m }); removeButton.setToolTipText("Remove this series"); JButton upButton = new JButton(I_UP); upButton.setPressedIcon(I_UP_PRESSED); upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4)); upButton.setBorderPainted(false); upButton.setContentAreaFilled(false); upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getGenerator().moveSeries(getSeriesIndex(), true); } }); upButton.setToolTipText("Draw this series higher in the series order"); JButton downButton = new JButton(I_DOWN); downButton.setPressedIcon(I_DOWN_PRESSED); downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4)); downButton.setBorderPainted(false); downButton.setContentAreaFilled(false); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getGenerator().moveSeries(getSeriesIndex(), false); } }); downButton.setToolTipText("Draw this series lower in the series order"); manipulators.add(removeButton); manipulators.add(upButton); manipulators.add(downButton); }
From source file:edu.gmu.cs.sim.util.media.chart.SeriesAttributes.java
void buildManipulators() { JButton removeButton = new JButton(I_CLOSE); removeButton.setPressedIcon(I_CLOSE_PRESSED); removeButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4)); removeButton.setBorderPainted(false); removeButton.setContentAreaFilled(false); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (JOptionPane.showOptionDialog(null, "Remove the Series " + getSeriesName() + "?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Remove", "Cancel" }, null) == 0) // remove {/*from www. j a v a 2 s.c o m*/ getGenerator().removeSeries(getSeriesIndex()); } } }); removeButton.setToolTipText("Remove this series"); JButton upButton = new JButton(I_UP); upButton.setPressedIcon(I_UP_PRESSED); upButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4)); upButton.setBorderPainted(false); upButton.setContentAreaFilled(false); upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getGenerator().moveSeries(getSeriesIndex(), true); } }); upButton.setToolTipText("Draw this series higher in the series order"); JButton downButton = new JButton(I_DOWN); downButton.setPressedIcon(I_DOWN_PRESSED); downButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));//4,4,4,4)); downButton.setBorderPainted(false); downButton.setContentAreaFilled(false); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getGenerator().moveSeries(getSeriesIndex(), false); } }); downButton.setToolTipText("Draw this series lower in the series order"); manipulators.add(removeButton); manipulators.add(upButton); manipulators.add(downButton); }
From source file:io.github.jeremgamer.editor.panels.Labels.java
public Labels(final JFrame frame, final LabelPanel lp, final PanelSave ps) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;// ww w . j a v a 2s .com try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(labelList), "Nommez le label :", "Crer un label", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new LabelSave(name); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (labelList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/labels/" + labelList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(labelList), "tes-vous sr de vouloir supprimer ce label?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } for (String section : ps .getSectionsContaining(labelList.getSelectedValue() + " (Label)")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (labelList.getSelectedValue().equals(lp.getFileName())) { lp.setFileName(""); } lp.hide(); file.delete(); data.remove(labelList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); labelList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { lp.show(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { lp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { lp.hideThenShow(); previousSelection = list.getSelectedValue(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { lp.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { lp.show(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { lp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { lp.hideThenShow(); previousSelection = list.getSelectedValue(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { lp.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(labelList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); }
From source file:io.github.jeremgamer.editor.panels.Others.java
public Others(final JFrame frame, final OtherPanel op, final PanelSave ps) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from w ww . j av a 2s. co m*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(otherList), "Nommez le composant :", "Crer un composant", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new OtherSave(name); ActionPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (otherList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/others/" + otherList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(otherList), "tes-vous sr de vouloir supprimer ce composant?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } OtherSave os = new OtherSave(); try { os.load(file); } catch (IOException e1) { e1.printStackTrace(); } String type = null; switch (os.getInt("type")) { case 0: type = "Zone de saisie"; break; case 1: type = "Zone de saisie de mot de passe"; break; case 2: type = "Zone de saisie (Grande)"; break; case 3: type = "Case cocher"; break; case 4: type = "Menu droulant"; break; case 5: type = "Barre de progression"; break; case 6: type = "Slider"; break; case 7: type = "Spinner"; break; } for (String section : ps.getSectionsContaining( otherList.getSelectedValue() + " (" + type + ")")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (otherList.getSelectedValue().equals(op.getFileName())) { op.setFileName(""); } op.hide(); file.delete(); data.remove(otherList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); otherList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { op.show(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { op.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { op.hideThenShow(); previousSelection = list.getSelectedValue(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { op.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { op.show(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { op.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { op.hideThenShow(); previousSelection = list.getSelectedValue(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { op.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(otherList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); OtherPanel.updateLists(); }
From source file:io.github.jeremgamer.editor.panels.Panels.java
public Panels(final JFrame frame, final PanelsPanel pp) { this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;// w w w. j av a 2s .co m try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(panelList), "Nommez le panneau :", "Crer un panneau", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new PanelSave(name); PanelsPanel.updateLists(); mainPanel.addItem(name); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (panelList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/panels/" + panelList.getSelectedValue() + "/" + panelList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(panelList), "tes-vous sr de vouloir supprimer ce panneau?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (panelList.getSelectedValue().equals(pp.getFileName())) { pp.setFileName(""); } pp.hide(); file.delete(); File parent = new File(file.getParent()); for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { img.delete(); } parent.delete(); mainPanel.removeItem(panelList.getSelectedValue()); data.remove(panelList.getSelectedIndex()); ActionPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); mainPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); GeneralSave gs = new GeneralSave(); try { gs.load(new File("projects/" + Editor.getProjectName() + "/general.rbd")); gs.set("mainPanel", combo.getSelectedItem()); } catch (IOException e) { e.printStackTrace(); } } }); updateList(); panelList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(panelList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); JPanel mainPanelInput = new JPanel(); mainPanelInput.setPreferredSize(new Dimension(280, 35)); mainPanelInput.setMaximumSize(new Dimension(280, 35)); mainPanelInput.add(new JLabel("Panneau principal:")); mainPanel.setPreferredSize(new Dimension(150, 27)); mainPanelInput.add(mainPanel); this.add(mainPanelInput); }
From source file:grafix.principal.Comandos.java
static public void cmdAplicarDefault() { ControleRegistro.alertaRegistro();/*from w ww . j a va 2 s . co m*/ try { if (JOptionPane.showConfirmDialog(Controle.getTela(), "Deseja desfazer todas as configuraes da janela?", "Confirmar ao", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { Controle.getJanelaAtiva().setConfiguracoesJanela(new ConfiguracoesJanela()); Controle.getTela().atualizarJanelasGraficos(); } } catch (Exception ex) { semJanelaAtiva(); } }
From source file:gdt.jgui.entity.bookmark.JBookmarksEditor.java
/** * Get context menu./*from www .j a v a 2 s .co m*/ * @return the context menu. */ @Override public JMenu getContextMenu() { menu = super.getContextMenu(); mia = null; int cnt = menu.getItemCount(); if (cnt > 0) { mia = new JMenuItem[cnt]; for (int i = 0; i < cnt; i++) mia[i] = menu.getItem(i); } menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // System.out.println("BookmarksEditor:getConextMenu:menu selected"); menu.removeAll(); if (mia != null) { for (JMenuItem mi : mia) menu.add(mi); } if (hasSelectedItems()) { menu.addSeparator(); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copy(); } }); menu.add(copyItem); JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { String[] sa = JBookmarksEditor.this.listSelectedItems(); if (sa == null) return; String bookmarkKey$; Entigrator entigrator = console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); for (String aSa : sa) { bookmarkKey$ = Locator.getProperty(aSa, BOOKMARK_KEY); if (bookmarkKey$ == null) continue; entity.removeElementItem("jbookmark", bookmarkKey$); } entigrator.save(entity); JConsoleHandler.execute(console, getLocator()); } } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(deleteItem); } if (hasToPaste()) { JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { paste(); } }); menu.add(pasteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
From source file:com.peter.javaautoupdater.JavaAutoUpdater.java
public static void run(String ftpHost, int ftpPort, String ftpUsername, String ftpPassword, boolean isLocalPassiveMode, boolean isRemotePassiveMode, String basePath, String softwareName, String args[]) {//w w w . j a v a 2s . com System.out.println("jarName=" + jarName); for (String arg : args) { if (arg.toLowerCase().trim().equals("-noautoupdate")) { return; } } JavaAutoUpdater.basePath = basePath; JavaAutoUpdater.softwareName = softwareName; JavaAutoUpdater.args = args; if (!jarName.endsWith(".jar") || jarName.startsWith("JavaAutoUpdater-")) { if (isDebug) { jarName = "test.jar"; } else { return; } } JProgressBarDialog d = new JProgressBarDialog(new JFrame(), "Auto updater", true); d.progressBar.setIndeterminate(true); d.progressBar.setStringPainted(true); d.progressBar.setString("Updating"); // d.addCancelEventListener(this); Thread longRunningThread = new Thread() { public void run() { d.progressBar.setString("checking latest version"); System.out.println("checking latest version"); FTPClient ftp = new FTPClient(); try { ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); ftp.connect(ftpHost, ftpPort); int reply = ftp.getReplyCode(); System.out.println("reply=" + reply + ", " + FTPReply.isPositiveCompletion(reply)); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); JOptionPane.showMessageDialog(null, "FTP server refused connection", "error", JOptionPane.ERROR_MESSAGE); } d.progressBar.setString("connected to ftp"); System.out.println("connected to ftp"); boolean success = ftp.login(ftpUsername, ftpPassword); if (!success) { ftp.disconnect(); JOptionPane.showMessageDialog(null, "FTP login fail, can't update software", "error", JOptionPane.ERROR_MESSAGE); } if (isLocalPassiveMode) { ftp.enterLocalPassiveMode(); } if (isRemotePassiveMode) { ftp.enterRemotePassiveMode(); } FTPFile[] ftpFiles = ftp.listFiles(basePath, new FTPFileFilter() { @Override public boolean accept(FTPFile file) { if (file.getName().startsWith(softwareName)) { return true; } else { return false; } } }); if (ftpFiles.length > 0) { FTPFile targetFile = ftpFiles[ftpFiles.length - 1]; System.out.println("targetFile : " + targetFile.getName() + " , " + targetFile.getSize() + "!=" + new File(jarName).length()); if (!targetFile.getName().equals(jarName) || targetFile.getSize() != new File(jarName).length()) { int r = JOptionPane.showConfirmDialog(null, "Confirm to update to " + targetFile.getName(), "Question", JOptionPane.YES_NO_OPTION); if (r == JOptionPane.YES_OPTION) { //ftp.enterRemotePassiveMode(); d.progressBar.setString("downloading " + targetFile.getName()); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE); d.progressBar.setIndeterminate(false); d.progressBar.setMaximum(100); CopyStreamAdapter streamListener = new CopyStreamAdapter() { @Override public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) { int percent = (int) (totalBytesTransferred * 100 / targetFile.getSize()); d.progressBar.setValue(percent); } }; ftp.setCopyStreamListener(streamListener); try (FileOutputStream fos = new FileOutputStream(targetFile.getName())) { ftp.retrieveFile(basePath + "/" + targetFile.getName(), fos); } catch (IOException e) { e.printStackTrace(); } d.progressBar.setString("restarting " + targetFile.getName()); restartApplication(targetFile.getName()); } } } ftp.logout(); ftp.disconnect(); } catch (Exception ex) { ex.printStackTrace(); } } }; d.thread = longRunningThread; d.setVisible(true); }
From source file:net.sf.jabref.external.MoveFileAction.java
@Override public void actionPerformed(ActionEvent event) { int selected = editor.getSelectedRow(); if (selected == -1) { return;//from w ww. j av a2 s . c o m } FileListEntry entry = editor.getTableModel().getEntry(selected); // Check if the current file exists: String ln = entry.link; boolean httpLink = ln.toLowerCase(Locale.ENGLISH).startsWith("http"); if (httpLink) { // TODO: notify that this operation cannot be done on remote links return; } // Get an absolute path representation: List<String> dirs = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory(); int found = -1; for (int i = 0; i < dirs.size(); i++) { if (new File(dirs.get(i)).exists()) { found = i; break; } } if (found < 0) { JOptionPane.showMessageDialog(frame, Localization.lang("File_directory_is_not_set_or_does_not_exist!"), MOVE_RENAME, JOptionPane.ERROR_MESSAGE); return; } File file = new File(ln); if (!file.isAbsolute()) { file = FileUtil.expandFilename(ln, dirs).orElse(null); } if ((file != null) && file.exists()) { // Ok, we found the file. Now get a new name: String extension = null; if (entry.type.isPresent()) { extension = "." + entry.type.get().getExtension(); } File newFile = null; boolean repeat = true; while (repeat) { repeat = false; String chosenFile; if (toFileDir) { // Determine which name to suggest: String suggName = FileUtil .createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(), Globals.journalAbbreviationLoader, Globals.prefs) .concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : ""); CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"), Localization.lang("Rename to '%0'", suggName), Globals.prefs.getBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR)); int answer; // Only ask about renaming file if the file doesn't have the proper name already: if (suggName.equals(file.getName())) { answer = JOptionPane.showConfirmDialog(frame, Localization.lang("Move file to file directory?"), MOVE_RENAME, JOptionPane.YES_NO_OPTION); } else { answer = JOptionPane.showConfirmDialog(frame, cbm, MOVE_RENAME, JOptionPane.YES_NO_OPTION); } if (answer != JOptionPane.YES_OPTION) { return; } Globals.prefs.putBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR, cbm.isSelected()); StringBuilder sb = new StringBuilder(dirs.get(found)); if (!dirs.get(found).endsWith(File.separator)) { sb.append(File.separator); } if (cbm.isSelected()) { // Rename: sb.append(suggName); } else { // Do not rename: sb.append(file.getName()); } chosenFile = sb.toString(); } else { chosenFile = FileDialogs.getNewFile(frame, file, Collections.singletonList(extension), JFileChooser.SAVE_DIALOG, false); } if (chosenFile == null) { return; // canceled } newFile = new File(chosenFile); // Check if the file already exists: if (newFile.exists() && (JOptionPane.showConfirmDialog(frame, Localization.lang("'%0' exists. Overwrite file?", newFile.getName()), MOVE_RENAME, JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)) { if (toFileDir) { return; } else { repeat = true; } } } if (!newFile.equals(file)) { try { boolean success = file.renameTo(newFile); if (!success) { success = FileUtil.copyFile(file, newFile, true); } if (success) { // Remove the original file: if (!file.delete()) { LOGGER.info("Cannot delete original file"); } // Relativise path, if possible. String canPath = new File(dirs.get(found)).getCanonicalPath(); if (newFile.getCanonicalPath().startsWith(canPath)) { if ((newFile.getCanonicalPath().length() > canPath.length()) && (newFile .getCanonicalPath().charAt(canPath.length()) == File.separatorChar)) { String newLink = newFile.getCanonicalPath().substring(1 + canPath.length()); editor.getTableModel().setEntry(selected, new FileListEntry(entry.description, newLink, entry.type)); } else { String newLink = newFile.getCanonicalPath().substring(canPath.length()); editor.getTableModel().setEntry(selected, new FileListEntry(entry.description, newLink, entry.type)); } } else { String newLink = newFile.getCanonicalPath(); editor.getTableModel().setEntry(selected, new FileListEntry(entry.description, newLink, entry.type)); } eEditor.updateField(editor); //JOptionPane.showMessageDialog(frame, Globals.lang("File moved"), // Globals.lang("Move/Rename file"), JOptionPane.INFORMATION_MESSAGE); frame.output(Localization.lang("File moved")); } else { JOptionPane.showMessageDialog(frame, Localization.lang("Move file failed"), MOVE_RENAME, JOptionPane.ERROR_MESSAGE); } } catch (SecurityException | IOException ex) { LOGGER.warn("Could not move file", ex); JOptionPane.showMessageDialog(frame, Localization.lang("Could not move file '%0'.", file.getAbsolutePath()) + ex.getMessage(), MOVE_RENAME, JOptionPane.ERROR_MESSAGE); } } } else { // File doesn't exist, so we can't move it. JOptionPane.showMessageDialog(frame, Localization.lang("Could not find file '%0'.", entry.link), Localization.lang("File not found"), JOptionPane.ERROR_MESSAGE); } }