Search in sources :

Example 91 with JScrollPane

use of javax.swing.JScrollPane in project pcgen by PCGen.

the class StatTableModel method install.

public void install() {
    table.setModel(this);
    table.setDefaultRenderer(Object.class, renderer);
    TableColumn abilityColumn = table.getColumn(ABILITY_COLUMN_ID);
    int columnIndex = abilityColumn.getModelIndex();
    int maxWidth = 0;
    for (StatFacade aStat : stats) {
        Component cell = renderer.getTableCellRendererComponent(table, aStat, false, false, -1, columnIndex);
        maxWidth = Math.max(maxWidth, cell.getPreferredSize().width);
    }
    //we add some extra spacing to prevent ellipses from showing
    abilityColumn.setPreferredWidth(maxWidth + 4);
    TableColumn column = table.getColumn(EDITABLE_COLUMN_ID);
    column.setCellRenderer(new TableCellUtilities.SpinnerRenderer());
    column.setCellEditor(editor);
    Dimension size = table.getPreferredSize();
    size.width = table.getTableHeader().getPreferredSize().width;
    JScrollPane scrollPane = (JScrollPane) table.getParent().getParent();
    //we want to add room for the vertical scroll bar so it doesn't
    //overlap with the table when it shows
    int vbarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width;
    size.width += vbarWidth;
    table.setPreferredScrollableViewportSize(size);
    //because of the extra viewport size in the table it will
    //always look a bit off center, adding a row header to
    //the scroll pane fixes this
    scrollPane.setRowHeaderView(Box.createHorizontalStrut(vbarWidth));
    for (StatFacade aStat : stats) {
        character.getScoreBaseRef(aStat).addReferenceListener(this);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) StatFacade(pcgen.facade.core.StatFacade) Dimension(java.awt.Dimension) JComponent(javax.swing.JComponent) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) TableCellUtilities(pcgen.gui2.util.table.TableCellUtilities)

Example 92 with JScrollPane

use of javax.swing.JScrollPane in project pcgen by PCGen.

the class JDynamicTable method unconfigureEnclosingScrollPane.

@Override
protected void unconfigureEnclosingScrollPane() {
    super.unconfigureEnclosingScrollPane();
    Container p = getParent();
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            // Make certain we are the viewPort's view and not, for
            // example, the rowHeaderView of the scrollPane -
            // an implementor of fixed columns might do this.
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }
            scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, null);
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) Container(java.awt.Container) JViewport(javax.swing.JViewport)

Example 93 with JScrollPane

use of javax.swing.JScrollPane in project pcgen by PCGen.

the class PreferencesPluginsPanel method getCenter.

@Override
protected JComponent getCenter() {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode characterNode;
    DefaultMutableTreeNode pcGenNode;
    DefaultMutableTreeNode appearanceNode;
    DefaultMutableTreeNode gameModeNode;
    panelList = new ArrayList<>(15);
    // Build the settings panel
    settingsPanel = new JPanel();
    settingsPanel.setLayout(new CardLayout());
    settingsPanel.setPreferredSize(new Dimension(780, 420));
    // Build the selection tree
    characterNode = new DefaultMutableTreeNode(in_character);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_charTip")), in_character);
    characterStatsPanel = new CharacterStatsPanel(this);
    addPanelToTree(characterNode, characterStatsPanel);
    hitPointsPanel = new HitPointsPanel();
    addPanelToTree(characterNode, hitPointsPanel);
    houseRulesPanel = new HouseRulesPanel();
    addPanelToTree(characterNode, houseRulesPanel);
    monsterPanel = new MonsterPanel();
    addPanelToTree(characterNode, monsterPanel);
    defaultsPanel = new DefaultsPanel();
    addPanelToTree(characterNode, defaultsPanel);
    rootNode.add(characterNode);
    appearanceNode = new DefaultMutableTreeNode(in_appearance);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_appearanceTip")), in_appearance);
    colorsPanel = new ColorsPanel();
    addPanelToTree(appearanceNode, colorsPanel);
    displayOptionsPanel = new DisplayOptionsPanel();
    addPanelToTree(appearanceNode, displayOptionsPanel);
    levelUpPanel = new LevelUpPanel();
    addPanelToTree(appearanceNode, levelUpPanel);
    lookAndFeelPanel = new LookAndFeelPanel(this);
    addPanelToTree(appearanceNode, lookAndFeelPanel);
    //		tabsPanel = new TabsPanel();
    //		addPanelToTree(appearanceNode, tabsPanel);
    rootNode.add(appearanceNode);
    pcGenNode = new DefaultMutableTreeNode(Constants.APPLICATION_NAME);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_pcgenTip")), Constants.APPLICATION_NAME);
    equipmentPanel = new EquipmentPanel();
    addPanelToTree(pcGenNode, equipmentPanel);
    languagePanel = new LanguagePanel();
    addPanelToTree(pcGenNode, languagePanel);
    locationPanel = new LocationPanel();
    addPanelToTree(pcGenNode, locationPanel);
    inputPanel = new InputPanel();
    addPanelToTree(pcGenNode, inputPanel);
    outputPanel = new OutputPanel();
    addPanelToTree(pcGenNode, outputPanel);
    sourcesPanel = new SourcesPanel();
    addPanelToTree(pcGenNode, sourcesPanel);
    rootNode.add(pcGenNode);
    String in_gamemode = LanguageBundle.getString("in_mnuSettingsCampaign");
    gameModeNode = new DefaultMutableTreeNode(in_gamemode);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_mnuSettingsCampaignTip")), in_gamemode);
    copySettingsPanel = new CopySettingsPanel();
    addPanelToTree(gameModeNode, copySettingsPanel);
    rootNode.add(gameModeNode);
    DefaultMutableTreeNode pluginNode = new DefaultMutableTreeNode(//$NON-NLS-1$
    LanguageBundle.getString("in_Prefs_plugins"));
    addPluginPanes(rootNode, pluginNode);
    settingsModel = new DefaultTreeModel(rootNode);
    settingsTree = new JTree(settingsModel);
    settingsTree.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
    settingsTree.setRootVisible(false);
    settingsTree.setShowsRootHandles(true);
    settingsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    settingsScroll = new JScrollPane(settingsTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // Turn off the icons
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    settingsTree.setCellRenderer(renderer);
    // Expand all of the branch nodes
    settingsTree.expandPath(new TreePath(characterNode.getPath()));
    settingsTree.expandPath(new TreePath(pcGenNode.getPath()));
    settingsTree.expandPath(new TreePath(appearanceNode.getPath()));
    settingsTree.expandPath(new TreePath(gameModeNode.getPath()));
    settingsTree.expandPath(new TreePath(pluginNode.getPath()));
    // Add the listener which switches panels when a node of the tree is selected
    settingsTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) settingsTree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            CardLayout cl = (CardLayout) (settingsPanel.getLayout());
            cl.show(settingsPanel, String.valueOf(node));
        }
    });
    // Build the split pane
    splitPane = new FlippingSplitPane(JSplitPane.HORIZONTAL_SPLIT, settingsScroll, settingsPanel, "Prefs");
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerSize(10);
    return splitPane;
}
Also used : JPanel(javax.swing.JPanel) LocationPanel(pcgen.gui2.prefs.LocationPanel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SourcesPanel(pcgen.gui2.prefs.SourcesPanel) OutputPanel(pcgen.gui2.prefs.OutputPanel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) HitPointsPanel(pcgen.gui2.prefs.HitPointsPanel) CopySettingsPanel(pcgen.gui2.prefs.CopySettingsPanel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) HouseRulesPanel(pcgen.gui2.prefs.HouseRulesPanel) DisplayOptionsPanel(pcgen.gui2.prefs.DisplayOptionsPanel) LevelUpPanel(pcgen.gui2.prefs.LevelUpPanel) ColorsPanel(pcgen.gui2.prefs.ColorsPanel) LanguagePanel(pcgen.gui2.prefs.LanguagePanel) EquipmentPanel(pcgen.gui2.prefs.EquipmentPanel) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) CharacterStatsPanel(pcgen.gui2.prefs.CharacterStatsPanel) InputPanel(pcgen.gui2.prefs.InputPanel) Dimension(java.awt.Dimension) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) JTree(javax.swing.JTree) DefaultsPanel(pcgen.gui2.prefs.DefaultsPanel) TreePath(javax.swing.tree.TreePath) MonsterPanel(pcgen.gui2.prefs.MonsterPanel) LookAndFeelPanel(pcgen.gui2.prefs.LookAndFeelPanel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 94 with JScrollPane

use of javax.swing.JScrollPane in project pcgen by PCGen.

the class PreferencesPluginsPanel method initComponents.

private void initComponents() {
    jScrollPane1 = new JScrollPane();
    mainPanel = new JPanel();
    setLayout(new BorderLayout());
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    for (String key : pluginMap.keySet()) {
        mainPanel.add(pluginMap.get(key));
    }
    jScrollPane1.setViewportView(mainPanel);
    add(jScrollPane1, BorderLayout.CENTER);
    //$NON-NLS-1$
    add(new JLabel(LanguageBundle.getString("in_Prefs_restartInfo")), BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel)

Example 95 with JScrollPane

use of javax.swing.JScrollPane in project pcgen by PCGen.

the class CharacterHPDialog method initComponents.

private void initComponents() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    JTable table = new JTable(tableModel) {

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            if (column == 5) {
                //TODO: the max roll should be calculated in a different manner
                String hd = levels.getClassTaken(levels.getElementAt(row)).getHD();
                int max = NumberUtils.toInt(hd);
                return new IntegerEditor(1, max);
            } else {
                return super.getCellEditor(row, column);
            }
        }
    };
    table.setDefaultRenderer(JButton.class, new Renderer());
    table.setDefaultEditor(JButton.class, new Editor());
    table.setCellSelectionEnabled(false);
    table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height);
    JTableHeader header = table.getTableHeader();
    header.setReorderingAllowed(false);
    JScrollPane scrollPane = new JScrollPane(table);
    pane.add(scrollPane, BorderLayout.CENTER);
    Box box = Box.createHorizontalBox();
    box.add(new JLabel("Total Hp:"));
    box.add(Box.createHorizontalStrut(3));
    final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() {

        @Override
        public void referenceChanged(ReferenceEvent<Integer> e) {
            totalHp.setText(e.getNewReference().toString());
        }
    };
    ReferenceFacade<Integer> hpRef = character.getTotalHPRef();
    totalHp.setText(hpRef.get().toString());
    hpRef.addReferenceListener(hpListener);
    box.add(totalHp);
    box.add(Box.createHorizontalStrut(5));
    JButton button = new JButton("Reroll All");
    button.setActionCommand("Reroll");
    button.addActionListener(this);
    box.add(button);
    box.add(Box.createHorizontalGlue());
    button = new JButton("Close");
    button.setActionCommand("Close");
    button.addActionListener(this);
    box.add(button);
    pane.add(box, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            //Make sure to remove the listeners so that the garbage collector can
            //dispose of this dialog and prevent a memory leak
            levels.removeHitPointListener(tableModel);
            character.getTotalHPRef().removeReferenceListener(hpListener);
        }
    });
    Utility.installEscapeCloseOperation(this);
}
Also used : JScrollPane(javax.swing.JScrollPane) IntegerEditor(pcgen.gui2.util.table.IntegerEditor) JButton(javax.swing.JButton) JTableHeader(javax.swing.table.JTableHeader) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) Box(javax.swing.Box) ReferenceListener(pcgen.facade.util.event.ReferenceListener) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) ReferenceEvent(pcgen.facade.util.event.ReferenceEvent) JTable(javax.swing.JTable) WindowEvent(java.awt.event.WindowEvent) TableCellRenderer(javax.swing.table.TableCellRenderer) TableCellEditor(javax.swing.table.TableCellEditor) AbstractCellEditor(javax.swing.AbstractCellEditor) IntegerEditor(pcgen.gui2.util.table.IntegerEditor)

Aggregations

JScrollPane (javax.swing.JScrollPane)832 JPanel (javax.swing.JPanel)431 Dimension (java.awt.Dimension)271 JLabel (javax.swing.JLabel)269 BorderLayout (java.awt.BorderLayout)260 JButton (javax.swing.JButton)191 GridBagLayout (java.awt.GridBagLayout)149 JTable (javax.swing.JTable)148 BoxLayout (javax.swing.BoxLayout)140 Insets (java.awt.Insets)122 GridBagConstraints (java.awt.GridBagConstraints)121 ActionEvent (java.awt.event.ActionEvent)120 JTextArea (javax.swing.JTextArea)110 ActionListener (java.awt.event.ActionListener)103 FlowLayout (java.awt.FlowLayout)96 JTextField (javax.swing.JTextField)70 FormLayout (com.jgoodies.forms.layout.FormLayout)60 Container (java.awt.Container)55 JSplitPane (javax.swing.JSplitPane)55 MouseEvent (java.awt.event.MouseEvent)52