Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Fixed margin issues in parameter dialogs #107

Merged
merged 3 commits into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.awt.Font;

import javax.annotation.Nonnull;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
Expand All @@ -42,8 +43,8 @@

import net.sf.mzmine.util.GUIUtils;

public class SQLColumnSettingsComponent extends JPanel implements
ActionListener {
public class SQLColumnSettingsComponent extends JPanel
implements ActionListener {

/**
*
Expand All @@ -57,114 +58,116 @@ public class SQLColumnSettingsComponent extends JPanel implements

public SQLColumnSettingsComponent() {

super(new BorderLayout());

value = new SQLColumnSettings();

// columnsTable = new JTable(value);
columnsTable = new JTable(value) {
/**
*
*/
private static final long serialVersionUID = 1L;

public Component prepareRenderer(TableCellRenderer renderer,
int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (!isCellEditable(row, column)) {
if (isCellSelected(row, column)) {
c.setBackground(Color.decode("#3399FF"));
c.setForeground(Color.white);
} else {
c.setBackground(Color.decode("#E3E3E3"));
}
} else {
if (isCellSelected(row, column)) {
c.setBackground(Color.decode("#3399FF"));
c.setForeground(Color.white);
} else {
c.setBackground(Color.white);
c.setForeground(Color.black);
}
}
return c;
}
};

columnsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
columnsTable.setRowSelectionAllowed(true);
columnsTable.setColumnSelectionAllowed(false);
columnsTable.getTableHeader().setReorderingAllowed(false);
columnsTable.getTableHeader().setResizingAllowed(false);
columnsTable
.setPreferredScrollableViewportSize(new Dimension(550, 220));

columnsTable.setRowHeight(columnsTable.getRowHeight() + 5);
columnsTable.setFont(new Font(getFont().getName(), Font.PLAIN, 13));

JComboBox<SQLExportDataType> dataTypeCombo = new JComboBox<SQLExportDataType>(
SQLExportDataType.values());
dataTypeCombo.setMaximumRowCount(22);
DefaultCellEditor dataTypeEditor = new DefaultCellEditor(dataTypeCombo);
columnsTable.setDefaultEditor(SQLExportDataType.class, dataTypeEditor);

// Create an ItemListener for the JComboBox component.
dataTypeCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
JComboBox<?> dataTypeCombo = (JComboBox<?>) e.getSource();
Boolean selected = ((SQLExportDataType) dataTypeCombo
.getSelectedItem()).isSelectableValue();
if (!selected && e.getStateChange() == 1) {
// Invalid selection - selection of title rows in JComboBox
// is not allowed
dataTypeCombo.setSelectedIndex(dataTypeCombo
.getSelectedIndex() + 1);
}
}
});

JScrollPane elementsScroll = new JScrollPane(columnsTable);
add(elementsScroll, BorderLayout.CENTER);

// Add buttons
JPanel buttonsPanel = new JPanel();
BoxLayout buttonsPanelLayout = new BoxLayout(buttonsPanel,
BoxLayout.Y_AXIS);
buttonsPanel.setLayout(buttonsPanelLayout);
addColumnButton = GUIUtils.addButton(buttonsPanel, "Add", null, this);
removeColumnButton = GUIUtils.addButton(buttonsPanel, "Remove", null,
this);
add(buttonsPanel, BorderLayout.EAST);
super(new BorderLayout());

setBorder(BorderFactory.createEmptyBorder(0, 9, 0, 0));

value = new SQLColumnSettings();

// columnsTable = new JTable(value);
columnsTable = new JTable(value) {
/**
*
*/
private static final long serialVersionUID = 1L;

public Component prepareRenderer(TableCellRenderer renderer,
int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (!isCellEditable(row, column)) {
if (isCellSelected(row, column)) {
c.setBackground(Color.decode("#3399FF"));
c.setForeground(Color.white);
} else {
c.setBackground(Color.decode("#E3E3E3"));
}
} else {
if (isCellSelected(row, column)) {
c.setBackground(Color.decode("#3399FF"));
c.setForeground(Color.white);
} else {
c.setBackground(Color.white);
c.setForeground(Color.black);
}
}
return c;
}
};

columnsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
columnsTable.setRowSelectionAllowed(true);
columnsTable.setColumnSelectionAllowed(false);
columnsTable.getTableHeader().setReorderingAllowed(false);
columnsTable.getTableHeader().setResizingAllowed(false);
columnsTable
.setPreferredScrollableViewportSize(new Dimension(550, 220));

columnsTable.setRowHeight(columnsTable.getRowHeight() + 5);
columnsTable.setFont(new Font(getFont().getName(), Font.PLAIN, 13));

JComboBox<SQLExportDataType> dataTypeCombo = new JComboBox<SQLExportDataType>(
SQLExportDataType.values());
dataTypeCombo.setMaximumRowCount(22);
DefaultCellEditor dataTypeEditor = new DefaultCellEditor(dataTypeCombo);
columnsTable.setDefaultEditor(SQLExportDataType.class, dataTypeEditor);

// Create an ItemListener for the JComboBox component.
dataTypeCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
JComboBox<?> dataTypeCombo = (JComboBox<?>) e.getSource();
Boolean selected = ((SQLExportDataType) dataTypeCombo
.getSelectedItem()).isSelectableValue();
if (!selected && e.getStateChange() == 1) {
// Invalid selection - selection of title rows in JComboBox
// is not allowed
dataTypeCombo.setSelectedIndex(
dataTypeCombo.getSelectedIndex() + 1);
}
}
});

JScrollPane elementsScroll = new JScrollPane(columnsTable);
add(elementsScroll, BorderLayout.CENTER);

// Add buttons
JPanel buttonsPanel = new JPanel();
BoxLayout buttonsPanelLayout = new BoxLayout(buttonsPanel,
BoxLayout.Y_AXIS);
buttonsPanel.setLayout(buttonsPanelLayout);
addColumnButton = GUIUtils.addButton(buttonsPanel, "Add", null, this);
removeColumnButton = GUIUtils.addButton(buttonsPanel, "Remove", null,
this);
add(buttonsPanel, BorderLayout.EAST);

}

public void actionPerformed(ActionEvent event) {

Object src = event.getSource();
Object src = event.getSource();

if (src == addColumnButton) {
value.addNewRow();
}
if (src == addColumnButton) {
value.addNewRow();
}

if (src == removeColumnButton) {
int selectedRow = columnsTable.getSelectedRow();
if (selectedRow < 0)
return;
value.removeRow(selectedRow);
}
if (src == removeColumnButton) {
int selectedRow = columnsTable.getSelectedRow();
if (selectedRow < 0)
return;
value.removeRow(selectedRow);
}
}

void setValue(@Nonnull SQLColumnSettings newValue) {

// Clear the table
this.value = newValue;
columnsTable.setModel(newValue);
// Clear the table
this.value = newValue;
columnsTable.setModel(newValue);
}

@Nonnull
synchronized SQLColumnSettings getValue() {
return value;
return value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

package net.sf.mzmine.parameters.parametertypes;

import java.awt.Insets;
import java.util.Collection;

import javax.swing.JCheckBox;

import net.sf.mzmine.parameters.UserParameter;

import org.w3c.dom.Element;

import net.sf.mzmine.parameters.UserParameter;

/**
* Simple Parameter implementation
*
Expand Down Expand Up @@ -66,7 +67,9 @@ public String getDescription() {

@Override
public JCheckBox createEditingComponent() {
return new JCheckBox();
JCheckBox checkBox = new JCheckBox();
checkBox.setMargin(new Insets(0, 7, 0, 0));
return checkBox;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2006-2015 The MZmine 2 Development Team
*
* This file is part of MZmine 2.
*
* MZmine 2 is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* MZmine 2; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.sf.mzmine.parameters.parametertypes;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JPanel;

public class ComboComponent<ValueType> extends JPanel {

/**
*
*/
private static final long serialVersionUID = 1L;

private final JComboBox<ValueType> comboBox;

public ComboComponent(ValueType choices[]) {
setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
comboBox = new JComboBox<ValueType>(choices);
add(comboBox);
}

@Override
public void setToolTipText(String toolTip) {
comboBox.setToolTipText(toolTip);
}

public Object getSelectedItem() {
return comboBox.getSelectedItem();
}

public int getSelectedIndex() {
return comboBox.getSelectedIndex();
}

public void setSelectedItem(ValueType newValue) {
comboBox.setSelectedItem(newValue);
}
}
Loading