public EchoAWT() throws UnknownHostException { super("채팅 프로그램"); // 각종 정의 h = new JPanel(new GridLayout(2, 3)); m = new JPanel(new BorderLayout()); f = new JPanel(new BorderLayout()); s = new JPanel(new BorderLayout()); login = new JPanel(new BorderLayout()); // name = new JLabel(" 사용자 이름 "); name = new JLabel(" 메세지 입력 "); jta = new JTextArea(); // clientList = new JTextArea(0, 10); clientList = new JList(); jsp = new JScrollPane(jta); list = new JScrollPane(clientList); jtf = new JTextField("입력하세요."); hi = new JTextField("HOST IP 입력"); pi = new JTextField("PORT 입력"); localport = new JTextField("원하는 PORT 입력"); lid = new JTextField("ID를 입력하세요."); lpw = new JTextField("PW를 입력하세요."); serveropen = new JButton("서버 오픈"); textin = new JButton("입력"); clientin = new JButton("서버 접속"); conf = new JButton("로그인"); join = new JButton("회원가입"); addr = InetAddress.getLocalHost(); // 사용자 해상도 및 창 크기 설정 및 가져오기. Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); setSize(500, 500); Dimension d = getSize(); // 각종 버튼 및 텍스트 필드 리스너 jtf.addActionListener(this); hi.addActionListener(this); pi.addActionListener(this); localport.addActionListener(this); lid.addActionListener(this); lpw.addActionListener(this); conf.addActionListener(this); join.addActionListener(this); serveropen.addActionListener(this); clientin.addActionListener(this); textin.addActionListener(this); jtf.addFocusListener(this); hi.addFocusListener(this); pi.addFocusListener(this); localport.addFocusListener(this); lid.addFocusListener(this); lpw.addFocusListener(this); // 서버 접속 h.add(hi); h.add(pi); h.add(clientin); // 서버 생성 h.add(new JLabel("IP : " + addr.getHostAddress(), (int) CENTER_ALIGNMENT)); h.add(localport); h.add(serveropen); // 채팅글창 글 작성 막기 jta.setEditable(false); // 접속자 리스트 width 제한 clientList.setFixedCellWidth(d.width / 3); // 입력 창 f.add(name, "West"); f.add(jtf, "Center"); f.add(textin, "East"); // 접속자 확인창 s.add(new JLabel("접속자", (int) CENTER_ALIGNMENT), "North"); s.add(list, "Center"); // clientList.setEditable(false); // 메인 창 m.add(jsp, "Center"); m.add(s, "East"); // 프레임 설정 add(h, "North"); add(m, "Center"); add(f, "South"); // 로그인 다이얼로그 jd = new JDialog(); jd.setTitle("채팅 로그인"); jd.add(login); jd.setSize(200, 200); Dimension dd = jd.getSize(); jd.setLocation(screenSize.width / 2 - (dd.width / 2), screenSize.height / 2 - (dd.height / 2)); jd.setVisible(true); // 로그인창 JPanel lm = new JPanel(new GridLayout(4, 1)); lm.add(lid); lm.add(new Label()); lm.add(lpw); lm.add(new Label()); JPanel bt = new JPanel(); bt.add(conf); bt.add(join); login.add(new Label(), "North"); login.add(new Label(), "West"); login.add(new Label(), "East"); login.add(lm, "Center"); login.add(bt, "South"); // 창의 위치, 보임, EXIT 단추 활성화. setLocation(screenSize.width / 2 - (d.width / 2), screenSize.height / 2 - (d.height / 2)); setVisible(false); setDefaultCloseOperation(EXIT_ON_CLOSE); }
public SQLiteDataBrowser() { SQLiteDbManager dbManager = new SQLiteDbManager(); setLayout(new BorderLayout()); showTablesList = new JList(); showTablesList.setLayoutOrientation(JList.VERTICAL_WRAP); showTablesList.setSelectedIndex(ListSelectionModel.SINGLE_SELECTION); showTablesList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); showTablesList.setFont(new Font("Times New Roman", Font.PLAIN, 13)); showTablesList.setDragEnabled(false); showTablesList.setFixedCellWidth(150); showTablesList.setVisibleRowCount(-1); showTablesList.setEnabled(false); showTablesListScroller = new JScrollPane(showTablesList); showTablesListScroller.setBorder( BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "List of Tables")); showTablesListScroller.setPreferredSize(new Dimension(160, this.getHeight())); add(showTablesListScroller, BorderLayout.EAST); loadDbPanel = new JPanel(new FlowLayout()); loadDbPanel.setBackground(new Color(0xe8e8e8)); loadDbPanel.setPreferredSize(new Dimension(getWidth(), 40)); loadDbLabel = new JLabel("Load SQLite Database: "); loadDbLabel.setToolTipText("Possible extensions being .sqlite|.sqlite3|.db|.db3"); loadedDbPath = new JTextField("Click browse to choose the database file.", 60); loadedDbPath.setForeground(Color.GRAY); loadedDbPath.setFont(new Font("Times New Roman", Font.ITALIC, 13)); loadedDbPath.setEditable(false); lastFolderLocation = new File(Utils.getUserHome()); fc = new JFileChooser(lastFolderLocation); browseDb = new JButton("Browse"); browseDb.addActionListener( actionEvent -> { int retVal = fc.showOpenDialog(SQLiteDataBrowser.this); if (retVal == JFileChooser.APPROVE_OPTION) { File dbPath = fc.getSelectedFile(); if (Utils.checkIfSQLiteDb(dbPath)) { loadedDbPath.setText(dbPath.toString()); lastFolderLocation = fc.getCurrentDirectory(); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { dbManager.setDbPath(dbPath.toString()); dbManager.initialize(); showTablesList.setListData(dbManager.getTables().toArray()); showTablesList.setEnabled(true); } catch (SQLException e) { e.printStackTrace(); } return null; } }.execute(); } else { JOptionPane.showMessageDialog( SQLiteDataBrowser.this, "The Selected file is not in SQLite Format", "File Format Error", JOptionPane.ERROR_MESSAGE); loadedDbPath.setText("Click browse to choose the database file."); } } }); loadDbPanel.add(loadDbLabel); loadDbPanel.add(loadedDbPath); loadDbPanel.add(browseDb); loadDbRecords = new JLabel("Records Fetched (Rows x Cols): "); loadDbRecords.setFont(new Font("Times New Roman", Font.ITALIC, 12)); loadDbPanel.add(loadDbRecords); loadDbRecordsCount = new JLabel(); loadDbRecordsCount.setFont(new Font("Times New Roman", Font.ITALIC, 12)); loadDbPanel.add(loadDbRecordsCount); final class DataBrowserTableModal extends DefaultTableModel { public DataBrowserTableModal() {} public DataBrowserTableModal(Object[][] tableData, Object[] colNames) { super(tableData, colNames); } @Override public void setDataVector(Object[][] tableData, Object[] colNames) { super.setDataVector(tableData, colNames); } @Override public boolean isCellEditable(int row, int column) { return false; } } DataBrowserTableModal tableModal = new DataBrowserTableModal(); defaultTableModel = tableModal; table = new JTable(); table.setModel(defaultTableModel); showTablesList.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { JList list = (JList) evt.getSource(); if (evt.getClickCount() == 2) { String tableName = list.getSelectedValue().toString(); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { ResultSet rs = dbManager.executeQuery("SELECT * from " + tableName); Vector<String> columnNames = dbManager.getColumnNames(rs); Vector<Vector<Object>> tableData = new Vector<>(); while (rs.next()) { Vector<Object> vector = new Vector<>(); for (int i = 1; i <= columnNames.size(); i++) { vector.add(rs.getObject(i)); } tableData.add(vector); } defaultTableModel.setDataVector(tableData, columnNames); } catch (SQLException e) { e.printStackTrace(); } loadDbRecordsCount.setText( defaultTableModel.getRowCount() + " x " + defaultTableModel.getColumnCount()); if (defaultTableModel.getColumnCount() < 5) { table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); } else { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); } return null; } }.execute(); } } }); tableScrollPane = new JScrollPane(table); tableScrollPane.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); tableScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); tableScrollPane.setPreferredSize(new Dimension(getWidth(), getHeight())); add(tableScrollPane, BorderLayout.CENTER); add(loadDbPanel, BorderLayout.NORTH); }
/** GUI element creating and arrangment. Partially generated using NetBeans IDE GUI utilities. */ @SuppressWarnings("unchecked") private void initComponents() { jButtonOldPackages = new JButton(); jTextDate = new JTextField(); jButtonSetLost = new JButton(); jButtonSetFound = new JButton(); jButtonShowLost = new JButton(); jButtonExit = new JButton(); jButtonReset = new JButton(); jScrollPane1 = new JScrollPane(); jListScans = new JList(); jScrollPane2 = new JScrollPane(); jListPackages = new JList(); jButtonSetFound.setEnabled(false); jButtonSetLost.setEnabled(false); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButtonOldPackages.setText("Timed out packages"); jButtonOldPackages.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { buttonOldPackagesActionPerformed(event); } }); ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { jListPackagesActionPertformed(event); } }; jButtonExit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); jButtonSetLost.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { buttonSetLostActionPerformed(event); } }); jButtonSetFound.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { buttonSetFoundActionPerformed(event); } }); jButtonShowLost.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { buttonShowLostActionPerformed(event); } }); jButtonReset.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { reset(event); } }); jListPackages.addListSelectionListener(listSelectionListener); jButtonSetLost.setText("List as Lost"); jButtonShowLost.setText("Lost Packages"); jButtonSetFound.setText("List as Found"); jButtonExit.setText("Logout"); jButtonReset.setText("Reset"); jScrollPane2.setViewportView(jListPackages); jScrollPane2.setPreferredSize(new Dimension(200, 200)); jListPackages.setFixedCellWidth(400); jScrollPane1.setViewportView(jListScans); // Layout javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addComponent( jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(111, 111, 111) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(111, 111, 111) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jTextDate, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jButtonSetLost, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( jButtonOldPackages, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( jButtonShowLost, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( jButtonSetFound, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButtonReset, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButtonExit, javax.swing.GroupLayout.Alignment.TRAILING)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGap(42, 42, 42) .addComponent( jTextDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonOldPackages) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonSetLost) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonSetFound) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonShowLost) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonReset) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonExit)) .addGroup( layout .createSequentialGroup() .addContainerGap() .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent( jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)) .addContainerGap())); pack(); }
public EditPackageDialog(JFrame frame) { super(frame, "Package Management- Edit a TV Package", true); label1 = new JLabel("Package Code: "); label2 = new JLabel("Package Name: "); error3 = new JLabel("Blank input occured! Please reenter it."); label3 = new JLabel("Charge Price(RM): "); error4 = new JLabel("Blank input occured! Please reenter it."); error6 = new JLabel("Wrong input format. Please enter in numeric format!"); label4 = new JLabel("Charge Type: "); error5 = new JLabel("Blank input occured! Please reenter it."); error7 = new JLabel("You must have at least one programme added to your package."); label5 = new JLabel("Programmes: "); label6 = new JLabel("Programmes inside this Package: "); textfield1 = new JTextField(15); textfield2 = new JTextField(15); textfield3 = new JTextField(15); textfield3.setEditable(false); combobox1 = new JComboBox(); button1 = new JButton("Submit"); button2 = new JButton("Cancel"); addBut = new JButton("", new ImageIcon(getClass().getResource("/resources/addtoright.png"))); rmvBut = new JButton("", new ImageIcon(getClass().getResource("/resources/removetoleft.png"))); addBut.setBackground(new Color(23, 28, 31)); rmvBut.setBackground(new Color(23, 28, 31)); color = new Color(23, 28, 30); color1 = new Color(244, 219, 234); color2 = new Color(239, 237, 237); textfield3.setBackground(color2); selPrgList = new LinkedList<>(); leftModel = new DefaultListModel(); rightModel = new DefaultListModel(); for (int i = 0; i < App.prgList.size(); i++) { for (int j = 0; j < App.pckgingList.size(); j++) { if (PackagePanel.pkgtemp[0].equalsIgnoreCase(App.pckgingList.get(j).getPkgCode())) { if (App.pckgingList .get(j) .getProgCode() .equalsIgnoreCase(App.prgList.get(i).getProgCode())) { selPrgList.add(App.pckgingList.get(j).getProgCode()); ((DefaultListModel) rightModel) .addElement( App.pckgingList.get(j).getProgCode() + "-" + App.prgList.get(i).getProgTitle()); } } } } selPrg = selPrgList.toArray(new String[selPrgList.size()]); for (int i = 0; i < App.prgList.size(); i++) { boolean check = false; for (int j = 0; j < selPrg.length; j++) { if (selPrg[j].equalsIgnoreCase(App.prgList.get(i).getProgCode())) { check = true; break; } } if (check == false) { if (!(App.prgList.get(i).getPrgStatus().equalsIgnoreCase("TERMINATED"))) { ((DefaultListModel) leftModel) .addElement( App.prgList.get(i).getProgCode() + "-" + App.prgList.get(i).getProgTitle()); } } } leftList = new JList(leftModel); leftList.setModel(leftModel); leftList.setVisibleRowCount(13); leftList.setFixedCellWidth(210); leftList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); rightList = new JList(rightModel); rightList.setModel(rightModel); rightList.setVisibleRowCount(13); rightList.setFixedCellWidth(210); rightList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); leftListScroll = new JScrollPane(leftList); leftListScroll.setViewportView(leftList); rightListScroll = new JScrollPane(rightList); rightListScroll.setViewportView(rightList); Container container = getContentPane(); container.setBackground(color); SpringLayout spring = new SpringLayout(); String[] string1 = { "<-----Please Choose a charge type----->", "Monthly", "Quarterly", "Annually" }; combobox1.setModel(new DefaultComboBoxModel(string1)); error3.setForeground(Color.RED); error4.setForeground(Color.RED); error5.setForeground(Color.RED); error6.setForeground(Color.RED); error7.setForeground(Color.RED); error3.setVisible(false); error4.setVisible(false); error5.setVisible(false); error6.setVisible(false); error7.setVisible(false); label1.setForeground(color1); label2.setForeground(color1); label3.setForeground(color1); label4.setForeground(color1); label5.setForeground(color1); label6.setForeground(color1); textfield3.setText(PackagePanel.pkgtemp[0]); textfield1.setText(PackagePanel.pkgtemp[1]); textfield2.setText(PackagePanel.pkgtemp[2]); combobox1.setSelectedItem((String) (PackagePanel.pkgtemp[3])); addBut.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int leftIndex = leftList.getSelectedIndex(); String toBeAdded = ((String) leftList.getModel().getElementAt(leftIndex)); LinkedList<String> leftElements = new LinkedList<>(); for (int p = 0; p < leftList.getModel().getSize(); p++) { leftElements.add((String) leftList.getModel().getElementAt(p)); } for (int i = 0; i < leftElements.size(); i++) { if ((leftElements.get(i)).equals(toBeAdded)) { leftElements.remove(i); break; } } String[] leftElArr = leftElements.toArray(new String[leftElements.size()]); leftList.setListData(leftElArr); leftList.revalidate(); leftList.repaint(); rightElements = new LinkedList<>(); for (int z = 0; z < rightList.getModel().getSize(); z++) { rightElements.add((String) rightList.getModel().getElementAt(z)); } rightElements.add(toBeAdded); rightElArr = rightElements.toArray(new String[rightElements.size()]); rightList.setListData(rightElArr); rightList.repaint(); rightList.revalidate(); } catch (Exception ex) { JOptionPane.showMessageDialog( null, "You can only add a TV Programme from the left list.", "Adding error", JOptionPane.INFORMATION_MESSAGE); } } }); rmvBut.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int rightIndex = rightList.getSelectedIndex(); String toBeRemoved = ((String) rightList.getModel().getElementAt(rightIndex)); LinkedList<String> rightElements = new LinkedList<>(); for (int p = 0; p < rightList.getModel().getSize(); p++) { rightElements.add((String) rightList.getModel().getElementAt(p)); } for (int i = 0; i < rightElements.size(); i++) { if ((rightElements.get(i)).equals(toBeRemoved)) { rightElements.remove(i); break; } } rightElArr = rightElements.toArray(new String[rightElements.size()]); rightList.setListData(rightElArr); rightList.revalidate(); rightList.repaint(); LinkedList<String> leftElements = new LinkedList<>(); for (int z = 0; z < leftList.getModel().getSize(); z++) { leftElements.add((String) leftList.getModel().getElementAt(z)); } leftElements.add(toBeRemoved); String[] leftElArr = leftElements.toArray(new String[leftElements.size()]); leftList.setListData(leftElArr); leftList.repaint(); leftList.revalidate(); } catch (Exception ex) { JOptionPane.showMessageDialog( null, "You can only remove a TV Programme from the right list when right list is filled in with TV Programme.", "Remove error", JOptionPane.INFORMATION_MESSAGE); } } }); button1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean flag1 = false, flag2 = false, flag3 = false, flag4 = false; if ((textfield1.getText().trim() == null) || (textfield1.getText().trim().equalsIgnoreCase(""))) { error3.setVisible(true); flag1 = false; } else { flag1 = true; error3.setVisible(false); } if ((textfield2.getText().trim() == null) || (textfield2.getText().trim().equalsIgnoreCase(""))) { error4.setVisible(true); error6.setVisible(false); flag2 = false; } else { try { flag2 = true; error4.setVisible(false); error6.setVisible(false); double a = Double.valueOf(textfield2.getText().trim()).doubleValue(); } catch (NumberFormatException ex) { error4.setVisible(false); error6.setVisible(true); flag2 = false; } } if ((((String) combobox1.getSelectedItem())) .equals("<-----Please Choose a charge type----->")) { error5.setVisible(true); flag3 = false; } else { flag3 = true; error5.setVisible(false); } try { if (rightElArr.length >= 1) { flag4 = true; error7.setVisible(false); } else { flag4 = false; error7.setVisible(true); } } catch (NullPointerException npe) { flag4 = true; } if ((flag1 == true) && (flag2 == true) && (flag3 == true) && (flag4 == true)) { for (int i = 0; i < App.pkgList.size(); i++) { if (App.pkgList.get(i).getPkgCode().equalsIgnoreCase(PackagePanel.pkgtemp[0])) { App.pkgList.get(i).setPkgName(textfield1.getText()); break; } } for (int i = 0; i < App.pkgList.size(); i++) { if (App.pkgList.get(i).getPkgCode().equalsIgnoreCase(PackagePanel.pkgtemp[0])) { App.pkgList .get(i) .setChargePrice(Double.valueOf(textfield2.getText().trim()).doubleValue()); break; } } for (int i = 0; i < App.pkgList.size(); i++) { if (App.pkgList.get(i).getPkgCode().equalsIgnoreCase(PackagePanel.pkgtemp[0])) { App.pkgList.get(i).setChargeType(combobox1.getSelectedItem().toString()); break; } } if (rightElArr != null) { for (int i = 0; i < App.pckgingList.size(); i++) { if (App.pckgingList .get(i) .getPkgCode() .equalsIgnoreCase(PackagePanel.pkgtemp[0])) { App.pckgingList.remove(i); i--; } } for (int i = 0; i < rightElArr.length; i++) { App.pckgingList.addLast( new Packaging(PackagePanel.pkgtemp[0], (rightElArr[i]).substring(0, 4))); } } else { for (int i = 0; i < App.prgList.size(); i++) { for (int j = 0; j < App.pckgingList.size(); j++) { if (PackagePanel.pkgtemp[0].equalsIgnoreCase( App.pckgingList.get(j).getPkgCode())) { if (App.pckgingList .get(j) .getProgCode() .equalsIgnoreCase(App.prgList.get(i).getProgCode())) { selPrgList.add(App.pckgingList.get(j).getProgCode()); ((DefaultListModel) rightModel) .addElement( App.pckgingList.get(j).getProgCode() + "-" + App.prgList.get(i).getProgTitle()); } } } } } JOptionPane.showMessageDialog( null, "You have successfully changed the details of TV Package " + PackagePanel.pkgtemp[0] + " !", PackagePanel.pkgtemp[0] + " edited", JOptionPane.PLAIN_MESSAGE); LogFile log = new LogFile( App.user, "has edited a TV Package '" + PackagePanel.pkgtemp[0] + "'."); App.logList.add(log); dispose(); } } }); button2.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int closeCf = JOptionPane.showConfirmDialog( null, "Stop Adding? All the changes will not be saved.", "Cancel Adding", JOptionPane.WARNING_MESSAGE); if (closeCf == JOptionPane.YES_OPTION) { dispose(); } } }); container.setLayout(spring); container.add(label1); container.add(textfield3); spring.putConstraint(SpringLayout.WEST, label1, 20, SpringLayout.WEST, container); spring.putConstraint(SpringLayout.NORTH, label1, 15, SpringLayout.NORTH, container); spring.putConstraint(SpringLayout.WEST, textfield3, 80, SpringLayout.EAST, label1); spring.putConstraint(SpringLayout.NORTH, textfield3, 15, SpringLayout.NORTH, container); container.add(label2); container.add(textfield1); container.add(error3); spring.putConstraint(SpringLayout.WEST, label2, 20, SpringLayout.WEST, container); spring.putConstraint(SpringLayout.NORTH, label2, 40, SpringLayout.SOUTH, label1); spring.putConstraint(SpringLayout.WEST, textfield1, 80, SpringLayout.EAST, label1); spring.putConstraint(SpringLayout.NORTH, textfield1, 30, SpringLayout.SOUTH, textfield3); spring.putConstraint(SpringLayout.NORTH, error3, -27, SpringLayout.SOUTH, textfield1); spring.putConstraint(SpringLayout.WEST, error3, 260, SpringLayout.EAST, label2); container.add(label3); container.add(textfield2); container.add(error4); container.add(error6); spring.putConstraint(SpringLayout.WEST, label3, 20, SpringLayout.WEST, container); spring.putConstraint(SpringLayout.NORTH, label3, 45, SpringLayout.SOUTH, label2); spring.putConstraint(SpringLayout.WEST, textfield2, 80, SpringLayout.EAST, label1); spring.putConstraint(SpringLayout.NORTH, textfield2, 30, SpringLayout.SOUTH, textfield1); spring.putConstraint(SpringLayout.NORTH, error4, -26, SpringLayout.SOUTH, textfield2); spring.putConstraint(SpringLayout.WEST, error4, 251, SpringLayout.EAST, label3); spring.putConstraint(SpringLayout.NORTH, error6, -26, SpringLayout.SOUTH, textfield2); spring.putConstraint(SpringLayout.WEST, error6, 251, SpringLayout.EAST, label3); container.add(label4); container.add(combobox1); container.add(error5); spring.putConstraint(SpringLayout.WEST, label4, 20, SpringLayout.WEST, container); spring.putConstraint(SpringLayout.NORTH, label4, 40, SpringLayout.SOUTH, label3); spring.putConstraint(SpringLayout.WEST, combobox1, 80, SpringLayout.EAST, label1); spring.putConstraint(SpringLayout.NORTH, combobox1, 30, SpringLayout.SOUTH, textfield2); spring.putConstraint(SpringLayout.NORTH, error5, -26, SpringLayout.SOUTH, combobox1); spring.putConstraint(SpringLayout.WEST, error5, 320, SpringLayout.EAST, label3); container.add(label5); container.add(label6); spring.putConstraint(SpringLayout.WEST, label5, 20, SpringLayout.WEST, container); spring.putConstraint(SpringLayout.NORTH, label5, 20, SpringLayout.SOUTH, label4); spring.putConstraint(SpringLayout.WEST, label6, 280, SpringLayout.EAST, label5); spring.putConstraint(SpringLayout.NORTH, label6, 20, SpringLayout.SOUTH, label4); container.add(leftListScroll); container.add(addBut); container.add(rmvBut); container.add(rightListScroll); container.add(error7); spring.putConstraint(SpringLayout.WEST, leftListScroll, 20, SpringLayout.WEST, container); spring.putConstraint(SpringLayout.NORTH, leftListScroll, 45, SpringLayout.SOUTH, label4); spring.putConstraint(SpringLayout.WEST, addBut, 35, SpringLayout.EAST, leftListScroll); spring.putConstraint(SpringLayout.NORTH, addBut, 52, SpringLayout.SOUTH, label4); spring.putConstraint(SpringLayout.WEST, rmvBut, 25, SpringLayout.EAST, leftListScroll); spring.putConstraint(SpringLayout.NORTH, rmvBut, 10, SpringLayout.SOUTH, addBut); spring.putConstraint(SpringLayout.WEST, rightListScroll, 24, SpringLayout.EAST, rmvBut); spring.putConstraint(SpringLayout.NORTH, rightListScroll, 45, SpringLayout.SOUTH, label4); spring.putConstraint(SpringLayout.WEST, error7, 40, SpringLayout.EAST, label4); spring.putConstraint(SpringLayout.NORTH, error7, 345, SpringLayout.SOUTH, label4); container.add(button1); container.add(button2); spring.putConstraint(SpringLayout.WEST, button1, 222, SpringLayout.WEST, container); spring.putConstraint(SpringLayout.NORTH, button1, 362, SpringLayout.SOUTH, combobox1); spring.putConstraint(SpringLayout.WEST, button2, 222, SpringLayout.EAST, label2); spring.putConstraint(SpringLayout.NORTH, button2, 362, SpringLayout.SOUTH, combobox1); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize(690, 680); setLocation(300, 60); setVisible(true); PackagePanel.defaultButtonSet(); }
public ExampleField(ExampleOption option) { super(option); model = new DefaultListModel(); model.addListDataListener( new ListDataListener() { @Override public void intervalAdded(ListDataEvent e) { fireChangeEvent(); } @Override public void intervalRemoved(ListDataEvent e) { fireChangeEvent(); } @Override public void contentsChanged(ListDataEvent e) { fireChangeEvent(); } }); final JList list = new JList(model) { @Override public Dimension getPreferredScrollableViewportSize() { return new Dimension(3 * CELL_SIZE, 2 * CELL_SIZE); } }; list.setLayoutOrientation(JList.HORIZONTAL_WRAP); list.setVisibleRowCount(0); list.setFixedCellHeight(CELL_SIZE); list.setFixedCellWidth(CELL_SIZE); list.setTransferHandler( new URIImportTransferHandler() { @Override public boolean canImport(TransferSupport support) { support.setShowDropLocation(false); return super.canImport(support); } @Override public boolean importData(TransferSupport support) { try { List<BufferedImage> images = new ArrayList<BufferedImage>(); for (URI u : getURIs(support)) { try { images.add(ImageIO.read(u.toURL())); } catch (IOException e) { } } addExamples(images); return true; } catch (IOException e) { return false; } catch (UnsupportedFlavorException e) { return false; } catch (URISyntaxException e) { return false; } } }); list.setCellRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Example example = (Example) value; setHorizontalAlignment(SwingConstants.CENTER); setText(null); setIcon(example.getIcon()); setBorder(BorderFactory.createEmptyBorder()); return this; } }); JScrollPane jsp = new JScrollPane(list); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); final JButton remove = new JButton("Remove"); remove.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int[] indices = list.getSelectedIndices(); for (int i = indices.length - 1; i >= 0; i--) { model.remove(indices[i]); } } }); list.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { remove.setEnabled(list.getSelectedIndex() != -1); } }); remove.setEnabled(false); panel = new JPanel(new GridBagLayout()); // Add list GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; panel.add(jsp, c); // Add remove button c = new GridBagConstraints(); c.gridx = 0; c.anchor = GridBagConstraints.WEST; panel.add(remove, c); }
public JunctionLinkDataFrame(final JunctionLink jl) { super( jl.getCurrName() + " properties", false, // resizable false, // closable false, // maximizable true); // iconifiable // PSRender.onHold(); super.setBackground(back_color); super.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameActivated(InternalFrameEvent e) { reload(); SelectedObject.setSelectedObject(jl); } }); PSRender.moveToTop(jl.getBound(), 0.5); ml = jl; setLocation(50, 50); dataModelMain = new HeadTable(jl); tableMain = new JTable(dataModelMain); tableMain.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); tableMain.setPreferredScrollableViewportSize(new Dimension(500, 20)); // tableMain.setBackground(back_color); // code TableColumn column_code = tableMain.getColumn("Code"); DefaultTableCellRenderer rendererCode = new DefaultTableCellRenderer(); rendererCode.setToolTipText("Enter new code for this path"); column_code.setCellRenderer(rendererCode); column_code.setCellEditor(new TextFieldEditor()); // name TableColumn column_name = tableMain.getColumn("Name"); LanguageButtonRender render_name = new LanguageButtonRender(); render_name.setToolTipText("Path name. Press for change name"); column_name.setCellRenderer(render_name); LanguageButtonEditor editor_name = new LanguageButtonEditor(new JCheckBox()); column_name.setCellEditor(editor_name); // junction 1 TableColumn column_junc_1 = tableMain.getColumn("Junction 1"); MLButtonRenderer rendererJunc_1 = new MLButtonRenderer(); rendererJunc_1.setToolTipText("Code of first Junction, click for open properties"); column_junc_1.setCellRenderer(rendererJunc_1); MLButtonEditor editorJunc = new MLButtonEditor(new JCheckBox()); column_junc_1.setCellEditor(editorJunc); // junction 2 TableColumn column_junc_2 = tableMain.getColumn("Junction 2"); MLButtonRenderer rendererJunc_2 = new MLButtonRenderer(); rendererJunc_2.setToolTipText("Code of second Junction, click for open properties"); column_junc_2.setCellRenderer(rendererJunc_2); column_junc_2.setCellEditor(editorJunc); // type JComboBox comboBoxType = new JComboBox(); String roadNames[] = jl.getTypeNames(); for (int i = 0, len = roadNames.length; i < len; i++) { comboBoxType.addItem(roadNames[i]); } TableColumn column_type = tableMain.getColumn("Type"); DefaultTableCellRenderer rendererType = new DefaultTableCellRenderer(); rendererType.setToolTipText("To change road type click for combo box"); column_type.setCellRenderer(rendererType); column_type.setCellEditor(new DefaultCellEditor(comboBoxType)); // legth TableColumn column_length = tableMain.getColumn("Length"); DefaultTableCellRenderer rendererLen = new DefaultTableCellRenderer(); rendererLen.setToolTipText("The path length in meters"); column_length.setCellRenderer(rendererLen); scrollpaneMain = new JScrollPane(tableMain); scrollpaneMain.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollpaneMain.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); scrollpaneMain.setPreferredSize(new Dimension(500, 50)); Container contentPane = super.getContentPane(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); contentPane.setLayout(gridbag); c.ipady = 0; // make this component tall c.weightx = 0.5; c.gridwidth = 4; c.gridx = 0; c.gridy = 0; gridbag.setConstraints(scrollpaneMain, c); // scrollpaneMain.setBackground(back_color); // scrollpaneMain.setForeground(back_color); contentPane.add(scrollpaneMain); TableModel dataModelPoints = new PointTableModel(jl); tablePoints = new JTable(dataModelPoints); tablePoints.setPreferredScrollableViewportSize( new Dimension(200, dataModelPoints.getRowCount() * tablePoints.getRowHeight())); ListModel lm = new AbstractListModel() { public int getSize() { return 1000; } public Object getElementAt(int index) { return "" + index; } }; JList rowHeader = new JList(lm); rowHeader.setFixedCellWidth(20); rowHeader.setFixedCellHeight(tablePoints.getRowHeight()); // + tablePoints.getRowMargin()); rowHeader.setCellRenderer(new RowHeaderRenderer(tablePoints)); scrollPanePoints = new JScrollPane(tablePoints); scrollPanePoints.setWheelScrollingEnabled(true); scrollPanePoints.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPanePoints.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); int mh; if (dataModelPoints.getRowCount() * tablePoints.getRowHeight() > 100) { mh = 100; } else { mh = dataModelPoints.getRowCount() * tablePoints.getRowHeight(); } scrollPanePoints.setPreferredSize(new Dimension(200, mh)); scrollPanePoints.setRowHeaderView(rowHeader); c.ipadx = 200; c.weightx = 0.5; c.gridwidth = 3; c.gridx = 1; c.gridy = 1; gridbag.setConstraints(scrollPanePoints, c); // scrollPanePoints.setBackground(back_color); contentPane.add(scrollPanePoints); button_ok = new JButton("Ok"); button_ok.addActionListener(this); JPanel buttonPane = new JPanel(null); buttonPane.setPreferredSize(new Dimension(500, 100)); button_ok.setBounds(205, 40, 90, 40); buttonPane.add(button_ok); c.ipady = 10; // make this component tall c.ipadx = 10; c.weightx = 0.5; c.gridwidth = 4; c.gridx = 2; c.gridy = 2; gridbag.setConstraints(buttonPane, c); buttonPane.setBackground(back_color); contentPane.add(buttonPane); super.pack(); super.setVisible(true); // MapApplication.getDesktop().setSelectedFrame(this); }