/** * Reassigns the set of canvases that this explorer controls. Though the collection of canvas may * be empty, it may not be null. * * @param items * @requires items != null && for each element in item, element!= null && the Collection is backed * by a type that gives a consistent iteration order */ public void setDrawersCard(Collection<? extends Canvas> items) { canvases.clear(); buttonPane.removeAll(); int size = items.size(); if (size % 2 == 1) size++; size = buttonHeight * size; buttonPane.setPreferredSize(new Dimension(6, size)); int i = 0; for (Canvas item : items) { final int index = i; // final CButton button = new CButton(item.getColor(), // item.getColor().brighter().brighter().brighter(),item.getName()); CButton button = new CBorderlessButton(item.getName()); JComponent scroll = new CHoverScrollPane( item.getJComponent(), ScrollPolicy.VERTICAL_BAR_AS_NEEDED, ScrollPolicy.HORIZONTAL_BAR_AS_NEEDED, 18, item.getColor(), Color.darkGray); canvases.add(scroll); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { selectCanvas(index); } }); buttonPane.add(button); i++; } if (!canvases.isEmpty()) canvasPane.add(canvases.get(0)); this.revalidate(); }
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new FlowLayout()); f.setSize(500, 300); f.getContentPane().setBackground(Color.red); final CButton c = new CGraphiteButton("hi"); f.add(c); f.setVisible(true); f.repaint(); final CPopupMenu menu = new CPopupMenu(); for (int i = 0; i < 17; i++) { menu.add(new CMenuItem("hi")); } c.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { menu.show(c, 0, 0); } }); c.add(menu); System.out.println(menu.getParent()); }
// Constructor connection receiving a socket number public ClientGUI(String host, int port, int udpPort) { super("Clash of Clans"); defaultPort = port; defaultUDPPort = udpPort; defaultHost = host; // the server name and the port number JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3)); tfServer = new JTextField(host); tfPort = new JTextField("" + port); tfPort.setHorizontalAlignment(SwingConstants.RIGHT); // CHAT COMPONENTS chatStatus = new JLabel("Please login first", SwingConstants.LEFT); chatField = new JTextField(18); chatField.setBackground(Color.WHITE); JPanel chatControls = new JPanel(); chatControls.add(chatStatus); chatControls.add(chatField); chatControls.setBounds(0, 0, 200, 50); chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80); chatArea.setEditable(false); JScrollPane jsp = new JScrollPane(chatArea); jsp.setBounds(0, 50, 200, 550); JPanel chatPanel = new JPanel(null); chatPanel.setSize(1000, 600); chatPanel.add(chatControls); chatPanel.add(jsp); // LOGIN COMPONENTS mainLogin = new MainPanel(); mainLogin.add(new JLabel("Main Login")); usernameField = new JTextField("user", 15); passwordField = new JTextField("password", 15); login = new CButton("Login"); login.addActionListener(this); sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT)); sideLogin.add(usernameField); sideLogin.add(passwordField); sideLogin.add(login); // MAIN MENU COMPONENTS mainMenu = new MainPanel(); mmLabel = new JLabel("Main Menu"); timer = new javax.swing.Timer(1000, this); mainMenu.add(mmLabel); sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT)); cmButton = new CButton("Customize Map"); tmButton = new CButton("Troop Movement"); gsButton = new CButton("Game Start"); logout = new CButton("Logout"); cmButton.addActionListener(this); tmButton.addActionListener(this); gsButton.addActionListener(this); logout.addActionListener(this); sideMenu.add(cmButton); // sideMenu.add(tmButton); sideMenu.add(gsButton); sideMenu.add(logout); // CM COMPONENTS mainCM = new MainPanel(new GridLayout(mapSize, mapSize)); tiles = new Tile[mapSize][mapSize]; int tileSize = mainCM.getWidth() / mapSize; for (int i = 0; i < mapSize; i++) { tiles[i] = new Tile[mapSize]; for (int j = 0; j < mapSize; j++) { tiles[i][j] = new Tile(i, j); tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize)); tiles[i][j].setSize(tileSize, tileSize); tiles[i][j].addActionListener(this); if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51)); else tiles[i][j].setBackground(new Color(51, 204, 51)); mainCM.add(tiles[i][j]); } } sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT)); cmBack = new CButton("Main Menu"); cmBack.setSize(150, 30); cmBack.setPreferredSize(new Dimension(150, 30)); cmBack.addActionListener(this); sideCM.add(cmBack); // TM COMPONENTS mainTM = new MainPanel(null); mapTM = new Map(600); mapTM.setPreferredSize(new Dimension(600, 600)); mapTM.setSize(600, 600); mapTM.setBounds(0, 0, 600, 600); mainTM.add(mapTM); sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT)); tmBack = new CButton("Main Menu"); tmBack.setSize(150, 30); tmBack.setPreferredSize(new Dimension(150, 30)); tmBack.addActionListener(this); sideTM.add(tmBack); JRadioButton button; ButtonGroup group; ub = new ArrayList<JRadioButton>(); group = new ButtonGroup(); button = new JRadioButton("Barbarian"); button.addActionListener(this); ub.add(button); sideTM.add(button); group.add(button); button = new JRadioButton("Archer"); button.addActionListener(this); ub.add(button); sideTM.add(button); group.add(button); createBuildings(); bb = new ArrayList<JRadioButton>(); group = new ButtonGroup(); JRadioButton removeButton = new JRadioButton("Remove Building"); bb.add(removeButton); sideCM.add(removeButton); group.add(removeButton); for (int i = 0; i < bList.size(); i++) { button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity()); bb.add(button); sideCM.add(button); group.add(button); } mainPanels = new MainPanel(new CardLayout()); mainPanels.add(mainLogin, "Login"); mainPanels.add(mainMenu, "Menu"); mainPanels.add(mainCM, "CM"); mainPanels.add(mainTM, "TM"); sidePanels = new SidePanel(new CardLayout()); sidePanels.add(sideLogin, "Login"); sidePanels.add(sideMenu, "Menu"); sidePanels.add(sideCM, "CM"); sidePanels.add(sideTM, "TM"); JPanel mainPanel = new JPanel(null); mainPanel.setSize(1000, 600); mainPanel.add(sidePanels); mainPanel.add(mainPanels); mainPanel.add(chatPanel); add(mainPanel, BorderLayout.CENTER); try { setIconImage(ImageIO.read(new File("images/logo.png"))); } catch (IOException exc) { exc.printStackTrace(); } setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(1000, 600); setVisible(true); setResizable(false); chatField.requestFocus(); }
/** Dynamic Init. Table Layout, Visual, Listener */ private void dynInit() { ColumnInfo[] layout = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class), // 1 new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), ".", String.class) // 2 }; xProductTable.prepareTable(layout, "", "", false, ""); xAssociateTable.prepareTable(layout, "", "", true, ""); xAssociateTable.setAutoResizeMode(3); xProductTable.setAutoResizeMode(3); // Visual CompiereColor.setBackground(this); // Listener xProductTable.getSelectionModel().addListSelectionListener(this); xAssociateTable.getModel().addTableModelListener(this); bDisassociate.addActionListener(this); bNewProduct.addActionListener(this); // pregunto si hay productos asociados para ver si cargo las tablas boolean ready = verify(); if (ready == false) { tableInit_option = 0; tableInit(); tableLoad(xProductTable); } else { tableInit_option = 1; tableInit(); tableLoad(xAssociateTable); bNewProduct.setEnabled(false); bDisassociate.setEnabled(true); } xProductTable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int rowP = xProductTable.getSelectedRow(); if (!(rowP == -1)) { cmd_associate(); } } } }); // Init statusBar.setStatusLine(""); statusBar.setStatusDB(0); MOrder order = new MOrder(Env.getCtx(), LineRefProv.getC_Order_ID(), null); boolean block = false; String oS = order.getXX_OrderStatus(); String compS = order.getDocStatus(); if (oS.equals("AN") || compS.equals("CO")) { block = true; } if (order.isXX_OrderReadyStatus() && order.getXX_OrderType().equalsIgnoreCase("Nacional")) block = true; if (order.getXX_OrderType().equalsIgnoreCase("Importada") && order.get_ValueAsInt("XX_ImportingCompany_ID") != 0) { if (order.get_ValueAsInt("XX_ImportingCompany_ID") != Env.getCtx().getContextAsInt("#XX_L_VSI_CLIENTCENTROBECO_ID")) { block = true; } } if (order.getXX_StoreDistribution().equals("Y") || block) { xProductTable.setEnabled(false); xAssociateTable.setEnabled(false); bNewProduct.setEnabled(false); bDisassociate.setEnabled(false); } } // dynInit