List of usage examples for javax.swing JList locationToIndex
public int locationToIndex(Point location)
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;/*from w w 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.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 . j a v a 2 s .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(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:io.github.jeremgamer.editor.panels.Panels.java
public Panels(final JFrame frame, final PanelsPanel pp) { this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from ww w .j a va 2 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((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: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 . ja v a2s . 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((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:androhashcheck.MainFrame.java
/** * Creates new form MainFrame/*from w w w . jav a2 s. c o m*/ * @param logInFrame */ public MainFrame(JFrame logInFrame) { initComponents(); this.logInFrame = logInFrame; jList5.setModel(listModel); dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); displayApkFolder(); //mouse listner - when clicked on uploaded package to show details jList3.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { JList list = (JList) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); final TaskObject taskObject = taskList.get(index); java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new TaskFrame(taskObject).setVisible(true); } }); } } }); shouldCheckTasks = true; startThreadForTaskUpdatesChecking(); }
From source file:com.unicauca.braim.braimclient.BraimGui.java
private void add_mouse_listener_to_list() { MouseListener mouseListener = new MouseAdapter() { @Override/* w ww . j ava 2s.com*/ public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { actualSong = actualSongList[index]; lbl_song_name.setText(actualSong.getName()); play_song(actualSong); } } } }; list_songs.addMouseListener(mouseListener); }
From source file:com.vgi.mafscaling.LogView.java
private void createLogViewPanel() { logViewPanel = new JPanel(); GridBagLayout gbl_logViewPanel = new GridBagLayout(); gbl_logViewPanel.columnWidths = new int[] { 0 }; gbl_logViewPanel.rowHeights = new int[] { 0, 0 }; gbl_logViewPanel.columnWeights = new double[] { 1.0 }; gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 }; logViewPanel.setLayout(gbl_logViewPanel); try {/*from w w w . j a v a 2s.co m*/ logDataTable = new DBTable(); logDataTable.copyColumnHeaderNames = true; logDataTable.defaultClickCountToStartEditor = 2; logDataTable.doNotUseDatabaseSort = true; logDataTable.listenKeyPressEventsWholeWindow = true; logDataTable.createControlPanel(DBTable.READ_NAVIGATION); logDataTable.enableExcelCopyPaste(); logDataTable.setSortEnabled(false); logDataTable.setSkin(new TableSkin()); logDataTable.refresh(new String[1][25]); logDataTable.setComparator(new DoubleComparator()); logDataTable.getTable().setCellSelectionEnabled(true); logDataTable.getTable().setColumnSelectionAllowed(true); logDataTable.getTable().setRowSelectionAllowed(true); logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(3)); rowTextField.setPreferredSize(null); rowTextField.setColumns(5); GridBagConstraints gbc_logDataTable = new GridBagConstraints(); gbc_logDataTable.insets = insets0; gbc_logDataTable.anchor = GridBagConstraints.PAGE_START; gbc_logDataTable.fill = GridBagConstraints.BOTH; gbc_logDataTable.gridx = 0; gbc_logDataTable.gridy = 0; logViewPanel.add(logDataTable, gbc_logDataTable); listModel = new DefaultListModel<JLabel>(); selectionCombo.removeAllItems(); String name; JTableHeader tableHeader = logDataTable.getTableHeader(); for (int i = 0; i < logDataTable.getColumnCount(); ++i) { Column col = logDataTable.getColumn(i); col.setNullable(true); col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader)); name = col.getHeaderValue().toString(); selectionCombo.addItem(name); listModel.addElement(new JLabel(name, new CheckBoxIcon(), JLabel.LEFT)); } JList<JLabel> menuList = new JList<JLabel>(listModel); menuList.setOpaque(false); menuList.setCellRenderer(new ImageListCellRenderer()); menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); menuList.setLayoutOrientation(JList.VERTICAL); menuList.setFixedCellHeight(25); menuList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { if (e.getClickCount() == 1 && colors.size() > 0) { JList<?> list = (JList<?>) e.getSource(); int index = list.locationToIndex(e.getPoint()); if (index >= 0) { int colIdx = logDataTable.getCurrentIndexForOriginalColumn(index); Column col = logDataTable.getColumn(colIdx); if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) { CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col .getHeaderRenderer(); JLabel label = (JLabel) list.getModel().getElementAt(index); CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon(); checkIcon.setChecked(!checkIcon.isChecked()); if (checkIcon.isChecked()) { checkIcon.setColor(colors.pop()); JTable table = logDataTable.getTable(); TableModel model = table.getModel(); addXYSeries(model, index, col.getHeaderValue().toString(), checkIcon.getColor()); } else { colors.push(checkIcon.getColor()); checkIcon.setColor(renderer.getDefaultColor()); removeXYSeries(index); } list.repaint(); } } } } catch (Exception ex) { ex.printStackTrace(); } } }); headerScrollPane = new JScrollPane(menuList); GridBagConstraints gbc_headersTree = new GridBagConstraints(); gbc_headersTree.insets = insets0; gbc_headersTree.anchor = GridBagConstraints.PAGE_START; gbc_headersTree.fill = GridBagConstraints.BOTH; gbc_headersTree.gridx = 0; gbc_headersTree.gridy = 1; logViewPanel.add(headerScrollPane, gbc_headersTree); headerScrollPane.setVisible(false); } catch (Exception e) { e.printStackTrace(); logger.error(e); } }
From source file:gui.SpamPanel.java
public void generate() { Message[] arrMsg = GmailAPI.Spam.toArray(new Message[GmailAPI.Spam.size()]); SpamList = new JList(arrMsg); SpamList.setCellRenderer(new DefaultListCellRenderer() { // Setting the DefaultListCellRenderer public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Message message = (Message) value; // Using value we are getting the object in JList Map<String, String> map = null; try { map = GmailAPI.getMessageDetails(message.getId()); } catch (MessagingException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); }/*from w w w . ja v a2s.c o m*/ String sub = map.get("subject"); if (map.get("subject").length() > 22) { sub = map.get("subject").substring(0, 20) + "..."; } setText(sub); // Setting the text //setIcon( shape.getImage() ); // Setting the Image Icon return this; } }); SpamList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); SpamList.setLayoutOrientation(JList.VERTICAL); SpamList.setVisibleRowCount(-1); jScrollPane1.setViewportView(SpamList); SpamList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { JList list = (JList) evt.getSource(); int index = list.locationToIndex(evt.getPoint()); String id = arrMsg[index].getId(); Map<String, String> map = GmailAPI.getMessageDetails(id); jTextField1.setText(map.get("from")); jTextField2.setText(map.get("subject")); dateTextField.setText(map.get("senddate")); BodyTextPane.setText(map.get("body")); BodyTextPane.setContentType("text/html"); //BodyTextArea.setCo } catch (IOException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (MessagingException ex) { Logger.getLogger(SpamPanel.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java
/** * @return//from w ww. j a va 2 s . co m */ private JPanel createColorCategoriesPanel() { JPanel categoryColorsConfigurationPanel = new JPanel(new GridBagLayout()); categoryColorsConfigurationPanel.setPreferredSize(new Dimension(180, 200)); GridBagConstraints itemConstraint = new GridBagConstraints(); JLabel categoryColorsLabel = new ResourceLabel( "plotter.configuration_dialog.color_scheme_dialog.category_colors"); { itemConstraint.fill = GridBagConstraints.HORIZONTAL; itemConstraint.anchor = GridBagConstraints.WEST; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.insets = new Insets(0, 5, 5, 5); itemConstraint.weightx = 1.0; categoryColorsConfigurationPanel.add(categoryColorsLabel, itemConstraint); } // add button panel { JPanel buttonPanel = new JPanel(new GridBagLayout()); // remove scheme button { removeCategoryColorButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.remove_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { removeSelectedColorAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(removeCategoryColorButton, itemConstraint); } { addCategoryButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.add_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Color oldColor = Color.white; Color newSchemeColor = createColorDialog(oldColor); if (newSchemeColor != null && !newSchemeColor.equals(oldColor)) { addColorAction(newSchemeColor); } } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(addCategoryButton, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.anchor = GridBagConstraints.EAST; itemConstraint.insets = new Insets(0, 5, 5, 5); categoryColorsConfigurationPanel.add(buttonPanel, itemConstraint); } { JPanel categoryListPanel = new JPanel(new GridBagLayout()); // add list of categorie colors { colorList = new JList<Color>(nominalColorListModel); categoryColorsLabel.setLabelFor(colorList); colorList.setCellRenderer(new ColorListCellRenderer()); colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); MouseAdapter ma = new MouseAdapter() { private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JList<?> list = (JList<?>) e.getSource(); list.setSelectedIndex(list.locationToIndex(e.getPoint())); Color selectedColor = (Color) list.getSelectedValue(); if (selectedColor == null) { return; } removeMenuItem.setEnabled(nominalColorListModel.getSize() > 2); popupMenu.show(list, x, y); } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } }; colorList.addMouseListener(ma); colorList.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { return; // Nothing to be done } @Override public void keyReleased(KeyEvent e) { return; // Nothing to be done } @Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_DELETE) { if (nominalColorListModel.getSize() > 2) { removeSelectedColorAction(); } } if (key == KeyEvent.VK_F2) { replaceSelectedColorAction(); } if (key == KeyEvent.VK_UP && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorUpAction(); } if (key == KeyEvent.VK_DOWN && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorDownAction(); } } }); colorListScrollPane = new JScrollPane(colorList); colorListScrollPane.setPreferredSize(new Dimension(170, 200)); colorListScrollPane.setMaximumSize(new Dimension(170, 200)); colorListScrollPane.setMinimumSize(new Dimension(170, 180)); colorListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); colorListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 0.0; itemConstraint.weighty = 0.5; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; categoryListPanel.add(colorListScrollPane, itemConstraint); } // add up/down button panel { JPanel upAndDownButtonPanel = new JPanel(new GridBagLayout()); // add up button { JButton upButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_up") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorUpAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(upButton, itemConstraint); } // add down button { JButton downButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_down") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorDownAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(downButton, itemConstraint); } // add spacer panel { JPanel spacer = new JPanel(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; upAndDownButtonPanel.add(spacer, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; categoryListPanel.add(upAndDownButtonPanel, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.BOTH; categoryColorsConfigurationPanel.add(categoryListPanel, itemConstraint); } return categoryColorsConfigurationPanel; }
From source file:gui.InboxPanel.java
public void generate() { Message[] arrMsg = GmailAPI.Inbox.toArray(new Message[GmailAPI.Inbox.size()]); InboxList = new JList(arrMsg); InboxList.setCellRenderer(new DefaultListCellRenderer() { // Setting the DefaultListCellRenderer public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Message message = (Message) value; // Using value we are getting the object in JList Map<String, String> map = null; try { map = GmailAPI.getMessageDetails(message.getId()); } catch (MessagingException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); }//from w w w .j a va2s.co m String sub = map.get("subject"); if (map.get("subject").length() > 22) { sub = map.get("subject").substring(0, 20) + "..."; } setText(sub); // Setting the text //setIcon( shape.getImage() ); // Setting the Image Icon return this; } }); InboxList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); InboxList.setLayoutOrientation(JList.VERTICAL); InboxList.setVisibleRowCount(-1); jScrollPane1.setViewportView(InboxList); InboxList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { JList list = (JList) evt.getSource(); int index = list.locationToIndex(evt.getPoint()); String id = arrMsg[index].getId(); curId = id; Map<String, String> map = GmailAPI.getMessageDetails(id); jTextField1.setText(map.get("from")); jTextField2.setText(map.get("subject")); dateTextField.setText(map.get("senddate")); BodyTextPane.setText(map.get("body")); //BodyTextPane.setContentType("text/html"); //BodyTextArea.setCo } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (MessagingException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } } }); }