private Component refreshViewRegion(TreeNode node) { Component guiComponent = node.getGuiComponent(); if (node.isLeaf()) { if (guiComponent == null) { guiComponent = new JTabbedPane(); node.setGuiComponent(guiComponent); } JTabbedPane tabs = (JTabbedPane) guiComponent; for (LeafNodeComponent compNode : node.getComponents()) { boolean exists = false; for (Component comp : tabs.getComponents()) { if (comp == compNode.getComponent()) { exists = true; } } if (!exists) { tabs.addTab(compNode.getLabel(), compNode.getComponent()); } } for (Component comp : tabs.getComponents()) { boolean removed = true; for (LeafNodeComponent compNode : node.getComponents()) { if (comp == compNode.getComponent()) { removed = false; } } if (removed) { tabs.remove(comp); } } return guiComponent; } else { JSplitPane split = null; if (guiComponent == null) { split = new JSplitPane(); node.setGuiComponent(split); } else { split = (JSplitPane) guiComponent; } split.setOrientation( node.isVertical() ? JSplitPane.VERTICAL_SPLIT : JSplitPane.HORIZONTAL_SPLIT); Component firstGuiComponent = refreshViewRegion(node.getFirst()); if (firstGuiComponent != null /* && firstGuiComponent instanceof JTabbedPane*/) { split.setTopComponent(firstGuiComponent); } Component secondGuiComponent = refreshViewRegion(node.getSecond()); if (secondGuiComponent != null /* && secondGuiComponent instanceof JTabbedPane*/) { split.setBottomComponent(secondGuiComponent); } return split; } }
private static void check() { try { JViewport vp = null; for (Component c : tabbedPane.getComponents()) { if (c instanceof JViewport) { vp = (JViewport) c; break; } } JComponent v = (JComponent) vp.getView(); Rectangle vr = vp.getViewRect(); Dimension vs = v.getSize(); // The tab view must be scrolled to the end so that the last tab is visible if (vs.width != (vr.x + vr.width)) { throw new RuntimeException( "tabScroller.tabPanel view is positioned incorrectly: " + vs.width + " vs " + (vr.x + vr.width)); } } catch (Exception e) { exception = e; } }
PanelThreadMonitor getPanelThreadMonitor(String strThreadID) { Component[] cmp = pnlThread.getComponents(); for (int iMonitorIndex = 0; iMonitorIndex < cmp.length; iMonitorIndex++) { if (cmp[iMonitorIndex] instanceof PanelThreadMonitor) { PanelThreadMonitor mntTemp = ((PanelThreadMonitor) cmp[iMonitorIndex]); if (mntTemp.mstrThreadID.equals(strThreadID)) return mntTemp; } } return null; }
/** * Returns all the opened graphs in the editor. * * @return List<PetriNetGraph> */ public List<PetriNetGraph> getOpenedGraphs() { List<PetriNetGraph> openedGraphs = new ArrayList<>(); for (Component graphComponent : tabs.getComponents()) { if (graphComponent instanceof GraphViewContainer) { openedGraphs.add(((GraphViewContainer) graphComponent).getGraph()); } } return openedGraphs; }
@Override public void remove(Component c) { if (tabCount == 0) throw new RuntimeException("Tried to remove from empty tabbedpanehiddenbar"); else if (tabCount == 1) { if (c == soleComponent) super.remove(c); } else if (tabCount == 2) { pane.remove(c); if (pane.getComponents().length == 1) { soleComponent = pane.getComponents()[0]; soleTitle = pane.getTitleAt(0); super.remove(pane); super.add(soleComponent); } } else { pane.remove(c); } tabCount--; revalidate(); repaint(); }
/** * Constructor to initialize the GUI. This should only be invoked from the Swing event thread. * Properties must be initialized first. In particular, {@link Survivor#currentColourScheme} must * be set. * * @param survivor The Survivor object associated with this object */ public RootPanel(final Survivor survivor) { this.backgroundColourableComponents = new HashSet<Component>(); this.complementaryAmenableForegroundColourableComponents = new HashSet<Component>(); this.colourSchemeButtons = new HashSet<AbstractButton>(); this.survivor = survivor; // Do nothing on close to allow close to be handles identically to File>Quit. this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); /* * This is added as an anonymous inner class to * prevent having to extend WindowAdapter or implement WindowListener. */ this.addWindowListener( new WindowAdapter() { /* (non-Javadoc) * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent) */ @Override public void windowClosing(WindowEvent e) { exit(); } }); this.setTitle(application.ProjectInfo.TITLE); this.setSize(size); this.setMinimumSize(size); this.setLayout(new BorderLayout()); /* * Attempts to set the Look and Feel to Nimbus. * Note that a modicum of backwards compatibility is present if Nimbus cannot be found. * It is ideal that it is available, since it severely reduces colour schemes. */ try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { this.nimbus = info.getClassName(); UIManager.setLookAndFeel(this.nimbus); break; } } } catch (Exception e) { } tabbedPane = new JTabbedPane(); ContestantManagementTab contestantManagementTab = new ContestantManagementTab(survivor); tabbedPane.addTab( ContestantManagementTab.TITLE, ContestantManagementTab.ICON, contestantManagementTab, ContestantManagementTab.TOOLTIP); tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_C); PlayerManagementTab playerManagementTab = new PlayerManagementTab(survivor); tabbedPane.addTab( PlayerManagementTab.TITLE, PlayerManagementTab.ICON, playerManagementTab, PlayerManagementTab.TOOLTIP); tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_P); tabbedPane.addTab( BonusQuestionTab.TITLE, BonusQuestionTab.ICON, new BonusQuestionTab(survivor), BonusQuestionTab.TOOLTIP); tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_B); tabbedPane.addTab( StandingsTab.TITLE, StandingsTab.ICON, new StandingsTab(), StandingsTab.TOOLTIP); tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, KeyEvent.VK_S); JButton startGame = new JButton(START_GAME); startGame.addActionListener(this); startGame.addActionListener(contestantManagementTab); startGame.addActionListener(playerManagementTab); startGame.setFont(Constants.BOLD_FONT); startGame.setMnemonic(KeyEvent.VK_G); colourSchemeButtons.add(startGame); tabbedPane.add(new JPanel(new GridLayout(1, 1))); this.startGameTabIndex = tabbedPane.getComponentCount() - 1; tabbedPane.setTabComponentAt(this.startGameTabIndex, startGame); tabbedPane.setEnabledAt(this.startGameTabIndex, false); backgroundColourableComponents.add(tabbedPane); for (Component c : tabbedPane.getComponents()) { backgroundColourableComponents.add(c); } this.add(tabbedPane); io.io.readProperties(); JMenuBar menuBar = new JMenuBar(); backgroundColourableComponents.add(menuBar); JMenu file = new JMenu("File"); file.setMnemonic(KeyEvent.VK_F); this.backgroundColourableComponents.add(file); this.complementaryAmenableForegroundColourableComponents.add(file); menuBar.add(file); JMenuItem menuItem = new JMenuItem(CLEAR_DATA, RESET_ICON); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.addActionListener(this); this.backgroundColourableComponents.add(menuItem); file.add(menuItem); file.addSeparator(); JLabel label = new JLabel("Colour Scheme"); file.add(label); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem rbMenuItemDefault = new JRadioButtonMenuItem(DEFAULT); rbMenuItemDefault.addActionListener(this); this.colourSchemeButtons.add(rbMenuItemDefault); this.backgroundColourableComponents.add(rbMenuItemDefault); group.add(rbMenuItemDefault); file.add(rbMenuItemDefault); JRadioButtonMenuItem rbMenuItemSunset = new JRadioButtonMenuItem(SUNSET); rbMenuItemSunset.addActionListener(this); this.colourSchemeButtons.add(rbMenuItemSunset); this.backgroundColourableComponents.add(rbMenuItemSunset); group.add(rbMenuItemSunset); file.add(rbMenuItemSunset); JRadioButtonMenuItem rbMenuItemDawn = new JRadioButtonMenuItem(DAWN); rbMenuItemDawn.addActionListener(this); this.colourSchemeButtons.add(rbMenuItemDawn); this.backgroundColourableComponents.add(rbMenuItemDawn); group.add(rbMenuItemDawn); file.add(rbMenuItemDawn); /* * Set both the colour scheme and the corresponding selection * of the radio button in the file menu. * This data is read from the configuration file, if available. */ setCurrentColourSchemeSelected(); setColourScheme(survivor.getCurrentColourScheme()); menuItem = new JMenuItem(QUIT, QUIT_ICON); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); this.backgroundColourableComponents.add(menuItem); file.add(menuItem); file.addSeparator(); JMenu help = new JMenu("Help"); help.setMnemonic(KeyEvent.VK_H); this.backgroundColourableComponents.add(help); this.complementaryAmenableForegroundColourableComponents.add(help); menuBar.add(help); menuItem = new JMenuItem(ABOUT, ABOUT_ICON); menuItem.setMnemonic(KeyEvent.VK_A); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); menuItem.addActionListener(this); this.backgroundColourableComponents.add(menuItem); help.add(menuItem); help.addSeparator(); this.add(menuBar, BorderLayout.PAGE_START); this.setVisible(true); }