private void changeDir(File dir) { prefs.put(KEY_DIR, dir.getAbsolutePath()); dirWatcher.cancel(); dirWatcher = new DirWatcher2(dir, option, getRegexpPattern(getExtensions())); setTitle(dir.getAbsolutePath()); Log.info("Creating DirWatcher"); currentDirectoryListing2.clear(); jList1.setListData(new Vector<SimpleLine2>(currentDirectoryListing2)); jList1.setVisible(true); }
/** Create the main JFrame */ public Driver() { frame = (JFrame) this; setTitle("RIDVentory v2.1.2"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Creates connection to controller control = Controller.getInstance(); setBounds(100, 100, 593, 370); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] {577, 0}; gridBagLayout.rowHeights = new int[] {332, 0}; gridBagLayout.columnWeights = new double[] {0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[] {0.0, Double.MIN_VALUE}; getContentPane().setLayout(gridBagLayout); // Create Menu TopMenuBar topMenu = new TopMenuBar(); this.setJMenuBar(topMenu.createMenuBar()); // Popup Menus // Category Menu final JPopupMenu popupCat = new JPopupMenu(); final JMenuItem addCat = new JMenuItem("Add Category"); final JMenuItem editCat = new JMenuItem("Edit Category"); final JMenuItem deleteCat = new JMenuItem("Delete Category"); popupCat.add(addCat); popupCat.add(editCat); popupCat.add(deleteCat); // Brand Menu final JPopupMenu popupBrand = new JPopupMenu(); final JMenuItem addBrand = new JMenuItem("Add Brand"); final JMenuItem editBrand = new JMenuItem("Edit Brand"); final JMenuItem deleteBrand = new JMenuItem("Delete Brand"); popupBrand.add(addBrand); popupBrand.add(editBrand); popupBrand.add(deleteBrand); GridBagConstraints gbc_table = new GridBagConstraints(); gbc_table.gridwidth = 3; gbc_table.fill = GridBagConstraints.BOTH; gbc_table.insets = new Insets(0, 0, 5, 0); gbc_table.gridx = 0; gbc_table.gridy = 0; gbc_table.weightx = 1; gbc_table.weighty = 1; GridBagConstraints gbc_buttonPanel = new GridBagConstraints(); gbc_buttonPanel.insets = new Insets(0, 0, 5, 5); gbc_buttonPanel.fill = GridBagConstraints.BOTH; gbc_buttonPanel.gridx = 0; gbc_buttonPanel.gridy = 0; gbc_buttonPanel.weightx = 1; gbc_buttonPanel.weighty = 1; GridBagConstraints gbc_list = new GridBagConstraints(); gbc_list.insets = new Insets(0, 0, 5, 0); gbc_list.anchor = GridBagConstraints.NORTHWEST; gbc_list.gridx = 1; gbc_list.gridy = 0; gbc_list.weightx = 1; gbc_list.weighty = 1; GridBagConstraints gbc_topMenu = new GridBagConstraints(); gbc_topMenu.insets = new Insets(0, 0, 5, 0); gbc_topMenu.anchor = GridBagConstraints.NORTHWEST; gbc_topMenu.gridx = 1; gbc_topMenu.gridy = 0; gbc_topMenu.weightx = 1; gbc_topMenu.weighty = 1; JSplitPane splitPane = new JSplitPane(); splitPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); GridBagConstraints gbc_splitPane = new GridBagConstraints(); gbc_splitPane.weighty = 1.0; gbc_splitPane.weightx = 1.0; gbc_splitPane.fill = GridBagConstraints.BOTH; gbc_splitPane.gridx = 0; gbc_splitPane.gridy = 0; getContentPane().add(splitPane, gbc_splitPane); JPanel rightPanel = new JPanel(); splitPane.setRightComponent(rightPanel); GridBagLayout gbl_rightPanel = new GridBagLayout(); gbl_rightPanel.columnWidths = new int[] {499, 0}; gbl_rightPanel.rowHeights = new int[] {281, 0}; gbl_rightPanel.columnWeights = new double[] {0.0, Double.MIN_VALUE}; gbl_rightPanel.rowWeights = new double[] {0.0, Double.MIN_VALUE}; rightPanel.setLayout(gbl_rightPanel); table = new JTable() { /** */ private static final long serialVersionUID = 1L; public boolean isCellEditable(int rowIndex, int vColIndex) { if (vColIndex > 0) // ID is not editable return true; else return false; } }; table.setFillsViewportHeight(true); table.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setAlignmentY(Component.BOTTOM_ALIGNMENT); // Load table data tableData = control.loadTableData(); final TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<DefaultTableModel>((DefaultTableModel) tableData); table.setModel(tableData); table.setRowSorter(sorter); // Change it so load is only called once (Store results of load call and use it for list) catCellEditor = new JComboBox<String>(control.loadCategories()); brandCellEditor = new JComboBox<String>(control.loadBrands()); // Make model editor a dropdown (Make dynamic in the future) categoryColumn = table.getColumnModel().getColumn(3); brandColumn = table.getColumnModel().getColumn(4); categoryColumn.setCellEditor(new DefaultCellEditor(catCellEditor)); brandColumn.setCellEditor(new DefaultCellEditor(brandCellEditor)); // Right main pane JSplitPane splitPaneMain = new JSplitPane(); splitPaneMain.setBorder(null); splitPaneMain.setDividerSize(-1); splitPaneMain.setResizeWeight(1.0); splitPaneMain.setPreferredSize(new Dimension(187, 25)); splitPaneMain.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); splitPaneMain.setOrientation(JSplitPane.VERTICAL_SPLIT); GridBagConstraints gbc_splitPaneMain = new GridBagConstraints(); gbc_splitPaneMain.weighty = 1.0; gbc_splitPaneMain.weightx = 1.0; gbc_splitPaneMain.fill = GridBagConstraints.BOTH; gbc_splitPaneMain.gridx = 0; gbc_splitPaneMain.gridy = 0; // Add split pane to main Right split pane rightPanel.add(splitPaneMain, gbc_splitPaneMain); // Right main pane, buttons row JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(0, 2, 0, 0)); final JButton btnInsert = new JButton("Insert"); final JButton btnDelete = new JButton("Delete"); buttonPanel.add(btnInsert); buttonPanel.add(btnDelete); // Set components splitPaneMain.setTopComponent(new JScrollPane(table)); splitPaneMain.setBottomComponent(buttonPanel); JPanel leftPanel = new JPanel(); splitPane.setLeftComponent(leftPanel); GridBagLayout gbl_leftPanel = new GridBagLayout(); gbl_leftPanel.columnWidths = new int[] {71, 0}; gbl_leftPanel.rowHeights = new int[] {34, 0}; gbl_leftPanel.columnWeights = new double[] {0.0, Double.MIN_VALUE}; gbl_leftPanel.rowWeights = new double[] {0.0, Double.MIN_VALUE}; leftPanel.setLayout(gbl_leftPanel); // Left Split panel JSplitPane splitPaneLists = new JSplitPane(); splitPaneLists.setResizeWeight(0.5); splitPaneLists.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); GridBagConstraints gbc_splitPaneLists = new GridBagConstraints(); gbc_splitPaneLists.anchor = GridBagConstraints.NORTHWEST; gbc_splitPaneLists.gridx = 0; gbc_splitPaneLists.gridy = 0; gbc_splitPaneLists.weightx = 1; gbc_splitPaneLists.weighty = 1; gbc_splitPaneLists.fill = GridBagConstraints.BOTH; leftPanel.add(splitPaneLists, gbc_splitPaneLists); // Right list final JList<String> brandList = new JList<String>(); brandList.setLayoutOrientation(JList.VERTICAL_WRAP); brandList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); brandList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); brandList.setAlignmentX(Component.RIGHT_ALIGNMENT); brandList.setAlignmentY(Component.TOP_ALIGNMENT); brandList.setModel(control.loadListBrands()); brandList.setSelectedIndex(0); final ListSelectionModel brandListSelectionModel = (ListSelectionModel) brandList.getSelectionModel(); splitPaneLists.setRightComponent(brandList); // Left List final JList<String> categoryList = new JList<String>(); categoryList.setLayoutOrientation(JList.VERTICAL_WRAP); categoryList.setVisible(true); categoryList.setAlignmentY(Component.TOP_ALIGNMENT); categoryList.setAlignmentX(Component.LEFT_ALIGNMENT); categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListSelectionModel catListSelectionModel = categoryList.getSelectionModel(); // Created to add listener categoryList.setModel(control.loadListCategories()); categoryList.setSelectedIndex(0); splitPaneLists.setLeftComponent(categoryList); table.addMouseListener( new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { Point p = e.getPoint(); int rowNumber = table.rowAtPoint(p); if (Debug.LEVEL > 1) System.out.println("Row " + rowNumber + " selected"); } } }); btnDelete.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { int selectedRow = table.getSelectedRow(); String name = (String) table.getModel().getValueAt(selectedRow, 1); if (selectedRow != -1) { int answer = JOptionPane.showConfirmDialog( frame, "Are you sure you want to erase product " + name + "?\n", "Are you sure?", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { if (Debug.LEVEL > 1) System.out.println("Row " + selectedRow + " Deleted"); DefaultTableModel model = (DefaultTableModel) table.getModel(); // Call Delete in controller int id = (int) model.getValueAt(selectedRow, 0); if (control.deleteItem(id) == -1) { JOptionPane.showMessageDialog( frame, "Error: Item could not be erased", "Error", JOptionPane.ERROR_MESSAGE); } if (Debug.LEVEL > 2) System.out.println("Product ID " + id); // Delete it from table model model.removeRow(selectedRow); } } } }); btnInsert.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { InsertItem dialog = new InsertItem(table.getModel()); dialog.setVisible(true); btnInsert.setEnabled(false); // Disable insert button so no multiple inserts btnDelete.setEnabled(false); // Put a listener on the window to determine when it closes dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { // Notify table that data has changed to rerun filter // fireTableCellUpdated ((DefaultTableModel) tableData).fireTableDataChanged(); btnInsert.setEnabled(true); // Re-Enable insert button btnDelete.setEnabled(true); if (Debug.LEVEL > 3) System.out.println("Insert item window closed"); } }); } }); categoryList.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { Point p = e.getPoint(); int itemChosen = categoryList.locationToIndex(p); // Make sure an item is chosen if (itemChosen > 0) // Greater than 0 to skip All { // Mark item as selected categoryList.setSelectedIndex(itemChosen); // Check if Delete Menu Item is on if (!popupDeleteOnCat) { popupCat.add(editCat); popupCat.add(deleteCat); // If not on, add it popupDeleteOnCat = true; } } else { // Check if Delete is on if (popupDeleteOnCat) { popupCat.remove(1); // Delete edit if turned on popupCat.remove(1); // Delete delete if turned on popupDeleteOnCat = false; } } popupCat.show(frame, e.getX(), e.getY()); if (Debug.LEVEL > 0) System.out.println("Category List Item Chosen: " + itemChosen); } } }); brandList.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { Point p = e.getPoint(); int itemChosen = brandList.locationToIndex(p); // Make sure an item has been chosen if (itemChosen > 0) // Greater than 0 because 0 is All { // Mark item as selected brandList.setSelectedIndex(itemChosen); // Check if Delete Menu Item is not on the menu if (!popupDeleteOnBrand) { popupBrand.add(editBrand); popupBrand.add(deleteBrand); // If not on, add it popupDeleteOnBrand = true; } } else { // Check if Delete is on the menu if (popupDeleteOnBrand) { popupBrand.remove(1); // Delete edit popupBrand.remove(1); // Delete delete if turned on popupDeleteOnBrand = false; } } popupBrand.show(frame, e.getX(), e.getY()); if (Debug.LEVEL > 0) System.out.println("Brand List Item Chosen: " + itemChosen); } } }); // Selected index listeners catListSelectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) // Proceed if values aren't being changed { int index = categoryList.getSelectedIndex(); if (index >= 0) // Make sure you're actually working on an item { String category = (String) categoryList.getModel().getElementAt(index); index = brandList.getSelectedIndex(); String brand = (String) brandList.getModel().getElementAt(index); // Call filter update sorter.setRowFilter(control.createFilter(category, brand)); // debug if (Debug.LEVEL > 0) System.out.println("Category List Index Chosen: " + index); } } } }); // Selected index listeners brandListSelectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) // Proceed if values aren't being changed { int indexCat = categoryList.getSelectedIndex(); int indexBrand = brandList.getSelectedIndex(); if (indexCat >= 0 && indexBrand >= 0) // Make sure you're actually working on an item { String category = (String) categoryList.getModel().getElementAt(indexCat); String brand = (String) brandList.getModel().getElementAt(indexBrand); // Call filter update sorter.setRowFilter(control.createFilter(category, brand)); } } } }); addCat.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { String newCat = (String) JOptionPane.showInputDialog( frame, "Enter the name of the new Category:", "Add New Category", JOptionPane.PLAIN_MESSAGE, null, null, null); if (newCat == null) { return; // Don't do anything } if (newCat.isEmpty() || newCat == "") { JOptionPane.showMessageDialog( frame, "No input encountered", "New category was not created", JOptionPane.ERROR_MESSAGE); return; // Don't do anything } String result = control.addCategory(newCat); // Input checking needs to be added before beta 2 if (result != null) { JOptionPane.showMessageDialog( frame, result, "SQL Error Encountered", JOptionPane.ERROR_MESSAGE); return; } // Add category to list DefaultListModel<String> model = (DefaultListModel<String>) categoryList.getModel(); model.addElement(newCat); catCellEditor.addItem(newCat); } }); deleteCat.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { int catChosenIndex = categoryList.getSelectedIndex(); String catName = (String) categoryList.getSelectedValue(); // System.out.println(catChosen); int answer = JOptionPane.showConfirmDialog( frame, "Are you sure you want to delete category " + catName + "?\n", "Are you sure?", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { if (control.deleteCategory(catName) != 0) { JOptionPane.showMessageDialog( frame, "Unable to erase category (category must not be used by any items)", "SQL Error Encountered", JOptionPane.ERROR_MESSAGE); return; } DefaultListModel<String> model = (DefaultListModel<String>) categoryList.getModel(); categoryList.clearSelection(); model.removeElementAt(catChosenIndex); catCellEditor.removeItem(catName); categoryList.setSelectedIndex(0); } } }); addBrand.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { String newBrand = (String) JOptionPane.showInputDialog( frame, "Enter the name of the new Brand:", "Add New Category", JOptionPane.PLAIN_MESSAGE, null, null, null); if (newBrand == null) { return; // Don't do anything } if (newBrand.isEmpty() || newBrand == "") { JOptionPane.showMessageDialog( frame, "No input encountered", "New category was not created", JOptionPane.ERROR_MESSAGE); return; // Don't do anything } String result = control.addBrand(newBrand); // Input checking needs to be added before beta 2 if (result != null) { JOptionPane.showMessageDialog( frame, result, "SQL Error Encountered", JOptionPane.ERROR_MESSAGE); return; } // Add category to list DefaultListModel<String> model = (DefaultListModel<String>) brandList.getModel(); model.addElement(newBrand); brandCellEditor.addItem(newBrand); } }); deleteBrand.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { int brandChosenIndex = brandList.getSelectedIndex(); String brandName = (String) brandList.getSelectedValue(); System.out.println(brandChosenIndex); int answer = JOptionPane.showConfirmDialog( frame, "Are you sure you want to delete category " + brandName + "?\n", "Are you sure?", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { if (control.deleteBrand(brandName) != 0) { JOptionPane.showMessageDialog( frame, "Unable to erase category (category must not be used by any items)", "SQL Error Encountered", JOptionPane.ERROR_MESSAGE); return; } DefaultListModel<String> model = (DefaultListModel<String>) brandList.getModel(); // brandList.clearSelection(); model.removeElementAt(brandChosenIndex); brandCellEditor.removeItem(brandName); // Use name to allow flexibility in future brandList.setSelectedIndex(0); // Reset to all } } }); // Data change listener tableData.addTableModelListener( new TableModelListener() { public void tableChanged(TableModelEvent e) { try { int row = e.getFirstRow(); int column = e.getColumn(); String columnName = tableData.getColumnName(column); int itemID = (int) tableData.getValueAt(row, 0); Object data = tableData.getValueAt(row, column); if (Debug.LEVEL > 0) { System.out.println( "Cell Edited at " + row + " " + column + ": " + columnName + " " + data + " ID: " + itemID); } int rowsUpdated = control.updateItem(itemID, columnName, data); if (rowsUpdated == 0) { System.out.println("Failed to update, changes reverted"); JOptionPane.showMessageDialog( frame, "Edit was invalid, please verify value is correct", "SQL Error Encountered", JOptionPane.ERROR_MESSAGE); // ((RidvTableModel)tableData).undoChange(); } } catch (ArrayIndexOutOfBoundsException exception) { // Temp fix for data insertion bypass } } }); }
/** * creates a new DocumentSelectionPanel. Will display the list of document from the server that * can be selected on one side (or a message that there are no documents on the server). On the * other side there will be a text field to create a new document with the given name (or a * variation of the name if its already taken, ie. Niki-3 is Niki is already taken). * * @param list list of documents on the server * @param editor the editor this selectionPanel is in. */ public DocumentSelectionPanel(String[] list, final Editor editor) { GroupLayout layout = new GroupLayout(this); this.setLayout(layout); // get some margins around components by default layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); openLabel = new JLabel("Open Existing Document"); openLabel.setFont( new Font(openLabel.getFont().getFamily(), Font.BOLD, openLabel.getFont().getSize())); createLabel = new JLabel("Create New Document"); createLabel.setFont( new Font(createLabel.getFont().getFamily(), Font.BOLD, createLabel.getFont().getSize())); ImageIcon icon = new ImageIcon("res/orange-or.png", "or-icon"); orLabel = new JLabel(icon, SwingConstants.CENTER); if (list != null) { ArrayList<DocumentIDsAndNames> newList = new ArrayList<DocumentIDsAndNames>(); for (String item : list) { newList.add(new DocumentIDsAndNames(item)); } docsList = new JList(newList.toArray()); } else { String[] blank = {"There are no documents on the server."}; docsList = new JList(blank); } docsList.setVisible(true); docsList.setMinimumSize(new Dimension(0, 200)); scrollPane = new JScrollPane(docsList); docNameTextField = new HintTextField("Enter Document Name"); docNameTextField.addActionListener( new ActionListener() { /** * When enter is hit from the new document text field send a requestNew message to the * server */ public void actionPerformed(ActionEvent ae) { String newName = docNameTextField.getText(); docNameTextField.setText(""); if (newName.contains("|") || newName.contains("~")) { JOptionPane.showMessageDialog( editor.getTabbedPane(), "pipes and tildas cannot be used in document names"); return; } editor.sendMessage(editor.createControlMessage("requestNew", -1, newName)); } }); createButton = new JButton(); createButton.setText("Create"); createButton.addActionListener( new ActionListener() { /** sends a message to the server indicating that a new document has been requested. */ public void actionPerformed(ActionEvent ae) { String newName = docNameTextField.getText(); docNameTextField.setText(""); if (newName.equals("Enter Document Name") || newName.equals("")) { newName = "New Document"; } editor.sendMessage(editor.createControlMessage("requestNew", -1, newName)); } }); openButton = new JButton(); openButton.setText("Open"); openButton.addActionListener( new ActionListener() { /** * When a document from the server is selected and the open button is pressed, opens that * document in the current tab and opens a new "NewDocPanel" tab as well. Sends message to * the server about the opened document. Refuses to open the document if it is already * open in the current editor. */ public void actionPerformed(ActionEvent ae) { openDocument(editor); } }); docsList.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { openDocument(editor); } } }); JLabel sep1 = new JLabel(new ImageIcon("res/divider.png")); JLabel sep2 = new JLabel(new ImageIcon("res/divider.png")); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(openLabel) .addComponent(scrollPane, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(openButton)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(sep1) .addComponent(orLabel) .addComponent(sep2)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(createLabel) .addComponent(docNameTextField, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(createButton))); layout.setVerticalGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addGroup( layout .createSequentialGroup() .addComponent(openLabel) .addComponent(scrollPane, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(openButton)) .addGroup( layout .createSequentialGroup() .addComponent(sep1, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(orLabel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(sep2, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup( layout .createSequentialGroup() .addComponent(createLabel) .addComponent( docNameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(createButton))); }
public Gui(Town town) { this.town = town; setTitle("Simple example"); setSize(300, 200); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel panel = new JPanel(); getContentPane().add(panel); panel.setLayout(new GridLayout(1, 2)); JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); panel.add(leftPanel); // panel.setLayout(new BorderLayout()); // panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); peopleNames = town.getAllPeopleNames(); people = town.getAllPeople(); list = new JList<Person>(people); list.setCellRenderer(new PersonListRenderer()); list.setVisible(true); list.addListSelectionListener(this); JScrollPane pane = new JScrollPane(); pane.getViewport().add(list); pane.setPreferredSize(new Dimension(250, 200)); search = new JTextField(""); search.addActionListener(this); search.setMaximumSize(new Dimension(Integer.MAX_VALUE, search.getPreferredSize().height)); personName = new JLabel("Name"); lAge = new JLabel(""); lBirth = new JLabel(""); lDeath = new JLabel(""); lEyeColor = new JLabel(""); lHairColor = new JLabel(""); lHeight = new JLabel(""); lInt = new JLabel(""); lFriends = new JLabel(""); relations = new JList<Person>(); relations.setCellRenderer(new PersonRelationListRenderer()); relations.addMouseListener(new PersonClickBehavior(this)); father = new JList<Person>(); father.setCellRenderer(new PersonListRenderer()); father.addMouseListener(new PersonClickBehavior(this)); // father.setMaximumSize(new Dimension(Integer.MAX_VALUE, father.getPreferredSize().height)); mother = new JList<Person>(); mother.setCellRenderer(new PersonListRenderer()); mother.addMouseListener(new PersonClickBehavior(this)); // mother.setMaximumSize(new Dimension(Integer.MAX_VALUE, mother.getPreferredSize().height)); eventList = new JList<String>(); eventList.addListSelectionListener(this); eventText = new JTextArea("Blank Text"); leftPanel.add(search); leftPanel.add(pane); JPanel personPanel = new JPanel(); personPanel.setLayout(new BoxLayout(personPanel, BoxLayout.PAGE_AXIS)); personPanel.add(personName); personPanel.add(lAge); personPanel.add(lBirth); personPanel.add(lDeath); personPanel.add(lEyeColor); personPanel.add(lHairColor); personPanel.add(lHeight); personPanel.add(lInt); personPanel.add(lFriends); personPanel.add(relations); JPanel eventPanel = new JPanel(); eventPanel.setLayout(new BoxLayout(eventPanel, BoxLayout.PAGE_AXIS)); JPanel familyPanel = new JPanel(); familyPanel.setLayout(new BoxLayout(familyPanel, BoxLayout.PAGE_AXIS)); JScrollPane familyScrollPane = new JScrollPane(); familyScrollPane.getViewport().add(relations); JPanel parentPanel = new JPanel(); JPanel fatherPanel = new JPanel(); JLabel fatherLabel = new JLabel("Father"); fatherPanel.add(fatherLabel); fatherPanel.add(father); JPanel motherPanel = new JPanel(); JLabel motherLabel = new JLabel("Mother"); motherPanel.add(motherLabel); motherPanel.add(mother); parentPanel.add(fatherPanel); parentPanel.add(motherPanel); familyPanel.add(parentPanel); familyPanel.add(familyScrollPane); JScrollPane eventScrollPane = new JScrollPane(); eventScrollPane.getViewport().add(eventList); eventPanel.add(eventScrollPane); // eventPanel.add(eventText); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("Person", personPanel); tabbedPane.addTab("Family", familyPanel); tabbedPane.addTab("Events", eventPanel); panel.add(tabbedPane); // panel.add(list); }
@SuppressWarnings("unchecked") private void showList() { LinkedList<String> ll = new LinkedList<String>(); LinkedList<String> ll2 = null; inJarTree = false; String s = listHead; if (s.toLowerCase().endsWith("package.json")) { ll2 = buildListFromJSON(s); // fullNodeName = s; // showFileNames(); } else { if (-1 == s.indexOf("!")) { // if fullNodeName is NOT a // file // within a jar file ... if (listHead == null) return; File f = new File(listHead); if (!f.exists() || !f.isDirectory()) return; String[] fl = f.list(); ll2 = new LinkedList<String>(); if (fl == null || fl.length == 0) { ll2.add("(empty folder)"); } else { for (int j = 0; j < fl.length; j++) { String fn = s + File.separator + fl[j]; File fx = new File(fn); if (!fx.exists()) continue; if (fx.isDirectory()) ll.add(fl[j]); // directories go into ll first } for (int j = 0; j < fl.length; j++) { String fn = s + File.separator + fl[j]; File fx = new File(fn); if (!fx.exists()) continue; if (!fx.isDirectory() && (fCParms.filter.accept(fx) || driver.allFiles)) ll2.add(fl[j]); // non-directories go into ll2, // which is // then sorted, and then added // to ll } } } else { inJarTree = true; if (currentNode == null) return; Enumeration<DefaultMutableTreeNode> e = currentNode.children(); ll = new LinkedList<String>(); ll2 = new LinkedList<String>(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (e.nextElement()); Object obj = node.getUserObject(); ll2.add((String) obj); } } } if (ll2 == null) return; Collections.sort(ll2, comp); for (String li : ll2) { ll.add(li); } if (!inJarTree) { if (listHead.equals(listShowingJarFile)) { s = driver.javaFBPJarFile; // int j = s.lastIndexOf(File.separator); // s = s.substring(j + 1); ll.add(s); } } Object[] oa = ll.toArray(); nodeNames = new String[oa.length]; for (int j = 0; j < oa.length; j++) { nodeNames[j] = (String) oa[j]; } list = new JList<String>(nodeNames); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addKeyListener(this); list.addMouseListener(this); list.addListSelectionListener(this); list.setFocusTraversalKeysEnabled(false); order.remove(3); order.add(3, list); list.setFixedCellHeight(driver.fontg.getSize() + 2); list.setCellRenderer(renderer); list.setEnabled(true); if (!saveAs) list.addAncestorListener(new RequestFocusListener()); if (listView != null) panel.remove(listView); listView = new JScrollPane(list); panel.add(listView, BorderLayout.CENTER); selComp = list; list.setSelectedIndex(0); list.setFocusable(true); list.setVisible(true); // list.requestFocusInWindow(); paintList(); frame.pack(); listView.repaint(); dialog.repaint(); panel.validate(); panel.repaint(); frame.repaint(); }