def showCC(self, event): result = JColorChooser().showDialog( None, # Parent component 'Color Selection', # Dialog title self.label.getForeground() # Initial color ) if result: message = 'New color: "%s"' % result.toString() self.label.setForeground(result) else: message = 'Request canceled by user' self.label.setText(message)
class EditSymbolAttr(JPanel): def __init__(self, sattr): self.attr = sattr self.cbox = JColorChooser(self.attr.color) self.sz_field = JTextField(str(self.attr.size)) szpanel = JPanel() szpanel.add(self.sz_field) szpanel.setBorder(BorderFactory.createTitledBorder("symbol size (integer)")) self.filled_box = JCheckBox("Filled ?:",self.attr.filled) self.shape_cbox = JComboBox(SymbolProps.sym_shape_map.keys()) self.shape_cbox.setSelectedItem(self.attr.shape) self.shape_cbox.setBorder(BorderFactory.createTitledBorder("Shape")) panel1 = JPanel() panel1.setLayout(BorderLayout()) panel1.add(szpanel,BorderLayout.NORTH) panel2 = JPanel() panel2.setLayout(GridLayout(1,2)) panel2.add(self.shape_cbox) panel2.add(self.filled_box) panel1.add(panel2,BorderLayout.SOUTH) self.setLayout(BorderLayout()) self.add(self.cbox,BorderLayout.CENTER) self.add(panel1,BorderLayout.SOUTH) def setAttribute(self,sattr): self.attr = sattr self.cbox.color = self.attr.color self.sz_field.text = str(self.attr.size) self.shape_cbox.setSelectedItem(self.attr.shape) def update(self): self.attr.color = self.cbox.getColor() self.attr.size = string.atoi(self.sz_field.getText()) self.attr.filled = self.filled_box.isSelected() self.attr.shape = self.shape_cbox.getSelectedItem() self.attr.sym = self.attr.createSymbol()
def __init__(self, cattr): self.attr = cattr self.cbox = JColorChooser(self.attr.color) self.sym_panel = EditSymbolAttr(cattr.sym_prop) self.thickness_field = JTextField(str(cattr.thickness),2) self.draw_symbol_box = JCheckBox("Draw Symbol?",cattr.draw_symbol) self.dps_field = JTextField(str(self.attr.data_per_symbol),2) self.dash_box = JComboBox(CurveProps.DASH_TYPES.keys()) self.dash_box.setSelectedItem(self.attr.dash_type) self.dash_box.setBorder(BorderFactory.createTitledBorder("Dash type: (Only JDK2 & Slow!)")) tpanelx = JPanel() tpanelx.add(self.thickness_field) tpanelx.setBorder(BorderFactory.createTitledBorder("curve thickness (integer)")) tpanely = JPanel() tpanely.add(self.dps_field) tpanely.setBorder(BorderFactory.createTitledBorder("data per symbol(integer)")) tpanel = JPanel();tpanel.setLayout(GridLayout(2,2)); tpanel.add(self.draw_symbol_box); tpanel.add(tpanelx); tpanel.add(tpanely); tpanel.add(self.dash_box); panel1 = JPanel() panel1.setLayout(BorderLayout()) panel1.add(self.cbox,BorderLayout.CENTER) panel1.add(tpanel, BorderLayout.SOUTH) panel2 = JPanel() panel2.setLayout(BorderLayout()) panel2.add(self.sym_panel,BorderLayout.CENTER) tp1 = JTabbedPane() tp1.addTab("Curve Attributes",panel1) tp1.addTab("Symbol Attributes",panel2) tp1.setSelectedComponent(panel1) self.setLayout(BorderLayout()) self.add(tp1,BorderLayout.CENTER)
class EditCurveAttr(JPanel): def __init__(self, cattr): self.attr = cattr self.cbox = JColorChooser(self.attr.color) self.sym_panel = EditSymbolAttr(cattr.sym_prop) self.thickness_field = JTextField(str(cattr.thickness), 2) self.draw_symbol_box = JCheckBox("Draw Symbol?", cattr.draw_symbol) self.dps_field = JTextField(str(self.attr.data_per_symbol), 2) self.dash_box = JComboBox(CurveProps.DASH_TYPES.keys()) self.dash_box.setSelectedItem(self.attr.dash_type) self.dash_box.setBorder( BorderFactory.createTitledBorder("Dash type: (Only JDK2 & Slow!)")) tpanelx = JPanel() tpanelx.add(self.thickness_field) tpanelx.setBorder( BorderFactory.createTitledBorder("curve thickness (integer)")) tpanely = JPanel() tpanely.add(self.dps_field) tpanely.setBorder( BorderFactory.createTitledBorder("data per symbol(integer)")) tpanel = JPanel() tpanel.setLayout(GridLayout(2, 2)) tpanel.add(self.draw_symbol_box) tpanel.add(tpanelx) tpanel.add(tpanely) tpanel.add(self.dash_box) panel1 = JPanel() panel1.setLayout(BorderLayout()) panel1.add(self.cbox, BorderLayout.CENTER) panel1.add(tpanel, BorderLayout.SOUTH) panel2 = JPanel() panel2.setLayout(BorderLayout()) panel2.add(self.sym_panel, BorderLayout.CENTER) tp1 = JTabbedPane() tp1.addTab("Curve Attributes", panel1) tp1.addTab("Symbol Attributes", panel2) tp1.setSelectedComponent(panel1) self.setLayout(BorderLayout()) self.add(tp1, BorderLayout.CENTER) def setAttribute(self, cattr): self.attr = cattr self.cbox.color = self.attr.color self.sym_panel.setAttribute(cattr.sym_prop) self.thickness_field.text = str(cattr.thickness) self.dps_field.text = str(cattr.data_per_symbol) self.draw_symbol_box.setSelected(cattr.draw_symbol) self.dash_box.setSelectedItem(cattr.dash_type) def update(self): self.attr.color = self.cbox.getColor() self.attr.thickness = string.atoi(self.thickness_field.text) self.attr.data_per_symbol = string.atoi(self.dps_field.text) self.attr.draw_symbol = self.draw_symbol_box.isSelected() self.attr.dash_type = self.dash_box.getSelectedItem() #print 'Updating Self.draw_symbol',self.draw_symbol,self.attr self.sym_panel.update()
def __init__(self, sattr): self.attr = sattr self.cbox = JColorChooser(self.attr.color) self.sz_field = JTextField(str(self.attr.size)) szpanel = JPanel() szpanel.add(self.sz_field) szpanel.setBorder( BorderFactory.createTitledBorder("symbol size (integer)")) self.filled_box = JCheckBox("Filled ?:", self.attr.filled) self.shape_cbox = JComboBox(SymbolProps.sym_shape_map.keys()) self.shape_cbox.setSelectedItem(self.attr.shape) self.shape_cbox.setBorder(BorderFactory.createTitledBorder("Shape")) panel1 = JPanel() panel1.setLayout(BorderLayout()) panel1.add(szpanel, BorderLayout.NORTH) panel2 = JPanel() panel2.setLayout(GridLayout(1, 2)) panel2.add(self.shape_cbox) panel2.add(self.filled_box) panel1.add(panel2, BorderLayout.SOUTH) self.setLayout(BorderLayout()) self.add(self.cbox, BorderLayout.CENTER) self.add(panel1, BorderLayout.SOUTH)
def __init__(self, sattr): self.attr = sattr self.cbox = JColorChooser(self.attr.color) self.sz_field = JTextField(str(self.attr.size)) szpanel = JPanel() szpanel.add(self.sz_field) szpanel.setBorder(BorderFactory.createTitledBorder("symbol size (integer)")) self.filled_box = JCheckBox("Filled ?:",self.attr.filled) self.shape_cbox = JComboBox(SymbolProps.sym_shape_map.keys()) self.shape_cbox.setSelectedItem(self.attr.shape) self.shape_cbox.setBorder(BorderFactory.createTitledBorder("Shape")) panel1 = JPanel() panel1.setLayout(BorderLayout()) panel1.add(szpanel,BorderLayout.NORTH) panel2 = JPanel() panel2.setLayout(GridLayout(1,2)) panel2.add(self.shape_cbox) panel2.add(self.filled_box) panel1.add(panel2,BorderLayout.SOUTH) self.setLayout(BorderLayout()) self.add(self.cbox,BorderLayout.CENTER) self.add(panel1,BorderLayout.SOUTH)
class EditSymbolAttr(JPanel): def __init__(self, sattr): self.attr = sattr self.cbox = JColorChooser(self.attr.color) self.sz_field = JTextField(str(self.attr.size)) szpanel = JPanel() szpanel.add(self.sz_field) szpanel.setBorder( BorderFactory.createTitledBorder("symbol size (integer)")) self.filled_box = JCheckBox("Filled ?:", self.attr.filled) self.shape_cbox = JComboBox(SymbolProps.sym_shape_map.keys()) self.shape_cbox.setSelectedItem(self.attr.shape) self.shape_cbox.setBorder(BorderFactory.createTitledBorder("Shape")) panel1 = JPanel() panel1.setLayout(BorderLayout()) panel1.add(szpanel, BorderLayout.NORTH) panel2 = JPanel() panel2.setLayout(GridLayout(1, 2)) panel2.add(self.shape_cbox) panel2.add(self.filled_box) panel1.add(panel2, BorderLayout.SOUTH) self.setLayout(BorderLayout()) self.add(self.cbox, BorderLayout.CENTER) self.add(panel1, BorderLayout.SOUTH) def setAttribute(self, sattr): self.attr = sattr self.cbox.color = self.attr.color self.sz_field.text = str(self.attr.size) self.shape_cbox.setSelectedItem(self.attr.shape) def update(self): self.attr.color = self.cbox.getColor() self.attr.size = string.atoi(self.sz_field.getText()) self.attr.filled = self.filled_box.isSelected() self.attr.shape = self.shape_cbox.getSelectedItem() self.attr.sym = self.attr.createSymbol()
def askColor(title, defaultColor): if isinstance(defaultColor, str): return JColorChooser.showDialog(None, title, X11Color.toColor(defaultColor)) else: return JColorChooser.showDialog(None, title, defaultColor)
def mouseClicked(self, event): color = JColorChooser.showDialog(self.frame, "Enter Color", self.panel.getBackground()) if color <> None: self.panel.setBackground(color)
def showStackOverlayWindow(self): all = JPanel() all.setLayout(MigLayout()) self.imageIDs = WindowManager.getIDList() self.imageNames = [] if self.imageIDs is None: IJ.error("No open images", "Stack Overlay requires at least one image to be already open.") return for i in self.imageIDs: self.imageNames.append(WindowManager.getImage(i).getTitle()) self.baseImageBox = JComboBox(self.imageNames) baseImageBoxLabel = JLabel("Base image") self.baseImageBox.setSelectedIndex(0) all.add(baseImageBoxLabel) all.add(self.baseImageBox, "wrap") self.overlayImageBox = JComboBox(self.imageNames) overlayImageBoxLabel = JLabel("Overlay image") if len(self.imageNames) > 1: self.overlayImageBox.setSelectedIndex(1) all.add(overlayImageBoxLabel) all.add(self.overlayImageBox, "wrap") all.add(JSeparator(SwingConstants.HORIZONTAL), "span, wrap") overlayStyleFrame = JPanel() overlayStyleFrame.setLayout(MigLayout()) overlayStyleFrame.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Overlay Style"), BorderFactory.createEmptyBorder(5,5,5,5))) colorLabel = JLabel("Overlay color") self.overlayColorPreviewLabel = JLabel(" ") self.overlayColorPreviewLabel.setBorder(BorderFactory.createEmptyBorder(0,0,1,0)) self.overlayColorPreviewLabel.setOpaque(True) self.overlayColorPreviewLabel.setBackground(Color.red) self.overlayColor = Color.red colorPicker = JColorChooser() colorPicker.setPreviewPanel(self.overlayColorPreviewLabel) colorButton = JButton("Select color...", actionPerformed=self.showColorChooser) opacityLabel = JLabel("Overlay opacity (%)") opacitySpinnerModel = SpinnerNumberModel(100, 0, 100, 1) self.opacitySpinner = JSpinner(opacitySpinnerModel) overlayStyleFrame.add(colorLabel) overlayStyleFrame.add(self.overlayColorPreviewLabel) overlayStyleFrame.add(colorButton, "wrap") overlayStyleFrame.add(opacityLabel) overlayStyleFrame.add(self.opacitySpinner, "wrap") all.add(overlayStyleFrame, "span, wrap") self.virtualStackCheckbox = JCheckBox("Use Virtual Stack", True) all.add(self.virtualStackCheckbox, "span, wrap") # TODO: add non-thermonuclear cancel button functionality overlayCancelButton = JButton("Cancel", actionPerformed=self.onQuit) overlayStartButton = JButton("Overlay images", actionPerformed=self.overlayImages) all.add(overlayCancelButton, "gapleft push") all.add(overlayStartButton, "gapleft push") self.frame = JFrame("Stack Overlay") self.frame.getContentPane().add(JScrollPane(all)) self.frame.pack() self.frame.setLocationRelativeTo(None) self.frame.setVisible(True)
def showColorChooser(self, e): colorChooser = JColorChooser() self.overlayColor = colorChooser.showDialog(self.frame, "Choose color", Color.red) self.overlayColorPreviewLabel.setBackground(self.overlayColor)
from java.awt import Color from javax.swing import JButton, JFrame, JColorChooser frame = JFrame() tcc = JColorChooser() tcc.showDialog(frame, "Test", Color.red)
def showStackOverlayWindow(self): all = JPanel() all.setLayout(MigLayout()) self.imageIDs = WindowManager.getIDList() self.imageNames = [] if self.imageIDs is None: IJ.error( "No open images", "Stack Overlay requires at least one image to be already open." ) return for i in self.imageIDs: self.imageNames.append(WindowManager.getImage(i).getTitle()) self.baseImageBox = JComboBox(self.imageNames) baseImageBoxLabel = JLabel("Base image") self.baseImageBox.setSelectedIndex(0) all.add(baseImageBoxLabel) all.add(self.baseImageBox, "wrap") self.overlayImageBox = JComboBox(self.imageNames) overlayImageBoxLabel = JLabel("Overlay image") if len(self.imageNames) > 1: self.overlayImageBox.setSelectedIndex(1) all.add(overlayImageBoxLabel) all.add(self.overlayImageBox, "wrap") all.add(JSeparator(SwingConstants.HORIZONTAL), "span, wrap") overlayStyleFrame = JPanel() overlayStyleFrame.setLayout(MigLayout()) overlayStyleFrame.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Overlay Style"), BorderFactory.createEmptyBorder(5, 5, 5, 5))) colorLabel = JLabel("Overlay color") self.overlayColorPreviewLabel = JLabel(" ") self.overlayColorPreviewLabel.setBorder( BorderFactory.createEmptyBorder(0, 0, 1, 0)) self.overlayColorPreviewLabel.setOpaque(True) self.overlayColorPreviewLabel.setBackground(Color.red) self.overlayColor = Color.red colorPicker = JColorChooser() colorPicker.setPreviewPanel(self.overlayColorPreviewLabel) colorButton = JButton("Select color...", actionPerformed=self.showColorChooser) opacityLabel = JLabel("Overlay opacity (%)") opacitySpinnerModel = SpinnerNumberModel(100, 0, 100, 1) self.opacitySpinner = JSpinner(opacitySpinnerModel) overlayStyleFrame.add(colorLabel) overlayStyleFrame.add(self.overlayColorPreviewLabel) overlayStyleFrame.add(colorButton, "wrap") overlayStyleFrame.add(opacityLabel) overlayStyleFrame.add(self.opacitySpinner, "wrap") all.add(overlayStyleFrame, "span, wrap") self.virtualStackCheckbox = JCheckBox("Use Virtual Stack", True) all.add(self.virtualStackCheckbox, "span, wrap") # TODO: add non-thermonuclear cancel button functionality overlayCancelButton = JButton("Cancel", actionPerformed=self.onQuit) overlayStartButton = JButton("Overlay images", actionPerformed=self.overlayImages) all.add(overlayCancelButton, "gapleft push") all.add(overlayStartButton, "gapleft push") self.frame = JFrame("Stack Overlay") self.frame.getContentPane().add(JScrollPane(all)) self.frame.pack() self.frame.setLocationRelativeTo(None) self.frame.setVisible(True)
def colorChooser(e): global color colorChooser = JColorChooser() color = colorChooser.showDialog(None, "Border Color", color) changeColorGUI(color) return