List of usage examples for com.jgoodies.forms.layout FormLayout FormLayout
public FormLayout(ColumnSpec[] colSpecs)
From source file:ca.sqlpower.wabit.swingui.chart.ChartPanel.java
License:Open Source License
/** * Subroutine of {@link #buildUI()}. Creates the form that appears to the * right of the JFreeChart preview./* w w w . j ava 2s .c o m*/ */ private Component buildChartPrefsPanel() { DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("70dlu, 3dlu, 90dlu"), logger.isDebugEnabled() ? new FormDebugPanel() : new JPanel()); builder.append("Legend Postion", legendPositionComboBox); builder.nextLine(); builder.append(yaxisNameLabel, yaxisNameField); builder.nextLine(); builder.append(xaxisNameLabel, xaxisNameField); builder.nextLine(); builder.append(xaxisLabelRotationLabel, xaxisLabelRotationSlider); builder.nextLine(); builder.append(this.xAxisAutoLabel, this.xAxisAuto); builder.append(this.xAxisMaxLabel, this.xAxisMax); builder.append(this.xAxisMinLabel, this.xAxisMin); builder.nextLine(); builder.append(this.yAxisAutoLabel, this.yAxisAuto); builder.append(this.yAxisMaxLabel, this.yAxisMax); builder.append(this.yAxisMinLabel, this.yAxisMin); builder.nextLine(); builder.append("Gratuitous Animation", gratuitousAnimationCheckbox); return builder.getPanel(); }
From source file:ca.sqlpower.wabit.swingui.enterprise.ServerInfoPanel.java
License:Open Source License
private JPanel buildUI(SPServerInfo si) { DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref, 4dlu, max(100dlu; pref):grow")); builder.append("Display Name", name = new JTextField(si.getName())); builder.append("Host", host = new JTextField(si.getServerAddress())); builder.append("Port", port = new JTextField(String.valueOf(si.getPort()))); builder.append("Path", path = new JTextField(si.getPath())); builder.append("Username", username = new JTextField(si.getUsername())); builder.append("Password", password = new JPasswordField(si.getPassword())); builder.append(testButton = new JButton("Test Connection")); this.testButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { lookupServerInfo(true);/*from www . jav a 2s .c o m*/ } }); builder.appendParagraphGapRow(); return builder.getPanel(); }
From source file:ca.sqlpower.wabit.swingui.NewWorkspaceScreen.java
License:Open Source License
private void buildUI() { dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override//from w ww .java2s . co m public void windowClosed(WindowEvent e) { if (databaseAdded) { SPObject currentEditor = session.getWorkspace().getEditorPanelModel(); try { final URI resource = WabitSwingSessionContextImpl.class .getResource(WabitSessionContext.NEW_WORKSPACE_URL).toURI(); URL importURL = resource.toURL(); URLConnection urlConnection = importURL.openConnection(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); final OpenWorkspaceXMLDAO workspaceLoader = new OpenWorkspaceXMLDAO(context, in, urlConnection.getContentLength()); workspaceLoader.importWorkspaces(session); } catch (Exception ex) { throw new RuntimeException("Cannot find the templates file at " + "location " + WabitSessionContext.NEW_WORKSPACE_URL); } session.getWorkspace().setEditorPanelModel(currentEditor); context.registerChildSession(session); } session.getWorkspace().removeDatabaseListChangeListener(workspaceDataSourceListener); } }); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref:grow")); final JLabel selectDSLabel = new JLabel("Select a data source for your new workspace."); selectDSLabel.setHorizontalAlignment(SwingConstants.CENTER); builder.append(selectDSLabel); builder.nextLine(); final JLabel additionalDSLabel = new JLabel("(Additional data sources can be added later.)"); additionalDSLabel.setHorizontalAlignment(SwingConstants.CENTER); builder.append(additionalDSLabel); builder.nextLine(); builder.append(WorkspacePanel.createDBConnectionManager(session, dialog).getPanel()); dialog.add(builder.getPanel()); }
From source file:ca.sqlpower.wabit.swingui.olap.OlapQueryPanel.java
License:Open Source License
private void buildUI() { final JComponent textQueryPanel; try {/*from w w w . j ava 2 s. c o m*/ textQueryPanel = createTextQueryPanel(); } catch (SQLException e) { throw new RuntimeException(e); } queryPanels = new JTabbedPane(); Action executeAction = new AbstractAction("Execute", WabitIcons.RUN_ICON_32) { public void actionPerformed(ActionEvent e) { executeMdxAction.actionPerformed(e); } }; toolBarBuilder.add(executeAction); toolBarBuilder.add(resetQueryButton); toolBarBuilder.addSeparator(); ExportWabitObjectAction<OlapQuery> exportAction = new ExportWabitObjectAction<OlapQuery>(session, query, WabitIcons.EXPORT_ICON_32, "Export OLAP Query to Wabit file"); toolBarBuilder.add(exportAction, "Export..."); toolBarBuilder.add(new CreateLayoutFromQueryAction(session.getWorkspace(), query, query.getName()), "Create Report"); toolBarBuilder.add(new NewChartAction(session, query), "Create Chart", new ImageIcon(QueryPanel.class.getClassLoader().getResource("icons/32x32/chart.png"))); final JCheckBox nonEmptyRowsCheckbox = new JCheckBox("Omit Empty Rows"); nonEmptyRowsCheckbox.setSelected(query.isNonEmpty()); nonEmptyRowsCheckbox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { query.setNonEmpty(nonEmptyRowsCheckbox.isSelected()); } catch (Exception ex) { throw new RuntimeException(ex); } } }); toolBarBuilder.add(nonEmptyRowsCheckbox); final JComponent viewComponent = cellSetViewer.getViewComponent(); queryPanels.add("GUI", viewComponent); queryPanels.add("MDX", textQueryPanel); DefaultFormBuilder builder = new DefaultFormBuilder( new FormLayout("pref, 5dlu, pref, 5dlu, pref, 5dlu, pref")); builder.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); builder.append("OLAP Connections", databaseComboBox); builder.append(cubeNameLabel); if (query.getCurrentCube() != null) { cubeNameLabel.setText(query.getCurrentCube().getName()); } builder.append(cubeChooserButton); panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createLineBorder(Color.GRAY)); panel.add(builder.getPanel(), BorderLayout.NORTH); panel.add(queryPanels, BorderLayout.CENTER); }
From source file:ca.sqlpower.wabit.swingui.QueryPanel.java
License:Open Source License
private void buildUI() { JTabbedPane resultPane = queryUIComponents.getResultTabPane(); queryUIComponents.getQueryArea().setLineWrap(true); queryToolPanel = new RTextScrollPane(queryUIComponents.getQueryArea(), true); queryPenAndTextTabPane = new JTabbedPane(); JPanel playPen = queryPen.createQueryPen(); DefaultFormBuilder queryExecuteBuilder = new DefaultFormBuilder(new FormLayout("pref:grow, 10dlu, pref")); queryPenPanel = new JPanel(new BorderLayout()); queryPenPanel.add(playPen, BorderLayout.CENTER); queryPenPanel.add(queryExecuteBuilder.getPanel(), BorderLayout.SOUTH); queryPenAndTextTabPane.add(queryPenPanel, "QueryPen"); queryPenAndTextTabPane.add(queryToolPanel, SQL_TEXT_TAB_HEADING); if (queryCache.isScriptModified()) { queryPenAndTextTabPane.setSelectedComponent(queryToolPanel); queryUIComponents.getQueryArea().setText(queryCache.generateQuery()); }// www . j a v a 2 s . co m // We need to map the insert var action here. final SPVariableHelper helper = new SPVariableHelper(queryCache); Action insertVariableAction = new InsertVariableAction("Variables", helper, null, new VariableInserter() { public void insert(String variable) { try { queryUIComponents.getQueryArea().getDocument() .insertString(queryUIComponents.getQueryArea().getCaretPosition(), variable, null); } catch (BadLocationException e) { throw new AssertionError(e); } } }, queryUIComponents.getQueryArea()); // Maps CTRL+SPACE to insert variable queryUIComponents.getQueryArea().getInputMap() .put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), "insertVariable"); queryUIComponents.getQueryArea().getActionMap().put("insertVariable", insertVariableAction); final JLabel whereText = new JLabel("Where:"); final JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(queryPenAndTextTabPane, BorderLayout.CENTER); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref, 5dlu, pref")); builder.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); builder.append("Database Connection", reportComboBox); topPanel.add(builder.getPanel(), BorderLayout.NORTH); if (queryPenPanel == queryPenAndTextTabPane.getSelectedComponent()) { changeToGUIToolBar(); } else if (queryToolPanel == queryPenAndTextTabPane.getSelectedComponent()) { changeToTextToolBar(); } queryPenAndTextTabPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { boolean execute = false; if (queryPenPanel == queryPenAndTextTabPane.getSelectedComponent()) { //This is temporary until we can parse the user string and set the query cache to look like //the query the user modified. int retval = JOptionPane.OK_OPTION; if (queryCache.isScriptModified()) { retval = JOptionPane.showConfirmDialog(getPanel(), "Changes will be lost to the SQL script if you go back to the PlayPen. \nDo you wish to continue?", "Changing", JOptionPane.YES_NO_OPTION); } if (retval != JOptionPane.OK_OPTION) { queryPenAndTextTabPane.setSelectedComponent(queryToolPanel); } else { //The RTextArea needs to have its text set to the empty string //or else it will set its text to the empty string before changing //its text when we come back to the query side and it will get //the query in a state where it thinks the user changed the query twice. queryUIComponents.getQueryArea().setText(null); queryCache.removeUserModifications(); boolean disableAutoExecute = context.getPrefs() .getBoolean(WabitSessionContext.DISABLE_QUERY_AUTO_EXECUTE, false); if (queryCache.isAutomaticallyExecuting() && !disableAutoExecute) { execute = true; } queryPen.getGlobalWhereText().setVisible(true); groupingCheckBox.setVisible(true); whereText.setVisible(true); changeToGUIToolBar(); } } else if (queryToolPanel == queryPenAndTextTabPane.getSelectedComponent()) { if (!queryCache.isScriptModified()) { queryUIComponents.getQueryArea().setText(queryCache.generateQuery()); // Since the query controller sets the userModifiedQuery property // on any insert to the query area, we need to revert the value // back to null. This is to ensure that if the user has not made // any changes, changing back to the query pen will not prompt // the user that "changes will be lost". queryCache.removeUserModifications(); boolean disableAutoExecute = context.getPrefs() .getBoolean(WabitSessionContext.DISABLE_QUERY_AUTO_EXECUTE, false); if (queryCache.isAutomaticallyExecuting() && !disableAutoExecute) { execute = true; } } queryPen.getGlobalWhereText().setVisible(false); groupingCheckBox.setVisible(false); whereText.setVisible(false); changeToTextToolBar(); } if (execute) { execute(); } } }); groupingCheckBox = new JCheckBox("Grouping"); groupingCheckBox.setSelected(queryCache.isGroupingEnabled()); groupingCheckBox.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { queryCache.setGroupingEnabled(groupingCheckBox.isSelected()); boolean disableAutoExecute = context.getPrefs() .getBoolean(WabitSessionContext.DISABLE_QUERY_AUTO_EXECUTE, false); if (queryCache.isAutomaticallyExecuting() && !disableAutoExecute) { execute(); } } }); FormLayout layout = new FormLayout("pref, 5dlu, pref, 3dlu, pref:grow, 5dlu, max(pref;50dlu)", "pref, fill:0dlu:grow"); DefaultFormBuilder southPanelBuilder = new DefaultFormBuilder(layout); southPanelBuilder.append(groupingCheckBox); southPanelBuilder.append(whereText, queryPen.getGlobalWhereText()); JPanel searchPanel = new JPanel(new BorderLayout()); searchPanel.add(new JLabel(ICON), BorderLayout.WEST); searchField = new JTextField(queryUIComponents.getSearchDocument(), null, 0); searchPanel.add(searchField, BorderLayout.CENTER); southPanelBuilder.append(searchPanel); southPanelBuilder.nextLine(); resultPane.setPreferredSize(new Dimension((int) resultPane.getPreferredSize().getWidth(), 0)); southPanelBuilder.append(resultPane, 7); dragTreeScrollPane = new JScrollPane(dragTree); dragTreeScrollPane.setMinimumSize(new Dimension(DBTreeCellRenderer.DB_ICON.getIconWidth() * 3, 0)); mainSplitPane.setOneTouchExpandable(true); mainSplitPane.setResizeWeight(1); mainSplitPane.add(topPanel, JSplitPane.TOP); JPanel bottomPanel = southPanelBuilder.getPanel(); mainSplitPane.add(bottomPanel, JSplitPane.BOTTOM); bottomPanel.setMinimumSize(new Dimension(0, ICON.getIconHeight() * 5)); mainSplitPane.addHierarchyListener(new HierarchyListener() { public void hierarchyChanged(HierarchyEvent e) { boolean disableAutoExecute = context.getPrefs() .getBoolean(WabitSessionContext.DISABLE_QUERY_AUTO_EXECUTE, false); if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) > 0 && mainSplitPane.getParent() != null && !queryCache.isScriptModified() && queryCache.isAutomaticallyExecuting() && !disableAutoExecute) { execute(); mainSplitPane.removeHierarchyListener(this); } } }); }
From source file:ca.sqlpower.wabit.swingui.report.ResultSetSwingRenderer.java
License:Open Source License
public DataEntryPanel getPropertiesPanel() { FormLayout layout = new FormLayout("20dlu, 4dlu, pref, 4dlu, 300dlu:grow, 4dlu, pref"); final DefaultFormBuilder fb = new DefaultFormBuilder(layout); final JLabel visOptionsLabel = new JLabel("Visual"); visOptionsLabel.setFont(visOptionsLabel.getFont().deriveFont(Font.BOLD)); fb.append(visOptionsLabel, 7);//from w w w .j a v a2 s. co m fb.nextLine(); fb.append(""); final JLabel headerFontExample = new JLabel("Header Font Example"); headerFontExample.setFont(renderer.getHeaderFont()); fb.append("Headers Font", headerFontExample, ReportUtil.createFontButton(headerFontExample, renderer)); fb.nextLine(); fb.append(""); final JLabel bodyFontExample = new JLabel("Body Font Example"); bodyFontExample.setFont(renderer.getBodyFont()); fb.append("Body Font", bodyFontExample, ReportUtil.createFontButton(bodyFontExample, renderer)); fb.nextLine(); fb.append(""); final JLabel backgroundColourLabel = new JLabel(" "); final JButton backgroundColorPickerButton = new JButton("Choose..."); backgroundColourLabel.setOpaque(true); backgroundColourLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); backgroundColourLabel.setBackground( renderer.getBackgroundColour() == null ? Color.WHITE : renderer.getBackgroundColour()); backgroundColourLabel.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { // no op } public void mousePressed(MouseEvent e) { // no op } public void mouseExited(MouseEvent e) { // no op } public void mouseEntered(MouseEvent e) { // no op } public void mouseClicked(MouseEvent e) { Color c; c = JColorChooser.showDialog(backgroundColorPickerButton, "Choose a background color", backgroundColourLabel.getBackground()); if (c != null) { backgroundColourLabel.setBackground(c); } } }); backgroundColorPickerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Color c; c = JColorChooser.showDialog(backgroundColorPickerButton, "Choose a background color", backgroundColourLabel.getBackground()); if (c != null) { backgroundColourLabel.setBackground(c); } } }); fb.append("Background color", backgroundColourLabel, backgroundColorPickerButton); fb.append(""); fb.nextLine(); fb.append(""); final JLabel headerColourLabel = new JLabel(" "); final JButton headerColorPickerButton = new JButton("Choose..."); headerColourLabel.setOpaque(true); headerColourLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); headerColourLabel .setBackground(renderer.getHeaderColour() == null ? Color.WHITE : renderer.getHeaderColour()); headerColourLabel.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { // no op } public void mousePressed(MouseEvent e) { // no op } public void mouseExited(MouseEvent e) { // no op } public void mouseEntered(MouseEvent e) { // no op } public void mouseClicked(MouseEvent e) { Color c; c = JColorChooser.showDialog(headerColorPickerButton, "Choose a header color", headerColourLabel.getBackground()); if (c != null) { headerColourLabel.setBackground(c); } } }); headerColorPickerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Color c; c = JColorChooser.showDialog(headerColorPickerButton, "Choose a header color", headerColourLabel.getBackground()); if (c != null) { headerColourLabel.setBackground(c); } } }); fb.append("Headers color", headerColourLabel, headerColorPickerButton); fb.append(""); fb.nextLine(); fb.append(""); final JLabel dataColourLabel = new JLabel(" "); final JButton dataColorPickerButton = new JButton("Choose..."); dataColourLabel.setOpaque(true); dataColourLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); dataColourLabel.setBackground(renderer.getDataColour() == null ? Color.WHITE : renderer.getDataColour()); dataColourLabel.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { // no op } public void mousePressed(MouseEvent e) { // no op } public void mouseExited(MouseEvent e) { // no op } public void mouseEntered(MouseEvent e) { // no op } public void mouseClicked(MouseEvent e) { Color c; c = JColorChooser.showDialog(dataColorPickerButton, "Choose a data color", dataColourLabel.getBackground()); if (c != null) { dataColourLabel.setBackground(c); } } }); dataColorPickerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Color c; c = JColorChooser.showDialog(dataColorPickerButton, "Choose a data color", dataColourLabel.getBackground()); if (c != null) { dataColourLabel.setBackground(c); } } }); fb.append("Data cells color", dataColourLabel, dataColorPickerButton); fb.append(""); fb.nextLine(); fb.append(""); final JComboBox borderComboBox = new JComboBox(BorderStyles.values()); borderComboBox.setSelectedItem(renderer.getBorderType()); fb.append("Border", borderComboBox); fb.nextLine(); fb.append(""); fb.appendUnrelatedComponentsGapRow(); fb.nextLine(); final JLabel dataOptionsLabel = new JLabel("Data"); dataOptionsLabel.setFont(dataOptionsLabel.getFont().deriveFont(Font.BOLD)); fb.append(dataOptionsLabel, 7); fb.nextLine(); fb.append(""); final JTextField nullStringField = new JTextField(renderer.getNullString()); fb.append("Null string", nullStringField); fb.nextLine(); fb.append(""); final JCheckBox grandTotalsCheckBox = new JCheckBox("Add Grand totals"); grandTotalsCheckBox.setSelected(renderer.isPrintingGrandTotals()); fb.append("", grandTotalsCheckBox); fb.nextLine(); fb.appendUnrelatedComponentsGapRow(); final JLabel columnOptionsLabel = new JLabel("Columns"); columnOptionsLabel.setFont(columnOptionsLabel.getFont().deriveFont(Font.BOLD)); fb.append(columnOptionsLabel, 7); fb.nextLine(); fb.append(""); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); final List<DataEntryPanel> columnPanels = new ArrayList<DataEntryPanel>(); for (ColumnInfo ci : renderer.getColumnInfoList()) { DataEntryPanel dep = createColumnPropsPanel(ci); columnPanels.add(dep); tabbedPane.add(ci.getName(), dep.getPanel()); } fb.append(tabbedPane, 5); fb.nextLine(); fb.appendUnrelatedComponentsGapRow(); return new DataEntryPanel() { public boolean applyChanges() { renderer.setHeaderFont(headerFontExample.getFont()); renderer.setBodyFont(bodyFontExample.getFont()); renderer.setNullString(nullStringField.getText()); renderer.setBackgroundColour(backgroundColourLabel.getBackground()); renderer.setDataColour(dataColourLabel.getBackground()); renderer.setHeaderColour(headerColourLabel.getBackground()); renderer.setBorderType((BorderStyles) borderComboBox.getSelectedItem()); renderer.setPrintingGrandTotals(grandTotalsCheckBox.isSelected()); boolean applied = true; for (DataEntryPanel columnPropsPanel : columnPanels) { applied &= columnPropsPanel.applyChanges(); } return applied; } public void discardChanges() { for (DataEntryPanel columnPropsPanel : columnPanels) { columnPropsPanel.discardChanges(); } } public JComponent getPanel() { return fb.getPanel(); } public boolean hasUnsavedChanges() { boolean hasUnsaved = false; for (DataEntryPanel columnPropsPanel : columnPanels) { hasUnsaved |= columnPropsPanel.hasUnsavedChanges(); } return hasUnsaved; } }; }
From source file:ca.sqlpower.wabit.swingui.report.ResultSetSwingRenderer.java
License:Open Source License
/** * Helper method for {@link #getPropertiesPanel()}. *///from www .j av a 2s . c o m private DataEntryPanel createColumnPropsPanel(final ColumnInfo ci) { final FormLayout layout = new FormLayout( "80dlu, 10dlu, min(pref; 100dlu):grow, 4dlu, pref:grow, 10dlu, pref:grow"); DefaultFormBuilder fb = new DefaultFormBuilder(layout); final JTextField columnLabel = new JTextField(ci.getName()); final JLabel widthLabel = new JLabel("Size"); final JSpinner widthSpinner = new JSpinner(new SpinnerNumberModel(ci.getWidth(), 0, Integer.MAX_VALUE, 12)); final JComboBox dataTypeComboBox = new JComboBox(DataType.values()); final JLabel dataTypeLabel = new JLabel("Type"); final JComboBox formatComboBox = new JComboBox(); formatComboBox.setEditable(true); final JLabel formatLabel = new JLabel("Format"); final JCheckBox subtotalCheckbox = new JCheckBox("Print Subtotals"); final JLabel linkingLabel = new JLabel("Link to report"); final JComboBox linkingBox = new JComboBox(); // XXX Enable only when this is working. linkingBox.setEnabled(false); final ButtonGroup breakAndGroupButtons = new ButtonGroup(); final JRadioButton noBreakOrGroupButton = new JRadioButton("None"); breakAndGroupButtons.add(noBreakOrGroupButton); final JRadioButton breakRadioButton = new JRadioButton("Break Into Sections"); breakAndGroupButtons.add(breakRadioButton); final JRadioButton pageBreakRadioButton = new JRadioButton("Break Into Sections (page break)"); breakAndGroupButtons.add(pageBreakRadioButton); final JRadioButton groupRadioButton = new JRadioButton("Group (Suppress Repeating Values)"); breakAndGroupButtons.add(groupRadioButton); final JLabel alignmentLabel = new JLabel("Alignment"); ButtonGroup hAlignmentGroup = new ButtonGroup(); final JToggleButton leftAlign = new JToggleButton(AlignmentIcons.LEFT_ALIGN_ICON, ci.getHorizontalAlignment() == HorizontalAlignment.LEFT); hAlignmentGroup.add(leftAlign); final JToggleButton centreAlign = new JToggleButton(AlignmentIcons.CENTRE_ALIGN_ICON, ci.getHorizontalAlignment() == HorizontalAlignment.CENTER); hAlignmentGroup.add(centreAlign); final JToggleButton rightAlign = new JToggleButton(AlignmentIcons.RIGHT_ALIGN_ICON, ci.getHorizontalAlignment() == HorizontalAlignment.RIGHT); hAlignmentGroup.add(rightAlign); Box alignmentBox = Box.createHorizontalBox(); alignmentBox.add(leftAlign); alignmentBox.add(centreAlign); alignmentBox.add(rightAlign); alignmentBox.add(Box.createHorizontalGlue()); /* * ROW 1 - Caption text field + two labels */ JLabel captionLabel = new JLabel("Caption"); captionLabel.setFont(captionLabel.getFont().deriveFont(Font.BOLD)); fb.append(captionLabel); JLabel visLabel = new JLabel("Visual options"); visLabel.setFont(visLabel.getFont().deriveFont(Font.BOLD)); fb.append(visLabel, 3); JLabel advLabel = new JLabel("Advanced options"); advLabel.setFont(advLabel.getFont().deriveFont(Font.BOLD)); fb.append(advLabel); fb.nextLine(); /* * Separator row */ fb.append(new JSeparator(), 7); fb.nextLine(); /* * Row 2 */ fb.append(columnLabel); fb.append(widthLabel); fb.append(widthSpinner); fb.append(subtotalCheckbox); subtotalCheckbox.setSelected(ci.getWillSubtotal()); if (ci.getDataType().equals(DataType.NUMERIC)) { subtotalCheckbox.setEnabled(true); } else { subtotalCheckbox.setEnabled(false); } fb.nextLine(); /* * Row 3 */ fb.append(new JLabel()); fb.append(dataTypeLabel); fb.append(dataTypeComboBox); fb.append(linkingLabel); fb.nextLine(); /* * Row 4 */ fb.append(new JLabel()); fb.append(formatLabel); fb.append(formatComboBox); fb.append(linkingBox); fb.nextLine(); /* * Row 5 */ fb.append(new JLabel()); fb.append(alignmentLabel); fb.append(alignmentBox); fb.append(new JLabel("Breaking and Grouping")); fb.nextLine(); /* * Row 6 */ fb.append(new JLabel(), 5); fb.append(noBreakOrGroupButton); fb.nextLine(); /* * Row 7 */ fb.append(new JLabel(), 5); fb.append(breakRadioButton); fb.nextLine(); /* * Row 8 */ fb.append(new JLabel(), 5); fb.append(pageBreakRadioButton); fb.nextLine(); /* * spacer */ fb.append(new JLabel(), 5); fb.append(groupRadioButton); fb.nextLine(); dataTypeComboBox.setSelectedItem(ci.getDataType()); if (dataTypeComboBox.getSelectedItem() == DataType.TEXT) { formatComboBox.setEnabled(false); } else { setItemforFormatComboBox(formatComboBox, (DataType) dataTypeComboBox.getSelectedItem()); if (ci.getFormat() != null) { this.setOrInsertFormat(formatComboBox, ci.getFormat()); } } dataTypeComboBox.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { if (((JComboBox) e.getSource()).getSelectedItem() == DataType.TEXT) { formatComboBox.setEnabled(false); subtotalCheckbox.setEnabled(false); } else if (((JComboBox) e.getSource()).getSelectedItem() == DataType.DATE) { formatComboBox.setEnabled(true); subtotalCheckbox.setEnabled(false); } else if (((JComboBox) e.getSource()).getSelectedItem() == DataType.NUMERIC) { formatComboBox.setEnabled(true); subtotalCheckbox.setEnabled(true); } setItemforFormatComboBox(formatComboBox, (DataType) dataTypeComboBox.getSelectedItem()); } }); if (ci.getWillGroupOrBreak().equals(GroupAndBreak.GROUP)) { groupRadioButton.setSelected(true); } else if (ci.getWillGroupOrBreak().equals(GroupAndBreak.BREAK)) { breakRadioButton.setSelected(true); } else if (ci.getWillGroupOrBreak().equals(GroupAndBreak.PAGEBREAK)) { pageBreakRadioButton.setSelected(true); } else { noBreakOrGroupButton.setSelected(true); } // XXX Enable only when this is working // for (Report report : WabitUtils.getWorkspace(ci).getReports()) { // linkingBox.addItem(report); // } // linkingBox.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // // TODO populate and add a listener to the linking box // } // }); final JPanel panel = fb.getPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 3, 3, 5)); return new DataEntryPanel() { public boolean applyChanges() { ci.setName(columnLabel.getText()); if (leftAlign.isSelected()) { ci.setHorizontalAlignment(HorizontalAlignment.LEFT); } else if (centreAlign.isSelected()) { ci.setHorizontalAlignment(HorizontalAlignment.CENTER); } else if (rightAlign.isSelected()) { ci.setHorizontalAlignment(HorizontalAlignment.RIGHT); } ci.setDataType((DataType) dataTypeComboBox.getSelectedItem()); logger.debug("formatCombobBox.getSelectedItem is" + (String) formatComboBox.getSelectedItem()); if (((DataType) dataTypeComboBox.getSelectedItem()).equals(DataType.TEXT) || (formatComboBox.getSelectedItem() != null && ((String) formatComboBox.getSelectedItem()) .equals(ReportUtil.DEFAULT_FORMAT_STRING))) { ci.setFormat(null); } else { ci.setFormat(getFormat(ci.getDataType(), (String) formatComboBox.getSelectedItem())); } ci.setWidth((Integer) widthSpinner.getValue()); if (groupRadioButton.isSelected()) { ci.setWillGroupOrBreak(GroupAndBreak.GROUP); } else if (breakRadioButton.isSelected()) { ci.setWillGroupOrBreak(GroupAndBreak.BREAK); } else if (pageBreakRadioButton.isSelected()) { ci.setWillGroupOrBreak(GroupAndBreak.PAGEBREAK); } else { ci.setWillGroupOrBreak(GroupAndBreak.NONE); } ci.setWillSubtotal(subtotalCheckbox.isSelected()); renderer.refresh(); return true; } public void discardChanges() { // no op } public JComponent getPanel() { return panel; } public boolean hasUnsavedChanges() { return true; } }; }
From source file:ca.sqlpower.wabit.swingui.WabitSwingSessionContextImpl.java
License:Open Source License
/** * Builds the GUI/*from www . ja v a 2s . c om*/ * @throws SQLObjectException */ private void buildUI() throws SQLObjectException { frame.setIconImage(FRAME_ICON.getImage()); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(windowClosingListener); aboutAction = new AboutAction(frame); // this will be the frame's content pane JPanel cp = new JPanel(new BorderLayout()); JToolBar toolBar = new JToolBar(JToolBar.HORIZONTAL); toolBar.setFloatable(false); /** * Creates a popup menu with all the possible 'New <insert Wabit object * here>' options */ Action newAction = new AbstractAction("New", NEW_ICON) { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JButton) { WabitSwingSession activeSession = getActiveSwingSession(); JButton source = (JButton) e.getSource(); JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new NewWorkspaceAction(WabitSwingSessionContextImpl.this)); JMenu newWorkspaceServerSubMenu = createServerListMenu(frame, "New Server Workspace", new ServerListMenuItemFactory() { public JMenuItem createMenuEntry(SPServerInfo serviceInfo, Component dialogOwner) { return new JMenuItem(new NewServerWorkspaceAction(dialogOwner, WabitSwingSessionContextImpl.this, serviceInfo)); } }); if (activeSession != null) { objectsMenu(popupMenu, WabitWorkspace.class.getSimpleName(), null, newWorkspaceServerSubMenu, WabitAccessManager.Permission.CREATE); if (activeSession.getWorkspace().isSystemWorkspace()) { objectsMenu(popupMenu, User.class.getSimpleName(), null, new JMenuItem(new NewUserAction(activeSession)), WabitAccessManager.Permission.CREATE); objectsMenu(popupMenu, Group.class.getSimpleName(), null, new JMenuItem(new NewGroupAction(activeSession)), WabitAccessManager.Permission.CREATE); } else { objectsMenu(popupMenu, QueryCache.class.getSimpleName(), null, new JMenuItem(new NewQueryAction(activeSession)), WabitAccessManager.Permission.CREATE); objectsMenu(popupMenu, OlapQuery.class.getSimpleName(), null, new JMenuItem(new NewOLAPQueryAction(activeSession)), WabitAccessManager.Permission.CREATE); objectsMenu(popupMenu, Chart.class.getSimpleName(), null, new JMenuItem(new NewChartAction(activeSession)), WabitAccessManager.Permission.CREATE); objectsMenu(popupMenu, WabitImage.class.getSimpleName(), null, new JMenuItem(new NewImageAction(activeSession)), WabitAccessManager.Permission.CREATE); objectsMenu(popupMenu, Report.class.getSimpleName(), null, new JMenuItem(new NewReportAction(activeSession)), WabitAccessManager.Permission.CREATE); objectsMenu(popupMenu, Template.class.getSimpleName(), null, new JMenuItem(new NewTemplateAction(activeSession)), WabitAccessManager.Permission.CREATE); if (activeSession.getWorkspace().isServerWorkspace()) { objectsMenu(popupMenu, ReportTask.class.getSimpleName(), null, new JMenuItem(new NewReportTaskAction(activeSession)), WabitAccessManager.Permission.CREATE); } } } popupMenu.show(source, 0, source.getHeight()); } } }; JButton newButton = new JButton(newAction); newButton.setVerticalTextPosition(SwingConstants.BOTTOM); newButton.setHorizontalTextPosition(SwingConstants.CENTER); JButton openButton = new JButton(openAction); openButton.setVerticalTextPosition(SwingConstants.BOTTOM); openButton.setHorizontalTextPosition(SwingConstants.CENTER); JButton saveButton = new JButton(saveAction); saveButton.setVerticalTextPosition(SwingConstants.BOTTOM); saveButton.setHorizontalTextPosition(SwingConstants.CENTER); JButton refreshButton = new JButton(new RefreshWorkspaceAction(this)); refreshButton.setVerticalTextPosition(SwingConstants.BOTTOM); refreshButton.setHorizontalTextPosition(SwingConstants.CENTER); // OS X specific client properties to modify the button appearance. // This only seems to affect OS X 10.5 Leopard's buttons. newButton.putClientProperty("JButton.buttonType", "toolbar"); openButton.putClientProperty("JButton.buttonType", "toolbar"); saveButton.putClientProperty("JButton.buttonType", "toolbar"); refreshButton.putClientProperty("JButton.buttonType", "toolbar"); toolBar.add(newButton); toolBar.add(openButton); toolBar.add(saveButton); toolBar.add(refreshButton); JPanel leftPanel = new JPanel(new BorderLayout()); // this is checked in the constructor assert getSessions().isEmpty(); final ChangeListener tabChangeListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { final int selectedIndex = stackedTabPane.getSelectedIndex(); if (stackedTabPane.indexOfTab("Search") == selectedIndex) return; if (selectedIndex >= 0) { setActiveSession((WabitSwingSession) getSessions().get(selectedIndex - 1)); setEditorPanel(); } } }; stackedTabPane.addChangeListener(tabChangeListener); JPanel logoPanel = new JPanel(new MigLayout("fill, ins 0, gap 0 0")); JLabel sqlPowerLogoLabel = SPSUtils.getSQLPowerLogoLabel(); sqlPowerLogoLabel.setOpaque(false); logoPanel.add(sqlPowerLogoLabel, "grow 0 0, push 0 0"); logoPanel.add(new JLabel(), "grow 100 0, push 100 0"); leftPanel.add(toolBar, BorderLayout.NORTH); leftPanel.add(stackedTabPane, BorderLayout.CENTER); leftPanel.add(logoPanel, BorderLayout.SOUTH); wabitPane.setLeftComponent(leftPanel); wabitPane.setDividerLocation(prefs.getInt(MAIN_DIVIDER_LOCATION, DEFAULT_TREE_WIDTH)); DefaultFormBuilder statusBarBuilder = new DefaultFormBuilder( new FormLayout("pref:grow, 4dlu, pref, 2dlu, max(50dlu; pref), 4dlu, pref")); statusBarBuilder.append(statusLabel); statusBarBuilder.append("Row Limit", getRowLimitSpinner()); MemoryMonitor memoryMonitor = new MemoryMonitor(); memoryMonitor.start(); JLabel memoryLabel = memoryMonitor.getLabel(); memoryLabel.setBorder(new EmptyBorder(0, 20, 0, 20)); statusBarBuilder.append(memoryLabel); cp.add(wabitPane, BorderLayout.CENTER); cp.add(statusBarBuilder.getPanel(), BorderLayout.SOUTH); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic('f'); menuBar.add(fileMenu); fileMenu.add(new NewWorkspaceAction(this)); JMenu newWorkspaceServerSubMenu = createServerListMenu(frame, "New Server Workspace", new ServerListMenuItemFactory() { public JMenuItem createMenuEntry(SPServerInfo serviceInfo, Component dialogOwner) { return new JMenuItem(new NewServerWorkspaceAction(dialogOwner, WabitSwingSessionContextImpl.this, serviceInfo)); } }); fileMenu.add(newWorkspaceServerSubMenu); fileMenu.add(new OpenWorkspaceAction(this)); fileMenu.add(createRecentMenu()); fileMenu.addSeparator(); fileMenu.add(createServerListMenu(frame, "Log In to Wabit Server", new ServerListMenuItemFactory() { public JMenuItem createMenuEntry(SPServerInfo serviceInfo, Component dialogOwner) { return new JMenuItem( new LogInToServerAction(dialogOwner, serviceInfo, WabitSwingSessionContextImpl.this)); } })); JMenuItem openDemoMenuItem = new JMenuItem(new AbstractAction() { public void actionPerformed(ActionEvent e) { try { final URI resource = WabitSwingSessionContextImpl.class.getResource(EXAMPLE_WORKSPACE_URL) .toURI(); OpenWorkspaceAction.loadFiles(WabitSwingSessionContextImpl.this, resource); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } } }); fileMenu.addSeparator(); openDemoMenuItem.setText("Open Demo Workspace"); openDemoMenuItem.setIcon(OPEN_DEMO_ICON); fileMenu.add(openDemoMenuItem); fileMenu.addSeparator(); fileMenu.add(new ImportWorkspaceAction(this)); fileMenu.addSeparator(); fileMenu.add(new SaveWorkspaceAction(this)); fileMenu.add(new SaveWorkspaceAsAction(this)); Icon saveAllIcon = new ImageIcon( WabitSwingSessionContextImpl.class.getClassLoader().getResource("icons/saveAll-16.png")); fileMenu.add(new AbstractAction("Save All", saveAllIcon) { public void actionPerformed(ActionEvent e) { SaveWorkspaceAction.saveAllSessions(WabitSwingSessionContextImpl.this); } }); fileMenu.addSeparator(); JMenuItem closeMenuItem = new JMenuItem(new CloseWorkspaceAction(this)); closeMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fileMenu.add(closeMenuItem); fileMenu.addSeparator(); JMenuItem databaseConnectionManager = new JMenuItem(new AbstractAction("Database Connection Manager...") { public void actionPerformed(ActionEvent e) { WabitSwingSession activeSwingSession = getActiveSwingSession(); if (activeSwingSession != null) { getActiveSwingSession().getDbConnectionManager().showDialog(getFrame()); } else { // XXX: Temporary fix until setActiveSession() fires // property change events so that we can disable this action // instead. JOptionPane.showMessageDialog(frame, "Please open a workspace first in order to see\n" + "which database connections are available"); } } }); fileMenu.add(databaseConnectionManager); if (!isMacOSX()) { fileMenu.addSeparator(); fileMenu.add(prefsAction); fileMenu.addSeparator(); fileMenu.add(exitAction); } JMenu editMenu = new JMenu("Edit"); editMenu.setMnemonic('e'); menuBar.add(editMenu); final JMenuItem searchMenuItem = new JMenuItem(selectSearchTabAction); searchMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(searchMenuItem); JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic('v'); menuBar.add(viewMenu); viewMenu.add(new JMenuItem(maximizeEditorAction)); viewMenu.addSeparator(); ButtonGroup sourceListStyleGroup = new ButtonGroup(); for (SourceListStyle sls : SourceListStyle.values()) { viewMenu.add(sls.makeMenuItem(this, sourceListStyleGroup)); } JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('h'); menuBar.add(helpMenu); if (!isMacOSX()) { helpMenu.add(aboutAction); helpMenu.addSeparator(); } helpMenu.add(new OpenUrlAction(SPSUtils.WABIT_GS_URL, "Getting Started")); helpMenu.add(new OpenUrlAction(SPSUtils.WABIT_DEMO_URL, "Tutorials")); helpMenu.add(new OpenUrlAction(SPSUtils.WABIT_FAQ_URL, "Frequently Asked Questions")); helpMenu.add(SPSUtils.forumAction); helpMenu.addSeparator(); helpMenu.add(new OpenUrlAction(SPSUtils.WABIT_UPGRADE_URL, "Upgrade to Enterprise Edition")); helpMenu.add(new OpenUrlAction(SPSUtils.WABIT_PS_URL, "Premium Support")); helpMenu.add(new OpenUrlAction(SPSUtils.WABIT_UG_URL, "User Guide")); helpMenu.addSeparator(); helpMenu.add(new CheckForUpdateAction("Check for Updates...", frame)); frame.setJMenuBar(menuBar); frame.setContentPane(cp); //prefs if (prefs.get("frameBounds", null) != null) { String[] frameBounds = prefs.get("frameBounds", null).split(","); if (frameBounds.length == 4) { logger.debug("Frame bounds are " + Integer.parseInt(frameBounds[0]) + ", " + Integer.parseInt(frameBounds[1]) + ", " + Integer.parseInt(frameBounds[2]) + ", " + Integer.parseInt(frameBounds[3])); frame.setBounds(Integer.parseInt(frameBounds[0]), Integer.parseInt(frameBounds[1]), Integer.parseInt(frameBounds[2]), Integer.parseInt(frameBounds[3])); } } else { frame.setSize(1050, 750); frame.setLocation(200, 100); } frame.setVisible(true); logger.debug("UI is built."); }
From source file:ca.sqlpower.wabit.swingui.WabitWelcomeScreen.java
License:Open Source License
private void buildUI() { //This panel is only here to center the icons panel in the middle of the dialog JPanel iconsPanel = new JPanel(new MigLayout("ins n 0 n 0", "[center, grow]")); iconsPanel.setOpaque(false);//from w w w. ja v a 2 s. c om JPanel generateLogoPanel = LogoLayout.generateLogoPanel(); generateLogoPanel.setOpaque(false); iconsPanel.add(generateLogoPanel, "wrap, alignx center"); iconsPanel.add(buildButtonsPanel(), ""); new JButton(new AbstractAction("View Tutorials") { public void actionPerformed(ActionEvent e) { // TODO Link to a website with demos of Wabit. } }); // bottomPanelBuilder.append(tutorialButton); //Temporary spacer label until tutorials exist on the website. DefaultFormBuilder bottomPanelBuilder = new DefaultFormBuilder( new FormLayout("pref, 4dlu, pref, 4dlu:grow, pref")); bottomPanelBuilder.setDefaultDialogBorder(); JButton helpButton = new JButton(new HelpAction(context.getFrame())); bottomPanelBuilder.append(helpButton); mainPanel = new FurryPanel(new BorderLayout()); mainPanel.add(iconsPanel, BorderLayout.CENTER); mainPanel.add(bottomPanelBuilder.getPanel(), BorderLayout.SOUTH); mainScrollPane = new JScrollPane(mainPanel); }
From source file:com.atlassian.theplugin.idea.ui.ScrollableTwoColumnPanel.java
License:Apache License
public void updateContent(@Nullable Collection<Entry> entries) { panel.removeAll();/* ww w. ja v a 2 s. c om*/ if (entries == null || entries.size() == 0) { panel.setLayout(new BorderLayout()); final JLabel label = new JLabel("No Custom Filter Defined", JLabel.CENTER); panel.setPreferredSize(label.getPreferredSize()); panel.add(label); return; } FormLayout layout = new FormLayout("4dlu, right:p, 4dlu, left:d, 4dlu"); PanelBuilder builder = new PanelBuilder(layout, panel); int row = 1; CellConstraints cc = new CellConstraints(); for (Entry entry : entries) { builder.appendRow("2dlu"); builder.appendRow("p"); cc.xy(2, row * 2).vAlign = CellConstraints.TOP; builder.addLabel(entry.getLabel() + ":", cc); cc.xy(VAL_COL, row * 2).vAlign = CellConstraints.TOP; if (entry.isError()) { builder.addLabel("<html>" + "<font color=\"red\">" + entry.getValue(), cc); } else { builder.addLabel("<html>" + entry.getValue(), cc); } row++; } // this lines (simulating JScrollPane resize) // are needed to more or less workaround the problem of revalidating whole scrollpane when more or fewer // rows could have been added. Without them you may end up with JScrollPane not completely showing its viewport panel.setPreferredSize(null); panel.setPreferredSize(new Dimension(getWidth(), panel.getPreferredSize().height)); panel.validate(); // it was needed here as sometimes panel was left with some old rubbish panel.repaint(); }