1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* 22 * 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 * 28 * pmInstallScreen.java 29 * Create add/modify GUI 30 */ 31 32package com.sun.admin.pm.client; 33 34import java.awt.*; 35import java.awt.event.*; 36import java.util.Vector; 37import javax.swing.JPanel; 38import javax.swing.*; 39 40import com.sun.admin.pm.server.*; 41 42/* 43 * Screen for Installing/Modifying local and network printers 44 */ 45 46public class pmInstallScreen extends pmButtonScreen { 47 48 pmTextField pnameText; 49 pmTextField snameText; 50 pmTextField descText; 51 pmTextField userText; 52 JComboBox portCombo; 53 JComboBox faultCombo; 54 55// For printers configured without using make/model/PPD files 56 JComboBox fileCombo; 57 JComboBox typeCombo; 58 59// For printers configured using make/model/PPD files 60 JComboBox ppdCombo; 61 JComboBox makeCombo; 62 JComboBox modelCombo; 63 64 pmTextField destText; 65 JComboBox protocolCombo; 66 JCheckBox defaultp; 67 JComboBox bannerCombo; 68 pmButton addButton; 69 pmButton deleteButton; 70 JList userList; 71 Vector userData; 72 73 public pmInstallScreen() {} 74 75 76 public void printernameLabel(JPanel north, GridBagConstraints c) { 77 north.add(new JLabel 78 (pmUtility.getResource("Printer.Name:")), c); 79 } 80 public void printernameTextField(JPanel north, GridBagConstraints c) { 81 pnameText = new pmTextField(14); 82 north.add(pnameText, c); 83 } 84 public void printernameStaticField(JPanel north, GridBagConstraints c) { 85 north.add(new JLabel 86 (pmUtility.getResource("Printer.Server:")), c); 87 } 88 89 public void servernameLabel(JPanel north, GridBagConstraints c) { 90 north.add(new JLabel 91 (pmUtility.getResource("Printer.Server:")), c); 92 } 93 public void servernameTextField(JPanel north, GridBagConstraints c) { 94 snameText = new pmTextField(30); 95 north.add(snameText, c); 96 } 97 public void servernameStaticField(JPanel north, GridBagConstraints c) { 98 } 99 100 public void descriptionLabel(JPanel north, GridBagConstraints c) { 101 north.add(new JLabel 102 (pmUtility.getResource("Description:")), c); 103 } 104 public void descriptionField(JPanel north, GridBagConstraints c) { 105 descText = new pmTextField(25); 106 north.add(descText, c); 107 } 108 109 public void printerportLabel(JPanel north, GridBagConstraints c) { 110 north.add(new JLabel 111 (pmUtility.getResource("Printer.Port:")), c); 112 } 113 114 public void devnullLabel(JPanel north, GridBagConstraints c) { 115 north.add(new JLabel("/dev/null")); 116 } 117 118 public void printerportField(JPanel north, GridBagConstraints c) { 119 120 String devices[]; 121 int i; 122 123 try { 124 devices = PrinterUtil.getDeviceList(); 125 } catch (Exception e) { 126 Debug.warning("CLNT: pmAccess:getDeviceList caught " + e); 127 devices = new String[1]; 128 devices[0] = ""; 129 } 130 portCombo = new JComboBox(devices); 131 portCombo.insertItemAt(pmUtility.getResource("Not.Selected"), 0); 132 portCombo.setSelectedIndex(0); 133 134 portCombo.addItem(pmUtility.getResource("Other...")); 135 portCombo.addActionListener(new ComboListener(Constants.PORT)); 136 137 north.add(portCombo, c); 138 139 } 140 public void printertypeLabel(JPanel north, GridBagConstraints c) { 141 north.add(new JLabel 142 (pmUtility.getResource("Printer.Type:")), c); 143 } 144 public void printertypeField(JPanel north, GridBagConstraints c) { 145 typeCombo = new JComboBox(); 146 typeCombo.addItem("PostScript"); 147 typeCombo.addItem("HP Printer"); 148 typeCombo.addItem("Reverse PostScript"); 149 typeCombo.addItem("Epson 2500"); 150 typeCombo.addItem("IBM ProPrinter"); 151 typeCombo.addItem("Qume Sprint 5"); 152 typeCombo.addItem("Daisy"); 153 typeCombo.addItem("Diablo"); 154 typeCombo.addItem("Datagraphix"); 155 typeCombo.addItem("DEC LA100"); 156 typeCombo.addItem("DEC LN03"); 157 typeCombo.addItem("Dec Writer"); 158 typeCombo.addItem("Texas Instruments 800"); 159 typeCombo.addItem(pmUtility.getResource("Other...")); 160 typeCombo.addActionListener(new ComboListener(Constants.TYPE)); 161 north.add(typeCombo, c); 162 } 163 164 public void filecontentsLabel(JPanel north, GridBagConstraints c) { 165 north.add(new JLabel 166 (pmUtility.getResource("File.Contents:")), c); 167 } 168 public void filecontentsField(JPanel north, GridBagConstraints c) { 169 fileCombo = new JComboBox(); 170 fileCombo.addItem(pmUtility.getResource("PostScript")); 171 fileCombo.addItem(pmUtility.getResource("ASCII")); 172 fileCombo.addItem( 173 pmUtility.getResource("Both.PostScript.and.ASCII")); 174 fileCombo.addItem(pmUtility.getResource("None")); 175 fileCombo.addItem(pmUtility.getResource("Any")); 176 north.add(fileCombo, c); 177 } 178 179 180 public void printermakeLabel(JPanel north, GridBagConstraints c) { 181 north.add(new JLabel 182 (pmUtility.getResource("Printer.Make:")), c); 183 } 184 public void printermakeField(JPanel north, GridBagConstraints c) { 185 186 String makes[]; 187 188 try { 189 makes = PrinterUtil.getMakesList(); 190 } catch (Exception e) { 191 Debug.warning("CLNT: pmAccess:getMakeList caught" +e); 192 makes = new String[1]; 193 makes[0] = ""; 194 } 195 196 makeCombo = new JComboBox(makes); 197 makeCombo.insertItemAt( 198 pmUtility.getResource("Not.Selected"), 0); 199 makeCombo.setSelectedIndex(0); 200 201 202 makeCombo.addActionListener(new ComboListener(Constants.MAKE)); 203 north.add(makeCombo, c); 204 } 205 206 public void printermodelsLabel(JPanel north, GridBagConstraints c) { 207 north.add(new JLabel 208 (pmUtility.getResource("Printer.Model:")), c); 209 } 210 211 public void printermodelsField(JPanel north, GridBagConstraints c) { 212 String models[]; 213 modelCombo = new JComboBox(); 214 modelCombo.addItem(" "); 215 modelCombo.addActionListener( 216 new ComboListener(Constants.MODEL)); 217 north.add(modelCombo, c); 218 } 219 220 public void ppdcontentsLabel(JPanel north, GridBagConstraints c) { 221 north.add(new JLabel 222 (pmUtility.getResource("Printer.Driver:")), c); 223 } 224 public void ppdcontentsField(JPanel north, GridBagConstraints c) { 225 ppdCombo = new JComboBox(); 226 ppdCombo.addItem(" "); 227 ppdCombo.addActionListener(new ComboListener(Constants.PPD)); 228 north.add(ppdCombo, c); 229 } 230 231 public void faultnotLabel(JPanel north, GridBagConstraints c) { 232 north.add(new JLabel 233 (pmUtility.getResource("Fault.Notification:")), c); 234 } 235 public void faultnotField(JPanel north, GridBagConstraints c) { 236 faultCombo = new JComboBox(); 237 238 faultCombo.addItem(pmUtility.getResource("Write.to.Superuser")); 239 faultCombo.addItem(pmUtility.getResource("Mail.to.Superuser")); 240 faultCombo.addItem(pmUtility.getResource("None")); 241 north.add(faultCombo, c); 242 } 243 244 public void destinationLabel(JPanel north, GridBagConstraints c) { 245 north.add(new JLabel 246 (pmUtility.getResource("Destination:")), c); 247 } 248 public void destinationField(JPanel north, GridBagConstraints c) { 249 destText = new pmTextField(25); 250 north.add(destText, c); 251 } 252 253 public void protocolLabel(JPanel north, GridBagConstraints c) { 254 north.add(new JLabel 255 (pmUtility.getResource("Protocol:")), c); 256 } 257 public void protocolField(JPanel north, GridBagConstraints c) { 258 protocolCombo = new JComboBox(); 259 protocolCombo.addItem("BSD"); 260 protocolCombo.addItem("TCP"); 261 protocolCombo.addItem("URI"); 262 north.add(protocolCombo, c); 263 } 264 265 public void optionsLabel(JPanel north, GridBagConstraints c) { 266 north.add(new JLabel 267 (pmUtility.getResource("Options:")), c); 268 } 269 270 public void bannerLabel(JPanel north, GridBagConstraints c) { 271 north.add(new JLabel 272 (pmUtility.getResource("Banner:")), c); 273 } 274 275 public void optionLabel(JPanel north, GridBagConstraints c) { 276 north.add(new JLabel 277 (pmUtility.getResource("Option:")), c); 278 } 279 280 public void optionsFields(JPanel north, GridBagConstraints c) { 281 defaultp = new JCheckBox( 282 pmUtility.getResource("Default.Printer")); 283 284 north.add(defaultp, c); 285 286 c.gridy++; 287 bannerCombo = new JComboBox(); 288 bannerCombo.addItem(pmUtility.getResource 289 ("Always.Print.Banner")); 290 bannerCombo.addItem(pmUtility.getResource 291 ("User.Selectable.Default.On")); 292 bannerCombo.addItem(pmUtility.getResource 293 ("Never.Print.Banner")); 294 295 north.add(bannerCombo, c); 296 } 297 298 public void defaultoptionField(JPanel north, GridBagConstraints c) { 299 defaultp = new JCheckBox( 300 pmUtility.getResource("Default.Printer")); 301 302 north.add(defaultp, c); 303 } 304 305 public void northPanelConstraints(GridBagConstraints c) { 306 c.weightx = c.weighty = 0.0; 307 c.fill = GridBagConstraints.NONE; 308 c.anchor = GridBagConstraints.WEST; 309 c.insets = new Insets(8, 5, 5, 5); 310 c.gridheight = 1; 311 c.gridwidth = 1; 312 } 313 314 public void labelConstraints(GridBagConstraints c) { 315 c.weightx = c.weighty = 0.0; 316 c.fill = GridBagConstraints.NONE; 317 c.anchor = GridBagConstraints.WEST; 318 } 319 public void TextFieldConstraints(GridBagConstraints c) { 320 c.ipadx = 15; 321 c.fill = GridBagConstraints.HORIZONTAL; 322 // c.fill = GridBagConstraints.NONE; 323 c.anchor = GridBagConstraints.WEST; 324 c.weightx = c.weighty = 1.0; 325 } 326 public void comboboxConstraints(GridBagConstraints c) { 327 c.weightx = c.weighty = 0.0; 328 c.fill = GridBagConstraints.NONE; 329 c.anchor = GridBagConstraints.WEST; 330 } 331 332 public void optionsConstraints(GridBagConstraints c) { 333 c.fill = GridBagConstraints.NONE; 334 c.weightx = c.weighty = 0.0; 335 } 336 337 class ComboListener implements ActionListener { 338 int activeCombo; 339 340 // Constructor 341 public ComboListener(int aCombo) 342 { 343 activeCombo = aCombo; 344 } 345 346 public void actionPerformed(ActionEvent e) { 347 348 switch (activeCombo) 349 { 350 case Constants.PORT: 351 actionportCombo(); 352 break; 353 354 case Constants.TYPE: 355 actiontypeCombo(); 356 break; 357 358 case Constants.MAKE: 359 actionmakeCombo(); 360 break; 361 362 case Constants.MODEL: 363 actionmodelCombo(); 364 break; 365 366 case Constants.PPD: 367 actionppdCombo(); 368 break; 369 370 } 371 } 372 } 373 374 public void actionportCombo() {} 375 376 public void actiontypeCombo() {} 377 378 public void actionmakeCombo() {} 379 380 public void actionmodelCombo() {} 381 382 public void actionppdCombo() {} 383 384 class adddelButtonListener implements ActionListener 385 { 386 int activeButton; 387 388 public adddelButtonListener(int aButton) 389 { 390 activeButton = aButton; 391 } 392 393 public void actionPerformed(ActionEvent e) { 394 395 switch (activeButton) 396 { 397 case Constants.ADD: 398 actionaddButton(); 399 break; 400 case Constants.DELETE: 401 actiondeleteButton(); 402 break; 403 } 404 } 405 } 406 407 public void actionaddButton() {} 408 409 public void actiondeleteButton() {} 410 411 public void useraccessLabel(JPanel center, GridBagConstraints c) { 412 center.add(new JLabel 413 (pmUtility.getResource("User.Access.List:")), c); 414 } 415 416 public void adButtons(GridBagConstraints c) { 417 418 c.anchor = GridBagConstraints.CENTER; 419 c.fill = GridBagConstraints.HORIZONTAL; 420 421 addButton = new pmButton(pmUtility.getResource("Add")); 422 deleteButton = new pmButton(pmUtility.getResource("Delete")); 423 addButton.addActionListener( 424 new adddelButtonListener(Constants.ADD)); 425 deleteButton.addActionListener( 426 new adddelButtonListener(Constants.DELETE)); 427 } 428 429 public void xxcenterPanel() { 430 431 JPanel center = new JPanel(); 432 center.setLayout(new GridBagLayout()); 433 GridBagConstraints c = new GridBagConstraints(); 434 435 c.insets = new Insets(15, 15, 15, 15); 436 c.anchor = GridBagConstraints.WEST; 437 438 // Create the label 439 c.gridx = 0; 440 c.gridy = 0; 441 c.fill = GridBagConstraints.NONE; 442 c.weightx = c.weighty = 0.0; 443 c.anchor = GridBagConstraints.NORTHWEST; 444 center.add(new JLabel 445 (pmUtility.getResource("User.Access.List:")), c); 446 447 // Create the User Access List as JList 448 userList = new JList(); 449 JScrollPane scrollPane = new JScrollPane(); 450 scrollPane.getViewport().setView(userList); 451 452 c.gridwidth = 2; 453 c.gridx = 1; 454 c.weightx = c.weighty = 1.0; 455 c.fill = GridBagConstraints.BOTH; 456 center.add(scrollPane, c); 457 458 // Create the text field for adding users 459 c.gridx = 1; 460 c.gridy = 1; 461 c.ipadx = 15; 462 c.fill = GridBagConstraints.HORIZONTAL; 463 c.anchor = GridBagConstraints.WEST; 464 c.weightx = c.weighty = 1.0; 465 466 userText = new pmTextField(25); 467 center.add(userText, c); 468 469 // Create the add/delete buttons 470 c.gridx = 1; 471 c.gridy = 2; 472 473 c.anchor = GridBagConstraints.CENTER; 474 c.fill = GridBagConstraints.HORIZONTAL; 475 476 addButton = new pmButton(pmUtility.getResource("Add")); 477 deleteButton = new pmButton(pmUtility.getResource("Delete")); 478 addButton.addActionListener( 479 new adddelButtonListener(Constants.ADD)); 480 deleteButton.addActionListener( 481 new adddelButtonListener(Constants.DELETE)); 482 483 484 c.gridwidth = 1; 485 center.add(addButton, c); 486 487 c.gridx = 2; 488 center.add(deleteButton, c); 489 490 add("Center", center); 491 492 } 493 494} 495