def __init__(self, program): self.setLayout(BorderLayout()) title = JLabel(program.title) title.setFont(Font("Arial", Font.BOLD, 28)) title.setHorizontalAlignment(JLabel.CENTER) title.setVerticalAlignment(JLabel.CENTER) title.setBorder(createEmptyBorder(15, 5, 15, 5)) if not program.public: lbl = JLabel("Private") lbl.setFont(Font("Arial", Font.BOLD, 20)) lbl.setForeground(Color(0xFF2424)) lbl.setBorder(createEmptyBorder(15, 15, 15, 15)) leftbox = lbl else: leftbox = Box.createHorizontalGlue() btnbox = TitleBtnBox(program) btnbox.setBorder(createEmptyBorder(5, 5, 5, 5)) self.add(leftbox, BorderLayout.LINE_START) self.add(title, BorderLayout.CENTER) self.add(btnbox, BorderLayout.LINE_END) same_size(leftbox, btnbox) self.setMaximumSize(Dimension(99999, self.getPreferredSize().height))
def __init__(self): self.setAlwaysOnTop(False); self.setSize(500, 500); menubar = JMenuBar(); menu = JMenu("A Menu"); menu_ac = menu.getAccessibleContext(); menu_ac.setAccessibleDescription("The only menu in this program"); menuitem = JMenuItem("A Menu Item"); menu.add(menuitem); menubar.add(menu); self.setJMenuBar(menubar); lbl = JLabel("A Label"); lbl.setHorizontalAlignment(JLabel.CENTER); lbl.setVerticalAlignment(JLabel.CENTER); self.setContentPane(lbl); self.setVisible(True);
class AlbumArt(SongContextView): def __init__(self): # set up the layout self.__component = JPanel(GridBagLayout()) self.__image = JLabel() self.__album = JLabel() self.__artist = JLabel() self.__application = None self.__image.setVerticalAlignment(SwingConstants.TOP) self.__album.setVerticalAlignment(SwingConstants.TOP) self.__artist.setVerticalAlignment(SwingConstants.TOP) gbc = GridBagConstraints() gbc.fill = GridBagConstraints.VERTICAL gbc.anchor = GridBagConstraints.NORTHWEST gbc.gridx = 0 gbc.gridy = 0 gbc.weighty = 2 gbc.gridheight = 2 self.__component.add(self.__image, gbc) gbc.fill = GridBagConstraints.HORIZONTAL gbc.anchor = GridBagConstraints.NORTHWEST gbc.gridx = 1 gbc.gridy = 0 gbc.gridheight = 1 gbc.weighty = 0 gbc.insets = Insets(0, 10, 0, 10) self.__component.add(self.__album, gbc) gbc.fill = GridBagConstraints.BOTH gbc.anchor = GridBagConstraints.NORTHWEST gbc.gridx = 1 gbc.gridy = 1 gbc.weightx = 2 gbc.weighty = 2 gbc.gridheight = 1 self.__component.add(self.__artist, gbc) # Is called when this view should be updated. def update(self, song): # check for None! if (song != None): albumArt = song.getImage() if (albumArt != None): self.__image.setIcon(ImageIcon(ImageScaler.scale(albumArt, 300, 300))); else: self.__image.setIcon(None); self.__album.setText("<html><font size='+3'>" + song.getAlbum() + "</font></html>"); self.__artist.setText("<html><font color='#555555' size='-1'>by " + song.getArtist() + "</font></html>"); else: self.__image.setIcon(None); self.__album.setText(None); self.__artist.setText(None); # Every SongContextView needs to be accompanied by a # SongContextComponentShowHideAction. # Return the action's id here. def getShowHideActionId(self): return "jython.albumart.showhide" # The visual component to be shown in this view. def getComponent(self): return self.__component def setApplication(self, application): self.__application = application def getApplication(self): return self.__application def getId(self): return "jython.albumart" def init(self): pass def shutdown(self): pass