@Override public void valueChanged(TreeSelectionEvent e) { if (LOG.isLoggable(Level.FINER)) { LOG.finer("TreeSelectionEvent: " + e.toString()); } // Stop editing the table, if editing is currently in progress if (groupTable.getCellEditor() != null) { groupTable.getCellEditor().stopCellEditing(); } InitTableModel tableModel = groupTable.getActorTableModel(); if (groupTree.getLastSelectedPathComponent() != null) { if (LOG.isLoggable(Level.FINER)) { LOG.finer("Current Selection: " + groupTree.getLastSelectedPathComponent().toString()); } GroupTreeNode node = (GroupTreeNode) groupTree.getLastSelectedPathComponent(); if (node.isGroup()) { // If current selection is a group, display the actors tableModel.setActorList(node.getActorList()); groupTable.setVisible(true); } else { // Otherwise don't show any actors groupTable.setVisible(false); tableModel.setActorList(null); } } else { if (LOG.isLoggable(Level.FINER)) { LOG.finer("Current Selection: null"); } groupTable.setVisible(false); tableModel.setActorList(null); } }
/** * Create a new group file. Will discard all unsaved changes WITHOUT PROMPTING! use * querySaveChanges() if you want to query the user to save changes. */ public void newGroupFile() { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating new group list"); } groupTree.setNewModel(); saveAsFile = null; groupTree.setClean(); groupTable.getActorTableModel().setClean(); super.setTitle("Groups Manager"); }
/** * Import a GCA4 character file * * @param file - the file to load from. Open File dialog used if file is null. * @return whether the load was completed successfully. */ public boolean importGCA4File(File file) { if (file == null) { if (LOG.isLoggable(Level.WARNING)) { LOG.warning("Given null file!"); } return false; } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Opening file: " + file.getName()); } Actor importedActor; try { importedActor = GCAImporter.importActor(file); } catch (FileNotFoundException e) { if (LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, e.getMessage(), e); } return false; } // Check if there is no valid selected group currently if (groupTable.getActorTableModel().getRowCount() == 0) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating new group to hold imported actor!"); } GroupTreeNode newGroup = groupTree.addNode("GCA4 Import", true); TreePath groupPath = new TreePath(newGroup.getPath()); groupTree.getSelectionModel().setSelectionPath(groupPath); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Adding imported actor to currently selected group"); } groupTable .getActorTableModel() .addActor(importedActor, groupTable.getActorTableModel().getRowCount() - 1); return true; }
/** * Load the group from a file * * @param file - the file to load from. Open File dialog used if file is null. * @return whether the load was completed successfully. */ public boolean loadGroupFile(File file) { if (file == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Opening file: Displaying file chooser"); } int retVal = groupFileChooser.showOpenDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) { file = groupFileChooser.getSelectedFile(); } else { return false; } } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Opening file: " + file.getName()); } ActorGroupFile.openActorGroupTree(groupTree, file); saveAsFile = file; groupTree.setClean(); groupTable.getActorTableModel().setClean(); super.setTitle("Groups Manager - " + saveAsFile.getName()); return true; }
/** * Save the group list to a file. * * @param file - the file to save as. Save As dialog used if file is null. * @return whether the save was completed successfully. */ public boolean saveGroupFile(File file) { if (file == null) { // Pick file int retVal = groupFileChooser.showSaveDialog(this); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Displaying file chooser"); } if (retVal == JFileChooser.APPROVE_OPTION) { file = groupFileChooser.getSelectedFile(); if (!file.toString().contains(".")) { file = new File(file.toString() + ".igroup"); } if (file.exists()) { int response = JOptionPane.showConfirmDialog( null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) return false; } } else { return false; } } // save group list if (LOG.isLoggable(Level.FINE)) { LOG.fine("Saving group list as file: " + file.getName()); } ActorGroupFile.saveActorGroupTree(groupTree, file); groupTree.setClean(); groupTable.getActorTableModel().setClean(); super.setTitle("Groups Manager - " + file.getName()); saveAsFile = file; return true; }
public GroupManager(Properties propertyBag) { super("Groups Manager"); this.propertyBag = propertyBag; setDefaultProperties(); // Set some UI options: UIManager.put( "Tree.leafIcon", new ImageIcon(GITApp.class.getResource("/resources/images/bullet_black.png"))); UIManager.put( "Tree.closedIcon", new ImageIcon(GITApp.class.getResource("/resources/images/folder.png"))); UIManager.put( "Tree.openIcon", new ImageIcon(GITApp.class.getResource("/resources/images/folder.png"))); // Create core components gameMaster = new GameMaster(); actorDetailsPanel = new ActorDetailsPanel_v2(false); groupTable = new InitTable(gameMaster, false, propertyBag); groupTable.getActorTableModel().setActorList(null); groupTree = new GroupTree(groupTable); searchSupport = new SearchSupport(getRootPane(), groupTree, groupTable); // Initialize GameMaster gameMaster.initTable = groupTable; gameMaster.detailsPanel = actorDetailsPanel; groupTable.getActorTableModel().addUndoableEditListener(gameMaster); groupTree.addUndoableEditListener(gameMaster); // Create and set up the window. setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); // The file chooser groupFileChooser = new JFileChooser(); groupFileChooser.setCurrentDirectory( new File(propertyBag.getProperty("Manager.groupFileChooser.defaultLocation"))); GroupFilter groupFilter = new GroupFilter(); groupFileChooser.addChoosableFileFilter(groupFilter); groupFileChooser.setFileFilter(groupFilter); gcaFileChooser = new JFileChooser(); gcaFileChooser.setCurrentDirectory( new File(propertyBag.getProperty("Manager.gcaFileChooser.defaultLocation"))); GCAFilter gcaFilter = new GCAFilter(); gcaFileChooser.addChoosableFileFilter(gcaFilter); gcaFileChooser.setFileFilter(gcaFilter); gcaFileChooser.setMultiSelectionEnabled(true); // The menu bar jMenuBar = new JMenuBar(); jMenu = new JMenu("File"); jMenu.setMnemonic(KeyEvent.VK_F); JMenuItem menuItem = new JMenuItem("New", KeyEvent.VK_N); // menuItem.setEnabled(false); menuItem.addActionListener(this); jMenu.add(menuItem); menuItem = new JMenuItem("Open", KeyEvent.VK_O); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.addActionListener(this); jMenu.add(menuItem); menuItem = new JMenuItem("Save As...", KeyEvent.VK_A); menuItem .getAccessibleContext() .setAccessibleDescription("Select the file to save the group list to"); menuItem.addActionListener(this); jMenu.add(menuItem); menuItem = new JMenuItem("Save", KeyEvent.VK_S); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Save the group list"); menuItem.addActionListener(this); jMenu.add(menuItem); jMenu.addSeparator(); menuItem = new JMenuItem("Import GCA4...", KeyEvent.VK_I); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Import a GCA4 character file"); menuItem.addActionListener(this); jMenu.add(menuItem); jMenuBar.add(jMenu); jMenu = new JMenu("Edit"); jMenu.setMnemonic(KeyEvent.VK_E); menuItem = new JMenuItem(gameMaster.actionUndo); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); jMenu.add(menuItem); menuItem = new JMenuItem(gameMaster.actionRedo); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK)); jMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CutAction()); menuItem.setText("Cut"); menuItem.setMnemonic(KeyEvent.VK_T); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); menuItem.setIcon(new ImageIcon(GITApp.class.getResource("/resources/images/cut.png"), "Cut")); jMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CopyAction()); menuItem.setText("Copy"); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); menuItem.setIcon( new ImageIcon(GITApp.class.getResource("/resources/images/page_copy.png"), "Copy")); jMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.PasteAction()); menuItem.setText("Paste"); menuItem.setMnemonic(KeyEvent.VK_V); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); menuItem.setIcon( new ImageIcon(GITApp.class.getResource("/resources/images/paste_plain.png"), "Paste")); jMenu.add(menuItem); jMenuBar.add(jMenu); jMenu = new JMenu("View"); jMenu.setMnemonic(KeyEvent.VK_V); menuItem = new JCheckBoxMenuItem("Auto-fit columns"); menuItem.setMnemonic(KeyEvent.VK_A); menuItem.setSelected(Boolean.valueOf(propertyBag.getProperty("Manager.groupTable.autoResize"))); menuItem .getAccessibleContext() .setAccessibleDescription("Table columns auto-fit automatically"); menuItem.addItemListener(this); jMenu.add(menuItem); menuItem = new JCheckBoxMenuItem("Actor Details"); // ((JCheckBoxMenuItem) menuItem).setSelected(true); menuItem.setSelected(Boolean.valueOf(propertyBag.getProperty("Manager.actorDetails.visible"))); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addItemListener(this); jMenu.add(menuItem); menuItem = new JMenuItem( new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { groupTable.showColumnCustomizer(); } }); menuItem.setText("Customize Columns"); menuItem.setMnemonic(KeyEvent.VK_C); jMenu.add(menuItem); jMenuBar.add(jMenu); setJMenuBar(jMenuBar); // The top tool bar (search) toolbar = searchSupport.getSearchToolBar(); toolbar.add(Box.createHorizontalGlue()); getContentPane().add(toolbar, BorderLayout.PAGE_START); groupTable.setVisible(false); groupTable.getSelectionModel().addListSelectionListener(this); groupTable.getActorTableModel().addFileChangeEventListener(new GroupFileChangeEventListener()); groupTable.getActorTableModel().addTableModelListener(new GroupInitTableModelListener()); groupTree.addTreeSelectionListener(this); groupTree.addFileChangeEventListener(new GroupFileChangeEventListener()); jScrollPaneTable = new JScrollPane(groupTable); jScrollPaneDetails = new JScrollPane(actorDetailsPanel); jScrollPaneDetails.setMinimumSize( new Dimension(actorDetailsPanel.getPreferredSize().width + 20, 0)); jScrollPaneTree = new JScrollPane(groupTree); jSplitPaneVertical = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jScrollPaneTree, jScrollPaneTable); jSplitPaneHorizontal = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jSplitPaneVertical, jScrollPaneDetails); jSplitPaneVertical.setDividerLocation( Integer.valueOf(propertyBag.getProperty("Manager.splitVertical.dividerLocation"))); jSplitPaneVertical.setContinuousLayout(true); jSplitPaneVertical.setResizeWeight(.95); jSplitPaneHorizontal.setDividerLocation( Integer.valueOf(propertyBag.getProperty("Manager.splitHorizontal.dividerLocation"))); jSplitPaneHorizontal.setContinuousLayout(true); jSplitPaneHorizontal.setResizeWeight(.95); layoutActorPanel(); setLocation( Integer.valueOf(propertyBag.getProperty("Manager.location.x")), Integer.valueOf(propertyBag.getProperty("Manager.location.y"))); setSize( Integer.valueOf(propertyBag.getProperty("Manager.size.width")), Integer.valueOf(propertyBag.getProperty("Manager.size.height"))); }