List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:org.piraso.ui.base.RequestTreeTopComponent.java
public RequestTreeTopComponent() { setName(Bundle.CTL_RequestTreeTopComponent()); setToolTipText(Bundle.HINT_RequestTreeTopComponent()); initComponents();//from www . j a v a 2 s .c o m InstanceContent content = new InstanceContent(); associateLookup(new AbstractLookup(content)); this.entryContent = new SingleClassInstanceContent<Entry>(content); jTree.setFont(FontProviderManager.INSTANCE.getEditorDefaultFont()); jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jTree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int selRow = jTree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = jTree.getPathForLocation(e.getX(), e.getY()); if (selRow != -1 && selPath != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent(); Child child = null; if (Child.class.isInstance(node.getUserObject())) { child = (Child) node.getUserObject(); } if (child != null && e.getClickCount() == 1) { child.select(); } } } }); jTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (e.getPath() != null && e.getPath().getLastPathComponent() != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); if (node.getUserObject() != null && Child.class.isInstance(node.getUserObject())) { Child child = (Child) node.getUserObject(); child.showRequestView(); } } } }); }
From source file:org.sakaiproject.scorm.ui.player.components.ActivityTree.java
public TreeNode selectNode(String activityId) { if (activityId == null) return null; Model model = (Model) this.getModel(); DefaultTreeModel treeModel = (DefaultTreeModel) model.getObject(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); for (Enumeration<DefaultMutableTreeNode> e = root.breadthFirstEnumeration(); e.hasMoreElements();) { DefaultMutableTreeNode node = e.nextElement(); SeqActivity activity = (SeqActivity) node.getUserObject(); if (log.isDebugEnabled()) { log.debug("Activity: " + activity.getID()); log.debug("Title: " + activity.getTitle()); log.debug("Is Constrain Choice: " + activity.getConstrainChoice()); log.debug("Is Control Forward Only: " + activity.getControlForwardOnly()); log.debug("Is Control Mode Choice: " + activity.getControlModeChoice()); log.debug("Is Control Mode Choice Exit: " + activity.getControlModeChoiceExit()); log.debug("Is Control Mode Flow: " + activity.getControlModeFlow()); }/*w w w.ja v a2 s . c o m*/ String id = activity == null ? null : activity.getID(); if (id != null && id.equals(activityId)) { if (!getTreeState().isNodeSelected(node)) getTreeState().selectNode(node, true); return node; } } return null; }
From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java
/** * Get the TreePath to this Artifact clause given a String rule and clause * name/* w ww. ja v a 2 s.c o m*/ * * @param ruleName the rule name to find * @param clauseName the clause name to find * * @return */ private TreePath findTreePathByRuleAndArtifactClauseName(String ruleName, String clauseName) { @SuppressWarnings("unchecked") Enumeration<DefaultMutableTreeNode> enumeration = rootNode.preorderEnumeration(); boolean insideRule = false; while (enumeration.hasMoreElements()) { DefaultMutableTreeNode node = enumeration.nextElement(); Item item = (Item) node.getUserObject(); if (item.getItemType() == ItemType.RULE) { insideRule = node.toString().equalsIgnoreCase(ruleName); } if ((insideRule == true) && (item.getItemType() == ItemType.ARTIFACT_CLAUSE) && (item.getName().compareTo(clauseName) == 0)) { return new TreePath(node.getPath()); } } return null; }
From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java
private void lsAttributeListValueChanged(javax.swing.event.ListSelectionEvent evt) { if (evt.getValueIsAdjusting() == false) { // if this is the final iteration through the value changed handler if (lsAttributeList.getSelectedIndex() >= 0) { // and we have a selected entry bnDeleteAttribute.setEnabled(true); DefaultMutableTreeNode node = (DefaultMutableTreeNode) trRuleList.getLastSelectedPathComponent(); if (node == null) { // Nothing is selected return; }/*from w w w .j a v a 2 s .co m*/ Item ruleInfo = (Item) node.getUserObject(); if (ruleInfo.getItemType() == ItemType.RULE_SET) { return; } Object listItem = lsAttributeList.getSelectedValue(); if (listItem != null) { Rule rule = exportRuleSet.getRules().get(ruleInfo.getRuleName()); if (rule != null) { // find the attribute to select for (ArtifactCondition ac : rule.getArtifactConditions()) { if (ac.getTreeDisplayName().compareTo(listItem.toString()) == 0) { // set selected and expand it TreePath shortPath = findTreePathByRuleName(rule.getName()); TreePath treePath = findTreePathByRuleAndArtifactClauseName(rule.getName(), listItem.toString()); trRuleList.expandPath(shortPath); // Don't let treeSelectionListener respond trRuleList.removeTreeSelectionListener(treeSelectionListener); treeSelectionModel.setSelectionPath(treePath); populateArtifactEditor(ac); setDeleteAttributeButton(); trRuleList.addTreeSelectionListener(treeSelectionListener); localRule = makeRuleFromUserInput(); break; } } } } else { bnDeleteAttribute.setEnabled(false); } } } }
From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java
private void trRuleListValueChanged(javax.swing.event.TreeSelectionEvent evt) { int selectionCount = treeSelectionModel.getSelectionCount(); lsAttributeList.removeAll();/*from w w w.j a v a 2 s. c om*/ attributeListModel.removeAllElements(); if (selectionCount > 0) { if (hasRuleChanged()) { // and the rule has changed without saving if (JOptionPane.showConfirmDialog(this, NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.UnsavedChangesLost"), NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.ChangesWillBeLost"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.CANCEL_OPTION) { // they were not quite ready to navigate away yet, so clear the selection trRuleList.clearSelection(); return; } } DefaultMutableTreeNode node = (DefaultMutableTreeNode) trRuleList.getLastSelectedPathComponent(); if (node == null) { // Nothing is selected return; } Item nodeInfo = (Item) node.getUserObject(); bnDeleteRule.setEnabled(nodeInfo.getItemType() == ItemType.RULE); if (nodeInfo.getItemType() == ItemType.RULE_SET) { tbRuleName.setText(null); clearSizeCondition(); clearMIMECondition(); clearArtifactCondition(); localRule = makeRuleFromUserInput(); return; } String selectedRuleName = nodeInfo.getRuleName(); Rule rule = exportRuleSet.getRules().get(selectedRuleName); if (rule != null) { // Read values for this rule and display them in the UI tbRuleName.setText(rule.getName()); FileMIMETypeCondition fileMIMETypeCondition = rule.getFileMIMETypeCondition(); if (fileMIMETypeCondition != null) { // if there is a MIME type condition cbMimeType.setSelected(true); comboBoxMimeTypeComparison.setSelectedItem(fileMIMETypeCondition.getRelationalOp().getSymbol()); comboBoxMimeValue.setSelectedItem(fileMIMETypeCondition.getMIMEType()); } else { // Clear the selection clearMIMECondition(); } List<FileSizeCondition> fileSizeCondition = rule.getFileSizeConditions(); if (fileSizeCondition != null && !fileSizeCondition.isEmpty()) { // if there is a file size condition FileSizeCondition condition = fileSizeCondition.get(0); cbFileSize.setSelected(true); spFileSizeValue.setValue(condition.getSize()); comboBoxFileSizeUnits.setSelectedItem(condition.getUnit().toString()); comboBoxFileSizeComparison.setSelectedItem(condition.getRelationalOperator().getSymbol()); } else { // Clear the selection clearSizeCondition(); } ArtifactCondition artifactConditionToPopulateWith = null; List<ArtifactCondition> artifactConditions = rule.getArtifactConditions(); if (nodeInfo.getItemType() != ItemType.ARTIFACT_CLAUSE) { // if there are any attribute clauses, populate the first one, otherwise clear artifact editor if (artifactConditions.isEmpty()) { clearArtifactCondition(); } else { artifactConditionToPopulateWith = artifactConditions.get(0); } } else { // an artifact clause is selected. populate it. for (ArtifactCondition artifact : artifactConditions) { if (artifact.getTreeDisplayName().compareTo(nodeInfo.getName()) == 0) { artifactConditionToPopulateWith = artifact; break; } } } if (artifactConditionToPopulateWith != null) { for (ArtifactCondition artifact : artifactConditions) { attributeListModel.addElement(artifact.getTreeDisplayName()); } // Don't let listSelectionListener respond lsAttributeList.removeListSelectionListener(listSelectionListener); lsAttributeList.setSelectedValue(artifactConditionToPopulateWith.getTreeDisplayName(), true); populateArtifactEditor(artifactConditionToPopulateWith); setDeleteAttributeButton(); lsAttributeList.addListSelectionListener(listSelectionListener); } } localRule = makeRuleFromUserInput(); } else { bnDeleteRule.setEnabled(false); } }
From source file:org.sonar.scanner.protocol.viewer.ScannerReportViewerApp.java
/** * Initialize the contents of the frame. */// w w w . j a va 2 s . c o m private void initialize() { try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { // If Nimbus is not available, you can set the GUI to another look and feel. } frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); splitPane = new JSplitPane(); frame.getContentPane().add(splitPane, BorderLayout.CENTER); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setPreferredSize(new Dimension(500, 7)); splitPane.setRightComponent(tabbedPane); componentDetailsTab = new JScrollPane(); tabbedPane.addTab("Component details", null, componentDetailsTab, null); componentEditor = new JEditorPane(); componentDetailsTab.setViewportView(componentEditor); sourceTab = new JScrollPane(); tabbedPane.addTab("Source", null, sourceTab, null); sourceEditor = createSourceEditor(); sourceEditor.setEditable(false); sourceTab.setViewportView(sourceEditor); textLineNumber = createTextLineNumber(); sourceTab.setRowHeaderView(textLineNumber); highlightingTab = new JScrollPane(); tabbedPane.addTab("Highlighting", null, highlightingTab, null); highlightingEditor = new JEditorPane(); highlightingTab.setViewportView(highlightingEditor); symbolTab = new JScrollPane(); tabbedPane.addTab("Symbol references", null, symbolTab, null); symbolEditor = new JEditorPane(); symbolTab.setViewportView(symbolEditor); coverageTab = new JScrollPane(); tabbedPane.addTab("Coverage", null, coverageTab, null); coverageEditor = new JEditorPane(); coverageTab.setViewportView(coverageEditor); duplicationTab = new JScrollPane(); tabbedPane.addTab("Duplications", null, duplicationTab, null); duplicationEditor = new JEditorPane(); duplicationTab.setViewportView(duplicationEditor); testsTab = new JScrollPane(); tabbedPane.addTab("Tests", null, testsTab, null); testsEditor = new JEditorPane(); testsTab.setViewportView(testsEditor); issuesTab = new JScrollPane(); tabbedPane.addTab("Issues", null, issuesTab, null); issuesEditor = new JEditorPane(); issuesTab.setViewportView(issuesEditor); measuresTab = new JScrollPane(); tabbedPane.addTab("Measures", null, measuresTab, null); measuresEditor = new JEditorPane(); measuresTab.setViewportView(measuresEditor); scmTab = new JScrollPane(); tabbedPane.addTab("SCM", null, scmTab, null); scmEditor = new JEditorPane(); scmTab.setViewportView(scmEditor); activeRuleTab = new JScrollPane(); tabbedPane.addTab("ActiveRules", null, activeRuleTab, null); activeRuleEditor = new JEditorPane(); activeRuleTab.setViewportView(activeRuleEditor); treeScrollPane = new JScrollPane(); treeScrollPane.setPreferredSize(new Dimension(200, 400)); splitPane.setLeftComponent(treeScrollPane); componentTree = new JTree(); componentTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("empty") { { } })); treeScrollPane.setViewportView(componentTree); componentTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); componentTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) componentTree.getLastSelectedPathComponent(); if (node == null) { // Nothing is selected. return; } frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); updateDetails((Component) node.getUserObject()); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }); frame.pack(); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTree() { treeModel = new DefaultTreeModel(null); tree = new JTree(treeModel); tree.setCellRenderer(new ComponentTreeCellRenderer()); // popup menu tree.addMouseListener(new PopupListener() { @Override/*from w w w. j av a 2 s . co m*/ public void showPopup(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); DefaultMutableTreeNode node = (path == null) ? null : (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == null) return; // ensure we select the node... tree.setSelectionPath(path); // get the element Element element = (Element) node.getUserObject(); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this); popup.show(tree, e.getX(), e.getY()); } }); ToolTipManager.sharedInstance().setInitialDelay(0); tree.setToolTipText(""); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTree() { treeModel = new DefaultTreeModel(null); tree = new JTree(treeModel); tree.setCellRenderer(new ComponentTreeCellRenderer()); // popup menu tree.addMouseListener(new PopupListener() { @Override// www. j av a 2s. com public void showPopup(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); DefaultMutableTreeNode node = (path == null) ? null : (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == null) return; // ensure we select the node... tree.setSelectionPath(path); // get the element Element element = (Element) node.getUserObject(); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this); popup.show(tree, e.getX(), e.getY()); } }); ToolTipManager.sharedInstance().setInitialDelay(0); tree.setToolTipText(""); }
From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java
/** * Instantiates a new tv show panel./*w ww .j a v a 2 s . c o m*/ */ public TvShowPanel() { super(); treeModel = new TvShowTreeModel(tvShowList.getTvShows()); tvShowSeasonSelectionModel = new TvShowSeasonSelectionModel(); tvShowEpisodeSelectionModel = new TvShowEpisodeSelectionModel(); // build menu menu = new JMenu(BUNDLE.getString("tmm.tvshows")); //$NON-NLS-1$ JFrame mainFrame = MainWindow.getFrame(); JMenuBar menuBar = mainFrame.getJMenuBar(); menuBar.add(menu); setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("850px:grow"), FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), })); JSplitPane splitPane = new JSplitPane(); splitPane.setContinuousLayout(true); add(splitPane, "2, 2, fill, fill"); JPanel panelTvShowTree = new JPanel(); splitPane.setLeftComponent(panelTvShowTree); panelTvShowTree.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.UNRELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("3px:grow"), FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); textField = EnhancedTextField.createSearchTextField(); panelTvShowTree.add(textField, "4, 1, right, bottom"); textField.setColumns(12); textField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(final DocumentEvent e) { applyFilter(); } @Override public void removeUpdate(final DocumentEvent e) { applyFilter(); } @Override public void changedUpdate(final DocumentEvent e) { applyFilter(); } public void applyFilter() { TvShowTreeModel filteredModel = (TvShowTreeModel) tree.getModel(); if (StringUtils.isNotBlank(textField.getText())) { filteredModel.setFilter(SearchOptions.TEXT, textField.getText()); } else { filteredModel.removeFilter(SearchOptions.TEXT); } filteredModel.filter(tree); } }); final JToggleButton btnFilter = new JToggleButton(IconManager.FILTER); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ panelTvShowTree.add(btnFilter, "6, 1, default, bottom"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panelTvShowTree.add(scrollPane, "2, 3, 5, 1, fill, fill"); JToolBar toolBar = new JToolBar(); toolBar.setRollover(true); toolBar.setFloatable(false); toolBar.setOpaque(false); panelTvShowTree.add(toolBar, "2, 1"); // toolBar.add(actionUpdateDatasources); final JSplitButton buttonUpdateDatasource = new JSplitButton(IconManager.REFRESH); // temp fix for size of the button buttonUpdateDatasource.setText(" "); buttonUpdateDatasource.setHorizontalAlignment(JButton.LEFT); // buttonScrape.setMargin(new Insets(2, 2, 2, 24)); buttonUpdateDatasource.setSplitWidth(18); buttonUpdateDatasource.setToolTipText(BUNDLE.getString("update.datasource")); //$NON-NLS-1$ buttonUpdateDatasource.addSplitButtonActionListener(new SplitButtonActionListener() { public void buttonClicked(ActionEvent e) { actionUpdateDatasources.actionPerformed(e); } public void splitButtonClicked(ActionEvent e) { // build the popupmenu on the fly buttonUpdateDatasource.getPopupMenu().removeAll(); buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateDatasources2)); buttonUpdateDatasource.getPopupMenu().addSeparator(); for (String ds : TvShowModuleManager.SETTINGS.getTvShowDataSource()) { buttonUpdateDatasource.getPopupMenu() .add(new JMenuItem(new TvShowUpdateSingleDatasourceAction(ds))); } buttonUpdateDatasource.getPopupMenu().addSeparator(); buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateTvShow)); buttonUpdateDatasource.getPopupMenu().pack(); } }); JPopupMenu popup = new JPopupMenu("popup"); buttonUpdateDatasource.setPopupMenu(popup); toolBar.add(buttonUpdateDatasource); JSplitButton buttonScrape = new JSplitButton(IconManager.SEARCH); // temp fix for size of the button buttonScrape.setText(" "); buttonScrape.setHorizontalAlignment(JButton.LEFT); buttonScrape.setSplitWidth(18); buttonScrape.setToolTipText(BUNDLE.getString("tvshow.scrape.selected")); //$NON-NLS-1$ // register for listener buttonScrape.addSplitButtonActionListener(new SplitButtonActionListener() { @Override public void buttonClicked(ActionEvent e) { actionScrape.actionPerformed(e); } @Override public void splitButtonClicked(ActionEvent e) { } }); popup = new JPopupMenu("popup"); JMenuItem item = new JMenuItem(actionScrape2); popup.add(item); // item = new JMenuItem(actionScrapeUnscraped); // popup.add(item); item = new JMenuItem(actionScrapeSelected); popup.add(item); item = new JMenuItem(actionScrapeNewItems); popup.add(item); buttonScrape.setPopupMenu(popup); toolBar.add(buttonScrape); toolBar.add(actionEdit); JButton btnMediaInformation = new JButton(); btnMediaInformation.setAction(actionMediaInformation); toolBar.add(btnMediaInformation); // install drawing of full with tree = new ZebraJTree(treeModel) { private static final long serialVersionUID = 2422163883324014637L; @Override public void paintComponent(Graphics g) { width = this.getWidth(); super.paintComponent(g); } }; tvShowSelectionModel = new TvShowSelectionModel(tree); TreeUI ui = new TreeUI() { @Override protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { bounds.width = width - bounds.x; super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } }; tree.setUI(ui); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setCellRenderer(new TvShowTreeCellRenderer()); tree.setRowHeight(0); scrollPane.setViewportView(tree); JPanel panelHeader = new JPanel() { private static final long serialVersionUID = -6914183798172482157L; @Override public void paintComponent(Graphics g) { super.paintComponent(g); JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getColHeaderColors(), 0, 0, getWidth(), getHeight()); } }; scrollPane.setColumnHeaderView(panelHeader); panelHeader.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px") }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, })); JLabel lblTvShowsColumn = new JLabel(BUNDLE.getString("metatag.tvshow")); //$NON-NLS-1$ lblTvShowsColumn.setHorizontalAlignment(JLabel.CENTER); panelHeader.add(lblTvShowsColumn, "2, 1"); JLabel lblNfoColumn = new JLabel(""); lblNfoColumn.setHorizontalAlignment(JLabel.CENTER); lblNfoColumn.setIcon(IconManager.INFO); lblNfoColumn.setToolTipText(BUNDLE.getString("metatag.nfo"));//$NON-NLS-1$ panelHeader.add(lblNfoColumn, "4, 1"); JLabel lblImageColumn = new JLabel(""); lblImageColumn.setHorizontalAlignment(JLabel.CENTER); lblImageColumn.setIcon(IconManager.IMAGE); lblImageColumn.setToolTipText(BUNDLE.getString("metatag.images"));//$NON-NLS-1$ panelHeader.add(lblImageColumn, "5, 1"); JLabel lblSubtitleColumn = new JLabel(""); lblSubtitleColumn.setHorizontalAlignment(JLabel.CENTER); lblSubtitleColumn.setIcon(IconManager.SUBTITLE); lblSubtitleColumn.setToolTipText(BUNDLE.getString("metatag.subtitles"));//$NON-NLS-1$ panelHeader.add(lblSubtitleColumn, "6, 1"); JPanel panel = new JPanel(); panelTvShowTree.add(panel, "2, 5, 3, 1, fill, fill"); panel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); JLabel lblTvShowsT = new JLabel(BUNDLE.getString("metatag.tvshows") + ":"); //$NON-NLS-1$ panel.add(lblTvShowsT, "1, 2, fill, fill"); lblTvShows = new JLabel(""); panel.add(lblTvShows, "3, 2"); JLabel labelSlash = new JLabel("/"); panel.add(labelSlash, "5, 2"); JLabel lblEpisodesT = new JLabel(BUNDLE.getString("metatag.episodes") + ":"); //$NON-NLS-1$ panel.add(lblEpisodesT, "7, 2"); lblEpisodes = new JLabel(""); panel.add(lblEpisodes, "9, 2"); JLayeredPane layeredPaneRight = new JLayeredPane(); layeredPaneRight.setLayout( new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default"), ColumnSpec.decode("default:grow") }, new RowSpec[] { RowSpec.decode("default"), RowSpec.decode("default:grow") })); panelRight = new JPanel(); layeredPaneRight.add(panelRight, "1, 1, 2, 2, fill, fill"); layeredPaneRight.setLayer(panelRight, 0); // glass pane final TvShowExtendedSearchPanel panelExtendedSearch = new TvShowExtendedSearchPanel(treeModel, tree); panelExtendedSearch.setVisible(false); // panelMovieList.add(panelExtendedSearch, "2, 5, 2, 1, fill, fill"); btnFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (panelExtendedSearch.isVisible() == true) { panelExtendedSearch.setVisible(false); } else { panelExtendedSearch.setVisible(true); } } }); // add a propertychangelistener which reacts on setting a filter tree.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("filterChanged".equals(evt.getPropertyName())) { if (Boolean.TRUE.equals(evt.getNewValue())) { btnFilter.setIcon(IconManager.FILTER_ACTIVE); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options.active")); //$NON-NLS-1$ } else { btnFilter.setIcon(IconManager.FILTER); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ } } } }); layeredPaneRight.add(panelExtendedSearch, "1, 1, fill, fill"); layeredPaneRight.setLayer(panelExtendedSearch, 1); splitPane.setRightComponent(layeredPaneRight); panelRight.setLayout(new CardLayout(0, 0)); JPanel panelTvShow = new TvShowInformationPanel(tvShowSelectionModel); panelRight.add(panelTvShow, "tvShow"); JPanel panelTvShowSeason = new TvShowSeasonInformationPanel(tvShowSeasonSelectionModel); panelRight.add(panelTvShowSeason, "tvShowSeason"); JPanel panelTvShowEpisode = new TvShowEpisodeInformationPanel(tvShowEpisodeSelectionModel); panelRight.add(panelTvShowEpisode, "tvShowEpisode"); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { // click on a tv show if (node.getUserObject() instanceof TvShow) { TvShow tvShow = (TvShow) node.getUserObject(); tvShowSelectionModel.setSelectedTvShow(tvShow); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShow"); } // click on a season if (node.getUserObject() instanceof TvShowSeason) { TvShowSeason tvShowSeason = (TvShowSeason) node.getUserObject(); tvShowSeasonSelectionModel.setSelectedTvShowSeason(tvShowSeason); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShowSeason"); } // click on an episode if (node.getUserObject() instanceof TvShowEpisode) { TvShowEpisode tvShowEpisode = (TvShowEpisode) node.getUserObject(); tvShowEpisodeSelectionModel.setSelectedTvShowEpisode(tvShowEpisode); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShowEpisode"); } } else { // check if there is at least one tv show in the model TvShowRootTreeNode root = (TvShowRootTreeNode) tree.getModel().getRoot(); if (root.getChildCount() == 0) { // sets an inital show tvShowSelectionModel.setSelectedTvShow(null); } } } }); addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { menu.setVisible(false); super.componentHidden(e); } @Override public void componentShown(ComponentEvent e) { menu.setVisible(true); super.componentHidden(e); } }); // further initializations init(); initDataBindings(); // selecting first TV show at startup if (tvShowList.getTvShows() != null && tvShowList.getTvShows().size() > 0) { DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) tree.getModel() .getRoot()).getFirstChild(); tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) firstLeaf.getParent()).getPath())); tree.setSelectionPath(new TreePath(firstLeaf.getPath())); } }
From source file:org.tridas.io.gui.control.convert.ConvertController.java
@SuppressWarnings("unchecked") public void preview(MVCEvent argEvent) { ObjectEvent<DefaultMutableTreeNode> event = (ObjectEvent<DefaultMutableTreeNode>) argEvent; DefaultMutableTreeNode node = event.getValue(); if (node.getUserObject() == null) { return;/*from w ww . j ava2 s .c o m*/ } if (node.getUserObject() instanceof DendroWrapper) { DendroWrapper file = (DendroWrapper) node.getUserObject(); PreviewModel pmodel = new PreviewModel(); pmodel.setFilename(file.toString()); String[] strings = null; try { strings = file.file.saveToString(); if (strings != null) { String all = StringUtils.join(strings, "\n"); if (file.file instanceof TridasFile) { try { all = XMLFormatter.format(all); } catch (Exception e) { log.error("Error formatting xml text: " + all); } } pmodel.setFileString(all); } } catch (UnsupportedOperationException e) { pmodel.setFileString("This is a binary file so cannot be viewed as a conventional text file"); } catch (Exception e) { log.error("Could not convert file '" + file.toString() + "' to strings", e); pmodel.setFileString(I18n.getText("view.popup.preview.error")); } MainWindow window = TricycleModelLocator.getInstance().getMainWindow(); Dimension size = window.getSize(); PreviewWindow preview = new PreviewWindow(window, size.width - 40, size.height - 40, pmodel); preview.setVisible(true); preview.toFront(); } }